|
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: Menu Application Library state. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbmainwindow.h> |
|
19 #include <hbview.h> |
|
20 #include <hbinstance.h> |
|
21 #include <qstatemachine.h> |
|
22 #include <hbaction.h> |
|
23 #include <qpluginloader.h> |
|
24 |
|
25 #include "hsdomainmodel_global.h" |
|
26 #include "hsapp_defs.h" |
|
27 #include "hsmenuevent.h" |
|
28 #include "hsviewappsettingsstate.h" |
|
29 #include "caentry.h" |
|
30 #include "canotifier.h" |
|
31 #include "canotifierfilter.h" |
|
32 |
|
33 #include "hsmenuservice.h" |
|
34 |
|
35 /*! |
|
36 \class HsCollectionNameDialog |
|
37 \ingroup HsViewAppSettingsState |
|
38 \brief State for showing Application Settings HbView from provided plugin |
|
39 */ |
|
40 |
|
41 /*! |
|
42 Constructor |
|
43 \param parent: parent state |
|
44 \retval void |
|
45 */ |
|
46 HsViewAppSettingsState::HsViewAppSettingsState(QState *parent) : |
|
47 QState(parent), |
|
48 mView(0), |
|
49 mPreviousView(0), |
|
50 mActionConfirm(0), |
|
51 mNotifier(0) |
|
52 |
|
53 { |
|
54 construct(); |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void HsViewAppSettingsState::construct() |
|
61 { |
|
62 setObjectName(this->parent()->objectName() |
|
63 + "/ViewAppSettingsState"); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Destructor. |
|
68 */ |
|
69 HsViewAppSettingsState::~HsViewAppSettingsState() |
|
70 { |
|
71 if (mNotifier) { |
|
72 delete mNotifier; |
|
73 } |
|
74 } |
|
75 |
|
76 /*! |
|
77 onEntry method invoked on entering the state |
|
78 \param event: event |
|
79 \retval void |
|
80 */ |
|
81 void HsViewAppSettingsState::onEntry(QEvent *event) |
|
82 { |
|
83 HSMENUTEST_FUNC_ENTRY("HsViewAppSettingsState::onEntry"); |
|
84 QState::onEntry(event); |
|
85 qDebug("CollectionState::onEntry()"); |
|
86 HsMenuEvent *menuEvent = static_cast<HsMenuEvent *>(event); |
|
87 QVariantMap data = menuEvent->data(); |
|
88 |
|
89 const int entryId = data.value(itemIdKey()).toInt(); |
|
90 QSharedPointer<const CaEntry> entry = CaService::instance()->getEntry(entryId); |
|
91 |
|
92 if(mView) |
|
93 { |
|
94 |
|
95 delete mActionConfirm; |
|
96 mActionConfirm = NULL; |
|
97 |
|
98 delete mView; |
|
99 mView = NULL; |
|
100 |
|
101 } |
|
102 |
|
103 QString pluginPath(entry->attribute(appSettingsPlugin())); |
|
104 QPluginLoader loader(pluginPath); |
|
105 mView = qobject_cast<HbView *>(loader.instance()); |
|
106 |
|
107 mActionConfirm = new HbAction(Hb::ConfirmNaviAction, mView); |
|
108 connect(mActionConfirm, SIGNAL(triggered()),SLOT(settingsDone())); |
|
109 |
|
110 if(mView) |
|
111 { |
|
112 subscribeForMemoryCardRemove(entryId); |
|
113 QObject::connect(this, SIGNAL(initialize(QString)), mView, SLOT(initialize(QString))); |
|
114 mView->setParent(this); |
|
115 emit initialize(entry->attribute(applicationUidEntryKey())); |
|
116 // Add View to main window |
|
117 HbMainWindow *hbMainWindow = mainWindow(); |
|
118 // add confirm action |
|
119 mView->setNavigationAction(mActionConfirm); |
|
120 |
|
121 hbMainWindow->addView(mView); |
|
122 // record the current view in order to activate it once done |
|
123 mPreviousView = hbMainWindow->currentView(); |
|
124 hbMainWindow->setCurrentView(mView); |
|
125 hbMainWindow->show(); |
|
126 } |
|
127 |
|
128 |
|
129 HSMENUTEST_FUNC_EXIT("HsViewAppSettingsState::onEntry"); |
|
130 } |
|
131 |
|
132 |
|
133 #ifdef COVERAGE_MEASUREMENT |
|
134 #pragma CTC SKIP |
|
135 #endif //COVERAGE_MEASUREMENT |
|
136 HbMainWindow *HsViewAppSettingsState::mainWindow() const |
|
137 { |
|
138 return HbInstance::instance()->allMainWindows().value(0); |
|
139 } |
|
140 #ifdef COVERAGE_MEASUREMENT |
|
141 #pragma CTC ENDSKIP |
|
142 #endif //COVERAGE_MEASUREMENT |
|
143 |
|
144 |
|
145 #ifdef COVERAGE_MEASUREMENT |
|
146 #pragma CTC SKIP |
|
147 #endif //COVERAGE_MEASUREMENT |
|
148 void HsViewAppSettingsState::settingsDone() |
|
149 { |
|
150 // Remove mView from main window and restore previous view. |
|
151 HbMainWindow *hbMainWindow = mainWindow(); |
|
152 hbMainWindow->setCurrentView(mPreviousView); |
|
153 hbMainWindow->removeView(mView); |
|
154 delete mActionConfirm; |
|
155 mActionConfirm = NULL; |
|
156 delete mView; |
|
157 mView = NULL; |
|
158 } |
|
159 #ifdef COVERAGE_MEASUREMENT |
|
160 #pragma CTC ENDSKIP |
|
161 #endif //COVERAGE_MEASUREMENT |
|
162 |
|
163 /*! |
|
164 Subscribe for memory card remove. |
|
165 \param entryId: entry id. |
|
166 \retval void |
|
167 */ |
|
168 void HsViewAppSettingsState::subscribeForMemoryCardRemove(int entryId) |
|
169 { |
|
170 CaNotifierFilter filter; |
|
171 QList<int> entryIds; |
|
172 entryIds.append(entryId); |
|
173 filter.setIds(entryIds); |
|
174 mNotifier = CaService::instance()->createNotifier(filter); |
|
175 mNotifier->setParent(this); |
|
176 connect(mNotifier, |
|
177 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
178 SLOT(settingsDone())); |
|
179 } |
|
180 |