88 |
82 |
89 } |
83 } |
90 |
84 |
91 |
85 |
92 /*! |
86 /*! |
93 destorys the list view, preview and theme changer objects. |
87 destorys the list view and theme changer objects. |
94 */ |
88 */ |
95 CpThemeControl::~CpThemeControl() |
89 CpThemeControl::~CpThemeControl() |
96 { |
90 { |
97 delete mThemeListView; |
91 delete mThemeListView; |
98 mThemeListView = 0; |
92 mThemeListView = 0; |
99 |
93 |
100 delete mThemeChanger; |
94 delete mThemeChanger; |
101 mThemeChanger = 0; |
95 mThemeChanger = 0; |
102 |
96 |
103 delete mThemePreview; |
|
104 mThemePreview = 0; |
|
105 |
|
106 delete mWaitDialog; |
97 delete mWaitDialog; |
107 mWaitDialog = 0; |
98 mWaitDialog = 0; |
108 } |
99 } |
109 |
100 |
110 /*! |
101 /*! |
111 Creates the theme list view. Gets the themes, creates a model based on |
102 Creates the theme list view. Gets the themes, creates a model and sets the list model. |
112 theme names, icons, and icon paths and sets the list model. |
|
113 */ |
103 */ |
114 void CpThemeControl::createThemeList() |
104 void CpThemeControl::createThemeList() |
115 { |
105 { |
116 |
106 |
117 mThemeListView = new CpThemeListView(); |
107 mThemeListView = new CpThemeListView(); |
120 mListModel = new CpThemeListModel(this); |
110 mListModel = new CpThemeListModel(this); |
121 } |
111 } |
122 |
112 |
123 // Set the model for theme list. |
113 // Set the model for theme list. |
124 mThemeListView->setModel(mListModel); |
114 mThemeListView->setModel(mListModel); |
125 mThemeListView->themeList()->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
126 |
115 |
127 setActiveThemeIndex(); |
116 setActiveThemeIndex(); |
128 |
|
129 |
117 |
130 //connect to signal for selecting a list item. |
118 //connect to signal for selecting a list item. |
131 connect(mThemeListView,SIGNAL(newThemeSelected(QModelIndex)), |
119 connect(mThemeListView,SIGNAL(newThemeSelected(QModelIndex)), |
132 this,SLOT(newThemeSelected(QModelIndex))); |
120 this,SLOT(newThemeSelected(QModelIndex))); |
|
121 |
|
122 connect(mThemeListView, SIGNAL(oviClicked()), this, SLOT(getOviTheme())); |
133 |
123 |
134 //handle signal for list view closing. (e.g Back softkey pressed) |
124 //handle signal for list view closing. (e.g Back softkey pressed) |
135 connect(mThemeListView,SIGNAL(aboutToClose()), |
125 connect(mThemeListView,SIGNAL(aboutToClose()), |
136 this,SLOT(themeListClosed())); |
126 this,SLOT(themeListClosed())); |
137 } |
127 } |
187 QVariant data; |
177 QVariant data; |
188 |
178 |
189 //reset the current index to active theme, so that the selection remains on current |
179 //reset the current index to active theme, so that the selection remains on current |
190 //theme even though another list item is selected. |
180 //theme even though another list item is selected. |
191 setActiveThemeIndex(); |
181 setActiveThemeIndex(); |
192 |
|
193 // Figure out whether this is a URI and appropriately delegate |
|
194 data = index.data(CpThemeListModel::ItemTypeRole); |
|
195 if(data.isValid() && data.canConvert<CpThemeInfo::ThemeListItemType>()) { |
|
196 |
|
197 CpThemeInfo::ThemeListItemType type = data.value<CpThemeInfo::ThemeListItemType>(); |
|
198 |
|
199 switch (type) { |
|
200 case CpThemeInfo::ThemeListItemType_URL: |
|
201 //get the URL |
|
202 data = index.data(CpThemeListModel::ItemDataRole); |
|
203 if(data.isValid()) { |
|
204 QString url = data.toString(); |
|
205 // Launch the URL in the browser and |
|
206 // continue to Preview if not successful |
|
207 if (QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode))) { |
|
208 return; |
|
209 } |
|
210 } |
|
211 break; |
|
212 |
|
213 case CpThemeInfo::ThemeListItemType_APP: |
|
214 break; |
|
215 |
|
216 default: |
|
217 // do nothing |
|
218 qt_noop(); |
|
219 } |
|
220 } |
|
221 |
182 |
222 //get the theme name. |
183 //get the theme name. |
223 data = index.data(Qt::DisplayRole); |
184 data = index.data(Qt::DisplayRole); |
224 if(data.isValid()) { |
185 if(data.isValid()) { |
225 themeInfo.setName(data.toString()); |
186 themeInfo.setName(data.toString()); |
226 } |
187 } |
227 |
188 |
|
189 //get theme path |
228 data = index.data(CpThemeListModel::ItemDataRole); |
190 data = index.data(CpThemeListModel::ItemDataRole); |
229 if(data.isValid()) { |
191 if(data.isValid()) { |
230 themeInfo.setItemData(data.toString()); |
192 themeInfo.setItemData(data.toString()); |
231 } |
193 } |
232 |
194 |
233 //get theme icon. |
195 applyTheme(themeInfo); |
234 data = index.data(Qt::DecorationRole); |
196 |
235 if(data.isValid()) { |
197 } |
236 themeInfo.setIcon(data.value<HbIcon>()); |
198 |
237 } |
199 void CpThemeControl::getOviTheme() |
238 |
200 { |
239 data = index.data(CpThemeListModel::PortraitPreviewRole); |
201 QString url = QString("http://lr.ovi.mobi/store/themes"); |
240 if(data.isValid()) { |
202 // Launch the URL in the browser and |
241 themeInfo.setPortraitPreviewIcon(data.value<HbIcon>()); |
203 // continue to Preview if not successful |
242 } |
204 QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); |
243 |
205 |
244 data = index.data(CpThemeListModel::LandscapePreviewRole); |
|
245 if(data.isValid()) { |
|
246 themeInfo.setLandscapePreviewIcon(data.value<HbIcon>()); |
|
247 } |
|
248 |
|
249 |
|
250 #ifdef CP_THEME_PREVIEW_DEFINED |
|
251 |
|
252 //Set up the theme preview and set it to |
|
253 //the current view of main window. |
|
254 |
|
255 HbMainWindow* mWindow = ::mainWindow(); |
|
256 |
|
257 if(!mThemePreview){ |
|
258 mThemePreview = new CpThemePreview(themeInfo); |
|
259 mWindow->addView(mThemePreview); |
|
260 |
|
261 connect(mThemePreview,SIGNAL(aboutToClose()), |
|
262 this, SLOT(previewClosed())); |
|
263 |
|
264 connect(mThemePreview, SIGNAL(applyTheme(CpThemeInfo)), |
|
265 this, SLOT(themeApplied(CpThemeInfo))); |
|
266 } else { |
|
267 mThemePreview->setThemeInfo(themeInfo); |
|
268 } |
|
269 mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel")); |
|
270 |
|
271 mWindow->setCurrentView(mThemePreview); |
|
272 #else |
|
273 themeApplied(themeInfo); |
|
274 #endif |
|
275 |
|
276 } |
206 } |
277 |
207 |
278 /*! |
208 /*! |
279 Slot called when a Select key is pressed in theme preview view. |
209 Slot called when a Select key is pressed in theme preview view. |
280 */ |
210 */ |
281 void CpThemeControl::themeApplied(const CpThemeInfo& theme) |
211 void CpThemeControl::applyTheme(const CpThemeInfo& theme) |
282 { |
212 { |
283 QThread::currentThread()->setPriority(QThread::HighPriority); |
213 QThread::currentThread()->setPriority(QThread::HighPriority); |
284 |
214 |
285 if(mThemeChanger->changeTheme(theme)) { |
215 if(mThemeChanger->changeTheme(theme)) { |
286 |
216 |
290 QTimer::singleShot(KThemeChangeTimeOutMilliSeconds, this, SLOT(themeWaitTimeout())); |
220 QTimer::singleShot(KThemeChangeTimeOutMilliSeconds, this, SLOT(themeWaitTimeout())); |
291 |
221 |
292 mThemeChangeFinished = false; |
222 mThemeChangeFinished = false; |
293 } else { |
223 } else { |
294 //theme change failed, go back to control panel. |
224 //theme change failed, go back to control panel. |
295 #ifdef CP_THEME_PREVIEW_DEFINED |
|
296 previewClosed(); |
|
297 triggerThemeListClose(); |
|
298 #else |
|
299 setActiveThemeIndex(); |
225 setActiveThemeIndex(); |
300 #endif |
226 } |
301 |
227 |
302 } |
|
303 |
|
304 } |
|
305 |
|
306 /*! |
|
307 Slot called when the theme preview view is closed. |
|
308 */ |
|
309 void CpThemeControl::previewClosed() |
|
310 { |
|
311 //The theme preview closed, go back |
|
312 //to theme list view. |
|
313 HbMainWindow* mainWindow = ::mainWindow(); |
|
314 if(mThemePreview){ |
|
315 mainWindow->removeView(mThemePreview); |
|
316 mThemePreview->deleteLater(); |
|
317 mThemePreview = 0; |
|
318 } |
|
319 |
|
320 //reset the current index to active theme, so that the selection remains on current |
|
321 //theme even though another list item is selected. |
|
322 setActiveThemeIndex(); |
|
323 mainWindow->setCurrentView(mThemeListView); |
|
324 } |
228 } |
325 |
229 |
326 /*! |
230 /*! |
327 Slot for when the theme list view is closed. Ownership of the theme list was given to |
231 Slot for when the theme list view is closed. Ownership of the theme list was given to |
328 control panel, so the class won't delete it. |
232 control panel, so the class won't delete it. |
329 |
233 |
330 */ |
234 */ |
331 void CpThemeControl::themeListClosed() |
235 void CpThemeControl::themeListClosed() |
332 { |
236 { |
333 mThemeListView = 0; |
237 mThemeListView = 0; |
334 |
|
335 delete mThemePreview; |
|
336 mThemePreview = 0; |
|
337 } |
238 } |
338 |
239 |
339 /*! |
240 /*! |
340 asks the theme list view to close. |
241 asks the theme list view to close. |
341 */ |
242 */ |
350 //so revert back the application priority to normal |
251 //so revert back the application priority to normal |
351 //and go back to control panel view. |
252 //and go back to control panel view. |
352 if(mWaitDialog && mWaitDialog->isVisible()) { |
253 if(mWaitDialog && mWaitDialog->isVisible()) { |
353 mWaitDialog->hide(); |
254 mWaitDialog->hide(); |
354 } |
255 } |
355 |
256 setActiveThemeIndex(); |
356 #ifdef CP_THEME_PREVIEW_DEFINED |
|
357 previewClosed(); |
|
358 //ask the themelistview to close. Control Panel will |
|
359 //take care of removing it from window. |
|
360 triggerThemeListClose(); |
|
361 #else |
|
362 setActiveThemeIndex(); |
|
363 |
|
364 #endif |
|
365 |
|
366 |
|
367 |
|
368 QThread::currentThread()->setPriority(QThread::NormalPriority); |
257 QThread::currentThread()->setPriority(QThread::NormalPriority); |
369 } |
258 } |
370 |
259 |
371 void CpThemeControl::themeWaitTimeout() |
260 void CpThemeControl::themeWaitTimeout() |
372 { |
261 { |