clock/clockui/clockcityselectionlist/src/clockcityselectionlist_p.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 51 0b38fc5b94c6
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    38 // User includes
    38 // User includes
    39 #include "clockcityselectionlist_p.h"
    39 #include "clockcityselectionlist_p.h"
    40 #include "clockcityselectionlist.h"
    40 #include "clockcityselectionlist.h"
    41 #include "clockcitylistproxymodel.h"
    41 #include "clockcitylistproxymodel.h"
    42 #include "clockcityselectionlistcommon.h"
    42 #include "clockcityselectionlistcommon.h"
    43 #include "clockcityselectionlistprototype.h"
    43 
    44 #include "timezoneclient.h"
    44 #include "timezoneclient.h"
    45 #include "clockdatatypes.h"
    45 #include "clockdatatypes.h"
    46 
    46 
    47 /*!
    47 /*!
    48 	\class ClockCitySelectionListPrivate
    48 	\class ClockCitySelectionListPrivate
    65 	// First get the q-pointer.
    65 	// First get the q-pointer.
    66 	q_ptr = static_cast<ClockCitySelectionList *> (parent);
    66 	q_ptr = static_cast<ClockCitySelectionList *> (parent);
    67 
    67 
    68 	mClient = client;
    68 	mClient = client;
    69 	if (!mClient) {
    69 	if (!mClient) {
    70 		mClient = new TimezoneClient(this);
    70 		mClient = TimezoneClient::getInstance();
    71 		mOwnsClient = true;
    71 		mOwnsClient = true;
    72 	}
    72 	}
    73 }
    73 }
    74 
    74 
    75 /*!
    75 /*!
    76 	Destructor.
    76 	Destructor.
    77  */
    77  */
    78 ClockCitySelectionListPrivate::~ClockCitySelectionListPrivate()
    78 ClockCitySelectionListPrivate::~ClockCitySelectionListPrivate()
    79 {
    79 {
    80 	if (mOwnsClient) {
    80 	if (mOwnsClient) {
    81 		delete mClient;
    81 		mClient->deleteInstance();
    82 	}
    82 	}
    83 	if (mLoader) {
    83 	if (mLoader) {
    84 		mLoader->reset();
    84 		mLoader->reset();
    85 		delete mLoader;
    85 		delete mLoader;
    86 		mLoader = 0;
    86 		mLoader = 0;
   101 	Populates the list model by getting the data from timezone client.
   101 	Populates the list model by getting the data from timezone client.
   102  */
   102  */
   103 void ClockCitySelectionListPrivate::populateListModel()
   103 void ClockCitySelectionListPrivate::populateListModel()
   104 {
   104 {
   105 	// First get the data from the timezone client.
   105 	// First get the data from the timezone client.
   106 	QList<LocationInfo> infoList = mClient->getLocations();
   106 	QList<LocationInfo> &infoList = mClient->getLocations();
   107 
   107 
   108 	// Sanity check.
   108 	// Sanity check.
   109 	if (!mListModel) {
   109 	if (!mListModel) {
   110 		mListModel = new QStandardItemModel(0, 1, this);
   110 		mListModel = new QStandardItemModel(0, 1, this);
   111 	}
   111 	}
   121 		LocationInfo info = infoList.at(iter);
   121 		LocationInfo info = infoList.at(iter);
   122 		QString displayString;
   122 		QString displayString;
   123 		displayString += info.cityName;
   123 		displayString += info.cityName;
   124 		displayString += ", ";
   124 		displayString += ", ";
   125 		displayString += info.countryName;
   125 		displayString += info.countryName;
       
   126 		mListModel->setData(index, displayString, Qt::DisplayRole);
   126 		mListModel->setData(index, displayString, Qt::UserRole + 100);
   127 		mListModel->setData(index, displayString, Qt::UserRole + 100);
   127 
   128 
   128 		// Now save the timezone and city group ids.
   129 		// Now save the timezone and city group ids.
   129 		mListModel->setData(
   130 		mListModel->setData(
   130 				index, QVariant(info.timezoneId), Qt::UserRole + 101);
   131 				index, QVariant(info.timezoneId), Qt::UserRole + 101);
   133 		mListModel->setData(
   134 		mListModel->setData(
   134 				index, info.cityName, Qt::UserRole + 103);
   135 				index, info.cityName, Qt::UserRole + 103);
   135 		mListModel->setData(
   136 		mListModel->setData(
   136 				index, info.countryName, Qt::UserRole + 104);
   137 				index, info.countryName, Qt::UserRole + 104);
   137 	}
   138 	}
       
   139 
       
   140 	// Cleanup.
       
   141 	infoList.clear();
   138 }
   142 }
   139 
   143 
   140 /*!
   144 /*!
   141 	Slot to handle the case when a list item is activated. Here we return the
   145 	Slot to handle the case when a list item is activated. Here we return the
   142 	city selected by the user. We emit a signal notifying this event and close
   146 	city selected by the user. We emit a signal notifying this event and close
   239 
   243 
   240 	// Create the dialog.
   244 	// Create the dialog.
   241 	mAddOwnCityDialog = new HbDialog;
   245 	mAddOwnCityDialog = new HbDialog;
   242 	mAddOwnCityDialog->setTimeout(HbDialog::NoTimeout);
   246 	mAddOwnCityDialog->setTimeout(HbDialog::NoTimeout);
   243 	mAddOwnCityDialog->setDismissPolicy(HbDialog::NoDismiss);
   247 	mAddOwnCityDialog->setDismissPolicy(HbDialog::NoDismiss);
       
   248 	mAddOwnCityDialog->setAttribute(Qt::WA_DeleteOnClose, true);
   244 
   249 
   245 	// Set the heading text
   250 	// Set the heading text
   246 	HbLabel *titlelabel = new HbLabel(hbTrId("txt_clk_opt_add_own_city"));
   251 	HbLabel *titlelabel = new HbLabel(hbTrId("txt_clk_opt_add_own_city"));
   247 	mAddOwnCityDialog->setHeadingWidget(titlelabel);
   252 	mAddOwnCityDialog->setHeadingWidget(titlelabel);
   248 
   253 
   271 
   276 
   272 	QGraphicsWidget *widget = new QGraphicsWidget();
   277 	QGraphicsWidget *widget = new QGraphicsWidget();
   273 	widget->setLayout(layout);
   278 	widget->setLayout(layout);
   274 
   279 
   275 	// Add actions to the dialog
   280 	// Add actions to the dialog
   276 	HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   281 	mOkAction = new HbAction(hbTrId("txt_common_button_ok"));
   277 	mAddOwnCityDialog->setPrimaryAction(okAction);
   282 	mCancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
   278 	connect(
   283 
   279 			okAction, SIGNAL(triggered()),
   284 	mAddOwnCityDialog->addAction(mOkAction);
   280 			this, SLOT(handleOkAction()));
   285 	mAddOwnCityDialog->addAction(mCancelAction);
   281 
       
   282 	HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   283 	mAddOwnCityDialog->setSecondaryAction(cancelAction);
       
   284 	connect(
       
   285 			cancelAction, SIGNAL(triggered()),
       
   286 			this, SLOT(handleCancelAction()));
       
   287 
   286 
   288 	mAddOwnCityDialog->setContentWidget(widget);
   287 	mAddOwnCityDialog->setContentWidget(widget);
   289 	mAddOwnCityDialog->exec();
   288 	mAddOwnCityDialog->open(this, SLOT(selectedAction(HbAction*)));
   290 }
   289 }
   291 
   290 
   292 /*!
   291 /*!
   293 	Hanldes Ok action of add own city dialog
   292 	Hanldes Ok action of add own city dialog
   294  */
   293  */
   319 		if (!addedCity.cityName.compare(cityName)) {
   318 		if (!addedCity.cityName.compare(cityName)) {
   320 			// Refresh the city list.
   319 			// Refresh the city list.
   321 			populateListModel();
   320 			populateListModel();
   322 		}
   321 		}
   323 	}
   322 	}
   324 
       
   325 	// Close the popup
       
   326 	handleCancelAction();
       
   327 }
       
   328 
       
   329 /*!
       
   330 	Handles Cancel action of add own city dialog
       
   331  */
       
   332 void ClockCitySelectionListPrivate::handleCancelAction()
       
   333 {
       
   334 	// Close the dialog.
       
   335 	if (mAddOwnCityDialog) {
       
   336 		mAddOwnCityDialog->close();
       
   337 		mAddOwnCityDialog->deleteLater();
       
   338 	}
       
   339 }
   323 }
   340 
   324 
   341 /*!
   325 /*!
   342 	Handles the selection of time zone offset.
   326 	Handles the selection of time zone offset.
   343 	Populates the country list.
   327 	Populates the country list.
   362 	mCountryComboBox->setItems(countries);
   346 	mCountryComboBox->setItems(countries);
   363 	}
   347 	}
   364 }
   348 }
   365 
   349 
   366 /*!
   350 /*!
       
   351 	Slot to handle the selected action
       
   352  */
       
   353 void ClockCitySelectionListPrivate::selectedAction(HbAction *action)
       
   354 {
       
   355 	if (action==mOkAction) {
       
   356 		handleOkAction();
       
   357 	}
       
   358 }
       
   359 /*!
   367 	Displays the city selection list.
   360 	Displays the city selection list.
   368  */
   361  */
   369 void ClockCitySelectionListPrivate::showCityList()
   362 void ClockCitySelectionListPrivate::showCityList()
   370 {
   363 {
   371 	// Construct the document loader.
   364 	// Construct the document loader.
   397 	mSearchBox->setSearchOptionsEnabled(false);
   390 	mSearchBox->setSearchOptionsEnabled(false);
   398 
   391 
   399 	connect(
   392 	connect(
   400 			mSearchBox, SIGNAL(criteriaChanged(QString)),
   393 			mSearchBox, SIGNAL(criteriaChanged(QString)),
   401 			this, SLOT(updateSearchCriteria(QString)));
   394 			this, SLOT(updateSearchCriteria(QString)));
   402 	
   395 
   403 	// Construct the source model.
   396 	// Construct the source model.
   404 	if (!mListModel) {
   397 	if (!mListModel) {
   405 		mListModel = new QStandardItemModel(0, 1, this);
   398 		mListModel = new QStandardItemModel(0, 1, this);
   406 	}
   399 	}
   407 	// Construct the proxy model.
   400 	// Construct the proxy model.
   408 	mProxyModel = new ClockCityListProxyModel(this);
   401 	mProxyModel = new ClockCityListProxyModel(this);
   409 	mProxyModel->setDynamicSortFilter(true);
   402 	mProxyModel->setDynamicSortFilter(true);
   410 	mProxyModel->setSourceModel(mListModel);
   403 	mProxyModel->setSourceModel(mListModel);
   411 	mProxyModel->setFilterRole(Qt::UserRole + 100);
   404 	mProxyModel->setFilterRole(Qt::UserRole + 100);
   412 
   405 
   413 	// Construct the custom list item prototype.
       
   414 	ClockCitySelectionListPrototype *prototype =
       
   415 			new ClockCitySelectionListPrototype;
       
   416 
       
   417 	// Loader the custom list view layout.
       
   418 	HbStyleLoader::registerFilePath(":/style/");
       
   419 	mListView->setLayoutName("cityselectionlist-default");
       
   420 	mListView->setItemPrototype(prototype);
       
   421 
       
   422 	// Construct the model for the list.
   406 	// Construct the model for the list.
   423 	QTimer::singleShot(1, this, SLOT(populateListModel()));
   407 	QTimer::singleShot(1, this, SLOT(populateListModel()));
   424 
   408 
   425 	// Set the model to the list.
   409 	// Set the model to the list.
   426 	mListView->setModel(mProxyModel);
   410 	mListView->setModel(mProxyModel);
   439 			mAddOwnCityAction, SIGNAL(triggered()),
   423 			mAddOwnCityAction, SIGNAL(triggered()),
   440 			this, SLOT(handleAddOwnCityAction()));
   424 			this, SLOT(handleAddOwnCityAction()));
   441 
   425 
   442 	// Add the view to the main window and show it.
   426 	// Add the view to the main window and show it.
   443 	HbMainWindow *window = hbInstance->allMainWindows().at(0);
   427 	HbMainWindow *window = hbInstance->allMainWindows().at(0);
   444 	mBackAction = new HbAction(Hb::BackAction, this);
   428 	mBackAction = new HbAction(Hb::BackNaviAction, this);
   445 	mView->setNavigationAction(mBackAction);
   429 	mView->setNavigationAction(mBackAction);
   446 	connect(
   430 	connect(
   447 			mBackAction, SIGNAL(triggered()),
   431 			mBackAction, SIGNAL(triggered()),
   448 			this, SLOT(handleBackAction()));
   432 			this, SLOT(handleBackAction()));
   449 
   433