summaryrefslogtreecommitdiffstats
path: root/buildtools/autotools/addtranslationdlg.cpp
blob: 11bf9a867d39b6b1f8f61c4c7db25ad03c7a116d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/***************************************************************************
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 *   bernd@kdevelop.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "addtranslationdlg.h"

#include <tqcombobox.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqlineedit.h>
#include <tqpushbutton.h>
#include <tqstrlist.h>
#include <kbuttonbox.h>
#include <kdialog.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kstdguiitem.h>
#include <kdeversion.h>

#include "misc.h"
#include "autoprojectpart.h"


AddTranslationDialog::AddTranslationDialog(AutoProjectPart *part, TQWidget *parent, const char *name)
    : TQDialog(parent, name, true)
{
    setCaption(i18n("Add Translation"));

    m_part = part;

    TQHBox *hbox = new TQHBox(this);
    (void) new TQLabel(i18n("Language:"), hbox);
    lang_combo = new TQComboBox(hbox);

    TQVBoxLayout *tqlayout = new TQVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
    tqlayout->addWidget(hbox);

    TQFrame *frame = new TQFrame(this);
    frame->setFrameStyle(TQFrame::HLine | TQFrame::Sunken);
    tqlayout->addWidget(frame, 0);

    KButtonBox *buttonbox = new KButtonBox(this);
    buttonbox->addStretch();
    TQPushButton *ok_button = buttonbox->addButton(KStdGuiItem::ok());
    TQPushButton *cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
    ok_button->setDefault(true);
    connect( ok_button, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept()) );
    connect( cancel_button, TQT_SIGNAL(clicked()), this, TQT_SLOT(reject()) );
    buttonbox->tqlayout();
    tqlayout->addWidget(buttonbox, 0);

    TQStringList rawlist, list;
    rawlist << "af" << "ar" << "bg" << "bo" << "br" << "bs" << "ca" << "cs" << "cy" << "da"
            << "de" << "el" << "en_GB"   << "eo" << "es" << "et" << "eu" << "fi" << "fr";
    rawlist << "ga" << "gl" << "gu" << "he" << "hi" << "hu" << "id" << "is" << "it" << "ja"
            << "km" << "ko" << "lt" << "lv" << "mi" << "mk" << "mr" << "nl" << "no" << "no_NY";
    rawlist << "oc" << "pl" << "pt" << "pt_BR" << "ro" << "ru" << "sk" << "sl" << "sr" << "sv"
            << "ta" << "th" << "tr" << "uk" << "wa" << "zh_CN.GB2312" << "zh_TW.Big5";

    // Remove already added languages
    TQStringList::ConstIterator it;
    for (it = rawlist.begin(); it != rawlist.end(); ++it) {
        TQFileInfo fi(m_part->projectDirectory() + "/po/" + (*it) + ".po");
        if (!fi.exists())
            list.append(*it);
    }

    if (list.isEmpty()) {
        KMessageBox::information(this, i18n("Your sourcecode is already translated to all supported languages."));
        ok_button->setEnabled(false);
    }
    lang_combo->insertStringList(list);
}


AddTranslationDialog::~AddTranslationDialog()
{}


void AddTranslationDialog::accept()
{
    TQString dir = m_part->projectDirectory() + "/po";
    TQString fileName = dir + "/" + lang_combo->currentText() + ".po";

    TQFile f(fileName);
    if (f.exists()) {
        KMessageBox::information(this, i18n("A translation file for the language %1 exists already."));
        return;
    }
    f.open(IO_WriteOnly);
    f.close();

    dir = m_part->buildDirectory() + "/po";
    m_part->startMakeCommand(dir, TQString::tqfromLatin1("force-reedit"));

    TQDialog::accept();
}

#include "addtranslationdlg.moc"