taskswitcherapp/tsserviceplugin/src/tsitemprovider.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 42 517f4fb5ec74
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
     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 
       
    18 #include "tsitemprovider.h"
       
    19 
       
    20 #include <QModelIndex>
       
    21 #include <QAbstractItemModel>
       
    22 
       
    23 #include <caservice.h>
       
    24 
       
    25 #include "tsrecentapplicationsmodel.h"
       
    26 #include "tsclosedapplicationsfiltermodel.h"
       
    27 #include "tsdataroles.h"
       
    28 
       
    29 /*!
       
    30     \class TsItemProvider
       
    31     \ingroup group_tsserviceplugin
       
    32     \brief Returns items that should be presented in TS.
       
    33 	
       
    34 	Service providing information about items that should be presented in TS. It also allows to
       
    35 	start some action on it (open/close).
       
    36 */
       
    37 
       
    38 TsItemProvider::TsItemProvider(QObject *parent) : TsItemProviderInterface(parent), mService(CaService::instance())
       
    39 {
       
    40     TsRecentApplicationsModel *recentAppModel = new TsRecentApplicationsModel(this);
       
    41     mModel = new TsClosedApplicationsFilterModel(this);
       
    42     mModel->setSourceModel(recentAppModel);
       
    43 }
       
    44 
       
    45 TsItemProvider::~TsItemProvider()
       
    46 {
       
    47 }
       
    48 
       
    49 QAbstractItemModel *TsItemProvider::model()
       
    50 {
       
    51     return mModel;
       
    52 }
       
    53 
       
    54 void TsItemProvider::openApplication(const QModelIndex &index)
       
    55 {
       
    56     QVariant entryId = index.data(TsDataRoles::EntryId);
       
    57     if (entryId.isValid()) {
       
    58         mService->executeCommand(entryId.toInt(), QString("open"));
       
    59     }
       
    60 }
       
    61 
       
    62 void TsItemProvider::closeApplication(const QModelIndex &index)
       
    63 {
       
    64     if (index.data(TsDataRoles::Closable).toBool()) {
       
    65         QVariant entryId = index.data(TsDataRoles::EntryId);
       
    66         if (entryId.isValid()) {
       
    67             mModel->addId(entryId.toInt());
       
    68             mService->executeCommand(entryId.toInt(), QString("close"));
       
    69         }
       
    70     }
       
    71 }
       
    72 
       
    73 void TsItemProvider::closeAllApplications()
       
    74 {
       
    75     QList<int> closableList;
       
    76     for (int row(0); row < mModel->rowCount(); ++row) {
       
    77         if (mModel->index(row, 0).data(TsDataRoles::Closable).toBool()) {
       
    78             QVariant entryId = mModel->index(row, 0).data(TsDataRoles::EntryId);
       
    79             if (entryId.isValid()) {
       
    80                 closableList.append(entryId.toInt());
       
    81             }
       
    82         }
       
    83     }
       
    84     foreach (int entryId, closableList) {
       
    85         mModel->addId(entryId);
       
    86         mService->executeCommand(entryId, QString("close"));        
       
    87     }
       
    88 }
       
    89 
       
    90 void TsItemProvider::clearClosedApplicationList()
       
    91 {
       
    92     mModel->clearIds();
       
    93 }