parley
languageproperties.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "languageproperties.h"
00015
00016 #include "languagepropertiespage.h"
00017 #include "languagesettings.h"
00018 #include "parleydocument.h"
00019
00020 #include <KMessageBox>
00021 #include <QLabel>
00022 #include <KLocale>
00023
00024 LanguageProperties::LanguageProperties(QWidget * parent)
00025 :KPageDialog(parent), m_doc(ParleyDocument::instance())
00026 {
00027 setCaption(i18n("Edit Languages"));
00028 setFaceType( List );
00029 setButtons(User1|User2|Ok|Cancel);
00030
00031 setButtonText(User2, i18n("Add language"));
00032 setButtonIcon(User2, KIcon("list-add"));
00033 setButtonText(User1, i18n("Remove language"));
00034 setButtonIcon(User1, KIcon("list-remove"));
00035
00036 connect( this, SIGNAL(user2Clicked()), this, SLOT(slotAppendIdentifier()));
00037 connect( this, SIGNAL(user1Clicked()), this, SLOT(slotDeleteIdentifier()));
00038
00039 for ( int i = 0; i < m_doc->document()->identifierCount(); i++ ) {
00040 createPage(i);
00041 }
00042 }
00043
00044 KPageWidgetItem* LanguageProperties::createPage(int i)
00045 {
00046 LanguagePropertiesPage* page = new LanguagePropertiesPage(m_doc, i, this);
00047
00048 QString name = i18n("New Language");
00049 QString currentIcon;
00050
00051
00052 if (m_doc->document()->identifierCount() > i) {
00053 name = m_doc->document()->identifier(i).name();
00054 LanguageSettings currentSettings(m_doc->document()->identifier(i).locale());
00055 currentSettings.readConfig();
00056 currentIcon = currentSettings.icon();
00057 }
00058
00059 KPageWidgetItem* editPage = new KPageWidgetItem(page, name);
00060 editPage->setHeader( i18nc("Edit language properties", "Properties for %1", name) );
00061
00062 m_pages.append(editPage);
00063 addPage(editPage);
00064
00065
00066 if (currentIcon.isEmpty()) {
00067 currentIcon = QString::fromLatin1("set-language");
00068 }
00069 editPage->setIcon( KIcon( currentIcon ) );
00070
00071 connect(page->identifierNameLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(pageNameChanged(const QString&)));
00072 connect(page, SIGNAL(iconSelected(const QString&)), this, SLOT(pageIconChanged(const QString&)));
00073 connect(this, SIGNAL(accepted()), page, SLOT(accept()));
00074
00075 return editPage;
00076 }
00077
00078 void LanguageProperties::accept()
00079 {
00080 KEduVocDocument *doc = m_doc->document();
00081 int deleted = 0;
00082
00083 for (int index = 0; index < m_pages.count(); index++) {
00084 if (m_pages.value(index)->isEnabled()) {
00085 if (index - deleted >= doc->identifierCount()) {
00086
00087 doc->appendIdentifier();
00088 }
00089 LanguagePropertiesPage * page = static_cast<LanguagePropertiesPage *>(m_pages.value(index)->widget());
00090 page->setLanguageIdentifierIndex(index-deleted);
00091 } else {
00092
00093 if (index < doc->identifierCount()) {
00094 if ( KMessageBox::warningYesNo(this, i18n("Really delete language: %1?", doc->identifier(index-deleted).name()), i18n("Remove Language")) == KMessageBox::Yes ) {
00095 doc->removeIdentifier(index-deleted);
00096 doc->setModified();
00097 deleted++;
00098 }
00099 }
00100 }
00101 }
00102
00103 KDialog::accept();
00104 }
00105
00106
00107 void LanguageProperties::slotAppendIdentifier()
00108 {
00109
00110 if (currentPage() && !currentPage()->isEnabled()) {
00111 currentPage()->setEnabled(true);
00112 return;
00113 }
00114
00115 int i = m_pages.count();
00116 KPageWidgetItem* newPage = createPage( i );
00117 setCurrentPage( newPage );
00118 }
00119
00120 void LanguageProperties::slotDeleteIdentifier()
00121 {
00122 currentPage()->setEnabled(false);
00123 }
00124
00125 void LanguageProperties::pageIconChanged(const QString & newIcon)
00126 {
00127 currentPage()->setIcon( KIcon(newIcon) );
00128 }
00129
00130 void LanguageProperties::pageNameChanged(const QString & newName)
00131 {
00132 currentPage()->setName( newName );
00133 }
00134
00135 #include "languageproperties.moc"