src/hbapps/hbthemechanger/themeselectionlist.cpp
changeset 5 627c4a0fd0e7
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    29 #include <hbinstance.h>
    29 #include <hbinstance.h>
    30 #include <hbmenu.h>
    30 #include <hbmenu.h>
    31 #include <hbaction.h>
    31 #include <hbaction.h>
    32 #include <hbicon.h>
    32 #include <hbicon.h>
    33 #include <hblistwidgetitem.h>
    33 #include <hblistwidgetitem.h>
       
    34 #include <restricted/hbthemeservices_r.h>
    34 #include <QDebug>
    35 #include <QDebug>
    35 #include <QTime>
    36 #include <QTime>
    36 #include <QThread>
    37 #include <QThread>
    37 
    38 
    38 #include "themeselectionlist.h"
    39 #include "themeselectionlist.h"
    39 #include "themechangerdefs.h"
    40 #include "themechangerdefs.h"
    40 
    41 
    41 /**
    42 /**
    42  * Constructor
    43  * Constructor
    43  */
    44  */
    44 ThemeSelectionList::ThemeSelectionList(
    45 ThemeSelectionList::ThemeSelectionList(): 
    45 #ifdef Q_OS_SYMBIAN
       
    46     ThemeClientSymbian* client
       
    47 #else
       
    48     ThemeClientQt* client
       
    49 #endif
       
    50                         ): 
       
    51                         oldItemIndex(-1),
    46                         oldItemIndex(-1),
    52                         themelist(new HbListWidget(this)),
    47                         themelist(new HbListWidget(this)),
    53                         rightMark(new HbIcon(QString("qtg_small_tick"))),
    48                         rightMark(new HbIcon(QString("qtg_small_tick"))),
    54                         noMark(new HbIcon(QString(""))),
    49                         noMark(new HbIcon(QString("")))
    55                         client(client)
       
    56 {
    50 {
    57     connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *)));
    51     connect(themelist, SIGNAL(activated(HbListWidgetItem *)),this, SLOT(setChosen(HbListWidgetItem *)));
    58     setWidget(themelist);
    52     setWidget(themelist);
    59 
    53 
    60     // Automatic updation of the themelist when some theme is installed or uninstalled
    54     // Automatic updation of the themelist when some theme is installed or uninstalled
    81 ThemeSelectionList::~ThemeSelectionList()
    75 ThemeSelectionList::~ThemeSelectionList()
    82 {
    76 {
    83     // Set the theme to the applied theme before exiting.
    77     // Set the theme to the applied theme before exiting.
    84     setChosen(themelist->item(oldItemIndex));
    78     setChosen(themelist->item(oldItemIndex));
    85     delete noMark;
    79     delete noMark;
    86 
       
    87     noMark=NULL;
    80     noMark=NULL;
    88     delete rightMark;
    81     delete rightMark;
    89     rightMark=NULL;
    82     rightMark=NULL;
    90 
    83 
    91     // Reset the item view
    84     // Reset the item view
    92     themelist->reset();
    85     themelist->reset();
    93     delete themelist;
    86     delete themelist;
    94     themelist=NULL;
    87     themelist=NULL;
       
    88     
       
    89     // Delete preview thubnails
       
    90     qDeleteAll(thumbnails);
       
    91     thumbnails.clear();
    95 }
    92 }
    96 
    93 
    97 
    94 
    98 /**
    95 /**
    99  * displayThemes
    96  * displayThemes
   114                 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder);
   111                 QDir iconThemePath(root.path()+"/themes/icons/"+themefolder);
   115                 if(iconThemePath.exists("index.theme")) {
   112                 if(iconThemePath.exists("index.theme")) {
   116                     QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
   113                     QSettings iniSetting(iconThemePath.path()+"/index.theme",QSettings::IniFormat);
   117                     iniSetting.beginGroup("Icon Theme");
   114                     iniSetting.beginGroup("Icon Theme");
   118                     QString hidden = iniSetting.value("Hidden").toString();
   115                     QString hidden = iniSetting.value("Hidden").toString();
   119                     QString name = iniSetting.value("Name").toString();
       
   120                     iniSetting.endGroup();
   116                     iniSetting.endGroup();
   121                     if((hidden == "true") ||( hidden == "")||(name!=themefolder) ) {
   117                     if((hidden == "true") ||( hidden == "")) {
   122                         iconthemeslist.removeOne(themefolder);
   118                         iconthemeslist.removeOne(themefolder);
   123                     }
   119                     }
   124                 }
   120                 }
   125                 else {
   121                 else {
   126                      iconthemeslist.removeOne(themefolder);
   122                      iconthemeslist.removeOne(themefolder);
   127                 }
   123                 }
   128             
   124             
   129             }
   125             }
   130             if(!entryAdded){
   126             if(!entryAdded){
   131                 iconthemeslist.insert(0,"hbdefault"); //adding one default entry
   127                 //adding one default entry
       
   128                 HbListWidgetItem *item = new HbListWidgetItem();
       
   129                 item->setText("hbdefault");
       
   130                 item->setSecondaryText("hbdefault");
       
   131                 QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg");                    
       
   132                 HbIcon *icon = new HbIcon(thumbPath);
       
   133                 thumbnails.append(icon);
       
   134                 item->setIcon(*icon);                                
       
   135                 if (HbInstance::instance()->theme()->name() == "hbdefault") {
       
   136                     item->setSecondaryIcon(*rightMark);
       
   137                     themelist->addItem(item);                
       
   138                     oldItemIndex=themelist->count()-1;
       
   139                     themelist->setCurrentRow(oldItemIndex);                    
       
   140                 } else {
       
   141                     item->setSecondaryIcon(*noMark);
       
   142                     themelist->addItem(item);                
       
   143                 }
   132                 entryAdded = true;
   144                 entryAdded = true;
   133             }
   145             }
   134             list=iconthemeslist;
   146             list=iconthemeslist;
   135             for (int i=0; i <list.count();i++) {
   147             for (int i=0; i <list.count();i++) {
   136                 // populate theme list with existing themes
   148                 // populate theme list with existing themes
   137                 if((HbInstance::instance()->theme()->name())==(list.at(i))) { 
   149                 HbListWidgetItem *item = new HbListWidgetItem();
   138                     themelist->addItem(*rightMark,list.at(i));
   150 
       
   151                 QSettings iniSetting(root.path()+"/themes/icons/"+list.at(i)+"/index.theme",QSettings::IniFormat);
       
   152                 iniSetting.beginGroup("Icon Theme");
       
   153                 QString name = iniSetting.value("Name").toString();
       
   154                 iniSetting.endGroup();
       
   155                 item->setText(name);
       
   156 
       
   157                 item->setSecondaryText(root.path()+"/themes/icons/"+list.at(i));
       
   158                 QString thumbPath(root.path()+"/themes/icons/"+list.at(i)+"/scalable/qtg_graf_theme_preview_thumbnail.svg");
       
   159                 HbIcon *icon = new HbIcon(thumbPath);
       
   160                 thumbnails.append(icon);
       
   161                 item->setIcon(*icon);
       
   162                 
       
   163                 
       
   164                 if (QFileInfo(HbThemeServices::themePath()) == QFileInfo(item->secondaryText())) {
       
   165                     item->setSecondaryIcon(*rightMark);
       
   166                     themelist->addItem(item);
   139                     oldItemIndex=themelist->count()-1;
   167                     oldItemIndex=themelist->count()-1;
   140                     themelist->setCurrentRow(oldItemIndex);
   168                     themelist->setCurrentRow(oldItemIndex);
   141                 }
   169                 }
   142                 else {
   170                 else {
   143                     themelist->addItem(*noMark,list.at(i));
   171                     item->setSecondaryIcon(*noMark);
       
   172                     themelist->addItem(item);
   144                 }
   173                 }
   145             }
   174             }
   146         }
   175         }
   147     }
   176     }
   148     //    else{//add a case for no theme ,make hbdefault entry
   177     //    else{//add a case for no theme ,make hbdefault entry
   149     if(!themePresent) {
   178     if(!themePresent) {
   150             QStringList defaultList;
   179             QStringList defaultList;
   151             defaultList.insert(0,"hbdefault"); //adding one default entry
   180             defaultList.insert(0,"hbdefault"); //adding one default entry
   152             themelist->addItem(*rightMark,defaultList.at(0));
   181             HbListWidgetItem *item = new HbListWidgetItem();
       
   182             item->setText(defaultList.at(0));
       
   183             item->setSecondaryText(defaultList.at(0));
       
   184             QString thumbPath(":/themes/icons/hbdefault/scalable/qtg_graf_theme_preview_thumbnail.svg");                    
       
   185             HbIcon *icon = new HbIcon(thumbPath);
       
   186             thumbnails.append(icon);
       
   187             item->setIcon(*icon);            
       
   188             item->setSecondaryIcon(*rightMark);
       
   189             themelist->addItem(item);
   153             QString themeName=HbInstance::instance()->theme()->name();
   190             QString themeName=HbInstance::instance()->theme()->name();
   154             if (themeName != "hbdefault")
   191             if (themeName != "hbdefault")
   155             {
   192             {
   156                 if (!client->isConnected()) {
   193                 emit newThemeSelected("hbdefault");
   157                     bool success = client->connectToServer();
       
   158                     if (success) {
       
   159                         emit newThemeSelected("hbdefault");
       
   160                     }
       
   161                 }
       
   162                 else {
       
   163                     emit newThemeSelected("hbdefault");
       
   164                 }
       
   165             }
   194             }
   166 
       
   167         }
   195         }
   168 }
   196 }
   169 
   197 
   170 /**
   198 /**
   171  * setChosen
   199  * setChosen
   172  */
   200  */
   173 void ThemeSelectionList::setChosen(HbListWidgetItem *item)
   201 void ThemeSelectionList::setChosen(HbListWidgetItem *item)
   174 {
   202 {
   175     QString str=item->text();
       
   176 
       
   177 #ifdef THEME_CHANGER_TRACES
   203 #ifdef THEME_CHANGER_TRACES
   178     qDebug() << "ThemeSelectionList::Setchosen with ThemeName: "<<str;
   204     qDebug() << "ThemeSelectionList::Setchosen with ThemeName: "<<item->secondaryText();
   179 #endif
   205 #endif
   180     if(iCurrentTheme != str ) {
   206     if(iCurrentTheme != item->secondaryText()) {
   181 #ifdef THEME_CHANGER_TIMER_LOG
   207 #ifdef THEME_CHANGER_TIMER_LOG
   182         timer.start();
   208         timer.start();
   183         qDebug() << "Selected theme: " << str;
   209         qDebug() << "Selected theme: " << item->secondaryText();
   184 #endif
   210 #endif
   185         iCurrentTheme = str;
   211         iCurrentTheme = item->secondaryText();
   186         if (!client->isConnected()) {
   212         QThread::currentThread()->setPriority(QThread::HighPriority);
   187             bool success = client->connectToServer();
   213         emit newThemeSelected(item->secondaryText());
   188             if (success) {
       
   189                 QThread::currentThread()->setPriority(QThread::HighPriority);
       
   190                 emit newThemeSelected(str);
       
   191             }
       
   192         }
       
   193         else {
       
   194             QThread::currentThread()->setPriority(QThread::HighPriority);
       
   195             emit newThemeSelected(str); 
       
   196         }
       
   197     }
   214     }
   198     else
   215     else
   199     {
   216     {
   200         applySelection(); //double tap //put a tick
   217         applySelection(); //double tap //put a tick
   201     }
   218     }
   206  * applySelection
   223  * applySelection
   207  */
   224  */
   208 void ThemeSelectionList::applySelection()
   225 void ThemeSelectionList::applySelection()
   209 {
   226 {
   210     if(oldItemIndex!=themelist->currentRow()) {
   227     if(oldItemIndex!=themelist->currentRow()) {
   211         themelist->setIcon(themelist->currentRow(),*rightMark);
   228         HbListWidgetItem *item = themelist->item(themelist->currentRow()); 
       
   229         item->setSecondaryIcon(*rightMark);
   212         if(oldItemIndex >= 0) {
   230         if(oldItemIndex >= 0) {
   213             themelist->setIcon(oldItemIndex,*noMark);
   231             HbListWidgetItem *olditem = themelist->item(oldItemIndex); 
       
   232             olditem->setSecondaryIcon(*noMark);
   214         }
   233         }
   215         oldItemIndex = themelist->currentRow();
   234         oldItemIndex = themelist->currentRow();
   216     }
   235     }
   217 }
   236 }
   218 
   237 
   246 /**
   265 /**
   247  * sendThemeName
   266  * sendThemeName
   248  */
   267  */
   249 void ThemeSelectionList::sendThemeName(const QString& name)
   268 void ThemeSelectionList::sendThemeName(const QString& name)
   250 {
   269 {
   251     client->changeTheme(name);
   270     HbThemeServices::setTheme(name);
   252 }
   271 }
   253 
   272 
   254 /**
   273 /**
   255  * \internal
   274  * \internal
   256  */
   275  */
   279 void ThemeSelectionList::processWhenIdle()
   298 void ThemeSelectionList::processWhenIdle()
   280 {    
   299 {    
   281     qDebug() << "Theme changed applied in " << timer.elapsed() << " msec";
   300     qDebug() << "Theme changed applied in " << timer.elapsed() << " msec";
   282     idleTimer->stop();
   301     idleTimer->stop();
   283     QThread::currentThread()->setPriority(QThread::NormalPriority);    
   302     QThread::currentThread()->setPriority(QThread::NormalPriority);    
   284     if (!client->isConnected()) {
       
   285         client->connectToServer();
       
   286     }
       
   287 }
   303 }
   288 
   304 
   289 void ThemeSelectionList::themeChanged()
   305 void ThemeSelectionList::themeChanged()
   290 {
   306 {
   291     idleTimer->start(0);
   307     idleTimer->start(0);