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