72
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved. This program and the accompanying materials
|
|
4 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
5 |
* which accompanies this distribution, and is available at
|
|
6 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
7 |
*
|
|
8 |
* Contributors:
|
|
9 |
* Nokia Corporation - initial implementation
|
|
10 |
*******************************************************************************/
|
|
11 |
|
|
12 |
#include <apgtask.h>
|
|
13 |
#include <apgcli.h>
|
78
|
14 |
#include <memory>
|
|
15 |
#include <javastorageentry.h>
|
|
16 |
#include <javastorage.h>
|
|
17 |
#include <javastoragenames.h>
|
|
18 |
#include <JavaCommonUtils.h>
|
|
19 |
#include <logger.h>
|
|
20 |
#include <QFile.h>
|
72
|
21 |
|
78
|
22 |
#include "javasoftindicator.h"
|
|
23 |
|
|
24 |
using namespace std;
|
|
25 |
using namespace java::storage;
|
|
26 |
using namespace java::util;
|
72
|
27 |
|
|
28 |
// ----------------------------------------------------------------------------
|
|
29 |
// JavaSoftIndicator::JavaSoftIndicator
|
|
30 |
// @see javasoftindicator.h
|
|
31 |
// ----------------------------------------------------------------------------
|
|
32 |
JavaSoftIndicator::JavaSoftIndicator(const QString &indicatorType) :
|
|
33 |
HbIndicatorInterface(indicatorType,
|
|
34 |
HbIndicatorInterface::NotificationCategory, InteractionActivated)
|
|
35 |
{
|
|
36 |
}
|
|
37 |
|
|
38 |
// ----------------------------------------------------------------------------
|
|
39 |
// JavaSoftIndicator::~JavaSoftIndicator
|
|
40 |
// @see javasoftindicator.h
|
|
41 |
// ----------------------------------------------------------------------------
|
|
42 |
JavaSoftIndicator::~JavaSoftIndicator()
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
// ----------------------------------------------------------------------------
|
|
47 |
// JavaSoftIndicator::handleInteraction
|
|
48 |
// @see javasoftindicator.h
|
|
49 |
// ----------------------------------------------------------------------------
|
|
50 |
bool JavaSoftIndicator::handleInteraction(InteractionType type)
|
|
51 |
{
|
|
52 |
bool handled = false;
|
|
53 |
if (type == InteractionActivated)
|
|
54 |
{
|
78
|
55 |
// get midlet to foreground or lauch if it is not open
|
72
|
56 |
TRAP_IGNORE(StartJavaMidletL());
|
|
57 |
QVariantMap variantMap;
|
|
58 |
if (iParameter.isValid() && iParameter.canConvert(QVariant::List))
|
|
59 |
{
|
|
60 |
variantMap.insert("MidletId",iParameter.toList()[0].toUInt());
|
78
|
61 |
variantMap.insert("NotificationId",iParameter.toList()[1].toInt());
|
72
|
62 |
}
|
78
|
63 |
// send user activated signal to indicator observer
|
72
|
64 |
emit userActivated(variantMap);
|
|
65 |
handled = true;
|
78
|
66 |
// remove softnote from database
|
|
67 |
RemoveSoftNoteFromStorage();
|
|
68 |
// remove indicator from status menu
|
72
|
69 |
emit deactivate();
|
78
|
70 |
// remove image from public directoy
|
|
71 |
QFile imgFile(iParameter.toList()[4].toString());
|
|
72 |
if(imgFile.exists())
|
|
73 |
{
|
|
74 |
imgFile.remove();
|
|
75 |
}
|
72
|
76 |
}
|
|
77 |
return handled;
|
|
78 |
}
|
|
79 |
|
|
80 |
// ----------------------------------------------------------------------------
|
|
81 |
// JavaSoftIndicator::indicatorData
|
|
82 |
// @see javasoftindicator.h
|
|
83 |
// ----------------------------------------------------------------------------
|
|
84 |
QVariant JavaSoftIndicator::indicatorData(int role) const
|
|
85 |
{
|
|
86 |
switch (role)
|
|
87 |
{
|
|
88 |
case PrimaryTextRole:
|
|
89 |
{
|
|
90 |
QString text("");
|
|
91 |
if (iParameter.isValid() && iParameter.canConvert(QVariant::List))
|
|
92 |
{
|
|
93 |
if (iParameter.toList()[2].isValid())
|
|
94 |
{
|
|
95 |
text = iParameter.toList()[2].toString();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
return text;
|
|
99 |
}
|
|
100 |
case SecondaryTextRole:
|
|
101 |
{
|
|
102 |
QString text("");
|
|
103 |
if (iParameter.isValid() && iParameter.canConvert(QVariant::List))
|
|
104 |
{
|
|
105 |
if (iParameter.toList()[3].isValid())
|
|
106 |
{
|
|
107 |
text = iParameter.toList()[3].toString();
|
|
108 |
}
|
|
109 |
}
|
|
110 |
return text;
|
|
111 |
}
|
|
112 |
case DecorationNameRole:
|
|
113 |
{
|
|
114 |
QVariant img;
|
|
115 |
if (iParameter.isValid() && iParameter.canConvert(QVariant::List))
|
|
116 |
{
|
|
117 |
if (iParameter.toList()[4].isValid())
|
|
118 |
{
|
|
119 |
img = iParameter.toList()[4].toString();
|
|
120 |
}
|
|
121 |
}
|
|
122 |
return img;
|
|
123 |
}
|
|
124 |
default:
|
|
125 |
return QVariant();
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
// ----------------------------------------------------------------------------
|
|
130 |
// JavaSoftIndicator::handleClientRequest
|
|
131 |
// ----------------------------------------------------------------------------
|
|
132 |
bool JavaSoftIndicator::handleClientRequest(RequestType type,
|
|
133 |
const QVariant ¶meter)
|
|
134 |
{
|
|
135 |
bool handled(false);
|
|
136 |
switch (type)
|
|
137 |
{
|
|
138 |
case RequestActivate:
|
|
139 |
{
|
|
140 |
if (iParameter != parameter)
|
|
141 |
{
|
|
142 |
iParameter = parameter;
|
|
143 |
}
|
|
144 |
emit dataChanged();
|
|
145 |
handled = true;
|
|
146 |
}
|
|
147 |
break;
|
|
148 |
case RequestDeactivate:
|
|
149 |
{
|
78
|
150 |
RemoveSoftNoteFromStorage();
|
72
|
151 |
emit deactivate();
|
78
|
152 |
QFile imgFile(iParameter.toList()[4].toString());
|
|
153 |
if(imgFile.exists())
|
|
154 |
{
|
|
155 |
imgFile.remove();
|
|
156 |
}
|
72
|
157 |
}
|
|
158 |
break;
|
|
159 |
default:
|
|
160 |
break;
|
|
161 |
}
|
|
162 |
return handled;
|
|
163 |
}
|
|
164 |
|
|
165 |
// ----------------------------------------------------------
|
|
166 |
// JavaSoftIndicator::StartJavaMidletL()
|
|
167 |
// ----------------------------------------------------------
|
|
168 |
void JavaSoftIndicator::StartJavaMidletL() const
|
|
169 |
{
|
|
170 |
if (iParameter.isValid() && iParameter.canConvert(QVariant::List))
|
|
171 |
{
|
|
172 |
if (iParameter.toList()[0].isValid())
|
|
173 |
{
|
78
|
174 |
TUint javaMidletUid = iParameter.toList()[0].toUInt();
|
72
|
175 |
|
|
176 |
RWsSession ws;
|
|
177 |
User::LeaveIfError(ws.Connect() == KErrNone);
|
|
178 |
TApaTaskList tasklist(ws);
|
78
|
179 |
TApaTask task = tasklist.FindApp(TUid::Uid(javaMidletUid));
|
72
|
180 |
if (task.Exists())
|
|
181 |
{
|
|
182 |
task.BringToForeground();
|
|
183 |
ws.Close();
|
|
184 |
}
|
|
185 |
else
|
|
186 |
{
|
|
187 |
ws.Close();
|
|
188 |
RApaLsSession appArcSession;
|
|
189 |
User::LeaveIfError(appArcSession.Connect());
|
|
190 |
TThreadId threadId;
|
|
191 |
appArcSession.StartDocument(_L(""),
|
78
|
192 |
TUid::Uid(javaMidletUid), threadId);
|
72
|
193 |
appArcSession.Close();
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
78
|
199 |
// ----------------------------------------------------------
|
|
200 |
// JavaSoftIndicator::RemoveSoftNoteFromStorage()
|
|
201 |
// ----------------------------------------------------------
|
|
202 |
void JavaSoftIndicator::RemoveSoftNoteFromStorage()
|
|
203 |
{
|
|
204 |
std::auto_ptr<JavaStorage> js(JavaStorage::createInstance());
|
|
205 |
try
|
|
206 |
{
|
|
207 |
js->open(JAVA_DATABASE_NAME);
|
|
208 |
|
|
209 |
JavaStorageApplicationEntry_t entries;
|
|
210 |
JavaStorageEntry attribute;
|
|
211 |
|
|
212 |
std::wstring midletId = JavaCommonUtils::intToWstring(
|
|
213 |
iParameter.toList()[0].toUInt());
|
|
214 |
attribute.setEntry(SOFTNOTE_MIDLET_ID, midletId,
|
|
215 |
JavaStorageEntry::STRING);
|
|
216 |
entries.insert(attribute);
|
|
217 |
|
|
218 |
std::wstring notificationId = JavaCommonUtils::intToWstring(
|
|
219 |
iParameter.toList()[1].toInt());
|
|
220 |
attribute.setEntry(SOFTNOTE_ID, notificationId, JavaStorageEntry::INT);
|
|
221 |
entries.insert(attribute);
|
|
222 |
|
|
223 |
js->remove(JAVA_SOFTNOTE_TABLE, entries);
|
|
224 |
js->close();
|
|
225 |
entries.clear();
|
|
226 |
}
|
|
227 |
catch (JavaStorageException& ex)
|
|
228 |
{
|
87
|
229 |
LOG1(EJavaStorage, EInfo," JavaSoftNote Exception %S", ex.toString().c_str());
|
78
|
230 |
}
|
|
231 |
}
|
|
232 |
|