taskswitcherapp/tsserviceplugin/src/tstaskpopuphandler.cpp
changeset 35 f9ce957a272c
child 36 cdae8c6c3876
equal deleted inserted replaced
5:c743ef5928ba 35:f9ce957a272c
       
     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:
       
    15 *
       
    16 */
       
    17 #include "tstaskpopuphandler.h"
       
    18 
       
    19 #include <hbmenu.h>
       
    20 #include <hbabstractviewitem.h>
       
    21 
       
    22 #include "tsdataroles.h"
       
    23 
       
    24 TsTaskPopupHandler::TsTaskPopupHandler(QObject *parent) : QObject(parent)
       
    25 {
       
    26 }
       
    27 
       
    28 #ifdef COVERAGE_MEASUREMENT
       
    29 #pragma CTC SKIP
       
    30 #endif //COVERAGE_MEASUREMENT
       
    31 void TsTaskPopupHandler::showTaskPopup(HbAbstractViewItem *item, const QPointF &coords)
       
    32 {
       
    33     QModelIndex itemIndex(item->modelIndex());
       
    34 
       
    35     //initialize popup menu
       
    36     HbMenu taskPopup;
       
    37     taskPopup.setTimeout(0);
       
    38     taskPopup.setDismissPolicy(HbPopup::TapOutside);
       
    39 
       
    40     HbAction *closeAction = NULL;
       
    41     HbAction *closeAllAction = NULL;
       
    42 
       
    43     if (isClosable(itemIndex)) {
       
    44         closeAction = taskPopup.addAction(
       
    45                 hbTrId("txt_tsw_menu_clear_this_task"));
       
    46     }
       
    47     if (closeAction || containsClosableItems(*itemIndex.model())) {
       
    48         closeAllAction = taskPopup.addAction(
       
    49                 hbTrId("txt_tsw_menu_clear_all_tasks"));
       
    50     }
       
    51 
       
    52     if (closeAllAction || closeAction) {
       
    53         // show popup
       
    54         HbAction *selectionAction = taskPopup.exec(coords);
       
    55 
       
    56         //check selection and emit right signal
       
    57         if (selectionAction == closeAction) {
       
    58             emit closeTask(itemIndex);
       
    59         } else if (selectionAction == closeAllAction) {
       
    60             emit closeAllTasks();
       
    61         }
       
    62     }
       
    63 
       
    64     //release resources
       
    65     taskPopup.close();
       
    66 }
       
    67 #ifdef COVERAGE_MEASUREMENT
       
    68 #pragma CTC ENDSKIP
       
    69 #endif //COVERAGE_MEASUREMENT
       
    70 
       
    71 bool TsTaskPopupHandler::isClosable(const QModelIndex &index) const
       
    72 {
       
    73     const QVariant state(index.data(TsDataRoles::Closable));
       
    74     return state.isValid() && state.toBool();
       
    75 }
       
    76 
       
    77 bool TsTaskPopupHandler::containsClosableItems(const QAbstractItemModel &model) const
       
    78 {
       
    79     bool retVal(false);
       
    80     for (int row(0); !retVal && row < model.rowCount(); ++row) {
       
    81         for (int col(0); !retVal && col < model.columnCount(); ++col) {
       
    82             retVal = isClosable(model.index(row, col));
       
    83         }
       
    84     }
       
    85     return retVal;
       
    86 }