20 #include <QDebug> |
20 #include <QDebug> |
21 #include <QItemSelectionModel> |
21 #include <QItemSelectionModel> |
22 #include <hbnotificationdialog.h> |
22 #include <hbnotificationdialog.h> |
23 #include <QProcess> |
23 #include <QProcess> |
24 #include <hbinstance.h> |
24 #include <hbinstance.h> |
25 #include <HbActivityManager.h> |
|
26 #include <hbapplication.h> |
25 #include <hbapplication.h> |
|
26 #include <afactivitystorage.h> |
|
27 #include <afactivation.h> |
|
28 |
27 |
29 |
28 //user includes |
30 //user includes |
29 #include "glxstatemanager.h" |
31 #include "glxstatemanager.h" |
30 #include "glxviewmanager.h" |
32 #include "glxviewmanager.h" |
31 #include "glxviewids.h" |
33 #include "glxviewids.h" |
61 mCurrentModel( NULL ), |
63 mCurrentModel( NULL ), |
62 mCurrentState( NULL ), |
64 mCurrentState( NULL ), |
63 mActionHandler( NULL ), |
65 mActionHandler( NULL ), |
64 mTNObserver ( NULL ), |
66 mTNObserver ( NULL ), |
65 isProgressbarRunning ( false ), |
67 isProgressbarRunning ( false ), |
66 mFetcherFilterType ( EGlxFetcherFilterNone ) |
68 mFetcherFilterType ( EGlxFetcherFilterNone ), |
|
69 mActivityStorage (NULL), |
|
70 mActivation (NULL) |
67 { |
71 { |
68 qDebug("GlxStateManager::GlxStateManager"); |
72 qDebug("GlxStateManager::GlxStateManager"); |
69 PERFORMANCE_ADV ( d1, "view manager creation time") { |
73 PERFORMANCE_ADV ( d1, "view manager creation time") { |
70 mViewManager = new GlxViewManager(); |
74 mViewManager = new GlxViewManager(); |
71 } |
75 } |
72 mTNObserver = new GlxTNObserver(); |
76 mTNObserver = new GlxTNObserver(); |
|
77 mActivityStorage = new AfActivityStorage(); |
|
78 mActivation = new AfActivation(); |
73 |
79 |
74 connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection ); |
80 connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection ); |
75 connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection ); |
81 connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection ); |
76 connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |
82 connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |
77 connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData())); |
83 connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData())); |
78 //TO:DO TBD through exception when it is null |
84 //TO:DO TBD through exception when it is null |
79 } |
85 } |
80 |
86 |
81 void GlxStateManager::enterMarkingMode() |
87 void GlxStateManager::enterMarkingMode() |
82 { |
88 { |
83 mViewManager->enterMarkingMode(mCurrentState->id()); |
89 mViewManager->enterMarkingMode( mCurrentState->id(), mCurrentState->commandId() ); |
84 } |
90 } |
85 |
91 |
86 void GlxStateManager::exitMarkingMode() |
92 void GlxStateManager::exitMarkingMode() |
87 { |
93 { |
88 mViewManager->exitMarkingMode(mCurrentState->id()); |
94 mViewManager->exitMarkingMode(mCurrentState->id()); |
135 void GlxStateManager::launchApplication() |
141 void GlxStateManager::launchApplication() |
136 { |
142 { |
137 qDebug("GlxStateManager::launchApplication"); |
143 qDebug("GlxStateManager::launchApplication"); |
138 bool activitySuccess = false; |
144 bool activitySuccess = false; |
139 //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S) |
145 //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S) |
140 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
146 |
141 if(app->activateReason() == Hb::ActivationReasonActivity) { |
147 if( mActivation->reason() == Af::ActivationReasonActivity ) { |
142 activitySuccess = launchActivity(); |
148 activitySuccess = launchActivity(); |
|
149 qDebug("GlxStateManager::launchApplication as Activity"); |
143 } |
150 } |
144 |
151 |
145 if( !activitySuccess ) { |
152 if( !activitySuccess ) { |
146 mCurrentState = createState( GLX_GRIDVIEW_ID ); |
153 mCurrentState = createState( GLX_GRIDVIEW_ID ); |
147 mCurrentState->setState( ALL_ITEM_S ); |
154 mCurrentState->setState( ALL_ITEM_S ); |
156 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel ); |
163 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel ); |
157 } |
164 } |
158 mTNObserver->startTNObserving() ; |
165 mTNObserver->startTNObserving() ; |
159 } |
166 } |
160 |
167 |
161 HbActivityManager* activityManager = app->activityManager(); |
168 |
162 bool ok = activityManager->removeActivity("PhotosMainView"); |
169 bool ok = mActivityStorage->removeActivity("PhotosMainView"); |
163 if ( !ok ) |
170 if ( !ok ) |
164 { |
171 { |
165 qDebug("launchapplication::Remove activity failed" ); |
172 qDebug("launchapplication::Remove activity failed" ); |
166 } |
173 } |
167 } |
174 } |
168 |
175 |
169 bool GlxStateManager::launchActivity() |
176 bool GlxStateManager::launchActivity() |
170 { |
177 { |
171 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
178 QVariant data = mActivityStorage->activityData("PhotosMainView"); |
172 bool ok = app->activityManager()->waitActivity(); |
|
173 if ( !ok ) |
|
174 { |
|
175 qDebug("subscribing to activity manager failed" ); |
|
176 } |
|
177 QVariant data = app->activityManager()->activityData( "PhotosMainView" ); |
|
178 QByteArray serializedModel = data.toByteArray(); |
179 QByteArray serializedModel = data.toByteArray(); |
179 QDataStream stream(&serializedModel, QIODevice::ReadOnly); |
180 QDataStream stream(&serializedModel, QIODevice::ReadOnly); |
180 |
181 |
181 //Fetch the data from the activity Manager |
182 //Fetch the data from the activity Manager |
182 stream >> mSaveActivity; |
183 stream >> mSaveActivity; |
183 qint32 stateId = mSaveActivity.value("ID"); |
184 |
|
185 if(!validateActivityData()) |
|
186 return false; |
|
187 |
|
188 qint32 stateId = mSaveActivity.value("ID"); |
184 mCurrentState = createState(stateId); |
189 mCurrentState = createState(stateId); |
185 mCurrentState->setState( mSaveActivity.value("InternalState") ); |
190 mCurrentState->setState( mSaveActivity.value("InternalState") ); |
186 createModel( stateId); |
191 createModel( stateId); |
187 /*Model might not be populated yet to set the visibleWindowIndex right away. |
192 /*Model might not be populated yet to set the visibleWindowIndex right away. |
188 *So, let us store the visible index as a temporary Variable, so that visible Window Index |
193 *So, let us store the visible index as a temporary Variable, so that visible Window Index |
190 */ |
195 */ |
191 mCurrentModel->setData(QModelIndex(), mSaveActivity.value("VisibleIndex") , GlxTempVisualWindowIndex ); |
196 mCurrentModel->setData(QModelIndex(), mSaveActivity.value("VisibleIndex") , GlxTempVisualWindowIndex ); |
192 mViewManager->launchApplication(stateId, mCurrentModel); |
197 mViewManager->launchApplication(stateId, mCurrentModel); |
193 return true; |
198 return true; |
194 } |
199 } |
|
200 |
|
201 bool GlxStateManager::validateActivityData() |
|
202 { |
|
203 |
|
204 if( (mSaveActivity.value("ID") == GLX_GRIDVIEW_ID) || |
|
205 ( (mSaveActivity.value("ID") == GLX_LISTVIEW_ID) && (mSaveActivity.value("InternalState") == ALL_ITEM_S) ) || |
|
206 (mSaveActivity.value("VisibleIndex") >= 0 ) ) { |
|
207 qDebug("GlxStateManager::validation passed"); |
|
208 return true; |
|
209 } |
|
210 |
|
211 qDebug("GlxStateManager::Validation failed"); |
|
212 qDebug("VIEW : %u", mSaveActivity.value("ID")); |
|
213 qDebug("SUB STATE: %u", mSaveActivity.value("InternalState")); |
|
214 qDebug("Visible Index: %u", mSaveActivity.value("VisibleIndex")); |
|
215 |
|
216 return false; |
|
217 |
|
218 } |
|
219 |
195 |
220 |
196 void GlxStateManager::launchFromExternal() |
221 void GlxStateManager::launchFromExternal() |
197 { |
222 { |
198 qDebug("GlxStateManager::launchFromExternal"); |
223 qDebug("GlxStateManager::launchFromExternal"); |
199 mCurrentState = createState(GLX_FULLSCREENVIEW_ID); |
224 mCurrentState = createState(GLX_FULLSCREENVIEW_ID); |
274 } |
299 } |
275 else { |
300 else { |
276 mSaveActivity.insert("VisibleIndex",0); |
301 mSaveActivity.insert("VisibleIndex",0); |
277 } |
302 } |
278 |
303 |
279 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
304 |
280 QVariantHash metadata; |
305 QVariantHash metadata; |
281 HbMainWindow *window = hbInstance->allMainWindows().first(); |
306 HbMainWindow *window = hbInstance->allMainWindows().first(); |
282 metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect())); |
307 metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect())); |
283 |
308 |
284 QByteArray serializedModel; |
309 QByteArray serializedModel; |
285 QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append); |
310 QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append); |
286 stream << mSaveActivity; |
311 stream << mSaveActivity; |
287 |
312 bool ok = mActivityStorage->saveActivity("PhotosMainView", serializedModel, metadata); |
288 bool ok = activityManager->addActivity("PhotosMainView", serializedModel, metadata); |
313 |
289 if ( !ok ) |
314 if ( !ok ) |
290 { |
315 { |
291 qDebug("SaveData::Add activity failed" ); |
316 qDebug("SaveData::Save activity failed" ); |
292 } |
317 } |
293 } |
318 } |
294 } |
319 } |
295 |
320 |
296 void GlxStateManager::nextState(qint32 state, int internalState) |
321 void GlxStateManager::nextState(qint32 state, int internalState) |
792 { |
817 { |
793 qDebug("GlxStateManager::~GlxStateManager"); |
818 qDebug("GlxStateManager::~GlxStateManager"); |
794 cleanAllModel(); |
819 cleanAllModel(); |
795 mSaveActivity.clear(); |
820 mSaveActivity.clear(); |
796 delete mActionHandler; |
821 delete mActionHandler; |
|
822 delete mActivation; |
|
823 delete mActivityStorage; |
797 qDebug("GlxStateManager::~GlxStateManager delete Model"); |
824 qDebug("GlxStateManager::~GlxStateManager delete Model"); |
798 |
825 |
799 disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) ); |
826 disconnect ( mViewManager, SIGNAL(actionTriggered(qint32 )), this, SLOT(actionTriggered(qint32 )) ); |
800 disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) ); |
827 disconnect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) ); |
801 disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |
828 disconnect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |