notes/notesui/notesviews/src/notesmainview.cpp
branchRCL_3
changeset 65 12af337248b1
equal deleted inserted replaced
60:96907930389d 65:12af337248b1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Definition file for NotesMainView class.
       
    16 *
       
    17 */
       
    18 
       
    19 // System includes
       
    20 #include <QDateTime>
       
    21 #include <HbListView>
       
    22 #include <HbListWidget>
       
    23 #include <HbAction>
       
    24 #include <HbTextEdit>
       
    25 #include <HbInstance>
       
    26 #include <HbMainWindow>
       
    27 #include <HbMenu>
       
    28 #include <HbLabel>
       
    29 #include <HbAbstractViewItem>
       
    30 #include <HbAbstractItemView>
       
    31 #include <HbGroupBox>
       
    32 #include <HbListViewItem>
       
    33 #include <hbapplication> // hbapplication
       
    34 #include <hbactivitymanager> // hbactivitymanager
       
    35 
       
    36 // User includes
       
    37 #include <agendautil.h>
       
    38 #include "agendaeventviewer.h"
       
    39 #include "notesmainview.h"
       
    40 #include "notescommon.h"
       
    41 #include "notesdocloader.h"
       
    42 #include "notesmodel.h"
       
    43 #include "notessortfilterproxymodel.h"
       
    44 #include "noteseditor.h"
       
    45 #include "notescommon.h"
       
    46 #include "OstTraceDefinitions.h"
       
    47 #ifdef OST_TRACE_COMPILER_IN_USE
       
    48 #include "notesmainviewTraces.h"
       
    49 #endif
       
    50  // NotesNamespace
       
    51 
       
    52 /*!
       
    53 	\class NotesMainView
       
    54 	\brief The main view of the notes application. Responsible for displaying
       
    55 			notes and todos.
       
    56 
       
    57 	\sa NotesViewManager
       
    58  */
       
    59 
       
    60 /*!
       
    61 	Constructs the NotesMainView object.
       
    62 
       
    63 	\param parent The parent of type QGraphicsWidget.
       
    64  */
       
    65 NotesMainView::NotesMainView(QGraphicsWidget *parent)
       
    66 :HbView(parent),
       
    67  mSelectedItem(0),
       
    68  mDeleteAction(0),
       
    69  mIsLongTop(false),
       
    70  mIsScreenShotCapruted(false)
       
    71 {
       
    72 	OstTraceFunctionEntry0( NOTESMAINVIEW_NOTESMAINVIEW_ENTRY );
       
    73 	// Nothing yet.
       
    74 	OstTraceFunctionExit0( NOTESMAINVIEW_NOTESMAINVIEW_EXIT );
       
    75 }
       
    76 
       
    77 /*!
       
    78 	Destructor.
       
    79  */
       
    80 NotesMainView::~NotesMainView()
       
    81 {
       
    82 	OstTraceFunctionEntry0( DUP1_NOTESMAINVIEW_NOTESMAINVIEW_ENTRY );
       
    83 	if (mDocLoader) {
       
    84 		delete mDocLoader;
       
    85 		mDocLoader = 0;
       
    86 	}
       
    87 
       
    88 	OstTraceFunctionExit0( DUP1_NOTESMAINVIEW_NOTESMAINVIEW_EXIT );
       
    89 }
       
    90 
       
    91 /*!
       
    92 	Called by the NotesViewManager after loading the view from the docml.
       
    93 	The initializaion/setup of the view is done here.
       
    94 
       
    95 	\param controller The NotesAppController object.
       
    96 	\param docLoader Pointer to NotesDocLoader object.
       
    97  */
       
    98 void NotesMainView::setupView(
       
    99 		NotesAppControllerIf &controllerIf, NotesDocLoader *docLoader)
       
   100 {
       
   101 	OstTraceFunctionEntry0( NOTESMAINVIEW_SETUPVIEW_ENTRY );
       
   102 
       
   103 	mDocLoader = docLoader;
       
   104 	mAppControllerIf = &controllerIf;
       
   105 	mNotesModel = mAppControllerIf->notesModel();
       
   106 	mAgendaUtil = mAppControllerIf->agendaUtil();
       
   107 
       
   108 	mProxyModel = new NotesSortFilterProxyModel(*mAgendaUtil, this);
       
   109 	mProxyModel->setDynamicSortFilter(true);
       
   110 	mProxyModel->setSourceModel(mNotesModel->sourceModel());
       
   111 
       
   112 	NotesSortFilterProxyModel *subModel =
       
   113 			new NotesSortFilterProxyModel(*mAgendaUtil, this);
       
   114 	subModel->setDynamicSortFilter(true);
       
   115 	subModel->setSourceModel(mProxyModel);
       
   116 
       
   117 	// Get the list object from the document and update the model.
       
   118 	mListView = static_cast<HbListView *> (mDocLoader->findWidget("listView"));
       
   119 	Q_ASSERT_X(
       
   120 			mListView,
       
   121 			"notesmainview.cpp",
       
   122 			"Unable to find list view.");
       
   123 	// Update the list view model.
       
   124 	mListView->setModel(subModel);
       
   125 
       
   126 	// Setup the operations that can be done with a list view.
       
   127 	connect(
       
   128 			mListView, SIGNAL(activated(const QModelIndex &)),
       
   129 			this, SLOT(handleItemReleased(const QModelIndex &)));
       
   130 	connect(
       
   131 			mListView,
       
   132 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
       
   133 			this,
       
   134 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
       
   135 	connect(
       
   136 			mNotesModel, SIGNAL(rowAdded(QModelIndex)),
       
   137 			this, SLOT(scrollTo(QModelIndex)));
       
   138 
       
   139 	// Get the empty list label.
       
   140 	mEmptyListLabel = static_cast<HbLabel *> (
       
   141 			mDocLoader->findWidget("emptyListLabel"));
       
   142 	mEmptyListLabel->hide();
       
   143 
       
   144 	// Get the view heading label
       
   145 	mSubTitle = static_cast<HbGroupBox *>(
       
   146 			mDocLoader->findWidget("viewHeading"));
       
   147 
       
   148 	// Handles the orientation change for list items
       
   149 	HbMainWindow *window = hbInstance->allMainWindows().first();
       
   150 	handleOrientationChanged(window->orientation());
       
   151 	connect(
       
   152 			window, SIGNAL(orientationChanged(Qt::Orientation)),
       
   153 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
       
   154 
       
   155 	// Set the graphics size for the icons.
       
   156 	HbListViewItem *prototype = mListView->listItemPrototype();
       
   157 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
       
   158 	
       
   159 	// Get a pointer to activity Manager
       
   160 	HbActivityManager* activityManager =
       
   161 			qobject_cast<HbApplication*>(qApp)->activityManager();
       
   162 
       
   163 	// clean up any previous versions of this activity from the activity manager
       
   164 	// ignore return value as the first boot would always return a false
       
   165 	// bool declared on for debugging purpose
       
   166 	bool ok = activityManager->removeActivity(notes);
       
   167 
       
   168 	// connect main view for the first time to recieve aboutToQuit signal
       
   169 	connect(
       
   170 			qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()),
       
   171 			this, SLOT(saveActivity()));
       
   172 	
       
   173 	OstTraceFunctionExit0( NOTESMAINVIEW_SETUPVIEW_EXIT );
       
   174 }
       
   175 
       
   176 void NotesMainView::setupAfterViewReady()
       
   177 {
       
   178 	OstTraceFunctionEntry0( NOTESMAINVIEW_SETUPAFTERVIEWREADY_ENTRY );
       
   179 	// Get the toolbar/menu actions.
       
   180 	mAddNoteAction = static_cast<HbAction *> (
       
   181 			mDocLoader->findObject("newNoteAction"));
       
   182 	Q_ASSERT_X(
       
   183 			mAddNoteAction,
       
   184 			"notesmainview.cpp",
       
   185 			"Unable to find addNoteAction.");
       
   186 	connect(
       
   187 			mAddNoteAction, SIGNAL(triggered()),
       
   188 			this, SLOT(createNewNote()));
       
   189 
       
   190 	mAllNotesAction = static_cast<HbAction *> (
       
   191 			mDocLoader->findObject("allNotesAction"));
       
   192 	Q_ASSERT_X(
       
   193 			mAllNotesAction,
       
   194 			"notesmainview.cpp",
       
   195 			"Unable to find allNotesAction.");
       
   196 	mAllNotesAction->setCheckable(true);
       
   197 	mAllNotesAction->setChecked(true);
       
   198 	connect(
       
   199 			mAllNotesAction, SIGNAL(changed()),
       
   200 			this, SLOT(handleActionStateChanged()));
       
   201 
       
   202 	mViewCollectionAction = static_cast<HbAction *> (
       
   203 			mDocLoader->findObject("collectionsViewAction"));
       
   204 	Q_ASSERT_X(
       
   205 			mViewCollectionAction,
       
   206 			"notescollectionview.cpp",
       
   207 			"Unable to find viewCollectionAction.");
       
   208 
       
   209 	connect(
       
   210 			mViewCollectionAction, SIGNAL(triggered()),
       
   211 			this, SLOT(displayCollectionView()));
       
   212 
       
   213 	connect(
       
   214 			mAgendaUtil, SIGNAL(entryAdded(ulong)),
       
   215 			this,SLOT(updateSubTitle(ulong)));
       
   216 	connect(
       
   217 			mAgendaUtil, SIGNAL(entryDeleted(ulong)),
       
   218 			this,SLOT(updateSubTitle(ulong)));
       
   219 	connect(
       
   220 			mAgendaUtil, SIGNAL(entryUpdated(ulong)),
       
   221 			this, SLOT(updateSubTitle(ulong)));
       
   222 	OstTraceFunctionExit0( NOTESMAINVIEW_SETUPAFTERVIEWREADY_EXIT );
       
   223 }
       
   224 
       
   225 /*
       
   226 	Updates the title text for the first launch
       
   227  */
       
   228 void NotesMainView::updateTitle()
       
   229 {
       
   230 	OstTraceFunctionEntry0( NOTESMAINVIEW_UPDATETITLE_ENTRY );
       
   231 	updateSubTitle();
       
   232 	OstTraceFunctionExit0( NOTESMAINVIEW_UPDATETITLE_EXIT );
       
   233 }
       
   234 
       
   235 /*!
       
   236 	Slot which gets called when `+ New note' action is triggered from the view
       
   237 	toolbar. This is responsible for launching the editor to create a new note.
       
   238  */
       
   239 void NotesMainView::createNewNote()
       
   240 {
       
   241 	OstTraceFunctionEntry0( NOTESMAINVIEW_CREATENEWNOTE_ENTRY );
       
   242 
       
   243 	// Here we Display an editor to the use to enter text.
       
   244 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
       
   245 	connect(
       
   246 			mNotesEditor, SIGNAL(editingCompleted(bool)),
       
   247 			this, SLOT(handleEditingCompleted(bool)));
       
   248 	mNotesEditor->create(NotesEditor::CreateNote);
       
   249 	// capture screenshot for future use, if application
       
   250 	// is exited/Quit from notesEditor
       
   251 	captureScreenShot(true);
       
   252 	OstTraceFunctionExit0( NOTESMAINVIEW_CREATENEWNOTE_EXIT );
       
   253 }
       
   254 
       
   255 /*!
       
   256 	Handles the pressing of a list item in the view.
       
   257 
       
   258 	Here we open the editor for viewing/editing.
       
   259 
       
   260 	\param index Reference to the QModelIndex representing the view item.
       
   261 	\sa HbAbstractViewItem
       
   262  */
       
   263 void NotesMainView::handleItemReleased(const QModelIndex &index)
       
   264 {
       
   265 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEITEMRELEASED_ENTRY );
       
   266 	if(!mIsLongTop) {
       
   267 		// Sanity check.
       
   268 		if (!index.isValid()) {
       
   269 			OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEITEMRELEASED_EXIT );
       
   270 			return;
       
   271 		}
       
   272 
       
   273 		// First get the id of the note and get the corresponding information
       
   274 		// from agendautil.
       
   275 		ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong>();
       
   276 
       
   277 		if (0 >= noteId) {
       
   278 			// Something wrong.
       
   279 			OstTraceFunctionExit0( DUP1_NOTESMAINVIEW_HANDLEITEMRELEASED_EXIT );
       
   280 			return;
       
   281 		}
       
   282 
       
   283 		// Get the entry details.
       
   284 		AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   285 		if (entry.isNull()) {
       
   286 			// Entry invalid.
       
   287 			OstTraceFunctionExit0( DUP2_NOTESMAINVIEW_HANDLEITEMRELEASED_EXIT );
       
   288 			return;
       
   289 		}
       
   290 
       
   291 		if(AgendaEntry::TypeTodo == entry.type()) {
       
   292 			// Construct agenda event viewer.
       
   293 			mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
       
   294 
       
   295 			connect(
       
   296 					mAgendaEventViewer, SIGNAL(viewingCompleted(const QDate)),
       
   297 					this, SLOT(handleViewingCompleted()));
       
   298 			// Launch agenda event viewer
       
   299 			mAgendaEventViewer->view(
       
   300 					entry, AgendaEventViewer::ActionEditDelete);
       
   301 		}else if(AgendaEntry::TypeNote == entry.type()) {
       
   302 			// Construct notes editor.
       
   303 			mNotesEditor = new NotesEditor(mAgendaUtil, this);
       
   304 			connect(
       
   305 					mNotesEditor, SIGNAL(editingCompleted(bool)),
       
   306 					this, SLOT(handleEditingCompleted(bool)));
       
   307 
       
   308 			// Launch the notes editor with the obtained info.
       
   309 			mNotesEditor->edit(entry);
       
   310 		}
       
   311 		// capture screenshot for future use, if application
       
   312 		// is exited/Quit from eventViewer/notesEditor
       
   313 		captureScreenShot(true);
       
   314 	}
       
   315 	OstTraceFunctionExit0( DUP3_NOTESMAINVIEW_HANDLEITEMRELEASED_EXIT );
       
   316 }
       
   317 
       
   318 /*!
       
   319 	Displays a list item specific context menu.
       
   320 
       
   321 	\param item The HbAbstractViewItem that was long pressed.
       
   322 	\param coords The position where mouse was pressed.
       
   323 
       
   324 	\sa HbAbstractViewItem, HbListView, HbMenu.
       
   325  */
       
   326 void NotesMainView::handleItemLongPressed(
       
   327 		HbAbstractViewItem *item, const QPointF &coords)
       
   328 {
       
   329 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEITEMLONGPRESSED_ENTRY );
       
   330 	mIsLongTop = true;
       
   331 	mSelectedItem = item;
       
   332 
       
   333 	ulong noteId = item->modelIndex().data(
       
   334 			NotesNamespace::IdRole).value<qulonglong>();
       
   335 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   336 
       
   337 	// Display a context specific menu.
       
   338 	HbMenu *contextMenu = new HbMenu();
       
   339 	connect(
       
   340 			contextMenu,SIGNAL(aboutToClose()),
       
   341 			this, SLOT(handleMenuClosed()));
       
   342 
       
   343 	mOpenAction =
       
   344 			contextMenu->addAction(hbTrId("txt_common_menu_open"));
       
   345 
       
   346 	// Add actions to the context menu.
       
   347 	if (AgendaEntry::TypeTodo == entry.type()) {
       
   348 		mEditTodoAction =
       
   349 				contextMenu->addAction(hbTrId("txt_common_menu_edit"));
       
   350 	}
       
   351 
       
   352 	mDeleteAction =
       
   353 			contextMenu->addAction(hbTrId("txt_common_menu_delete"));
       
   354 
       
   355 	if (AgendaEntry::TypeNote == entry.type()) {
       
   356 		if (entry.favourite()) {
       
   357 			mMakeFavouriteAction = contextMenu->addAction(
       
   358 					hbTrId("txt_notes_menu_remove_from_favorites"));
       
   359 		} else {
       
   360 			mMakeFavouriteAction = contextMenu->addAction(
       
   361 					hbTrId("txt_notes_menu_mark_as_favorite"));
       
   362 		}
       
   363 
       
   364 		mMarkTodoAction =
       
   365 				contextMenu->addAction(
       
   366 						hbTrId("txt_notes_menu_make_it_as_todo_note"));
       
   367 
       
   368 	} else if (AgendaEntry::TypeTodo == entry.type()) {
       
   369 		if (AgendaEntry::TodoNeedsAction == entry.status()) {
       
   370 			mTodoStatusAction = contextMenu->addAction(
       
   371 					hbTrId("txt_notes_menu_mark_as_done"));
       
   372 		} else if (AgendaEntry::TodoCompleted == entry.status()) {
       
   373 			mTodoStatusAction = contextMenu->addAction(
       
   374 					hbTrId("txt_notes_menu_mark_as_not_done"));
       
   375 		}
       
   376 	}
       
   377 
       
   378 	// Show the menu.
       
   379 	contextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   380 	contextMenu->setPreferredPos(coords);
       
   381 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEITEMLONGPRESSED_EXIT );
       
   382 }
       
   383 
       
   384 /*!
       
   385 	Slot to delete a selected note.
       
   386  */
       
   387 void NotesMainView::deleteNote()
       
   388 {
       
   389 	OstTraceFunctionEntry0( NOTESMAINVIEW_DELETENOTE_ENTRY );
       
   390 	Q_ASSERT(mSelectedItem);
       
   391 
       
   392 	QModelIndex index = mSelectedItem->modelIndex();
       
   393 	if (!index.isValid()) {
       
   394 		OstTraceFunctionExit0( NOTESMAINVIEW_DELETENOTE_EXIT );
       
   395 		return;
       
   396 	}
       
   397 	ulong noteId =
       
   398 			index.data(NotesNamespace::IdRole).value<qulonglong>();
       
   399 	if (!noteId) {
       
   400 
       
   401 		OstTraceFunctionExit0( DUP1_NOTESMAINVIEW_DELETENOTE_EXIT );
       
   402 		return;
       
   403 	}
       
   404 
       
   405 	// Emit the signal.Deletion would happen in view manager.
       
   406 	emit deleteEntry(noteId);
       
   407 
       
   408 	mSelectedItem = 0;
       
   409 	OstTraceFunctionExit0( DUP2_NOTESMAINVIEW_DELETENOTE_EXIT );
       
   410 }
       
   411 
       
   412 /*!
       
   413 	Marks to-do entry as done or undone based on the completed value
       
   414 
       
   415 	\param entry reference to the agenda entry
       
   416 	\param status is true if to-do entry to be marked as done
       
   417 			is false if to-do entry to be marked as undone
       
   418  */
       
   419 void NotesMainView::markTodoStatus()
       
   420 {
       
   421 	OstTraceFunctionEntry0( NOTESMAINVIEW_MARKTODOSTATUS_ENTRY );
       
   422 	ulong noteId = mSelectedItem->modelIndex().data(
       
   423 			NotesNamespace::IdRole).value<qulonglong>();
       
   424 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   425 
       
   426 	QDateTime currentDateTime = QDateTime::currentDateTime();
       
   427 
       
   428 	if (AgendaEntry::TodoNeedsAction == entry.status()) {
       
   429 		mAgendaUtil->setCompleted(entry, true, currentDateTime);
       
   430 	} else if (AgendaEntry::TodoCompleted == entry.status()) {
       
   431 		mAgendaUtil->setCompleted(entry, false, currentDateTime);
       
   432 	}
       
   433 
       
   434 	OstTraceFunctionExit0( NOTESMAINVIEW_MARKTODOSTATUS_EXIT );
       
   435 }
       
   436 
       
   437 /*!
       
   438 	Marks/unmarks the note as favourite.
       
   439  */
       
   440 void NotesMainView::markNoteAsFavourite()
       
   441 {
       
   442 	OstTraceFunctionEntry0( NOTESMAINVIEW_MARKNOTEASFAVOURITE_ENTRY );
       
   443 	ulong noteId = mSelectedItem->modelIndex().data(
       
   444 				NotesNamespace::IdRole).value<qulonglong>();
       
   445 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   446 
       
   447 	if (entry.favourite()) {
       
   448 		entry.setFavourite(0);
       
   449 	} else {
       
   450 		entry.setFavourite(1);
       
   451 	}
       
   452 	mAgendaUtil->store(entry);
       
   453 
       
   454 	OstTraceFunctionExit0( NOTESMAINVIEW_MARKNOTEASFAVOURITE_EXIT );
       
   455 }
       
   456 
       
   457 /*!
       
   458 	Slot to handle the signal editingCompleted by the notes editor.
       
   459 
       
   460 	\param status Boolean value indicating whether the note was saved or not.
       
   461 
       
   462 	\sa NotesEditor.
       
   463  */
       
   464 void NotesMainView::handleEditingCompleted(bool status)
       
   465 {
       
   466 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEEDITINGCOMPLETED_ENTRY );
       
   467 	Q_UNUSED(status)
       
   468 
       
   469 	// Cleanup.
       
   470 	mNotesEditor->deleteLater();
       
   471 	// set captured screenshot as invalid as the control is returned back 
       
   472 	// to the main view
       
   473 	captureScreenShot(false);
       
   474 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEEDITINGCOMPLETED_EXIT );
       
   475 }
       
   476 
       
   477 /*!
       
   478 	Displays the collections' view.
       
   479  */
       
   480 void NotesMainView::displayCollectionView()
       
   481 {
       
   482 	OstTraceFunctionEntry0( NOTESMAINVIEW_DISPLAYCOLLECTIONVIEW_ENTRY );
       
   483 	// no need to capture the screen shot for future use as 
       
   484 	// NotesViewManager::switchToView takes care of it
       
   485 	// Switch to collections view.
       
   486 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
       
   487 
       
   488 	OstTraceFunctionExit0( NOTESMAINVIEW_DISPLAYCOLLECTIONVIEW_EXIT );
       
   489 }
       
   490 
       
   491 /*!
       
   492 	Slot where the list view is made to scroll to the QModelIndex index.
       
   493 
       
   494 	\param index QModelIndex to be scrolled to.
       
   495  */
       
   496 void NotesMainView::scrollTo(QModelIndex index)
       
   497 {
       
   498 	OstTraceFunctionEntry0( NOTESMAINVIEW_SCROLLTO_ENTRY );
       
   499 	mListView->scrollTo(index, HbAbstractItemView::EnsureVisible);
       
   500 	OstTraceFunctionExit0( NOTESMAINVIEW_SCROLLTO_EXIT );
       
   501 }
       
   502 
       
   503 /*!
       
   504 	Slot to handle viewing Completed signal from agenda event viewer
       
   505 
       
   506 	\param status Indicates the status of viewing
       
   507  */
       
   508 void NotesMainView::handleViewingCompleted()
       
   509 {
       
   510 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEVIEWINGCOMPLETED_ENTRY );
       
   511 	mAgendaEventViewer->deleteLater();
       
   512 	// set captured screenshot as invalid as the control is returned back 
       
   513 	// to the main view
       
   514 	captureScreenShot(false);
       
   515 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEVIEWINGCOMPLETED_EXIT );
       
   516 }
       
   517 
       
   518 /*!
       
   519 	Slot to handle the case when the state of an action has changed.
       
   520  */
       
   521 void NotesMainView::handleActionStateChanged()
       
   522 {
       
   523 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEACTIONSTATECHANGED_ENTRY );
       
   524 	mAllNotesAction->setChecked(true);
       
   525 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEACTIONSTATECHANGED_EXIT );
       
   526 }
       
   527 
       
   528 /*!
       
   529 	Launches the to-do editor to edit the to-do entry
       
   530  */
       
   531 
       
   532 void NotesMainView::editTodo()
       
   533 {
       
   534 	OstTraceFunctionEntry0( NOTESMAINVIEW_EDITTODO_ENTRY );
       
   535 	// Get the selected list item index
       
   536 	QModelIndex index = mSelectedItem->modelIndex();
       
   537 	if (!index.isValid()) {
       
   538 		OstTraceFunctionExit0( NOTESMAINVIEW_EDITTODO_EXIT );
       
   539 		return;
       
   540 	}
       
   541 	ulong todoId =
       
   542 			index.data(NotesNamespace::IdRole).value<qulonglong>();
       
   543 	if (!todoId) {
       
   544 
       
   545 		OstTraceFunctionExit0( DUP1_NOTESMAINVIEW_EDITTODO_EXIT );
       
   546 		return;
       
   547 	}
       
   548 
       
   549 	// Construct notes editor.
       
   550 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
       
   551 	connect(
       
   552 			mNotesEditor, SIGNAL(editingCompleted(bool)),
       
   553 			this, SLOT(handleEditingCompleted(bool)));
       
   554 
       
   555 	// Launch the to-do editor with the obtained info.
       
   556 	mNotesEditor->edit(todoId);
       
   557 	// capture screenshot for future use, if application
       
   558 	// is exited/Quit from notesEditor
       
   559 	captureScreenShot(true);
       
   560 
       
   561 	OstTraceFunctionExit0( DUP2_NOTESMAINVIEW_EDITTODO_EXIT );
       
   562 }
       
   563 
       
   564 /*!
       
   565 	Handles the orientation changes.Updates the list
       
   566 	item when orientation is changed
       
   567 
       
   568 	\param orientation Value of the orientation
       
   569  */
       
   570 void NotesMainView::handleOrientationChanged(Qt::Orientation orientation)
       
   571 {
       
   572 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEORIENTATIONCHANGED_ENTRY );
       
   573 	HbListViewItem *prototype = mListView->listItemPrototype();
       
   574 
       
   575 	if (Qt::Horizontal == orientation) {
       
   576 		prototype->setStretchingStyle(HbListViewItem::StretchLandscape);
       
   577 	} else {
       
   578 		prototype->setStretchingStyle(HbListViewItem::NoStretching);
       
   579 	}
       
   580 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEORIENTATIONCHANGED_EXIT );
       
   581 }
       
   582 
       
   583 /*!
       
   584 	Updates the sub heading text
       
   585  */
       
   586 void NotesMainView::updateSubTitle(ulong id)
       
   587 {
       
   588 	OstTraceFunctionEntry0( NOTESMAINVIEW_UPDATESUBTITLE_ENTRY );
       
   589 	Q_UNUSED(id)
       
   590 
       
   591 	// Get the number of notes and to-do entries.
       
   592 	QList<ulong> entries = mAgendaUtil->entryIds(
       
   593 			(AgendaUtil::FilterFlags)
       
   594 			(AgendaUtil::IncludeNotes
       
   595 			| AgendaUtil::IncludeCompletedTodos
       
   596 			| AgendaUtil::IncludeIncompletedTodos));
       
   597 	
       
   598 	if (0 >= entries.count()) {
       
   599 		mEmptyListLabel->show();
       
   600 		mListView->hide();
       
   601 	} else {
       
   602 		mEmptyListLabel->hide();
       
   603 		mListView->show();
       
   604 	}
       
   605 	
       
   606 	mSubTitle->setHeading(
       
   607 			hbTrId("txt_notes_subhead_ln_notes",entries.count()));
       
   608 	OstTraceFunctionExit0( NOTESMAINVIEW_UPDATESUBTITLE_EXIT );
       
   609 }
       
   610 
       
   611 /*!
       
   612 	Slot to make a note as to-do.
       
   613  */
       
   614 void NotesMainView::markNoteAsTodo()
       
   615 {
       
   616 	OstTraceFunctionEntry0( NOTESMAINVIEW_MARKNOTEASTODO_ENTRY );
       
   617 	Q_ASSERT(mSelectedItem);
       
   618 
       
   619 	QModelIndex index = mSelectedItem->modelIndex();
       
   620 	if (!index.isValid()) {
       
   621 		OstTraceFunctionExit0( NOTESMAINVIEW_MARKNOTEASTODO_EXIT );
       
   622 		return;
       
   623 	}
       
   624 	ulong noteId = index.data(NotesNamespace::IdRole).value<qulonglong> ();
       
   625 	if (!noteId) {
       
   626 		OstTraceFunctionExit0( DUP1_NOTESMAINVIEW_MARKNOTEASTODO_EXIT );
       
   627 		return;
       
   628 	}
       
   629 	// Get the entry details.
       
   630 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   631 
       
   632 	if (entry.isNull()) {
       
   633 		// Entry invalid.
       
   634 		OstTraceFunctionExit0( DUP2_NOTESMAINVIEW_MARKNOTEASTODO_EXIT );
       
   635 		return;
       
   636 	}
       
   637 
       
   638 	// Here change the type of modified note and destroy the noteeditor and
       
   639 	// construct the to-do editor.
       
   640 	entry.setType(AgendaEntry::TypeTodo);
       
   641 
       
   642 	QDateTime dueDateTime;
       
   643 	QDate currentDate(QDate::currentDate());
       
   644 	dueDateTime.setDate(
       
   645 			QDate(currentDate.year(),currentDate.month(),currentDate.day()+1));
       
   646 	dueDateTime.setTime(QTime::fromString("12:00 am", "hh:mm ap"));
       
   647 
       
   648 	entry.setStartAndEndTime(dueDateTime, dueDateTime);
       
   649 
       
   650 	entry.setSummary(entry.description().left(80));
       
   651 
       
   652 	if (80 > entry.description().length()) {
       
   653 		entry.setDescription("");
       
   654 	}
       
   655 
       
   656 	// Remove favourite if marked so.
       
   657 	entry.setFavourite(0);
       
   658 	
       
   659 	// Set the priority of the to-do as normal
       
   660 	entry.setPriority(2);
       
   661 
       
   662 	// Set the status of the to-do.
       
   663 	entry.setStatus(AgendaEntry::TodoNeedsAction);
       
   664 
       
   665 	// First clone the todoEntry for the new type.
       
   666 	mAgendaUtil->cloneEntry(entry, AgendaEntry::TypeTodo);
       
   667 
       
   668 	// Delete the old entry.
       
   669 	mAgendaUtil->deleteEntry(entry.id());
       
   670 	OstTraceFunctionExit0( DUP3_NOTESMAINVIEW_MARKNOTEASTODO_EXIT );
       
   671 }
       
   672 
       
   673 
       
   674 /*
       
   675 	Opens the notes editor if selected item is note otherwise opens
       
   676 	to-do viewer if selected item is to-do event
       
   677  */
       
   678 void NotesMainView::openNote()
       
   679 {
       
   680 	OstTraceFunctionEntry0( NOTESMAINVIEW_OPENNOTE_ENTRY );
       
   681 	ulong noteId = mSelectedItem->modelIndex().data(
       
   682 			NotesNamespace::IdRole).value<qulonglong>();
       
   683 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
       
   684 
       
   685 	if (AgendaEntry::TypeNote == entry.type()) {
       
   686 		// Construct notes editor.
       
   687 		mNotesEditor = new NotesEditor(mAgendaUtil, this);
       
   688 		connect(
       
   689 				mNotesEditor, SIGNAL(editingCompleted(bool)),
       
   690 				this, SLOT(handleEditingCompleted(bool)));
       
   691 
       
   692 		// Launch the notes editor with the obtained info.
       
   693 		mNotesEditor->edit(entry);
       
   694 	} else if (AgendaEntry::TypeTodo == entry.type()) {
       
   695 
       
   696 		// Construct agenda event viewer.
       
   697 		mAgendaEventViewer = new AgendaEventViewer(mAgendaUtil, this);
       
   698 
       
   699 		connect(
       
   700 				mAgendaEventViewer, SIGNAL(viewingCompleted(bool)),
       
   701 				this, SLOT(handleViewingCompleted(bool)));
       
   702 		// Launch agenda event viewer
       
   703 		mAgendaEventViewer->view(
       
   704 				entry, AgendaEventViewer::ActionEditDelete);
       
   705 	}
       
   706 	// capture screenshot for future use, if application
       
   707 	// is exited/Quit from notesEditor/eventViewer
       
   708 	captureScreenShot(true);
       
   709 	OstTraceFunctionExit0( NOTESMAINVIEW_OPENNOTE_EXIT );
       
   710 }
       
   711 
       
   712 /*!
       
   713 	 Slot to handle the selected context menu actions
       
   714  */
       
   715 void NotesMainView::selectedMenuAction(HbAction *action)
       
   716 {
       
   717 	OstTraceFunctionEntry0( NOTESMAINVIEW_SELECTEDMENUACTION_ENTRY );
       
   718 	if (action == mOpenAction) {
       
   719 		openNote();
       
   720 	} else if (action == mEditTodoAction) {
       
   721 		editTodo();
       
   722 	} else if (action == mDeleteAction) {
       
   723 		deleteNote();
       
   724 	} else if (action == mMakeFavouriteAction) {
       
   725 		markNoteAsFavourite();
       
   726 	} else if (action == mMarkTodoAction) {
       
   727 		markNoteAsTodo();
       
   728 	} else if (action == mTodoStatusAction) {
       
   729 		markTodoStatus();
       
   730 	}
       
   731 	OstTraceFunctionExit0( NOTESMAINVIEW_SELECTEDMENUACTION_EXIT );
       
   732 }
       
   733 
       
   734 /*!
       
   735 	Slot to handle the context menu closed.
       
   736  */
       
   737 void NotesMainView::handleMenuClosed()
       
   738 {
       
   739 	OstTraceFunctionEntry0( NOTESMAINVIEW_HANDLEMENUCLOSED_ENTRY );
       
   740 	mIsLongTop = false;
       
   741 	OstTraceFunctionExit0( NOTESMAINVIEW_HANDLEMENUCLOSED_EXIT );
       
   742 }
       
   743 
       
   744 /*!
       
   745 	CaptureScreenShot captures screen shot 
       
   746 	\param captureScreenShot bool to indicate if screenshot needs to be captured
       
   747 */ 
       
   748 void NotesMainView::captureScreenShot(bool captureScreenShot)
       
   749 {
       
   750 	OstTraceFunctionEntry0( NOTESMAINVIEW_CAPTURESCREENSHOT_ENTRY );
       
   751 	// check if screen shot needs to be captured
       
   752 	if (captureScreenShot) {
       
   753 		mScreenShot.clear();
       
   754 		mScreenShot.insert(
       
   755 				"screenshot", QPixmap::grabWidget(
       
   756 						mainWindow(), mainWindow()->rect()));
       
   757 	}
       
   758 	// set mIsScreenShotCapruted set validity of screenshot
       
   759 	mIsScreenShotCapruted = captureScreenShot;
       
   760 	OstTraceFunctionExit0( NOTESMAINVIEW_CAPTURESCREENSHOT_EXIT );
       
   761 }
       
   762 
       
   763 /*!
       
   764 	saveActivity saves main view as an activity 
       
   765 */
       
   766 void NotesMainView::saveActivity()
       
   767 {
       
   768 	OstTraceFunctionEntry0( NOTESMAINVIEW_SAVEACTIVITY_ENTRY );
       
   769 	// Get a pointer to activity Manager
       
   770 	HbActivityManager* activityManager =
       
   771 			qobject_cast<HbApplication*>(qApp)->activityManager();
       
   772 	
       
   773 	// check if a valid screenshot is already captured
       
   774 	if (!mIsScreenShotCapruted) {
       
   775 		mScreenShot.clear();
       
   776 		mScreenShot.insert(
       
   777 				"screenshot", QPixmap::grabWidget(
       
   778 						mainWindow(), mainWindow()->rect()));
       
   779 	}
       
   780 
       
   781 	// save any data necessary to save the state
       
   782 	QByteArray serializedActivity;
       
   783 	QDataStream stream(
       
   784 			&serializedActivity, QIODevice::WriteOnly | QIODevice::Append);
       
   785 	stream << NotesNamespace::NotesMainViewId;
       
   786 
       
   787 	// add the activity to the activity manager
       
   788 	bool ok = activityManager->addActivity(
       
   789 			notes, serializedActivity, mScreenShot);
       
   790 	if (!ok) {
       
   791 		qFatal("Add failed" );
       
   792 	}
       
   793 	OstTraceFunctionExit0( NOTESMAINVIEW_SAVEACTIVITY_EXIT );
       
   794 }
       
   795 
       
   796 // End of file	--Don't remove this.