notes/notesui/notesviewmanager/src/notesviewmanager.cpp
changeset 26 a949c2543c15
parent 23 fd30d51f876b
child 49 5de72ea7a065
equal deleted inserted replaced
23:fd30d51f876b 26:a949c2543c15
    57 {
    57 {
    58 	HbMainWindow *window = hbInstance->allMainWindows().first();
    58 	HbMainWindow *window = hbInstance->allMainWindows().first();
    59 
    59 
    60 	mAgendaUtil = mAppControllerIf.agendaUtil();
    60 	mAgendaUtil = mAppControllerIf.agendaUtil();
    61 
    61 
       
    62 	connect(
       
    63 			mAgendaUtil, SIGNAL(instanceViewCreationCompleted(int)),
       
    64 			this,SLOT(handleInstanceViewCreationCompleted(int)));
       
    65 
    62 	// Load the main view at the start up.
    66 	// Load the main view at the start up.
    63 	loadNotesMainView();
    67 	loadNotesMainView();
    64 
    68 
    65 	// Delay loading of other views till main view is loaded.
    69 	// Delay loading of other views till main view is loaded.
    66 	connect(
    70 	connect(
   247 			mNoteView, SIGNAL(deleteEntry(ulong)),
   251 			mNoteView, SIGNAL(deleteEntry(ulong)),
   248 			this, SLOT(deleteEntryFromView(ulong)));
   252 			this, SLOT(deleteEntryFromView(ulong)));
   249 }
   253 }
   250 
   254 
   251 /*!
   255 /*!
   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.
   256 	Loads other views from the docml file.
   264  */
   257  */
   265 void NotesViewManager::loadOtherViews()
   258 void NotesViewManager::loadOtherViews()
   266 {
   259 {
       
   260 	mMainView->setupAfterViewReady();
       
   261 
   267 	// Load the collection view.
   262 	// Load the collection view.
   268 	loadNotesCollectionView();
   263 	loadNotesCollectionView();
   269 	// Load the to-do view.
   264 	// Load the to-do view.
   270 	loadTodoView();
   265 	loadTodoView();
   271 	// Load the favorites view.
   266 	// Load the favorites view.
   278 	disconnect(
   273 	disconnect(
   279 			window, SIGNAL(viewReady()),
   274 			window, SIGNAL(viewReady()),
   280 			this, SLOT(loadOtherViews()));
   275 			this, SLOT(loadOtherViews()));
   281 }
   276 }
   282 
   277 
   283 /* !
   278 /*!
   284 	Show the delete confirmation query.
   279 	 Delete the entry.
   285  */
   280  */
   286 bool NotesViewManager::showDeleteConfirmationQuery(ulong noteId)
   281 void NotesViewManager::deleteEntryFromView(ulong entryId)
   287 {
   282 {
   288 	bool retValue(false);
   283 	mEntryId = entryId;
   289 
   284 	HbMessageBox *confirmationQuery = new HbMessageBox(
   290 	HbMessageBox confirmationQuery(HbMessageBox::MessageTypeQuestion);
   285 			HbMessageBox::MessageTypeQuestion);
   291 	confirmationQuery.setDismissPolicy(HbDialog::NoDismiss);
   286 	confirmationQuery->setDismissPolicy(HbDialog::NoDismiss);
   292 	confirmationQuery.setTimeout(HbDialog::NoTimeout);
   287 	confirmationQuery->setTimeout(HbDialog::NoTimeout);
   293 	confirmationQuery.setIconVisible(true);
   288 	confirmationQuery->setIconVisible(true);
   294 
   289 
   295 	QString displayText;
   290 	QString displayText;
   296 	QString x;
   291 	QString x;
   297 	AgendaEntry entry = mAgendaUtil->fetchById(noteId);
   292 	AgendaEntry entry = mAgendaUtil->fetchById(entryId);
   298 	if (AgendaEntry::TypeTodo == entry.type()) {
   293 	if (AgendaEntry::TypeTodo == entry.type()) {
   299 		displayText += hbTrId("txt_notes_info_delete_todo_note");
   294 		displayText += hbTrId("txt_notes_info_delete_todo_note");
   300 	} else {
   295 	} else {
   301 		displayText += hbTrId("txt_notes_info_delete_note");
   296 		displayText += hbTrId("txt_notes_info_delete_note");
   302 	}
   297 	}
   303 
   298 
   304 	confirmationQuery.setText(displayText);
   299 	confirmationQuery->setText(displayText);
   305 
   300 
   306 	confirmationQuery.setPrimaryAction(new HbAction(
   301 	// Remove the default actions.
   307 	    hbTrId("txt_notes_button_dialog_delete"), &confirmationQuery));
   302 	QList<QAction *> defaultActions = confirmationQuery->actions();
   308 	confirmationQuery.setSecondaryAction(new HbAction(
   303 	for (int index=0;index<defaultActions.count();index++) {
   309 	    hbTrId("txt_common_button_cancel"), &confirmationQuery));
   304 		confirmationQuery->removeAction(defaultActions[index]);
   310 	HbAction *selected = confirmationQuery.exec();
       
   311 	if (selected == confirmationQuery.primaryAction()) {
       
   312 		retValue = true;
       
   313 	}
   305 	}
   314 
   306 	defaultActions.clear();
   315 	return retValue;
   307 
       
   308 	// Add delete and cancel actions
       
   309 	mDeleteAction = new HbAction(hbTrId("txt_notes_button_dialog_delete"));
       
   310 	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   311 
       
   312 	confirmationQuery->addAction(mDeleteAction);
       
   313 	confirmationQuery->addAction(mCancelAction);
       
   314 
       
   315 	confirmationQuery->open(this, SLOT(selectedAction(HbAction*)));
       
   316 }
       
   317 
       
   318 /*!
       
   319 	Slot to handle the delete action
       
   320  */
       
   321 void NotesViewManager::selectedAction(HbAction *action)
       
   322 {
       
   323 	if (action == mDeleteAction) {
       
   324 		// Delete the given note.
       
   325 		mAgendaUtil->deleteEntry(mEntryId);
       
   326 	}
       
   327 }
       
   328 
       
   329 /*!
       
   330 	Slot to handle instance view creation complete.
       
   331  */
       
   332 void NotesViewManager::handleInstanceViewCreationCompleted(int status)
       
   333 {
       
   334 	Q_UNUSED(status)
       
   335 
       
   336 	// Update the title for main view.
       
   337 	mMainView->updateTitle();
       
   338 
       
   339 	// Populate collections view.
       
   340 	mCollectionView->populateListView();
       
   341 
       
   342 	// Update the title for to-do view.
       
   343 	mTodoView->updateTitle();
   316 }
   344 }
   317 // End of file	--Don't remove this.
   345 // End of file	--Don't remove this.