notes/notesui/notesviewmanager/src/notesviewmanager.cpp
changeset 23 fd30d51f876b
parent 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
18:c198609911f9 23:fd30d51f876b
    14 * Description: Definition file for class NotesDocLoader.
    14 * Description: Definition file for class NotesDocLoader.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <qdebug.h>
       
    20 #include <qglobal.h>
    19 #include <qglobal.h>
    21 #include <QtGui>
    20 #include <QtGui>
    22 #include <HbMainWindow>
    21 #include <HbMainWindow>
    23 #include <HbView>
    22 #include <HbView>
    24 #include <HbInstance>
    23 #include <HbInstance>
    25 #include <HbListView>
    24 #include <HbListView>
       
    25 #include <HbMessageBox>
       
    26 #include <HbAction>
    26 
    27 
    27 // User includes
    28 // User includes
    28 #include "notesviewmanager.h"
    29 #include "notesviewmanager.h"
    29 #include "notesmainview.h"
    30 #include "notesmainview.h"
    30 #include "notescollectionview.h"
    31 #include "notescollectionview.h"
    52 NotesViewManager::NotesViewManager(
    53 NotesViewManager::NotesViewManager(
    53 		NotesAppControllerIf &controllerIf, QObject *parent)
    54 		NotesAppControllerIf &controllerIf, QObject *parent)
    54 :QObject(parent),
    55 :QObject(parent),
    55  mAppControllerIf(controllerIf)
    56  mAppControllerIf(controllerIf)
    56 {
    57 {
    57 	qDebug() << "notes: NotesViewManager::NotesViewManager -->";
    58 	HbMainWindow *window = hbInstance->allMainWindows().first();
    58 
    59 
    59 	// The document loader and views.
    60 	mAgendaUtil = mAppControllerIf.agendaUtil();
    60 	loadViews();
    61 
    61 
    62 	// Load the main view at the start up.
    62 	qDebug() << "notes: NotesViewManager::NotesViewManager <--";
    63 	loadNotesMainView();
       
    64 
       
    65 	// Delay loading of other views till main view is loaded.
       
    66 	connect(
       
    67 			window, SIGNAL(viewReady()),
       
    68 			this, SLOT(loadOtherViews()));
    63 }
    69 }
    64 
    70 
    65 /*!
    71 /*!
    66 	Destructor.
    72 	Destructor.
    67  */
    73  */
   114 			break;
   120 			break;
   115 	}
   121 	}
   116 }
   122 }
   117 
   123 
   118 /*!
   124 /*!
   119 	Loads the views from the docml file.
   125 	Loads the notes main view.
   120  */
   126  */
   121 void NotesViewManager::loadViews()
   127 void NotesViewManager::loadNotesMainView()
   122 {
   128 {
   123 	qDebug() << "notes: NotesViewManager::loadViews -->";
   129 	bool loadSuccess;
   124 
   130 
   125 	// Load the main view.
   131 	// Construct the document loader instance
   126 	loadNotesMainView();
   132 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   133 
       
   134 	// Load the application xml.
       
   135 	docLoader->load(NOTES_MAIN_VIEW_XML, &loadSuccess);
       
   136 	Q_ASSERT_X(
       
   137 			loadSuccess,
       
   138 			"notesviewmanager.cpp",
       
   139 			"Unable to load the main view app xml");
       
   140 
       
   141 	// Find the main view.
       
   142 	mMainView = static_cast<NotesMainView *> (
       
   143 			docLoader->findWidget(NOTES_MAIN_VIEW));
       
   144 	Q_ASSERT_X(
       
   145 			mMainView, "notesviewmanager.cpp", "Unable to find the main view.");
       
   146 	// Setup the view.
       
   147 	mMainView->setupView(mAppControllerIf, docLoader);
       
   148 	// Connect to main view signal for entry deletion.
       
   149 	connect (
       
   150 			mMainView, SIGNAL(deleteEntry(ulong)),
       
   151 			this, SLOT(deleteEntryFromView(ulong)));
       
   152 
       
   153 	// Set the main view to the window
       
   154 	hbInstance->allMainWindows().first()->addView(mMainView);
       
   155 }
       
   156 
       
   157 /*!
       
   158 	Loads the notes collection view.
       
   159  */
       
   160 void NotesViewManager::loadNotesCollectionView()
       
   161 {
       
   162 	bool loadSuccess;
       
   163 
       
   164 	// Construct the document loader instance
       
   165 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   166 
       
   167 	// Load the application xml.
       
   168 	docLoader->load(NOTES_COLLECTION_VIEW_XML, &loadSuccess);
       
   169 
       
   170 	// Find the collection view.
       
   171 	mCollectionView = static_cast<NotesCollectionView *> (
       
   172 			docLoader->findWidget(NOTES_COLLECTION_VIEW));
       
   173 	// Setup the view.
       
   174 	mCollectionView->setupView(mAppControllerIf, docLoader);
       
   175 }
       
   176 
       
   177 /*!
       
   178 	Loads the to-do view.
       
   179  */
       
   180 void NotesViewManager::loadTodoView()
       
   181 {
       
   182 
       
   183 	bool loadSuccess;
       
   184 
       
   185 	// Construct the document loader instance
       
   186 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   187 
       
   188 	// Load the application xml.
       
   189 	docLoader->load(NOTES_TODO_VIEW_XML, &loadSuccess);
       
   190 
       
   191 	// Find the to-do view.
       
   192 	mTodoView = static_cast<NotesTodoView *> (
       
   193 			docLoader->findWidget(NOTES_TODO_VIEW));
       
   194 	// Setup the view.
       
   195 	mTodoView->setupView(mAppControllerIf, docLoader);
       
   196 	// Connect to to-do view signal for entry deletion.
       
   197 	connect (
       
   198 			mTodoView, SIGNAL(deleteEntry(ulong)),
       
   199 			this, SLOT(deleteEntryFromView(ulong)));
       
   200 }
       
   201 
       
   202 /*!
       
   203 	Loads the favorites view.
       
   204  */
       
   205 void NotesViewManager::loadFavoritesView()
       
   206 {
       
   207 	bool loadSuccess;
       
   208 
       
   209 	// Construct the document loader instance
       
   210 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   211 
       
   212 	// Load the application xml.
       
   213 	docLoader->load(NOTES_FAVORITES_VIEW_XML, &loadSuccess);
       
   214 
       
   215 	// Find the favorites view.
       
   216 	mFavoriteView = static_cast<NotesFavoriteView *> (
       
   217 			docLoader->findWidget(NOTES_FAVORITES_VIEW));
       
   218 	// Setup the view.
       
   219 	mFavoriteView->setupView(mAppControllerIf, docLoader);
       
   220 
       
   221 	// Connect to favourite view signal for entry deletion.
       
   222 	connect (
       
   223 			mFavoriteView, SIGNAL(deleteEntry(ulong)),
       
   224 			this, SLOT(deleteEntryFromView(ulong)));
       
   225 }
       
   226 
       
   227 /*!
       
   228 	Loads the recent notes view.
       
   229  */
       
   230 void NotesViewManager::loadNoteView()
       
   231 {
       
   232 	bool loadSuccess;
       
   233 
       
   234 	// Construct the document loader instance
       
   235 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   236 
       
   237 	// Load the application xml.
       
   238 	docLoader->load(NOTES_NOTE_VIEW_XML, &loadSuccess);
       
   239 
       
   240 	// Find the note view.
       
   241 	mNoteView = static_cast<NotesNoteView *> (
       
   242 			docLoader->findWidget(NOTES_NOTE_VIEW));
       
   243 	// Setup the view.
       
   244 	mNoteView->setupView(mAppControllerIf, docLoader);
       
   245 
       
   246 	connect(
       
   247 			mNoteView, SIGNAL(deleteEntry(ulong)),
       
   248 			this, SLOT(deleteEntryFromView(ulong)));
       
   249 }
       
   250 
       
   251 /*!
       
   252 	 Delete the entry.
       
   253  */
       
   254 void NotesViewManager::deleteEntryFromView(ulong entryId)
       
   255 {
       
   256 	if (showDeleteConfirmationQuery(entryId)) {
       
   257 		// Delete the given note.
       
   258 		mAgendaUtil->deleteEntry(entryId);
       
   259 	}
       
   260 }
       
   261 
       
   262 /*!
       
   263 	Loads other views from the docml file.
       
   264  */
       
   265 void NotesViewManager::loadOtherViews()
       
   266 {
   127 	// Load the collection view.
   267 	// Load the collection view.
   128 	loadNotesCollectionView();
   268 	loadNotesCollectionView();
   129 	// Load the to-do view.
   269 	// Load the to-do view.
   130 	loadTodoView();
   270 	loadTodoView();
   131 	// Load the favorites view.
   271 	// Load the favorites view.
   132 	loadFavoritesView();
   272 	loadFavoritesView();
   133 	// Load the recent notes view.
   273 	// Load the recent notes view.
   134 	loadNoteView();
   274 	loadNoteView();
   135 
   275 
   136 	// Set the main view to the window
   276 	// Disconnect the signal viewReady as all the views are loaded.
   137 	hbInstance->allMainWindows().first()->addView(mMainView);
   277 	HbMainWindow *window = hbInstance->allMainWindows().first();
   138 
   278 	disconnect(
   139 	qDebug() << "notes: NotesViewManager::loadViews <--";
   279 			window, SIGNAL(viewReady()),
   140 }
   280 			this, SLOT(loadOtherViews()));
   141 
   281 }
   142 /*!
   282 
   143 	Loads the notes main view.
   283 /* !
   144  */
   284 	Show the delete confirmation query.
   145 void NotesViewManager::loadNotesMainView()
   285  */
   146 {
   286 bool NotesViewManager::showDeleteConfirmationQuery(ulong noteId)
   147 	qDebug() << "notes: NotesViewManager::loadNotesMainView -->";
   287 {
   148 
   288 	bool retValue(false);
   149 	bool loadSuccess;
   289 
   150 
   290 	HbMessageBox confirmationQuery(HbMessageBox::MessageTypeQuestion);
   151 	// Construct the document loader instance
   291 	confirmationQuery.setDismissPolicy(HbDialog::NoDismiss);
   152 	NotesDocLoader *docLoader = new NotesDocLoader();
   292 	confirmationQuery.setTimeout(HbDialog::NoTimeout);
   153 
   293 	confirmationQuery.setIconVisible(true);
   154 	// Load the application xml.
   294 
   155 	docLoader->load(NOTES_MAIN_VIEW_XML, &loadSuccess);
   295 	QString displayText;
   156 	Q_ASSERT_X(
   296 	QString x;
   157 			loadSuccess,
   297 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   158 			"notesviewmanager.cpp",
   298 	if (AgendaEntry::TypeTodo == entry.type()) {
   159 			"Unable to load the main view app xml");
   299 		displayText += hbTrId("txt_notes_info_delete_todo_note");
   160 
   300 	} else {
   161 	// Find the main view.
   301 		displayText += hbTrId("txt_notes_info_delete_note");
   162 	mMainView = static_cast<NotesMainView *> (
   302 	}
   163 			docLoader->findWidget(NOTES_MAIN_VIEW));
   303 
   164 	Q_ASSERT_X(
   304 	confirmationQuery.setText(displayText);
   165 			mMainView, "notesviewmanager.cpp", "Unable to find the main view.");
   305 
   166 	// Setup the view.
   306 	confirmationQuery.setPrimaryAction(new HbAction(
   167 	mMainView->setupView(mAppControllerIf, docLoader);
   307 	    hbTrId("txt_notes_button_dialog_delete"), &confirmationQuery));
   168 
   308 	confirmationQuery.setSecondaryAction(new HbAction(
   169 	qDebug() << "notes: NotesViewManager::loadNotesMainView <--";
   309 	    hbTrId("txt_common_button_cancel"), &confirmationQuery));
   170 }
   310 	HbAction *selected = confirmationQuery.exec();
   171 
   311 	if (selected == confirmationQuery.primaryAction()) {
   172 /*!
   312 		retValue = true;
   173 	Loads the notes collection view.
   313 	}
   174  */
   314 
   175 void NotesViewManager::loadNotesCollectionView()
   315 	return retValue;
   176 {
   316 }
   177 	qDebug("notes: NotesViewManager::loadNotesCollectionView -- Entry");
       
   178 
       
   179 	bool loadSuccess;
       
   180 
       
   181 	// Construct the document loader instance
       
   182 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   183 
       
   184 	// Load the application xml.
       
   185 	docLoader->load(NOTES_COLLECTION_VIEW_XML, &loadSuccess);
       
   186 
       
   187 	// Find the collection view.
       
   188 	mCollectionView = static_cast<NotesCollectionView *> (
       
   189 			docLoader->findWidget(NOTES_COLLECTION_VIEW));
       
   190 	// Setup the view.
       
   191 	mCollectionView->setupView(mAppControllerIf, docLoader);
       
   192 
       
   193 	qDebug() << "notes: NotesViewManager::loadNotesCollectionView <--";
       
   194 }
       
   195 
       
   196 /*!
       
   197 	Loads the to-do view.
       
   198  */
       
   199 void NotesViewManager::loadTodoView()
       
   200 {
       
   201 	qDebug("notes: NotesViewManager::loadTodoView -->");
       
   202 
       
   203 	bool loadSuccess;
       
   204 
       
   205 	// Construct the document loader instance
       
   206 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   207 
       
   208 	// Load the application xml.
       
   209 	docLoader->load(NOTES_TODO_VIEW_XML, &loadSuccess);
       
   210 
       
   211 	// Find the to-do view.
       
   212 	mTodoView = static_cast<NotesTodoView *> (
       
   213 			docLoader->findWidget(NOTES_TODO_VIEW));
       
   214 	// Setup the view.
       
   215 	mTodoView->setupView(mAppControllerIf, docLoader);
       
   216 
       
   217 	qDebug() << "notes: NotesViewManager::loadTodoView <--";
       
   218 }
       
   219 
       
   220 /*!
       
   221 	Loads the favorites view.
       
   222  */
       
   223 void NotesViewManager::loadFavoritesView()
       
   224 {
       
   225 	qDebug("notes: NotesViewManager::loadFavoritesView -->");
       
   226 
       
   227 	bool loadSuccess;
       
   228 
       
   229 	// Construct the document loader instance
       
   230 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   231 
       
   232 	// Load the application xml.
       
   233 	docLoader->load(NOTES_FAVORITES_VIEW_XML, &loadSuccess);
       
   234 
       
   235 	// Find the favorites view.
       
   236 	mFavoriteView = static_cast<NotesFavoriteView *> (
       
   237 			docLoader->findWidget(NOTES_FAVORITES_VIEW));
       
   238 	// Setup the view.
       
   239 	mFavoriteView->setupView(mAppControllerIf, docLoader);
       
   240 
       
   241 	qDebug() << "notes: NotesViewManager::loadFavoritesView <--";
       
   242 }
       
   243 
       
   244 /*!
       
   245 	Loads the recent notes view.
       
   246  */
       
   247 void NotesViewManager::loadNoteView()
       
   248 {
       
   249 	qDebug("notes: NotesViewManager::loadNoteView -->");
       
   250 
       
   251 	bool loadSuccess;
       
   252 
       
   253 	// Construct the document loader instance
       
   254 	NotesDocLoader *docLoader = new NotesDocLoader();
       
   255 
       
   256 	// Load the application xml.
       
   257 	docLoader->load(NOTES_NOTE_VIEW_XML, &loadSuccess);
       
   258 
       
   259 	// Find the note view.
       
   260 	mNoteView = static_cast<NotesNoteView *> (
       
   261 			docLoader->findWidget(NOTES_NOTE_VIEW));
       
   262 	// Setup the view.
       
   263 	mNoteView->setupView(mAppControllerIf, docLoader);
       
   264 
       
   265 	qDebug() << "notes: NotesViewManager::loadNoteView <--";
       
   266 }
       
   267 
       
   268 // End of file	--Don't remove this.
   317 // End of file	--Don't remove this.