stateproviders/ftustateprovider/src/ftuwizardmenustate.cpp
changeset 0 c464cd7e2753
child 2 66c26770985f
equal deleted inserted replaced
-1:000000000000 0:c464cd7e2753
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of the wizard menu state.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ftuwizardmenustate.h"
       
    20 #include "ftucontentservice.h"
       
    21 #include <ftuwizard.h>
       
    22 
       
    23 #include <hbmainwindow.h>
       
    24 #include <hbview.h>
       
    25 #include <hblabel.h>
       
    26 #include <hbicon.h>
       
    27 #include <hbinstance.h>
       
    28 #include <hblistview.h>
       
    29 
       
    30 #include <hbdocumentloader.h>
       
    31 
       
    32 #include <QStandardItemModel>
       
    33 #include <QDate>
       
    34 #include <hbaction.h>
       
    35 
       
    36 const int progressCompelete = 100;
       
    37 const char* emptyLine = " ";
       
    38 
       
    39 #define WMS_LOG qDebug() << "ftu:FtuWizardMenuState"
       
    40 
       
    41 const char *FTUSTATEPROVIDER_DOCML = ":/xml/ftustateprovider.docml";
       
    42 const char *TOC_VIEW = "tocView";
       
    43 const char *TOC_INFOTEXT_LABEL = "tocInfoTextLabel";
       
    44 const char *TOC_LIST_VIEW = "tocListView";
       
    45 
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // FtuWizardMenuState::FtuWizardMenuState
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 FtuWizardMenuState::FtuWizardMenuState(QState *parent) :
       
    53     QState(parent),
       
    54     mMainWindow(NULL),
       
    55     mTocView(NULL),
       
    56     mInfoText(NULL),
       
    57     mListView(NULL),
       
    58 	mDocumentLoader(NULL),
       
    59     mModel(NULL)   
       
    60 {
       
    61     mMainWindow = hbInstance->allMainWindows().at(0);
       
    62     mModel = new QStandardItemModel(this);
       
    63 
       
    64 	mDocumentLoader = new HbDocumentLoader();
       
    65 	bool ok = false;
       
    66 	mDocumentLoader->load(FTUSTATEPROVIDER_DOCML, &ok);
       
    67 	QGraphicsWidget *widget = mDocumentLoader->findWidget(TOC_VIEW);
       
    68 	Q_ASSERT_X(ok && (widget != 0), "ftustateprovider", "invalid DocML file");
       
    69 	mTocView = qobject_cast<HbView*>(widget);
       
    70 
       
    71     mTocView->setTitle(qtTrId("txt_ftu_title_setup"));
       
    72 
       
    73 	mMainWindow->addView(mTocView);
       
    74     // Set as initial view.
       
    75     mMainWindow->setCurrentView(mTocView);
       
    76     mExitAction = new HbAction(Hb::QuitNaviAction, this);
       
    77     mTocView->setNavigationAction(mExitAction);
       
    78     QObject::connect( mExitAction, SIGNAL(triggered()), this, SLOT(exitApp()));
       
    79 }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // FtuWizardMenuState::~FtuWizardMenuState
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 FtuWizardMenuState::~FtuWizardMenuState()
       
    86 {
       
    87 	if(mModel)
       
    88 	{
       
    89 		delete mModel;
       
    90 	}
       
    91 	delete mDocumentLoader;
       
    92 }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // FtuWizardMenuState::onEntry
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void FtuWizardMenuState::onEntry(QEvent *event)
       
    99 {    
       
   100     WMS_LOG << "::onEntry";
       
   101     QState::onEntry(event);
       
   102 
       
   103     if(!mInfoText)
       
   104     {    
       
   105         createInfoText();
       
   106     }    
       
   107     if(!mListView)
       
   108     {
       
   109         createTocList();
       
   110     }
       
   111 
       
   112     // If this is not the current view, we're getting back from plugin view
       
   113     if(mMainWindow->currentView() != mTocView)
       
   114     {
       
   115         mMainWindow->setCurrentView(mTocView, true);
       
   116     }
       
   117 
       
   118     mMainWindow->show();
       
   119 }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // FtuWizardMenuState::onExit
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 void FtuWizardMenuState::onExit(QEvent *event)
       
   126 {
       
   127     QState::onExit(event);
       
   128 }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // FtuWizardMenuState::content
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 FtuContentService *FtuWizardMenuState::content() const
       
   135 {
       
   136     return property(FTU_CONTENT_SERVICE_KEY).value<FtuContentService*>();
       
   137 }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // FtuWizardMenuState::updatedAsString
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 QString FtuWizardMenuState::updatedAsString(const QDate& date) const
       
   144 {
       
   145     QString status;
       
   146 
       
   147     if(date == QDate().currentDate() )
       
   148     { 	
       
   149         status.append(qtTrId("txt_ftu_list_update_today"));
       
   150     }
       
   151     else
       
   152     {
       
   153         status.append(qtTrId("txt_ftu_list_update_date").arg(date.toString()));
       
   154     }
       
   155     return status;
       
   156 }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // FtuWizardMenuState::addWizardToListModel
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void FtuWizardMenuState::addWizardToListModel(int aIndex)
       
   163 {    
       
   164     WMS_LOG << "::addWizardToListModel idx : " << aIndex;
       
   165     FtuContentService* ftuContentService = content();
       
   166 
       
   167     FtuWizard* addedWizard = ftuContentService->wizard(aIndex);
       
   168     if(addedWizard)
       
   169     {    
       
   170         // Connect for progress updates.
       
   171         connect(addedWizard, SIGNAL(progressUpdated(FtuWizard *, bool, int)), 
       
   172                 this, SLOT(updateProgress(FtuWizard *, bool, int)));
       
   173 
       
   174     	const FtuWizardSetting& settings = addedWizard->wizardSettings();
       
   175 	    QStandardItem* newItem = new QStandardItem();
       
   176 	    HbIcon icon (settings.mTocDefaultIcon.absoluteFilePath());
       
   177         QStringList data;
       
   178         data << settings.mTocLabel;
       
   179         QDate date = addedWizard->wizardCompletedDate();
       
   180         if(date.isNull())
       
   181         {
       
   182             data << emptyLine;
       
   183         }
       
   184         else
       
   185         {
       
   186             data << updatedAsString(date);
       
   187         }
       
   188 
       
   189         newItem->setBackground(QBrush(Qt::lightGray));
       
   190         newItem->setData(icon, Qt::DecorationRole);
       
   191         newItem->setData(QVariant(data), Qt::DisplayRole);
       
   192 
       
   193         mModel->appendRow(newItem);        
       
   194     }
       
   195 }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // FtuWizardMenuState::createTocList
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void FtuWizardMenuState::createTocList()
       
   202 {
       
   203     if (!mListView)
       
   204     {
       
   205 		mListView = qobject_cast<HbListView *>(mDocumentLoader->findWidget(
       
   206 															TOC_LIST_VIEW));
       
   207 	    connect(mListView,
       
   208                 SIGNAL(activated(const QModelIndex)),
       
   209                 this,
       
   210                 SLOT(activateWizard(const QModelIndex)));
       
   211 
       
   212         mListView->setModel(mModel);
       
   213     }
       
   214 }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // FtWizardMenuState::createInfoText
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 void FtuWizardMenuState::createInfoText()
       
   221 {
       
   222     mInfoText = qobject_cast<HbLabel *>(mDocumentLoader->findWidget(TOC_INFOTEXT_LABEL));                               
       
   223     mInfoText->setPlainText(qtTrId("txt_ftu_subtitle_toc"));
       
   224 }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // FtuWizardMenuState::activateWizard
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void FtuWizardMenuState::activateWizard(const QModelIndex index)
       
   231 {
       
   232     // Set the active wizard index
       
   233     content()->setActiveWizard(index.row());
       
   234     // signal to activated state
       
   235     emit wizardSelected();
       
   236 }
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // FtuWizardMenuState::updateProgress
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void FtuWizardMenuState::updateProgress(FtuWizard *caller, bool show, 
       
   243                                            int progress)
       
   244 {
       
   245     Q_UNUSED(show)
       
   246     QList<FtuWizard*> wizards = content()->wizards();
       
   247     int index = -1;
       
   248     
       
   249     // Get the index of the wizard
       
   250     for(int i = 0 ; i < wizards.size() ; ++i)
       
   251     {
       
   252         if(caller == wizards[i])
       
   253         {
       
   254             WMS_LOG << "::updateProgress wizard found at: " << i;
       
   255             index = i;
       
   256         }
       
   257     }
       
   258     if(index != -1)
       
   259     {  
       
   260         QStringList data;
       
   261         data << wizards[index]->wizardSettings().mTocLabel;           
       
   262         
       
   263         if(progress < progressCompelete)
       
   264         {
       
   265             QString progressStr;
       
   266             QString progressNumber;
       
   267             progressNumber.setNum(progress);
       
   268             progressStr = qtTrId("txt_ftu_list_progress_status").arg(progressNumber);
       
   269             data << progressStr;
       
   270         }
       
   271         else
       
   272         {         
       
   273             QDate date = wizards[index]->wizardCompletedDate();
       
   274             data << updatedAsString(date);            
       
   275         }
       
   276         mModel->item(index)->setData(QVariant(data), Qt::DisplayRole);
       
   277     }
       
   278 }
       
   279 
       
   280 void FtuWizardMenuState::exitApp()
       
   281     {
       
   282     qApp->exit();
       
   283     }