67 qDebug("GlxStateManager::GlxStateManager"); |
67 qDebug("GlxStateManager::GlxStateManager"); |
68 PERFORMANCE_ADV ( d1, "view manager creation time") { |
68 PERFORMANCE_ADV ( d1, "view manager creation time") { |
69 mViewManager = new GlxViewManager(); |
69 mViewManager = new GlxViewManager(); |
70 } |
70 } |
71 mTNObserver = new GlxTNObserver(); |
71 mTNObserver = new GlxTNObserver(); |
72 mSaveActivity.clear(); |
|
73 |
72 |
74 connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection ); |
73 connect ( this, SIGNAL( setupItemsSignal() ), this, SLOT( setupItems() ), Qt::QueuedConnection ); |
75 connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection ); |
74 connect ( mViewManager, SIGNAL(actionTriggered( qint32 )), this, SLOT(actionTriggered( qint32 )), Qt::QueuedConnection ); |
76 connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |
75 connect ( mTNObserver, SIGNAL( leftTNCount( int ) ), this, SLOT( updateTNProgress( int ) ) ); |
77 connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData())); |
76 connect ( qobject_cast<HbApplication*>(qApp), SIGNAL (aboutToQuit()), this, SLOT(saveData())); |
120 mTNObserver->stopTNMDaemon(); |
119 mTNObserver->stopTNMDaemon(); |
121 } |
120 } |
122 return QObject::eventFilter(obj, event); |
121 return QObject::eventFilter(obj, event); |
123 } |
122 } |
124 |
123 |
|
124 void GlxStateManager::launchFetcher() |
|
125 { |
|
126 qDebug("GlxStateManager::launchFetcher"); |
|
127 mCurrentState = createState(GLX_GRIDVIEW_ID); |
|
128 mCurrentState->setState(FETCHER_ITEM_S); |
|
129 |
|
130 createModel(GLX_GRIDVIEW_ID); |
|
131 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel); |
|
132 } |
|
133 |
125 void GlxStateManager::launchApplication() |
134 void GlxStateManager::launchApplication() |
126 { |
135 { |
127 qDebug("GlxStateManager::launchApplication"); |
136 qDebug("GlxStateManager::launchApplication"); |
128 bool activitySuccess = false; |
137 bool activitySuccess = false; |
129 //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S) |
138 //To:Do use it in future once performance code is removed nextState(GLX_GRIDVIEW_ID, ALL_ITEM_S) |
130 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
139 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
131 if(app->activateReason() == Hb::ActivationReasonActivity) { |
140 if(app->activateReason() == Hb::ActivationReasonActivity) { |
132 activitySuccess = launchActivity(); |
141 activitySuccess = launchActivity(); |
133 } |
142 } |
134 if( !activitySuccess ) { |
143 |
135 mCurrentState = createState( GLX_GRIDVIEW_ID ); |
144 if( !activitySuccess ) { |
136 mCurrentState->setState( ALL_ITEM_S ); |
145 mCurrentState = createState( GLX_GRIDVIEW_ID ); |
137 |
146 mCurrentState->setState( ALL_ITEM_S ); |
138 int leftCount = mTNObserver->getTNLeftCount() ; |
147 |
139 if ( leftCount > 0 ) { |
148 int leftCount = mTNObserver->getTNLeftCount() ; |
140 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel); |
149 if ( leftCount > 0 ) { |
141 launchProgressDialog(); |
150 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel ); |
142 } |
151 launchProgressDialog(); |
143 else { |
152 } |
144 createModel( GLX_GRIDVIEW_ID ); |
153 else { |
145 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel); |
154 createModel( GLX_GRIDVIEW_ID ); |
146 } |
155 mViewManager->launchApplication( GLX_GRIDVIEW_ID, mCurrentModel ); |
147 |
156 } |
148 mTNObserver->startTNObserving() ; |
157 mTNObserver->startTNObserving() ; |
149 } |
158 } |
150 //Remove the previous activity |
159 |
151 HbActivityManager* activityManager = app->activityManager(); |
160 HbActivityManager* activityManager = app->activityManager(); |
152 bool ok = activityManager->removeActivity("PhotosMainView"); |
161 bool ok = activityManager->removeActivity("PhotosMainView"); |
153 if ( !ok ) |
162 if ( !ok ) |
154 { |
163 { |
155 qDebug("launchapplication::Remove activity failed" ); |
164 qDebug("launchapplication::Remove activity failed" ); |
156 } |
165 } |
157 } |
166 } |
|
167 |
158 bool GlxStateManager::launchActivity() |
168 bool GlxStateManager::launchActivity() |
159 { |
169 { |
160 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
170 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
161 bool ok = app->activityManager()->waitActivity(); |
171 bool ok = app->activityManager()->waitActivity(); |
162 if ( !ok ) |
172 if ( !ok ) |
163 { |
173 { |
164 qDebug("subscribing to activity manager failed" ); |
174 qDebug("subscribing to activity manager failed" ); |
165 //return false; TBD: waitActivity is always returning false. Could be some issue with AM. |
|
166 } |
175 } |
167 QVariant data = app->activityManager()->activityData( "PhotosMainView" ); |
176 QVariant data = app->activityManager()->activityData( "PhotosMainView" ); |
168 QByteArray serializedModel = data.toByteArray(); |
177 QByteArray serializedModel = data.toByteArray(); |
169 QDataStream stream(&serializedModel, QIODevice::ReadOnly); |
178 QDataStream stream(&serializedModel, QIODevice::ReadOnly); |
|
179 |
170 //Fetch the data from the activity Manager |
180 //Fetch the data from the activity Manager |
171 QMap<QString, qint32> fetchActivity; |
181 stream >> mSaveActivity; |
172 stream >> fetchActivity; |
182 qint32 stateId = mSaveActivity.value("ID"); |
173 qint32 stateId = fetchActivity.value("ID"); |
|
174 mCurrentState = createState(stateId); |
183 mCurrentState = createState(stateId); |
175 mCurrentState->setState( fetchActivity.value("InternalState") ); |
184 mCurrentState->setState( mSaveActivity.value("InternalState") ); |
176 createModel( stateId); |
185 createModel( stateId); |
177 /*Model might not be populated yet to set the visibleWindowIndex right away. |
186 /*Model might not be populated yet to set the visibleWindowIndex right away. |
178 *So, let us store the visible index as a temporary Variable, so that visible Window Index |
187 *So, let us store the visible index as a temporary Variable, so that visible Window Index |
179 *is set once the model is populated. |
188 *is set once the model is populated. |
180 */ |
189 */ |
181 mCurrentModel->setData(QModelIndex(), fetchActivity.value("VisibleIndex") , GlxTempVisualWindowIndex ); |
190 mCurrentModel->setData(QModelIndex(), mSaveActivity.value("VisibleIndex") , GlxTempVisualWindowIndex ); |
182 mViewManager->launchApplication(stateId, mCurrentModel); |
191 mViewManager->launchApplication(stateId, mCurrentModel); |
183 return true; |
192 return true; |
184 } |
193 } |
185 |
194 |
186 void GlxStateManager::launchFromExternal() |
195 void GlxStateManager::launchFromExternal() |
187 { |
196 { |
188 qDebug("GlxStateManager::launchApplication"); |
197 qDebug("GlxStateManager::launchFromExternal"); |
189 mCurrentState = createState(GLX_FULLSCREENVIEW_ID); |
198 mCurrentState = createState(GLX_FULLSCREENVIEW_ID); |
190 mCurrentState->setState(IMAGEVIEWER_S); |
199 mCurrentState->setState(IMAGEVIEWER_S); |
191 |
200 |
192 createModel(GLX_FULLSCREENVIEW_ID); |
201 createModel(GLX_FULLSCREENVIEW_ID); |
193 mCurrentModel->setData( mCurrentModel->index(0,0), 0, GlxFocusIndexRole ); |
202 mCurrentModel->setData( mCurrentModel->index(0,0), 0, GlxFocusIndexRole ); |
208 { |
217 { |
209 qDebug("GlxStateManager::setupItems()"); |
218 qDebug("GlxStateManager::setupItems()"); |
210 mActionHandler = new GlxActionHandler(); |
219 mActionHandler = new GlxActionHandler(); |
211 connect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) ); |
220 connect ( mViewManager, SIGNAL(externalCommand(int )), this, SIGNAL(externalCommand(int )) ); |
212 mViewManager->setupItems(); |
221 mViewManager->setupItems(); |
213 mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID); |
222 switch( mSaveActivity.value( "ID" ) ){ |
|
223 case GLX_LISTVIEW_ID: |
|
224 mViewManager->updateToolBarIcon(GLX_ALBUM_ACTION_ID); |
|
225 break; |
|
226 |
|
227 case GLX_GRIDVIEW_ID: |
|
228 default: |
|
229 mViewManager->updateToolBarIcon(GLX_ALL_ACTION_ID); |
|
230 } |
214 } |
231 } |
215 |
232 |
216 void GlxStateManager::updateTNProgress( int count) |
233 void GlxStateManager::updateTNProgress( int count) |
217 { |
234 { |
218 TRACER("GlxStateManager::updateTNProgress() "); |
235 TRACER("GlxStateManager::updateTNProgress() "); |
219 // mCurrentModel ------------this is case when progress bar is not showing |
236 // this is case when progress bar is not showing |
220 // count > 5 ----------------in the case of rename of an image or capture the single item |
237 // in the case of rename of an image or capture the single item |
221 // it is also launching the progress bar, to avoid this scenario add the check of count more than 5 |
238 // it is also launching the progress bar, to avoid this scenario add the check of count more than 5 |
222 // count == KErrNotReady ----A case when memory card is inserted but it is not harvest so it is given an error |
|
223 // In that case also user should be block to browse the images |
|
224 if ( mCurrentModel && ( count > 5 ) ) { |
239 if ( mCurrentModel && ( count > 5 ) ) { |
225 goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ; |
240 goBack( GLX_GRIDVIEW_ID, ALL_ITEM_S ) ; |
226 cleanAllModel(); |
241 cleanAllModel(); |
227 launchProgressDialog(); |
242 launchProgressDialog(); |
228 } |
243 } |
229 |
244 |
230 if ( isProgressbarRunning ){ |
245 if ( isProgressbarRunning ){ |
231 if ( count == 0 ) { |
246 if ( count == 0 ) { |
232 createModel( mCurrentState->id() ); |
|
233 mViewManager->setModel( mCurrentModel ); |
|
234 vanishProgressDialog(); |
247 vanishProgressDialog(); |
235 } |
248 } |
236 else { |
249 else { |
237 mViewManager->updateProgressDialog( count ); |
250 mViewManager->updateProgressDialog( count ); |
238 } |
251 } |
239 } |
252 } |
240 } |
253 } |
241 |
254 |
|
255 void GlxStateManager::thumbnailPopulated() |
|
256 { |
|
257 mViewManager->setModel( mCurrentModel ); |
|
258 isProgressbarRunning = false; |
|
259 mViewManager->updateProgressDialog( 0 ); |
|
260 disconnect ( mCurrentModel, SIGNAL( thumbnailPopulated() ), this, SLOT( thumbnailPopulated() ) ); |
|
261 } |
|
262 |
242 void GlxStateManager::saveData() |
263 void GlxStateManager::saveData() |
243 { |
264 { |
244 if( (mCurrentState->id() == GLX_GRIDVIEW_ID && mCurrentState->state() == ALL_ITEM_S) || mCurrentState->id() == GLX_LISTVIEW_ID ) { |
265 if( (mCurrentState->id() == GLX_GRIDVIEW_ID && mCurrentState->state() == ALL_ITEM_S) || mCurrentState->id() == GLX_LISTVIEW_ID ) { |
245 mSaveActivity.insert("ID",mCurrentState->id()); |
266 mSaveActivity.insert("ID",mCurrentState->id()); |
246 mSaveActivity.insert("InternalState",mCurrentState->state()); |
267 mSaveActivity.insert("InternalState",mCurrentState->state()); |
247 |
268 if(mCurrentModel) { |
248 //Store the visual Index |
269 QVariant variant = mCurrentModel->data( mCurrentModel->index(0,0), GlxVisualWindowIndex ); |
249 if(mCurrentModel) |
270 if ( variant.isValid() && variant.canConvert<int> () ) { |
250 { |
271 mSaveActivity.insert("VisibleIndex",variant.value<int>()); |
251 QVariant variant = mCurrentModel->data( mCurrentModel->index(0,0), GlxVisualWindowIndex ); |
272 } |
252 if ( variant.isValid() && variant.canConvert<int> () ) { |
|
253 mSaveActivity.insert("VisibleIndex",variant.value<int>()); |
|
254 } |
|
255 } |
273 } |
256 else |
274 else { |
257 mSaveActivity.insert("VisibleIndex",0); |
275 mSaveActivity.insert("VisibleIndex",0); |
258 |
276 } |
259 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
277 |
260 |
278 HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager(); |
261 //Take a screenshot |
279 QVariantHash metadata; |
262 QVariantHash metadata; |
280 HbMainWindow *window = hbInstance->allMainWindows().first(); |
263 HbMainWindow *window = hbInstance->allMainWindows().first(); |
281 metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect())); |
264 metadata.insert("screenshot", QPixmap::grabWidget(window, window->rect())); |
282 |
265 |
283 QByteArray serializedModel; |
266 QByteArray serializedModel; |
284 QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append); |
267 QDataStream stream(&serializedModel, QIODevice::WriteOnly | QIODevice::Append); |
285 stream << mSaveActivity; |
268 stream << mSaveActivity; |
286 |
269 //Add the activity |
287 bool ok = activityManager->addActivity("PhotosMainView", serializedModel, metadata); |
270 bool ok = activityManager->addActivity("PhotosMainView", serializedModel, metadata); |
288 if ( !ok ) |
271 if ( !ok ) |
289 { |
272 { |
290 qDebug("SaveData::Add activity failed" ); |
273 qDebug("SaveData::Add activity failed" ); |
291 } |
274 } |
292 } |
275 } |
293 } |
276 } |
|
277 |
|
278 |
294 |
279 void GlxStateManager::nextState(qint32 state, int internalState) |
295 void GlxStateManager::nextState(qint32 state, int internalState) |
280 { |
296 { |
281 qDebug("GlxStateManager::nextState next state = %u", state); |
297 qDebug("GlxStateManager::nextState next state = %u", state); |
282 GlxEffect effect = NO_EFFECT ; |
298 GlxEffect effect = NO_EFFECT ; |
325 mViewManager->launchView( mCurrentState->id(), mCurrentModel, effect, viewEffect); |
342 mViewManager->launchView( mCurrentState->id(), mCurrentModel, effect, viewEffect); |
326 } |
343 } |
327 } |
344 } |
328 delete state; |
345 delete state; |
329 } |
346 } |
330 |
347 |
|
348 void GlxStateManager::saveImage() |
|
349 { |
|
350 CGlxImageViewerManager *imageViewerInstance = CGlxImageViewerManager::InstanceL(); |
|
351 if(imageViewerInstance->IsPrivate()) |
|
352 { |
|
353 HBufC* imagePath = imageViewerInstance->ImageUri(); |
|
354 QString srcPath = QString::fromUtf16(imagePath->Des().Ptr(),imagePath->Length()); |
|
355 QString imageName = srcPath.section('\\', -1); |
|
356 QString imagesFolderPath("c:/data/images/"); |
|
357 QString destPath; |
|
358 destPath.append(imagesFolderPath); |
|
359 destPath.append(imageName); |
|
360 int cnt = 1; |
|
361 qDebug() << "GlxStateManager::saveImage path before while = "<< destPath; |
|
362 while(!QFile::copy(srcPath,destPath)) |
|
363 { |
|
364 QString filename = imageName.section('.', 0,0); |
|
365 QString ext = imageName.section('.', -1); |
|
366 destPath.clear(); |
|
367 destPath = imagesFolderPath + filename + QString::number(cnt) + "." + ext; |
|
368 qDebug() << "GlxStateManager::saveImage path = "<< destPath; |
|
369 cnt++; |
|
370 } |
|
371 } |
|
372 imageViewerInstance->Close(); |
|
373 } |
|
374 |
331 void GlxStateManager::goBack(qint32 stateId, int internalState) |
375 void GlxStateManager::goBack(qint32 stateId, int internalState) |
332 { |
376 { |
333 qDebug("GlxStateManager::goBack()"); |
377 qDebug("GlxStateManager::goBack()"); |
334 |
378 |
335 //if current state and it internal state is same then no need to do any thing |
379 //if current state and it internal state is same then no need to do any thing |
426 } |
470 } |
427 |
471 |
428 void GlxStateManager::launchProgressDialog() |
472 void GlxStateManager::launchProgressDialog() |
429 { |
473 { |
430 TRACER("GlxStateManager::launchProgressDialog() "); |
474 TRACER("GlxStateManager::launchProgressDialog() "); |
431 //HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
432 //window->setAutomaticOrientationEffectEnabled( true ); |
|
433 |
475 |
434 QCoreApplication::instance()->installEventFilter( this ); |
476 QCoreApplication::instance()->installEventFilter( this ); |
435 mViewManager->launchProgressDialog( mTNObserver->getTNLeftCount() ); |
477 if ( isProgressbarRunning ) { |
|
478 mViewManager->updateProgressDialog( mTNObserver->getTNLeftCount() ); |
|
479 } |
|
480 else { |
|
481 mViewManager->launchProgressDialog( mTNObserver->getTNLeftCount() ); |
|
482 } |
436 isProgressbarRunning = true ; |
483 isProgressbarRunning = true ; |
437 } |
484 } |
438 |
485 |
439 void GlxStateManager::vanishProgressDialog() |
486 void GlxStateManager::vanishProgressDialog() |
440 { |
487 { |
441 TRACER("GlxStateManager::vanishProgressDialog() "); |
488 TRACER("GlxStateManager::vanishProgressDialog() "); |
442 //HbMainWindow *window = hbInstance->allMainWindows().first(); |
|
443 //window->setAutomaticOrientationEffectEnabled( false ); |
|
444 |
|
445 QCoreApplication::instance()->removeEventFilter( this ); |
489 QCoreApplication::instance()->removeEventFilter( this ); |
446 isProgressbarRunning = false; |
490 createModel( mCurrentState->id() ); |
447 mViewManager->updateProgressDialog( 0 ); |
491 connect ( mCurrentModel, SIGNAL( thumbnailPopulated() ), this, SLOT( thumbnailPopulated() ) ); |
448 } |
492 } |
449 |
493 |
450 GlxState * GlxStateManager::createState(qint32 stateId) |
494 GlxState * GlxStateManager::createState(qint32 stateId) |
451 { |
495 { |
452 qDebug("GlxStateManager::createState state id = %d", stateId); |
496 qDebug("GlxStateManager::createState state id = %d", stateId); |
590 switch(id) { |
636 switch(id) { |
591 case EGlxCmdAllGridOpen : |
637 case EGlxCmdAllGridOpen : |
592 changeState( GLX_GRIDVIEW_ID, ALL_ITEM_S ); |
638 changeState( GLX_GRIDVIEW_ID, ALL_ITEM_S ); |
593 id = EGlxCmdHandled; |
639 id = EGlxCmdHandled; |
594 break; |
640 break; |
|
641 |
|
642 case EGlxCmdFetcherAllGridOpen : |
|
643 changeState( GLX_GRIDVIEW_ID, FETCHER_ITEM_S ); |
|
644 id = EGlxCmdHandled; |
|
645 break; |
595 |
646 |
596 case EGlxCmdAlbumListOpen: |
647 case EGlxCmdAlbumListOpen: |
597 changeState( GLX_LISTVIEW_ID, -1 ); |
648 changeState( GLX_LISTVIEW_ID, -1 ); |
598 id = EGlxCmdHandled; |
649 id = EGlxCmdHandled; |
599 break; |
650 break; |
600 |
651 case EGlxCmdFetcherAlbumListOpen: |
|
652 changeState( GLX_LISTVIEW_ID, FETCHER_ALBUM_S ); |
|
653 id = EGlxCmdHandled; |
|
654 break; |
|
655 |
601 case EGlxCmdAlbumGridOpen: |
656 case EGlxCmdAlbumGridOpen: |
602 nextState( GLX_GRIDVIEW_ID, ALBUM_ITEM_S ); |
657 nextState( GLX_GRIDVIEW_ID, ALBUM_ITEM_S ); |
603 id = EGlxCmdHandled; |
658 id = EGlxCmdHandled; |
604 break; |
659 break; |
605 |
660 case EGlxCmdFetcherAlbumGridOpen: |
|
661 nextState( GLX_GRIDVIEW_ID, FETCHER_ALBUM_ITEM_S ); |
|
662 id = EGlxCmdHandled; |
|
663 break; |
|
664 |
606 case EGlxCmdFirstSlideshow : |
665 case EGlxCmdFirstSlideshow : |
607 //play the slide show with first item |
666 //play the slide show with first item |
608 mCurrentModel->setData( mCurrentModel->index(0, 0), 0, GlxFocusIndexRole ); |
667 mCurrentModel->setData( mCurrentModel->index(0, 0), 0, GlxFocusIndexRole ); |
609 nextState( GLX_SLIDESHOWVIEW_ID, SLIDESHOW_GRID_ITEM_S ); |
668 nextState( GLX_SLIDESHOWVIEW_ID, SLIDESHOW_GRID_ITEM_S ); |
610 id = EGlxCmdHandled; |
669 id = EGlxCmdHandled; |