notes/notesui/notesviews/src/notesmainview.cpp
branchGCC_SURGE
changeset 54 e6894b852bc6
parent 50 579cc610882e
child 58 ef813d54df51
equal deleted inserted replaced
40:4b686cfad39d 54:e6894b852bc6
    28 #include <HbLabel>
    28 #include <HbLabel>
    29 #include <HbAbstractViewItem>
    29 #include <HbAbstractViewItem>
    30 #include <HbAbstractItemView>
    30 #include <HbAbstractItemView>
    31 #include <HbGroupBox>
    31 #include <HbGroupBox>
    32 #include <HbListViewItem>
    32 #include <HbListViewItem>
       
    33 #include <hbapplication> // hbapplication
       
    34 #include <hbactivitymanager> // hbactivitymanager
    33 
    35 
    34 // User includes
    36 // User includes
    35 #include "agendaeventviewer.h"
    37 #include "agendaeventviewer.h"
    36 #include "notesmainview.h"
    38 #include "notesmainview.h"
    37 #include "notescommon.h"
    39 #include "notescommon.h"
    38 #include "notesdocloader.h"
    40 #include "notesdocloader.h"
    39 #include "agendautil.h"
    41 #include "agendautil.h"
    40 #include "notesmodel.h"
    42 #include "notesmodel.h"
    41 #include "notessortfilterproxymodel.h"
    43 #include "notessortfilterproxymodel.h"
    42 #include "noteseditor.h"
    44 #include "noteseditor.h"
       
    45 #include "notescommon.h" // NotesNamespace
    43 
    46 
    44 /*!
    47 /*!
    45 	\class NotesMainView
    48 	\class NotesMainView
    46 	\brief The main view of the notes application. Responsible for displaying
    49 	\brief The main view of the notes application. Responsible for displaying
    47 			notes and todos.
    50 			notes and todos.
    56  */
    59  */
    57 NotesMainView::NotesMainView(QGraphicsWidget *parent)
    60 NotesMainView::NotesMainView(QGraphicsWidget *parent)
    58 :HbView(parent),
    61 :HbView(parent),
    59  mSelectedItem(0),
    62  mSelectedItem(0),
    60  mDeleteAction(0),
    63  mDeleteAction(0),
    61  mIsLongTop(false)
    64  mIsLongTop(false),
       
    65  mIsScreenShotCapruted(false)
    62 {
    66 {
    63 	// Nothing yet.
    67 	// Nothing yet.
    64 }
    68 }
    65 
    69 
    66 /*!
    70 /*!
   120 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   124 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   121 	connect(
   125 	connect(
   122 			mNotesModel, SIGNAL(rowAdded(QModelIndex)),
   126 			mNotesModel, SIGNAL(rowAdded(QModelIndex)),
   123 			this, SLOT(scrollTo(QModelIndex)));
   127 			this, SLOT(scrollTo(QModelIndex)));
   124 
   128 
       
   129 	// Get the empty list label.
       
   130 	mEmptyListLabel = static_cast<HbLabel *> (
       
   131 			mDocLoader->findWidget("emptyListLabel"));
       
   132 	mEmptyListLabel->hide();
       
   133 
   125 	// Get the view heading label
   134 	// Get the view heading label
   126 /*	mViewHeading = static_cast<HbLabel *> (
       
   127 			mDocLoader->findWidget("viewHeading"));*/
       
   128 
       
   129 	mSubTitle = static_cast<HbGroupBox *>(
   135 	mSubTitle = static_cast<HbGroupBox *>(
   130 			mDocLoader->findWidget("viewHeading"));
   136 			mDocLoader->findWidget("viewHeading"));
   131 
   137 
   132 	// Handles the orientation change for list items
   138 	// Handles the orientation change for list items
   133 	HbMainWindow *window = hbInstance->allMainWindows().first();
   139 	HbMainWindow *window = hbInstance->allMainWindows().first();
   137 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   143 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   138 
   144 
   139 	// Set the graphics size for the icons.
   145 	// Set the graphics size for the icons.
   140 	HbListViewItem *prototype = mListView->listItemPrototype();
   146 	HbListViewItem *prototype = mListView->listItemPrototype();
   141 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   147 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   142 }
   148 	
       
   149     // Get a pointer to activity Manager
       
   150     HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   151   
       
   152     // clean up any previous versions of this activity from the activity manager.
       
   153     // ignore return value as the first boot would always return a false
       
   154     // bool declared on for debugging purpose
       
   155     bool ok = activityManager->removeActivity(notes);
       
   156 	
       
   157 	// connect main view for the first time to recieve aboutToQuit signal
       
   158     connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   159     
       
   160  }
   143 
   161 
   144 void NotesMainView::setupAfterViewReady()
   162 void NotesMainView::setupAfterViewReady()
   145 {
   163 {
   146 	// Get the toolbar/menu actions.
   164 	// Get the toolbar/menu actions.
   147 	mAddNoteAction = static_cast<HbAction *> (
   165 	mAddNoteAction = static_cast<HbAction *> (
   207 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   225 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   208 	connect(
   226 	connect(
   209 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   227 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   210 			this, SLOT(handleEditingCompleted(bool)));
   228 			this, SLOT(handleEditingCompleted(bool)));
   211 	mNotesEditor->create(NotesEditor::CreateNote);
   229 	mNotesEditor->create(NotesEditor::CreateNote);
       
   230 	// capture screenshot for future use, if application
       
   231 	// is exited/Quit from notesEditor
       
   232 	captureScreenShot(true);
   212 }
   233 }
   213 
   234 
   214 /*!
   235 /*!
   215 	Handles the pressing of a list item in the view.
   236 	Handles the pressing of a list item in the view.
   216 
   237 
   261 					this, SLOT(handleEditingCompleted(bool)));
   282 					this, SLOT(handleEditingCompleted(bool)));
   262 
   283 
   263 			// Launch the notes editor with the obtained info.
   284 			// Launch the notes editor with the obtained info.
   264 			mNotesEditor->edit(entry);
   285 			mNotesEditor->edit(entry);
   265 		}
   286 		}
       
   287 		// capture screenshot for future use, if application
       
   288 		// is exited/Quit from eventViewer/notesEditor
       
   289 		captureScreenShot(true);
   266 	}
   290 	}
   267 }
   291 }
   268 
   292 
   269 /*!
   293 /*!
   270 	Displays a list item specific context menu.
   294 	Displays a list item specific context menu.
   406 {
   430 {
   407 	Q_UNUSED(status)
   431 	Q_UNUSED(status)
   408 
   432 
   409 	// Cleanup.
   433 	// Cleanup.
   410 	mNotesEditor->deleteLater();
   434 	mNotesEditor->deleteLater();
   411 
   435 	// set captured screenshot as invalid as the control is returned back 
       
   436 	// to the main view
       
   437 	captureScreenShot(false);
   412 }
   438 }
   413 
   439 
   414 /*!
   440 /*!
   415 	Displays the collections' view.
   441 	Displays the collections' view.
   416  */
   442  */
   417 void NotesMainView::displayCollectionView()
   443 void NotesMainView::displayCollectionView()
   418 {
   444 {
   419 
   445     // no need to capture the screen shot for future use as 
       
   446     // NotesViewManager::switchToView takes care of it
   420 	// Switch to collections view.
   447 	// Switch to collections view.
   421 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   448 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   422 
   449 
   423 }
   450 }
   424 
   451 
   438 	\param status Indicates the status of viewing
   465 	\param status Indicates the status of viewing
   439  */
   466  */
   440 void NotesMainView::handleViewingCompleted()
   467 void NotesMainView::handleViewingCompleted()
   441 {
   468 {
   442 	mAgendaEventViewer->deleteLater();
   469 	mAgendaEventViewer->deleteLater();
       
   470 	// set captured screenshot as invalid as the control is returned back 
       
   471 	// to the main view
       
   472 	captureScreenShot(false);
   443 }
   473 }
   444 
   474 
   445 /*!
   475 /*!
   446 	Slot to handle the case when the state of an action has changed.
   476 	Slot to handle the case when the state of an action has changed.
   447  */
   477  */
   474 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   504 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   475 			this, SLOT(handleEditingCompleted(bool)));
   505 			this, SLOT(handleEditingCompleted(bool)));
   476 
   506 
   477 	// Launch the to-do editor with the obtained info.
   507 	// Launch the to-do editor with the obtained info.
   478 	mNotesEditor->edit(todoId);
   508 	mNotesEditor->edit(todoId);
       
   509 	// capture screenshot for future use, if application
       
   510 	// is exited/Quit from notesEditor
       
   511 	captureScreenShot(true);
   479 
   512 
   480 }
   513 }
   481 
   514 
   482 /*!
   515 /*!
   483 	Handles the orientation changes.Updates the list
   516 	Handles the orientation changes.Updates the list
   507 	QList<ulong> entries = mAgendaUtil->entryIds(
   540 	QList<ulong> entries = mAgendaUtil->entryIds(
   508 			(AgendaUtil::FilterFlags)
   541 			(AgendaUtil::FilterFlags)
   509 			(AgendaUtil::IncludeNotes
   542 			(AgendaUtil::IncludeNotes
   510 			| AgendaUtil::IncludeCompletedTodos
   543 			| AgendaUtil::IncludeCompletedTodos
   511 			| AgendaUtil::IncludeIncompletedTodos));
   544 			| AgendaUtil::IncludeIncompletedTodos));
   512 	int c= entries.count();
   545 	
       
   546 	if (0 >= entries.count()) {
       
   547 		mEmptyListLabel->show();
       
   548 		mListView->hide();
       
   549 	} else {
       
   550 		mEmptyListLabel->hide();
       
   551 		mListView->show();
       
   552 	}
       
   553 	
   513 	mSubTitle->setHeading(
   554 	mSubTitle->setHeading(
   514 			hbTrId("txt_notes_subhead_ln_notes",entries.count()));
   555 			hbTrId("txt_notes_subhead_ln_notes",entries.count()));
   515 }
   556 }
   516 
   557 
   517 /*!
   558 /*!
   598 				this, SLOT(handleViewingCompleted(bool)));
   639 				this, SLOT(handleViewingCompleted(bool)));
   599 		// Launch agenda event viewer
   640 		// Launch agenda event viewer
   600 		mAgendaEventViewer->view(
   641 		mAgendaEventViewer->view(
   601 				entry, AgendaEventViewer::ActionEditDelete);
   642 				entry, AgendaEventViewer::ActionEditDelete);
   602 	}
   643 	}
       
   644 	// capture screenshot for future use, if application
       
   645 	// is exited/Quit from notesEditor/eventViewer
       
   646 	captureScreenShot(true);
   603 }
   647 }
   604 
   648 
   605 /*!
   649 /*!
   606 	 Slot to handle the selected context menu actions
   650 	 Slot to handle the selected context menu actions
   607  */
   651  */
   628 void NotesMainView::handleMenuClosed()
   672 void NotesMainView::handleMenuClosed()
   629 {
   673 {
   630 	mIsLongTop = false;
   674 	mIsLongTop = false;
   631 }
   675 }
   632 
   676 
       
   677 /*!
       
   678 	CaptureScreenShot captures screen shot 
       
   679 	\param captureScreenShot bool to indicate if screenshot needs to be captured
       
   680 */ 
       
   681 void NotesMainView::captureScreenShot(bool captureScreenShot)
       
   682     {
       
   683     if (captureScreenShot) // check if screen shot needs to be captured
       
   684         {
       
   685         mScreenShot.clear();
       
   686         mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
       
   687         }
       
   688     mIsScreenShotCapruted = captureScreenShot; // set mIsScreenShotCapruted set validity of screenshot
       
   689     }
       
   690 
       
   691 /*!    
       
   692 	saveActivity saves main view as an activity 
       
   693 */ 
       
   694 void NotesMainView::saveActivity()
       
   695  {
       
   696    // Get a pointer to activity Manager
       
   697    HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   698  
       
   699    if (!mIsScreenShotCapruted) // check if a valid screenshot is already captured
       
   700        {
       
   701        mScreenShot.clear();
       
   702        mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
       
   703        }
       
   704  
       
   705    // save any data necessary to save the state
       
   706    QByteArray serializedActivity;
       
   707    QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append);
       
   708    stream << NotesNamespace::NotesMainViewId;
       
   709  
       
   710    // add the activity to the activity manager
       
   711    bool ok = activityManager->addActivity(notes, serializedActivity, mScreenShot);
       
   712    if ( !ok )
       
   713        {
       
   714        qFatal("Add failed" );
       
   715        }
       
   716  }
   633 // End of file	--Don't remove this.
   717 // End of file	--Don't remove this.