controlpanelplugins/themeplugin/src/cpthemecontrol.cpp
changeset 24 f5dfdd5e4a1b
parent 17 4a9568303383
child 25 19394c261aa5
equal deleted inserted replaced
17:4a9568303383 24:f5dfdd5e4a1b
    31 #include <QString>
    31 #include <QString>
    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 
    37 
    37 #include <hbmainwindow.h>
    38 #include <hbmainwindow.h>
    38 #include <hbinstance.h>
    39 #include <hbinstance.h>
    39 #include "cpthemechanger.h"
    40 #include "cpthemechanger.h"
    40 
    41 
    41 #include "cpthemecontrol.h"
    42 #include "cpthemecontrol.h"
    42 #include "cpthemelistview.h"
    43 #include "cpthemelistview.h"
    43 #include "cpthemepreview.h"
    44 #include "cpthemepreview.h"
    44 
    45 
    45 static const QString KPlaceholderPreview = ":/image/themePreview.svg";
    46 #include <hbdialog.h>
       
    47 #include <hblabel.h>
       
    48 
    46 
    49 
    47 /*!
    50 /*!
    48 	Helper function to fetch the main window.
    51 	Helper function to fetch the main window.
    49 */
    52 */
    50 
    53 
    63 CpThemeControl::CpThemeControl(): mThemeListView(0), 
    66 CpThemeControl::CpThemeControl(): mThemeListView(0), 
    64     mThemePreview(0), 
    67     mThemePreview(0), 
    65     mThemeChanger(0),
    68     mThemeChanger(0),
    66     mListModel(0),
    69     mListModel(0),
    67     mSortModel(0),
    70     mSortModel(0),
    68     mIdleTimer(0)
    71     mThemeChangeFinished(false),
       
    72     mWaitDialog(0)
    69 {
    73 {
    70     mThemeChanger = new CpThemeChanger();
    74     mThemeChanger = new CpThemeChanger();
    71    
       
    72        
    75        
    73     QTranslator *translator = new QTranslator(this);
    76     QTranslator *translator = new QTranslator(this);
    74     QString lang = QLocale::system().name();
    77     QString lang = QLocale::system().name();
    75     QString path = "Z:/resource/qt/translations/";
    78     QString path = "Z:/resource/qt/translations/";
    76     translator->load("control_panel_" + lang, path);
    79     translator->load("control_panel_" + lang, path);
    77     qApp->installTranslator(translator);
    80     qApp->installTranslator(translator);
    78     
    81     
    79     mIdleTimer = new QTimer(this);
       
    80     connect(mIdleTimer, SIGNAL(timeout()), this, SLOT(themeChangeTimeout()));
       
    81     connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChangeFinished()));
    82     connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(themeChangeFinished()));
    82    
    83    
    83 }
    84 }
    84 
    85 
    85 
    86 
    86 
       
    87 /*!
    87 /*!
    88 	destorys the list view, preview and theme changer objects.
    88 	destorys the list view, preview and theme changer objects.
    89 */
    89 */
    90 CpThemeControl::~CpThemeControl()
    90 CpThemeControl::~CpThemeControl()
    91 {
    91 {
    95     delete mThemeChanger;
    95     delete mThemeChanger;
    96     mThemeChanger = 0;
    96     mThemeChanger = 0;
    97 
    97 
    98     delete mThemePreview;
    98     delete mThemePreview;
    99     mThemePreview = 0;
    99     mThemePreview = 0;
       
   100     
       
   101     delete mWaitDialog;
       
   102     mWaitDialog = 0;
   100 }
   103 }
   101 
   104 
   102 /*!
   105 /*!
   103 	Creates the theme list view.  Gets the themes, creates a model based on
   106 	Creates the theme list view.  Gets the themes, creates a model based on
   104 	theme names, icons, and icon paths and sets the list model.
   107 	theme names, icons, and icon paths and sets the list model.
   215         connect(mThemePreview, SIGNAL(applyTheme(const QString&)),
   218         connect(mThemePreview, SIGNAL(applyTheme(const QString&)),
   216                 this, SLOT(themeApplied(const QString&)));
   219                 this, SLOT(themeApplied(const QString&)));
   217     } else {
   220     } else {
   218         mThemePreview->setThemeInfo(themeInfo);
   221         mThemePreview->setThemeInfo(themeInfo);
   219     }
   222     }
   220     //TODO: use qtTrId(text_id).
   223     mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel"));
   221     mThemePreview->setTitle(tr("Control Panel"));
       
   222 	  	
   224 	  	
   223     mWindow->setCurrentView(mThemePreview);
   225     mWindow->setCurrentView(mThemePreview);
   224 	
   226 	
   225 }
   227 }
   226 
   228 
   236     if (success) {
   238     if (success) {
   237         QThread::currentThread()->setPriority(QThread::HighPriority);  
   239         QThread::currentThread()->setPriority(QThread::HighPriority);  
   238         mThemeChanger->changeTheme(theme);
   240         mThemeChanger->changeTheme(theme);
   239         emit themeUpdated(mThemeChanger->currentTheme().name, mThemeChanger->currentTheme().icon);
   241         emit themeUpdated(mThemeChanger->currentTheme().name, mThemeChanger->currentTheme().icon);
   240     }
   242     }
   241 
   243     
   242     //Go back to control panel view. Close theme preview.
   244     //Start a timer. If theme change takes more than 1 seconds,
   243     previewClosed();
   245     //we will show a dialog (mWaitDialog) until theme change
   244     //ask the themelistview to close.  Control Panel will
   246     //is done (themeChangeFinished is called).
   245     //take care of removing it from window.
   247     QTimer::singleShot(1000, this, SLOT(themeWaitTimeout()));
   246     triggerThemeListClose();
   248         
   247 
   249     mThemeChangeFinished = false;
       
   250    
   248 }
   251 }
   249 
   252 
   250 /*!
   253 /*!
   251 	Slot called when the theme preview view is closed.
   254 	Slot called when the theme preview view is closed.
   252 */
   255 */
   286     mThemeListView->closeView();
   289     mThemeListView->closeView();
   287 }
   290 }
   288 
   291 
   289 void CpThemeControl::themeChangeTimeout()
   292 void CpThemeControl::themeChangeTimeout()
   290 {
   293 {
   291     mIdleTimer->stop();
   294     //Theme change is finished and idle timer has timed out,
       
   295     //so revert back the application priority to normal
       
   296     //and go back to control panel view.
       
   297     if(mWaitDialog && mWaitDialog->isVisible()) {
       
   298         mWaitDialog->hide();
       
   299     }
       
   300     
       
   301     previewClosed();
       
   302     //ask the themelistview to close.  Control Panel will
       
   303     //take care of removing it from window.
       
   304     triggerThemeListClose();
       
   305     
   292     QThread::currentThread()->setPriority(QThread::NormalPriority); 
   306     QThread::currentThread()->setPriority(QThread::NormalPriority); 
   293         
   307 }
       
   308 
       
   309 void CpThemeControl::themeWaitTimeout()
       
   310 {
       
   311     //If after this timeOut, theme change is still in progress,
       
   312     //show a processing dialog.
       
   313     if(!mThemeChangeFinished)
       
   314     {
       
   315         if(!mWaitDialog) {
       
   316             mWaitDialog = new HbDialog();
       
   317             mWaitDialog->setModal(false);
       
   318             mWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   319             //TODO: need localized text for Hb Dialog
       
   320             // Create and set HbLabel as content widget.
       
   321             HbLabel *label = new HbLabel("Processing ...");
       
   322             label->setAlignment(Qt::AlignCenter);
       
   323             mWaitDialog->setContentWidget(label);
       
   324         }
       
   325        // as we do not need any signals, calling show() instead of open()
       
   326        mWaitDialog->show();
       
   327     }
   294 }
   328 }
   295 
   329 
   296 void CpThemeControl::themeChangeFinished()
   330 void CpThemeControl::themeChangeFinished()
   297 {
   331 {
   298     mIdleTimer->start(0);
   332     //Theme change is done. Start an idle timer to let the UI
       
   333     //finish remaining tasks.
       
   334     QTimer::singleShot(0, this, SLOT(themeChangeTimeout()));
       
   335     mThemeChangeFinished = true;
       
   336     
   299 }
   337 }
   300 
   338 
   301 /*!
   339 /*!
   302  * Private function that sets the current index of theme list view to indicate
   340  * Private function that sets the current index of theme list view to indicate
   303  * the active theme.
   341  * the active theme.