30 #include <hbmenu.h> |
30 #include <hbmenu.h> |
31 #include <hbaction.h> |
31 #include <hbaction.h> |
32 #include <hbicon.h> |
32 #include <hbicon.h> |
33 #include <hblistwidgetitem.h> |
33 #include <hblistwidgetitem.h> |
34 #include <restricted/hbthemeservices_r.h> |
34 #include <restricted/hbthemeservices_r.h> |
|
35 #include <hblabel.h> |
|
36 #include <hbiconitem.h> |
|
37 #include <hbtoolbar.h> |
35 #include <QDebug> |
38 #include <QDebug> |
36 #include <QTime> |
39 #include <QTime> |
37 #include <QThread> |
40 #include <QThread> |
|
41 #include <QGesture> |
|
42 #include <QGraphicsLinearLayout> |
38 |
43 |
39 #include "themeselectionlist.h" |
44 #include "themeselectionlist.h" |
40 #include "themechangerdefs.h" |
45 #include "themechangerdefs.h" |
41 |
46 |
|
47 class PreviewView : public HbView |
|
48 { |
|
49 public: |
|
50 |
|
51 PreviewView(const QString &name, const QString &theme, QGraphicsItem* parent=0): |
|
52 HbView(parent), preview(0), themePath(theme) |
|
53 { |
|
54 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
55 HbLabel *label = new HbLabel(tr("Apply theme %1?").arg(name)); |
|
56 label->setFontSpec(HbFontSpec(HbFontSpec::Primary)); |
|
57 label->setElideMode(Qt::ElideNone); |
|
58 layout->addItem(label); |
|
59 QString previewPath(""); |
|
60 if (HbDeviceProfile::profile(this).orientation() == Qt::Horizontal) { |
|
61 previewPath = themePath + "/scalable/qtg_graf_theme_preview_lsc."; |
|
62 } else { |
|
63 previewPath = themePath + "/scalable/qtg_graf_theme_preview_prt."; |
|
64 } |
|
65 QString nvgPreview(previewPath + "nvg"); |
|
66 QString svgPreview(previewPath + "svg"); |
|
67 |
|
68 if (QFile::exists(nvgPreview)) { |
|
69 previewPath = nvgPreview; |
|
70 } else if (QFile::exists(svgPreview)) { |
|
71 previewPath = svgPreview; |
|
72 } else { |
|
73 previewPath = "qtg_large_corrupted"; |
|
74 } |
|
75 preview = new HbIconItem(previewPath); |
|
76 preview->setAspectRatioMode(Qt::KeepAspectRatio); |
|
77 QSize s = HbDeviceProfile::profile(this).logicalSize(); |
|
78 preview->setPreferredSize(s); |
|
79 layout->addItem(preview); |
|
80 this->setLayout(layout); |
|
81 } |
|
82 |
|
83 ~PreviewView() |
|
84 { |
|
85 delete preview; |
|
86 } |
|
87 |
|
88 void resizeEvent(QGraphicsSceneResizeEvent *event) |
|
89 { |
|
90 Q_UNUSED(event); |
|
91 if (preview) { |
|
92 QString previewPath(""); |
|
93 if (HbDeviceProfile::profile(this).orientation() == Qt::Horizontal) { |
|
94 previewPath = themePath + "/scalable/qtg_graf_theme_preview_lsc."; |
|
95 } else { |
|
96 previewPath = themePath + "/scalable/qtg_graf_theme_preview_prt."; |
|
97 } |
|
98 QString nvgPreview(previewPath + "nvg"); |
|
99 QString svgPreview(previewPath + "svg"); |
|
100 |
|
101 if (QFile::exists(nvgPreview)) { |
|
102 previewPath = nvgPreview; |
|
103 } else if (QFile::exists(svgPreview)) { |
|
104 previewPath = svgPreview; |
|
105 } else { |
|
106 previewPath = "qtg_large_corrupted"; |
|
107 } |
|
108 |
|
109 preview->setIconName(previewPath); |
|
110 preview->setAspectRatioMode(Qt::KeepAspectRatio); |
|
111 QSize s = HbDeviceProfile::profile(this).logicalSize(); |
|
112 preview->setPreferredSize(s); |
|
113 } |
|
114 } |
|
115 private: |
|
116 HbIconItem *preview; |
|
117 QString themePath; |
|
118 }; |
|
119 |
42 /** |
120 /** |
43 * Constructor |
121 * Constructor |
44 */ |
122 */ |
45 ThemeSelectionList::ThemeSelectionList(): |
123 ThemeSelectionList::ThemeSelectionList(HbMainWindow *mainWindow): |
46 oldItemIndex(-1), |
124 oldItemIndex(-1), |
47 themelist(new HbListWidget(this)), |
125 themelist(new HbListWidget(this)), |
48 rightMark(new HbIcon(QString("qtg_small_tick"))), |
126 rightMark(new HbIcon(QString("qtg_small_tick"))), |
49 noMark(new HbIcon(QString(""))) |
127 noMark(new HbIcon(QString(""))), |
50 { |
128 previewView(0) |
|
129 { |
|
130 mMainWindow = mainWindow; |
51 connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *))); |
131 connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *))); |
|
132 connect(themelist, SIGNAL(longPressed(HbListWidgetItem*, QPointF)), |
|
133 this, SLOT(onLongPressed(HbListWidgetItem*, QPointF))); |
|
134 |
52 setWidget(themelist); |
135 setWidget(themelist); |
53 |
136 |
54 // Automatic updation of the themelist when some theme is installed or uninstalled |
137 // Automatic updation of the themelist when some theme is installed or uninstalled |
55 // when the hbthemechanger app is open |
138 // when the hbthemechanger app is open |
56 watcher=new QFileSystemWatcher(); |
139 watcher=new QFileSystemWatcher(); |
58 if(!KThemeRootPath.contains("/romthemes")){ |
141 if(!KThemeRootPath.contains("/romthemes")){ |
59 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
142 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
60 } |
143 } |
61 } |
144 } |
62 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
145 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
63 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
146 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
|
147 grabGesture(Qt::TapAndHoldGesture); |
64 #ifdef THEME_CHANGER_TIMER_LOG |
148 #ifdef THEME_CHANGER_TIMER_LOG |
65 idleTimer = new QTimer(this); |
149 idleTimer = new QTimer(this); |
66 connect(idleTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle())); |
150 connect(idleTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle())); |
67 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChanged())); |
151 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChanged())); |
68 idleTimer->start(0); // to make a connection to server |
152 idleTimer->start(0); // to make a connection to server |
107 QDir root = KThemeRootPath; |
191 QDir root = KThemeRootPath; |
108 dir.setPath(root.path()+"/themes/icons/") ; |
192 dir.setPath(root.path()+"/themes/icons/") ; |
109 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
193 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
110 foreach(QString themefolder, iconthemeslist) { |
194 foreach(QString themefolder, iconthemeslist) { |
111 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder); |
195 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder); |
112 if(iconThemePath.exists("index.theme")) { |
196 QFile themeIndexFile(root.path()+"/themes/"+themefolder+".themeindex"); |
|
197 if(themeIndexFile.exists() && iconThemePath.exists("index.theme")) { |
113 QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat); |
198 QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat); |
114 iniSetting.beginGroup("Icon Theme"); |
199 iniSetting.beginGroup("Icon Theme"); |
115 QString hidden = iniSetting.value("Hidden").toString(); |
200 QString hidden = iniSetting.value("Hidden").toString(); |
116 iniSetting.endGroup(); |
201 iniSetting.endGroup(); |
117 if((hidden == "true") ||( hidden == "")) { |
202 if((hidden == "true") ||( hidden == "")) { |
127 //adding one default entry |
212 //adding one default entry |
128 HbListWidgetItem *item = new HbListWidgetItem(); |
213 HbListWidgetItem *item = new HbListWidgetItem(); |
129 item->setText("hbdefault"); |
214 item->setText("hbdefault"); |
130 item->setSecondaryText("hbdefault"); |
215 item->setSecondaryText("hbdefault"); |
131 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
216 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
|
217 if (!QFile::exists(thumbPath)) { |
|
218 thumbPath = "qtg_large_corrupted"; |
|
219 } |
132 HbIcon *icon = new HbIcon(thumbPath); |
220 HbIcon *icon = new HbIcon(thumbPath); |
133 thumbnails.append(icon); |
221 thumbnails.append(icon); |
134 item->setIcon(*icon); |
222 item->setIcon(*icon); |
135 if (HbInstance::instance()->theme()->name() == "hbdefault") { |
223 if (HbInstance::instance()->theme()->name() == "hbdefault") { |
136 item->setSecondaryIcon(*rightMark); |
224 item->setSecondaryIcon(*rightMark); |
153 QString name = iniSetting.value("Name").toString(); |
241 QString name = iniSetting.value("Name").toString(); |
154 iniSetting.endGroup(); |
242 iniSetting.endGroup(); |
155 item->setText(name); |
243 item->setText(name); |
156 |
244 |
157 item->setSecondaryText(root.path()+"/themes/icons/"+list.at(i)); |
245 item->setSecondaryText(root.path()+"/themes/icons/"+list.at(i)); |
158 QString thumbPath(root.path()+"/themes/icons/"+list.at(i)+"/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
246 QString thumbPath(root.path()+"/themes/icons/"+list.at(i)+"/scalable/qtg_graf_theme_preview_thumbnail."); |
|
247 QString nvgPath(thumbPath + "nvg"); |
|
248 QString svgPath(thumbPath + "svg"); |
|
249 if (QFile::exists(nvgPath)) { |
|
250 thumbPath = nvgPath; |
|
251 } else if (QFile::exists(svgPath)) { |
|
252 thumbPath = svgPath; |
|
253 } |
|
254 else { |
|
255 thumbPath = "qtg_large_corrupted"; |
|
256 } |
159 HbIcon *icon = new HbIcon(thumbPath); |
257 HbIcon *icon = new HbIcon(thumbPath); |
160 thumbnails.append(icon); |
258 thumbnails.append(icon); |
161 item->setIcon(*icon); |
259 item->setIcon(*icon); |
162 |
260 |
163 |
261 |
180 defaultList.insert(0,"hbdefault"); //adding one default entry |
278 defaultList.insert(0,"hbdefault"); //adding one default entry |
181 HbListWidgetItem *item = new HbListWidgetItem(); |
279 HbListWidgetItem *item = new HbListWidgetItem(); |
182 item->setText(defaultList.at(0)); |
280 item->setText(defaultList.at(0)); |
183 item->setSecondaryText(defaultList.at(0)); |
281 item->setSecondaryText(defaultList.at(0)); |
184 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
282 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg"); |
|
283 if (!QFile::exists(thumbPath)) { |
|
284 thumbPath = "qtg_large_corrupted"; |
|
285 } |
185 HbIcon *icon = new HbIcon(thumbPath); |
286 HbIcon *icon = new HbIcon(thumbPath); |
186 thumbnails.append(icon); |
287 thumbnails.append(icon); |
187 item->setIcon(*icon); |
288 item->setIcon(*icon); |
188 item->setSecondaryIcon(*rightMark); |
289 item->setSecondaryIcon(*rightMark); |
189 themelist->addItem(item); |
290 themelist->addItem(item); |
292 rootDirs << HB_RESOURCES_DIR; |
377 rootDirs << HB_RESOURCES_DIR; |
293 #endif |
378 #endif |
294 return rootDirs; |
379 return rootDirs; |
295 } |
380 } |
296 |
381 |
|
382 void ThemeSelectionList::onLongPressed(HbListWidgetItem* listViewItem, const QPointF& coords) |
|
383 { |
|
384 Q_UNUSED(coords); |
|
385 if (previewView) { |
|
386 delete previewView; |
|
387 previewView = 0; |
|
388 } |
|
389 previewItem = listViewItem; |
|
390 QString theme; |
|
391 if (listViewItem->secondaryText() != "hbdefault") { |
|
392 theme = listViewItem->secondaryText(); |
|
393 } else { |
|
394 theme = ":/themes/icons/hbdefault"; |
|
395 } |
|
396 previewView = new PreviewView(listViewItem->text(), theme, this); |
|
397 mMainWindow->addView(previewView); |
|
398 |
|
399 HbAction *act = new HbAction(tr("Ok")); |
|
400 connect(act, SIGNAL(triggered()), this, SLOT(applyTheme())); |
|
401 previewView->toolBar()->addAction(act); |
|
402 act = new HbAction(tr("Cancel")); |
|
403 connect(act, SIGNAL(triggered()), this, SLOT(cancelTheme())); |
|
404 previewView->toolBar()->addAction(act); |
|
405 |
|
406 mMainWindow->setCurrentView(previewView); |
|
407 } |
|
408 |
|
409 void ThemeSelectionList::cancelTheme() |
|
410 { |
|
411 mMainWindow->removeView(mMainWindow->currentView()); |
|
412 } |
|
413 |
|
414 void ThemeSelectionList::applyTheme() |
|
415 { |
|
416 if (previewItem) { |
|
417 setChosen(previewItem); |
|
418 applySelection(); |
|
419 } |
|
420 mMainWindow->removeView(mMainWindow->currentView()); |
|
421 } |
|
422 |
297 #ifdef THEME_CHANGER_TIMER_LOG |
423 #ifdef THEME_CHANGER_TIMER_LOG |
298 void ThemeSelectionList::processWhenIdle() |
424 void ThemeSelectionList::processWhenIdle() |
299 { |
425 { |
300 qDebug() << "Theme changed applied in " << timer.elapsed() << " msec"; |
426 qDebug() << "Theme changed applied in " << timer.elapsed() << " msec"; |
301 idleTimer->stop(); |
427 idleTimer->stop(); |