emailuis/nmailui/src/nmapplication.cpp
changeset 20 ecc8def7944a
parent 18 578830873419
child 23 2dc6caa42ec3
equal deleted inserted replaced
18:578830873419 20:ecc8def7944a
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 #ifdef Q_OS_SYMBIAN
    19 #ifdef Q_OS_SYMBIAN
       
    20 #include <email_services_api.h>
    20 #include <e32base.h>
    21 #include <e32base.h>
    21 #else
    22 #else
    22 #define NM_WINS_ENV
    23 #define NM_WINS_ENV
    23 #endif
    24 #endif
    24 
    25 
    25 static const qreal nmCacheSize = 2097152;
    26 static const qreal nmCacheSize = 2097152;
       
    27 static const char *NMUI_CACHE_DIR = "cache";
       
    28 static const QString NmSendServiceName = "com.nokia.symbian.IMessage.Send";
    26 
    29 
    27 /*!
    30 /*!
    28 	\class NmApplication
    31 	\class NmApplication
    29 	\brief Application class, creates main window and handles view switching
    32 	\brief Application class, creates main window and handles view switching
    30 */
    33 */
    39 mActiveViewId(NmUiViewNone),
    42 mActiveViewId(NmUiViewNone),
    40 mUiEngine(NULL),
    43 mUiEngine(NULL),
    41 mBackAction(NULL),
    44 mBackAction(NULL),
    42 mExtensionManager(NULL),
    45 mExtensionManager(NULL),
    43 mMbListModel(NULL),
    46 mMbListModel(NULL),
    44 mServiceViewId(NmUiViewNone)
    47 mServiceViewId(NmUiViewNone),
       
    48 mForegroundService(false),
       
    49 mUtilities(NULL)
    45 {
    50 {
    46     // Create network access manager and cache for application use.
    51     // Create network access manager and cache for application use.
    47     mNetManager = new NmViewerViewNetManager();
    52     mNetManager = new NmViewerViewNetManager();
    48     QNetworkDiskCache *cache = new QNetworkDiskCache();
    53     QNetworkDiskCache *cache = new QNetworkDiskCache();
       
    54     cache->setCacheDirectory(NMUI_CACHE_DIR);
    49     cache->setMaximumCacheSize(nmCacheSize);
    55     cache->setMaximumCacheSize(nmCacheSize);
    50     mNetManager->setCache(cache);
    56     mNetManager->setCache(cache);
    51 
    57 
    52     // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is
    58     // TEMPORARY WORKAROUND TO PREVENT PANIC User panic 66, where there is
    53     // a PushL call to cleanup stack without any TRAP.
    59     // a PushL call to cleanup stack without any TRAP.
    58     #endif
    64     #endif
    59     createMainWindow();
    65     createMainWindow();
    60 
    66 
    61 #ifndef NM_WINS_ENV
    67 #ifndef NM_WINS_ENV
    62     mSendServiceInterface =
    68     mSendServiceInterface =
    63             new NmSendServiceInterface(NULL, *mUiEngine, this);
    69             new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this);
       
    70     mSendServiceInterface2 =
       
    71             new NmSendServiceInterface(emailInterfaceNameSend, NULL, *mUiEngine, this);
    64     mMailboxServiceInterface =
    72     mMailboxServiceInterface =
    65             new NmMailboxServiceInterface(NULL, *mUiEngine, this);
    73             new NmMailboxServiceInterface(NULL, *mUiEngine, this);
    66     mViewerServiceInterface =
    74     mViewerServiceInterface =
    67             new NmViewerServiceInterface(NULL, this, *mUiEngine);
    75             new NmViewerServiceInterface(NULL, this, *mUiEngine);
    68 #endif
    76 #endif
       
    77     mUtilities = new NmUtilities();
    69 }
    78 }
    70 
    79 
    71 /*!
    80 /*!
    72     Destructor
    81     Destructor
    73 */
    82 */
    74 NmApplication::~NmApplication()
    83 NmApplication::~NmApplication()
    75 {
    84 {
    76 #ifndef NM_WINS_ENV
    85 #ifndef NM_WINS_ENV
    77 	delete mSendServiceInterface;
    86 	delete mSendServiceInterface;
       
    87 	delete mSendServiceInterface2;
    78 	delete mMailboxServiceInterface;
    88 	delete mMailboxServiceInterface;
    79 	delete mViewerServiceInterface;
    89 	delete mViewerServiceInterface;
    80 #endif
    90 #endif
    81 
    91 
    82 	resetViewStack();
    92 	resetViewStack();
    91             mNetManager->cache()->clear();
   101             mNetManager->cache()->clear();
    92         }
   102         }
    93     delete mNetManager;
   103     delete mNetManager;
    94     mNetManager=NULL;
   104     mNetManager=NULL;
    95     }
   105     }
       
   106     delete mUtilities;
       
   107     delete mMainWindow;
    96 }
   108 }
    97 
   109 
    98 /*!
   110 /*!
    99     Main application window creation
   111     Main application window creation
   100 */
   112 */
   119     HbStyleLoader::registerFilePath(":nmviewerheader.widgetml");
   131     HbStyleLoader::registerFilePath(":nmviewerheader.widgetml");
   120     HbStyleLoader::registerFilePath(":nmviewerheader.css");
   132     HbStyleLoader::registerFilePath(":nmviewerheader.css");
   121 
   133 
   122     // Create main window
   134     // Create main window
   123     mMainWindow = new HbMainWindow();
   135     mMainWindow = new HbMainWindow();
   124     mMainWindow->show();
       
   125 
   136 
   126     // Create extension manager
   137     // Create extension manager
   127     mExtensionManager = new NmUiExtensionManager();
   138     mExtensionManager = new NmUiExtensionManager();
   128 
   139 
   129     // Create view stack
   140     // Create view stack
   131 
   142 
   132     // Create back action and connect it to popView()
   143     // Create back action and connect it to popView()
   133     if (mMainWindow) {
   144     if (mMainWindow) {
   134         mBackAction = new HbAction(Hb::BackNaviAction,this);
   145         mBackAction = new HbAction(Hb::BackNaviAction,this);
   135         connect(mBackAction, SIGNAL(triggered()), this, SLOT(popView()));
   146         connect(mBackAction, SIGNAL(triggered()), this, SLOT(popView()));
   136     }
   147         // Show main window
       
   148         mMainWindow->show();
       
   149     }
       
   150 
       
   151     // async operation completion related notifications
       
   152     connect(
       
   153         mUiEngine, SIGNAL(operationCompleted(const NmOperationCompletionEvent &)),
       
   154         this, SLOT(handleOperationCompleted(const NmOperationCompletionEvent &)));
   137 
   155 
   138     mMbListModel = &mUiEngine->mailboxListModel();
   156     mMbListModel = &mUiEngine->mailboxListModel();
   139 
   157 
   140     // Start application to mailbox view
   158     // Start application to mailbox view
   141     // If started as service, there is no need to create views
   159     // If started as service, there is no need to create views
   191             view->aboutToExitView();
   209             view->aboutToExitView();
   192             NmUiViewId topViewId = view->nmailViewId();
   210             NmUiViewId topViewId = view->nmailViewId();
   193             // Remove view from stack.
   211             // Remove view from stack.
   194             mMainWindow->removeView(view);
   212             mMainWindow->removeView(view);
   195 
   213 
       
   214             // if we were in editor and sent a message, pop viewer from stack first
       
   215             // so we can go straight to mail list
       
   216             if (!mViewStack->isEmpty() && topViewId == NmUiViewMessageEditor &&
       
   217                 mUiEngine->isSendingMessage() &&
       
   218                 mViewStack->top()->nmailViewId() == NmUiViewMessageViewer) {
       
   219                 NmBaseView *tmpView = mViewStack->pop();
       
   220                 mMainWindow->removeView(tmpView);
       
   221                 delete tmpView;
       
   222                 tmpView = NULL;
       
   223             }
       
   224 
   196             if (!mViewStack->isEmpty()) {
   225             if (!mViewStack->isEmpty()) {
   197                 // Activate next view in stack
   226                 // Activate next view in stack
   198                 NmBaseView *showView = mViewStack->top();
   227                 NmBaseView *showView = mViewStack->top();
   199                 mMainWindow->addView(showView);
   228                 mMainWindow->addView(showView);
   200                 // Store activated view id
   229                 // Store activated view id
   203 
   232 
   204             delete view;
   233             delete view;
   205             view = NULL;
   234             view = NULL;
   206 
   235 
   207 #ifndef NM_WINS_ENV
   236 #ifndef NM_WINS_ENV
   208             // If view was started as service, move the app now to the background
   237             // If view was started as service, move the app now
       
   238             // to the background, unless it was started when the app
       
   239             // was already in foreground..
   209             if (mServiceViewId == topViewId) {
   240             if (mServiceViewId == topViewId) {
   210                 mServiceViewId = NmUiViewNone;
   241                 mServiceViewId = NmUiViewNone;
   211 
   242 
   212                 // if started as embedded, do not hide the app
   243                 // if started as embedded, do not hide the app
   213 		        if (!XQServiceUtil::isEmbedded()) {
   244 		        if (!XQServiceUtil::isEmbedded() &&
       
   245 		            !mForegroundService) {
   214 		            XQServiceUtil::toBackground(true);
   246 		            XQServiceUtil::toBackground(true);
   215                 }
   247                 }
   216             }
   248             }
   217 #endif
   249 #endif
   218         }
   250         }
   251 void NmApplication::enterNmUiView(NmUiStartParam* startParam)
   283 void NmApplication::enterNmUiView(NmUiStartParam* startParam)
   252 {
   284 {
   253     // Check the validity of start parameter object
   285     // Check the validity of start parameter object
   254     if (startParam) {
   286     if (startParam) {
   255 
   287 
       
   288         if (startParam->service() && mMainWindow) {
       
   289 			// Store the visibility state when the service was launched
       
   290 			mForegroundService = mMainWindow->isVisible();
       
   291 
       
   292 			// When the message list is started as a service previous views are removed
       
   293 			// from the stack. Open editors are not closed.
       
   294 			// Also if the view is same than the new one, keep it open (reload the content).
       
   295 			
       
   296 		    // at least one view must remain in the stack
       
   297 			while (mViewStack->count()>1) { 
       
   298 			    NmUiViewId topId = mViewStack->top()->nmailViewId();
       
   299 			    if (topId!=NmUiViewMessageEditor && 
       
   300 			        topId!=NmUiViewMailboxList &&
       
   301 			        topId!=startParam->viewId()) {
       
   302 			        popView();
       
   303 			    }
       
   304 			    else {
       
   305 			        // Editor or mailbox list in the top. Stop the loop.
       
   306 			        break;
       
   307 			    }
       
   308 			}
       
   309         }
       
   310         
   256         // Check whether requested view is already active
   311         // Check whether requested view is already active
   257         // and if so, ask it to reload contents with new start parameter data
   312         // and if so, ask it to reload contents with new start parameter data
   258         // Do not reuse the view if started as service (ShareUI or Launch API)
   313         // Do not reuse the view if started as service to editor view (ShareUI)
   259         if (mActiveViewId==startParam->viewId() && !startParam->service()) {
   314         if (mActiveViewId==startParam->viewId() &&
       
   315         	(!startParam->service() || mActiveViewId!=NmUiViewMessageEditor)) {
   260             mViewStack->top()->reloadViewContents(startParam);
   316             mViewStack->top()->reloadViewContents(startParam);
   261         }
   317         }
   262         else {
   318         else {
   263             switch (startParam->viewId()) {
   319             switch (startParam->viewId()) {
   264                 case NmUiViewMailboxList:
   320                 case NmUiViewMailboxList:
   269                     pushView(mbListView);
   325                     pushView(mbListView);
   270                 }
   326                 }
   271                 break;
   327                 break;
   272                 case NmUiViewMessageList:
   328                 case NmUiViewMessageList:
   273                 {
   329                 {
       
   330                     // Check the topmost view. If it is an editor, do not open
       
   331                     // a new mail list view
       
   332                     if (startParam->service() && !mViewStack->isEmpty() && 
       
   333                         mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
       
   334                         break;
       
   335                     }
   274                     NmMessageListModel &messageListModel = mUiEngine->messageListModel(
   336                     NmMessageListModel &messageListModel = mUiEngine->messageListModel(
   275                                                 startParam->mailboxId(), startParam->folderId());
   337                                                 startParam->mailboxId(), startParam->folderId());
   276                     NmMessageListView *msgList =new NmMessageListView(
   338                     NmMessageListView *msgList =new NmMessageListView(
   277                     		*this, startParam, *mUiEngine, *mMbListModel, messageListModel,
   339                     		*this, startParam, *mUiEngine, *mMbListModel, messageListModel,
   278                     		new HbDocumentLoader(mMainWindow));
   340                     		new HbDocumentLoader(mMainWindow));
   286                     pushView(new NmEditorView(*this, startParam, *mUiEngine));
   348                     pushView(new NmEditorView(*this, startParam, *mUiEngine));
   287                     break;
   349                     break;
   288                 default:
   350                 default:
   289                     // Reset view stack and exit application
   351                     // Reset view stack and exit application
   290                     delete startParam;
   352                     delete startParam;
       
   353                     startParam=NULL;
   291                     resetViewStack();
   354                     resetViewStack();
   292                     break;
   355                     break;
   293             }
   356             }
   294 
   357 
   295             if (startParam->service()) {
   358             if (startParam && startParam->service()) {
   296 				// Store the view id that was launched as service
   359 				// Store the view id that was launched as service
   297         		mServiceViewId = mActiveViewId;
   360         		mServiceViewId = mActiveViewId;
   298 			}
   361 			}
   299         }
   362         }
   300     }
   363     }
   309 {
   372 {
   310 	NMLOG("NmApplication::exitApplication");
   373 	NMLOG("NmApplication::exitApplication");
   311 #ifndef NM_WINS_ENV
   374 #ifndef NM_WINS_ENV
   312     delete mSendServiceInterface;
   375     delete mSendServiceInterface;
   313     mSendServiceInterface = NULL;
   376     mSendServiceInterface = NULL;
       
   377     delete mSendServiceInterface2;
       
   378     mSendServiceInterface2 = NULL;
   314     delete mMailboxServiceInterface;
   379     delete mMailboxServiceInterface;
   315     mMailboxServiceInterface = NULL;
   380     mMailboxServiceInterface = NULL;
   316     delete mViewerServiceInterface;
   381     delete mViewerServiceInterface;
   317     mViewerServiceInterface = NULL;
   382     mViewerServiceInterface = NULL;
   318 #endif
   383 #endif
   348 }
   413 }
   349 
   414 
   350 /*!
   415 /*!
   351     Getter for network access manager
   416     Getter for network access manager
   352 */
   417 */
   353 NmViewerViewNetManager* NmApplication::networkAccessManager()
   418 NmViewerViewNetManager& NmApplication::networkAccessManager()
   354 {
   419 {
   355     return mNetManager;
   420     return *mNetManager;
   356 }
   421 }
   357 
   422 
   358 /*!
   423 /*!
   359     screen size. Function returns curtent screen size
   424     screen size. Function returns curtent screen size
   360 */
   425 */
   385             }
   450             }
   386         }
   451         }
   387     }
   452     }
   388     return ret;
   453     return ret;
   389 }
   454 }
       
   455 
       
   456 /*!
       
   457     handles all asynchronous operation's completions at UI level
       
   458 */
       
   459 void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event)
       
   460 {
       
   461     mUtilities->displayOperationCompletionNote(event);
       
   462 }