homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hsappschecklist.cpp
changeset 69 87476091b3f5
parent 46 23b5d6a29cce
child 81 7dd137878ff8
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <hbaction.h>
    18 #include <hbaction.h>
    19 #include <hbinstance.h>
    19 #include <hbinstance.h>
    20 #include <hbview.h>
    20 #include <hbdialog.h>
    21 #include <hblistview.h>
    21 #include <hblistview.h>
    22 #include <hbdocumentloader.h>
    22 #include <hbdocumentloader.h>
    23 #include <hsmenuservice.h>
    23 #include <hsmenuservice.h>
    24 #include <hsmenuitemmodel.h>
    24 #include <hsmenuitemmodel.h>
    25 
    25 
    79 /*!
    79 /*!
    80  Constructor
    80  Constructor
    81  \retval void
    81  \retval void
    82  */
    82  */
    83 HsAppsCheckList::HsAppsCheckList() :
    83 HsAppsCheckList::HsAppsCheckList() :
    84     mView(0), mPreviousView(0), mActionConfirm(0), mListView(0), mModel(0),
    84     mAppsSelectDialog(0), mActionConfirm(0), mListView(0), mModel(0),
    85     mSortAttribute(AscendingNameHsSortAttribute)
    85     mSortAttribute(AscendingNameHsSortAttribute)
    86 {
    86 {
    87 }
    87 }
    88 
    88 
    89 /*!
    89 /*!
    99  \retval void
    99  \retval void
   100  */
   100  */
   101 void HsAppsCheckList::cleanUp()
   101 void HsAppsCheckList::cleanUp()
   102 {
   102 {
   103     //clean up
   103     //clean up
   104 
   104     if (mAppsSelectDialog) {
   105     qDeleteAll(mLoadedObjects);
   105         mAppsSelectDialog->close();
   106     mLoadedObjects.clear();
   106     }
   107     mListView = NULL;
   107 
   108     mView = NULL;
       
   109 
       
   110     delete mActionConfirm;
       
   111     mActionConfirm = NULL;
       
   112     delete mModel;
       
   113     mModel = NULL;
       
   114     mSortAttribute = AscendingNameHsSortAttribute;
   108     mSortAttribute = AscendingNameHsSortAttribute;
   115 }
   109 }
   116 
   110 
   117 /*!
   111 /*!
   118  Sets sort order for applications.
   112  Sets sort order for applications.
   125 
   119 
   126 /*!
   120 /*!
   127  Shows check box list with all application.
   121  Shows check box list with all application.
   128  \param sortAttribute order to sort applications.
   122  \param sortAttribute order to sort applications.
   129  */
   123  */
   130 #ifdef COVERAGE_MEASUREMENT
       
   131 #pragma CTC SKIP
       
   132 #endif //COVERAGE_MEASUREMENT
       
   133 void HsAppsCheckList::showAppsCheckboxList(HsSortAttribute sortOrder)
   124 void HsAppsCheckList::showAppsCheckboxList(HsSortAttribute sortOrder)
   134 {
   125 {
   135     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::showAppsCheckboxList");
   126     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::showAppsCheckboxList");
   136     if (!mModel) {
   127     if (!mModel) {
   137         mModel = HsMenuService::getAllApplicationsModel(sortOrder);
   128         mModel = HsMenuService::getAllApplicationsModel(sortOrder);
   138     }
   129     }
   139     // fills model with data
   130     // fills model with data
   140     // constucts controls such as checklist
   131     // constucts controls such as checklist
   141     constructControls();
   132     constructControls();
   142 
   133     
   143     // Add mListView to main window
   134     if (mAppsSelectDialog) {
   144     HbMainWindow *hbMainWindow = mainWindow();
   135         mAppsSelectDialog->setTimeout(HbPopup::NoTimeout);
   145 
   136         mAppsSelectDialog->setAttribute(Qt::WA_DeleteOnClose);
   146     // add confirm action
   137         mAppsSelectDialog->open(this,
   147     mView->setNavigationAction(mActionConfirm);
   138             SLOT(appsSelectionDialogFinished(HbAction*)));
   148 
   139     }
   149     hbMainWindow->addView(mView);
   140 
   150     // record the current view in order to activate it once done
       
   151     mPreviousView = hbMainWindow->currentView();
       
   152     hbMainWindow->setCurrentView(mView);
       
   153     hbMainWindow->show();
       
   154     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::showAppsCheckboxList");
   141     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::showAppsCheckboxList");
   155 }
   142 }
   156 #ifdef COVERAGE_MEASUREMENT
   143 
   157 #pragma CTC ENDSKIP
       
   158 #endif //COVERAGE_MEASUREMENT
       
   159 /*!
   144 /*!
   160  Construct contrlos.
   145  Construct contrlos.
   161  */
   146  */
   162 void HsAppsCheckList::constructControls()
   147 void HsAppsCheckList::constructControls()
   163 {
   148 {
   164     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::constructControls");
   149     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::constructControls");
   165     if (!mActionConfirm) {
   150 
   166         mActionConfirm = new HbAction(Hb::ConfirmNaviAction, mView);
   151     bool loadStatusOk = false;
   167         connect(mActionConfirm, SIGNAL(triggered()),SLOT(selectApplicationsDone()));
   152     HbDocumentLoader loader;
   168     }
   153     loader.load(HS_APP_CHECK_LIST_LAYOUT, &loadStatusOk);
   169 
   154 
   170     if (!mView) { // it implies that mListView is NULL as well
   155     Q_ASSERT_X(loadStatusOk,
   171         bool loadStatusOk = false;
   156                 HS_APP_CHECK_LIST_LAYOUT,
   172 
   157                "Error while loading docml file.");
   173         HbDocumentLoader loader;
   158 
   174         mLoadedObjects = loader.load(HS_APP_CHECK_LIST_LAYOUT, &loadStatusOk);
   159     static const QString APPS_SELECTION_DIALOG("applications_selection_dialog");
   175 
   160     mAppsSelectDialog =
   176         Q_ASSERT_X(loadStatusOk,
   161         qobject_cast<HbDialog *>(loader.findWidget(APPS_SELECTION_DIALOG));
   177                     HS_APP_CHECK_LIST_LAYOUT,
   162 
   178                    "Error while loading docml file.");
   163     if (mAppsSelectDialog) {
   179 
   164         static const QString LIST_VIEW_WIDGET("listView");
   180         static const QString VIEW_WIDGET_NAME("view");
       
   181         mView = qobject_cast<HbView *> (loader.findWidget(VIEW_WIDGET_NAME));
       
   182         mView->setParent(this);
       
   183 
       
   184         static const QString LIST_VIEW_WIDGET_NAME("listView");
       
   185         mListView = qobject_cast<HbListView *> (loader.findWidget(
   165         mListView = qobject_cast<HbListView *> (loader.findWidget(
   186                 LIST_VIEW_WIDGET_NAME));
   166             LIST_VIEW_WIDGET));
       
   167         mModel->setParent(mAppsSelectDialog);
   187         mListView->setModel(mModel);
   168         mListView->setModel(mModel);
       
   169 
       
   170         connect(mListView,SIGNAL(activated(const QModelIndex&) ),this
       
   171                 ,SLOT(selectedItemsChanged()));
       
   172         connect(mModel,SIGNAL(rowsRemoved(const QModelIndex&, int,int)),
       
   173         		this, SLOT(selectedItemsChanged()));
       
   174 
       
   175         // add confirm action
       
   176         static const QString HS_APPS_SELECTION_DIALOG_CONFIRMATION_ACTION
       
   177                 ("aps_dialog_softkey_2_left");
       
   178         mActionConfirm = qobject_cast<HbAction*>(loader.findObject(
       
   179                         HS_APPS_SELECTION_DIALOG_CONFIRMATION_ACTION));
       
   180         mActionConfirm->setEnabled(false);
       
   181         mAppsSelectDialog->actions()[0]->setParent(mAppsSelectDialog);
       
   182         mAppsSelectDialog->actions()[1]->setParent(mAppsSelectDialog);
   188     }
   183     }
   189     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::constructControls");
   184     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::constructControls");
   190 }
   185 }
   191 
   186 
   192 /*!
   187 /*!
   193  Slot connected trrigger action of secondary soft key of check list box.
   188  Action after closed application selection dialog.
   194  It is called when done button is selected.
   189  \param finishedAction chosen action.
   195  */
   190  \retval void
   196 #ifdef COVERAGE_MEASUREMENT
   191  */
   197 #pragma CTC SKIP
   192 void HsAppsCheckList::appsSelectionDialogFinished(HbAction* finishedAction)
   198 #endif //COVERAGE_MEASUREMENT
   193 {
   199 void HsAppsCheckList::selectApplicationsDone()
   194     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::appsSelectionDialogFinished");
   200 {
       
   201     HSMENUTEST_FUNC_ENTRY("HsAppsCheckList::selectApplicationsDone");
       
   202     // Remove mListView from main window and restore previous view.
       
   203     HbMainWindow *hbMainWindow = mainWindow();
       
   204     hbMainWindow->setCurrentView(mPreviousView);
       
   205     hbMainWindow->removeView(mView);
       
   206     
       
   207     QItemSelectionModel *itemSelectionModel = mListView->selectionModel();
       
   208     QList<int> itemsList;
   195     QList<int> itemsList;
   209     if (itemSelectionModel) {
   196     if (finishedAction == mActionConfirm) {
   210         QModelIndexList modelIndexList =
   197         QItemSelectionModel *itemSelectionModel = mListView->selectionModel();
   211             itemSelectionModel->selectedIndexes();
   198         if (itemSelectionModel) {
   212         itemsList = getSortedItemsList(modelIndexList);
   199             QModelIndexList modelIndexList =
   213     }
   200                 itemSelectionModel->selectedIndexes();
       
   201             itemsList = getSortedItemsList(modelIndexList);
       
   202         }
       
   203     }
       
   204     mAppsSelectDialog = NULL;
   214     emit commit(itemsList);
   205     emit commit(itemsList);
   215     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::selectApplicationsDone");
   206     HSMENUTEST_FUNC_EXIT("HsAppsCheckList::appsSelectionDialogFinished");
   216 }
   207 }
   217 #ifdef COVERAGE_MEASUREMENT
       
   218 #pragma CTC ENDSKIP
       
   219 #endif //COVERAGE_MEASUREMENT
       
   220 
   208 
   221 /*!
   209 /*!
   222  Returns list with selected items ids.
   210  Returns list with selected items ids.
   223  \param modelIndexList list with selected model indexes.
   211  \param modelIndexList list with selected model indexes.
   224  \return list with items ids.
   212  \return list with items ids.
   249     }
   237     }
   250     return list;
   238     return list;
   251 }
   239 }
   252 
   240 
   253 /*!
   241 /*!
   254  Returns pointer to tha main window.
   242  Slot activated then user select or unselect item
   255  \return Pointer to the main window.
   243  */
   256  */
   244 void HsAppsCheckList::selectedItemsChanged()
   257 #ifdef COVERAGE_MEASUREMENT
   245 {
   258 #pragma CTC SKIP
   246     if (mListView->selectionModel()->hasSelection()) {
   259 #endif //COVERAGE_MEASUREMENT
   247         mActionConfirm->setEnabled(true);
   260 HbMainWindow *HsAppsCheckList::mainWindow() const
   248     } else {
   261 {
   249         mActionConfirm->setEnabled(false);
   262     return HbInstance::instance()->allMainWindows().value(0);
   250     }
   263 }
   251 }
   264 #ifdef COVERAGE_MEASUREMENT
       
   265 #pragma CTC ENDSKIP
       
   266 #endif //COVERAGE_MEASUREMENT