23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 #include <QSettings> |
25 #include <QSettings> |
26 #include <QStringList> |
26 #include <QStringList> |
27 #include <QDir> |
27 #include <QDir> |
|
28 #include <QTimer> |
28 #include <hbinstance.h> |
29 #include <hbinstance.h> |
29 #include <hbmenu.h> |
30 #include <hbmenu.h> |
30 #include <hbaction.h> |
31 #include <hbaction.h> |
31 #include <hbicon.h> |
32 #include <hbicon.h> |
|
33 #include <hblistwidgetitem.h> |
32 #include <QDebug> |
34 #include <QDebug> |
|
35 #include <QTime> |
33 |
36 |
34 #include "themeselectionlist.h" |
37 #include "themeselectionlist.h" |
35 #include "themechangerdefs.h" |
38 #include "themechangerdefs.h" |
36 |
39 |
37 /** |
40 /** |
42 ThemeClientSymbian* client |
45 ThemeClientSymbian* client |
43 #else |
46 #else |
44 ThemeClientQt* client |
47 ThemeClientQt* client |
45 #endif |
48 #endif |
46 ): |
49 ): |
47 themelist(new HbListView(this)), |
50 oldItemIndex(-1), |
48 model(new QStandardItemModel(this)), |
51 themelist(new HbListWidget(this)), |
49 rightMark(new HbIcon(QString("qtg_small_tick"))), |
52 rightMark(new HbIcon(QString("qtg_small_tick"))), |
50 noMark(new HbIcon(QString(""))), |
53 noMark(new HbIcon(QString(""))), |
51 client(client) |
54 client(client) |
52 { |
55 { |
53 connect(themelist, SIGNAL(activated(const QModelIndex&)),this, SLOT(setChosen(const QModelIndex&))); |
56 connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *))); |
54 setWidget(themelist); |
57 setWidget(themelist); |
55 |
58 |
56 // Automatic updation of the themelist when some theme is installed or uninstalled |
59 // Automatic updation of the themelist when some theme is installed or uninstalled |
57 // when the themechanger app is open |
60 // when the themechanger app is open |
58 watcher=new QFileSystemWatcher(); |
61 watcher=new QFileSystemWatcher(); |
61 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
64 watcher->addPath(KThemeRootPath+"/themes/icons/"); |
62 } |
65 } |
63 } |
66 } |
64 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
67 connect(watcher,SIGNAL(directoryChanged(const QString &)),this,SLOT(updateThemeList(const QString &))); |
65 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
68 QObject::connect(this,SIGNAL(newThemeSelected(QString)),this,SLOT(sendThemeName(QString))); |
|
69 #ifdef THEME_CHANGER_TIMER_LOG |
|
70 idleTimer = new QTimer(this); |
|
71 connect(idleTimer, SIGNAL(timeout()), this, SLOT(processWhenIdle())); |
|
72 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChanged())); |
|
73 idleTimer->start(0); // to make a connection to server |
|
74 #endif |
66 } |
75 } |
67 |
76 |
68 /** |
77 /** |
69 * Destructor |
78 * Destructor |
70 */ |
79 */ |
71 ThemeSelectionList::~ThemeSelectionList() |
80 ThemeSelectionList::~ThemeSelectionList() |
72 { |
81 { |
73 // Set the theme to the applied theme before exiting. |
82 // Set the theme to the applied theme before exiting. |
74 setChosen(oldItemIndex); |
83 setChosen(themelist->item(oldItemIndex)); |
75 delete noMark; |
84 delete noMark; |
76 |
85 |
77 noMark=NULL; |
86 noMark=NULL; |
78 delete rightMark; |
87 delete rightMark; |
79 rightMark=NULL; |
88 rightMark=NULL; |
80 |
|
81 // Remove all the items from model, then delete |
|
82 model->clear(); |
|
83 delete model; |
|
84 model=NULL; |
|
85 |
89 |
86 // Reset the item view |
90 // Reset the item view |
87 themelist->reset(); |
91 themelist->reset(); |
88 delete themelist; |
92 delete themelist; |
89 themelist=NULL; |
93 themelist=NULL; |
98 bool entryAdded = false; |
102 bool entryAdded = false; |
99 bool themePresent = false; |
103 bool themePresent = false; |
100 foreach(const QString &KThemeRootPath, rootPaths()){ |
104 foreach(const QString &KThemeRootPath, rootPaths()){ |
101 dir.setPath(KThemeRootPath) ; |
105 dir.setPath(KThemeRootPath) ; |
102 QStringList list = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
106 QStringList list = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
103 if(list.contains("themes",Qt::CaseSensitive )) { |
107 if(list.contains("themes",Qt::CaseInsensitive )) { |
104 themePresent = true; |
108 themePresent = true; |
105 QDir root = KThemeRootPath; |
109 QDir root = KThemeRootPath; |
106 dir.setPath(root.path()+"/themes/icons/") ; |
110 dir.setPath(root.path()+"/themes/icons/") ; |
107 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
111 QStringList iconthemeslist=dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot,QDir::Name); |
108 foreach(QString themefolder, iconthemeslist) { |
112 foreach(QString themefolder, iconthemeslist) { |
126 iconthemeslist.insert(0,"hbdefault"); //adding one default entry |
130 iconthemeslist.insert(0,"hbdefault"); //adding one default entry |
127 entryAdded = true; |
131 entryAdded = true; |
128 } |
132 } |
129 list=iconthemeslist; |
133 list=iconthemeslist; |
130 for (int i=0; i <list.count();i++) { |
134 for (int i=0; i <list.count();i++) { |
131 // Items are populated to create the model |
135 // populate theme list with existing themes |
132 QStandardItem *item=new QStandardItem(list.at(i)); |
|
133 model->appendRow(item); |
|
134 if((HbInstance::instance()->theme()->name())==(list.at(i))) { |
136 if((HbInstance::instance()->theme()->name())==(list.at(i))) { |
135 item->setIcon(rightMark->qicon()); |
137 themelist->addItem(*rightMark,list.at(i)); |
136 oldItemIndex=item->index(); |
138 oldItemIndex=themelist->count()-1; |
137 themelist->setCurrentIndex(oldItemIndex,QItemSelectionModel::Select); |
139 themelist->setCurrentRow(oldItemIndex); |
138 } |
140 } |
139 else { |
141 else { |
140 item->setIcon(noMark->qicon()); |
142 themelist->addItem(*noMark,list.at(i)); |
141 } |
143 } |
142 } |
144 } |
143 } |
145 } |
144 } |
146 } |
145 // else{//add a case for no theme ,make hbdefault entry |
147 // else{//add a case for no theme ,make hbdefault entry |
146 if(!themePresent) { |
148 if(!themePresent) { |
147 QStringList defaultList; |
149 QStringList defaultList; |
148 defaultList.insert(0,"hbdefault"); //adding one default entry |
150 defaultList.insert(0,"hbdefault"); //adding one default entry |
149 QStandardItem *item=new QStandardItem(defaultList.at(0)); |
151 themelist->addItem(*rightMark,defaultList.at(0)); |
150 model->appendRow(item); |
|
151 item->setIcon(rightMark->qicon()); |
|
152 QString themeName=HbInstance::instance()->theme()->name(); |
152 QString themeName=HbInstance::instance()->theme()->name(); |
153 if (themeName != "hbdefault") |
153 if (themeName != "hbdefault") |
154 { |
154 { |
155 if (!client->isConnected()) { |
155 if (!client->isConnected()) { |
156 bool success = client->connectToServer(); |
156 bool success = client->connectToServer(); |
162 emit newThemeSelected("hbdefault"); |
162 emit newThemeSelected("hbdefault"); |
163 } |
163 } |
164 } |
164 } |
165 |
165 |
166 } |
166 } |
167 |
|
168 // Set the this model for the list |
|
169 themelist->setModel(model); |
|
170 } |
167 } |
171 |
168 |
172 /** |
169 /** |
173 * setChosen |
170 * setChosen |
174 */ |
171 */ |
175 void ThemeSelectionList::setChosen(const QModelIndex &index) |
172 void ThemeSelectionList::setChosen(HbListWidgetItem *item) |
176 { |
173 { |
177 // Extract the string from the model index |
174 QString str=item->text(); |
178 QVariant variant=index.data(); |
|
179 QString str=variant.toString(); |
|
180 |
175 |
181 #ifdef THEME_CHANGER_TRACES |
176 #ifdef THEME_CHANGER_TRACES |
182 qDebug() << "ThemeSelectionList::Setchosen with ThemeName: "<<str; |
177 qDebug() << "ThemeSelectionList::Setchosen with ThemeName: "<<str; |
183 #endif |
178 #endif |
184 if(iCurrentTheme != str ) { |
179 if(iCurrentTheme != str ) { |
|
180 #ifdef THEME_CHANGER_TIMER_LOG |
|
181 timer.start(); |
|
182 qDebug() << "Selected theme: " << str; |
|
183 #endif |
185 iCurrentTheme = str; |
184 iCurrentTheme = str; |
186 if (!client->isConnected()) { |
185 if (!client->isConnected()) { |
187 bool success = client->connectToServer(); |
186 bool success = client->connectToServer(); |
188 if (success) { |
187 if (success) { |
189 emit newThemeSelected(str); |
188 emit newThemeSelected(str); |
203 /** |
202 /** |
204 * applySelection |
203 * applySelection |
205 */ |
204 */ |
206 void ThemeSelectionList::applySelection() |
205 void ThemeSelectionList::applySelection() |
207 { |
206 { |
208 QModelIndex currentItemIndex = (themelist)->currentIndex(); |
207 if(oldItemIndex!=themelist->currentRow()) { |
209 if(oldItemIndex!=currentItemIndex) { |
208 themelist->setIcon(themelist->currentRow(),*rightMark); |
210 (model->itemFromIndex(currentItemIndex))->setIcon(rightMark->qicon()); |
209 if(oldItemIndex >= 0) { |
211 if(oldItemIndex.isValid()) { |
210 themelist->setIcon(oldItemIndex,*noMark); |
212 (model->itemFromIndex(oldItemIndex))->setIcon(noMark->qicon()); |
211 } |
213 } |
212 oldItemIndex = themelist->currentRow(); |
214 oldItemIndex = currentItemIndex; |
213 } |
215 } |
|
216 |
|
217 } |
214 } |
218 |
215 |
219 |
216 |
220 /** |
217 /** |
221 * event |
218 * event |
222 */ |
219 */ |
223 bool ThemeSelectionList::event(QEvent *e) |
220 bool ThemeSelectionList::event(QEvent *e) |
224 { |
221 { |
225 if((e->type()==QEvent::ShortcutOverride)||(e->type()==QEvent::WindowDeactivate)) { |
222 if((e->type()==QEvent::ShortcutOverride)||(e->type()==QEvent::WindowDeactivate)) { |
226 themelist->setCurrentIndex(oldItemIndex,QItemSelectionModel::Select); |
223 // save old applied theme |
|
224 themelist->setCurrentRow(oldItemIndex); |
227 themelist->setFocus(); |
225 themelist->setFocus(); |
228 setChosen(oldItemIndex); |
226 setChosen(themelist->item(oldItemIndex)); |
229 return true; |
227 return true; |
230 } |
228 } |
231 return (HbView::event(e)); |
229 return (HbView::event(e)); |
232 } |
230 } |
233 |
231 |
256 QStringList ThemeSelectionList::rootPaths() |
254 QStringList ThemeSelectionList::rootPaths() |
257 { |
255 { |
258 QStringList rootDirs; |
256 QStringList rootDirs; |
259 #if defined(Q_OS_SYMBIAN) |
257 #if defined(Q_OS_SYMBIAN) |
260 rootDirs << "c:/resource/hb" |
258 rootDirs << "c:/resource/hb" |
261 << "z:/resource/hb"; |
259 << "z:/resource/hb" |
|
260 << "e:/resource/hb" |
|
261 << "f:/resource/hb"; |
262 #else |
262 #else |
263 QString envDir = qgetenv("HB_THEMES_DIR"); |
263 QString envDir = qgetenv("HB_THEMES_DIR"); |
264 if (!envDir.isEmpty()) |
264 if (!envDir.isEmpty()) |
265 rootDirs << envDir; |
265 rootDirs << envDir; |
266 #endif |
266 #endif |
269 #elif !defined(Q_OS_SYMBIAN) |
269 #elif !defined(Q_OS_SYMBIAN) |
270 rootDirs << HB_RESOURCES_DIR; |
270 rootDirs << HB_RESOURCES_DIR; |
271 #endif |
271 #endif |
272 return rootDirs; |
272 return rootDirs; |
273 } |
273 } |
|
274 |
|
275 #ifdef THEME_CHANGER_TIMER_LOG |
|
276 void ThemeSelectionList::processWhenIdle() |
|
277 { |
|
278 qDebug() << "Theme changed applied in " << timer.elapsed() << " msec"; |
|
279 idleTimer->stop(); |
|
280 if (!client->isConnected()) { |
|
281 client->connectToServer(); |
|
282 } |
|
283 } |
|
284 |
|
285 void ThemeSelectionList::themeChanged() |
|
286 { |
|
287 idleTimer->start(0); |
|
288 } |
|
289 #endif //THEME_CHANGER_TIMER_LOG |