diff -r a5692c68d772 -r 593f946f4fec controlpanelplugins/themeplugin/src/cpthemecontrol.cpp --- a/controlpanelplugins/themeplugin/src/cpthemecontrol.cpp Fri Jun 25 17:12:20 2010 +0800 +++ b/controlpanelplugins/themeplugin/src/cpthemecontrol.cpp Wed Sep 29 10:09:58 2010 +0800 @@ -17,12 +17,9 @@ /*! \class CpThemeControl - \brief CpThemeControl creates and controls two views for Theme Changer plugin and handles + \brief CpThemeControl creates and controls views for Theme Changer plugin and handles user interaction to preview and change the themes. - It creates a list view of the themes. When a list item is selected, it creates a preview - of the theme icon using a CpThemePreview class. - This class also connects to the theme server using the HbThemeChanger and sets the theme based on user interaction with the views. @@ -43,32 +40,19 @@ #include "cpthemecontrol.h" #include "cpthemelistview.h" -#include "cpthemepreview.h" #include "cpthemeinfo.h" #include "cpthemelistmodel.h" #include #include - -/*! - Helper function to fetch the main window. -*/ - -static HbMainWindow *mainWindow() -{ - QList< HbMainWindow* > mainWindows = hbInstance->allMainWindows(); - if (!mainWindows.isEmpty()) { - return mainWindows.front(); - } - return 0; -} +//time out time before showing a processing dialog. +static const int KThemeChangeTimeOutMilliSeconds = 2000; /*! constructor. */ CpThemeControl::CpThemeControl(): mThemeListView(0), - mThemePreview(0), mThemeChanger(0), mListModel(0), mThemeChangeFinished(false), @@ -88,7 +72,7 @@ /*! - destorys the list view, preview and theme changer objects. + destorys the list view and theme changer objects. */ CpThemeControl::~CpThemeControl() { @@ -98,16 +82,12 @@ delete mThemeChanger; mThemeChanger = 0; - delete mThemePreview; - mThemePreview = 0; - delete mWaitDialog; mWaitDialog = 0; } /*! - Creates the theme list view. Gets the themes, creates a model based on - theme names, icons, and icon paths and sets the list model. + Creates the theme list view. Gets the themes, creates a model and sets the list model. */ void CpThemeControl::createThemeList() { @@ -120,14 +100,14 @@ // Set the model for theme list. mThemeListView->setModel(mListModel); - mThemeListView->themeList()->setSelectionMode(HbAbstractItemView::SingleSelection); setActiveThemeIndex(); + //connect to signal for selecting a list item. + connect(mThemeListView,SIGNAL(newThemeSelected(QModelIndex)), + this,SLOT(newThemeSelected(QModelIndex))); - //connect to signal for selecting a list item. - connect(mThemeListView,SIGNAL(newThemeSelected(const QModelIndex&)), - this,SLOT(newThemeSelected(const QModelIndex&))); + connect(mThemeListView, SIGNAL(oviClicked()), this, SLOT(getOviTheme())); //handle signal for list view closing. (e.g Back softkey pressed) connect(mThemeListView,SIGNAL(aboutToClose()), @@ -188,83 +168,35 @@ //theme even though another list item is selected. setActiveThemeIndex(); - // Figure out whether this is a URI and appropriately delegate - data = index.data(CpThemeListModel::ItemTypeRole); - if(data.isValid() && data.canConvert()) { - - CpThemeInfo::ThemeListItemType type = data.value(); - - switch (type) { - case CpThemeInfo::ThemeListItemType_URL: - //get the URL - data = index.data(CpThemeListModel::ItemDataRole); - if(data.isValid()) { - QString url = data.toString(); - // Launch the URL in the browser and - // continue to Preview if not successful - if (QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode))) { - return; - } - } - break; - - case CpThemeInfo::ThemeListItemType_APP: - break; - - default: - // do nothing - qt_noop(); - } - } - //get the theme name. data = index.data(Qt::DisplayRole); if(data.isValid()) { themeInfo.setName(data.toString()); } - //get theme icon. - data = index.data(Qt::DecorationRole); + //get theme path + data = index.data(CpThemeListModel::ItemDataRole); if(data.isValid()) { - themeInfo.setIcon(data.value()); - } - - data = index.data(CpThemeListModel::PortraitPreviewRole); - if(data.isValid()) { - themeInfo.setPortraitPreviewIcon(data.value()); - } - - data = index.data(CpThemeListModel::LandscapePreviewRole); - if(data.isValid()) { - themeInfo.setLandscapePreviewIcon(data.value()); + themeInfo.setItemData(data.toString()); } - //Set up the theme preview and set it to - //the current view of main window. - HbMainWindow* mWindow = ::mainWindow(); - - if(!mThemePreview){ - mThemePreview = new CpThemePreview(themeInfo); - mWindow->addView(mThemePreview); - - connect(mThemePreview,SIGNAL(aboutToClose()), - this, SLOT(previewClosed())); + applyTheme(themeInfo); + +} - connect(mThemePreview, SIGNAL(applyTheme(const QString&)), - this, SLOT(themeApplied(const QString&))); - } else { - mThemePreview->setThemeInfo(themeInfo); - } - mThemePreview->setTitle(hbTrId("txt_cp_title_control_panel")); - - mWindow->setCurrentView(mThemePreview); - +void CpThemeControl::getOviTheme() +{ + QString url = QString("http://lr.ovi.mobi/store/themes"); + // Launch the URL in the browser and + // continue to Preview if not successful + QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); + } /*! Slot called when a Select key is pressed in theme preview view. */ -void CpThemeControl::themeApplied(const QString& theme) +void CpThemeControl::applyTheme(const CpThemeInfo& theme) { QThread::currentThread()->setPriority(QThread::HighPriority); @@ -273,36 +205,17 @@ //Start a timer. If theme change takes more than 1 seconds, //we will show a dialog (mWaitDialog) until theme change //is done (themeChangeFinished is called). - QTimer::singleShot(1000, this, SLOT(themeWaitTimeout())); + QTimer::singleShot(KThemeChangeTimeOutMilliSeconds, this, SLOT(themeWaitTimeout())); mThemeChangeFinished = false; } else { //theme change failed, go back to control panel. - previewClosed(); - triggerThemeListClose(); + setActiveThemeIndex(); } } /*! - Slot called when the theme preview view is closed. -*/ -void CpThemeControl::previewClosed() -{ - //The theme preview closed, go back - //to theme list view. - HbMainWindow* mainWindow = ::mainWindow(); - mainWindow->removeView(mThemePreview); - mThemePreview->deleteLater(); - mThemePreview = 0; - - //reset the current index to active theme, so that the selection remains on current - //theme even though another list item is selected. - setActiveThemeIndex(); - mainWindow->setCurrentView(mThemeListView); -} - -/*! Slot for when the theme list view is closed. Ownership of the theme list was given to control panel, so the class won't delete it. @@ -310,9 +223,6 @@ void CpThemeControl::themeListClosed() { mThemeListView = 0; - - delete mThemePreview; - mThemePreview = 0; } /*! @@ -331,12 +241,7 @@ if(mWaitDialog && mWaitDialog->isVisible()) { mWaitDialog->hide(); } - - previewClosed(); - //ask the themelistview to close. Control Panel will - //take care of removing it from window. - triggerThemeListClose(); - + setActiveThemeIndex(); QThread::currentThread()->setPriority(QThread::NormalPriority); } @@ -344,16 +249,15 @@ { //If after this timeOut, theme change is still in progress, //show a processing dialog. - if(!mThemeChangeFinished) - { + if(!mThemeChangeFinished){ if(!mWaitDialog) { mWaitDialog = new HbDialog(); mWaitDialog->setDismissPolicy(HbPopup::NoDismiss); mWaitDialog->setModal(false); mWaitDialog->setTimeout(HbPopup::NoTimeout); - //TODO: need localized text for Hb Dialog // Create and set HbLabel as content widget. - HbLabel *label = new HbLabel("Processing ..."); + QString processingText = hbTrId("txt_common_info_processing") + QString("..."); + HbLabel *label = new HbLabel(processingText); label->setAlignment(Qt::AlignCenter); mWaitDialog->setContentWidget(label); } @@ -389,6 +293,9 @@ //set current index. mThemeListView->themeList()->setCurrentIndex(sourceIndex, QItemSelectionModel::SelectCurrent); } + else { + mThemeListView->themeList()->setCurrentIndex(QModelIndex(), QItemSelectionModel::Clear); + } }