2 * satk - SIM application toolkit
3 * Copyright © 2011, Intel Corporation.
5 * This program is licensed under the terms and conditions of the
6 * Apache License, version 2.0. The full text of the Apache License is at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Written by - Luc Yriarte <luc.yriarte@linux.intel.com>
13 #include "stkagentservice.h"
17 #include <QtGui/QApplication>
20 /* oFono SIM Toolkit utilities*/
21 #include "stkofonoutils.h"
23 /* SIM Toolkit widgets */
24 #include "stkmenumodel.h"
26 /* Fallback return values */
27 #define FALLBACK_BOOL false
28 #define FALLBACK_UCHAR 255
29 #define FALLBACK_QSTRING ""
32 StkAgentService::StkAgentService(SimIf * simIf, QObject *parent) :
36 mExitOnRelease = false;
40 void StkAgentService::Cancel()
42 // handle method call org.ofono.SimToolkitAgent.Cancel
43 qDebug() << "Cancel" ;
48 bool StkAgentService::ConfirmCallSetup(const QString &info, uchar icon)
50 // handle method call org.ofono.SimToolkitAgent.ConfirmCallSetup
51 bool out0 = FALLBACK_BOOL;
52 qDebug() << "ConfirmCallSetup: " << info << "(" << icon << ")";
54 StkDialog * dlg = addNewWidget(info, icon,"qrc:/StkYesNo.qml");
55 dlg->setShowBackButton(false);
57 if (dlg->exec() != QDialog::Accepted)
59 AgentResponse ret = dlg->getAgentResponse();
68 connection().send(message().createErrorReply(STK_ERR_END,""));
77 bool StkAgentService::ConfirmLaunchBrowser(const QString &info, uchar icon, const QString &url)
79 // handle method call org.ofono.SimToolkitAgent.ConfirmLaunchBrowser
80 bool out0 = FALLBACK_BOOL;
81 qDebug() << "ConfirmLaunchBrowser: " << info << "(" << icon << ")" << " -- url: " << url;
83 StkDialog * web = addNewWidget(url, icon,"qrc:/StkWebView.qml");
84 StkDialog * dlg = addNewWidget(info, icon,"qrc:/StkYesNo.qml");
85 dlg->setShowBackButton(false);
86 dlg->setShowEndButton(false);
88 if (dlg->exec() != QDialog::Accepted)
90 AgentResponse ret = dlg->getAgentResponse();
99 closeLastWidget(); // StkYesNo
100 closeLastWidget(); // StkWebView
110 bool StkAgentService::ConfirmOpenChannel(const QString &info, uchar icon)
112 // handle method call org.ofono.SimToolkitAgent.ConfirmOpenChannel
113 bool out0 = FALLBACK_BOOL;
114 qDebug() << "ConfirmOpenChannel: " << info << "(" << icon << ")";
116 StkDialog * dlg = addNewWidget(info, icon,"qrc:/StkYesNo.qml");
117 dlg->setShowBackButton(false);
119 if (dlg->exec() != QDialog::Accepted)
121 AgentResponse ret = dlg->getAgentResponse();
130 connection().send(message().createErrorReply(STK_ERR_END,""));
139 void StkAgentService::DisplayAction(const QString &text, uchar icon)
141 // handle method call org.ofono.SimToolkitAgent.DisplayAction
142 qDebug() << "DisplayAction: " << text << "(" << icon << ")";
144 StkDialog * dlg = addNewWidget(text, icon,"qrc:/StkMessage.qml");
146 if (dlg->exec() != QDialog::Accepted)
148 AgentResponse ret = dlg->getAgentResponse();
151 connection().send(message().createErrorReply(STK_ERR_END,""));
159 void StkAgentService::DisplayActionInformation(const QString &text, uchar icon)
161 // handle method call org.ofono.SimToolkitAgent.DisplayActionInformation
162 qDebug() << "DisplayActionInformation: " << text << "(" << icon << ")";
164 StkDialog * dlg = addNewWidget(text, icon,"qrc:/StkMessage.qml");
165 dlg->setShowEndButton(false);
171 void StkAgentService::DisplayText(const QString &title, uchar icon, bool urgent)
173 // handle method call org.ofono.SimToolkitAgent.DisplayText
174 qDebug() << "DisplayText: " << title << "(" << icon << ")" << " urgent: " << urgent;
176 StkDialog * dlg = addNewWidget(title, icon,"qrc:/StkPopup.qml");
178 if (dlg->exec() != QDialog::Accepted)
180 AgentResponse ret = dlg->getAgentResponse();
185 connection().send(message().createErrorReply(STK_ERR_BACK,""));
188 connection().send(message().createErrorReply(STK_ERR_END,""));
196 void StkAgentService::LoopTone(const QString &tone, const QString &text, uchar icon)
198 // handle method call org.ofono.SimToolkitAgent.LoopTone
199 qDebug() << "LoopTone: " << tone << " : " << text << "(" << icon << ")";
201 StkDialog *dlg = addNewWidget(text + "(playing: " + tone + ")",
202 icon, "qrc:/StkPlaySound.qml");
203 dlg->setLoopTone(true);
204 dlg->setToneSource(tone);
210 void StkAgentService::PlayTone(const QString &tone, const QString &text, uchar icon)
212 // handle method call org.ofono.SimToolkitAgent.PlayTone
213 qDebug() << "PlayTone: " << tone << " : " << text << "(" << icon << ")";
215 StkDialog * dlg = addNewWidget(text + "(playing: " + tone + ")",
216 icon, "qrc:/StkPlaySound.qml");
217 dlg->setToneSource(tone);
219 if (dlg->exec() != QDialog::Accepted)
221 AgentResponse ret = dlg->getAgentResponse();
226 connection().send(message().createErrorReply(STK_ERR_END,""));
234 void StkAgentService::Release()
236 // handle method call org.ofono.SimToolkitAgent.Release
237 qDebug() << "Release" ;
238 while (closeLastWidget()) {}
240 QApplication::instance()->exit();
244 bool StkAgentService::RequestConfirmation(const QString &title, uchar icon)
246 // handle method call org.ofono.SimToolkitAgent.RequestConfirmation
247 bool out0 = FALLBACK_BOOL;
248 qDebug() << "RequestConfirmation: " << title << "(" << icon << ")";
250 StkDialog * dlg = addNewWidget(title, icon,"qrc:/StkYesNo.qml");
252 if (dlg->exec() != QDialog::Accepted)
254 AgentResponse ret = dlg->getAgentResponse();
263 connection().send(message().createErrorReply(STK_ERR_BACK,""));
266 connection().send(message().createErrorReply(STK_ERR_END,""));
275 QString StkAgentService::RequestDigit(const QString &title, uchar icon)
277 // handle method call org.ofono.SimToolkitAgent.RequestDigit
278 QString out0 = FALLBACK_QSTRING;
279 qDebug() << "RequestDigit: " << title << "(" << icon << ")";
281 StkDialog * dlg = addNewWidget(title, icon,"qrc:/StkInputKey.qml");
282 dlg->setNumeric(true);
284 if (dlg->exec() != QDialog::Accepted)
286 AgentResponse ret = dlg->getAgentResponse();
289 out0 = dlg->getResponseData().toString();
292 connection().send(message().createErrorReply(STK_ERR_BACK,""));
295 connection().send(message().createErrorReply(STK_ERR_END,""));
304 QString StkAgentService::RequestDigits(const QString &title, uchar icon,
305 const QString &defaultValue,
306 uchar minChars, uchar maxChars, bool hideTyping)
308 // handle method call org.ofono.SimToolkitAgent.RequestDigits
309 QString out0 = defaultValue;
310 qDebug() << "RequestDigits: " << title << "(" << icon << ")" << " (" << defaultValue
311 << ") [" << minChars << ".." << maxChars << "] passwd:" << hideTyping;
313 StkDialog * dlg = addNewWidget(title, icon,
314 hideTyping ? "qrc:/StkPassword.qml" : "qrc:/StkInputText.qml");
315 dlg->setDefaultText(defaultValue);
316 dlg->setCharBounds((int)minChars,(int)maxChars);
317 dlg->setHideTyping(hideTyping);
318 dlg->setNumeric(true);
320 if (dlg->exec() != QDialog::Accepted)
322 AgentResponse ret = dlg->getAgentResponse();
325 out0 = dlg->getResponseData().toString();
328 connection().send(message().createErrorReply(STK_ERR_BACK,""));
331 connection().send(message().createErrorReply(STK_ERR_END,""));
340 QString StkAgentService::RequestInput(const QString &title, uchar icon,
341 const QString &defaultValue,
342 uchar minChars, uchar maxChars, bool hideTyping)
344 // handle method call org.ofono.SimToolkitAgent.RequestInput
345 QString out0 = defaultValue;
346 qDebug() << "RequestInput: " << title << "(" << icon << ")" << " (" << defaultValue
347 << ") [" << minChars << ".." << maxChars << "] passwd:" << hideTyping;
349 StkDialog * dlg = addNewWidget(title, icon,
350 hideTyping ? "qrc:/StkPassword.qml" : "qrc:/StkInputText.qml");
351 dlg->setDefaultText(defaultValue);
352 dlg->setCharBounds((int)minChars,(int)maxChars);
353 dlg->setHideTyping(hideTyping);
354 dlg->setNumeric(false);
356 if (dlg->exec() != QDialog::Accepted)
358 AgentResponse ret = dlg->getAgentResponse();
361 out0 = dlg->getResponseData().toString();
364 connection().send(message().createErrorReply(STK_ERR_BACK,""));
367 connection().send(message().createErrorReply(STK_ERR_END,""));
376 QString StkAgentService::RequestKey(const QString &title, uchar icon)
378 // handle method call org.ofono.SimToolkitAgent.RequestKey
379 QString out0 = FALLBACK_QSTRING;
380 qDebug() << "RequestKey: " << title << "(" << icon << ")";
382 StkDialog * dlg = addNewWidget(title, icon,"qrc:/StkInputKey.qml");
383 dlg->setNumeric(false);
385 if (dlg->exec() != QDialog::Accepted)
387 AgentResponse ret = dlg->getAgentResponse();
390 out0 = dlg->getResponseData().toString();
393 connection().send(message().createErrorReply(STK_ERR_BACK,""));
396 connection().send(message().createErrorReply(STK_ERR_END,""));
405 uchar StkAgentService::RequestSelection(const QString &title, uchar icon, OfonoMenuList items,
408 // handle method call org.ofono.SimToolkitAgent.RequestSelection
409 uchar out0 = FALLBACK_UCHAR;
410 qDebug() << "RequestSelection: " << title << "(" << icon << ")" << " default: " << defaultValue;
412 QList<StkMenuItem> dlgitems;
413 foreach (const OfonoMenuEntry entry, items)
414 dlgitems.append(StkMenuItem(StkOfonoUtils::findIconUrl(entry.icon), entry.label));
415 StkDialog * dlg = addNewWidget(title, icon,"qrc:/StkMenu.qml");
416 dlg->setMenuItems(dlgitems);
417 dlg->setSelection(int(defaultValue));
419 if (dlg->exec() != QDialog::Accepted)
421 AgentResponse ret = dlg->getAgentResponse();
424 out0 = (uchar)dlg->getResponseData().toInt();
427 connection().send(message().createErrorReply(STK_ERR_BACK,""));
430 connection().send(message().createErrorReply(STK_ERR_END,""));
439 /* private functions */
442 StkDialog * StkAgentService::addNewWidget(const QString &info, uchar icon,
443 const QString &qmlViewUrl)
445 StkDialog * dlg = new StkDialog(new SimImageProvider(mSimIf),
446 StkOfonoUtils::findIconUrl(icon), info, qmlViewUrl);
447 mWidgetStack.append(dlg);
452 bool StkAgentService::closeLastWidget()
454 if (!mWidgetStack.isEmpty()) {
455 QWidget * widget = mWidgetStack.takeLast();
459 return !mWidgetStack.isEmpty();