clock/clockui/clockcityselectionlist/src/clockcityselectionlist_p.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 51 0b38fc5b94c6
--- a/clock/clockui/clockcityselectionlist/src/clockcityselectionlist_p.cpp	Mon May 03 12:30:32 2010 +0300
+++ b/clock/clockui/clockcityselectionlist/src/clockcityselectionlist_p.cpp	Mon Jun 28 15:22:02 2010 +0530
@@ -40,7 +40,7 @@
 #include "clockcityselectionlist.h"
 #include "clockcitylistproxymodel.h"
 #include "clockcityselectionlistcommon.h"
-#include "clockcityselectionlistprototype.h"
+
 #include "timezoneclient.h"
 #include "clockdatatypes.h"
 
@@ -67,7 +67,7 @@
 
 	mClient = client;
 	if (!mClient) {
-		mClient = new TimezoneClient(this);
+		mClient = TimezoneClient::getInstance();
 		mOwnsClient = true;
 	}
 }
@@ -78,7 +78,7 @@
 ClockCitySelectionListPrivate::~ClockCitySelectionListPrivate()
 {
 	if (mOwnsClient) {
-		delete mClient;
+		mClient->deleteInstance();
 	}
 	if (mLoader) {
 		mLoader->reset();
@@ -103,7 +103,7 @@
 void ClockCitySelectionListPrivate::populateListModel()
 {
 	// First get the data from the timezone client.
-	QList<LocationInfo> infoList = mClient->getLocations();
+	QList<LocationInfo> &infoList = mClient->getLocations();
 
 	// Sanity check.
 	if (!mListModel) {
@@ -123,6 +123,7 @@
 		displayString += info.cityName;
 		displayString += ", ";
 		displayString += info.countryName;
+		mListModel->setData(index, displayString, Qt::DisplayRole);
 		mListModel->setData(index, displayString, Qt::UserRole + 100);
 
 		// Now save the timezone and city group ids.
@@ -135,6 +136,9 @@
 		mListModel->setData(
 				index, info.countryName, Qt::UserRole + 104);
 	}
+
+	// Cleanup.
+	infoList.clear();
 }
 
 /*!
@@ -241,6 +245,7 @@
 	mAddOwnCityDialog = new HbDialog;
 	mAddOwnCityDialog->setTimeout(HbDialog::NoTimeout);
 	mAddOwnCityDialog->setDismissPolicy(HbDialog::NoDismiss);
+	mAddOwnCityDialog->setAttribute(Qt::WA_DeleteOnClose, true);
 
 	// Set the heading text
 	HbLabel *titlelabel = new HbLabel(hbTrId("txt_clk_opt_add_own_city"));
@@ -273,20 +278,14 @@
 	widget->setLayout(layout);
 
 	// Add actions to the dialog
-	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
-	mAddOwnCityDialog->setPrimaryAction(okAction);
-	connect(
-			okAction, SIGNAL(triggered()),
-			this, SLOT(handleOkAction()));
+	mOkAction = new HbAction(hbTrId("txt_common_button_ok"));
+	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
 
-	HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
-	mAddOwnCityDialog->setSecondaryAction(cancelAction);
-	connect(
-			cancelAction, SIGNAL(triggered()),
-			this, SLOT(handleCancelAction()));
+	mAddOwnCityDialog->addAction(mOkAction);
+	mAddOwnCityDialog->addAction(mCancelAction);
 
 	mAddOwnCityDialog->setContentWidget(widget);
-	mAddOwnCityDialog->exec();
+	mAddOwnCityDialog->open(this, SLOT(selectedAction(HbAction*)));
 }
 
 /*!
@@ -321,21 +320,6 @@
 			populateListModel();
 		}
 	}
-
-	// Close the popup
-	handleCancelAction();
-}
-
-/*!
-	Handles Cancel action of add own city dialog
- */
-void ClockCitySelectionListPrivate::handleCancelAction()
-{
-	// Close the dialog.
-	if (mAddOwnCityDialog) {
-		mAddOwnCityDialog->close();
-		mAddOwnCityDialog->deleteLater();
-	}
 }
 
 /*!
@@ -364,6 +348,15 @@
 }
 
 /*!
+	Slot to handle the selected action
+ */
+void ClockCitySelectionListPrivate::selectedAction(HbAction *action)
+{
+	if (action==mOkAction) {
+		handleOkAction();
+	}
+}
+/*!
 	Displays the city selection list.
  */
 void ClockCitySelectionListPrivate::showCityList()
@@ -399,7 +392,7 @@
 	connect(
 			mSearchBox, SIGNAL(criteriaChanged(QString)),
 			this, SLOT(updateSearchCriteria(QString)));
-	
+
 	// Construct the source model.
 	if (!mListModel) {
 		mListModel = new QStandardItemModel(0, 1, this);
@@ -410,15 +403,6 @@
 	mProxyModel->setSourceModel(mListModel);
 	mProxyModel->setFilterRole(Qt::UserRole + 100);
 
-	// Construct the custom list item prototype.
-	ClockCitySelectionListPrototype *prototype =
-			new ClockCitySelectionListPrototype;
-
-	// Loader the custom list view layout.
-	HbStyleLoader::registerFilePath(":/style/");
-	mListView->setLayoutName("cityselectionlist-default");
-	mListView->setItemPrototype(prototype);
-
 	// Construct the model for the list.
 	QTimer::singleShot(1, this, SLOT(populateListModel()));
 
@@ -441,7 +425,7 @@
 
 	// Add the view to the main window and show it.
 	HbMainWindow *window = hbInstance->allMainWindows().at(0);
-	mBackAction = new HbAction(Hb::BackAction, this);
+	mBackAction = new HbAction(Hb::BackNaviAction, this);
 	mView->setNavigationAction(mBackAction);
 	connect(
 			mBackAction, SIGNAL(triggered()),