clock/clockui/clockviews/src/clockmainview.cpp
changeset 18 c198609911f9
child 26 a949c2543c15
child 45 b6db4fd4947b
equal deleted inserted replaced
0:f979ecb2b13e 18:c198609911f9
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Definition file for class ClockMainView.
       
    16 *
       
    17 */
       
    18 
       
    19 // System includes
       
    20 #include <QGraphicsItem>
       
    21 #include <QDebug>
       
    22 #include <HbInstance>
       
    23 #include <HbLabel>
       
    24 #include <HbAbstractViewItem>
       
    25 #include <HbMenu>
       
    26 #include <HbAction>
       
    27 #include <HbListView>
       
    28 #include <HbNotificationDialog>
       
    29 #include <HbStyleLoader>
       
    30 
       
    31 // User includes
       
    32 #include "clockmainview.h"
       
    33 #include "clockdocloader.h"
       
    34 #include "clockappcontrollerif.h"
       
    35 #include "alarmclient.h"
       
    36 #include "clocksettingsview.h"
       
    37 #include "clockcommon.h"
       
    38 #include "clockalarmeditor.h"
       
    39 #include "settingsutility.h"
       
    40 #include "timezoneclient.h"
       
    41 #include "clockalarmlistitemprototype.h"
       
    42 #include "skinnableclock.h"
       
    43 #include "clockalarmlistmodel.h"
       
    44 
       
    45 /*!
       
    46 	\class ClockMainView
       
    47 
       
    48 	The main view of the clock application.
       
    49  */
       
    50 
       
    51 /*!
       
    52 	Constructor.
       
    53 
       
    54 	\param parent The parent of type QGraphicsWidget.
       
    55  */
       
    56 ClockMainView::ClockMainView(QGraphicsItem *parent)
       
    57 :HbView(parent),
       
    58  mAlarmList(0),
       
    59  mSelectedItem(-1)
       
    60 {
       
    61 	qDebug("clock: ClockMainView::ClockMainView() -->");
       
    62 
       
    63 	qDebug("clock: ClockMainView::ClockMainView() <--");
       
    64 }
       
    65 
       
    66 /*!
       
    67 	Destructor.
       
    68  */
       
    69 ClockMainView::~ClockMainView()
       
    70 {
       
    71 	qDebug("clock: ClockMainView::~ClockMainView() -->");
       
    72 
       
    73 	if (mDocLoader) {
       
    74 		delete mDocLoader;
       
    75 		mDocLoader = 0;
       
    76 	}
       
    77 	if (mAlarmListModel) {
       
    78 		delete mAlarmListModel;
       
    79 		mAlarmListModel = 0;
       
    80 	}
       
    81 
       
    82 	qDebug("clock: ClockMainView::~ClockMainView() <--");
       
    83 }
       
    84 
       
    85 /*!
       
    86 	Called by the ClockViewManager after loading the view from the docml.
       
    87 	The initializaion/setup of the view is done here.
       
    88 
       
    89 	\param controller The ClockAppController object.
       
    90 	\param docLoader Pointer to ClockDocLoader object.
       
    91  */
       
    92 void ClockMainView::setupView(
       
    93 		ClockAppControllerIf &controllerIf, ClockDocLoader *docLoader)
       
    94 {
       
    95 	qDebug("clock: ClockMainView::setupView() -->");
       
    96 
       
    97 	mDocLoader = docLoader;
       
    98 	mAppControllerIf = &controllerIf;
       
    99 
       
   100 	mTimezoneClient = controllerIf.timezoneClient();
       
   101 	mSettingsUtility = controllerIf.settingsUtility();
       
   102 	mAlarmClient = controllerIf.alarmClient();
       
   103 
       
   104 	// Create the model.
       
   105 	mAlarmListModel =  new ClockAlarmListModel(*mAppControllerIf, this);
       
   106 	connect(
       
   107 			mAlarmListModel, SIGNAL(changeAlarmListDisplay()),
       
   108 			this, SLOT(handleAlarmListDisplay()));
       
   109 
       
   110 	QList<AlarmInfo> alarmInfoList;
       
   111 	// Get the list of pending clock alarms.
       
   112 	mAlarmClient->getAlarmList(alarmInfoList);
       
   113 	QList<AlarmInfo> displayInfoList;
       
   114 	AlarmInfo alarmInfo;
       
   115 	for (int index = 0; index < alarmInfoList.count(); ++index) {
       
   116 		alarmInfo = alarmInfoList[index];
       
   117 		if (Notified == alarmInfo.alarmState) {
       
   118 			continue;
       
   119 		}
       
   120 		displayInfoList.append(alarmInfo);
       
   121 	}
       
   122 	int alarmCount = displayInfoList.count();
       
   123 
       
   124 
       
   125 	connect(
       
   126 			mTimezoneClient, SIGNAL(timechanged()),
       
   127 			this, SLOT(updatePlaceLabel()));
       
   128 	connect(
       
   129 			mTimezoneClient, SIGNAL(timechanged()),
       
   130 			this, SLOT(updateDateLabel()));
       
   131 	connect(
       
   132 			mTimezoneClient, SIGNAL(timechanged()),
       
   133 			this, SLOT(updateClockWidget()));
       
   134 
       
   135 	HbMainWindow *window = hbInstance->allMainWindows().first();
       
   136 
       
   137 	bool loadSuccess = false;
       
   138 	Qt::Orientation currentOrienation = window->orientation();
       
   139 
       
   140 	// Get the "No alarm set" label.
       
   141 	mNoAlarmLabel = qobject_cast<HbLabel *> (
       
   142 			mDocLoader->findWidget(CLOCK_NOALARMLABEL));
       
   143 
       
   144 	// Get the alarm's list.
       
   145 	mAlarmList = qobject_cast<HbListView *> (
       
   146 			mDocLoader->findWidget(CLOCK_ALARMLIST));
       
   147 
       
   148 	connect(
       
   149 			mAlarmList, SIGNAL(activated(const QModelIndex &)),
       
   150 			this, SLOT(handleActivated(const QModelIndex &)));
       
   151 
       
   152 	connect(
       
   153 			mAlarmList,
       
   154 			SIGNAL(longPressed(HbAbstractViewItem*, const QPointF&)),
       
   155 			this,
       
   156 			SLOT(handleLongPress(HbAbstractViewItem*, const QPointF&)));
       
   157 
       
   158 	HbStyleLoader::registerFilePath(CLOCK_VIEWS_STYLE_PATH);
       
   159 	setmodel();
       
   160 
       
   161 	// Load the correct section based on orientation.
       
   162 	if (Qt::Vertical == currentOrienation) {
       
   163 		mDocLoader->load(
       
   164 				CLOCK_MAIN_VIEW_DOCML,
       
   165 				CLOCK_MAIN_VIEW_PORTRAIT_SECTION,
       
   166 				&loadSuccess);
       
   167 	} else {
       
   168 		mDocLoader->load(
       
   169 				CLOCK_MAIN_VIEW_DOCML,
       
   170 				CLOCK_MAIN_VIEW_LANDSCAPE_SECTION,
       
   171 				&loadSuccess);
       
   172 	}
       
   173 	if (loadSuccess) {
       
   174 		if (0 == alarmCount) {
       
   175 			hideAlarmList(true);
       
   176 		} else {
       
   177 			hideAlarmList(false);
       
   178 			mAlarmListModel->populateModel();
       
   179 		}
       
   180 	}
       
   181 
       
   182 	// Get the toolbar/menu actions.
       
   183 	mRefreshMainView = static_cast<HbAction *> (
       
   184 			mDocLoader->findObject("alarmsAction"));
       
   185 
       
   186 	mRefreshMainView->setCheckable(true);
       
   187 	mRefreshMainView->setChecked(true);
       
   188 
       
   189 	connect(
       
   190 			mRefreshMainView, SIGNAL(changed()),
       
   191 			this, SLOT(refreshMainView()));
       
   192 
       
   193 	mDisplayWorldClockView = static_cast<HbAction *> (
       
   194 			mDocLoader->findObject("worldClockAction"));
       
   195 	connect(
       
   196 			mDisplayWorldClockView, SIGNAL(triggered()),
       
   197 			this, SLOT(displayWorldClockView()));
       
   198 
       
   199 	mAddNewAlarm = static_cast<HbAction *> (
       
   200 			mDocLoader->findObject("newAlarmAction"));
       
   201 	connect(
       
   202 			mAddNewAlarm, SIGNAL(triggered()),
       
   203 			this, SLOT(addNewAlarm()));
       
   204 
       
   205 	if (Qt::Vertical == currentOrienation) {
       
   206 		// Remove toolbar item's texts as only icons are shown.
       
   207 		// TODO to use text ids from ts file.
       
   208 		mRefreshMainView->setText(tr(""));
       
   209 		mDisplayWorldClockView->setText(tr(""));
       
   210 		mAddNewAlarm->setText("");
       
   211 	} else if (Qt::Horizontal == currentOrienation) {
       
   212 		// Display toolbar item's texts
       
   213 		// TODO to use text ids from ts file.
       
   214 		mRefreshMainView->setText(tr("Alarms"));
       
   215 		mDisplayWorldClockView->setText(tr("World clock"));
       
   216 		mAddNewAlarm->setText("New alarm");
       
   217 	}
       
   218 
       
   219 	mSettingsAction = static_cast<HbAction *> (
       
   220 			mDocLoader->findObject("settingsAction"));
       
   221 	connect(
       
   222 			mSettingsAction, SIGNAL(triggered()),
       
   223 			this, SLOT(openSettings()));
       
   224 
       
   225 	mDayLabel = static_cast<HbLabel *> (
       
   226 			mDocLoader->findObject("dateLabel"));
       
   227 
       
   228 	mPlaceLabel = static_cast<HbLabel *> (
       
   229 			mDocLoader->findObject("placeLabel"));
       
   230 
       
   231 	mClockWidget = static_cast<SkinnableClock *> (
       
   232 			mDocLoader->findObject("clockWidget"));
       
   233 
       
   234 	// Update the date info.
       
   235 	updateDateLabel();
       
   236 	// Update the place info.
       
   237 	updatePlaceLabel();
       
   238 	// Update clock widget display.
       
   239 	updateClockWidget();
       
   240 
       
   241 	// Connect to orientation change and load appropriate section.
       
   242 	connect(
       
   243 			window, SIGNAL(orientationChanged(Qt::Orientation)),
       
   244 			this, SLOT(checkOrientationAndLoadSection(Qt::Orientation)));
       
   245 
       
   246 	qDebug("clock: ClockMainView::setupView() <--");
       
   247 }
       
   248 
       
   249 /*!
       
   250 	Slot which gets called for the status change of the alarm i.e for
       
   251 	active/inactive.
       
   252 
       
   253 	\param row contains the row number of the alarm in the alarm list
       
   254  */
       
   255 void ClockMainView::handleAlarmStatusChanged(int row)
       
   256 {
       
   257 	qDebug() << "clock: ClockMainView::handleAlarmStatusChanged -->";
       
   258 
       
   259 	// Get the data for the alarm.
       
   260 	QList<QVariant> alarmData =
       
   261 			mAlarmListModel->sourceModel()->index(row, 0).data(
       
   262 					AlarmDetails).toList();
       
   263 	int alarmStatus = alarmData.at(2).value<int>();
       
   264 
       
   265 	mSelectedItem = row;
       
   266 
       
   267 	if (-1 < mSelectedItem) {
       
   268 		QList<QVariant> alarmData =
       
   269 				mAlarmListModel->sourceModel()->index(
       
   270 						mSelectedItem, 0).data(AlarmDetails).toList();
       
   271 		int alarmId = alarmData.at(0).value<int>();
       
   272 		QString displayNote;
       
   273 		// Activate or deactivate the alarm depending on the alarm status.
       
   274 		// Display the NotificationDialog with appropriate message.
       
   275 		if (!alarmStatus) {
       
   276 			mAlarmClient->toggleAlarmStatus(alarmId, Disabled);
       
   277 			displayNote.append(hbTrId("txt_clock_main_view_dpopinfo_alarm_deactivated"));
       
   278 			HbNotificationDialog::launchDialog(displayNote);
       
   279 		} else {
       
   280 			mAlarmClient->toggleAlarmStatus(alarmId, Enabled);
       
   281 			displayNote.append(hbTrId("txt_clock_main_view_dpopinfo_alarm_activated"));
       
   282 			HbNotificationDialog::launchDialog(displayNote);
       
   283 		}
       
   284 		mSelectedItem = -1;
       
   285 	}
       
   286 
       
   287 	qDebug() << "clock: ClockMainView::handleAlarmStatusChanged <--";
       
   288 }
       
   289 
       
   290 /*!
       
   291 	Slot which gets called when `Alarm' action is triggered from the view
       
   292 	toolbar. This is responsible for reloading the content of the main view.
       
   293  */
       
   294 void ClockMainView::refreshMainView()
       
   295 {
       
   296 	qDebug() << "clock: ClockMainView::refreshMainView -->";
       
   297 	mRefreshMainView->setChecked(true);
       
   298 
       
   299 	qDebug() << "clock: ClockMainView::refreshMainView <--";
       
   300 }
       
   301 
       
   302 /*!
       
   303 	Slot which gets called when `World clock' action is triggered from the view
       
   304 	toolbar. This is responsible for launching the world clock.
       
   305  */
       
   306 void ClockMainView::displayWorldClockView()
       
   307 {
       
   308 	qDebug() << "clock: ClockMainView::displayWorldClockView -->";
       
   309 
       
   310 	mAppControllerIf->switchToView(WorldClock);
       
   311 
       
   312 	qDebug() << "clock: ClockMainView::displayWorldClockView <--";
       
   313 }
       
   314 
       
   315 /*!
       
   316 	Slot which gets called when `New alarm' action is triggered from the view
       
   317 	toolbar. This is responsible for launching the editor to create a new alarm.
       
   318  */
       
   319 void ClockMainView::addNewAlarm()
       
   320 {
       
   321 	qDebug() << "clock: ClockMainView::addNewAlarm -->";
       
   322 
       
   323 	ClockAlarmEditor *alarmEditor = new ClockAlarmEditor();
       
   324 	alarmEditor->showAlarmEditor();
       
   325 
       
   326 	connect(
       
   327 			alarmEditor, SIGNAL(alarmSet()),
       
   328 			this, SLOT(handleAlarmSet()));
       
   329 
       
   330 	qDebug() << "clock: ClockMainView::addNewAlarm <--";
       
   331 }
       
   332 
       
   333 /*!
       
   334 	Slot which gets called when `Settings' action is triggered from the view
       
   335 	menu. This is responsible for launching the settings view.
       
   336  */
       
   337 void ClockMainView::openSettings()
       
   338 {
       
   339 	qDebug() << "clock: ClockMainView::openSettings -->";
       
   340 
       
   341 	// Create the settings view.
       
   342 	ClockSettingsView *settingsView = new ClockSettingsView(this);
       
   343 	settingsView->loadSettingsView();
       
   344 
       
   345 	qDebug() << "clock: ClockMainView::openSettings <--";
       
   346 }
       
   347 
       
   348 /*!
       
   349 	This slot handles the 'activated' signal of the alarm list. Opens the
       
   350 	alarm editor to edit the alarm.
       
   351 	\param index the modelIndex in the list which has been tapped.
       
   352  */
       
   353 void ClockMainView::handleActivated(const QModelIndex &index)
       
   354 {
       
   355 	qDebug() << "clock: ClockMainView::handleActivated -->";
       
   356 
       
   357 	// Get the data for the alarm.
       
   358 	int row = index.row();
       
   359 	QList<QVariant> alarmData =
       
   360 			mAlarmListModel->sourceModel()->index(row, 0).data(
       
   361 					AlarmDetails).toList();
       
   362 	int alarmId = alarmData.at(0).value<int>();
       
   363 
       
   364 	// Construct the alarm editor.
       
   365 	ClockAlarmEditor *alarmEditor = new ClockAlarmEditor(alarmId);
       
   366 	alarmEditor->showAlarmEditor();
       
   367 	connect(
       
   368 			alarmEditor, SIGNAL(alarmSet()),
       
   369 			this, SLOT(handleAlarmSet()));
       
   370 
       
   371 	qDebug() << "clock: ClockMainView::handleActivated <--";
       
   372 }
       
   373 
       
   374 /*!
       
   375 	This slot handles the 'longpressed' signal of the alarm list. Opens the
       
   376 	context menu.
       
   377 
       
   378 	\param item The item in the list which has been long pressed.
       
   379 	\param coords The position where mouse was pressed.
       
   380  */
       
   381 void ClockMainView::handleLongPress(
       
   382 		HbAbstractViewItem *item, const QPointF &coords)
       
   383 {
       
   384 	qDebug() << "clock: ClockMainView::handleLongPress -->";
       
   385 
       
   386 	AlarmInfo alarmInfo;
       
   387 
       
   388 	// Save the item row number where the long press was made.
       
   389 	mSelectedItem = item->modelIndex().row();
       
   390 
       
   391 	// Get the data for the alarm.
       
   392 	QList<QVariant> alarmData =
       
   393 			mAlarmListModel->sourceModel()->
       
   394 			index(mSelectedItem, 0).data(AlarmDetails).toList();
       
   395 	int alarmId = alarmData.at(0).value<int>();
       
   396 
       
   397 	mAlarmClient->getAlarmInfo(alarmId, alarmInfo);
       
   398 
       
   399 	// On long press we display item specific context menu.
       
   400 	HbMenu *itemContextMenu = new HbMenu();
       
   401 
       
   402 	// Add the delete action to the context menu.
       
   403 	HbAction *deleteAction = itemContextMenu->addAction(
       
   404 	    hbTrId("txt_clk_main_view_menu_delete_alarm"));
       
   405 	connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteAlarm()));
       
   406 
       
   407 	// Show the menu.
       
   408 	itemContextMenu->exec(coords);
       
   409 
       
   410 	qDebug() << "clock: ClockMainView::handleLongPress <--";
       
   411 }
       
   412 
       
   413 /*!
       
   414 	This slot handles the deletion of the alarm from the server.
       
   415 
       
   416  */
       
   417 void ClockMainView::deleteAlarm()
       
   418 {
       
   419 	qDebug() << "clock: ClockMainView::deleteAlarm -->";
       
   420 
       
   421 	if (-1 < mSelectedItem) {
       
   422 		// Get the data for the alarm.
       
   423 		QList<QVariant> alarmData = mAlarmListModel->sourceModel()->
       
   424 				index(mSelectedItem, 0).data(AlarmDetails).toList();
       
   425 		int alarmId = alarmData.at(0).value<int>();
       
   426 		mAlarmClient->deleteAlarm(alarmId);
       
   427 		mSelectedItem = -1;
       
   428 	}
       
   429 
       
   430 	qDebug() << "clock: ClockMainView::deleteAlarm <--";
       
   431 }
       
   432 
       
   433 /*!
       
   434 	Updates the day and date in the day label.
       
   435  */
       
   436 void ClockMainView::updateDateLabel()
       
   437 {
       
   438 	qDebug() << "clock: ClockMainView::updateDateLabel -->";
       
   439 
       
   440 	// Get the current datetime.
       
   441 	QDateTime dateTime = QDateTime::currentDateTime();
       
   442 	// Get the day name.
       
   443 	QString dayName = dateTime.toString("dddd");
       
   444 	// Get the date in correct format.
       
   445 	QString currentDate = mSettingsUtility->date();
       
   446 	// Construct the day + date string.
       
   447 	QString dayDateString;
       
   448 	dayDateString+= dayName;
       
   449 	dayDateString += " ";
       
   450 	dayDateString += currentDate;
       
   451 
       
   452 	mDayLabel->setPlainText(dayDateString);
       
   453 
       
   454 	qDebug() << "clock: ClockMainView::updateDateLabel <--";
       
   455 }
       
   456 
       
   457 /*!
       
   458 	Updates the zone info in the place label.
       
   459  */
       
   460 void ClockMainView::updatePlaceLabel()
       
   461 {
       
   462 	qDebug() << "clock: MainViewWidget::updateClockZoneInfo -->";
       
   463 
       
   464 	// Get the current zone info.
       
   465 	LocationInfo currentZoneInfo = mTimezoneClient->getCurrentZoneInfoL();
       
   466 
       
   467 	// Construct the GMT +/- X string.
       
   468 	QString gmtOffset;
       
   469 
       
   470 	int utcOffset = currentZoneInfo.zoneOffset;
       
   471 	int offsetInHours (utcOffset/60);
       
   472 	int offsetInMinutes (utcOffset%60);
       
   473 
       
   474 	// Check wether the offset is +ve or -ve.
       
   475 	if (0 < utcOffset) {
       
   476 		// We have a positive offset. Append the '+' character.
       
   477 		gmtOffset += tr(" +");
       
   478 	} else if (0 > utcOffset) {
       
   479 		// We have a negative offset. Append the '-' character.
       
   480 		gmtOffset += tr(" -");
       
   481 		offsetInHours = -offsetInHours;
       
   482 	} else {
       
   483 		// We dont have an offset. We are at GMT zone.
       
   484 	}
       
   485 
       
   486 	// Append the hour component.
       
   487 	gmtOffset += QString::number(offsetInHours);
       
   488 
       
   489 	// Get the time separator from settings and append it.
       
   490 	QStringList timeSeparatorList;
       
   491 	int index = mSettingsUtility->timeSeparator(timeSeparatorList);
       
   492 	gmtOffset += timeSeparatorList.at(index);
       
   493 
       
   494 	// Append the minute component.
       
   495 	// If minute component is less less than 10, append a '00'
       
   496 	if (0 <= offsetInMinutes && offsetInMinutes < 10) {
       
   497 		gmtOffset += tr("00");
       
   498 	} else {
       
   499 		gmtOffset += QString::number(offsetInMinutes);
       
   500 	}
       
   501 	
       
   502 	// Append space.
       
   503 	gmtOffset += tr(" ");
       
   504 	
       
   505 	// Append GMT sting.
       
   506 	gmtOffset += hbTrId("txt_common_common_gmt");
       
   507 	
       
   508 	// Append space.
       
   509 	gmtOffset += tr(" ");
       
   510 
       
   511 	// Append DST info.
       
   512 	if (currentZoneInfo.dstOn) {
       
   513 		gmtOffset += hbTrId("txt_common_setlabel_dst");
       
   514 	}
       
   515 
       
   516 	// Update the labels with the correct info.
       
   517 	mPlaceLabel->clear();
       
   518 	if (mTimezoneClient->timeUpdateOn()) {
       
   519 		mPlaceLabel->setPlainText(
       
   520 				currentZoneInfo.countryName + tr(" ") + gmtOffset);
       
   521 	} else {
       
   522 		mPlaceLabel->setPlainText(
       
   523 				currentZoneInfo.cityName + tr(", ")
       
   524 				+ currentZoneInfo.countryName + tr(" ") + gmtOffset);
       
   525 	}
       
   526 
       
   527 	qDebug() << "clock: MainViewWidget::updateDayDateInfo <--";
       
   528 }
       
   529 
       
   530 /*!
       
   531 	Updates the clock widget display.
       
   532  */
       
   533 void ClockMainView::updateClockWidget()
       
   534 {
       
   535 	qDebug() << "clock: ClockMainView::updateClockWidget -->";
       
   536 
       
   537 	mClockWidget->updateDisplay(true);
       
   538 
       
   539 	qDebug() << "clock: ClockMainView::updateClockWidget <--";
       
   540 }
       
   541 
       
   542 /*!
       
   543 	Slot to either hide or show the alarmlist.
       
   544  */
       
   545 void ClockMainView::handleAlarmListDisplay()
       
   546 {
       
   547 	qDebug() << "clock: ClockMainView::handleAlarmListDisplay -->";
       
   548 
       
   549 	// Get the list of pending clock alarms from server.
       
   550 	QList<AlarmInfo> alarmInfoList;
       
   551 	QList<AlarmInfo> displayInfoList;
       
   552 	AlarmInfo alarmInfo;
       
   553 	mAlarmClient->getAlarmList(alarmInfoList);
       
   554 	for (int index = 0; index < alarmInfoList.count(); ++index) {
       
   555 		alarmInfo = alarmInfoList[index];
       
   556 		if (Notified == alarmInfo.alarmState) {
       
   557 			continue;
       
   558 		}
       
   559 		displayInfoList.append(alarmInfo);
       
   560 	}
       
   561 	if (mHideAlarmList) {
       
   562 		hideAlarmList(false);
       
   563 	} else {
       
   564 		if (0 == displayInfoList.count() &&
       
   565 				0 == mAlarmListModel->sourceModel()->rowCount()) {
       
   566 			hideAlarmList(true);
       
   567 		}
       
   568 	}
       
   569 
       
   570 	qDebug() << "clock: ClockMainView::handleAlarmListDisplay <--";
       
   571 }
       
   572 
       
   573 /*!
       
   574 	Sets the model to the alarm list.
       
   575  */
       
   576 void ClockMainView::setmodel()
       
   577 {
       
   578 	qDebug() << "clock: ClockMainView::setmodel -->";
       
   579 
       
   580 	// Set the model.
       
   581 	if (mAlarmList) {
       
   582 		mAlarmList->setModel(mAlarmListModel->sourceModel());
       
   583 		ClockAlarmListItemPrototype *listItemPrototype =
       
   584 				new ClockAlarmListItemPrototype(this);
       
   585 		mAlarmList->setItemPrototype(listItemPrototype);
       
   586 		mAlarmList->setLayoutName("layout-alarmlist");
       
   587 	}
       
   588 
       
   589 	qDebug() << "clock: ClockMainView::setmodel <--";
       
   590 }
       
   591 
       
   592 /*!
       
   593 	Hides the alarmlist in the main view.
       
   594 
       
   595 	\param hide 'true' if alarm list is to be hidden.
       
   596  */
       
   597 void ClockMainView::hideAlarmList(bool hide)
       
   598 {
       
   599 	qDebug() << "clock: ClockMainView::hideAlarmList -->";
       
   600 
       
   601 	if (hide) {
       
   602 		mNoAlarmLabel->show();
       
   603 		mAlarmList->hide();
       
   604 		mHideAlarmList = true;
       
   605 	} else {
       
   606 		mAlarmList->show();
       
   607 		mNoAlarmLabel->hide();
       
   608 		mHideAlarmList = false;
       
   609 	}
       
   610 
       
   611 	qDebug() << "clock: ClockMainView::hideAlarmList <--";
       
   612 }
       
   613 
       
   614 /*!
       
   615 	Slot to check the orientation & load the appropriate section.
       
   616 
       
   617 	\param orientation contains the current orientation of the window.
       
   618  */
       
   619 void ClockMainView::checkOrientationAndLoadSection(
       
   620 		Qt::Orientation orientation)
       
   621 {
       
   622 	qDebug() << "clock: ClockMainView::checkOrientationAndLoadSection -->";
       
   623 
       
   624 	bool success;
       
   625 	// If horizontal, load the landscape section.
       
   626 	if (Qt::Horizontal == orientation) {
       
   627 		mDocLoader->load(
       
   628 				CLOCK_MAIN_VIEW_DOCML, CLOCK_MAIN_VIEW_LANDSCAPE_SECTION,
       
   629 				&success);
       
   630 
       
   631 		// Display toolbar item's texts
       
   632 		// TODO have to use text ids from ts file.
       
   633 		mRefreshMainView->setText(tr("Alarms"));
       
   634 		mDisplayWorldClockView->setText(tr("World clock"));
       
   635 		mAddNewAlarm->setText("New alarm");
       
   636 
       
   637 	} else {
       
   638 		mDocLoader->load(
       
   639 				CLOCK_MAIN_VIEW_DOCML, CLOCK_MAIN_VIEW_PORTRAIT_SECTION,
       
   640 				&success);
       
   641 
       
   642 		// Remove toolbar item's texts as only icons are shown.
       
   643 		// TODO have to use text ids from ts file.
       
   644 		mRefreshMainView->setText(tr(""));
       
   645 		mDisplayWorldClockView->setText(tr(""));
       
   646 		mAddNewAlarm->setText("");
       
   647 	}
       
   648 
       
   649 	if(success) {
       
   650 		QList<AlarmInfo> alarmInfoList;
       
   651 		// Get the list of all clock alarms.
       
   652 		mAlarmClient->getAlarmList(alarmInfoList);
       
   653 		if (0 == alarmInfoList.count()) {
       
   654 			hideAlarmList(true);
       
   655 		} else {
       
   656 			hideAlarmList(false);
       
   657 		}
       
   658 	}
       
   659 
       
   660 	qDebug() << "clock: ClockMainView::checkOrientationAndLoadSection <--";
       
   661 }
       
   662 
       
   663 // End of file	--Don't remove.