notes/notesui/notesviewmanager/src/notesviewmanager.cpp
changeset 55 2c54b51f39c4
parent 45 b6db4fd4947b
child 70 a5ed90760192
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: Definition file for class NotesDocLoader.
    14 * Description: Definition file for class NotesViewManager.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <qglobal.h>
    19 #include <qglobal.h>
    36 #include "notesnoteview.h"
    36 #include "notesnoteview.h"
    37 #include "notesdocloader.h"
    37 #include "notesdocloader.h"
    38 #include "notescommon.h"
    38 #include "notescommon.h"
    39 #include "notesmodel.h"
    39 #include "notesmodel.h"
    40 #include "notessortfilterproxymodel.h"
    40 #include "notessortfilterproxymodel.h"
    41 #include "agendautil.h"
    41 #include <agendautil.h>
       
    42 #include "OstTraceDefinitions.h"
       
    43 #ifdef OST_TRACE_COMPILER_IN_USE
       
    44 #include "notesviewmanagerTraces.h"
       
    45 #endif
       
    46 
    42 
    47 
    43 /*!
    48 /*!
    44 	\class NotesViewManager
    49 	\class NotesViewManager
    45 
    50 
    46 	This is the heart of the notes application. This is responsible for
    51 	This is the heart of the notes application. This is responsible for
    55 NotesViewManager::NotesViewManager(
    60 NotesViewManager::NotesViewManager(
    56 		NotesAppControllerIf &controllerIf, QObject *parent)
    61 		NotesAppControllerIf &controllerIf, QObject *parent)
    57 :QObject(parent),
    62 :QObject(parent),
    58  mAppControllerIf(controllerIf)
    63  mAppControllerIf(controllerIf)
    59 {
    64 {
       
    65 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_NOTESVIEWMANAGER_ENTRY );
    60 	HbMainWindow *window = hbInstance->allMainWindows().first();
    66 	HbMainWindow *window = hbInstance->allMainWindows().first();
    61 
    67 
    62 	mAgendaUtil = mAppControllerIf.agendaUtil();
    68 	mAgendaUtil = mAppControllerIf.agendaUtil();
    63 
    69 
    64 	// Check the Application Startup reason from Activity Manager
    70 	// Check the Application Startup reason from Activity Manager
    65 	int activityReason = qobject_cast<HbApplication*>(qApp)->activateReason();
    71 	int activityReason = qobject_cast<HbApplication*>(qApp)->activateReason();
    66 
    72 	
    67 	if (Hb::ActivationReasonActivity == activityReason) // Check if application is started 
    73 	// Check if application is started from an application
    68 	    // from an application
    74 	if (Hb::ActivationReasonActivity == activityReason) {
    69 	    {
    75 		// Application is started from an activity
    70         // Application is started from an activity
       
    71 		// extract activity data
    76 		// extract activity data
    72         QVariant data = qobject_cast<HbApplication*>(qApp)->activateData();
    77 		QVariant data = qobject_cast<HbApplication*>(qApp)->activateData();
    73         // Restore state from activity data
    78 		// Restore state from activity data
    74         QByteArray serializedModel = data.toByteArray();
    79 		QByteArray serializedModel = data.toByteArray();
    75         QDataStream stream(&serializedModel, QIODevice::ReadOnly);
    80 		QDataStream stream(&serializedModel, QIODevice::ReadOnly);
    76         int viewId;
    81 		int viewId;
    77         stream >> viewId; // read stream into an int
    82 		stream >> viewId; // read stream into an int
    78 
    83 
    79         if (NotesNamespace::NotesMainViewId == viewId) // Check if viewId is main view
    84 		// Check if viewId is main view.
    80             {
    85 		if (NotesNamespace::NotesMainViewId == viewId) {
    81             // Load MainView
    86 			// Load MainView
    82             loadNotesMainView();
    87 			loadNotesMainView();
    83             }
    88 		} else if (NotesNamespace::NotesCollectionViewId == viewId) {
    84         else if (NotesNamespace::NotesCollectionViewId == viewId) // Check if the viewId is collective view
    89 			// Check if the viewId is collective view
    85             {
    90 			//no implementation yet, UI Specs not available
    86             //no implementation yet, UI Specs not available
    91 		} 
    87             }
    92 	} else {
    88 	    }
    93 			// application started by either service framework or normally
    89 	else // application started by either service framework or normally
    94 			// Load the main view at the start up.
    90 	    {
    95 			loadNotesMainView();
    91         // Load the main view at the start up.
    96 		}
    92         loadNotesMainView();
       
    93 	    }
       
    94 
    97 
    95 	connect(
    98 	connect(
    96 			mAgendaUtil, SIGNAL(instanceViewCreationCompleted(int)),
    99 			mAgendaUtil, SIGNAL(instanceViewCreationCompleted(int)),
    97 			this,SLOT(handleInstanceViewCreationCompleted(int)));
   100 			this,SLOT(handleInstanceViewCreationCompleted(int)));
    98 
   101 
    99 	// Delay loading of other views till main view is loaded.
   102 	// Delay loading of other views till main view is loaded.
   100 	connect(
   103 	connect(
   101 			window, SIGNAL(viewReady()),
   104 			window, SIGNAL(viewReady()),
   102 			this, SLOT(loadOtherViews()));
   105 			this, SLOT(loadOtherViews()));
       
   106 	OstTraceFunctionExit0( NOTESVIEWMANAGER_NOTESVIEWMANAGER_EXIT );
   103 }
   107 }
   104 
   108 
   105 /*!
   109 /*!
   106 	Destructor.
   110 	Destructor.
   107  */
   111  */
   108 NotesViewManager::~NotesViewManager()
   112 NotesViewManager::~NotesViewManager()
   109 {
   113 {
       
   114 	OstTraceFunctionEntry0( DUP1_NOTESVIEWMANAGER_NOTESVIEWMANAGER_ENTRY );
   110 	// No implementation yet
   115 	// No implementation yet
       
   116 	OstTraceFunctionExit0( DUP1_NOTESVIEWMANAGER_NOTESVIEWMANAGER_EXIT );
   111 }
   117 }
   112 
   118 
   113 /*!
   119 /*!
   114 	Switches to view specified by viewId.
   120 	Switches to view specified by viewId.
   115 
   121 
   116 	\param viewId View Id.
   122 	\param viewId View Id.
   117  */
   123  */
   118 void NotesViewManager::switchToView(NotesNamespace::NotesViewIds viewId)
   124 void NotesViewManager::switchToView(NotesNamespace::NotesViewIds viewId)
   119 {
   125 {
       
   126 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_SWITCHTOVIEW_ENTRY );
   120 	HbMainWindow *window = hbInstance->allMainWindows().first();
   127 	HbMainWindow *window = hbInstance->allMainWindows().first();
   121 
   128 
   122 	switch (viewId) {
   129 	switch (viewId) {
   123 		case NotesNamespace::NotesMainViewId:
   130 		case NotesNamespace::NotesMainViewId:
       
   131 		{
   124 			window->removeView(window->currentView());
   132 			window->removeView(window->currentView());
   125 			window->addView(mMainView);
   133 			window->addView(mMainView);
   126 			window->setCurrentView(mMainView);
   134 			window->setCurrentView(mMainView);
   127 			mMainView->captureScreenShot(false);
   135 			mMainView->captureScreenShot(false);
   128 			break;
   136 			break;
   129 
   137 		}
   130 		case NotesNamespace::NotesCollectionViewId:
   138 		case NotesNamespace::NotesCollectionViewId:
   131 		    if (mMainView)
   139 		{
   132 		        {
   140 			if (mMainView) {
   133                 if (mMainView == window->currentView())
   141 				if (mMainView == window->currentView()) {
   134                     {
   142 					mMainView->captureScreenShot(true);
   135                     mMainView->captureScreenShot(true);
   143 				}
   136                     }
   144 			}
   137 		        }
       
   138 			window->removeView(window->currentView());
   145 			window->removeView(window->currentView());
   139 			window->addView(mCollectionView);
   146 			window->addView(mCollectionView);
   140 			window->setCurrentView(mCollectionView);
   147 			window->setCurrentView(mCollectionView);
   141 			break;
   148 			break;
   142 
   149 		}
   143 		case NotesNamespace::NotesTodoViewId:
   150 		case NotesNamespace::NotesTodoViewId:
   144 		    if (mMainView)
   151 		{
   145 		        {
   152 			if (mMainView) {
   146                 if (mMainView == window->currentView())
   153 				if (mMainView == window->currentView()) {
   147                     {
   154 					mMainView->captureScreenShot(true);
   148                     mMainView->captureScreenShot(true);
   155 				}
   149                     }
   156 			}
   150 		        }
       
   151 
       
   152 			window->removeView(window->currentView());
   157 			window->removeView(window->currentView());
   153 			window->addView(mTodoView);
   158 			window->addView(mTodoView);
   154 			window->setCurrentView(mTodoView);
   159 			window->setCurrentView(mTodoView);
   155 			break;
   160 			break;
   156 
   161 		}
   157 		case NotesNamespace::NotesFavoritesViewId:
   162 		case NotesNamespace::NotesFavoritesViewId:
   158 	         if (mMainView)
   163 		{
   159 	             {
   164 			if (mMainView) {
   160                  if (mMainView == window->currentView())
   165 				if (mMainView == window->currentView()) {
   161                      {
   166 					mMainView->captureScreenShot(true);
   162 	                 mMainView->captureScreenShot(true);
   167 				}
   163 	                 }
   168 			}
   164 	             }
       
   165 
       
   166 			window->removeView(window->currentView());
   169 			window->removeView(window->currentView());
   167 			window->addView(mFavoriteView);
   170 			window->addView(mFavoriteView);
   168 			window->setCurrentView(mFavoriteView);
   171 			window->setCurrentView(mFavoriteView);
   169 			break;
   172 			break;
   170 
   173 		}
   171 		case NotesNamespace::NotesNoteViewId:
   174 		case NotesNamespace::NotesNoteViewId:
   172 	         if (mMainView)
   175 		{
   173 	             {
   176 			if (mMainView) {
   174 	             if (mMainView == window->currentView())
   177 				if (mMainView == window->currentView()) {
   175 	                 {
   178 					mMainView->captureScreenShot(true);
   176 	                 mMainView->captureScreenShot(true);
   179 				}
   177 	                 }
   180 			}
   178 	             }
       
   179 
       
   180 			window->removeView(window->currentView());
   181 			window->removeView(window->currentView());
   181 			window->addView(mNoteView);
   182 			window->addView(mNoteView);
   182 			window->setCurrentView(mNoteView);
   183 			window->setCurrentView(mNoteView);
   183 			break;
   184 			break;
   184 
   185 		}
   185 		default:
   186 		default:
   186 			break;
   187 			break;
   187 	}
   188 	}
       
   189 	OstTraceFunctionExit0( NOTESVIEWMANAGER_SWITCHTOVIEW_EXIT );
   188 }
   190 }
   189 
   191 
   190 /*!
   192 /*!
   191 	Loads the notes main view.
   193 	Loads the notes main view.
   192  */
   194  */
   193 void NotesViewManager::loadNotesMainView()
   195 void NotesViewManager::loadNotesMainView()
   194 {
   196 {
       
   197 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTESMAINVIEW_ENTRY );
   195 	bool loadSuccess;
   198 	bool loadSuccess;
   196 
   199 
   197 	// Construct the document loader instance
   200 	// Construct the document loader instance
   198 	NotesDocLoader *docLoader = new NotesDocLoader();
   201 	NotesDocLoader *docLoader = new NotesDocLoader();
   199 
   202 
   216 			mMainView, SIGNAL(deleteEntry(ulong)),
   219 			mMainView, SIGNAL(deleteEntry(ulong)),
   217 			this, SLOT(deleteEntryFromView(ulong)));
   220 			this, SLOT(deleteEntryFromView(ulong)));
   218 
   221 
   219 	// Set the main view to the window
   222 	// Set the main view to the window
   220 	hbInstance->allMainWindows().first()->addView(mMainView);
   223 	hbInstance->allMainWindows().first()->addView(mMainView);
       
   224 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTESMAINVIEW_EXIT );
   221 }
   225 }
   222 
   226 
   223 /*!
   227 /*!
   224 	Loads the notes collection view.
   228 	Loads the notes collection view.
   225  */
   229  */
   226 void NotesViewManager::loadNotesCollectionView()
   230 void NotesViewManager::loadNotesCollectionView()
   227 {
   231 {
       
   232 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTESCOLLECTIONVIEW_ENTRY );
   228 	bool loadSuccess;
   233 	bool loadSuccess;
   229 
   234 
   230 	// Construct the document loader instance
   235 	// Construct the document loader instance
   231 	NotesDocLoader *docLoader = new NotesDocLoader();
   236 	NotesDocLoader *docLoader = new NotesDocLoader();
   232 
   237 
   236 	// Find the collection view.
   241 	// Find the collection view.
   237 	mCollectionView = static_cast<NotesCollectionView *> (
   242 	mCollectionView = static_cast<NotesCollectionView *> (
   238 			docLoader->findWidget(NOTES_COLLECTION_VIEW));
   243 			docLoader->findWidget(NOTES_COLLECTION_VIEW));
   239 	// Setup the view.
   244 	// Setup the view.
   240 	mCollectionView->setupView(mAppControllerIf, docLoader);
   245 	mCollectionView->setupView(mAppControllerIf, docLoader);
       
   246 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTESCOLLECTIONVIEW_EXIT );
   241 }
   247 }
   242 
   248 
   243 /*!
   249 /*!
   244 	Loads the to-do view.
   250 	Loads the to-do view.
   245  */
   251  */
   246 void NotesViewManager::loadTodoView()
   252 void NotesViewManager::loadTodoView()
   247 {
   253 {
       
   254 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADTODOVIEW_ENTRY );
   248 
   255 
   249 	bool loadSuccess;
   256 	bool loadSuccess;
   250 
   257 
   251 	// Construct the document loader instance
   258 	// Construct the document loader instance
   252 	NotesDocLoader *docLoader = new NotesDocLoader();
   259 	NotesDocLoader *docLoader = new NotesDocLoader();
   261 	mTodoView->setupView(mAppControllerIf, docLoader);
   268 	mTodoView->setupView(mAppControllerIf, docLoader);
   262 	// Connect to to-do view signal for entry deletion.
   269 	// Connect to to-do view signal for entry deletion.
   263 	connect (
   270 	connect (
   264 			mTodoView, SIGNAL(deleteEntry(ulong)),
   271 			mTodoView, SIGNAL(deleteEntry(ulong)),
   265 			this, SLOT(deleteEntryFromView(ulong)));
   272 			this, SLOT(deleteEntryFromView(ulong)));
       
   273 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADTODOVIEW_EXIT );
   266 }
   274 }
   267 
   275 
   268 /*!
   276 /*!
   269 	Loads the favorites view.
   277 	Loads the favorites view.
   270  */
   278  */
   271 void NotesViewManager::loadFavoritesView()
   279 void NotesViewManager::loadFavoritesView()
   272 {
   280 {
       
   281 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADFAVORITESVIEW_ENTRY );
   273 	bool loadSuccess;
   282 	bool loadSuccess;
   274 
   283 
   275 	// Construct the document loader instance
   284 	// Construct the document loader instance
   276 	NotesDocLoader *docLoader = new NotesDocLoader();
   285 	NotesDocLoader *docLoader = new NotesDocLoader();
   277 
   286 
   286 
   295 
   287 	// Connect to favourite view signal for entry deletion.
   296 	// Connect to favourite view signal for entry deletion.
   288 	connect (
   297 	connect (
   289 			mFavoriteView, SIGNAL(deleteEntry(ulong)),
   298 			mFavoriteView, SIGNAL(deleteEntry(ulong)),
   290 			this, SLOT(deleteEntryFromView(ulong)));
   299 			this, SLOT(deleteEntryFromView(ulong)));
       
   300 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADFAVORITESVIEW_EXIT );
   291 }
   301 }
   292 
   302 
   293 /*!
   303 /*!
   294 	Loads the recent notes view.
   304 	Loads the recent notes view.
   295  */
   305  */
   296 void NotesViewManager::loadNoteView()
   306 void NotesViewManager::loadNoteView()
   297 {
   307 {
       
   308 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADNOTEVIEW_ENTRY );
   298 	bool loadSuccess;
   309 	bool loadSuccess;
   299 
   310 
   300 	// Construct the document loader instance
   311 	// Construct the document loader instance
   301 	NotesDocLoader *docLoader = new NotesDocLoader();
   312 	NotesDocLoader *docLoader = new NotesDocLoader();
   302 
   313 
   310 	mNoteView->setupView(mAppControllerIf, docLoader);
   321 	mNoteView->setupView(mAppControllerIf, docLoader);
   311 
   322 
   312 	connect(
   323 	connect(
   313 			mNoteView, SIGNAL(deleteEntry(ulong)),
   324 			mNoteView, SIGNAL(deleteEntry(ulong)),
   314 			this, SLOT(deleteEntryFromView(ulong)));
   325 			this, SLOT(deleteEntryFromView(ulong)));
       
   326 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADNOTEVIEW_EXIT );
   315 }
   327 }
   316 
   328 
   317 /*!
   329 /*!
   318 	Loads other views from the docml file.
   330 	Loads other views from the docml file.
   319  */
   331  */
   320 void NotesViewManager::loadOtherViews()
   332 void NotesViewManager::loadOtherViews()
   321 {
   333 {
       
   334 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_LOADOTHERVIEWS_ENTRY );
   322 	mMainView->setupAfterViewReady();
   335 	mMainView->setupAfterViewReady();
   323 
   336 
   324 	// Load the collection view.
   337 	// Load the collection view.
   325 	loadNotesCollectionView();
   338 	loadNotesCollectionView();
   326 	// Load the to-do view.
   339 	// Load the to-do view.
   333 	// Disconnect the signal viewReady as all the views are loaded.
   346 	// Disconnect the signal viewReady as all the views are loaded.
   334 	HbMainWindow *window = hbInstance->allMainWindows().first();
   347 	HbMainWindow *window = hbInstance->allMainWindows().first();
   335 	disconnect(
   348 	disconnect(
   336 			window, SIGNAL(viewReady()),
   349 			window, SIGNAL(viewReady()),
   337 			this, SLOT(loadOtherViews()));
   350 			this, SLOT(loadOtherViews()));
       
   351 	OstTraceFunctionExit0( NOTESVIEWMANAGER_LOADOTHERVIEWS_EXIT );
   338 }
   352 }
   339 
   353 
   340 /*!
   354 /*!
   341 	 Delete the entry.
   355 	 Delete the entry.
   342  */
   356  */
   343 void NotesViewManager::deleteEntryFromView(ulong entryId)
   357 void NotesViewManager::deleteEntryFromView(ulong entryId)
   344 {
   358 {
       
   359 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_DELETEENTRYFROMVIEW_ENTRY );
   345 	mEntryId = entryId;
   360 	mEntryId = entryId;
   346 	HbMessageBox *confirmationQuery = new HbMessageBox(
   361 	HbMessageBox *confirmationQuery = new HbMessageBox(
   347 			HbMessageBox::MessageTypeQuestion);
   362 			HbMessageBox::MessageTypeQuestion);
   348 	confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
   363 	confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
   349 	confirmationQuery->setTimeout(HbDialog::NoTimeout);
   364 	confirmationQuery->setTimeout(HbDialog::NoTimeout);
   373 
   388 
   374 	confirmationQuery->addAction(mDeleteAction);
   389 	confirmationQuery->addAction(mDeleteAction);
   375 	confirmationQuery->addAction(mCancelAction);
   390 	confirmationQuery->addAction(mCancelAction);
   376 
   391 
   377 	confirmationQuery->open(this, SLOT(selectedAction(HbAction*)));
   392 	confirmationQuery->open(this, SLOT(selectedAction(HbAction*)));
       
   393 	OstTraceFunctionExit0( NOTESVIEWMANAGER_DELETEENTRYFROMVIEW_EXIT );
   378 }
   394 }
   379 
   395 
   380 /*!
   396 /*!
   381 	Slot to handle the delete action
   397 	Slot to handle the delete action
   382  */
   398  */
   383 void NotesViewManager::selectedAction(HbAction *action)
   399 void NotesViewManager::selectedAction(HbAction *action)
   384 {
   400 {
       
   401 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_SELECTEDACTION_ENTRY );
   385 	if (action == mDeleteAction) {
   402 	if (action == mDeleteAction) {
   386 		// Delete the given note.
   403 		// Delete the given note.
   387 		mAgendaUtil->deleteEntry(mEntryId);
   404 		mAgendaUtil->deleteEntry(mEntryId);
   388 	}
   405 	}
       
   406 	OstTraceFunctionExit0( NOTESVIEWMANAGER_SELECTEDACTION_EXIT );
   389 }
   407 }
   390 
   408 
   391 /*!
   409 /*!
   392 	Slot to handle instance view creation complete.
   410 	Slot to handle instance view creation complete.
   393  */
   411  */
   394 void NotesViewManager::handleInstanceViewCreationCompleted(int status)
   412 void NotesViewManager::handleInstanceViewCreationCompleted(int status)
   395 {
   413 {
       
   414 	OstTraceFunctionEntry0( NOTESVIEWMANAGER_HANDLEINSTANCEVIEWCREATIONCOMPLETED_ENTRY );
   396 	Q_UNUSED(status)
   415 	Q_UNUSED(status)
   397 
   416 
   398 	// Update the title for main view.
   417 	// Update the title for main view.
   399 	mMainView->updateTitle();
   418 	mMainView->updateTitle();
   400 
   419 
   407 	// Update the plain notes view.
   426 	// Update the plain notes view.
   408 	mNoteView->updateNoteView();
   427 	mNoteView->updateNoteView();
   409 	
   428 	
   410 	// Update the favorites view.
   429 	// Update the favorites view.
   411 	mFavoriteView->updateFavoriteView();
   430 	mFavoriteView->updateFavoriteView();
   412 }
   431 	
       
   432 	// Need to emit this signal after the view is fully constructed & populated
       
   433 	// with actual data and ready to be used. So entry view & instance view
       
   434 	// needs to be created so that a new entry can also be created. Finally
       
   435 	// NotesApplication object needs to emit applicationReady Signal.
       
   436 	emit appReady();
       
   437 	OstTraceFunctionExit0( NOTESVIEWMANAGER_HANDLEINSTANCEVIEWCREATIONCOMPLETED_EXIT );
       
   438 }
       
   439 
   413 // End of file	--Don't remove this.
   440 // End of file	--Don't remove this.