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: tsactivitymodelitem.cpp
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <hbicon.h>
|
|
18 |
#include <afstorageglobals.h>
|
|
19 |
|
|
20 |
#include "tsactivitymodelitem.h"
|
|
21 |
#include "tsdataroles.h"
|
|
22 |
|
|
23 |
/*!
|
|
24 |
\class TsActivityModelItem
|
|
25 |
\ingroup group_tsdevicedialogplugin
|
|
26 |
\brief Item presenting activity in the grid.
|
|
27 |
*/
|
|
28 |
|
|
29 |
/*!
|
|
30 |
Standard C++ constructor
|
|
31 |
/param model - reference to parent model
|
|
32 |
/param service - reference to initialized ActivityManager instance
|
|
33 |
/param entry - Activity data
|
|
34 |
*/
|
|
35 |
TsActivityModelItem::TsActivityModelItem(QAbstractListModel &model,
|
|
36 |
QObject& service,
|
|
37 |
const QVariantHash & activity)
|
|
38 |
:
|
|
39 |
mService(service),
|
|
40 |
mActivity(activity),
|
|
41 |
mIcon(),
|
|
42 |
mRequestPending(false)
|
|
43 |
{
|
|
44 |
connect(this,
|
|
45 |
SIGNAL(entryChanged(TsModelItem *)),
|
|
46 |
&model,
|
|
47 |
SLOT(entryChanged(TsModelItem *)));
|
|
48 |
connect(&mService,
|
|
49 |
SIGNAL(thumbnailReady(QPixmap, void *)),
|
|
50 |
this,
|
|
51 |
SLOT(thumbnailReady(QPixmap, void *)));
|
|
52 |
}
|
|
53 |
|
|
54 |
/*!
|
|
55 |
Standard C++ destructor
|
|
56 |
/param service - reference to initialized ActivityManager instance
|
|
57 |
/param entry - Activity data
|
|
58 |
*/
|
|
59 |
TsActivityModelItem::~TsActivityModelItem()
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
/*!
|
|
64 |
Returns the data stored under the given role.
|
|
65 |
/param role - requested data role
|
|
66 |
/return data encapulated by QVariant
|
|
67 |
*/
|
|
68 |
QVariant TsActivityModelItem::data(int role) const
|
|
69 |
{
|
|
70 |
switch (role) {
|
|
71 |
case Qt::DisplayRole:
|
|
72 |
return displayRole();
|
|
73 |
case Qt::DecorationRole:
|
|
74 |
return decorationRole();
|
|
75 |
case TsDataRoles::Closable:
|
|
76 |
return QVariant(false);
|
102
|
77 |
case TsDataRoles::Active:
|
|
78 |
return QVariant(false);
|
99
|
79 |
default:
|
|
80 |
return QVariant(QVariant::Invalid);
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
/*!
|
|
85 |
Empty interface implementation
|
|
86 |
*/
|
|
87 |
void TsActivityModelItem::close()
|
|
88 |
{
|
|
89 |
//no implementation required
|
|
90 |
}
|
|
91 |
|
|
92 |
/*!
|
|
93 |
Open or move to foreground activity repesented by entry
|
|
94 |
*/
|
|
95 |
void TsActivityModelItem::open()
|
|
96 |
{
|
|
97 |
QVariant application(mActivity.value(ActivityApplicationKeyword));
|
|
98 |
QVariant activity(mActivity.value(ActivityActivityKeyword));
|
|
99 |
|
|
100 |
if (application.isValid() && activity.isValid()) {
|
|
101 |
QMetaObject::invokeMethod(&mService,
|
|
102 |
"launchActivity",
|
|
103 |
Q_ARG(int, application.toInt()),
|
|
104 |
Q_ARG(QString, activity.toString()));
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
/*!
|
|
109 |
Return application name keyword
|
|
110 |
*/
|
|
111 |
QString TsActivityModelItem::applicationKeyword()
|
|
112 |
{
|
|
113 |
static QString applicationName(ActivityApplicationName);
|
|
114 |
return applicationName;
|
|
115 |
}
|
|
116 |
|
|
117 |
/*!
|
|
118 |
Return activity visibility status keyword
|
|
119 |
*/
|
|
120 |
QString TsActivityModelItem::visibilityKeyword()
|
|
121 |
{
|
|
122 |
static QString visibility("visible");
|
|
123 |
return visibility;
|
|
124 |
}
|
|
125 |
|
|
126 |
/*!
|
|
127 |
Return activity screenshot keyword
|
|
128 |
*/
|
|
129 |
QString TsActivityModelItem::screenshotKeyword()
|
|
130 |
{
|
|
131 |
static QString screenshot(ActivityScreenshotKeyword);
|
|
132 |
return screenshot;
|
|
133 |
}
|
|
134 |
|
|
135 |
/*!
|
|
136 |
Returns the data stored under decoration role.
|
|
137 |
/return data encapulated by QVariant
|
|
138 |
*/
|
|
139 |
QVariant TsActivityModelItem::decorationRole() const
|
|
140 |
{
|
|
141 |
if (!mRequestPending) {
|
|
142 |
const_cast<TsActivityModelItem *>(this)->mRequestPending = true;
|
|
143 |
QVariant screenshot = mActivity.value(screenshotKeyword());
|
|
144 |
if (screenshot.isValid()) {
|
|
145 |
QMetaObject::invokeMethod(&mService,
|
|
146 |
"getThumbnail",
|
|
147 |
Q_ARG(QSize, QSize(128, 128)),
|
|
148 |
Q_ARG(QString, screenshot.toString()),
|
|
149 |
Q_ARG(void *, const_cast<TsActivityModelItem *>(this)));
|
|
150 |
}
|
|
151 |
}
|
|
152 |
return QVariant::fromValue<HbIcon>(HbIcon(mIcon));
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
|
156 |
Returns the data stored under display role.
|
|
157 |
/return data encapulated by QVariant
|
|
158 |
*/
|
|
159 |
QVariant TsActivityModelItem::displayRole() const
|
|
160 |
{
|
|
161 |
return mActivity.value(applicationKeyword());
|
|
162 |
}
|
|
163 |
|
|
164 |
/*!
|
|
165 |
Slot retrieve thumbnail form TM, update content and notify observers
|
|
166 |
/param pixmap - thumbnail content
|
|
167 |
/ptr - user data provided to request
|
|
168 |
*/
|
|
169 |
void TsActivityModelItem::thumbnailReady(QPixmap pixmap, void *ptr)
|
|
170 |
{
|
|
171 |
if (ptr == this) {
|
|
172 |
mIcon = pixmap;
|
|
173 |
emit entryChanged(this);
|
|
174 |
}
|
|
175 |
}
|