1 /* |
|
2 * Copyright (c) 2010 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 |
|
19 #include <QEventLoop> |
|
20 #include <QCoreApplication> |
|
21 #include <QVariant> |
|
22 #include <QStringList> |
|
23 #include <QtDebug> |
|
24 |
|
25 #include "satappaction.h" |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // global des2str |
|
29 // trasmit from symbian descripter to QString |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 QString des2str(const TDesC& desc) |
|
33 { |
|
34 return QString::fromUtf16(desc.Ptr(), desc.Length()); |
|
35 } |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ================================================== |
|
38 |
|
39 // ---------------------------------------------------------------------------- |
|
40 // SatAppAction::SatAppAction |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 SatAppAction::SatAppAction(int action, QObject *parent) |
|
44 : QObject(parent) |
|
45 { |
|
46 qDebug("SATAPP: SatAppAction::SatAppAction"); |
|
47 mAction = action; |
|
48 mResponse = ESatNoResponseFromUser; |
|
49 mState = Active; |
|
50 |
|
51 //monitor application |
|
52 SAT_ASSERT(connect( |
|
53 qApp,SIGNAL(aboutToQuit()), |
|
54 this,SLOT(completeWithSessionTerminated()))); |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // SatAppAction::~SatAppAction |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 SatAppAction::~SatAppAction() |
|
62 { |
|
63 if (mState==Waiting) |
|
64 complete(); // release waiting thread |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // SatAppAction::waitUntilCompleted |
|
69 // sync method that returns when this action is completed |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 void SatAppAction::waitUntilCompleted() |
|
73 { |
|
74 qDebug("SATAPP: SatAppAction::waitUntilCompleted"); |
|
75 if (mState==Completed) return; // no need to wait! |
|
76 QEventLoop loop; |
|
77 SAT_ASSERT(connect( |
|
78 this,SIGNAL(actionCompleted(SatAppAction*)), |
|
79 &loop,SLOT(quit()))); |
|
80 mState=Waiting; |
|
81 qDebug("SATAPP: waitUntilCompleted: waiting..."); |
|
82 loop.exec(); |
|
83 // When use the FSW complete the satapp, the signal aboutToExit |
|
84 // can not be recieved. temp solution |
|
85 if(Waiting == mState){ |
|
86 mState=Completed; |
|
87 mResponse=ESatSessionTerminatedByUser; |
|
88 } |
|
89 qDebug("SATAPP: waitUntilCompleted: ...released"); |
|
90 } |
|
91 |
|
92 // ---------------------------------------------------------------------------- |
|
93 // SatAppAction::complete |
|
94 // completes the action |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 void SatAppAction::complete(TSatUiResponse resp) |
|
98 { |
|
99 qDebug("SATAPP: SatAppAction::complete resp= %x in", resp); |
|
100 if (mState!=Completed) { |
|
101 qDebug("SATAPP: SatAppAction::completed"); |
|
102 setResponse(resp); |
|
103 mState = Completed; |
|
104 emit actionCompleted(this); |
|
105 } |
|
106 qDebug("SATAPP: SatAppAction::complete resp= %x out", resp); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // SatAppAction::set |
|
111 // setter for QVariant |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 void SatAppAction::set(const QString& key, QVariant value) |
|
115 { |
|
116 qDebug() << "SATAPP: SatAppAction::set(" << |
|
117 key << "=" << value << ")"; |
|
118 mParams[key] = value; |
|
119 } |
|
120 |
|
121 // ---------------------------------------------------------------------------- |
|
122 // SatAppAction::set |
|
123 // setter for Symbian Descripter |
|
124 // ---------------------------------------------------------------------------- |
|
125 // |
|
126 void SatAppAction::set(const QString& key, const TDesC& value) |
|
127 { |
|
128 set(key,des2str(value)); |
|
129 } |
|
130 |
|
131 // ---------------------------------------------------------------------------- |
|
132 // SatAppAction::set |
|
133 // setter for Symbian MDesCArray - Menu list |
|
134 // ---------------------------------------------------------------------------- |
|
135 // |
|
136 void SatAppAction::set(const QString& key, const MDesCArray& value) |
|
137 { |
|
138 QList<QVariant> list; |
|
139 for(int i=0; i<value.MdcaCount(); ++i) |
|
140 list.append(des2str(value.MdcaPoint(i))); |
|
141 set(key,list); |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // SatAppAction::set |
|
146 // setter for CArrayFixFlat<TInt> - mene icon |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 void SatAppAction::set(const QString& key, CArrayFixFlat<TInt>& value) |
|
150 { |
|
151 QList<QVariant> list; |
|
152 for(int i=0; i<value.Count(); ++i) |
|
153 list.append(value[i]); |
|
154 set(key,list); |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // SatAppAction::set |
|
159 // setter for TTimeIntervalSeconds - duration |
|
160 // ---------------------------------------------------------------------------- |
|
161 // |
|
162 void SatAppAction::set(const QString& key, TTimeIntervalSeconds& value) |
|
163 { |
|
164 int value_millisec = value.Int() * 1000; // sec->millisec |
|
165 set(key,value_millisec); |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // SatAppAction::set |
|
170 // setter for TTimeIntervalMicroSeconds - duration |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 void SatAppAction::set(const QString& key, TTimeIntervalMicroSeconds& value) |
|
174 { |
|
175 int value_millisec = value.Int64() / 1000; // microsec->millisec |
|
176 set(key,value_millisec); |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // SatAppAction::value |
|
181 // getter by key |
|
182 // ---------------------------------------------------------------------------- |
|
183 // |
|
184 QVariant SatAppAction::value(const QString& key) |
|
185 { |
|
186 if (!mParams.contains(key)) |
|
187 { |
|
188 // lazy-fetch params implementation goes here. |
|
189 // for instance if Icon is requested, request for the icons here. |
|
190 // however at this moment, all parameters should be present. |
|
191 qFatal("SATAPP: SatAppAction::value - param missing: %s", |
|
192 key.toLatin1().data()); |
|
193 } |
|
194 return mParams[key]; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // SatAppAction::hasValue |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 bool SatAppAction::hasValue(const QString& key) |
|
202 { |
|
203 return mParams.contains(key); |
|
204 } |
|
205 |
|
206 //End of file |
|