src/hbapps/hbthemechanger/settingsview.cpp
changeset 7 923ff622b8b9
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbApps module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <hbmainwindow.h>
       
    27 #include <hbaction.h>
       
    28 #include <hbtoolbar.h>
       
    29 #include <hbdataform.h>
       
    30 #include <hbdataformmodel.h>
       
    31 #include <hbdataformmodelitem.h>
       
    32 #include <QGraphicsLinearLayout>
       
    33 #include <hbthemeutils_p.h>
       
    34 #include <hbcombobox.h>
       
    35 #include <hbmessagebox.h>
       
    36 #include "settingsview.h"
       
    37 
       
    38 /**
       
    39  * Constructor
       
    40  */
       
    41 SettingsView::SettingsView(const QStringList &themes, HbMainWindow *mainWindow, HbView* parent): HbView(parent),
       
    42                                                                                                  mThemes(themes)
       
    43 {
       
    44     mMainWindow = mainWindow;
       
    45     mParentView = parent;
       
    46 
       
    47     for(int i=0;i<mThemes.count();i++) {
       
    48         mThemeUiNames += QDir(mThemes[i]).dirName();
       
    49     }
       
    50     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
       
    51 
       
    52     this->setTitle(tr("Settings"));
       
    53 
       
    54     mDataForm = new HbDataForm(this);
       
    55     HbDataFormModel *model = new HbDataFormModel(this);
       
    56 
       
    57     mBaseThemeSetting = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, tr("Base Theme"));
       
    58     mDefaultThemeSetting = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, tr("Default Theme"));
       
    59     mPriorityThemeSetting = model->appendDataFormItem(HbDataFormModelItem::TextItem, tr("Priority Theme"));
       
    60     mDataForm->setModel(model);
       
    61 
       
    62     loadSettings();
       
    63 
       
    64     layout->addItem(mDataForm);
       
    65 
       
    66     HbAction *act = new HbAction(tr("Save"));
       
    67     connect(act, SIGNAL(triggered()), this, SLOT(saveSettings()));
       
    68     this->toolBar()->addAction(act);
       
    69     act = new HbAction(tr("Cancel"));
       
    70     connect(act, SIGNAL(triggered()), this, SLOT(cancel()));
       
    71     this->toolBar()->addAction(act);
       
    72     act = new HbAction(Hb::BackNaviAction);
       
    73     connect(act, SIGNAL(triggered()), this, SLOT(cancel()));
       
    74     this->setNavigationAction(act);
       
    75 
       
    76     this->setLayout(layout);
       
    77 
       
    78     mMainWindow->addView(this);
       
    79 }
       
    80 
       
    81 /**
       
    82  * Destructor
       
    83  */
       
    84 SettingsView::~SettingsView()
       
    85 {
       
    86     delete mDataForm;
       
    87 }
       
    88 
       
    89 void SettingsView::loadSettings()
       
    90 {
       
    91     mBaseThemeSetting->setContentWidgetData("items",mThemeUiNames);
       
    92     mBaseThemeSetting->setContentWidgetData("selected", mThemes.indexOf(HbThemeUtils::getThemeSetting(HbThemeUtils::BaseThemeSetting)));
       
    93     mDefaultThemeSetting->setContentWidgetData("items",mThemeUiNames);
       
    94     mDefaultThemeSetting->setContentWidgetData("selected", mThemes.indexOf(HbThemeUtils::getThemeSetting(HbThemeUtils::DefaultThemeSetting)));
       
    95     mPriorityThemeSetting->setContentWidgetData("text",HbThemeUtils::getThemeSetting(HbThemeUtils::OperatorNameSetting));
       
    96 }
       
    97 
       
    98 void SettingsView::saveSettings()
       
    99 {
       
   100     HbThemeUtils::setThemeSetting(HbThemeUtils::BaseThemeSetting, mThemes[mBaseThemeSetting->contentWidgetData("selected").toInt()]);
       
   101     HbThemeUtils::setThemeSetting(HbThemeUtils::DefaultThemeSetting, mThemes[mDefaultThemeSetting->contentWidgetData("selected").toInt()]);
       
   102     HbThemeUtils::setThemeSetting(HbThemeUtils::OperatorNameSetting, mPriorityThemeSetting->contentWidgetData("text").toString());
       
   103     loadSettings();
       
   104 #ifdef Q_OS_SYMBIAN
       
   105     HbMessageBox::information(tr("Please reboot the device to apply the changes."));
       
   106 #else
       
   107     HbMessageBox::information(tr("Please restart the Hb application to apply the changes."));
       
   108 #endif
       
   109     mMainWindow->setCurrentView(mParentView);
       
   110 }
       
   111 
       
   112 void SettingsView::cancel()
       
   113 {
       
   114     loadSettings();
       
   115     mMainWindow->setCurrentView(mParentView);
       
   116 }