|
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: |
|
15 * |
|
16 */ |
|
17 #include "lunchwidget.h" |
|
18 #include <QRect> |
|
19 #include <QPainter> |
|
20 #include <QUrl> |
|
21 #include <qservicemanager.h> |
|
22 #include <afactivities_global.h> |
|
23 #include <hbcheckbox.h> |
|
24 #include <hbcombobox.h> |
|
25 #include <afactivitylauncher.h> |
|
26 #include <XQConversions> |
|
27 |
|
28 QTM_USE_NAMESPACE |
|
29 |
|
30 const QString KAppUid = "Efe0aa02"; |
|
31 const QString KActUid = "Eba3ddd2"; |
|
32 |
|
33 lunchwidget::lunchwidget(QGraphicsItem *parent) |
|
34 : HbWidget(parent) |
|
35 { |
|
36 |
|
37 QServiceManager serviceManager; |
|
38 mActivityManager = serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager"); |
|
39 if (!mActivityManager) { |
|
40 qFatal("Cannot initialize critical com.nokia.qt.activities.ActivityManager service."); |
|
41 } |
|
42 mBackgroundCheckBox = new HbCheckBox("background"); |
|
43 mBackgroundCheckBox->setCheckState(Qt::Unchecked); |
|
44 mLunchButton = new HbPushButton("Lunch App"); |
|
45 mLunchButton1 = new HbPushButton("Lunch Act"); |
|
46 mResultLabel = new HbLabel; |
|
47 mPlatformCombo = new HbComboBox(); |
|
48 mPlatformCombo->addItem("Qt"); |
|
49 mPlatformCombo->addItem("Symbian"); |
|
50 |
|
51 mGridLayout = new QGraphicsGridLayout(); |
|
52 mGridLayout->addItem(mResultLabel, 0, 0, 1, 1); |
|
53 mGridLayout->addItem(mLunchButton, 1, 0, 1, 1); |
|
54 mGridLayout->addItem(mLunchButton1, 2, 0, 1, 1); |
|
55 mGridLayout->addItem(mBackgroundCheckBox, 3, 0, 1, 1); |
|
56 mGridLayout->addItem(mPlatformCombo, 4, 0, 1, 1); |
|
57 setLayout(mGridLayout); |
|
58 |
|
59 |
|
60 connect(mLunchButton, SIGNAL(released()), this, SLOT(lunchApp())); |
|
61 connect(mLunchButton1, SIGNAL(released()), this, SLOT(lunchAct())); |
|
62 |
|
63 User::LeaveIfError(mApaLsSession.Connect()); |
|
64 User::LeaveIfError(mWsSession.Connect()); |
|
65 mSymbianAL = CAfActivityLauncher::NewL(mApaLsSession, mWsSession) ; |
|
66 |
|
67 } |
|
68 |
|
69 lunchwidget::~lunchwidget() |
|
70 { |
|
71 mApaLsSession.Close(); |
|
72 mWsSession.Close(); |
|
73 delete mSymbianAL; |
|
74 } |
|
75 |
|
76 void lunchwidget::lunchApp() |
|
77 { |
|
78 QUrl url; |
|
79 url.setScheme(Af::KActivityScheme); |
|
80 url.setHost(KAppUid); |
|
81 url.addQueryItem(Af::KActivityUriNameKey, "nonexist"); |
|
82 if (mBackgroundCheckBox->checkState() == Qt::Checked) { |
|
83 url.addQueryItem(Af::KActivityUriBackgroundKey, "back"); |
|
84 } |
|
85 url.addQueryItem("param1", "trompka"); |
|
86 QString debugString = url.toString(); |
|
87 lunch(url); |
|
88 } |
|
89 |
|
90 void lunchwidget::lunchAct() |
|
91 { |
|
92 QUrl url; |
|
93 url.setScheme(Af::KActivityScheme); |
|
94 url.setHost(KActUid); |
|
95 url.addQueryItem(Af::KActivityUriNameKey, "bold"); |
|
96 if (mBackgroundCheckBox->checkState() == Qt::Checked) { |
|
97 url.addQueryItem(Af::KActivityUriBackgroundKey, "back"); |
|
98 } |
|
99 url.addQueryItem("param1", "trompka"); |
|
100 QString debugString = url.toString(); |
|
101 |
|
102 lunch(url); |
|
103 } |
|
104 |
|
105 void lunchwidget::lunch(const QUrl& url) |
|
106 { |
|
107 bool ok = true; |
|
108 if(mPlatformCombo->currentText() == "Qt") { |
|
109 ok = QMetaObject::invokeMethod(mActivityManager, "launchActivity", Q_ARG(QUrl, url) ); |
|
110 } |
|
111 else { |
|
112 HBufC *uriDescriptor = XQConversions::qStringToS60Desc(QString(url.toEncoded())); |
|
113 TRAPD(err, mSymbianAL->launchActivityL(*uriDescriptor)); |
|
114 bool errbool = static_cast<bool>(err); |
|
115 ok = !errbool; |
|
116 delete uriDescriptor; |
|
117 } |
|
118 |
|
119 if ( ok ) { |
|
120 mResultLabel->setPlainText( "ok" ); |
|
121 } |
|
122 else { |
|
123 mResultLabel->setPlainText( "fail" ); |
|
124 } |
|
125 } |