Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

language.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "settings.h"
00022 
00023 #include <qpe/global.h>
00024 #include <qpe/fontmanager.h>
00025 #include <qpe/config.h>
00026 #include <qpe/applnk.h>
00027 #include <qpe/qpedialog.h>
00028 #include <qpe/qpeapplication.h>
00029 #if defined(Q_WS_QWS) && !defined(QT_NO_COP)
00030 #include <qpe/qcopenvelope_qws.h>
00031 #endif
00032 
00033 #include <qlabel.h>
00034 #include <qcheckbox.h>
00035 #include <qradiobutton.h>
00036 #include <qtabwidget.h>
00037 #include <qslider.h>
00038 #include <qfile.h>
00039 #include <qtextstream.h>
00040 #include <qdatastream.h>
00041 #include <qmessagebox.h>
00042 #include <qcombobox.h>
00043 #include <qspinbox.h>
00044 #include <qlistbox.h>
00045 #include <qdir.h>
00046 #if QT_VERSION >= 0x030000
00047 #include <qstylefactory.h>
00048 #endif
00049 
00050 #include <stdlib.h>
00051 
00052 
00053 LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl )
00054                 : LanguageSettingsBase( parent, name, TRUE, fl )
00055 {
00056         if ( FontManager::hasUnicodeFont() )
00057                 languages->setFont(FontManager::unicodeFont(FontManager::Proportional));
00058 
00059 
00060         QString tfn = QPEApplication::qpeDir() + "i18n/";
00061         QDir langDir = tfn;
00062         QStringList list = langDir.entryList("*", QDir::Dirs );
00063 
00064         QStringList::Iterator it;
00065 
00066         for ( it = list.begin(); it != list.end(); ++it ) {
00067                 QString name = (*it);
00068                 QFileInfo desktopFile( tfn + "/" + name + "/.directory" );
00069                 if ( desktopFile.exists() ) {
00070                         langAvail.append(name);
00071                         Config conf( desktopFile.filePath(), Config::File );
00072                         QString langName = conf.readEntry( "Name" );
00073                         QString ownName = conf.readEntryDirect( "Name[" + name + "]" );
00074                         if ( ownName.isEmpty() )
00075                                 ownName = conf.readEntryDirect( "Name" );
00076                         if ( !ownName.isEmpty() && ownName != langName )
00077                                 langName = langName + " [" + ownName + "]";
00078                         languages->insertItem( langName );
00079 
00080                 }
00081         }
00082         if ( langAvail. find ( "en" ) == -1 ) {
00083                 langAvail. prepend ( "" ); // no tr
00084                 languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 );
00085         }
00086 
00087         dl = new QPEDialogListener(this);
00088         reset();
00089 }
00090 
00091 LanguageSettings::~LanguageSettings()
00092 {}
00093 
00094 void LanguageSettings::accept()
00095 {
00096     Config c( "qpe" );
00097     c.setGroup( "Startup" );
00098     if ( ( c.readNumEntry( "FirstUse", 42 ) == 0 ) &&
00099        ( QMessageBox::warning( this, tr("Language"), tr("<qt>Attention, all windows will be closed by changing the language\n"
00100                                                  "without saving the Data.<br><br>Go on?</qt>"), 1, 2) ) 
00101          == QMessageBox::Cancel )
00102                                                  return;
00103     applyLanguage();
00104     QDialog::accept();
00105 }
00106 
00107 void LanguageSettings::applyLanguage()
00108 {
00109         setLanguage ( langAvail. at ( languages-> currentItem ( )));
00110 }
00111 
00112 
00113 void LanguageSettings::reject()
00114 {
00115         reset();
00116         QDialog::reject();
00117 }
00118 
00119 void LanguageSettings::reset()
00120 {
00121         QString l = getenv("LANG");
00122         Config config("locale");
00123         config.setGroup("Language");
00124         l = config.readEntry( "Language", l );
00125         actualLanguage = l;
00126         if (l.isEmpty())
00127                 l = "en";
00128 
00129         int n = langAvail.find( l );
00130         languages->setCurrentItem( n );
00131 }
00132 
00133 QString LanguageSettings::actualLanguage;
00134 
00135 void LanguageSettings::setLanguage(const QString& lang)
00136 {
00137         if ( lang != actualLanguage ) {
00138                 Config config("locale");
00139                 config.setGroup( "Language" );
00140                 if ( lang. isEmpty ( ))
00141                         config. removeEntry ( "Language" );
00142                 else
00143                         config.writeEntry( "Language", lang );
00144                 config.write();
00145 
00146 #if defined(Q_WS_QWS) && !defined(QT_NO_COP)
00147 
00148                 QCopEnvelope e("QPE/System", "language(QString)");
00149                 e << lang;
00150 #endif
00151 
00152         }
00153 }
00154 
00155 void LanguageSettings::done(int r)
00156 {
00157         QDialog::done(r);
00158         close();
00159 }

Generated on Sat Nov 5 16:17:48 2005 for OPIE by  doxygen 1.4.2