Diffstat (limited to 'noncore/settings/language/language.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/language/language.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/noncore/settings/language/language.cpp b/noncore/settings/language/language.cpp new file mode 100644 index 0000000..397d372 --- a/dev/null +++ b/noncore/settings/language/language.cpp | |||
@@ -0,0 +1,150 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "settings.h" | ||
22 | |||
23 | #include <qpe/global.h> | ||
24 | #include <qpe/fontmanager.h> | ||
25 | #include <qpe/config.h> | ||
26 | #include <qpe/applnk.h> | ||
27 | #include <qpe/qpedialog.h> | ||
28 | #include <qpe/qpeapplication.h> | ||
29 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
30 | #include <qpe/qcopenvelope_qws.h> | ||
31 | #endif | ||
32 | |||
33 | #include <qlabel.h> | ||
34 | #include <qcheckbox.h> | ||
35 | #include <qradiobutton.h> | ||
36 | #include <qtabwidget.h> | ||
37 | #include <qslider.h> | ||
38 | #include <qfile.h> | ||
39 | #include <qtextstream.h> | ||
40 | #include <qdatastream.h> | ||
41 | #include <qmessagebox.h> | ||
42 | #include <qcombobox.h> | ||
43 | #include <qspinbox.h> | ||
44 | #include <qlistbox.h> | ||
45 | #include <qdir.h> | ||
46 | #if QT_VERSION >= 300 | ||
47 | #include <qstylefactory.h> | ||
48 | #endif | ||
49 | |||
50 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | ||
51 | #include <unistd.h> | ||
52 | #include <linux/fb.h> | ||
53 | #include <sys/types.h> | ||
54 | #include <sys/stat.h> | ||
55 | #include <fcntl.h> | ||
56 | #include <sys/ioctl.h> | ||
57 | #endif | ||
58 | #include <stdlib.h> | ||
59 | |||
60 | |||
61 | LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl ) | ||
62 | : LanguageSettingsBase( parent, name, TRUE, fl ) | ||
63 | { | ||
64 | if ( FontManager::hasUnicodeFont() ) | ||
65 | languages->setFont(FontManager::unicodeFont(FontManager::Proportional)); | ||
66 | |||
67 | QString tfn = QPEApplication::qpeDir()+"/i18n/"; | ||
68 | QDir langDir = tfn; | ||
69 | QStringList list = langDir.entryList("*", QDir::Dirs ); | ||
70 | |||
71 | QStringList::Iterator it; | ||
72 | |||
73 | for( it = list.begin(); it != list.end(); ++it ) { | ||
74 | QString name = (*it); | ||
75 | QFileInfo desktopFile( tfn + "/" + name + "/.directory" ); | ||
76 | if( desktopFile.exists() ) { | ||
77 | langAvail.append(name); | ||
78 | Config conf( desktopFile.filePath(), Config::File ); | ||
79 | QString langName = conf.readEntry( "Name" ); | ||
80 | QString ownName = conf.readEntryDirect( "Name["+name+"]" ); | ||
81 | if ( ownName.isEmpty() ) | ||
82 | ownName = conf.readEntryDirect( "Name" ); | ||
83 | if ( !ownName.isEmpty() && ownName != langName ) | ||
84 | langName = langName + " [" + ownName + "]"; | ||
85 | languages->insertItem( langName ); | ||
86 | |||
87 | } | ||
88 | } | ||
89 | |||
90 | dl = new QPEDialogListener(this); | ||
91 | reset(); | ||
92 | } | ||
93 | |||
94 | LanguageSettings::~LanguageSettings() | ||
95 | { | ||
96 | } | ||
97 | |||
98 | void LanguageSettings::accept() | ||
99 | { | ||
100 | applyLanguage(); | ||
101 | QDialog::accept(); | ||
102 | } | ||
103 | |||
104 | void LanguageSettings::applyLanguage() | ||
105 | { | ||
106 | QString lang = langAvail.at( languages->currentItem() ); | ||
107 | setLanguage( lang ); | ||
108 | } | ||
109 | |||
110 | |||
111 | void LanguageSettings::reject() | ||
112 | { | ||
113 | reset(); | ||
114 | QDialog::reject(); | ||
115 | } | ||
116 | |||
117 | void LanguageSettings::reset() | ||
118 | { | ||
119 | QString l = getenv("LANG"); | ||
120 | Config config("language"); | ||
121 | l = config.readEntry( "Language", l ); | ||
122 | if(l.isEmpty()) l = "en"; | ||
123 | actualLanguage = l; | ||
124 | |||
125 | int n = langAvail.find( l ); | ||
126 | languages->setCurrentItem( n ); | ||
127 | } | ||
128 | |||
129 | QString LanguageSettings::actualLanguage; | ||
130 | |||
131 | void LanguageSettings::setLanguage(const QString& lang) | ||
132 | { | ||
133 | if( lang != actualLanguage ) { | ||
134 | Config config("locale"); | ||
135 | config.setGroup( "Language" ); | ||
136 | config.writeEntry( "Language", lang ); | ||
137 | config.write(); | ||
138 | |||
139 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
140 | QCopEnvelope e("QPE/System","language(QString)"); | ||
141 | e << lang; | ||
142 | #endif | ||
143 | } | ||
144 | } | ||
145 | |||
146 | void LanguageSettings::done(int r) | ||
147 | { | ||
148 | QDialog::done(r); | ||
149 | close(); | ||
150 | } | ||