|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbApps module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include <QSettings> |
|
26 #include <QStringList> |
|
27 #include <QDir> |
|
28 #include <QTimer> |
|
29 #include <hbinstance.h> |
|
30 #include <hbmenu.h> |
|
31 #include <hbaction.h> |
|
32 #include <hbicon.h> |
|
33 #include <hblistwidgetitem.h> |
|
34 #include <QDebug> |
|
35 #include <QTime> |
|
36 #include <QThread> |
|
37 |
|
38 #include "themeselectionlist.h" |
|
39 #include "themechangerdefs.h" |
|
40 |
|
41 /** |
|
42 * Constructor |
|
43 */ |
|
44 ThemeSelectionList::ThemeSelectionList( |
|
45 #ifdef Q_OS_SYMBIAN |
|
46 ThemeClientSymbian* client |
|
47 #else |
|
48 ThemeClientQt* client |
|
49 #endif |
|
50 ): |
|
51 oldItemIndex(-1), |
|
52 themelist(new HbListWidget(this)), |
|
53 rightMark(new HbIcon(QString("qtg_small_tick"))), |
|
54 noMark(new HbIcon(QString(""))), |
|
55 client(client) |
|
56 { |
|
57 connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *))); |
|
58 setWidget(themelist); |
|
59 |
|
60 // Automatic updation of the themelist when some theme is installed or uninstalled |
|
61 // when the hbthemechanger app is open |
|
62 watcher=new QFileSystemWatcher(); |
|
63 foreach(const QString &KThemeRootPath, rootPaths()) { |
|
64 if(!KThemeRootPath.contains("/romthemes")){ |
|
65 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
|
66 } |
|
67 } |
|
68 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
|
69 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
|
70 #ifdef THEME_CHANGER_TIMER_LOG |
|
71 idleTimer = new QTimer(this); |
|
72 connect(idleTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle())); |
|
73 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChanged())); |
|
74 idleTimer->start(0); // to make a connection to server |
|
75 #endif |
|
76 } |
|
77 |
|
78 /** |
|
79 * Destructor |
|
80 */ |
|
81 ThemeSelectionList::~ThemeSelectionList() |
|
82 { |
|
83 // Set the theme to the applied theme before exiting. |
|
84 setChosen(themelist->item(oldItemIndex)); |
|
85 delete noMark; |
|
86 |
|
87 noMark=NULL; |
|
88 delete rightMark; |
|
89 rightMark=NULL; |
|
90 |
|
91 // Reset the item view |
|
92 themelist->reset(); |
|
93 delete themelist; |
|
94 themelist=NULL; |
|
95 } |
|
96 |
|
97 |
|
98 /** |
|
99 * displayThemes |
|
100 */ |
|
101 void ThemeSelectionList::displayThemes() |
|
102 { |
|
103 bool entryAdded = false; |
|
104 bool themePresent = false; |
|
105 foreach(const QString &KThemeRootPath, rootPaths()){ |
|
106 dir.setPath(KThemeRootPath) ; |
|
107 QStringList list = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
|
108 if(list.contains("themes",Qt::CaseInsensitive )) { |
|
109 themePresent = true; |
|
110 QDir root = KThemeRootPath; |
|
111 dir.setPath(root.path()+"/themes/icons/") ; |
|
112 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
|
113 foreach(QString themefolder, iconthemeslist) { |
|
114 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder); |
|
115 if(iconThemePath.exists("index.theme")) { |
|
116 QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat); |
|
117 iniSetting.beginGroup("Icon Theme"); |
|
118 QString hidden = iniSetting.value("Hidden").toString(); |
|
119 QString name = iniSetting.value("Name").toString(); |
|
120 iniSetting.endGroup(); |
|
121 if((hidden == "true") ||( hidden == "")||(name!=themefolder) ) { |
|
122 iconthemeslist.removeOne(themefolder); |
|
123 } |
|
124 } |
|
125 else { |
|
126 iconthemeslist.removeOne(themefolder); |
|
127 } |
|
128 |
|
129 } |
|
130 if(!entryAdded){ |
|
131 iconthemeslist.insert(0,"hbdefault"); //adding one default entry |
|
132 entryAdded = true; |
|
133 } |
|
134 list=iconthemeslist; |
|
135 for (int i=0; i <list.count();i++) { |
|
136 // populate theme list with existing themes |
|
137 if((HbInstance::instance()->theme()->name())==(list.at(i))) { |
|
138 themelist->addItem(*rightMark,list.at(i)); |
|
139 oldItemIndex=themelist->count()-1; |
|
140 themelist->setCurrentRow(oldItemIndex); |
|
141 } |
|
142 else { |
|
143 themelist->addItem(*noMark,list.at(i)); |
|
144 } |
|
145 } |
|
146 } |
|
147 } |
|
148 // else{//add a case for no theme ,make hbdefault entry |
|
149 if(!themePresent) { |
|
150 QStringList defaultList; |
|
151 defaultList.insert(0,"hbdefault"); //adding one default entry |
|
152 themelist->addItem(*rightMark,defaultList.at(0)); |
|
153 QString themeName=HbInstance::instance()->theme()->name(); |
|
154 if (themeName != "hbdefault") |
|
155 { |
|
156 if (!client->isConnected()) { |
|
157 bool success = client->connectToServer(); |
|
158 if (success) { |
|
159 emit newThemeSelected("hbdefault"); |
|
160 } |
|
161 } |
|
162 else { |
|
163 emit newThemeSelected("hbdefault"); |
|
164 } |
|
165 } |
|
166 |
|
167 } |
|
168 } |
|
169 |
|
170 /** |
|
171 * setChosen |
|
172 */ |
|
173 void ThemeSelectionList::setChosen(HbListWidgetItem *item) |
|
174 { |
|
175 QString str=item->text(); |
|
176 |
|
177 #ifdef THEME_CHANGER_TRACES |
|
178 qDebug() << "ThemeSelectionList::Setchosen with ThemeName: "<<str; |
|
179 #endif |
|
180 if(iCurrentTheme != str ) { |
|
181 #ifdef THEME_CHANGER_TIMER_LOG |
|
182 timer.start(); |
|
183 qDebug() << "Selected theme: " << str; |
|
184 #endif |
|
185 iCurrentTheme = str; |
|
186 if (!client->isConnected()) { |
|
187 bool success = client->connectToServer(); |
|
188 if (success) { |
|
189 QThread::currentThread()->setPriority(QThread::HighPriority); |
|
190 emit newThemeSelected(str); |
|
191 } |
|
192 } |
|
193 else { |
|
194 QThread::currentThread()->setPriority(QThread::HighPriority); |
|
195 emit newThemeSelected(str); |
|
196 } |
|
197 } |
|
198 else |
|
199 { |
|
200 applySelection(); //double tap //put a tick |
|
201 } |
|
202 } |
|
203 |
|
204 |
|
205 /** |
|
206 * applySelection |
|
207 */ |
|
208 void ThemeSelectionList::applySelection() |
|
209 { |
|
210 if(oldItemIndex!=themelist->currentRow()) { |
|
211 themelist->setIcon(themelist->currentRow(),*rightMark); |
|
212 if(oldItemIndex >= 0) { |
|
213 themelist->setIcon(oldItemIndex,*noMark); |
|
214 } |
|
215 oldItemIndex = themelist->currentRow(); |
|
216 } |
|
217 } |
|
218 |
|
219 |
|
220 /** |
|
221 * event |
|
222 */ |
|
223 bool ThemeSelectionList::event(QEvent *e) |
|
224 { |
|
225 if((e->type()==QEvent::ShortcutOverride)||(e->type()==QEvent::WindowDeactivate)) { |
|
226 // save old applied theme |
|
227 themelist->setCurrentRow(oldItemIndex); |
|
228 themelist->setFocus(); |
|
229 setChosen(themelist->item(oldItemIndex)); |
|
230 return true; |
|
231 } |
|
232 return (HbView::event(e)); |
|
233 } |
|
234 |
|
235 /** |
|
236 * updateThemeList |
|
237 */ |
|
238 void ThemeSelectionList::updateThemeList(const QString &path) |
|
239 { |
|
240 Q_UNUSED(path); |
|
241 themelist->clear(); |
|
242 this->displayThemes(); |
|
243 } |
|
244 |
|
245 |
|
246 /** |
|
247 * sendThemeName |
|
248 */ |
|
249 void ThemeSelectionList::sendThemeName(const QString& name) |
|
250 { |
|
251 client->changeTheme(name); |
|
252 } |
|
253 |
|
254 /** |
|
255 * \internal |
|
256 */ |
|
257 QStringList ThemeSelectionList::rootPaths() |
|
258 { |
|
259 QStringList rootDirs; |
|
260 #if defined(Q_OS_SYMBIAN) |
|
261 rootDirs << "c:/resource/hb" |
|
262 << "z:/resource/hb" |
|
263 << "e:/resource/hb" |
|
264 << "f:/resource/hb"; |
|
265 #else |
|
266 QString envDir = qgetenv("HB_THEMES_DIR"); |
|
267 if (!envDir.isEmpty()) |
|
268 rootDirs << envDir; |
|
269 #endif |
|
270 #if defined(Q_OS_MAC) |
|
271 rootDirs << QDir::homePath() + "/Library/UI Extensions for Mobile"; |
|
272 #elif !defined(Q_OS_SYMBIAN) |
|
273 rootDirs << HB_RESOURCES_DIR; |
|
274 #endif |
|
275 return rootDirs; |
|
276 } |
|
277 |
|
278 #ifdef THEME_CHANGER_TIMER_LOG |
|
279 void ThemeSelectionList::processWhenIdle() |
|
280 { |
|
281 qDebug() << "Theme changed applied in " << timer.elapsed() << " msec"; |
|
282 idleTimer->stop(); |
|
283 QThread::currentThread()->setPriority(QThread::NormalPriority); |
|
284 if (!client->isConnected()) { |
|
285 client->connectToServer(); |
|
286 } |
|
287 } |
|
288 |
|
289 void ThemeSelectionList::themeChanged() |
|
290 { |
|
291 idleTimer->start(0); |
|
292 } |
|
293 #endif //THEME_CHANGER_TIMER_LOG |