controlpanelplugins/themeplugin/src/cpthemecontrol.cpp
changeset 31 e79ce701c376
parent 25 19394c261aa5
child 37 cb294e641644
equal deleted inserted replaced
25:19394c261aa5 31:e79ce701c376
    48 #include "cpthemelistmodel.h"
    48 #include "cpthemelistmodel.h"
    49 
    49 
    50 #include <hbdialog.h>
    50 #include <hbdialog.h>
    51 #include <hblabel.h>
    51 #include <hblabel.h>
    52 
    52 
       
    53 //time out time before showing a processing dialog.
       
    54 static const int KThemeChangeTimeOutMilliSeconds = 2000;  
    53 
    55 
    54 /*!
    56 /*!
    55 	Helper function to fetch the main window.
    57 	Helper function to fetch the main window.
    56 */
    58 */
    57 
    59 
   124     
   126     
   125     setActiveThemeIndex();
   127     setActiveThemeIndex();
   126     
   128     
   127     
   129     
   128     //connect to signal for selecting a list item.
   130     //connect to signal for selecting a list item.
   129     connect(mThemeListView,SIGNAL(newThemeSelected(const QModelIndex&)),
   131     connect(mThemeListView,SIGNAL(newThemeSelected(QModelIndex)),
   130             this,SLOT(newThemeSelected(const QModelIndex&)));
   132             this,SLOT(newThemeSelected(QModelIndex)));
   131 
   133 
   132 	//handle signal for list view closing. (e.g Back softkey pressed)
   134 	//handle signal for list view closing. (e.g Back softkey pressed)
   133     connect(mThemeListView,SIGNAL(aboutToClose()),
   135     connect(mThemeListView,SIGNAL(aboutToClose()),
   134             this,SLOT(themeListClosed()));
   136             this,SLOT(themeListClosed()));
   135 }
   137 }
   221     data = index.data(Qt::DisplayRole);
   223     data = index.data(Qt::DisplayRole);
   222     if(data.isValid()) {
   224     if(data.isValid()) {
   223         themeInfo.setName(data.toString());
   225         themeInfo.setName(data.toString());
   224     }
   226     }
   225     
   227     
       
   228     data = index.data(CpThemeListModel::ItemDataRole);
       
   229     if(data.isValid()) {
       
   230         themeInfo.setItemData(data.toString());
       
   231     }
       
   232     
   226     //get theme icon.
   233     //get theme icon.
   227     data = index.data(Qt::DecorationRole);
   234     data = index.data(Qt::DecorationRole);
   228     if(data.isValid()) {
   235     if(data.isValid()) {
   229         themeInfo.setIcon(data.value<HbIcon>());
   236         themeInfo.setIcon(data.value<HbIcon>());
   230     }
   237     }
   237     data = index.data(CpThemeListModel::LandscapePreviewRole);
   244     data = index.data(CpThemeListModel::LandscapePreviewRole);
   238     if(data.isValid()) {
   245     if(data.isValid()) {
   239         themeInfo.setLandscapePreviewIcon(data.value<HbIcon>());
   246         themeInfo.setLandscapePreviewIcon(data.value<HbIcon>());
   240     }
   247     }
   241     
   248     
       
   249     
       
   250 #ifdef CP_THEME_PREVIEW_DEFINED    
       
   251     
   242    //Set up the theme preview and set it to
   252    //Set up the theme preview and set it to
   243     //the current view of main window.
   253     //the current view of main window.
       
   254 
   244     HbMainWindow*  mWindow = ::mainWindow();
   255     HbMainWindow*  mWindow = ::mainWindow();
   245    
   256    
   246     if(!mThemePreview){
   257     if(!mThemePreview){
   247         mThemePreview = new CpThemePreview(themeInfo);
   258         mThemePreview = new CpThemePreview(themeInfo);
   248         mWindow->addView(mThemePreview);
   259         mWindow->addView(mThemePreview);
   249         
   260         
   250         connect(mThemePreview,SIGNAL(aboutToClose()),
   261         connect(mThemePreview,SIGNAL(aboutToClose()),
   251             this, SLOT(previewClosed()));
   262             this, SLOT(previewClosed()));
   252 
   263 
   253         connect(mThemePreview, SIGNAL(applyTheme(const QString&)),
   264         connect(mThemePreview, SIGNAL(applyTheme(CpThemeInfo)),
   254                 this, SLOT(themeApplied(const QString&)));
   265                 this, SLOT(themeApplied(CpThemeInfo)));
   255     } else {
   266     } else {
   256         mThemePreview->setThemeInfo(themeInfo);
   267         mThemePreview->setThemeInfo(themeInfo);
   257     }
   268     }
   258     mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel"));
   269     mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel"));
   259 
   270 
   260     mWindow->setCurrentView(mThemePreview);
   271     mWindow->setCurrentView(mThemePreview);
       
   272 #else
       
   273     themeApplied(themeInfo);
       
   274 #endif
   261 
   275 
   262 }
   276 }
   263 
   277 
   264 /*!
   278 /*!
   265 	Slot called when a Select key is pressed in theme preview view.
   279 	Slot called when a Select key is pressed in theme preview view.
   266 */
   280 */
   267 void CpThemeControl::themeApplied(const QString& theme)
   281 void CpThemeControl::themeApplied(const CpThemeInfo& theme)
   268 {
   282 {
   269     QThread::currentThread()->setPriority(QThread::HighPriority);  
   283     QThread::currentThread()->setPriority(QThread::HighPriority);  
   270     
   284     
   271     if(mThemeChanger->changeTheme(theme)) {
   285     if(mThemeChanger->changeTheme(theme)) {
   272     
   286     
   273         //Start a timer. If theme change takes more than 1 seconds,
   287         //Start a timer. If theme change takes more than 1 seconds,
   274         //we will show a dialog (mWaitDialog) until theme change
   288         //we will show a dialog (mWaitDialog) until theme change
   275         //is done (themeChangeFinished is called).
   289         //is done (themeChangeFinished is called).
   276         QTimer::singleShot(1000, this, SLOT(themeWaitTimeout()));
   290         QTimer::singleShot(KThemeChangeTimeOutMilliSeconds, this, SLOT(themeWaitTimeout()));
   277         
   291         
   278         mThemeChangeFinished = false;
   292         mThemeChangeFinished = false;
   279     } else {
   293     } else {
   280         //theme change failed, go back to control panel.
   294         //theme change failed, go back to control panel.
       
   295 #ifdef CP_THEME_PREVIEW_DEFINED
   281         previewClosed();
   296         previewClosed();
   282         triggerThemeListClose();
   297         triggerThemeListClose();
       
   298 #else
       
   299         setActiveThemeIndex();
       
   300 #endif
       
   301    
   283     }
   302     }
   284    
   303    
   285 }
   304 }
   286 
   305 
   287 /*!
   306 /*!
   290 void CpThemeControl::previewClosed()
   309 void CpThemeControl::previewClosed()
   291 {
   310 {
   292     //The theme preview closed, go back
   311     //The theme preview closed, go back
   293     //to theme list view.
   312     //to theme list view.
   294     HbMainWindow*  mainWindow = ::mainWindow();
   313     HbMainWindow*  mainWindow = ::mainWindow();
   295 	mainWindow->removeView(mThemePreview);
   314     if(mThemePreview){
   296     mThemePreview->deleteLater();
   315         mainWindow->removeView(mThemePreview);
   297     mThemePreview = 0;
   316         mThemePreview->deleteLater();
       
   317         mThemePreview = 0;
       
   318     }
   298   
   319   
   299     //reset the current index to active theme, so that the selection remains on current
   320     //reset the current index to active theme, so that the selection remains on current
   300     //theme even though another list item is selected.
   321     //theme even though another list item is selected.
   301     setActiveThemeIndex();
   322     setActiveThemeIndex();
   302 	mainWindow->setCurrentView(mThemeListView);   
   323 	mainWindow->setCurrentView(mThemeListView);   
   329     //so revert back the application priority to normal
   350     //so revert back the application priority to normal
   330     //and go back to control panel view.
   351     //and go back to control panel view.
   331     if(mWaitDialog && mWaitDialog->isVisible()) {
   352     if(mWaitDialog && mWaitDialog->isVisible()) {
   332         mWaitDialog->hide();
   353         mWaitDialog->hide();
   333     }
   354     }
   334     
   355    
   335     previewClosed();
   356 #ifdef CP_THEME_PREVIEW_DEFINED
   336     //ask the themelistview to close.  Control Panel will
   357         previewClosed();
   337     //take care of removing it from window.
   358         //ask the themelistview to close.  Control Panel will
   338     triggerThemeListClose();
   359         //take care of removing it from window.
   339     
   360         triggerThemeListClose();
       
   361 #else
       
   362         setActiveThemeIndex();
       
   363        
       
   364 #endif
       
   365        
       
   366 
       
   367   
   340     QThread::currentThread()->setPriority(QThread::NormalPriority); 
   368     QThread::currentThread()->setPriority(QThread::NormalPriority); 
   341 }
   369 }
   342 
   370 
   343 void CpThemeControl::themeWaitTimeout()
   371 void CpThemeControl::themeWaitTimeout()
   344 {
   372 {
   345     //If after this timeOut, theme change is still in progress,
   373     //If after this timeOut, theme change is still in progress,
   346     //show a processing dialog.
   374     //show a processing dialog.
   347     if(!mThemeChangeFinished)
   375     if(!mThemeChangeFinished){
   348     {
       
   349         if(!mWaitDialog) {
   376         if(!mWaitDialog) {
   350             mWaitDialog = new HbDialog();
   377             mWaitDialog = new HbDialog();
   351             mWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
   378             mWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
   352             mWaitDialog->setModal(false);
   379             mWaitDialog->setModal(false);
   353             mWaitDialog->setTimeout(HbPopup::NoTimeout);
   380             mWaitDialog->setTimeout(HbPopup::NoTimeout);
   354             //TODO: need localized text for Hb Dialog
       
   355             // Create and set HbLabel as content widget.
   381             // Create and set HbLabel as content widget.
   356             HbLabel *label = new HbLabel("Processing ...");
   382             QString processingText = hbTrId("txt_common_info_processing") + QString("...");
       
   383             HbLabel *label = new HbLabel(processingText);
   357             label->setAlignment(Qt::AlignCenter);
   384             label->setAlignment(Qt::AlignCenter);
   358             mWaitDialog->setContentWidget(label);
   385             mWaitDialog->setContentWidget(label);
   359         }
   386         }
   360        // as we do not need any signals, calling show() instead of open()
   387        // as we do not need any signals, calling show() instead of open()
   361        mWaitDialog->show();
   388        mWaitDialog->show();
   387     if(themeListModel && currentTheme) {
   414     if(themeListModel && currentTheme) {
   388         QModelIndex sourceIndex = mListModel->index(themeListModel->indexOf(*currentTheme),0);
   415         QModelIndex sourceIndex = mListModel->index(themeListModel->indexOf(*currentTheme),0);
   389         //set current index.
   416         //set current index.
   390         mThemeListView->themeList()->setCurrentIndex(sourceIndex, QItemSelectionModel::SelectCurrent);
   417         mThemeListView->themeList()->setCurrentIndex(sourceIndex, QItemSelectionModel::SelectCurrent);
   391     }
   418     }
   392 }
   419     else {
   393     
   420         mThemeListView->themeList()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Clear);
   394 
   421     }
   395 
   422 }
   396 
   423     
   397 
   424 
   398 
   425 
       
   426 
       
   427 
       
   428