taskswitcherapp/tsserviceplugin/src/tsitemprovider.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 
       
    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 TsItemProvider::TsItemProvider(QObject *parent) : TsItemProviderInterface(parent), mService(CaService::instance())
       
    30 {
       
    31     TsRecentApplicationsModel *recentAppModel = new TsRecentApplicationsModel(this);
       
    32     mModel = new TsClosedApplicationsFilterModel(this);
       
    33     mModel->setSourceModel(recentAppModel);
       
    34 }
       
    35 
       
    36 TsItemProvider::~TsItemProvider()
       
    37 {
       
    38 }
       
    39 
       
    40 QAbstractItemModel *TsItemProvider::model()
       
    41 {
       
    42     return mModel;
       
    43 }
       
    44 
       
    45 void TsItemProvider::openApplication(const QModelIndex &index)
       
    46 {
       
    47     QVariant entryId = index.data(TsDataRoles::EntryId);
       
    48     if (entryId.isValid()) {
       
    49         mService->executeCommand(entryId.toInt(), QString("open"));
       
    50     }
       
    51 }
       
    52 
       
    53 void TsItemProvider::closeApplication(const QModelIndex &index)
       
    54 {
       
    55     if (index.data(TsDataRoles::Closable).toBool()) {
       
    56         QVariant entryId = index.data(TsDataRoles::EntryId);
       
    57         if (entryId.isValid()) {
       
    58             mModel->addId(entryId.toInt());
       
    59             mService->executeCommand(entryId.toInt(), QString("close"));
       
    60         }
       
    61     }
       
    62 }
       
    63 
       
    64 void TsItemProvider::closeAllApplications()
       
    65 {
       
    66     for (int row(0); row < mModel->rowCount(); ++row) {
       
    67         closeApplication(mModel->index(row, 0));
       
    68     }
       
    69 }
       
    70 
       
    71 void TsItemProvider::clearClosedApplicationList()
       
    72 {
       
    73     mModel->clearIds();
       
    74 }