54 //dialpad widget. If connection is moved to a view, then it's not guarantied. |
54 //dialpad widget. If connection is moved to a view, then it's not guarantied. |
55 connect( &mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
55 connect( &mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), |
56 this, SLOT(handleOrientationChanged()) ); |
56 this, SLOT(handleOrientationChanged()) ); |
57 |
57 |
58 mComponentsRepository = new LogsComponentRepository(*this); |
58 mComponentsRepository = new LogsComponentRepository(*this); |
59 initViews(); |
59 |
60 |
60 connect( &mService, SIGNAL( activateView(LogsServices::LogsView, bool, QString) ), |
61 connect( &mService, SIGNAL( activateView(LogsServices::LogsView, bool) ), |
61 this, SLOT( changeRecentViewViaService(LogsServices::LogsView, bool, QString) ) ); |
62 this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) ); |
|
63 |
62 |
64 connect( &mService, SIGNAL( activateView(QString) ), |
63 connect( &mService, SIGNAL( activateView(QString) ), |
65 this, SLOT( changeMatchesView(QString) )); |
64 this, SLOT( changeMatchesViewViaService(QString) )); |
66 |
65 |
67 connect( &mServiceOld, SIGNAL( activateView(LogsServices::LogsView, bool) ), |
66 connect( &mServiceOld, SIGNAL( activateView(LogsServices::LogsView, bool, QString) ), |
68 this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) ); |
67 this, SLOT( changeRecentViewViaService(LogsServices::LogsView, bool, QString) ) ); |
69 |
68 |
70 connect( &mServiceOld, SIGNAL( activateView(QString) ), |
69 connect( &mServiceOld, SIGNAL( activateView(QString) ), |
71 this, SLOT( changeMatchesView(QString) )); |
70 this, SLOT( changeMatchesViewViaService(QString) )); |
72 |
71 |
73 QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveActivity())); |
72 QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveActivity())); |
74 |
73 |
75 handleFirstActivation(); |
74 handleFirstActivation(); |
76 |
75 |
90 |
89 |
91 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::~LogsViewManager()" ); |
90 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::~LogsViewManager()" ); |
92 } |
91 } |
93 |
92 |
94 // ----------------------------------------------------------------------------- |
93 // ----------------------------------------------------------------------------- |
95 // LogsViewManager::initViews |
94 // LogsViewManager::changeRecentViewViaService |
96 // ----------------------------------------------------------------------------- |
95 // ----------------------------------------------------------------------------- |
97 // |
96 // |
98 void LogsViewManager::initViews() |
97 void LogsViewManager::changeRecentViewViaService( |
99 { |
98 LogsServices::LogsView view, bool showDialpad, QString dialpadText) |
100 LOGS_QDEBUG( "logs [UI] -> LogsViewManager::initViews()" ); |
99 { |
101 |
100 mComponentsRepository->dialpad()->editor().setText(dialpadText); |
102 // Don't activate any view, app focus gaining or service request |
101 changeRecentView(view, showDialpad); |
103 // will cause view activation |
102 } |
104 // |
103 |
105 LogsRecentCallsView* view = mComponentsRepository->recentCallsView(); |
104 // ----------------------------------------------------------------------------- |
106 Q_ASSERT_X(view != 0, "logs [UI] ", "recentCallsView not found!"); |
105 // LogsViewManager::changeMatchesViewViaService |
107 LOGS_QDEBUG( "logs [UI] adding view" ); |
106 // ----------------------------------------------------------------------------- |
108 mViewStack.append(view); |
107 // |
109 mMainWindow.addView(view); |
108 void LogsViewManager::changeMatchesViewViaService(QString dialpadText) |
110 |
109 { |
111 LogsDetailsView* detailsView = mComponentsRepository->detailsView(); |
110 LOGS_QDEBUG( "logs [UI] -> LogsViewManager::changeMatchesView()" ); |
112 mViewStack.append(detailsView); |
111 mComponentsRepository->dialpad()->editor().setText(dialpadText); |
113 mMainWindow.addView(detailsView); |
112 doActivateView(LogsMatchesViewId, true, QVariant()); |
114 |
113 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::changeMatchesView()" ); |
115 LogsMatchesView* matchesView = mComponentsRepository->matchesView(); |
|
116 mViewStack.append(matchesView); |
|
117 mMainWindow.addView(matchesView); |
|
118 |
|
119 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::initViews()" ); |
|
120 } |
114 } |
121 |
115 |
122 // ----------------------------------------------------------------------------- |
116 // ----------------------------------------------------------------------------- |
123 // LogsViewManager::changeRecentView |
117 // LogsViewManager::changeRecentView |
124 // ----------------------------------------------------------------------------- |
118 // ----------------------------------------------------------------------------- |
125 // |
119 // |
126 void LogsViewManager::changeRecentView(LogsServices::LogsView view, bool showDialpad) |
120 void LogsViewManager::changeRecentView( |
|
121 LogsServices::LogsView view, bool showDialpad) |
127 { |
122 { |
128 QVariant args(view); |
123 QVariant args(view); |
129 doActivateView(LogsRecentViewId, showDialpad, args); |
124 doActivateView(LogsRecentViewId, showDialpad, args); |
130 } |
125 } |
131 |
126 |
132 // ----------------------------------------------------------------------------- |
127 // ----------------------------------------------------------------------------- |
133 // LogsViewManager::changeMatchesView |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void LogsViewManager::changeMatchesView(QString dialpadText) |
|
137 { |
|
138 LOGS_QDEBUG( "logs [UI] -> LogsViewManager::changeMatchesView()" ); |
|
139 doActivateView(LogsMatchesViewId, true, QVariant(), dialpadText); |
|
140 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::changeMatchesView()" ); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // LogsViewManager::proceedExit |
128 // LogsViewManager::proceedExit |
145 // ----------------------------------------------------------------------------- |
129 // ----------------------------------------------------------------------------- |
146 // |
130 // |
147 void LogsViewManager::proceedExit() |
131 void LogsViewManager::proceedExit() |
148 { |
132 { |
149 LOGS_QDEBUG( "logs [UI] -> LogsViewManager::proceedExit()" ); |
133 LOGS_QDEBUG( "logs [UI] -> LogsViewManager::proceedExit()" ); |
150 |
134 |
151 // Instead of compressing data, exit the application for real because |
|
152 // of bug in wk16 platform which prevents bg/fg switching of the app. |
|
153 // |
|
154 |
|
155 //mComponentsRepository->model()->compressData(); |
|
156 qApp->quit(); |
135 qApp->quit(); |
157 |
136 |
158 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::proceedExit()" ); |
137 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::proceedExit()" ); |
159 } |
138 } |
160 |
139 |
223 // Previously activated view is at slot 1 of view stack |
202 // Previously activated view is at slot 1 of view stack |
224 // ----------------------------------------------------------------------------- |
203 // ----------------------------------------------------------------------------- |
225 // |
204 // |
226 bool LogsViewManager::activatePreviousView() |
205 bool LogsViewManager::activatePreviousView() |
227 { |
206 { |
228 if ( mViewStack.count() < 2 ){ |
207 LogsAppViewId viewId = ( mViewStack.count() > 1 ) ? |
229 return false; |
208 mViewStack.at(1)->viewId() : LogsRecentViewId; |
230 } |
209 return doActivateView(viewId, false, QVariant()); |
231 return doActivateView(mViewStack.at(1)->viewId(), false, QVariant()); |
|
232 } |
210 } |
233 |
211 |
234 // ----------------------------------------------------------------------------- |
212 // ----------------------------------------------------------------------------- |
235 // LogsViewManager::doActivateView |
213 // LogsViewManager::doActivateView |
236 // Currently activated view is always at beginning of view stack. Deactivates |
214 // Currently activated view is always at beginning of view stack. Deactivates |
253 if ( mViewStack.at(i)->viewId() == viewId ){ |
231 if ( mViewStack.at(i)->viewId() == viewId ){ |
254 newView = mViewStack.takeAt(i); |
232 newView = mViewStack.takeAt(i); |
255 } |
233 } |
256 } |
234 } |
257 |
235 |
|
236 if ( !newView ){ |
|
237 newView = createView(viewId); |
|
238 } |
|
239 |
258 if ( oldView && newView && oldView != newView ){ |
240 if ( oldView && newView && oldView != newView ){ |
259 oldView->deactivated(); |
241 oldView->deactivated(); |
260 disconnect( &mMainWindow, SIGNAL( callKeyPressed() ), oldView, 0 ); |
242 disconnect( &mMainWindow, SIGNAL( callKeyPressed() ), oldView, 0 ); |
261 } |
243 } |
262 |
244 |
263 if ( newView ){ |
245 if ( newView ){ |
264 mViewStack.insert(0, newView); |
246 mViewStack.insert(0, newView); |
265 mMainWindow.setCurrentView(newView); |
247 mMainWindow.setCurrentView(newView); |
|
248 //Setting mainwindow interactive to enable user input during |
|
249 //view switching animation. |
|
250 mMainWindow.setInteractive(true); |
266 mViewActivationArgs = args; |
251 mViewActivationArgs = args; |
267 mViewActivationShowDialpad = showDialpad; |
252 mViewActivationShowDialpad = showDialpad; |
268 completeViewActivation(); |
253 completeViewActivation(); |
269 activated = true; |
254 activated = true; |
270 } |
255 } |
324 foreach ( LogsBaseView* view, mViewStack ){ |
309 foreach ( LogsBaseView* view, mViewStack ){ |
325 view->clearActivity(*activityManager); |
310 view->clearActivity(*activityManager); |
326 } |
311 } |
327 |
312 |
328 QVariantHash metaData; |
313 QVariantHash metaData; |
329 metaData.insert("screenshot", QPixmap::grabWidget(&mMainWindow, mMainWindow.rect())); |
314 |
|
315 LOGS_QDEBUG( "logs [UI] Start taking screenshot" ); |
|
316 QImage* img = new QImage(mMainWindow.rect().size(), QImage::Format_ARGB32_Premultiplied); |
|
317 QPainter p( img ); |
|
318 // Use render instead of QPixmap::grabWidget as otherwise screenshot |
|
319 // may become empty. |
|
320 mMainWindow.render( &p, mMainWindow.rect(), mMainWindow.rect() ); |
|
321 metaData.insert("screenshot", QPixmap::fromImage(*img)); |
|
322 delete img; |
|
323 LOGS_QDEBUG( "logs [UI] End taking screenshot" ); |
330 |
324 |
331 QByteArray serializedActivity; |
325 QByteArray serializedActivity; |
332 QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append); |
326 QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append); |
333 |
327 |
|
328 metaData.insert( |
|
329 logsActivityParamInternalViewId, mViewStack.at(0)->viewId() ); |
334 metaData.insert( |
330 metaData.insert( |
335 logsActivityParamShowDialpad, mComponentsRepository->dialpad()->isOpen() ); |
331 logsActivityParamShowDialpad, mComponentsRepository->dialpad()->isOpen() ); |
336 metaData.insert( |
332 metaData.insert( |
337 logsActivityParamDialpadText, mComponentsRepository->dialpad()->editor().text() ); |
333 logsActivityParamDialpadText, mComponentsRepository->dialpad()->editor().text() ); |
338 QString activityId = mViewStack.at(0)->saveActivity(stream, metaData); |
334 QString activityId = mViewStack.at(0)->saveActivity(stream, metaData); |
364 LogsBaseView* matchingView = 0; |
360 LogsBaseView* matchingView = 0; |
365 for ( int i = 0; i < mViewStack.count() && !matchingView; i++ ){ |
361 for ( int i = 0; i < mViewStack.count() && !matchingView; i++ ){ |
366 if ( mViewStack.at(i)->matchWithActivityId(activityId) ){ |
362 if ( mViewStack.at(i)->matchWithActivityId(activityId) ){ |
367 matchingView = mViewStack.at(i); |
363 matchingView = mViewStack.at(i); |
368 } |
364 } |
|
365 } |
|
366 |
|
367 QList<QVariantHash> allParams = hbApp->activityManager()->activities(); |
|
368 QVariantHash params = allParams.isEmpty() ? QVariantHash() : allParams.at(0); |
|
369 LOGS_QDEBUG_2( "logs [UI] Activity params", params ); |
|
370 |
|
371 if ( !matchingView ){ |
|
372 // Try if creating such view is possible |
|
373 int viewId = params.value(logsActivityParamInternalViewId).toInt(); |
|
374 matchingView = createView(static_cast<LogsAppViewId>(viewId)); |
369 } |
375 } |
370 |
376 |
371 if ( matchingView ){ |
377 if ( matchingView ){ |
372 // Should have only one param hash in the list, use first always |
378 // Should have only one param hash in the list, use first always |
373 QList<QVariantHash> allParams = hbApp->activityManager()->activities(); |
379 QList<QVariantHash> allParams = hbApp->activityManager()->activities(); |
392 // |
398 // |
393 LogsAppViewId LogsViewManager::checkMatchesViewTransition( |
399 LogsAppViewId LogsViewManager::checkMatchesViewTransition( |
394 LogsAppViewId viewId, const QString& dialpadText) |
400 LogsAppViewId viewId, const QString& dialpadText) |
395 { |
401 { |
396 if ( !dialpadText.isEmpty() ){ |
402 if ( !dialpadText.isEmpty() ){ |
397 Dialpad* dialpad = mComponentsRepository->dialpad(); |
403 mComponentsRepository->dialpad()->editor().setText(dialpadText); |
398 dialpad->editor().setText(dialpadText); |
|
399 } |
404 } |
400 |
405 |
401 if ( viewId == LogsMatchesViewId ){ |
406 if ( viewId == LogsMatchesViewId ){ |
402 LogsModel* model = mComponentsRepository->model(); |
407 LogsModel* model = mComponentsRepository->model(); |
403 if ( model && model->predictiveSearchStatus() != logsContactSearchEnabled ){ |
408 if ( model && model->predictiveSearchStatus() != logsContactSearchEnabled ){ |
433 foreach ( LogsBaseView* view, mViewStack ){ |
438 foreach ( LogsBaseView* view, mViewStack ){ |
434 view->clearActivity(*activityManager); |
439 view->clearActivity(*activityManager); |
435 } |
440 } |
436 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleFirstActivation()" ); |
441 LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleFirstActivation()" ); |
437 } |
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 LogsBaseView* LogsViewManager::createView(LogsAppViewId viewId) |
|
449 { |
|
450 LogsBaseView* newView = 0; |
|
451 if ( viewId == LogsRecentViewId ){ |
|
452 newView = mComponentsRepository->recentCallsView(); |
|
453 mMainWindow.addView(newView); |
|
454 } else if ( viewId == LogsMatchesViewId ) { |
|
455 newView = mComponentsRepository->matchesView(); |
|
456 mMainWindow.addView(newView); |
|
457 } else if ( viewId == LogsDetailsViewId ) { |
|
458 newView = mComponentsRepository->detailsView(); |
|
459 mMainWindow.addView(newView); |
|
460 } |
|
461 return newView; |
|
462 } |