|
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 <qservicemanager.h> |
|
18 #include <HbInstance> |
|
19 #include <QStringList> |
|
20 #include <QCoreApplication> |
|
21 #include <hbapplication.h> |
|
22 #include "viewmanager.h" |
|
23 #include "letterwidget.h" |
|
24 #include <QGraphicsGridLayout> |
|
25 #include <HbPushButton> |
|
26 #include "afstorageglobals.h" |
|
27 |
|
28 QTM_USE_NAMESPACE |
|
29 |
|
30 viewmanager::viewmanager(): |
|
31 HbMainWindow() |
|
32 { |
|
33 mLw = new letterwidget; |
|
34 addView(mLw); |
|
35 |
|
36 QServiceManager serviceManager; |
|
37 mActivityStorage = serviceManager.loadInterface("com.nokia.qt.activities.Storage"); |
|
38 if (!mActivityStorage) { |
|
39 qFatal("load Storage plugin failed"); |
|
40 } |
|
41 |
|
42 mActivaction = serviceManager.loadInterface("com.nokia.qt.activities.Activation"); |
|
43 if (!mActivaction) { |
|
44 qFatal("load Activation plugin failed"); |
|
45 } |
|
46 |
|
47 qRegisterMetaType<Af::ActivationReason>("Af::ActivationReason"); |
|
48 connect(mActivaction, SIGNAL(activated(Af::ActivationReason, QString, QVariantHash)), this, SLOT(loadActivityData(Af::ActivationReason, QString, QVariantHash))); |
|
49 |
|
50 |
|
51 //startup case |
|
52 Af::ActivationReason reason; |
|
53 bool ok = QMetaObject::invokeMethod(mActivaction, "reason", Q_RETURN_ARG(Af::ActivationReason, reason)); |
|
54 if (!ok) { |
|
55 qFatal("Get reason failed"); |
|
56 } |
|
57 QString actName; |
|
58 QVariantHash parameters; |
|
59 if (reason == Af::ActivationReasonActivity) { |
|
60 ok = QMetaObject::invokeMethod(mActivaction, "name", Q_RETURN_ARG(QString, actName)); |
|
61 if (!ok) { |
|
62 qFatal("Get name failed"); |
|
63 } |
|
64 ok = QMetaObject::invokeMethod(mActivaction, "parameters", Q_RETURN_ARG(QVariantHash, parameters)); |
|
65 if (!ok) { |
|
66 qFatal("Get parameter failed"); |
|
67 } |
|
68 |
|
69 QVariant data; |
|
70 ok = QMetaObject::invokeMethod(mActivityStorage, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, actName)); |
|
71 if (!ok) { |
|
72 qFatal("Get data failed"); |
|
73 } |
|
74 loadActivityData(data); |
|
75 } |
|
76 //startup case end |
|
77 |
|
78 connect(mLw, SIGNAL(save()), this, SLOT(save())); |
|
79 connect(mLw, SIGNAL(del()), this, SLOT(del())); |
|
80 } |
|
81 |
|
82 viewmanager::~viewmanager() |
|
83 { |
|
84 delete mActivityStorage; |
|
85 delete mActivaction; |
|
86 } |
|
87 |
|
88 void viewmanager::save() |
|
89 { |
|
90 mSaveVariant = mLw->state(); |
|
91 |
|
92 HbMainWindow *mainWindow = hbInstance->allMainWindows().first(); |
|
93 QPixmap screenshot = QPixmap::grabWidget(mainWindow, mainWindow->rect()); |
|
94 QVariantHash metadata; |
|
95 metadata.insert(ActivityScreenshotKeyword, screenshot); |
|
96 |
|
97 bool ok, retok; |
|
98 ok = QMetaObject::invokeMethod(mActivityStorage, "saveActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, mLw->state()), Q_ARG(QVariant, mSaveVariant), Q_ARG(QVariantHash, metadata)); |
|
99 |
|
100 if (!ok || !retok) { |
|
101 qFatal("Save failed"); |
|
102 } |
|
103 } |
|
104 void viewmanager::del() |
|
105 { |
|
106 bool retok; |
|
107 bool ok = QMetaObject::invokeMethod(mActivityStorage, "removeActivity", Q_RETURN_ARG(bool, retok), Q_ARG(QString, mLw->state())); |
|
108 if (!ok) { |
|
109 qFatal("Remove failed"); |
|
110 } |
|
111 } |
|
112 |
|
113 void viewmanager::loadActivityData(Af::ActivationReason reason, const QString &name, QVariantHash parameter) |
|
114 { |
|
115 QVariant data; |
|
116 bool ok = QMetaObject::invokeMethod(mActivityStorage, "activityData", Q_RETURN_ARG(QVariant, data), Q_ARG(QString, name)); |
|
117 if (!ok) { |
|
118 qFatal("Get data failed"); |
|
119 } |
|
120 loadActivityData(data); |
|
121 } |
|
122 |
|
123 void viewmanager::loadActivityData(const QVariant &data) |
|
124 { |
|
125 QString statename = data.toString(); |
|
126 mLw->setState(statename); |
|
127 } |