--- a/emailuis/nmailui/src/nmapplication.cpp Tue Jul 06 14:04:34 2010 +0300
+++ b/emailuis/nmailui/src/nmapplication.cpp Wed Aug 18 09:37:47 2010 +0300
@@ -21,15 +21,18 @@
static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare";
+static const QString NmActivityName = "EmailInboxView";
+
/*!
\class NmApplication
\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),
@@ -75,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;
@@ -102,6 +112,7 @@
delete mViewStack;
NmIcons::freeIcons();
+
NmUiEngine::releaseInstance(mUiEngine);
mUiEngine = NULL;
@@ -122,8 +133,9 @@
if (mNetManager->cache()) {
mNetManager->cache()->clear();
}
- delete mNetManager;
- mNetManager = NULL;
+
+ delete mNetManager;
+ mNetManager = NULL;
}
// Effects need to be deleted before MainWindow.
@@ -133,6 +145,7 @@
delete mSettingsViewLauncher;
}
+
/*!
Main application window creation.
*/
@@ -209,30 +222,39 @@
// NmAttachmentListWidget::paint().
mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);
}
+
+ // 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();
}
}
}
+
/*!
- 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) {
@@ -240,6 +262,18 @@
// Exit application if no pending operations are on-going.
}
}
+ else if (event && event->type() == QEvent::ApplicationActivate) {
+ NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
+ // Update task switcher name & screenshot, we could have activated into some other mailbox
+ updateActivity();
+ }
+ 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);
+ }
if (!consumed) {
consumed = QObject::eventFilter(obj, event);
@@ -248,6 +282,7 @@
return consumed;
}
+
/*!
Push view to view stack.
*/
@@ -319,6 +354,30 @@
}
}
+
+/*!
+ Hide the application
+*/
+void NmApplication::hideApplication()
+{
+ // Hide the application
+ XQServiceUtil::toBackground(true);
+
+ // hide the sync indicator as well
+ mUiEngine->enableSyncIndicator(false);
+
+ // Hide the mail from the task switcher
+ TsTaskSettings taskSettings;
+ taskSettings.setVisibility(false);
+
+ // Remove also the mailbox item from the task switcher
+ HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
+ if (hbApp) {
+ hbApp->activityManager()->removeActivity(NmActivityName);
+ }
+}
+
+
/*!
Pop view from view stack. View object is deleted.
*/
@@ -340,6 +399,13 @@
}
}
mBackButtonPressed = false;
+
+ // Move the application to background if closing the message list view
+ if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) {
+ hideApplication();
+ return;
+ }
+
mViewStack->pop();
// Call custom exit function.
view->aboutToExitView();
@@ -394,6 +460,7 @@
}
}
+
/*!
Reset view stack. Remove and destroy view objects.
*/
@@ -411,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
@@ -422,6 +490,8 @@
// Check the validity of start parameter object.
if (startParam) {
+
+ mCurrentMailboxId = startParam->mailboxId();
if (startParam->service() && mMainWindow) {
// When the message list is started as a service previous views
@@ -524,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.
@@ -532,6 +603,9 @@
{
NM_FUNCTION;
+ HbApplication* hbApp = dynamic_cast<HbApplication*>(parent());
+ hbApp->activityManager()->removeActivity("EmailInboxView");
+
delete mSendServiceInterface;
mSendServiceInterface = NULL;
delete mSendServiceInterface2;
@@ -546,6 +620,7 @@
qApp->quit();
}
+
/*!
Exit the application in the next event loop.
*/
@@ -555,6 +630,7 @@
QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection);
}
+
/*!
Getter for main window instance.
*/
@@ -563,6 +639,7 @@
return mMainWindow;
}
+
/*!
Getter for main UI extension manager.
*/
@@ -571,6 +648,7 @@
return *mExtensionManager;
}
+
/*!
Getter for network access manager.
*/
@@ -579,6 +657,7 @@
return *mNetManager;
}
+
/*!
Get the screen size. Function returns curtent screen size.
*/
@@ -612,6 +691,7 @@
return ret;
}
+
/*!
Handles all asynchronous operation's completions at UI level.
*/
@@ -643,6 +723,7 @@
}
}
+
/*!
Launches settings view of the specified mailbox.
*/
@@ -663,6 +744,7 @@
}
}
+
/*!
Stores the visibility state, e.g. when the service was launched.
\return true if the app was visible.
@@ -675,3 +757,53 @@
NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
return mForegroundService;
}
+
+
+/*!
+ 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;
+ tasksettings.setVisibility(false);
+ QVariantHash metadata;
+ metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
+ metadata.insert(ActivityApplicationName, meta->name());
+ metadata.insert(ActivityVisibility, true);
+ hbApp->activityManager()->removeActivity(NmActivityName);
+ hbApp->activityManager()->addActivity(NmActivityName, QVariant(), metadata);
+ }
+ else {
+ hbApp->activityManager()->removeActivity(NmActivityName);
+ TsTaskSettings tasksettings;
+ tasksettings.setVisibility(true);
+ }
+ }
+}
+
+
+/*!
+ 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);
+ }
+ }
+}
+