notes/notesui/notesviews/src/notesmainview.cpp
changeset 49 5de72ea7a065
parent 26 a949c2543c15
child 50 579cc610882e
equal deleted inserted replaced
37:360d55486d7f 49:5de72ea7a065
    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 /*!
   137 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   141 			this, SLOT(handleOrientationChanged(Qt::Orientation)));
   138 
   142 
   139 	// Set the graphics size for the icons.
   143 	// Set the graphics size for the icons.
   140 	HbListViewItem *prototype = mListView->listItemPrototype();
   144 	HbListViewItem *prototype = mListView->listItemPrototype();
   141 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   145 	prototype->setGraphicsSize(HbListViewItem::SmallIcon);
   142 }
   146 	
       
   147     // Get a pointer to activity Manager
       
   148     HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   149   
       
   150     // clean up any previous versions of this activity from the activity manager.
       
   151     // ignore return value as the first boot would always return a false
       
   152     // bool declared on for debugging purpose
       
   153     bool ok = activityManager->removeActivity(notes);
       
   154 	
       
   155 	// connect main view for the first time to recieve aboutToQuit signal
       
   156     connect(qobject_cast<HbApplication*>(qApp), SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
   157     
       
   158  }
   143 
   159 
   144 void NotesMainView::setupAfterViewReady()
   160 void NotesMainView::setupAfterViewReady()
   145 {
   161 {
   146 	// Get the toolbar/menu actions.
   162 	// Get the toolbar/menu actions.
   147 	mAddNoteAction = static_cast<HbAction *> (
   163 	mAddNoteAction = static_cast<HbAction *> (
   207 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   223 	mNotesEditor = new NotesEditor(mAgendaUtil, this);
   208 	connect(
   224 	connect(
   209 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   225 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   210 			this, SLOT(handleEditingCompleted(bool)));
   226 			this, SLOT(handleEditingCompleted(bool)));
   211 	mNotesEditor->create(NotesEditor::CreateNote);
   227 	mNotesEditor->create(NotesEditor::CreateNote);
       
   228 	// capture screenshot for future use, if application
       
   229 	// is exited/Quit from notesEditor
       
   230 	captureScreenShot(true);
   212 }
   231 }
   213 
   232 
   214 /*!
   233 /*!
   215 	Handles the pressing of a list item in the view.
   234 	Handles the pressing of a list item in the view.
   216 
   235 
   261 					this, SLOT(handleEditingCompleted(bool)));
   280 					this, SLOT(handleEditingCompleted(bool)));
   262 
   281 
   263 			// Launch the notes editor with the obtained info.
   282 			// Launch the notes editor with the obtained info.
   264 			mNotesEditor->edit(entry);
   283 			mNotesEditor->edit(entry);
   265 		}
   284 		}
       
   285 		// capture screenshot for future use, if application
       
   286 		// is exited/Quit from eventViewer/notesEditor
       
   287 		captureScreenShot(true);
   266 	}
   288 	}
   267 }
   289 }
   268 
   290 
   269 /*!
   291 /*!
   270 	Displays a list item specific context menu.
   292 	Displays a list item specific context menu.
   406 {
   428 {
   407 	Q_UNUSED(status)
   429 	Q_UNUSED(status)
   408 
   430 
   409 	// Cleanup.
   431 	// Cleanup.
   410 	mNotesEditor->deleteLater();
   432 	mNotesEditor->deleteLater();
   411 
   433 	// set captured screenshot as invalid as the control is returned back 
       
   434 	// to the main view
       
   435 	captureScreenShot(false);
   412 }
   436 }
   413 
   437 
   414 /*!
   438 /*!
   415 	Displays the collections' view.
   439 	Displays the collections' view.
   416  */
   440  */
   417 void NotesMainView::displayCollectionView()
   441 void NotesMainView::displayCollectionView()
   418 {
   442 {
   419 
   443     // no need to capture the screen shot for future use as 
       
   444     // NotesViewManager::switchToView takes care of it
   420 	// Switch to collections view.
   445 	// Switch to collections view.
   421 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   446 	mAppControllerIf->switchToView(NotesNamespace::NotesCollectionViewId);
   422 
   447 
   423 }
   448 }
   424 
   449 
   438 	\param status Indicates the status of viewing
   463 	\param status Indicates the status of viewing
   439  */
   464  */
   440 void NotesMainView::handleViewingCompleted()
   465 void NotesMainView::handleViewingCompleted()
   441 {
   466 {
   442 	mAgendaEventViewer->deleteLater();
   467 	mAgendaEventViewer->deleteLater();
       
   468 	// set captured screenshot as invalid as the control is returned back 
       
   469 	// to the main view
       
   470 	captureScreenShot(false);
   443 }
   471 }
   444 
   472 
   445 /*!
   473 /*!
   446 	Slot to handle the case when the state of an action has changed.
   474 	Slot to handle the case when the state of an action has changed.
   447  */
   475  */
   474 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   502 			mNotesEditor, SIGNAL(editingCompleted(bool)),
   475 			this, SLOT(handleEditingCompleted(bool)));
   503 			this, SLOT(handleEditingCompleted(bool)));
   476 
   504 
   477 	// Launch the to-do editor with the obtained info.
   505 	// Launch the to-do editor with the obtained info.
   478 	mNotesEditor->edit(todoId);
   506 	mNotesEditor->edit(todoId);
       
   507 	// capture screenshot for future use, if application
       
   508 	// is exited/Quit from notesEditor
       
   509 	captureScreenShot(true);
   479 
   510 
   480 }
   511 }
   481 
   512 
   482 /*!
   513 /*!
   483 	Handles the orientation changes.Updates the list
   514 	Handles the orientation changes.Updates the list
   598 				this, SLOT(handleViewingCompleted(bool)));
   629 				this, SLOT(handleViewingCompleted(bool)));
   599 		// Launch agenda event viewer
   630 		// Launch agenda event viewer
   600 		mAgendaEventViewer->view(
   631 		mAgendaEventViewer->view(
   601 				entry, AgendaEventViewer::ActionEditDelete);
   632 				entry, AgendaEventViewer::ActionEditDelete);
   602 	}
   633 	}
       
   634 	// capture screenshot for future use, if application
       
   635 	// is exited/Quit from notesEditor/eventViewer
       
   636 	captureScreenShot(true);
   603 }
   637 }
   604 
   638 
   605 /*!
   639 /*!
   606 	 Slot to handle the selected context menu actions
   640 	 Slot to handle the selected context menu actions
   607  */
   641  */
   628 void NotesMainView::handleMenuClosed()
   662 void NotesMainView::handleMenuClosed()
   629 {
   663 {
   630 	mIsLongTop = false;
   664 	mIsLongTop = false;
   631 }
   665 }
   632 
   666 
       
   667 /*!
       
   668 	CaptureScreenShot captures screen shot 
       
   669 	\param captureScreenShot bool to indicate if screenshot needs to be captured
       
   670 */ 
       
   671 void NotesMainView::captureScreenShot(bool captureScreenShot)
       
   672     {
       
   673     if (captureScreenShot) // check if screen shot needs to be captured
       
   674         {
       
   675         mScreenShot.clear();
       
   676         mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
       
   677         }
       
   678     mIsScreenShotCapruted = captureScreenShot; // set mIsScreenShotCapruted set validity of screenshot
       
   679     }
       
   680 
       
   681 /*!    
       
   682 	saveActivity saves main view as an activity 
       
   683 */ 
       
   684 void NotesMainView::saveActivity()
       
   685  {
       
   686    // Get a pointer to activity Manager
       
   687    HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   688  
       
   689    if (!mIsScreenShotCapruted) // check if a valid screenshot is already captured
       
   690        {
       
   691        mScreenShot.clear();
       
   692        mScreenShot.insert("screenshot", QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
       
   693        }
       
   694  
       
   695    // save any data necessary to save the state
       
   696    QByteArray serializedActivity;
       
   697    QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append);
       
   698    stream << NotesNamespace::NotesMainViewId;
       
   699  
       
   700    // add the activity to the activity manager
       
   701    bool ok = activityManager->addActivity(notes, serializedActivity, mScreenShot);
       
   702    if ( !ok )
       
   703        {
       
   704        qFatal("Add failed" );
       
   705        }
       
   706  }
   633 // End of file	--Don't remove this.
   707 // End of file	--Don't remove this.