32 #include <QModelIndex> |
32 #include <QModelIndex> |
33 #include <QTranslator> |
33 #include <QTranslator> |
34 #include <QSortFilterProxyModel> |
34 #include <QSortFilterProxyModel> |
35 #include <QThread> |
35 #include <QThread> |
36 #include <QTimer> |
36 #include <QTimer> |
|
37 #include <QDesktopServices> |
|
38 #include <QUrl> |
37 |
39 |
38 #include <hbmainwindow.h> |
40 #include <hbmainwindow.h> |
39 #include <hbinstance.h> |
41 #include <hbinstance.h> |
40 #include "cpthemechanger.h" |
42 #include "cpthemechanger.h" |
41 |
43 |
42 #include "cpthemecontrol.h" |
44 #include "cpthemecontrol.h" |
43 #include "cpthemelistview.h" |
45 #include "cpthemelistview.h" |
44 #include "cpthemepreview.h" |
46 #include "cpthemepreview.h" |
|
47 #include "cpthemeinfo.h" |
|
48 #include "cpthemelistmodel.h" |
45 |
49 |
46 #include <hbdialog.h> |
50 #include <hbdialog.h> |
47 #include <hblabel.h> |
51 #include <hblabel.h> |
48 |
52 |
49 |
53 |
77 QString lang = QLocale::system().name(); |
80 QString lang = QLocale::system().name(); |
78 QString path = "Z:/resource/qt/translations/"; |
81 QString path = "Z:/resource/qt/translations/"; |
79 translator->load("control_panel_" + lang, path); |
82 translator->load("control_panel_" + lang, path); |
80 qApp->installTranslator(translator); |
83 qApp->installTranslator(translator); |
81 |
84 |
82 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChangeFinished())); |
85 connect(mThemeChanger,SIGNAL(themeChangeFinished()), this, SLOT(themeChangeFinished())); |
83 |
86 |
84 } |
87 } |
85 |
88 |
86 |
89 |
87 /*! |
90 /*! |
109 void CpThemeControl::createThemeList() |
112 void CpThemeControl::createThemeList() |
110 { |
113 { |
111 |
114 |
112 mThemeListView = new CpThemeListView(); |
115 mThemeListView = new CpThemeListView(); |
113 |
116 |
114 mListModel = &mThemeChanger->model(); |
117 if(!mListModel) { |
115 |
118 mListModel = new CpThemeListModel(this); |
116 mSortModel = new QSortFilterProxyModel(this); |
119 } |
117 mSortModel->setDynamicSortFilter(true); |
120 |
118 mSortModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
119 mSortModel->sort(0); |
|
120 mSortModel->setSourceModel(mListModel); |
|
121 |
|
122 // Set the model for theme list. |
121 // Set the model for theme list. |
123 mThemeListView->setModel(mSortModel); |
122 mThemeListView->setModel(mListModel); |
124 mThemeListView->themeList()->setSelectionMode(HbAbstractItemView::SingleSelection); |
123 mThemeListView->themeList()->setSelectionMode(HbAbstractItemView::SingleSelection); |
125 |
124 |
126 setActiveThemeIndex(); |
125 setActiveThemeIndex(); |
127 |
126 |
128 |
127 |
152 /*! |
151 /*! |
153 returns the name of the current theme. |
152 returns the name of the current theme. |
154 */ |
153 */ |
155 QString CpThemeControl::currentThemeName() const |
154 QString CpThemeControl::currentThemeName() const |
156 { |
155 { |
157 return mThemeChanger->currentTheme().name; |
156 QString name = ""; |
|
157 if(mThemeChanger->currentTheme()) { |
|
158 name = mThemeChanger->currentTheme()->name(); |
|
159 } |
|
160 return name; |
158 } |
161 } |
159 |
162 |
160 /*! |
163 /*! |
161 returns the repersenatative icon of the current theme. |
164 returns the repersenatative icon of the current theme. |
162 */ |
165 */ |
163 HbIcon CpThemeControl::currentThemeIcon() const |
166 HbIcon CpThemeControl::currentThemeIcon() const |
164 { |
167 { |
165 return mThemeChanger->currentTheme().icon; |
168 HbIcon icon; |
|
169 if(mThemeChanger->currentTheme()) { |
|
170 icon = mThemeChanger->currentTheme()->icon(); |
|
171 } |
|
172 return icon; |
166 } |
173 } |
167 |
174 |
168 /*! |
175 /*! |
169 Slot called when a list item of the theme list is selected. |
176 Slot called when a list item of the theme list is selected. |
170 */ |
177 */ |
171 void CpThemeControl::newThemeSelected(const QModelIndex& index) |
178 void CpThemeControl::newThemeSelected(const QModelIndex& index) |
172 { |
179 { |
173 if(!index.isValid()) { |
180 if(!index.isValid()) { |
174 return; |
181 return; |
175 } |
182 } |
176 |
183 |
177 |
184 CpThemeInfo themeInfo; |
178 CpThemeChanger::ThemeInfo themeInfo; |
|
179 QVariant data; |
185 QVariant data; |
180 |
186 |
181 //reset the current index to active theme, so that the selection remains on current |
187 //reset the current index to active theme, so that the selection remains on current |
182 //theme even though another list item is selected. |
188 //theme even though another list item is selected. |
183 setActiveThemeIndex(); |
189 setActiveThemeIndex(); |
184 |
190 |
|
191 // Figure out whether this is a URI and appropriately delegate |
|
192 data = index.data(CpThemeListModel::ItemTypeRole); |
|
193 if(data.isValid() && data.canConvert<CpThemeInfo::ThemeListItemType>()) { |
|
194 |
|
195 CpThemeInfo::ThemeListItemType type = data.value<CpThemeInfo::ThemeListItemType>(); |
|
196 |
|
197 switch (type) { |
|
198 case CpThemeInfo::ThemeListItemType_URL: |
|
199 //get the URL |
|
200 data = index.data(CpThemeListModel::ItemDataRole); |
|
201 if(data.isValid()) { |
|
202 QString url = data.toString(); |
|
203 // Launch the URL in the browser and |
|
204 // continue to Preview if not successful |
|
205 if (QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode))) { |
|
206 return; |
|
207 } |
|
208 } |
|
209 break; |
|
210 |
|
211 case CpThemeInfo::ThemeListItemType_APP: |
|
212 break; |
|
213 |
|
214 default: |
|
215 // do nothing |
|
216 qt_noop(); |
|
217 } |
|
218 } |
|
219 |
185 //get the theme name. |
220 //get the theme name. |
186 data = index.data(Qt::DisplayRole); |
221 data = index.data(Qt::DisplayRole); |
187 if(data.isValid()) { |
222 if(data.isValid()) { |
188 themeInfo.name = data.toString(); |
223 themeInfo.setName(data.toString()); |
189 } |
224 } |
|
225 |
190 //get theme icon. |
226 //get theme icon. |
191 data = index.data(Qt::DecorationRole); |
227 data = index.data(Qt::DecorationRole); |
192 if(data.isValid()) { |
228 if(data.isValid()) { |
193 themeInfo.icon = data.value<HbIcon>(); |
229 themeInfo.setIcon(data.value<HbIcon>()); |
194 } |
230 } |
195 |
231 |
196 data = index.data(CpThemeChanger::PortraitPreviewRole); |
232 data = index.data(CpThemeListModel::PortraitPreviewRole); |
197 if(data.isValid()) { |
233 if(data.isValid()) { |
198 themeInfo.portraitPreviewIcon = data.value<HbIcon>(); |
234 themeInfo.setPortraitPreviewIcon(data.value<HbIcon>()); |
199 } |
235 } |
200 |
236 |
201 data = index.data(CpThemeChanger::LandscapePreviewRole); |
237 data = index.data(CpThemeListModel::LandscapePreviewRole); |
202 if(data.isValid()) { |
238 if(data.isValid()) { |
203 themeInfo.landscapePreviewIcon = data.value<HbIcon>(); |
239 themeInfo.setLandscapePreviewIcon(data.value<HbIcon>()); |
204 } |
240 } |
205 |
241 |
206 |
242 //Set up the theme preview and set it to |
207 //Set up the theme preview and set it to |
|
208 //the current view of main window. |
243 //the current view of main window. |
209 HbMainWindow* mWindow = ::mainWindow(); |
244 HbMainWindow* mWindow = ::mainWindow(); |
210 |
245 |
211 if(!mThemePreview){ |
246 if(!mThemePreview){ |
212 mThemePreview = new CpThemePreview(themeInfo); |
247 mThemePreview = new CpThemePreview(themeInfo); |
219 this, SLOT(themeApplied(const QString&))); |
254 this, SLOT(themeApplied(const QString&))); |
220 } else { |
255 } else { |
221 mThemePreview->setThemeInfo(themeInfo); |
256 mThemePreview->setThemeInfo(themeInfo); |
222 } |
257 } |
223 mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel")); |
258 mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel")); |
224 |
259 |
225 mWindow->setCurrentView(mThemePreview); |
260 mWindow->setCurrentView(mThemePreview); |
226 |
261 |
227 } |
262 } |
228 |
263 |
229 /*! |
264 /*! |
230 Slot called when a Select key is pressed in theme preview view. |
265 Slot called when a Select key is pressed in theme preview view. |
231 */ |
266 */ |
232 void CpThemeControl::themeApplied(const QString& theme) |
267 void CpThemeControl::themeApplied(const QString& theme) |
233 { |
268 { |
234 bool success = false; |
269 QThread::currentThread()->setPriority(QThread::HighPriority); |
235 |
270 |
236 success = mThemeChanger->connectToServer(); |
271 if(mThemeChanger->changeTheme(theme)) { |
237 |
272 |
238 if (success) { |
273 //Start a timer. If theme change takes more than 1 seconds, |
239 QThread::currentThread()->setPriority(QThread::HighPriority); |
274 //we will show a dialog (mWaitDialog) until theme change |
240 mThemeChanger->changeTheme(theme); |
275 //is done (themeChangeFinished is called). |
241 emit themeUpdated(mThemeChanger->currentTheme().name, mThemeChanger->currentTheme().icon); |
276 QTimer::singleShot(1000, this, SLOT(themeWaitTimeout())); |
242 } |
|
243 |
|
244 //Start a timer. If theme change takes more than 1 seconds, |
|
245 //we will show a dialog (mWaitDialog) until theme change |
|
246 //is done (themeChangeFinished is called). |
|
247 QTimer::singleShot(1000, this, SLOT(themeWaitTimeout())); |
|
248 |
277 |
249 mThemeChangeFinished = false; |
278 mThemeChangeFinished = false; |
|
279 } else { |
|
280 //theme change failed, go back to control panel. |
|
281 previewClosed(); |
|
282 triggerThemeListClose(); |
|
283 } |
250 |
284 |
251 } |
285 } |
252 |
286 |
253 /*! |
287 /*! |
254 Slot called when the theme preview view is closed. |
288 Slot called when the theme preview view is closed. |
312 //show a processing dialog. |
346 //show a processing dialog. |
313 if(!mThemeChangeFinished) |
347 if(!mThemeChangeFinished) |
314 { |
348 { |
315 if(!mWaitDialog) { |
349 if(!mWaitDialog) { |
316 mWaitDialog = new HbDialog(); |
350 mWaitDialog = new HbDialog(); |
|
351 mWaitDialog->setDismissPolicy(HbPopup::NoDismiss); |
317 mWaitDialog->setModal(false); |
352 mWaitDialog->setModal(false); |
318 mWaitDialog->setDismissPolicy(HbPopup::NoDismiss); |
353 mWaitDialog->setTimeout(HbPopup::NoTimeout); |
319 //TODO: need localized text for Hb Dialog |
354 //TODO: need localized text for Hb Dialog |
320 // Create and set HbLabel as content widget. |
355 // Create and set HbLabel as content widget. |
321 HbLabel *label = new HbLabel("Processing ..."); |
356 HbLabel *label = new HbLabel("Processing ..."); |
322 label->setAlignment(Qt::AlignCenter); |
357 label->setAlignment(Qt::AlignCenter); |
323 mWaitDialog->setContentWidget(label); |
358 mWaitDialog->setContentWidget(label); |
332 //Theme change is done. Start an idle timer to let the UI |
367 //Theme change is done. Start an idle timer to let the UI |
333 //finish remaining tasks. |
368 //finish remaining tasks. |
334 QTimer::singleShot(0, this, SLOT(themeChangeTimeout())); |
369 QTimer::singleShot(0, this, SLOT(themeChangeTimeout())); |
335 mThemeChangeFinished = true; |
370 mThemeChangeFinished = true; |
336 |
371 |
|
372 if(mThemeChanger->currentTheme()) { |
|
373 emit themeUpdated(mThemeChanger->currentTheme()->name(), mThemeChanger->currentTheme()->icon()); |
|
374 } |
|
375 |
337 } |
376 } |
338 |
377 |
339 /*! |
378 /*! |
340 * Private function that sets the current index of theme list view to indicate |
379 * Private function that sets the current index of theme list view to indicate |
341 * the active theme. |
380 * the active theme. |
342 */ |
381 */ |
343 void CpThemeControl::setActiveThemeIndex() |
382 void CpThemeControl::setActiveThemeIndex() |
344 { |
383 { |
345 //Get the index of current theme. |
384 //Get the index of current theme. |
346 QModelIndex sourceIndex = mListModel->index(mThemeChanger->indexOf(mThemeChanger->currentTheme()),0); |
385 CpThemeListModel* themeListModel = dynamic_cast<CpThemeListModel*>(mListModel); |
347 //Map it to the sort model index. |
386 const CpThemeInfo* currentTheme = mThemeChanger->currentTheme(); |
348 QModelIndex sortedIndex = mSortModel->mapFromSource(sourceIndex); |
387 if(themeListModel && currentTheme) { |
349 //set current index. |
388 QModelIndex sourceIndex = mListModel->index(themeListModel->indexOf(*currentTheme),0); |
350 mThemeListView->themeList()->setCurrentIndex(sortedIndex, QItemSelectionModel::SelectCurrent); |
389 //set current index. |
351 } |
390 mThemeListView->themeList()->setCurrentIndex(sourceIndex, QItemSelectionModel::SelectCurrent); |
352 |
391 } |
353 |
392 } |
354 |
393 |
355 |
394 |
356 |
395 |
357 |
396 |
|
397 |
|
398 |