homescreenapp/stateplugins/hsmenuworkerstateplugin/src/hscollectionslistdialog.cpp
changeset 77 4b195f3bea29
parent 61 2b1b11a301d2
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
     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: Hs list dialog
       
    15  *
       
    16  */
       
    17 
       
    18 #include <HbAction>
       
    19 #include <HbLabel>
       
    20 #include <QDebug>
       
    21 #include <QStandardItemModel>
       
    22 
       
    23 #include <hsmenuservice.h>
       
    24 #include <hsmenuitemmodel.h>
       
    25 #include "hscollectionslistdialog.h"
       
    26 
       
    27 /*!
       
    28  \class HsCollectionsListDialog
       
    29  \ingroup group_hsworkerstateplugin
       
    30  \brief Hs List Dialog
       
    31  Hs List Dialog
       
    32  */
       
    33 
       
    34 /*!
       
    35  \var HsCollectionsListDialog::mModel
       
    36  Model.
       
    37  */
       
    38 
       
    39 /*!
       
    40  \var HsCollectionsListDialog::mItemId
       
    41  Selected item id.
       
    42  */
       
    43 
       
    44 /*!
       
    45  \fn void HsCollectionsListDialog::makeConnect();
       
    46  Connects edit line signals to slots.
       
    47 */
       
    48 
       
    49 /*!
       
    50  \fn void HsCollectionsListDialog::makeDisconnect();
       
    51  Disconnects edit line signals from slots.
       
    52  */
       
    53 
       
    54 /*!
       
    55  Constructor
       
    56  \param sortOrder sort order.
       
    57  \param collectionId collectionId id of collection
       
    58  to remove from list.
       
    59  \retval void
       
    60  */
       
    61 HsCollectionsListDialog::HsCollectionsListDialog(HsSortAttribute sortOrder,
       
    62         int collectionId) :
       
    63     HbSelectionDialog(), mItemId(0)
       
    64 {
       
    65     clearActions();
       
    66     HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"), this);
       
    67     addAction(cancelAction);
       
    68 
       
    69     setHeadingWidget(new HbLabel(hbTrId("txt_applib_title_add_to")));
       
    70     // it must be single selection, although it shows checkboxes -
       
    71     // it is Orbit defect and will be fixed in next release
       
    72     setSelectionMode(HbAbstractItemView::SingleSelection);
       
    73     mModel = standartItemModel(sortOrder, collectionId);
       
    74     setModel(mModel);
       
    75 }
       
    76 
       
    77 /*!
       
    78  Destructor
       
    79  */
       
    80 HsCollectionsListDialog::~HsCollectionsListDialog()
       
    81 {
       
    82     delete mModel;
       
    83 }
       
    84 
       
    85 /*!
       
    86  Executes dialog.
       
    87  \retval Selected action.
       
    88  */
       
    89 void HsCollectionsListDialog::open(QObject* receiver, const char* member)
       
    90 {
       
    91     this->setAttribute(Qt::WA_DeleteOnClose);
       
    92     HbSelectionDialog::open(receiver, member);
       
    93 }
       
    94 
       
    95 /*!
       
    96     \reimp
       
    97     Disconnects signals and calls base class impl. which emits finished(HbAction*)
       
    98  */
       
    99 void HsCollectionsListDialog::closeEvent ( QCloseEvent * event )
       
   100 {
       
   101     qDebug("HsCollectionsListDialog::closeEvent");
       
   102     HbAction *closingAction = qobject_cast<HbAction *>(sender());
       
   103 
       
   104     if (closingAction != actions().value(0)) {
       
   105         QModelIndexList modlist = selectedModelIndexes();
       
   106         if (modlist.count()) {
       
   107             mItemId
       
   108             = mModel-> data(modlist[0], CaItemModel::IdRole).toInt();
       
   109         }
       
   110     }
       
   111 
       
   112     HbDialog::closeEvent(event); // emits finished(HbAction*)
       
   113 }
       
   114 
       
   115 /*!
       
   116  Creates standard item model.
       
   117  \param sortOrder sort order.
       
   118  \param collectionId id of collection to remove from model.
       
   119  \return QStandardItemModel - caller takes ownership.
       
   120  */
       
   121 QStandardItemModel *HsCollectionsListDialog::standartItemModel(
       
   122     HsSortAttribute sortOrder, int collectionId)
       
   123 {
       
   124     HSMENUTEST_FUNC_ENTRY("HsListDialog::standartItemModel");
       
   125     QScopedPointer<HsMenuItemModel> caModel(
       
   126         HsMenuService::getAllCollectionsModel(sortOrder));
       
   127     caModel->setSecondLineVisibility(false);
       
   128     QStandardItemModel *model = new QStandardItemModel(this);
       
   129     QList<QStandardItem *> items;
       
   130     for (int row = 0; row < caModel->rowCount(); row++) {
       
   131         uint flags = caModel->data(caModel->index(row, 0),
       
   132                                    CaItemModel::FlagsRole).value<EntryFlags> ();
       
   133         int itemId = caModel->data(caModel->index(row, 0),
       
   134                                    CaItemModel::IdRole).toInt();
       
   135         if ((flags & RemovableEntryFlag) && (itemId != collectionId)) {
       
   136             QStandardItem *standardItem = new QStandardItem();
       
   137             standardItem->setData(caModel->data(caModel->index(row, 0),
       
   138                                                 CaItemModel::IdRole), CaItemModel::IdRole);
       
   139             standardItem->setData(caModel->data(caModel->index(row, 0),
       
   140                                                 Qt::DisplayRole), Qt::DisplayRole);
       
   141             standardItem->setData(caModel->data(caModel->index(row, 0),
       
   142                                                 Qt::DecorationRole), Qt::DecorationRole);
       
   143             items << standardItem;
       
   144         }
       
   145     }
       
   146     model->insertColumn(0, items);
       
   147 
       
   148     insertNewCollectionItem(model);
       
   149     HSMENUTEST_FUNC_EXIT("HsListDialog::standartItemModel");
       
   150     return model;
       
   151 }
       
   152 
       
   153 /*!
       
   154  Inserts "new collection" item into model.
       
   155  \param model a model.
       
   156  */
       
   157 void HsCollectionsListDialog::insertNewCollectionItem(
       
   158     QStandardItemModel *model)
       
   159 {
       
   160     HSMENUTEST_FUNC_ENTRY("HsListDialog::insertNewCollectionItem");
       
   161     QStandardItem *standardItem = new QStandardItem();
       
   162     standardItem->setData(0, CaItemModel::IdRole);
       
   163     standardItem->setData(hbTrId("txt_applib_list_new_collection"),
       
   164                           Qt::DisplayRole);
       
   165 
       
   166     standardItem->setData(HbIcon(defaultCollectionIconId()),
       
   167                           Qt::DecorationRole);
       
   168 
       
   169     QList<QStandardItem *> items;
       
   170     items << standardItem;
       
   171     model->insertRow(0, items);
       
   172     HSMENUTEST_FUNC_EXIT("HsListDialog::insertNewCollectionItem");
       
   173 }
       
   174 
       
   175 /*!
       
   176  Gets selected item id.
       
   177  \retval Selected item id.
       
   178  */
       
   179 int HsCollectionsListDialog::getItemId()
       
   180 {
       
   181     return mItemId;
       
   182 }