99
|
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: tsmodel.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <HbIcon>
|
|
18 |
#include <qvariant.h>
|
|
19 |
#include <qlist.h>
|
|
20 |
#include <afstorageglobals.h>
|
|
21 |
|
|
22 |
#ifdef Q_OS_SYMBIAN
|
|
23 |
#include <XQSettingsManager>
|
|
24 |
#include <apaid.h>
|
|
25 |
|
|
26 |
const int TSDeviceDialogUid = 0x2002677F;
|
|
27 |
const int ItemsLimit = 0x00000001;
|
|
28 |
#endif
|
|
29 |
|
107
|
30 |
#include "tsmodel.h"
|
|
31 |
#include "tsmodelitem.h"
|
|
32 |
#include "tsentrymodelitem.h"
|
|
33 |
#include "tsactivitymodelitem.h"
|
|
34 |
#include "tsdataroles.h"
|
|
35 |
|
99
|
36 |
const int maxItems(10);
|
|
37 |
/*!
|
|
38 |
\class TsModel
|
|
39 |
\ingroup group_tsdevicedialogplugin
|
|
40 |
\brief Model storing running application and activieties.
|
|
41 |
*/
|
|
42 |
|
|
43 |
/*!
|
|
44 |
Constructor
|
|
45 |
\param query used to create model
|
|
46 |
\param pointer to parent object
|
|
47 |
*/
|
107
|
48 |
TsModel::TsModel(TsTaskMonitor &applicationSrv,
|
|
49 |
QObject &activitySrv,
|
|
50 |
QObject *parent) :
|
99
|
51 |
QAbstractListModel(parent),
|
|
52 |
mEntries(),
|
|
53 |
mApplicationService(applicationSrv),
|
|
54 |
mActivityService(activitySrv),
|
|
55 |
mMaxItems(maxItems)
|
|
56 |
{
|
|
57 |
|
|
58 |
#ifdef Q_OS_SYMBIAN
|
|
59 |
XQSettingsManager *crManager = new XQSettingsManager;
|
|
60 |
XQCentralRepositorySettingsKey itemsNumberKey(TSDeviceDialogUid, ItemsLimit);
|
107
|
61 |
QVariant itemsNumberVariant =
|
|
62 |
crManager->readItemValue(itemsNumberKey, XQSettingsManager::TypeInt);
|
99
|
63 |
if (!itemsNumberVariant.isNull()) {
|
|
64 |
int number = itemsNumberVariant.toInt();
|
|
65 |
if (number > 0) {
|
|
66 |
mMaxItems = number;
|
|
67 |
}
|
|
68 |
}
|
|
69 |
iAppArcSession.Connect();
|
|
70 |
#endif
|
|
71 |
|
107
|
72 |
connect(&activitySrv,
|
|
73 |
SIGNAL(dataChanged()),
|
|
74 |
this,
|
|
75 |
SLOT(updateModel()));
|
|
76 |
connect(&applicationSrv,
|
|
77 |
SIGNAL(taskListChanged()),
|
|
78 |
this,
|
|
79 |
SLOT(updateModel()));
|
99
|
80 |
updateModel();
|
|
81 |
}
|
|
82 |
|
|
83 |
/*!
|
|
84 |
Destructor
|
|
85 |
*/
|
|
86 |
TsModel::~TsModel()
|
|
87 |
{
|
|
88 |
#ifdef Q_OS_SYMBIAN
|
|
89 |
iAppArcSession.Close();
|
|
90 |
#endif
|
|
91 |
qDeleteAll(mEntries);
|
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
|
95 |
Returns count of rows in model
|
|
96 |
\retval number of rows
|
|
97 |
*/
|
|
98 |
int TsModel::rowCount(
|
|
99 |
const QModelIndex &parent) const
|
|
100 |
{
|
|
101 |
Q_UNUSED(parent);
|
|
102 |
return mEntries.count();
|
|
103 |
}
|
|
104 |
|
|
105 |
/*!
|
|
106 |
Returns appropiate model's data
|
|
107 |
\param index model index
|
|
108 |
\param role which data role to return
|
|
109 |
\retval models data
|
|
110 |
*/
|
|
111 |
QVariant TsModel::data(const QModelIndex &index,
|
|
112 |
int role) const
|
|
113 |
{
|
|
114 |
return index.isValid() ? entry(index)->data(role) : QVariant();
|
|
115 |
}
|
|
116 |
|
|
117 |
/*!
|
|
118 |
Returns maximum anount of data allowed for model
|
|
119 |
\retval maximum data count
|
|
120 |
*/
|
|
121 |
|
|
122 |
int TsModel::maxRowCount()const
|
|
123 |
{
|
|
124 |
return mMaxItems;
|
|
125 |
}
|
|
126 |
|
|
127 |
/*!
|
|
128 |
Activate one of model entries
|
|
129 |
*/
|
|
130 |
void TsModel::openApplication(const QModelIndex &index)
|
|
131 |
{
|
|
132 |
if (!index.isValid()) {
|
|
133 |
return;
|
|
134 |
}
|
|
135 |
entry(index)->open();
|
|
136 |
}
|
|
137 |
|
|
138 |
/*!
|
|
139 |
Close one of moder entries
|
|
140 |
*/
|
|
141 |
void TsModel::closeApplication(const QModelIndex &index)
|
|
142 |
{
|
107
|
143 |
if (!index.isValid() ||
|
|
144 |
!entry(index)->data(TsDataRoles::Closable).toBool()) {
|
99
|
145 |
return;
|
|
146 |
}
|
|
147 |
entry(index)->close();
|
|
148 |
}
|
|
149 |
|
|
150 |
/*!
|
|
151 |
Updates model with fresh entries
|
|
152 |
*/
|
|
153 |
void TsModel::updateModel()
|
|
154 |
{
|
|
155 |
//clear current data
|
107
|
156 |
beginResetModel();
|
99
|
157 |
qDeleteAll(mEntries);
|
|
158 |
mEntries.clear();
|
|
159 |
getApplications();
|
|
160 |
getActivities();
|
|
161 |
endResetModel();
|
|
162 |
|
|
163 |
}
|
|
164 |
|
|
165 |
/*!
|
|
166 |
Read list of running applications
|
|
167 |
*/
|
|
168 |
void TsModel::getApplications()
|
|
169 |
{
|
|
170 |
//get running applications
|
|
171 |
QList< QSharedPointer<TsTask> > tasks(mApplicationService.taskList());
|
|
172 |
foreach (QSharedPointer<TsTask> taskData, tasks) {
|
107
|
173 |
mEntries.append(new TsEntryModelItem(taskData));
|
99
|
174 |
}
|
|
175 |
}
|
|
176 |
|
|
177 |
/*!
|
|
178 |
Read current activities
|
|
179 |
*/
|
|
180 |
void TsModel::getActivities()
|
|
181 |
{
|
|
182 |
//get activities
|
|
183 |
TsModelItem *entry(0);
|
|
184 |
QList<QVariantHash> activities;
|
107
|
185 |
QMetaObject::invokeMethod(&mActivityService,
|
|
186 |
"activitiesList",
|
|
187 |
Q_RETURN_ARG(QList<QVariantHash>,
|
|
188 |
activities));
|
99
|
189 |
foreach(QVariantHash activity, activities) {
|
|
190 |
prepareActivityEntry(activity);
|
|
191 |
entry = new TsActivityModelItem(*this, mActivityService, activity);
|
107
|
192 |
if (maxRowCount() <= mEntries.count()) {
|
|
193 |
delete entry;
|
|
194 |
break;
|
99
|
195 |
}
|
107
|
196 |
mEntries.append(entry);
|
99
|
197 |
}
|
|
198 |
}
|
|
199 |
|
|
200 |
/*!
|
|
201 |
Modify activity entry replacing application id with name
|
|
202 |
*/
|
|
203 |
void TsModel::prepareActivityEntry(QVariantHash &activity)
|
|
204 |
{
|
|
205 |
if (!activity.contains(TsActivityModelItem::applicationKeyword())) {
|
|
206 |
activity.insert(TsActivityModelItem::applicationKeyword(),
|
|
207 |
activity.contains(ActivityApplicationKeyword) ?
|
|
208 |
getApplicationName(activity[ActivityApplicationKeyword].toInt()) :
|
|
209 |
QString::null);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
/*!
|
|
214 |
Return application name
|
|
215 |
\param id - reqiested application identyfier
|
|
216 |
*/
|
|
217 |
QString TsModel::getApplicationName(int id)
|
|
218 |
{
|
|
219 |
QString retVal;
|
|
220 |
#ifdef Q_OS_SYMBIAN
|
|
221 |
TApaAppInfo info;
|
|
222 |
iAppArcSession.GetAppInfo( info, TUid::Uid(id));
|
|
223 |
retVal = QString::fromUtf16(info.iShortCaption.Ptr(),
|
|
224 |
info.iShortCaption.Length());
|
|
225 |
#endif
|
|
226 |
return retVal;
|
|
227 |
}
|
|
228 |
|
|
229 |
/*!
|
|
230 |
Called when some item was changed
|
|
231 |
\param itemPtr - address of updated item
|
|
232 |
*/
|
|
233 |
void TsModel::entryChanged(TsModelItem *itemPtr)
|
|
234 |
{
|
|
235 |
const int itemIndex = mEntries.indexOf(itemPtr);
|
|
236 |
if (itemIndex != -1) {
|
|
237 |
emit dataChanged(index(itemIndex, 0), index(itemIndex, 0));
|
|
238 |
}
|
|
239 |
}
|
|
240 |
|
|
241 |
/*!
|
|
242 |
Returns an entry from model
|
|
243 |
\param index of entry in model
|
|
244 |
\retval pointer to an entry
|
|
245 |
*/
|
|
246 |
TsModelItem *TsModel::entry(const QModelIndex &index) const
|
|
247 |
{
|
|
248 |
return mEntries.at(index.row());
|
|
249 |
}
|
|
250 |
|