clock/clockui/clockviews/src/clockworldview.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <QGraphicsItem>
    20 #include <QGraphicsItem>
    21 #include <QStandardItem>
    21 #include <QStandardItem>
    22 #include <QStandardItemModel>
    22 #include <QStandardItemModel>
    23 #include <QDebug>
       
    24 #include <HbInstance>
    23 #include <HbInstance>
    25 #include <HbLabel>
       
    26 #include <HbPushButton>
       
    27 #include <HbAbstractViewItem>
    24 #include <HbAbstractViewItem>
    28 #include <HbMenu>
    25 #include <HbMenu>
    29 #include <HbAction>
    26 #include <HbAction>
    30 #include <HbStyleLoader>
    27 #include <HbStyleLoader>
    31 #include <HbListView>
    28 #include <HbListView>
    36 #include "clockappcontrollerif.h"
    33 #include "clockappcontrollerif.h"
    37 #include "clockcommon.h"
    34 #include "clockcommon.h"
    38 #include "settingsutility.h"
    35 #include "settingsutility.h"
    39 #include "timezoneclient.h"
    36 #include "timezoneclient.h"
    40 #include "clockcityselectionlist.h"
    37 #include "clockcityselectionlist.h"
    41 #include "listitemprototype.h"
    38 #include "clockhomecityitem.h"
    42 
    39 
    43 /*!
    40 /*!
    44 	\class ClockWorldView
    41 	\class ClockWorldView
    45 
    42 
    46 	The world clock view of the clock application.
    43 	The world clock view of the clock application.
    53  */
    50  */
    54 ClockWorldView::ClockWorldView(QGraphicsItem *parent)
    51 ClockWorldView::ClockWorldView(QGraphicsItem *parent)
    55 :HbView(parent),
    52 :HbView(parent),
    56  mSelectedItem(-1)
    53  mSelectedItem(-1)
    57 {
    54 {
    58 	qDebug("clock: ClockWorldView::ClockWorldView() -->");
       
    59 
       
    60 	// Timer for updating list data upon time change/update.
    55 	// Timer for updating list data upon time change/update.
    61 	mRefreshTimer = new QTimer();
    56 	mRefreshTimer = new QTimer();
    62 	connect(
    57 	connect(
    63 			mRefreshTimer, SIGNAL(timeout()),
    58 			mRefreshTimer, SIGNAL(timeout()),
    64 			this, SLOT(refreshCityList()));
    59 			this, SLOT(refreshCityList()));
    65 
    60 
    66 	// Create the model.
    61 	// Create the model.
    67 	mCityListModel = new QStandardItemModel();
    62 	mCityListModel = new QStandardItemModel();
    68 
       
    69 	qDebug("clock: ClockWorldView::ClockWorldView() <--");
       
    70 }
    63 }
    71 
    64 
    72 /*!
    65 /*!
    73 	Destructor.
    66 	Destructor.
    74  */
    67  */
    75 ClockWorldView::~ClockWorldView()
    68 ClockWorldView::~ClockWorldView()
    76 {
    69 {
    77 	qDebug("clock: ClockWorldView::~ClockWorldView() -->");
       
    78 
       
    79 	if (mDocLoader) {
    70 	if (mDocLoader) {
    80 		delete mDocLoader;
    71 		delete mDocLoader;
    81 	}
    72 		mDocLoader = 0;
    82 
    73 	}
    83 	qDebug("clock: ClockWorldView::~ClockWorldView() <--");
    74 	if(mCityListModel){
       
    75 		delete mCityListModel;
       
    76 	}
       
    77 	
       
    78 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.css");
       
    79 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem.widgetml");
       
    80 	HbStyleLoader::unregisterFilePath(":/style/hblistviewitem_color.css");
    84 }
    81 }
    85 
    82 
    86 /*!
    83 /*!
    87 	Called by the ClockViewManager after loading the view from the docml.
    84 	Called by the ClockViewManager after loading the view from the docml.
    88 	The initializaion/setup of the view is done here.
    85 	The initializaion/setup of the view is done here.
    92  */
    89  */
    93 void ClockWorldView::setupView(
    90 void ClockWorldView::setupView(
    94 		ClockAppControllerIf &controllerIf,
    91 		ClockAppControllerIf &controllerIf,
    95 		ClockDocLoader *docLoader)
    92 		ClockDocLoader *docLoader)
    96 {
    93 {
    97 	qDebug("clock: ClockWorldView::setupView() <--");
       
    98 
       
    99 	mDocLoader = docLoader;
    94 	mDocLoader = docLoader;
   100 	mAppControllerIf = &controllerIf;
    95 	mAppControllerIf = &controllerIf;
   101 
    96 
   102 	mTimezoneClient = controllerIf.timezoneClient();
    97 	mTimezoneClient = controllerIf.timezoneClient();
   103 	mSettingsUtility = controllerIf.settingsUtility();
    98 	mSettingsUtility = controllerIf.settingsUtility();
   104 
    99 
   105 	// Establish required connections.
   100 	// Establish required connections.
   106 	connect(
   101 	connect(
   107 			mTimezoneClient, SIGNAL(timechanged()),
   102 			mTimezoneClient, SIGNAL(timechanged()),
   108 			this, SLOT(updateClockDisplay()));
   103 			this, SLOT(updateAllLocationInfo()));
   109 	connect(
   104 	connect(
   110 			mTimezoneClient, SIGNAL(timechanged()),
   105 			mTimezoneClient, SIGNAL(autoTimeUpdateChanged(int)),
   111 			this, SLOT(updateDayDateInfo()));
   106 			this, SLOT(updateCurrentLocationInfo(int)));
   112 	connect(
   107 	connect(
   113 			mTimezoneClient, SIGNAL(timechanged()),
   108 			mTimezoneClient, SIGNAL(cityUpdated()),
   114 			this, SLOT(updateCurrentLocationInfo()));
   109 			this, SLOT(updateAllLocationInfo()));
   115 	connect(
       
   116 			mTimezoneClient, SIGNAL(timechanged()),
       
   117 			this, SLOT(updateCurrentZoneInfo()));
       
   118 
   110 
   119 	mDisplayWorldClockView = static_cast<HbAction *> (
   111 	mDisplayWorldClockView = static_cast<HbAction *> (
   120 	            mDocLoader->findObject("worldClockAction"));
   112 			mDocLoader->findObject("worldClockAction"));
   121 
   113 
   122 	mDisplayWorldClockView->setCheckable(true);
   114 	mDisplayWorldClockView->setCheckable(true);
   123 	mDisplayWorldClockView->setChecked(true);
   115 	mDisplayWorldClockView->setChecked(true);
   124 
   116 
   125 	connect(
   117 	connect(
   126 	        mDisplayWorldClockView, SIGNAL(changed()),
   118 			mDisplayWorldClockView, SIGNAL(changed()),
   127             this, SLOT(refreshWorldView()));
   119 			this, SLOT(refreshWorldView()));
   128 
   120 
   129 	// Get the currently added locations to the list.
   121 	// Get the currently added locations to the list.
   130 	mCityInfoList = mTimezoneClient->getSavedLocations();
   122 	mCityInfoList = mTimezoneClient->getSavedLocations();
   131 
   123 
   132 	// Create the custom prototype.
   124 	// Get the homecity widget.
   133 	ListItemPrototype *customPrototype = new ListItemPrototype();
   125 	mHomeCityWidget = qobject_cast<ClockHomeCityItem *>(
       
   126 			mDocLoader->findWidget(CLOCK_WORLD_HOMECITY));
       
   127 	
       
   128 	// Get the city list item.
   134 	mCityListView = qobject_cast<HbListView *> (
   129 	mCityListView = qobject_cast<HbListView *> (
   135 			mDocLoader->findWidget("worldClockCityListView"));
   130 			mDocLoader->findWidget(CLOCK_WORLD_CITYLIST));
   136 	HbStyleLoader::registerFilePath(":/style/");
   131 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.css");
       
   132 	HbStyleLoader::registerFilePath(":/style/hblistviewitem.widgetml");
       
   133 	HbStyleLoader::registerFilePath(":/style/hblistviewitem_color.css");
       
   134 	mCityListView->setLayoutName("citylist-portrait");
   137 	mCityListView->setModel(mCityListModel);
   135 	mCityListView->setModel(mCityListModel);
   138 	mCityListView->setItemPrototype(customPrototype);
   136 	
   139 	mCityListView->setLayoutName("custom");
       
   140 
       
   141 	mPlaceLabel =
       
   142 			qobject_cast<HbLabel *> (mDocLoader->findWidget("placeLabel"));
       
   143 //	mPlaceLabel->setTextWrapping(Hb::TextWordWrap);
       
   144 
       
   145 	mDayDateLabel =
       
   146 			qobject_cast<HbLabel *> (mDocLoader->findWidget("dateLabel"));
       
   147 
       
   148 	// Get the toolbar/menu actions.
   137 	// Get the toolbar/menu actions.
   149 	mAddCityAction = static_cast<HbAction *> (
   138 	mAddCityAction = static_cast<HbAction *> (
   150 			mDocLoader->findObject("addCityAction"));
   139 			mDocLoader->findObject("addCityAction"));
   151 	mAddCityAction->setIcon(HbIcon(":/clock/add_new_city.svg"));
       
   152 	connect(
   140 	connect(
   153 			mAddCityAction, SIGNAL(triggered()),
   141 			mAddCityAction, SIGNAL(triggered()),
   154 			this, SLOT(handleAddLocation()));
   142 			this, SLOT(handleAddLocation()));
   155 
   143 
   156 	mShowAlarmsViewAction = static_cast<HbAction *> (
   144 	mShowAlarmsViewAction = static_cast<HbAction *> (
   157 			mDocLoader->findObject("alarmsAction"));
   145 			mDocLoader->findObject("alarmsAction"));
   158 	connect(
   146 	connect(
   159 			mShowAlarmsViewAction, SIGNAL(triggered()),
   147 			mShowAlarmsViewAction, SIGNAL(triggered()),
   160 			this, SLOT(showAlarmsView()));
   148 			this, SLOT(showAlarmsView()));
   161 
   149 
   162 	HbMainWindow *window;
   150 	HbMainWindow *window = hbInstance->allMainWindows().first();
   163 	window = hbInstance->allMainWindows().first();
       
   164 	updateToolbarTexts(window->orientation());
       
   165 
   151 
   166 	connect(
   152 	connect(
   167 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   153 			window, SIGNAL(orientationChanged(Qt::Orientation)),
   168 			this, SLOT(updateToolbarTexts(Qt::Orientation)));
   154 			this, SLOT(loadSection(Qt::Orientation)));
   169 
   155 
   170 	if (mCityInfoList.count() > 0) {
   156 	if (mCityInfoList.count() > 0) {
   171 		// There is atleast one city. Refresh needed.
   157 		// There is atleast one city. Refresh needed.
   172 		// Calculate after how much time the refresh has to happen.
   158 		// Calculate after how much time the refresh has to happen.
   173 		QTime currentTime = QDateTime::currentDateTime().time();
   159 		QTime currentTime = QDateTime::currentDateTime().time();
   174 		int after = 60 - currentTime.second();
   160 		int after = 60 - currentTime.second();
   175 		mRefreshTimer->start(after * 1000);
   161 		mRefreshTimer->start(after * 1000);
   176 	}
   162 	}
   177 
   163 
   178 	// Update the date and day info.
       
   179 	updateDayDateInfo();
       
   180 
       
   181 	connect(
   164 	connect(
   182 			mCityListView,
   165 			mCityListView,
   183 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   166 			SIGNAL(longPressed(HbAbstractViewItem *, const QPointF &)),
   184 			this,
   167 			this,
   185 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   168 			SLOT(handleItemLongPressed(HbAbstractViewItem *, const QPointF &)));
   186 
   169 
       
   170 	// Update current location info.
       
   171 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
       
   172 
   187 	// Populate the list.
   173 	// Populate the list.
   188 	int index = 0;
   174 	for (int index = 0; index < mCityInfoList.count(); index++) {
   189 	// Update current location info.
       
   190 	updateCurrentLocationInfo();
       
   191 
       
   192 	for (; index < mCityInfoList.count(); index++) {
       
   193 		addCityToList(mCityInfoList.at(index));
   175 		addCityToList(mCityInfoList.at(index));
   194 	}
   176 	}
   195 
   177 	
   196 	qDebug("clock: ClockWorldView::setupView() <--");
   178 	// Adding the "Add city" in options menu.
       
   179 	mAddCityMenuAction = new HbAction(
       
   180 			QString(hbTrId("txt_clock_opt_add_city")),this);
       
   181 	menu()->addAction(mAddCityMenuAction);
       
   182 	mAddCityMenuAction->setVisible(true);
       
   183 	connect(
       
   184 			mAddCityMenuAction, SIGNAL(triggered()),
       
   185 			this, SLOT(handleAddLocation()));
       
   186 
       
   187 	// Check for disabling of addCityAction in view toolbar.
       
   188 	if ((KMaximumCityListCount-1) == mCityInfoList.count()) {
       
   189 		mAddCityAction->setEnabled(false);
       
   190 		mAddCityMenuAction->setVisible(false);
       
   191 	}
   197 }
   192 }
   198 
   193 
   199 /*!
   194 /*!
   200 	Refreshes the data in the city list.
   195 	Refreshes the data in the city list.
   201  */
   196  */
   202 void ClockWorldView::refreshCityList()
   197 void ClockWorldView::refreshCityList()
   203 {
   198 {
       
   199 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   204 	int cityInfoCount = mCityInfoList.count();
   200 	int cityInfoCount = mCityInfoList.count();
   205 
   201 
   206 	if (cityInfoCount) {
   202 	if (cityInfoCount) {
   207 		QStandardItem *item = 0;
   203 		QStandardItem *item = 0;
   208 		for (int infoIndex = 0; infoIndex < cityInfoCount; infoIndex++) {
   204 		for (int infoIndex = 0; infoIndex < cityInfoCount; infoIndex++) {
   209 			item = mCityListModel->item(infoIndex);
   205 			item = mCityListModel->item(infoIndex);
   210 
   206 			item->setData(
   211 			QDateTime dateTime = QDateTime::currentDateTime();
   207 					getCityListDisplayString(mCityInfoList.at(infoIndex)),
   212 			dateTime = dateTime.toUTC();
   208 					Qt::DisplayRole);
   213 			dateTime = dateTime.addSecs(
   209 			item->setData(
   214 					mCityInfoList.at(infoIndex).zoneOffset * 60);
   210 					getCityListDecorationString(mCityInfoList.at(infoIndex)),
   215 
   211 					Qt::DecorationRole);
   216 			// Display day/night indicators.
       
   217 			QString dayNightIconPath = "";
       
   218 			if (isDay(dateTime)) {
       
   219 				dayNightIconPath = ":/clock/day";
       
   220 			} else {
       
   221 				dayNightIconPath = ":/clock/night";
       
   222 			}
       
   223 			item->setData(dayNightIconPath, Qt::UserRole + 1000);
       
   224 
       
   225 			// Update the date info.
       
   226 			QString dateInfo = dateTime.toString(
       
   227 					mSettingsUtility->dateFormatString());
       
   228 			if (dateTime.date() == QDate::currentDate()) {
       
   229 				dateInfo = tr("Today");
       
   230 			}
       
   231 			item->setData(dateInfo, Qt::UserRole + 1001);
       
   232 
       
   233 			// Set the DST icon.
       
   234 			QString dstIconPath = "";
       
   235 			if (mCityInfoList.at(infoIndex).dstOn) {
       
   236 				dstIconPath = ":/clock/dst_icon";
       
   237 			}
       
   238 			item->setData(dstIconPath, Qt::UserRole + 1004);
       
   239 
       
   240 			// Update the time info.
       
   241 			QString timeInfo = dateTime.toString(
       
   242 					mSettingsUtility->timeFormatString());
       
   243 			item->setData(timeInfo, Qt::UserRole + 1005);
       
   244 		}
   212 		}
   245 
   213 
   246 		// Start the timer again for one minute.
   214 		// Start the timer again for one minute.
   247 		QTimer::singleShot(60 * 1000, this, SLOT(refreshCityList()));
   215 		QTimer::singleShot(60 * 1000, this, SLOT(refreshCityList()));
   248 	}
   216 	}
   249 }
   217 }
   250 
   218 
   251 /*!
   219 /*!
   252 	Updates the clock display.
       
   253  */
       
   254 void ClockWorldView::updateClockDisplay()
       
   255 {
       
   256 //	mSkinnableClock->updateDisplay(true);
       
   257 }
       
   258 
       
   259 /*!
       
   260 	Updates the day-date info.
       
   261  */
       
   262 void ClockWorldView::updateDayDateInfo()
       
   263 {
       
   264 	// Get the current datetime.
       
   265 	QDateTime dateTime = QDateTime::currentDateTime();
       
   266 	QString dayName = dateTime.toString("dddd");
       
   267 
       
   268 	QString currentDate = mSettingsUtility->date();
       
   269 	// Construct the day + date string.
       
   270 	QString dayDateString;
       
   271 	dayDateString+= dayName;
       
   272 	dayDateString += " ";
       
   273 	dayDateString += currentDate;
       
   274 
       
   275 	mDayDateLabel->clear();
       
   276 	mDayDateLabel->setPlainText(dayDateString);
       
   277 }
       
   278 
       
   279 /*!
       
   280 	Updates the current location info.
   220 	Updates the current location info.
   281  */
   221  */
   282 void ClockWorldView::updateCurrentLocationInfo()
   222 void ClockWorldView::updateCurrentLocationInfo(int networkTime)
   283 {
   223 {
   284 	// Get the updated home city.
   224 	HbMainWindow *window = hbInstance->allMainWindows().first();
   285 	LocationInfo homeCity = mTimezoneClient->getCurrentZoneInfoL();
   225 	Qt::Orientation currentOrienation = window->orientation();
   286 
   226 	loadSection(currentOrienation);
   287 	// Construct the GMT +/- X string.
   227 
   288 	QString gmtOffset;
   228 	if (!networkTime) {
   289 
   229 		// Get the updated home city.
   290 	int utcOffset = homeCity.zoneOffset;
   230 		LocationInfo homeCity = mTimezoneClient->getCurrentZoneInfoL();
   291 	int offsetInHours (utcOffset/60);
   231 
   292 	int offsetInMinutes (utcOffset%60);
   232 		QMap<QString, QVariant> itemList;
   293 
   233 		QString value;
   294 	// Check wether the offset is +ve or -ve.
   234 		QDateTime dateTime = QDateTime::currentDateTime();
   295 	if (0 < utcOffset) {
   235 
   296 		// We have a positive offset. Append the '+' character.
   236 		// Show the date. If date is current date then show 'today'.
   297 		gmtOffset += tr(" +");
   237 		QString dateInfo = dateTime.toString(
   298 	} else if (0 > utcOffset) {
   238 				mSettingsUtility->dateFormatString());
   299 		// We have a negative offset. Append the '-' character.
   239 		itemList.insert(value.setNum(ClockHomeCityItem::Date), dateInfo);
   300 		gmtOffset += tr(" -");
   240 
   301 		offsetInHours = -offsetInHours;
   241 		// Show the city and country name.
   302 	} else {
   242 		QString placeInfo =
   303 		// We dont have an offset. We are at GMT zone.
   243 				homeCity.cityName + tr(", ") + homeCity.countryName;
   304 	}
   244 		itemList.insert(value.setNum(ClockHomeCityItem::City), placeInfo);
   305 
   245 
   306 	// Append the hour component.
   246 		// Show the time at that location.
   307 	gmtOffset += QString::number(offsetInHours);
   247 		QString timeInfo = dateTime.toString(
   308 
   248 				mSettingsUtility->timeFormatString());
   309 	// Get the time separator from settings and append it.
   249 		itemList.insert(value.setNum(ClockHomeCityItem::Time), timeInfo);
   310 	QStringList timeSeparatorList;
   250 
   311 	int index = mSettingsUtility->timeSeparator(timeSeparatorList);
   251 		//Use the home city specific icons.
   312 	gmtOffset += timeSeparatorList.at(index);
   252 		// Display day/night indicators.
   313 
   253 		QString dayNightIconPath = "";
   314 	// Append the minute component.
   254 		if (isDay(dateTime)) {
   315 	// If minute component is less less than 10, append a '00'
   255 			dayNightIconPath = "qtg_large_clock_home";
   316 	if (0 <= offsetInMinutes && offsetInMinutes < 10) {
   256 		} else {
   317 		gmtOffset += tr("00");
   257 			dayNightIconPath = "qtg_large_clock_night_home";
   318 	} else {
   258 		}
   319 		gmtOffset += QString::number(offsetInMinutes);
   259 		itemList.insert(value.setNum(
   320 	}
   260 				ClockHomeCityItem::DayNightIndicator), dayNightIconPath);
   321 
   261 
   322 	// Append space.
   262 		// Show dst icon when needed.
   323 	gmtOffset += tr(" ");
   263 		if (homeCity.dstOn) {
   324 
   264 			QString dstIconPath = "qtg_mono_day_light_saving_time";
   325 	// Append GMT sting.
   265 			itemList.insert(value.setNum(ClockHomeCityItem::Dst), dstIconPath);
   326 	gmtOffset += hbTrId("txt_common_common_gmt");
   266 		}
   327 
   267 		mHomeCityWidget->setHomeCityItemData(itemList);
   328 	// Append space.
   268 	}
   329 	gmtOffset += tr(" ");
   269 }
   330 
   270 
   331 	// Append DST info.
   271 /*!
   332 	if (homeCity.dstOn) {
   272 	Handles the long press on each item in the citylist.
   333 		gmtOffset += hbTrId("txt_common_setlabel_dst");
   273 	Displays a list item specific context menu.
   334 	}
   274 
   335 
   275 	\param item The HbAbstractViewItem that was long pressed.
   336 	// Set the city and country name .
   276 	\param coords The position where mouse was pressed.
   337 	mPlaceLabel->clear();
   277  */
   338 	if (mTimezoneClient->timeUpdateOn()) {
       
   339 		mPlaceLabel->setPlainText(homeCity.countryName + tr(" ") + gmtOffset);
       
   340 	} else {
       
   341 		mPlaceLabel->setPlainText(
       
   342 				homeCity.cityName + tr(", ") + homeCity.countryName
       
   343 				+ tr(" ") + gmtOffset);
       
   344 	}
       
   345 }
       
   346 
       
   347 void ClockWorldView::handleItemLongPressed(
   278 void ClockWorldView::handleItemLongPressed(
   348 		HbAbstractViewItem *item, const QPointF &coords)
   279 		HbAbstractViewItem *item, const QPointF &coords)
   349 {
   280 {
   350 	// Get the ndex of the selected item.
   281 	// Get the ndex of the selected item.
   351 	mSelectedItem = item->modelIndex().row();
   282 	mSelectedItem = item->modelIndex().row();
   353 	// On long press we display item specific context menu.
   284 	// On long press we display item specific context menu.
   354 	HbMenu *itemContextMenu = new HbMenu();
   285 	HbMenu *itemContextMenu = new HbMenu();
   355 
   286 
   356 	// Add the actions to the context menu.
   287 	// Add the actions to the context menu.
   357 	mSetCurrentLocationAction = itemContextMenu->addAction(
   288 	mSetCurrentLocationAction = itemContextMenu->addAction(
   358 	    hbTrId("txt_clk_menu_set_as_current_location"));
   289 			hbTrId("txt_clk_menu_set_as_current_location"));
   359 	mRemoveCityAction = itemContextMenu->addAction(
   290 	mRemoveCityAction = itemContextMenu->addAction(
   360 	    hbTrId("txt_clk_menu_delete"));
   291 			hbTrId("txt_clk_menu_delete"));
   361 
       
   362 	connect(
       
   363 			mSetCurrentLocationAction, SIGNAL(triggered()),
       
   364 			this, SLOT(handleSetAsCurrentLocationAction()));
       
   365 	connect(
       
   366 			mRemoveCityAction, SIGNAL(triggered()),
       
   367 			this, SLOT(handleDeleteAction()));
       
   368 
   292 
   369 	// Show the menu.
   293 	// Show the menu.
   370 	itemContextMenu->exec(coords);
   294 	itemContextMenu->open(this, SLOT(selectedMenuAction(HbAction*)));
       
   295 	itemContextMenu->setPreferredPos(coords);
       
   296 	itemContextMenu->setAttribute( Qt::WA_DeleteOnClose,true);
   371 }
   297 }
   372 
   298 
   373 /*!
   299 /*!
   374 	This slot is called when Add location action is triggered. It is responsible
   300 	This slot is called when Add location action is triggered. It is responsible
   375 	for launching the city selection list.
   301 	for launching the city selection list.
   391 	the view.
   317 	the view.
   392  */
   318  */
   393 void ClockWorldView::handleDeleteAction()
   319 void ClockWorldView::handleDeleteAction()
   394 {
   320 {
   395 	if (-1 != mSelectedItem) {
   321 	if (-1 != mSelectedItem) {
   396 		int temp = mCityListModel->rowCount();
       
   397 
       
   398 		QStandardItem *item = mCityListModel->takeItem(mSelectedItem);
   322 		QStandardItem *item = mCityListModel->takeItem(mSelectedItem);
   399 		mCityListModel->removeRow(mSelectedItem);
   323 		mCityListModel->removeRow(mSelectedItem);
   400 		delete item;
   324 		delete item;
   401 
   325 
   402 		temp = mCityListModel->rowCount();
       
   403 
       
   404 		mCityInfoList.removeAt(mSelectedItem);
   326 		mCityInfoList.removeAt(mSelectedItem);
   405 		mSelectedItem = -1;
   327 		mSelectedItem = -1;
   406 
   328 
   407 		// Update the data file.
   329 		// Update the data file.
   408 		mTimezoneClient->saveLocations(mCityInfoList);
   330 		mTimezoneClient->saveLocations(mCityInfoList);
   409 
   331 
   410 		if (mCityInfoList.count() <= 0) {
   332 		if (mCityInfoList.count() <= 0) {
   411 			// No need to refresh the list anymore.
   333 			// No need to refresh the list anymore.
   412 			mRefreshTimer->stop();
   334 			mRefreshTimer->stop();
       
   335 		} else if (mCityInfoList.count() < (KMaximumCityListCount-1) &&
       
   336 				!mAddCityAction->isEnabled()) {
       
   337 			mAddCityAction->setEnabled(true);
       
   338 			mAddCityMenuAction->setVisible(true);
   413 		}
   339 		}
   414 	}
   340 	}
   415 }
   341 }
   416 
   342 
   417 /*!
   343 /*!
   418 	This slot sets the selected city as the current location.
   344 	This slot sets the selected city as the current location.
   419  */
   345  */
   420 void ClockWorldView::handleSetAsCurrentLocationAction()
   346 void ClockWorldView::handleSetAsCurrentLocationAction()
   421 {
   347 {
       
   348 	// Get the info of the selected item.
       
   349 	LocationInfo newHomeCity = mCityInfoList[mSelectedItem];
       
   350 
   422 	// Check if time update is set to ON.
   351 	// Check if time update is set to ON.
   423 	// If yes, reset it to OFF and change the home location.
   352 	// If yes, reset it to OFF and change the home location.
   424 	if (mTimezoneClient->timeUpdateOn()) {
   353 	if (mTimezoneClient->timeUpdateOn()) {
   425 		mTimezoneClient->setTimeUpdateOn(false);
   354 		mTimezoneClient->setTimeUpdateOn(false);
       
   355 
       
   356 		QStandardItem *item = mCityListModel->takeItem(mSelectedItem);
       
   357 		mCityListModel->removeRow(mSelectedItem);
       
   358 		delete item;
       
   359 
       
   360 		mCityInfoList.removeAt(mSelectedItem);
   426 	} else {
   361 	} else {
   427 		// The current location and home city should be swapped.
   362 		// The current location and home city should be swapped.
   428 		// Store the info of current home city.
   363 		// Store the info of current home city.
   429 		LocationInfo oldHomeCity = mTimezoneClient->getCurrentZoneInfoL();
   364 		LocationInfo oldHomeCity = mTimezoneClient->getCurrentZoneInfoL();
   430 		// Get the info of the selected item.
       
   431 		LocationInfo newHomeCity = mCityInfoList[mSelectedItem];
       
   432 
       
   433 		QStandardItem *cityItem = mCityListModel->item(mSelectedItem);
       
   434 		QDateTime dateTime = QDateTime::currentDateTime();
       
   435 
       
   436 		// Display day/night indicators.
       
   437 		QString dayNightIconPath = "";
       
   438 		if (isDay(dateTime)) {
       
   439 			dayNightIconPath = ":/clock/day";
       
   440 		} else {
       
   441 			dayNightIconPath = ":/clock/night";
       
   442 		}
       
   443 		cityItem->setData(dayNightIconPath, Qt::UserRole + 1000);
       
   444 
       
   445 		// Date.
       
   446 		QString dateString = dateTime.toString(
       
   447 				mSettingsUtility->dateFormatString());
       
   448 		if (dateTime.date() == QDate::currentDate()) {
       
   449 			dateString = tr("Today");
       
   450 			}
       
   451 		cityItem->setData(dateString, Qt::UserRole + 1001);
       
   452 
       
   453 		// The city/country name.
       
   454 		QString placeInfo =
       
   455 				oldHomeCity.cityName + tr(", ") + oldHomeCity.countryName;
       
   456 		cityItem->setData(placeInfo, Qt::UserRole + 1002);
       
   457 
       
   458 		// Dst icon.
       
   459 		QString dstIconPath = "";
       
   460 		if (oldHomeCity.dstOn) {
       
   461 			dstIconPath = ":/clock/dst_icon";
       
   462 		}
       
   463 		cityItem->setData(dstIconPath, Qt::UserRole + 1004);
       
   464 
       
   465 		// Time.
       
   466 		QString timeString = dateTime.toString(
       
   467 				mSettingsUtility->timeFormatString());
       
   468 		cityItem->setData(timeString, Qt::UserRole + 1005);
       
   469 
   365 
   470 		// Update the info list.
   366 		// Update the info list.
   471 		mCityInfoList.removeAt(mSelectedItem);
   367 		mCityInfoList.removeAt(mSelectedItem);
   472 		mCityInfoList.insert(mSelectedItem, oldHomeCity);
   368 		mCityInfoList.insert(mSelectedItem, oldHomeCity);
   473 		// Update the home city with the timezone server.
   369 
   474 		mTimezoneClient->setAsCurrentLocationL(newHomeCity);
   370 	}
   475 
   371 	// Update the home city with the timezone server.
   476 		// Update the current location info.
   372 	mTimezoneClient->setAsCurrentLocationL(newHomeCity);
   477 		updateCurrentLocationInfo();
   373 
   478 
   374 	// Update the current location info.
   479 		// Update the offset difference in each list item.
   375 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
   480 		updateOffsetDifferences();
   376 
   481 	}
   377 	// Update the offset difference in each list item.
       
   378 	refreshCityList();
   482 
   379 
   483 	// Update the data file.
   380 	// Update the data file.
   484 	mTimezoneClient->saveLocations(mCityInfoList);
   381 	mTimezoneClient->saveLocations(mCityInfoList);
   485 	mSelectedItem = -1;
   382 	mSelectedItem = -1;
   486 }
   383 }
   497 	// that case.
   394 	// that case.
   498 	if (-1 != info.timezoneId) {
   395 	if (-1 != info.timezoneId) {
   499 		// Now we check if the city is already added in the list.
   396 		// Now we check if the city is already added in the list.
   500 		bool proceed = true;
   397 		bool proceed = true;
   501 		for (int i = 0; i < mCityInfoList.count(); i++) {
   398 		for (int i = 0; i < mCityInfoList.count(); i++) {
   502 			if (info.timezoneId == mCityInfoList.at(i).timezoneId) {
   399 			if (info.timezoneId == mCityInfoList.at(i).timezoneId
       
   400 					&& (info.cityName == mCityInfoList.at(i).cityName)
       
   401 					&& (info.countryName == mCityInfoList.at(i).countryName) ) {
   503 				proceed = false;
   402 				proceed = false;
   504 				break;
   403 				break;
   505 			}
   404 			}
   506 		}
   405 		}
   507 
   406 
       
   407 		LocationInfo currentCity = mTimezoneClient->getCurrentZoneInfoL();
   508 		// Check if the selected city is not the home city.
   408 		// Check if the selected city is not the home city.
   509 		if (info.timezoneId
   409 		if (
   510 				== mTimezoneClient->getCurrentZoneInfoL().timezoneId) {
   410 				(info.timezoneId == currentCity.timezoneId)
       
   411 				&& (info.cityName == currentCity.cityName)
       
   412 				&& (info.countryName == currentCity.countryName)) {
   511 			proceed = false;
   413 			proceed = false;
   512 		}
   414 		}
   513 
   415 
   514 		if (proceed) {
   416 		if (proceed) {
   515 			// This is new city totally. So add it.
   417 			// This is new city totally. So add it.
   526 				int after = 60 - currentTime.second();
   428 				int after = 60 - currentTime.second();
   527 				mRefreshTimer->start(after * 1000);
   429 				mRefreshTimer->start(after * 1000);
   528 			}
   430 			}
   529 		}
   431 		}
   530 	}
   432 	}
   531 
   433 	if ((KMaximumCityListCount-1) == mCityInfoList.count() &&
       
   434 			mAddCityAction->isEnabled()) {
       
   435 		mAddCityAction->setEnabled(false);
       
   436 		mAddCityMenuAction->setVisible(false);
       
   437 	}
   532 	// Cleanup.
   438 	// Cleanup.
   533 	mCitySelectionList->deleteLater();
   439 	mCitySelectionList->deleteLater();
   534 }
   440 }
   535 
   441 
   536 /*!
   442 /*!
   537 	Navigates to the clock alarms view.
   443 	Navigates to the clock alarms view.
   538  */
   444  */
   539 
       
   540 void ClockWorldView::showAlarmsView()
   445 void ClockWorldView::showAlarmsView()
   541 {
   446 {
   542 	qDebug() << "clock: ClockWorldView::showAlarmsView -->";
       
   543 
       
   544 	mAppControllerIf->switchToView(MainView);
   447 	mAppControllerIf->switchToView(MainView);
   545 
   448 }
   546 	qDebug() << "clock: ClockWorldView::showAlarmsView <--";
   449 
   547 }
   450 /*!
   548 
   451 	Slot which gets called when `World Clock' action is triggered from the view
   549 /*!
   452 	toolbar. This is responsible for reloading the content of worldclock view.
   550 	Updates the offset difference shown in each item with respect to the home
       
   551 	city.
       
   552  */
       
   553 void ClockWorldView::updateOffsetDifferences()
       
   554 {
       
   555 	// Get the home city information.
       
   556 	LocationInfo homeCityInfo = mTimezoneClient->getCurrentZoneInfoL();
       
   557 
       
   558 	for (int iter = 0; iter < mCityListModel->rowCount(); iter++) {
       
   559 		QModelIndex index = mCityListModel->index(iter, 0);
       
   560 		LocationInfo cityInfo = mCityInfoList[iter];
       
   561 
       
   562 		// Find out if the city being added has an offset greater than or less
       
   563 		// than the homecity offset.
       
   564 		QString offsetDifference;
       
   565 		if (cityInfo.zoneOffset < homeCityInfo.zoneOffset) {
       
   566 			offsetDifference += "-";
       
   567 		} else if (cityInfo.zoneOffset > homeCityInfo.zoneOffset) {
       
   568 			offsetDifference += "+";
       
   569 		}
       
   570 		// Now get the hours and minutes.
       
   571 		int difference =
       
   572 				qAbs(homeCityInfo.zoneOffset - cityInfo.zoneOffset);
       
   573 		int hours = difference / 60;
       
   574 		int minutes = difference % 60;
       
   575 		offsetDifference += QString::number(hours);
       
   576 		offsetDifference += "hrs";
       
   577 		if (minutes) {
       
   578 			offsetDifference += ", ";
       
   579 			offsetDifference += QString::number(minutes);
       
   580 			offsetDifference += "mins";
       
   581 		}
       
   582 		// TODO : Need to enable these code once we recieve the localisation.
       
   583 		/*QString displayFormat = tr("%1hrs, %2mins");
       
   584 		QString offsetString = displayFormat.arg(hours, minutes);
       
   585 		offsetDifference += offsetString;*/
       
   586 		mCityListModel->setData(index, offsetDifference, Qt::UserRole + 1003);
       
   587 	}
       
   588 }
       
   589 
       
   590 /*!
       
   591     Slot which gets called when `World Clock' action is triggered from the view
       
   592     toolbar. This is responsible for reloading the content of the world clock view.
       
   593  */
   453  */
   594 void ClockWorldView::refreshWorldView()
   454 void ClockWorldView::refreshWorldView()
   595 {
   455 {
   596     qDebug() << "clock: ClockWorldView::refreshWorldView -->";
       
   597 
       
   598 	mDisplayWorldClockView->setChecked(true);
   456 	mDisplayWorldClockView->setChecked(true);
   599 
   457 }
   600     qDebug() << "clock: ClockWorldView::refreshWorldView <--";
   458 
   601 }
   459 /*!
   602 
   460 	Loads the appropriate section based on window orientaion.
   603 /*!
   461  */
   604 	Slot to handle orientation changes
   462 void ClockWorldView::loadSection(Qt::Orientation orientation)
   605  */
   463 {
   606 void ClockWorldView::updateToolbarTexts(Qt::Orientation currentOrientation)
   464 	bool networkTime = mTimezoneClient->timeUpdateOn();
   607 {
   465 	bool loadSuccess;
   608 	if (Qt::Horizontal == currentOrientation) {
   466 	if (Qt::Horizontal == orientation) {
   609 		// Display toolbar item's texts
   467 		if (networkTime) {
   610 		// TODO to use text ids from ts file.
   468 			// Do not show home city.
   611 		mShowAlarmsViewAction->setText(tr("Alarms"));
   469 			mDocLoader->load(
   612 		mDisplayWorldClockView->setText(tr("World clock"));
   470 					CLOCK_WORLD_VIEW_DOCML,
   613 		mAddCityAction->setText(tr("Add city"));
   471 					CLOCK_WORLD_VIEW_LANDSCAPE_NOHOMECITY_SECTION,
   614 	} else if(Qt::Vertical == currentOrientation){
   472 					&loadSuccess);
   615 		// Remove toolbar item's texts as only icons are shown.
   473 			mHomeCityWidget->hide();
   616 		// TODO to use text ids from ts file.
   474 		} else {
   617 		mShowAlarmsViewAction->setText(tr(""));
   475 			mDocLoader->load(
   618 		mDisplayWorldClockView->setText(tr(""));
   476 					CLOCK_WORLD_VIEW_DOCML,
   619 		mAddCityAction->setText("");
   477 					CLOCK_WORLD_VIEW_LANDSCAPE_HOMECITY_SECTION,
       
   478 					&loadSuccess);
       
   479 			mHomeCityWidget->show();
       
   480 		}
       
   481 	} else if (Qt::Vertical == orientation) {
       
   482 		if (networkTime) {
       
   483 			// Do not show home city.
       
   484 			mDocLoader->load(
       
   485 					CLOCK_WORLD_VIEW_DOCML,
       
   486 					CLOCK_WORLD_VIEW_PORTRAIT_NOHOMECITY_SECTION,
       
   487 					&loadSuccess);
       
   488 			mHomeCityWidget->hide();
       
   489 		} else {
       
   490 			// Show home city.
       
   491 			mDocLoader->load(
       
   492 					CLOCK_WORLD_VIEW_DOCML,
       
   493 					CLOCK_WORLD_VIEW_PORTRAIT_HOMECITY_SECTION,
       
   494 					&loadSuccess);
       
   495 			mHomeCityWidget->show();
       
   496 		}
       
   497 	}
       
   498 	mCityListView->update();
       
   499 }
       
   500 
       
   501 /*!
       
   502 	Slot which gets called for timeChanged signal of timezone client.
       
   503 	Refreshes both homecity & city list.
       
   504  */
       
   505 void ClockWorldView::updateAllLocationInfo()
       
   506 {
       
   507 	updateCurrentLocationInfo(mTimezoneClient->timeUpdateOn());
       
   508 	updateCityList();
       
   509 	refreshCityList();
       
   510 }
       
   511 
       
   512 /*!
       
   513 	Slot to handle the selected context menu actions
       
   514  */
       
   515 void ClockWorldView::selectedMenuAction(HbAction *action)
       
   516 {
       
   517 	if (action == mSetCurrentLocationAction) {
       
   518 		handleSetAsCurrentLocationAction();
       
   519 	} else if (action == mRemoveCityAction) {
       
   520 		handleDeleteAction();
   620 	}
   521 	}
   621 }
   522 }
   622 
   523 
   623 /*!
   524 /*!
   624 	Adds the location info to the city list.
   525 	Adds the location info to the city list.
   628 QModelIndex ClockWorldView::addCityToList(const LocationInfo& locationInfo)
   529 QModelIndex ClockWorldView::addCityToList(const LocationInfo& locationInfo)
   629 {
   530 {
   630 	// Here we construct a model item and add it to the list model.
   531 	// Here we construct a model item and add it to the list model.
   631 	QStandardItem *modelItem = new QStandardItem();
   532 	QStandardItem *modelItem = new QStandardItem();
   632 
   533 
       
   534 	// Add the item to the model.
       
   535 	mCityListModel->appendRow(modelItem);
       
   536 
       
   537 	QModelIndex index = mCityListModel->indexFromItem(modelItem);
       
   538 	mCityListModel->setData(
       
   539 			index, getCityListDisplayString(locationInfo), Qt::DisplayRole);
       
   540 	mCityListModel->setData(
       
   541 			index, getCityListDecorationString(locationInfo),
       
   542 			Qt::DecorationRole);
       
   543 
       
   544 	return index;
       
   545 }
       
   546 
       
   547 /*!
       
   548 	Checks if the given time is day or night.
       
   549 	6:00 AM and 6:00 PM is considered as day. Otherwise night.
       
   550 
       
   551 	\param dateTime Time for which check has to be performed.
       
   552 	\return bool True if it is day otherwise false.
       
   553  */
       
   554 bool ClockWorldView::isDay(QDateTime dateTime)
       
   555 {
       
   556 	// It is day between 6:00 AM and 6:00 PM. Otherwise night.
       
   557 	if (17 < dateTime.time().hour() || 6 > dateTime.time().hour()) {
       
   558 		return false;
       
   559 	}
       
   560 	return true;
       
   561 }
       
   562 
       
   563 /*!
       
   564 	Returns the QVariantList for citylist to be set for DisplayRole.
       
   565 	
       
   566 	/param locationInfo Details of the city to be added to the list.
       
   567  */
       
   568 QVariantList ClockWorldView::getCityListDisplayString(
       
   569 		const LocationInfo& locationInfo)
       
   570 {
       
   571 	QVariantList displayString;
   633 	QDateTime dateTime = QDateTime::currentDateTime();
   572 	QDateTime dateTime = QDateTime::currentDateTime();
   634 	dateTime = dateTime.toUTC();
   573 	dateTime = dateTime.toUTC();
   635 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   574 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   636 
   575 
   637 	// Display day/night indicators.
       
   638 	QString dayNightIconPath = "";
       
   639 	if (isDay(dateTime)) {
       
   640 		dayNightIconPath = ":/clock/day";
       
   641 	} else {
       
   642 		dayNightIconPath = ":/clock/night";
       
   643 	}
       
   644 	modelItem->setData(dayNightIconPath, Qt::UserRole + 1000);
       
   645 
       
   646 	// Show the date. If date is current date then show 'today'.
   576 	// Show the date. If date is current date then show 'today'.
   647 	QString dateInfo = dateTime.toString(mSettingsUtility->dateFormatString());
   577 	QString dateInfo = dateTime.toString(mSettingsUtility->dateFormatString());
   648 	if (dateTime.date() == QDate::currentDate()) {
   578 	if (dateTime.date() == QDate::currentDate()) {
   649 		dateInfo = tr("Today");
   579 		dateInfo = hbTrId("txt_clock_main_view_dblist_daily_val_today");
   650 	}
   580 	}
   651 	modelItem->setData(dateInfo, Qt::UserRole + 1001);
   581 	displayString.append(dateInfo);
   652 
   582 
   653 	// Show the city and country name.
   583 	// Show the city and country name.
   654 	QString placeInfo =
   584 	QString placeInfo =
   655 			locationInfo.cityName + tr(", ") + locationInfo.countryName;
   585 			locationInfo.cityName + tr(", ") + locationInfo.countryName;
   656 	modelItem->setData(placeInfo, Qt::UserRole + 1002);
   586 	displayString.append(placeInfo);
   657 
   587 
   658 	// Get the homecity information.
   588 	// Get the homecity information.
   659 	LocationInfo homeCityInfo = mTimezoneClient->getCurrentZoneInfoL();
   589 	LocationInfo homeCityInfo = mTimezoneClient->getCurrentZoneInfoL();
   660 	// Find out if the city being added has an offset greater than or less than
   590 	// Find out if the city being added has an offset greater than or less than
   661 	// the homecity offset.
   591 	// the homecity offset.
   667 	}
   597 	}
   668 	// Now get the hours and minutes.
   598 	// Now get the hours and minutes.
   669 	int difference = qAbs(homeCityInfo.zoneOffset - locationInfo.zoneOffset);
   599 	int difference = qAbs(homeCityInfo.zoneOffset - locationInfo.zoneOffset);
   670 	int hours = difference / 60;
   600 	int hours = difference / 60;
   671 	int minutes = difference % 60;
   601 	int minutes = difference % 60;
       
   602 	QString displayFormat("");
       
   603 	QString offsetString("");
   672 
   604 
   673 	if ( hours && minutes ) {
   605 	if ( hours && minutes ) {
   674 		if (hours == 1) {
   606 		if (hours == 1) {
   675 			QString displayFormat =
   607 			displayFormat =
   676 					hbTrId("txt_clock_dblist_daily_val_1_hr_2_mins");
   608 					hbTrId("txt_clock_dblist_daily_val_1_hr_2_mins");
   677 			QString offsetString = displayFormat.arg(hours).arg(minutes);
   609 			offsetString = displayFormat.arg(hours).arg(minutes);
   678 			offsetDifference += offsetString;
   610 			offsetDifference += offsetString;
   679 		}
   611 		}
   680 		else {
   612 		else {
   681 			QString displayFormat =
   613 			displayFormat =
   682 					hbTrId("txt_clock_dblist_daily_val_1_hrs_2_mins");
   614 					hbTrId("txt_clock_dblist_daily_val_1_hrs_2_mins");
   683 			QString offsetString = displayFormat.arg(hours).arg(minutes);
   615 			offsetString = displayFormat.arg(hours).arg(minutes);
   684 			offsetDifference += offsetString;
   616 			offsetDifference += offsetString;
   685 		}
   617 		}
   686 	}
   618 	}
   687 	else if ( hours ){
   619 	else if ( hours ){
   688 		if(hours == 1 ) {
   620 		if(hours == 1 ) {
   689 			QString displayFormat = hbTrId("txt_clock_dblist_val_1_hr");
   621 			displayFormat = hbTrId("txt_clock_dblist_val_1_hr");
   690 			QString offsetString = displayFormat.arg(hours);
   622 			offsetString = displayFormat.arg(hours);
   691 			offsetDifference += offsetString;
   623 			offsetDifference += offsetString;
   692 		}
   624 		}
   693 		else {
   625 		else {
   694 			QString displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   626 			displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   695 			QString offsetString = displayFormat.arg(hours);
   627 			offsetString = displayFormat.arg(hours);
   696 			offsetDifference += offsetString;
   628 			offsetDifference += offsetString;
   697 		}
   629 		}
   698 	}
   630 	}
   699 	else if (minutes){
   631 	else if (minutes){
   700 		QString displayFormat = hbTrId("txt_clock_dblist_val_1_mins");
   632 		displayFormat = hbTrId("txt_clock_dblist_val_1_mins");
   701 		QString offsetString = displayFormat.arg(minutes);
   633 		offsetString = displayFormat.arg(minutes);
   702 		offsetDifference += offsetString;
   634 		offsetDifference += offsetString;
   703 	}
   635 	} else {
   704 
   636 		displayFormat = hbTrId("txt_clock_dblist_val_1_hrs");
   705 	modelItem->setData(offsetDifference, Qt::UserRole + 1003);
   637 		offsetString = displayFormat.arg(0);
   706 
   638 		offsetDifference += offsetString;
   707 	// Show dst icon when needed.
   639 	}
   708 	QString dstIconPath = "";
   640 	displayString.append(offsetDifference);
   709 	if (locationInfo.dstOn) {
       
   710 		dstIconPath = ":/clock/dst_icon";
       
   711 	}
       
   712 	modelItem->setData(dstIconPath, Qt::UserRole + 1004);
       
   713 
   641 
   714 	// Show the time at that location.
   642 	// Show the time at that location.
   715 	QString timeInfo = dateTime.toString(mSettingsUtility->timeFormatString());
   643 	QString timeInfo = dateTime.toString(mSettingsUtility->timeFormatString());
   716 	modelItem->setData(timeInfo, Qt::UserRole + 1005);
   644 	displayString.append(timeInfo);
   717 
   645 
   718 	// Add the item to the model.
   646 	return displayString;
   719 	mCityListModel->appendRow(modelItem);
   647 }
   720 
   648 
   721 	return(mCityListModel->indexFromItem(modelItem));
   649 /*!
   722 }
   650 	Returns the QVariantList for citylist to be set for DecorationRole.
   723 
   651 
   724 /*!
   652 	/param locationInfo Details of the city to be added to the list.
   725 	Checks if the given time is day or night.
   653  */
   726 	6:00 AM and 6:00 PM is considered as day. Otherwise night.
   654 QVariantList ClockWorldView::getCityListDecorationString(
   727 
   655 		const LocationInfo& locationInfo)
   728 	\param dateTime Time for which check has to be performed.
   656 {
   729 	\return bool True if it is day otherwise false.
   657 	QVariantList decorationString;
   730  */
   658 	QDateTime dateTime = QDateTime::currentDateTime();
   731 bool ClockWorldView::isDay(QDateTime dateTime)
   659 	dateTime = dateTime.toUTC();
   732 {
   660 	dateTime = dateTime.addSecs(locationInfo.zoneOffset * 60);
   733 	// It is day between 6:00 AM and 6:00 PM. Otherwise night.
   661 
   734 	if (17 < dateTime.time().hour() || 6 > dateTime.time().hour()) {
   662 	// Display day/night indicators.
   735 		return false;
   663 	// TODO: change the icon name for night when available.
   736 	}
   664 	QString dayNightIconPath = "";
   737 	return true;
   665 	if (isDay(dateTime)) {
       
   666 		dayNightIconPath = "qtg_large_clock";
       
   667 	} else {
       
   668 		dayNightIconPath = "qtg_large_clock_night";
       
   669 	}
       
   670 	decorationString.append(HbIcon(dayNightIconPath));
       
   671 
       
   672 	// Show dst icon when needed.
       
   673 	if (locationInfo.dstOn) {
       
   674 		QString dstIconPath = "qtg_mono_day_light_saving_time";
       
   675 		decorationString.append(HbIcon(dstIconPath));
       
   676 	}
       
   677 	return decorationString;
       
   678 	
       
   679 }
       
   680 
       
   681 /*!
       
   682 	Updates the city list according to the home city.
       
   683  */
       
   684 void ClockWorldView::updateCityList()
       
   685 {
       
   686 	int cityInfoCount = mCityInfoList.count();
       
   687 
       
   688 	if (cityInfoCount) {
       
   689 		bool deletion = false;
       
   690 		int index;
       
   691 		LocationInfo currentCity = mTimezoneClient->getCurrentZoneInfoL();
       
   692 		for (index = 0; index < cityInfoCount; index++) {
       
   693 			if (currentCity.timezoneId == mCityInfoList.at(index).timezoneId
       
   694 					&& (currentCity.cityName ==
       
   695 							mCityInfoList.at(index).cityName)
       
   696 					&& (currentCity.countryName ==
       
   697 							mCityInfoList.at(index).countryName) ) {
       
   698 				deletion = true;
       
   699 				break;
       
   700 			}
       
   701 		}
       
   702 		if (deletion) {
       
   703 			QStandardItem *item = mCityListModel->takeItem(index);
       
   704 			mCityListModel->removeRow(index);
       
   705 			delete item;
       
   706 
       
   707 			mCityInfoList.removeAt(index);
       
   708 			index = -1;
       
   709 
       
   710 			// Update the data file.
       
   711 			mTimezoneClient->saveLocations(mCityInfoList);
       
   712 
       
   713 			if (mCityInfoList.count() <= 0) {
       
   714 				// No need to refresh the list anymore.
       
   715 				mRefreshTimer->stop();
       
   716 			} else if (mCityInfoList.count() < (KMaximumCityListCount-1) &&
       
   717 					!mAddCityAction->isEnabled()) {
       
   718 				mAddCityAction->setEnabled(true);
       
   719 				mAddCityMenuAction->setVisible(true);
       
   720 			}
       
   721 			
       
   722 		}
       
   723 	}
   738 }
   724 }
   739 
   725 
   740 // End of file-- Don't delete.
   726 // End of file-- Don't delete.