138 setWidget(themelist); |
138 setWidget(themelist); |
139 |
139 |
140 // Automatic updation of the themelist when some theme is installed or uninstalled |
140 // Automatic updation of the themelist when some theme is installed or uninstalled |
141 // when the hbthemechanger app is open |
141 // when the hbthemechanger app is open |
142 watcher=new QFileSystemWatcher(); |
142 watcher=new QFileSystemWatcher(); |
143 foreach(const QString &KThemeRootPath, rootPaths()) { |
143 foreach(const QString &themePath, themePaths()) { |
144 if(!KThemeRootPath.contains("/romthemes")){ |
144 watcher->addPath(themePath); |
145 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
|
146 } |
|
147 } |
145 } |
148 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
146 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
149 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
147 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
150 grabGesture(Qt::TapAndHoldGesture); |
148 grabGesture(Qt::TapAndHoldGesture); |
151 |
149 |
189 /** |
187 /** |
190 * displayThemes |
188 * displayThemes |
191 */ |
189 */ |
192 void ThemeSelectionList::displayThemes() |
190 void ThemeSelectionList::displayThemes() |
193 { |
191 { |
194 rootThemes.clear(); |
192 QList<QPair<QString, QString> > themes; |
195 bool entryAdded = false; |
193 |
196 bool themePresent = false; |
194 // First add default entry |
197 foreach(const QString &KThemeRootPath, rootPaths()){ |
195 themes.append(QPair<QString,QString>("hbdefault", ":/themes/icons/hbdefault")); |
198 dir.setPath(KThemeRootPath) ; |
196 // And then rest of the themes |
199 QStringList list = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
197 themes.append(HbThemeServices::availableThemes()); |
200 if(list.contains("themes",Qt::CaseInsensitive )) { |
198 |
201 themePresent = true; |
199 for (int i=0; i <themes.count();i++) { |
202 QDir root = KThemeRootPath; |
200 // populate theme list with existing themes |
203 dir.setPath(root.path()+"/themes/icons/") ; |
201 HbListWidgetItem *item = new HbListWidgetItem(); |
204 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
202 item->setText(themes.at(i).first); |
205 foreach(QString themefolder, iconthemeslist) { |
203 item->setSecondaryText(themes.at(i).second); |
206 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder); |
204 |
207 QFile themeIndexFile(root.path()+"/themes/"+themefolder+".themeindex"); |
205 QString thumbPath(themes.at(i).second+"/scalable/qtg_graf_theme_preview_thumbnail."); |
208 if(themeIndexFile.exists() && iconThemePath.exists("index.theme")) { |
206 QString nvgPath(thumbPath + "nvg"); |
209 QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat); |
207 QString svgPath(thumbPath + "svg"); |
210 iniSetting.beginGroup("Icon Theme"); |
208 if (QFile::exists(nvgPath)) { |
211 QString hidden = iniSetting.value("Hidden").toString(); |
209 thumbPath = nvgPath; |
212 iniSetting.endGroup(); |
210 } else if (QFile::exists(svgPath)) { |
213 if((hidden == "true") ||( hidden == "")) { |
211 thumbPath = svgPath; |
214 iconthemeslist.removeOne(themefolder); |
212 } |
215 } |
213 else { |
216 #ifdef Q_OS_SYMBIAN |
214 thumbPath = "qtg_large_corrupted"; |
217 if (KThemeRootPath[0] == 'z') { |
215 } |
218 #endif |
216 HbIcon *icon = new HbIcon(thumbPath); |
219 rootThemes.append(iconThemePath.absolutePath()); |
217 thumbnails.append(icon); |
220 #ifdef Q_OS_SYMBIAN |
218 item->setIcon(*icon); |
221 } |
219 |
222 #endif |
220 |
223 |
221 if (QFileInfo(HbThemeServices::themePath()) == QFileInfo(item->secondaryText())) { |
224 } |
|
225 else { |
|
226 iconthemeslist.removeOne(themefolder); |
|
227 } |
|
228 |
|
229 } |
|
230 if(!entryAdded){ |
|
231 rootThemes.append(":/themes/icons/hbdefault"); |
|
232 //adding one default entry |
|
233 HbListWidgetItem *item = new HbListWidgetItem(); |
|
234 item->setText("hbdefault"); |
|
235 item->setSecondaryText(":/themes/icons/hbdefault"); |
|
236 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
|
237 if (!QFile::exists(thumbPath)) { |
|
238 thumbPath = "qtg_large_corrupted"; |
|
239 } |
|
240 HbIcon *icon = new HbIcon(thumbPath); |
|
241 thumbnails.append(icon); |
|
242 item->setIcon(*icon); |
|
243 if (HbInstance::instance()->theme()->name() == "hbdefault") { |
|
244 item->setSecondaryIcon(*rightMark); |
|
245 themelist->addItem(item); |
|
246 themelist->setCurrentRow(themelist->count()-1); |
|
247 } else { |
|
248 item->setSecondaryIcon(*noMark); |
|
249 themelist->addItem(item); |
|
250 } |
|
251 entryAdded = true; |
|
252 } |
|
253 list=iconthemeslist; |
|
254 for (int i=0; i <list.count();i++) { |
|
255 // populate theme list with existing themes |
|
256 HbListWidgetItem *item = new HbListWidgetItem(); |
|
257 |
|
258 QSettings iniSetting(root.path()+"/themes/icons/"+list.at(i)+"/index.theme",QSettings::IniFormat); |
|
259 iniSetting.beginGroup("Icon Theme"); |
|
260 QString name = iniSetting.value("Name").toString(); |
|
261 iniSetting.endGroup(); |
|
262 item->setText(name); |
|
263 |
|
264 item->setSecondaryText(root.path()+"/themes/icons/"+list.at(i)); |
|
265 QString thumbPath(root.path()+"/themes/icons/"+list.at(i)+"/scalable/qtg_graf_theme_preview_thumbnail."); |
|
266 QString nvgPath(thumbPath + "nvg"); |
|
267 QString svgPath(thumbPath + "svg"); |
|
268 if (QFile::exists(nvgPath)) { |
|
269 thumbPath = nvgPath; |
|
270 } else if (QFile::exists(svgPath)) { |
|
271 thumbPath = svgPath; |
|
272 } |
|
273 else { |
|
274 thumbPath = "qtg_large_corrupted"; |
|
275 } |
|
276 HbIcon *icon = new HbIcon(thumbPath); |
|
277 thumbnails.append(icon); |
|
278 item->setIcon(*icon); |
|
279 |
|
280 |
|
281 if (QFileInfo(HbThemeServices::themePath()) == QFileInfo(item->secondaryText())) { |
|
282 item->setSecondaryIcon(*rightMark); |
|
283 themelist->addItem(item); |
|
284 themelist->setCurrentRow(themelist->count()-1); |
|
285 } |
|
286 else { |
|
287 item->setSecondaryIcon(*noMark); |
|
288 themelist->addItem(item); |
|
289 } |
|
290 } |
|
291 } |
|
292 } |
|
293 // else{//add a case for no theme ,make hbdefault entry |
|
294 if(!themePresent) { |
|
295 rootThemes.append(":/themes/icons/hbdefault"); |
|
296 //adding one default entry |
|
297 HbListWidgetItem *item = new HbListWidgetItem(); |
|
298 item->setText("hbdefault"); |
|
299 item->setSecondaryText(":/themes/icons/hbdefault"); |
|
300 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
|
301 if (!QFile::exists(thumbPath)) { |
|
302 thumbPath = "qtg_large_corrupted"; |
|
303 } |
|
304 HbIcon *icon = new HbIcon(thumbPath); |
|
305 thumbnails.append(icon); |
|
306 item->setIcon(*icon); |
|
307 item->setSecondaryIcon(*rightMark); |
222 item->setSecondaryIcon(*rightMark); |
308 themelist->addItem(item); |
223 themelist->addItem(item); |
309 QString themeName=HbInstance::instance()->theme()->name(); |
224 themelist->setCurrentRow(themelist->count()-1); |
310 if (themeName != "hbdefault") |
225 } |
311 { |
226 else { |
312 emit newThemeSelected(":/themes/icons/hbdefault"); |
227 item->setSecondaryIcon(*noMark); |
313 } |
228 themelist->addItem(item); |
314 } |
229 } |
|
230 } |
315 } |
231 } |
316 |
232 |
317 /** |
233 /** |
318 * setChosen |
234 * setChosen |
319 */ |
235 */ |
357 */ |
273 */ |
358 QStringList ThemeSelectionList::rootPaths() |
274 QStringList ThemeSelectionList::rootPaths() |
359 { |
275 { |
360 QStringList rootDirs; |
276 QStringList rootDirs; |
361 #if defined(Q_OS_SYMBIAN) |
277 #if defined(Q_OS_SYMBIAN) |
362 rootDirs << "z:/resource/hb" |
278 rootDirs << "z:/resource/hb/themes"; |
363 << "c:/resource/hb" |
|
364 << "e:/resource/hb" |
|
365 << "f:/resource/hb"; |
|
366 #else |
279 #else |
367 QString envDir = qgetenv("HB_THEMES_DIR"); |
280 QString envDir = QDir::fromNativeSeparators(qgetenv("HB_THEMES_DIR")); |
368 if (!envDir.isEmpty()) |
281 if (!envDir.isEmpty()) |
369 rootDirs << envDir; |
282 rootDirs << envDir + "/themes"; |
370 #endif |
283 #endif |
371 #if defined(Q_OS_MAC) |
284 rootDirs << ":/themes"; |
372 rootDirs << QDir::homePath() + "/Library/UI Extensions for Mobile"; |
285 return rootDirs; |
373 #elif !defined(Q_OS_SYMBIAN) |
286 } |
374 rootDirs << HB_RESOURCES_DIR; |
287 |
|
288 void ThemeSelectionList::updateRootThemes() |
|
289 { |
|
290 QDir dir; |
|
291 mRootThemes.clear(); |
|
292 foreach(const QString &rootPath, rootPaths()){ |
|
293 dir.setPath(rootPath+"/icons"); |
|
294 QStringList iconthemeslist = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
|
295 foreach(const QString &themefolder, iconthemeslist) { |
|
296 QDir iconThemePath(dir.path()+'/'+themefolder); |
|
297 QFile themeIndexFile(rootPath+'/'+themefolder+".themeindex"); |
|
298 if(themeIndexFile.exists() && iconThemePath.exists("index.theme")) { |
|
299 mRootThemes.append(iconThemePath.absolutePath()); |
|
300 } |
|
301 } |
|
302 } |
|
303 } |
|
304 |
|
305 QStringList ThemeSelectionList::themePaths() |
|
306 { |
|
307 QStringList themeDirs; |
|
308 #if defined(Q_OS_SYMBIAN) |
|
309 themeDirs << "z:/resource/hb/themes" |
|
310 << "c:/resource/hb/themes" |
|
311 << "e:/resource/hb/themes" |
|
312 << "f:/resource/hb/themes"; |
|
313 #else |
|
314 QString envDir = QDir::fromNativeSeparators(qgetenv("HB_THEMES_DIR")); |
|
315 if (!envDir.isEmpty()) { |
|
316 themeDirs << envDir + "/themes"; |
|
317 } |
375 #endif |
318 #endif |
376 return rootDirs; |
319 return themeDirs; |
377 } |
320 } |
378 |
321 |
379 void ThemeSelectionList::onLongPressed(HbListWidgetItem* listViewItem, const QPointF& coords) |
322 void ThemeSelectionList::onLongPressed(HbListWidgetItem* listViewItem, const QPointF& coords) |
380 { |
323 { |
381 Q_UNUSED(coords); |
324 Q_UNUSED(coords); |