clock/clockui/clockviews/src/clockworldview.cpp
changeset 58 ef813d54df51
parent 49 5de72ea7a065
child 68 a5a1242fd2e8
equal deleted inserted replaced
50:579cc610882e 58:ef813d54df51
    34 #include "clockcommon.h"
    34 #include "clockcommon.h"
    35 #include "settingsutility.h"
    35 #include "settingsutility.h"
    36 #include "timezoneclient.h"
    36 #include "timezoneclient.h"
    37 #include "clockcityselectionlist.h"
    37 #include "clockcityselectionlist.h"
    38 #include "clockhomecityitem.h"
    38 #include "clockhomecityitem.h"
       
    39 #include "OstTraceDefinitions.h"
       
    40 #ifdef OST_TRACE_COMPILER_IN_USE
       
    41 #include "clockworldviewTraces.h"
       
    42 #endif
       
    43 
    39 
    44 
    40 /*!
    45 /*!
    41 	\class ClockWorldView
    46 	\class ClockWorldView
    42 
    47 
    43 	The world clock view of the clock application.
    48 	The world clock view of the clock application.
    50  */
    55  */
    51 ClockWorldView::ClockWorldView(QGraphicsItem *parent)
    56 ClockWorldView::ClockWorldView(QGraphicsItem *parent)
    52 :HbView(parent),
    57 :HbView(parent),
    53  mSelectedItem(-1)
    58  mSelectedItem(-1)
    54 {
    59 {
       
    60 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_CLOCKWORLDVIEW_ENTRY );
    55 	// Timer for updating list data upon time change/update.
    61 	// Timer for updating list data upon time change/update.
    56 	mRefreshTimer = new QTimer();
    62 	mRefreshTimer = new QTimer();
    57 	connect(
    63 	connect(
    58 			mRefreshTimer, SIGNAL(timeout()),
    64 			mRefreshTimer, SIGNAL(timeout()),
    59 			this, SLOT(refreshCityList()));
    65 			this, SLOT(refreshCityList()));
    60 
    66 
    61 	// Create the model.
    67 	// Create the model.
    62 	mCityListModel = new QStandardItemModel();
    68 	mCityListModel = new QStandardItemModel();
       
    69 	OstTraceFunctionExit0( CLOCKWORLDVIEW_CLOCKWORLDVIEW_EXIT );
    63 }
    70 }
    64 
    71 
    65 /*!
    72 /*!
    66 	Destructor.
    73 	Destructor.
    67  */
    74  */
    68 ClockWorldView::~ClockWorldView()
    75 ClockWorldView::~ClockWorldView()
    69 {
    76 {
       
    77 	OstTraceFunctionEntry0( DUP1_CLOCKWORLDVIEW_CLOCKWORLDVIEW_ENTRY );
    70 	if (mDocLoader) {
    78 	if (mDocLoader) {
    71 		delete mDocLoader;
    79 		delete mDocLoader;
    72 		mDocLoader = 0;
    80 		mDocLoader = 0;
    73 	}
    81 	}
    74 	if(mCityListModel){
    82 	if(mCityListModel){
    76 	}
    84 	}
    77 	
    85 	
    78 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.css");
    86 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.css");
    79 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.widgetml");
    87 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.widgetml");
    80 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem_color.css");
    88 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem_color.css");
       
    89 	OstTraceFunctionExit0( DUP1_CLOCKWORLDVIEW_CLOCKWORLDVIEW_EXIT );
    81 }
    90 }
    82 
    91 
    83 /*!
    92 /*!
    84 	Called by the ClockViewManager after loading the view from the docml.
    93 	Called by the ClockViewManager after loading the view from the docml.
    85 	The initializaion/setup of the view is done here.
    94 	The initializaion/setup of the view is done here.
    89  */
    98  */
    90 void ClockWorldView::setupView(
    99 void ClockWorldView::setupView(
    91 		ClockAppControllerIf &controllerIf,
   100 		ClockAppControllerIf &controllerIf,
    92 		ClockDocLoader *docLoader)
   101 		ClockDocLoader *docLoader)
    93 {
   102 {
       
   103 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_SETUPVIEW_ENTRY );
    94 	mDocLoader = docLoader;
   104 	mDocLoader = docLoader;
    95 	mAppControllerIf = &controllerIf;
   105 	mAppControllerIf = &controllerIf;
    96 
   106 
    97 	mTimezoneClient = controllerIf.timezoneClient();
   107 	mTimezoneClient = controllerIf.timezoneClient();
    98 	mSettingsUtility = controllerIf.settingsUtility();
   108 	mSettingsUtility = controllerIf.settingsUtility();
   129 	mCityListView = qobject_cast<HbListView *> (
   139 	mCityListView = qobject_cast<HbListView *> (
   130 			mDocLoader->findWidget(CLOCK_WORLD_CITYLIST));
   140 			mDocLoader->findWidget(CLOCK_WORLD_CITYLIST));
   131 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.css");
   141 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.css");
   132 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.widgetml");
   142 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.widgetml");
   133 	HbStyleLoader::registerFilePath(":/style/hblistviewitem_color.css");
   143 	HbStyleLoader::registerFilePath(":/style/hblistviewitem_color.css");
   134 	mCityListView->setLayoutName("citylist-portrait");
   144 	mCityListView->setLayoutName("citylist");
   135 	mCityListView->setModel(mCityListModel);
   145 	mCityListView->setModel(mCityListModel);
   136 	
   146 	
   137 	// Get the toolbar/menu actions.
   147 	// Get the toolbar/menu actions.
   138 	mAddCityAction = static_cast<HbAction *> (
   148 	mAddCityAction = static_cast<HbAction *> (
   139 			mDocLoader->findObject("addCityAction"));
   149 			mDocLoader->findObject("addCityAction"));
   187 	// Check for disabling of addCityAction in view toolbar.
   197 	// Check for disabling of addCityAction in view toolbar.
   188 	if ((KMaximumCityListCount-1) == mCityInfoList.count()) {
   198 	if ((KMaximumCityListCount-1) == mCityInfoList.count()) {
   189 		mAddCityAction->setEnabled(false);
   199 		mAddCityAction->setEnabled(false);
   190 		mAddCityMenuAction->setVisible(false);
   200 		mAddCityMenuAction->setVisible(false);
   191 	}
   201 	}
       
   202 	OstTraceFunctionExit0( CLOCKWORLDVIEW_SETUPVIEW_EXIT );
   192 }
   203 }
   193 
   204 
   194 /*!
   205 /*!
   195 	Refreshes the data in the city list.
   206 	Refreshes the data in the city list.
   196  */
   207  */
   197 void ClockWorldView::refreshCityList()
   208 void ClockWorldView::refreshCityList()
   198 {
   209 {
       
   210 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_REFRESHCITYLIST_ENTRY );
   199 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   211 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   200 	int cityInfoCount = mCityInfoList.count();
   212 	int cityInfoCount = mCityInfoList.count();
   201 
   213 
   202 	if (cityInfoCount) {
   214 	if (cityInfoCount) {
   203 		QStandardItem *item = 0;
   215 		QStandardItem *item = 0;
   212 		}
   224 		}
   213 
   225 
   214 		// Start the timer again for one minute.
   226 		// Start the timer again for one minute.
   215 		QTimer::singleShot(60 * 1000, this, SLOT(refreshCityList()));
   227 		QTimer::singleShot(60 * 1000, this, SLOT(refreshCityList()));
   216 	}
   228 	}
       
   229 	OstTraceFunctionExit0( CLOCKWORLDVIEW_REFRESHCITYLIST_EXIT );
   217 }
   230 }
   218 
   231 
   219 /*!
   232 /*!
   220 	Updates the current location info.
   233 	Updates the current location info.
   221  */
   234  */
   222 void ClockWorldView::updateCurrentLocationInfo(int networkTime)
   235 void ClockWorldView::updateCurrentLocationInfo(int networkTime)
   223 {
   236 {
       
   237 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_UPDATECURRENTLOCATIONINFO_ENTRY );
   224 	HbMainWindow *window = hbInstance->allMainWindows().first();
   238 	HbMainWindow *window = hbInstance->allMainWindows().first();
   225 	Qt::Orientation currentOrienation = window->orientation();
   239 	Qt::Orientation currentOrienation = window->orientation();
   226 	loadSection(currentOrienation);
   240 	loadSection(currentOrienation);
   227 
   241 
   228 	if (!networkTime) {
   242 	if (!networkTime) {
   231 
   245 
   232 		QMap<QString, QVariant> itemList;
   246 		QMap<QString, QVariant> itemList;
   233 		QString value;
   247 		QString value;
   234 		QDateTime dateTime = QDateTime::currentDateTime();
   248 		QDateTime dateTime = QDateTime::currentDateTime();
   235 
   249 
   236 		// Show the date. If date is current date then show 'today'.
   250 		// Show the date.
   237 		QString dateInfo = dateTime.toString(
   251 		QString dateInfo = dateTime.toString(
   238 				mSettingsUtility->dateFormatString());
   252 				mSettingsUtility->dateFormatString());
   239 		itemList.insert(value.setNum(ClockHomeCityItem::Date), dateInfo);
   253 		itemList.insert(value.setNum(ClockHomeCityItem::Date), dateInfo);
   240 
   254 
   241 		// Show the city and country name.
   255 		// Show the city and country name.
   258 		}
   272 		}
   259 		itemList.insert(value.setNum(
   273 		itemList.insert(value.setNum(
   260 				ClockHomeCityItem::DayNightIndicator), dayNightIconPath);
   274 				ClockHomeCityItem::DayNightIndicator), dayNightIconPath);
   261 
   275 
   262 		// Show dst icon when needed.
   276 		// Show dst icon when needed.
       
   277 		QString dstIconPath = " ";
   263 		if (homeCity.dstOn) {
   278 		if (homeCity.dstOn) {
   264 			QString dstIconPath = "qtg_mono_day_light_saving_time";
   279 			dstIconPath = "qtg_mono_day_light_saving_time";
   265 			itemList.insert(value.setNum(ClockHomeCityItem::Dst), dstIconPath);
   280 		}
   266 		}
   281 		itemList.insert(value.setNum(ClockHomeCityItem::Dst), dstIconPath);
       
   282 		
   267 		mHomeCityWidget->setHomeCityItemData(itemList);
   283 		mHomeCityWidget->setHomeCityItemData(itemList);
   268 	}
   284 	}
       
   285 	OstTraceFunctionExit0( CLOCKWORLDVIEW_UPDATECURRENTLOCATIONINFO_EXIT );
   269 }
   286 }
   270 
   287 
   271 /*!
   288 /*!
   272 	Handles the long press on each item in the citylist.
   289 	Handles the long press on each item in the citylist.
   273 	Displays a list item specific context menu.
   290 	Displays a list item specific context menu.
   276 	\param coords The position where mouse was pressed.
   293 	\param coords The position where mouse was pressed.
   277  */
   294  */
   278 void ClockWorldView::handleItemLongPressed(
   295 void ClockWorldView::handleItemLongPressed(
   279 		HbAbstractViewItem *item, const QPointF &coords)
   296 		HbAbstractViewItem *item, const QPointF &coords)
   280 {
   297 {
       
   298 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_HANDLEITEMLONGPRESSED_ENTRY );
   281 	// Get the ndex of the selected item.
   299 	// Get the ndex of the selected item.
   282 	mSelectedItem = item->modelIndex().row();
   300 	mSelectedItem = item->modelIndex().row();
   283 
   301 
   284 	// On long press we display item specific context menu.
   302 	// On long press we display item specific context menu.
   285 	HbMenu *itemContextMenu = new HbMenu();
   303 	HbMenu *itemContextMenu = new HbMenu();
   292 
   310 
   293 	// Show the menu.
   311 	// Show the menu.
   294 	itemContextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
   312 	itemContextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
   295 	itemContextMenu->setPreferredPos(coords);
   313 	itemContextMenu->setPreferredPos(coords);
   296 	itemContextMenu->setAttribute( Qt::WA_DeleteOnClose,true);
   314 	itemContextMenu->setAttribute( Qt::WA_DeleteOnClose,true);
       
   315 	OstTraceFunctionExit0( CLOCKWORLDVIEW_HANDLEITEMLONGPRESSED_EXIT );
   297 }
   316 }
   298 
   317 
   299 /*!
   318 /*!
   300 	This slot is called when Add location action is triggered. It is responsible
   319 	This slot is called when Add location action is triggered. It is responsible
   301 	for launching the city selection list.
   320 	for launching the city selection list.
   302  */
   321  */
   303 void ClockWorldView::handleAddLocation()
   322 void ClockWorldView::handleAddLocation()
   304 {
   323 {
       
   324 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_HANDLEADDLOCATION_ENTRY );
   305 	// Construct the city selection list and show the same.
   325 	// Construct the city selection list and show the same.
   306 	mCitySelectionList = new ClockCitySelectionList(mTimezoneClient, this);
   326 	mCitySelectionList = new ClockCitySelectionList(mTimezoneClient, this);
   307 	connect(
   327 	connect(
   308 			mCitySelectionList, SIGNAL(citySelected(LocationInfo)),
   328 			mCitySelectionList, SIGNAL(citySelected(LocationInfo)),
   309 			this, SLOT(handleCitySelected(LocationInfo)));
   329 			this, SLOT(handleCitySelected(LocationInfo)));
   310 
   330 
   311 	// Show the city list.
   331 	// Show the city list.
   312 	mCitySelectionList->showCityList();
   332 	mCitySelectionList->showCityList();
       
   333 	OstTraceFunctionExit0( CLOCKWORLDVIEW_HANDLEADDLOCATION_EXIT );
   313 }
   334 }
   314 
   335 
   315 /*!
   336 /*!
   316 	This slot handles delete action on the city list. It removes the item from
   337 	This slot handles delete action on the city list. It removes the item from
   317 	the view.
   338 	the view.
   318  */
   339  */
   319 void ClockWorldView::handleDeleteAction()
   340 void ClockWorldView::handleDeleteAction()
   320 {
   341 {
       
   342 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_HANDLEDELETEACTION_ENTRY );
   321 	if (-1 != mSelectedItem) {
   343 	if (-1 != mSelectedItem) {
   322 		QStandardItem *item = mCityListModel->takeItem(mSelectedItem);
   344 		QStandardItem *item = mCityListModel->takeItem(mSelectedItem);
   323 		mCityListModel->removeRow(mSelectedItem);
   345 		mCityListModel->removeRow(mSelectedItem);
   324 		delete item;
   346 		delete item;
   325 
   347 
   336 				!mAddCityAction->isEnabled()) {
   358 				!mAddCityAction->isEnabled()) {
   337 			mAddCityAction->setEnabled(true);
   359 			mAddCityAction->setEnabled(true);
   338 			mAddCityMenuAction->setVisible(true);
   360 			mAddCityMenuAction->setVisible(true);
   339 		}
   361 		}
   340 	}
   362 	}
       
   363 	OstTraceFunctionExit0( CLOCKWORLDVIEW_HANDLEDELETEACTION_EXIT );
   341 }
   364 }
   342 
   365 
   343 /*!
   366 /*!
   344 	This slot sets the selected city as the current location.
   367 	This slot sets the selected city as the current location.
   345  */
   368  */
   346 void ClockWorldView::handleSetAsCurrentLocationAction()
   369 void ClockWorldView::handleSetAsCurrentLocationAction()
   347 {
   370 {
       
   371 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_HANDLESETASCURRENTLOCATIONACTION_ENTRY );
   348 	// Get the info of the selected item.
   372 	// Get the info of the selected item.
   349 	LocationInfo newHomeCity = mCityInfoList[mSelectedItem];
   373 	LocationInfo newHomeCity = mCityInfoList[mSelectedItem];
   350 
   374 
   351 	// Check if time update is set to ON.
   375 	// Check if time update is set to ON.
   352 	// If yes, reset it to OFF and change the home location.
   376 	// If yes, reset it to OFF and change the home location.
   378 	refreshCityList();
   402 	refreshCityList();
   379 
   403 
   380 	// Update the data file.
   404 	// Update the data file.
   381 	mTimezoneClient->saveLocations(mCityInfoList);
   405 	mTimezoneClient->saveLocations(mCityInfoList);
   382 	mSelectedItem = -1;
   406 	mSelectedItem = -1;
       
   407 	OstTraceFunctionExit0( CLOCKWORLDVIEW_HANDLESETASCURRENTLOCATIONACTION_EXIT );
   383 }
   408 }
   384 
   409 
   385 /*!
   410 /*!
   386 	Slot to handle the case when a city has been selected in from the city
   411 	Slot to handle the case when a city has been selected in from the city
   387 	selection list.
   412 	selection list.
   388 
   413 
   389 	\param info of type LocationInfo which contains the city selected.
   414 	\param info of type LocationInfo which contains the city selected.
   390  */
   415  */
   391 void ClockWorldView::handleCitySelected(LocationInfo info)
   416 void ClockWorldView::handleCitySelected(LocationInfo info)
   392 {
   417 {
       
   418 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_HANDLECITYSELECTED_ENTRY );
   393 	// Info is invalid if the timezoneId is set to -1. We don't do anything in
   419 	// Info is invalid if the timezoneId is set to -1. We don't do anything in
   394 	// that case.
   420 	// that case.
   395 	if (-1 != info.timezoneId) {
   421 	if (-1 != info.timezoneId) {
   396 		// Now we check if the city is already added in the list.
   422 		// Now we check if the city is already added in the list.
   397 		bool proceed = true;
   423 		bool proceed = true;
   435 		mAddCityAction->setEnabled(false);
   461 		mAddCityAction->setEnabled(false);
   436 		mAddCityMenuAction->setVisible(false);
   462 		mAddCityMenuAction->setVisible(false);
   437 	}
   463 	}
   438 	// Cleanup.
   464 	// Cleanup.
   439 	mCitySelectionList->deleteLater();
   465 	mCitySelectionList->deleteLater();
       
   466 	OstTraceFunctionExit0( CLOCKWORLDVIEW_HANDLECITYSELECTED_EXIT );
   440 }
   467 }
   441 
   468 
   442 /*!
   469 /*!
   443 	Navigates to the clock alarms view.
   470 	Navigates to the clock alarms view.
   444  */
   471  */
   445 void ClockWorldView::showAlarmsView()
   472 void ClockWorldView::showAlarmsView()
   446 {
   473 {
       
   474 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_SHOWALARMSVIEW_ENTRY );
   447 	mAppControllerIf->switchToView(MainView);
   475 	mAppControllerIf->switchToView(MainView);
       
   476 	OstTraceFunctionExit0( CLOCKWORLDVIEW_SHOWALARMSVIEW_EXIT );
   448 }
   477 }
   449 
   478 
   450 /*!
   479 /*!
   451 	Slot which gets called when `World Clock' action is triggered from the view
   480 	Slot which gets called when `World Clock' action is triggered from the view
   452 	toolbar. This is responsible for reloading the content of worldclock view.
   481 	toolbar. This is responsible for reloading the content of worldclock view.
   453  */
   482  */
   454 void ClockWorldView::refreshWorldView()
   483 void ClockWorldView::refreshWorldView()
   455 {
   484 {
       
   485 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_REFRESHWORLDVIEW_ENTRY );
   456 	mDisplayWorldClockView->setChecked(true);
   486 	mDisplayWorldClockView->setChecked(true);
       
   487 	OstTraceFunctionExit0( CLOCKWORLDVIEW_REFRESHWORLDVIEW_EXIT );
   457 }
   488 }
   458 
   489 
   459 /*!
   490 /*!
   460 	Loads the appropriate section based on window orientaion.
   491 	Loads the appropriate section based on window orientaion.
   461  */
   492  */
   462 void ClockWorldView::loadSection(Qt::Orientation orientation)
   493 void ClockWorldView::loadSection(Qt::Orientation orientation)
   463 {
   494 {
       
   495 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_LOADSECTION_ENTRY );
   464 	bool networkTime = mTimezoneClient->timeUpdateOn();
   496 	bool networkTime = mTimezoneClient->timeUpdateOn();
   465 	bool loadSuccess;
   497 	bool loadSuccess;
   466 	if (Qt::Horizontal == orientation) {
   498 	if (Qt::Horizontal == orientation) {
   467 		if (networkTime) {
   499 		if (networkTime) {
   468 			// Do not show home city.
   500 			// Do not show home city.
   494 					&loadSuccess);
   526 					&loadSuccess);
   495 			mHomeCityWidget->show();
   527 			mHomeCityWidget->show();
   496 		}
   528 		}
   497 	}
   529 	}
   498 	mCityListView->update();
   530 	mCityListView->update();
       
   531 	OstTraceFunctionExit0( CLOCKWORLDVIEW_LOADSECTION_EXIT );
   499 }
   532 }
   500 
   533 
   501 /*!
   534 /*!
   502 	Slot which gets called for timeChanged signal of timezone client.
   535 	Slot which gets called for timeChanged signal of timezone client.
   503 	Refreshes both homecity & city list.
   536 	Refreshes both homecity & city list.
   504  */
   537  */
   505 void ClockWorldView::updateAllLocationInfo()
   538 void ClockWorldView::updateAllLocationInfo()
   506 {
   539 {
       
   540 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_UPDATEALLLOCATIONINFO_ENTRY );
   507 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   541 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   508 	updateCityList();
   542 	updateCityList();
   509 	refreshCityList();
   543 	refreshCityList();
       
   544 	OstTraceFunctionExit0( CLOCKWORLDVIEW_UPDATEALLLOCATIONINFO_EXIT );
   510 }
   545 }
   511 
   546 
   512 /*!
   547 /*!
   513 	Slot to handle the selected context menu actions
   548 	Slot to handle the selected context menu actions
   514  */
   549  */
   515 void ClockWorldView::selectedMenuAction(HbAction *action)
   550 void ClockWorldView::selectedMenuAction(HbAction *action)
   516 {
   551 {
       
   552 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_SELECTEDMENUACTION_ENTRY );
   517 	if (action == mSetCurrentLocationAction) {
   553 	if (action == mSetCurrentLocationAction) {
   518 		handleSetAsCurrentLocationAction();
   554 		handleSetAsCurrentLocationAction();
   519 	} else if (action == mRemoveCityAction) {
   555 	} else if (action == mRemoveCityAction) {
   520 		handleDeleteAction();
   556 		handleDeleteAction();
   521 	}
   557 	}
       
   558 	OstTraceFunctionExit0( CLOCKWORLDVIEW_SELECTEDMENUACTION_EXIT );
   522 }
   559 }
   523 
   560 
   524 /*!
   561 /*!
   525 	Adds the location info to the city list.
   562 	Adds the location info to the city list.
   526 
   563 
   527 	\param locationInfo Details of the city to be added to the list.
   564 	\param locationInfo Details of the city to be added to the list.
   528  */
   565  */
   529 QModelIndex ClockWorldView::addCityToList(const LocationInfo& locationInfo)
   566 QModelIndex ClockWorldView::addCityToList(const LocationInfo& locationInfo)
   530 {
   567 {
       
   568 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_ADDCITYTOLIST_ENTRY );
   531 	// Here we construct a model item and add it to the list model.
   569 	// Here we construct a model item and add it to the list model.
   532 	QStandardItem *modelItem = new QStandardItem();
   570 	QStandardItem *modelItem = new QStandardItem();
   533 
   571 
   534 	// Add the item to the model.
   572 	// Add the item to the model.
   535 	mCityListModel->appendRow(modelItem);
   573 	mCityListModel->appendRow(modelItem);
   539 			index, getCityListDisplayString(locationInfo), Qt::DisplayRole);
   577 			index, getCityListDisplayString(locationInfo), Qt::DisplayRole);
   540 	mCityListModel->setData(
   578 	mCityListModel->setData(
   541 			index, getCityListDecorationString(locationInfo),
   579 			index, getCityListDecorationString(locationInfo),
   542 			Qt::DecorationRole);
   580 			Qt::DecorationRole);
   543 
   581 
       
   582 	OstTraceFunctionExit0( CLOCKWORLDVIEW_ADDCITYTOLIST_EXIT );
   544 	return index;
   583 	return index;
   545 }
   584 }
   546 
   585 
   547 /*!
   586 /*!
   548 	Checks if the given time is day or night.
   587 	Checks if the given time is day or night.
   551 	\param dateTime Time for which check has to be performed.
   590 	\param dateTime Time for which check has to be performed.
   552 	\return bool True if it is day otherwise false.
   591 	\return bool True if it is day otherwise false.
   553  */
   592  */
   554 bool ClockWorldView::isDay(QDateTime dateTime)
   593 bool ClockWorldView::isDay(QDateTime dateTime)
   555 {
   594 {
       
   595 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_ISDAY_ENTRY );
   556 	// It is day between 6:00 AM and 6:00 PM. Otherwise night.
   596 	// It is day between 6:00 AM and 6:00 PM. Otherwise night.
   557 	if (17 < dateTime.time().hour() || 6 > dateTime.time().hour()) {
   597 	if (17 < dateTime.time().hour() || 6 > dateTime.time().hour()) {
       
   598 		OstTraceFunctionExit0( CLOCKWORLDVIEW_ISDAY_EXIT );
   558 		return false;
   599 		return false;
   559 	}
   600 	}
       
   601 	OstTraceFunctionExit0( DUP1_CLOCKWORLDVIEW_ISDAY_EXIT );
   560 	return true;
   602 	return true;
   561 }
   603 }
   562 
   604 
   563 /*!
   605 /*!
   564 	Returns the QVariantList for citylist to be set for DisplayRole.
   606 	Returns the QVariantList for citylist to be set for DisplayRole.
   566 	/param locationInfo Details of the city to be added to the list.
   608 	/param locationInfo Details of the city to be added to the list.
   567  */
   609  */
   568 QVariantList ClockWorldView::getCityListDisplayString(
   610 QVariantList ClockWorldView::getCityListDisplayString(
   569 		const LocationInfo& locationInfo)
   611 		const LocationInfo& locationInfo)
   570 {
   612 {
       
   613 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_GETCITYLISTDISPLAYSTRING_ENTRY );
   571 	QVariantList displayString;
   614 	QVariantList displayString;
   572 	QDateTime dateTime = QDateTime::currentDateTime();
   615 	QDateTime dateTime = QDateTime::currentDateTime();
   573 	dateTime = dateTime.toUTC();
   616 	dateTime = dateTime.toUTC();
   574 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   617 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   575 
   618 
   616 			offsetDifference += offsetString;
   659 			offsetDifference += offsetString;
   617 		}
   660 		}
   618 	}
   661 	}
   619 	else if ( hours ){
   662 	else if ( hours ){
   620 		if(hours == 1 ) {
   663 		if(hours == 1 ) {
   621 			displayFormat = hbTrId("txt_clock_dblist_val_1_hr");
   664 			displayFormat = hbTrId("txt_clock_dblist_daily_val_ln_hr");
   622 			offsetString = displayFormat.arg(hours);
   665 			offsetString = displayFormat.arg(hours);
   623 			offsetDifference += offsetString;
   666 			offsetDifference += offsetString;
   624 		}
   667 		}
   625 		else {
   668 		else {
   626 			displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   669 			displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   627 			offsetString = displayFormat.arg(hours);
   670 			offsetString = displayFormat.arg(hours);
   628 			offsetDifference += offsetString;
   671 			offsetDifference += offsetString;
   629 		}
   672 		}
   630 	}
   673 	}
   631 	else if (minutes){
   674 	else if (minutes){
   632 		displayFormat = hbTrId("txt_clock_dblist_val_1_mins");
   675 		displayFormat = hbTrId("txt_clock_dblist_daily_val_ln_mins");
   633 		offsetString = displayFormat.arg(minutes);
   676 		offsetString = displayFormat.arg(minutes);
   634 		offsetDifference += offsetString;
   677 		offsetDifference += offsetString;
   635 	} else {
   678 	} else {
   636 		displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   679 		displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   637 		offsetString = displayFormat.arg(0);
   680 		offsetString = displayFormat.arg(0);
   641 
   684 
   642 	// Show the time at that location.
   685 	// Show the time at that location.
   643 	QString timeInfo = dateTime.toString(mSettingsUtility->timeFormatString());
   686 	QString timeInfo = dateTime.toString(mSettingsUtility->timeFormatString());
   644 	displayString.append(timeInfo);
   687 	displayString.append(timeInfo);
   645 
   688 
       
   689 	OstTraceFunctionExit0( CLOCKWORLDVIEW_GETCITYLISTDISPLAYSTRING_EXIT );
   646 	return displayString;
   690 	return displayString;
   647 }
   691 }
   648 
   692 
   649 /*!
   693 /*!
   650 	Returns the QVariantList for citylist to be set for DecorationRole.
   694 	Returns the QVariantList for citylist to be set for DecorationRole.
   652 	/param locationInfo Details of the city to be added to the list.
   696 	/param locationInfo Details of the city to be added to the list.
   653  */
   697  */
   654 QVariantList ClockWorldView::getCityListDecorationString(
   698 QVariantList ClockWorldView::getCityListDecorationString(
   655 		const LocationInfo& locationInfo)
   699 		const LocationInfo& locationInfo)
   656 {
   700 {
       
   701 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_GETCITYLISTDECORATIONSTRING_ENTRY );
   657 	QVariantList decorationString;
   702 	QVariantList decorationString;
   658 	QDateTime dateTime = QDateTime::currentDateTime();
   703 	QDateTime dateTime = QDateTime::currentDateTime();
   659 	dateTime = dateTime.toUTC();
   704 	dateTime = dateTime.toUTC();
   660 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   705 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   661 
   706 
   662 	// Display day/night indicators.
   707 	// Display day/night indicators.
   663 	// TODO: change the icon name for night when available.
       
   664 	QString dayNightIconPath = "";
   708 	QString dayNightIconPath = "";
   665 	if (isDay(dateTime)) {
   709 	if (isDay(dateTime)) {
   666 		dayNightIconPath = "qtg_large_clock";
   710 		dayNightIconPath = "qtg_large_clock";
   667 	} else {
   711 	} else {
   668 		dayNightIconPath = "qtg_large_clock_night";
   712 		dayNightIconPath = "qtg_large_clock_night";
   669 	}
   713 	}
   670 	decorationString.append(HbIcon(dayNightIconPath));
   714 	decorationString.append(HbIcon(dayNightIconPath));
   671 
   715 
   672 	// Show dst icon when needed.
   716 	// Show dst icon when needed.
       
   717 	QString dstIconPath = "";
   673 	if (locationInfo.dstOn) {
   718 	if (locationInfo.dstOn) {
   674 		QString dstIconPath = "qtg_mono_day_light_saving_time";
   719 		dstIconPath = "qtg_mono_day_light_saving_time";
   675 		decorationString.append(HbIcon(dstIconPath));
   720 	}
   676 	}
   721 	decorationString.append(HbIcon(dstIconPath));
       
   722 	
       
   723 	OstTraceFunctionExit0( CLOCKWORLDVIEW_GETCITYLISTDECORATIONSTRING_EXIT );
   677 	return decorationString;
   724 	return decorationString;
   678 	
   725 	
   679 }
   726 }
   680 
   727 
   681 /*!
   728 /*!
   682 	Updates the city list according to the home city.
   729 	Updates the city list according to the home city.
   683  */
   730  */
   684 void ClockWorldView::updateCityList()
   731 void ClockWorldView::updateCityList()
   685 {
   732 {
       
   733 	OstTraceFunctionEntry0( CLOCKWORLDVIEW_UPDATECITYLIST_ENTRY );
   686 	int cityInfoCount = mCityInfoList.count();
   734 	int cityInfoCount = mCityInfoList.count();
   687 
   735 
   688 	if (cityInfoCount) {
   736 	if (cityInfoCount) {
   689 		bool deletion = false;
   737 		bool deletion = false;
       
   738 		bool valueUpdated = false;
   690 		int index;
   739 		int index;
   691 		LocationInfo currentCity = mTimezoneClient->getCurrentZoneInfoL();
   740 		LocationInfo currentCity = mTimezoneClient->getCurrentZoneInfoL();
       
   741 		// Remove the new home city if it is already added to the list.
   692 		for (index = 0; index < cityInfoCount; index++) {
   742 		for (index = 0; index < cityInfoCount; index++) {
   693 			if (currentCity.timezoneId == mCityInfoList.at(index).timezoneId
   743 			if (currentCity.timezoneId == mCityInfoList.at(index).timezoneId
   694 					&& (currentCity.cityName ==
   744 					&& (currentCity.cityName ==
   695 							mCityInfoList.at(index).cityName)
   745 							mCityInfoList.at(index).cityName)
   696 					&& (currentCity.countryName ==
   746 					&& (currentCity.countryName ==
   718 				mAddCityAction->setEnabled(true);
   768 				mAddCityAction->setEnabled(true);
   719 				mAddCityMenuAction->setVisible(true);
   769 				mAddCityMenuAction->setVisible(true);
   720 			}
   770 			}
   721 			
   771 			
   722 		}
   772 		}
   723 	}
   773 		
       
   774 		for (int index = 0; index < cityInfoCount; ++index) {
       
   775 			int tzid = mCityInfoList[index].timezoneId;
       
   776 			bool dst = mTimezoneClient->isDSTOnL(tzid);
       
   777 			if (dst != mCityInfoList[index].dstOn) {
       
   778 				mCityInfoList[index].dstOn = dst;
       
   779 				valueUpdated = true;
       
   780 			}
       
   781 
       
   782 		}
       
   783 		
       
   784 		if (valueUpdated) {
       
   785 			// Update the data file.
       
   786 			mTimezoneClient->saveLocations(mCityInfoList);
       
   787         }
       
   788 	}
       
   789 	OstTraceFunctionExit0( CLOCKWORLDVIEW_UPDATECITYLIST_EXIT );
   724 }
   790 }
   725 
   791 
   726 // End of file-- Don't delete.
   792 // End of file-- Don't delete.