--- a/emailuis/nmailui/src/nmapplication.cpp Fri Jul 23 19:09:50 2010 +0300
+++ b/emailuis/nmailui/src/nmapplication.cpp Thu Aug 05 21:09:09 2010 +0300
@@ -21,10 +21,6 @@
static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare";
-// Delay before a screenshot is taken after view activation so that view has time to draw itself,
-// testing seems to indicate 500ms to be a good value
-static const int NmActivityUpdateDelayMs = 500;
-
static const QString NmActivityName = "EmailInboxView";
/*!
@@ -32,10 +28,11 @@
\brief Application class, creates main window and handles view switching.
*/
+
/*!
Constructor.
*/
-NmApplication::NmApplication(QObject *parent, quint32 accountId)
+NmApplication::NmApplication(QObject *parent, quint64 accountId)
: QObject(parent),
mMainWindow(NULL),
mViewStack(NULL),
@@ -51,8 +48,7 @@
mSettingsViewLauncher(NULL),
mViewReady(false),
mQueryDialog(NULL),
- mBackButtonPressed(false),
- mActivityUpdateNeeded(false)
+ mBackButtonPressed(false)
{
TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
@@ -82,18 +78,25 @@
if(accountId != 0) {
QVariant mailbox;
- mailbox.setValue(mUiEngine->getPluginIdByMailboxId(accountId).id());
+ mailbox.setValue(accountId);
mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
}
mEffects = new NmUiEffects(*mMainWindow);
+
+ QObject::connect(parent, SIGNAL(activate()), this, SLOT(activityActivated()));
}
+
/*!
Destructor.
*/
NmApplication::~NmApplication()
{
+ // Remove the event filter early since catching application activated/
+ // deactivated events now may cause a crash.
+ QCoreApplication::instance()->removeEventFilter(this);
+
if (mQueryDialog) {
delete mQueryDialog;
mQueryDialog = NULL;
@@ -109,6 +112,7 @@
delete mViewStack;
NmIcons::freeIcons();
+
NmUiEngine::releaseInstance(mUiEngine);
mUiEngine = NULL;
@@ -129,8 +133,9 @@
if (mNetManager->cache()) {
mNetManager->cache()->clear();
}
- delete mNetManager;
- mNetManager = NULL;
+
+ delete mNetManager;
+ mNetManager = NULL;
}
// Effects need to be deleted before MainWindow.
@@ -140,6 +145,7 @@
delete mSettingsViewLauncher;
}
+
/*!
Main application window creation.
*/
@@ -217,18 +223,22 @@
mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);
}
- // installed to get ApplicationActivate/Deactivate events
+ // Install the event filter in order to receive ApplicationActivate/Deactivate
+ // events.
QCoreApplication::instance()->installEventFilter(this);
}
+
/*!
Slot. React to view ready signal and call current view method.
*/
void NmApplication::viewReady()
{
mViewReady = true;
+
if (mViewStack && !mViewStack->isEmpty()) {
NmBaseView *currentView = mViewStack->top();
+
if (currentView) {
currentView->viewReady();
emit applicationReady();
@@ -236,14 +246,15 @@
}
}
+
/*!
- Event filter. End key is filtered from the main window and either the
- view takes case of the or the app is exited by default.
+ Event filter. End key is filtered from the main window and either the view
+ takes case or the app is exited by default.
*/
bool NmApplication::eventFilter(QObject *obj, QEvent *event)
{
bool consumed(false);
-
+
if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_No) {
@@ -251,18 +262,15 @@
// Exit application if no pending operations are on-going.
}
}
- else if (event->type()==QEvent::ApplicationActivate) {
+ else if (event && event->type() == QEvent::ApplicationActivate) {
NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
-
- // Activity thumbnails must be shown again
- if (mActivityUpdateNeeded) {
- mActivityUpdateNeeded = false;
- updateActivity();
- }
+ // Update task switcher name & screenshot, we could have activated into some other mailbox
+ updateActivity();
}
- else if (event->type()==QEvent::ApplicationDeactivate) {
+ else if (event && event->type() == QEvent::ApplicationDeactivate) {
NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
-
+ // Update the screenshot in the taskswitcher to represent current state
+ updateActivity();
// hide the sync indicator when app goes to background
mUiEngine->enableSyncIndicator(false);
}
@@ -274,6 +282,7 @@
return consumed;
}
+
/*!
Push view to view stack.
*/
@@ -313,7 +322,6 @@
if (hideView) {
mMainWindow->removeView(hideView);
}
- QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
}
}
@@ -346,6 +354,7 @@
}
}
+
/*!
Hide the application
*/
@@ -366,11 +375,9 @@
if (hbApp) {
hbApp->activityManager()->removeActivity(NmActivityName);
}
-
- // Update the activity when needed
- mActivityUpdateNeeded = true;
}
+
/*!
Pop view from view stack. View object is deleted.
*/
@@ -425,7 +432,6 @@
mActiveViewId=showView->nmailViewId();
// Perform send animation if requested.
mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
- QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
}
delete view;
@@ -454,6 +460,7 @@
}
}
+
/*!
Reset view stack. Remove and destroy view objects.
*/
@@ -471,6 +478,7 @@
}
}
+
/*!
Function activates view based on viewId parameter. If requested view is
already open, it is requested to reload. Otherwise view object is created
@@ -586,6 +594,7 @@
}
}
+
/*!
Function can be used from views to exit the application. View stack is
cleared. Views can connect exit menu selection to this slot.
@@ -611,6 +620,7 @@
qApp->quit();
}
+
/*!
Exit the application in the next event loop.
*/
@@ -620,6 +630,7 @@
QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection);
}
+
/*!
Getter for main window instance.
*/
@@ -628,6 +639,7 @@
return mMainWindow;
}
+
/*!
Getter for main UI extension manager.
*/
@@ -636,6 +648,7 @@
return *mExtensionManager;
}
+
/*!
Getter for network access manager.
*/
@@ -644,6 +657,7 @@
return *mNetManager;
}
+
/*!
Get the screen size. Function returns curtent screen size.
*/
@@ -677,6 +691,7 @@
return ret;
}
+
/*!
Handles all asynchronous operation's completions at UI level.
*/
@@ -708,6 +723,7 @@
}
}
+
/*!
Launches settings view of the specified mailbox.
*/
@@ -724,11 +740,11 @@
if( mailboxMetaData ) {
// Launch.
mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
- QTimer::singleShot(NmActivityUpdateDelayMs, this, SLOT(updateActivity()));
}
}
}
+
/*!
Stores the visibility state, e.g. when the service was launched.
\return true if the app was visible.
@@ -742,13 +758,15 @@
return mForegroundService;
}
+
/*!
- Update the thumbnail in the task switcher
+ Update the thumbnail in the task switcher.
*/
void NmApplication::updateActivity()
{
NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
+
if (hbApp) {
if (meta) {
TsTaskSettings tasksettings;
@@ -767,3 +785,25 @@
}
}
}
+
+
+/*!
+ Switch to activated mailbox
+*/
+void NmApplication::activityActivated()
+{
+ HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
+ if (hbApp) {
+ quint64 accountId(0);
+ QString activateId = hbApp->activateId();
+ if (hbApp->activateReason() == Hb::ActivationReasonActivity &&
+ activateId.startsWith(NmActivityName) ) {
+ QString accountIdString = activateId.mid(NmActivityName.length());
+ accountId = accountIdString.toULongLong();
+ QVariant mailbox;
+ mailbox.setValue(accountId);
+ mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
+ }
+ }
+}
+