KDevelop API Documentation

addtranslationdlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Bernd Gehrmann                                  *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "addtranslationdlg.h"
00013 
00014 #include <qcombobox.h>
00015 #include <qfile.h>
00016 #include <qfileinfo.h>
00017 #include <qhbox.h>
00018 #include <qlabel.h>
00019 #include <qlayout.h>
00020 #include <qlineedit.h>
00021 #include <qpushbutton.h>
00022 #include <qstrlist.h>
00023 #include <kbuttonbox.h>
00024 #include <kdialog.h>
00025 #include <klocale.h>
00026 #include <kmessagebox.h>
00027 #include <kstdguiitem.h>
00028 #include <kdeversion.h>
00029 
00030 #include "misc.h"
00031 #include "autoprojectpart.h"
00032 
00033 
00034 AddTranslationDialog::AddTranslationDialog(AutoProjectPart *part, QWidget *parent, const char *name)
00035     : QDialog(parent, name, true)
00036 {
00037     setCaption(i18n("Add Translation"));
00038 
00039     m_part = part;
00040 
00041     QHBox *hbox = new QHBox(this);
00042     (void) new QLabel(i18n("Language:"), hbox);
00043     lang_combo = new QComboBox(hbox);
00044 
00045     QVBoxLayout *layout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
00046     layout->addWidget(hbox);
00047 
00048     QFrame *frame = new QFrame(this);
00049     frame->setFrameStyle(QFrame::HLine | QFrame::Sunken);
00050     layout->addWidget(frame, 0);
00051 
00052     KButtonBox *buttonbox = new KButtonBox(this);
00053     buttonbox->addStretch();
00054 #if KDE_IS_VERSION( 3, 2, 90 )
00055     QPushButton *ok_button = buttonbox->addButton(KStdGuiItem::ok());
00056     QPushButton *cancel_button = buttonbox->addButton(KStdGuiItem::cancel());
00057 #else
00058     QPushButton *ok_button = buttonbox->addButton(KStdGuiItem::ok().text());
00059     QPushButton *cancel_button = buttonbox->addButton(KStdGuiItem::cancel().text());
00060 #endif
00061     ok_button->setDefault(true);
00062     connect( ok_button, SIGNAL(clicked()), this, SLOT(accept()) );
00063     connect( cancel_button, SIGNAL(clicked()), this, SLOT(reject()) );
00064     buttonbox->layout();
00065     layout->addWidget(buttonbox, 0);
00066 
00067     QStringList rawlist, list;
00068     rawlist << "af" << "ar" << "bg" << "bo" << "br" << "bs" << "ca" << "cs" << "cy" << "da"
00069             << "de" << "el" << "en_GB"   << "eo" << "es" << "et" << "eu" << "fi" << "fr";
00070     rawlist << "ga" << "gl" << "gu" << "he" << "hi" << "hu" << "id" << "is" << "it" << "ja"
00071             << "km" << "ko" << "lt" << "lv" << "mi" << "mk" << "mr" << "nl" << "no" << "no_NY";
00072     rawlist << "oc" << "pl" << "pt" << "pt_BR" << "ro" << "ru" << "sk" << "sl" << "sr" << "sv"
00073             << "ta" << "th" << "tr" << "uk" << "wa" << "zh_CN.GB2312" << "zh_TW.Big5";
00074 
00075     // Remove already added languages
00076     QStringList::ConstIterator it;
00077     for (it = rawlist.begin(); it != rawlist.end(); ++it) {
00078         QFileInfo fi(m_part->projectDirectory() + "/po/" + (*it) + ".po");
00079         if (!fi.exists())
00080             list.append(*it);
00081     }
00082 
00083     if (list.isEmpty()) {
00084         KMessageBox::information(this, i18n("Your sourcecode is already translated to all supported languages."));
00085         ok_button->setEnabled(false);
00086     }
00087     lang_combo->insertStringList(list);
00088 }
00089 
00090 
00091 AddTranslationDialog::~AddTranslationDialog()
00092 {}
00093 
00094 
00095 void AddTranslationDialog::accept()
00096 {
00097     QString dir = m_part->projectDirectory() + "/po";
00098     QString fileName = dir + "/" + lang_combo->currentText() + ".po";
00099 
00100     QFile f(fileName);
00101     if (f.exists()) {
00102         KMessageBox::information(this, i18n("A translation file for the language %1 exists already."));
00103         return;
00104     }
00105     f.open(IO_WriteOnly);
00106     f.close();
00107 
00108     dir = m_part->buildDirectory() + "/po";
00109     m_part->startMakeCommand(dir, QString::fromLatin1("force-reedit"));
00110 
00111     QDialog::accept();
00112 }
00113 
00114 #include "addtranslationdlg.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:39 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003