author | sandman <sandman> | 2002-10-21 12:13:18 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-21 12:13:18 (UTC) |
commit | cdaf60fdf5dc19e88db4faa319daacfe4e879518 (patch) (unidiff) | |
tree | 39ef0f3b4505cddb7f7eca2f2a1b14528c937bf2 | |
parent | 3774660eaa50fe7adab39564ded7a2e1f296724b (diff) | |
download | opie-cdaf60fdf5dc19e88db4faa319daacfe4e879518.zip opie-cdaf60fdf5dc19e88db4faa319daacfe4e879518.tar.gz opie-cdaf60fdf5dc19e88db4faa319daacfe4e879518.tar.bz2 |
Language settings didn't let you de-select a language (i.e. if you have
opie-i18n-de, but NOT opie-i18n-en installed, you can't go back to english)
Now there's always a "English (default)" entry, as long as opie-i18n-en is
not installed.
-rw-r--r-- | noncore/settings/language/language.cpp | 124 |
1 files changed, 67 insertions, 57 deletions
diff --git a/noncore/settings/language/language.cpp b/noncore/settings/language/language.cpp index 397d372..5c4284b 100644 --- a/noncore/settings/language/language.cpp +++ b/noncore/settings/language/language.cpp | |||
@@ -13,138 +13,148 @@ | |||
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "settings.h" | 21 | #include "settings.h" |
22 | 22 | ||
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | #include <qpe/fontmanager.h> | 24 | #include <qpe/fontmanager.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
27 | #include <qpe/qpedialog.h> | 27 | #include <qpe/qpedialog.h> |
28 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 29 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
30 | #include <qpe/qcopenvelope_qws.h> | 30 | #include <qpe/qcopenvelope_qws.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qradiobutton.h> | 35 | #include <qradiobutton.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qslider.h> | 37 | #include <qslider.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | #include <qdatastream.h> | 40 | #include <qdatastream.h> |
41 | #include <qmessagebox.h> | 41 | #include <qmessagebox.h> |
42 | #include <qcombobox.h> | 42 | #include <qcombobox.h> |
43 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
44 | #include <qlistbox.h> | 44 | #include <qlistbox.h> |
45 | #include <qdir.h> | 45 | #include <qdir.h> |
46 | #if QT_VERSION >= 300 | 46 | #if QT_VERSION >= 300 |
47 | #include <qstylefactory.h> | 47 | #include <qstylefactory.h> |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 50 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #include <linux/fb.h> | 52 | #include <linux/fb.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
55 | #include <fcntl.h> | 55 | #include <fcntl.h> |
56 | #include <sys/ioctl.h> | 56 | #include <sys/ioctl.h> |
57 | #endif | 57 | #endif |
58 | #include <stdlib.h> | 58 | #include <stdlib.h> |
59 | 59 | ||
60 | 60 | ||
61 | LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl ) | 61 | LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl ) |
62 | : LanguageSettingsBase( parent, name, TRUE, fl ) | 62 | : LanguageSettingsBase( parent, name, TRUE, fl ) |
63 | { | 63 | { |
64 | if ( FontManager::hasUnicodeFont() ) | 64 | if ( FontManager::hasUnicodeFont() ) |
65 | languages->setFont(FontManager::unicodeFont(FontManager::Proportional)); | 65 | languages->setFont(FontManager::unicodeFont(FontManager::Proportional)); |
66 | 66 | ||
67 | QString tfn = QPEApplication::qpeDir()+"/i18n/"; | 67 | |
68 | QDir langDir = tfn; | 68 | QString tfn = QPEApplication::qpeDir() + "/i18n/"; |
69 | QStringList list = langDir.entryList("*", QDir::Dirs ); | 69 | QDir langDir = tfn; |
70 | 70 | QStringList list = langDir.entryList("*", QDir::Dirs ); | |
71 | QStringList::Iterator it; | 71 | |
72 | 72 | QStringList::Iterator it; | |
73 | for( it = list.begin(); it != list.end(); ++it ) { | 73 | |
74 | QString name = (*it); | 74 | for ( it = list.begin(); it != list.end(); ++it ) { |
75 | QFileInfo desktopFile( tfn + "/" + name + "/.directory" ); | 75 | QString name = (*it); |
76 | if( desktopFile.exists() ) { | 76 | QFileInfo desktopFile( tfn + "/" + name + "/.directory" ); |
77 | langAvail.append(name); | 77 | if ( desktopFile.exists() ) { |
78 | Config conf( desktopFile.filePath(), Config::File ); | 78 | langAvail.append(name); |
79 | QString langName = conf.readEntry( "Name" ); | 79 | Config conf( desktopFile.filePath(), Config::File ); |
80 | QString ownName = conf.readEntryDirect( "Name["+name+"]" ); | 80 | QString langName = conf.readEntry( "Name" ); |
81 | if ( ownName.isEmpty() ) | 81 | QString ownName = conf.readEntryDirect( "Name[" + name + "]" ); |
82 | ownName = conf.readEntryDirect( "Name" ); | 82 | if ( ownName.isEmpty() ) |
83 | if ( !ownName.isEmpty() && ownName != langName ) | 83 | ownName = conf.readEntryDirect( "Name" ); |
84 | langName = langName + " [" + ownName + "]"; | 84 | if ( !ownName.isEmpty() && ownName != langName ) |
85 | languages->insertItem( langName ); | 85 | langName = langName + " [" + ownName + "]"; |
86 | 86 | languages->insertItem( langName ); | |
87 | |||
88 | } | ||
87 | } | 89 | } |
88 | } | 90 | if ( langAvail. find ( "en" ) == -1 ) { |
89 | 91 | langAvail. prepend ( "" ); // no tr | |
90 | dl = new QPEDialogListener(this); | 92 | languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 ); |
91 | reset(); | 93 | } |
94 | |||
95 | dl = new QPEDialogListener(this); | ||
96 | reset(); | ||
92 | } | 97 | } |
93 | 98 | ||
94 | LanguageSettings::~LanguageSettings() | 99 | LanguageSettings::~LanguageSettings() |
95 | { | 100 | {} |
96 | } | ||
97 | 101 | ||
98 | void LanguageSettings::accept() | 102 | void LanguageSettings::accept() |
99 | { | 103 | { |
100 | applyLanguage(); | 104 | applyLanguage(); |
101 | QDialog::accept(); | 105 | QDialog::accept(); |
102 | } | 106 | } |
103 | 107 | ||
104 | void LanguageSettings::applyLanguage() | 108 | void LanguageSettings::applyLanguage() |
105 | { | 109 | { |
106 | QString lang = langAvail.at( languages->currentItem() ); | 110 | setLanguage ( langAvail. at ( languages-> currentItem ( ))); |
107 | setLanguage( lang ); | ||
108 | } | 111 | } |
109 | 112 | ||
110 | 113 | ||
111 | void LanguageSettings::reject() | 114 | void LanguageSettings::reject() |
112 | { | 115 | { |
113 | reset(); | 116 | reset(); |
114 | QDialog::reject(); | 117 | QDialog::reject(); |
115 | } | 118 | } |
116 | 119 | ||
117 | void LanguageSettings::reset() | 120 | void LanguageSettings::reset() |
118 | { | 121 | { |
119 | QString l = getenv("LANG"); | 122 | QString l = getenv("LANG"); |
120 | Config config("language"); | 123 | Config config("locale"); |
121 | l = config.readEntry( "Language", l ); | 124 | config.setGroup("Language"); |
122 | if(l.isEmpty()) l = "en"; | 125 | l = config.readEntry( "Language", l ); |
123 | actualLanguage = l; | 126 | if (l.isEmpty()) |
124 | 127 | l = "en"; | |
125 | int n = langAvail.find( l ); | 128 | actualLanguage = l; |
126 | languages->setCurrentItem( n ); | 129 | |
130 | int n = langAvail.find( l ); | ||
131 | languages->setCurrentItem( n ); | ||
127 | } | 132 | } |
128 | 133 | ||
129 | QString LanguageSettings::actualLanguage; | 134 | QString LanguageSettings::actualLanguage; |
130 | 135 | ||
131 | void LanguageSettings::setLanguage(const QString& lang) | 136 | void LanguageSettings::setLanguage(const QString& lang) |
132 | { | 137 | { |
133 | if( lang != actualLanguage ) { | 138 | if ( lang != actualLanguage ) { |
134 | Config config("locale"); | 139 | Config config("locale"); |
135 | config.setGroup( "Language" ); | 140 | config.setGroup( "Language" ); |
136 | config.writeEntry( "Language", lang ); | 141 | if ( lang. isEmpty ( )) |
137 | config.write(); | 142 | config. removeEntry ( "Language" ); |
138 | 143 | else | |
144 | config.writeEntry( "Language", lang ); | ||
145 | config.write(); | ||
146 | |||
139 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 147 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
140 | QCopEnvelope e("QPE/System","language(QString)"); | 148 | |
141 | e << lang; | 149 | QCopEnvelope e("QPE/System", "language(QString)"); |
150 | e << lang; | ||
142 | #endif | 151 | #endif |
143 | } | 152 | |
153 | } | ||
144 | } | 154 | } |
145 | 155 | ||
146 | void LanguageSettings::done(int r) | 156 | void LanguageSettings::done(int r) |
147 | { | 157 | { |
148 | QDialog::done(r); | 158 | QDialog::done(r); |
149 | close(); | 159 | close(); |
150 | } | 160 | } |