clock/clockui/clockviews/src/clockalarmlistmodel.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 57 bb2d3e476f29
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    15 * Definition file for class ClockAlarmListModel.
    15 * Definition file for class ClockAlarmListModel.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <QDebug>
       
    21 #include <QTimer>
    20 #include <QTimer>
    22 
    21 
    23 #include <QStandardItemModel>
    22 #include <QStandardItemModel>
    24 #include <QStandardItem>
    23 #include <QStandardItem>
    25 #include <HbIcon>
    24 #include <HbIcon>
    53 		ClockAppControllerIf &controllerIf, QObject *parent)
    52 		ClockAppControllerIf &controllerIf, QObject *parent)
    54 :QObject(parent),
    53 :QObject(parent),
    55  mSourceModel(0),
    54  mSourceModel(0),
    56  mAppControllerIf(controllerIf)
    55  mAppControllerIf(controllerIf)
    57 {
    56 {
    58 	qDebug() << "clock: ClockAlarmListModel::ClockAlarmListModel -->";
       
    59 
       
    60 	// Construct the source model.
    57 	// Construct the source model.
    61 	mSourceModel = new QStandardItemModel(0, 1, this);
    58 	mSourceModel = new QStandardItemModel(0, 1, this);
    62 	
    59 	
    63 	// Register to listen to the alarm state changes.
    60 	// Register to listen to the alarm state changes.
    64 	mAppControllerIf.alarmClient()->startListener();
    61 	mAppControllerIf.alarmClient()->startListener();
    72 	// Start a timer. For updating the remaining alarm time.
    69 	// Start a timer. For updating the remaining alarm time.
    73 	mTickTimer = new QTimer(this);
    70 	mTickTimer = new QTimer(this);
    74 	connect(
    71 	connect(
    75 			mTickTimer, SIGNAL(timeout()),
    72 			mTickTimer, SIGNAL(timeout()),
    76 			this, SLOT(updateRemainingTime()));
    73 			this, SLOT(updateRemainingTime()));
    77 	
       
    78 	qDebug() << "clock: ClockAlarmListModel::ClockAlarmListModel <--";
       
    79 }
    74 }
    80 
    75 
    81 /*!
    76 /*!
    82 	Destructor.
    77 	Destructor.
    83  */
    78  */
    84 ClockAlarmListModel::~ClockAlarmListModel()
    79 ClockAlarmListModel::~ClockAlarmListModel()
    85 {
    80 {
    86 	qDebug() << "clock: ClockAlarmListModel::~ClockAlarmListModel -->";
       
    87 
       
    88 	if (mSourceModel) {
    81 	if (mSourceModel) {
    89 		delete mSourceModel;
    82 		delete mSourceModel;
    90 		mSourceModel = 0;
    83 		mSourceModel = 0;
    91 	}
    84 	}
    92 
       
    93 	qDebug() << "clock: ClockAlarmListModel::~ClockAlarmListModel <--";
       
    94 }
    85 }
    95 
    86 
    96 /*!
    87 /*!
    97 	Populates the source model & starts the timer for 1 minute.
    88 	Populates the source model & starts the timer for 1 minute.
    98  */
    89  */
   107 	\return QAbstractItemModel
    98 	\return QAbstractItemModel
   108 	\sa QAbstractItemModel, HbListView.
    99 	\sa QAbstractItemModel, HbListView.
   109  */
   100  */
   110 QAbstractItemModel *ClockAlarmListModel::sourceModel()
   101 QAbstractItemModel *ClockAlarmListModel::sourceModel()
   111 {
   102 {
   112 	qDebug() << "clock: ClockAlarmListModel::sourceModel -->";
       
   113 
       
   114 	qDebug() << "clock: ClockAlarmListModel::sourceModel <--";
       
   115 
       
   116 	return mSourceModel;
   103 	return mSourceModel;
   117 }
   104 }
   118 
   105 
   119 /*!
   106 /*!
   120 	Populates the source model.
   107 	Populates the source model.
   121  */
   108  */
   122 void ClockAlarmListModel::populateSourceModel()
   109 void ClockAlarmListModel::populateSourceModel()
   123 {
   110 {
   124 	qDebug() << "clock: ClockAlarmListModel::populateSourceModel -->";
       
   125 
       
   126 	// Clear the model if it has any data already.
   111 	// Clear the model if it has any data already.
   127 	mSourceModel->clear();
   112 	mSourceModel->clear();
   128 	mSourceModel->setColumnCount(1);
   113 	mSourceModel->setColumnCount(1);
   129 	
   114 	
   130 	QList<AlarmInfo> alarmInfoList;
   115 	QList<AlarmInfo> alarmInfoList;
   151 	
   136 	
   152 	if (0 < getActiveAlarmCount() && !mTickTimer->isActive()) {
   137 	if (0 < getActiveAlarmCount() && !mTickTimer->isActive()) {
   153 		// Start the Timer for 1 minute.
   138 		// Start the Timer for 1 minute.
   154 		mTickTimer->start(60000 - 1000 * QTime::currentTime().second());
   139 		mTickTimer->start(60000 - 1000 * QTime::currentTime().second());
   155 	}
   140 	}
   156 	qDebug() << "clock: ClockAlarmListModel::populateSourceModel <--";
       
   157 }
   141 }
   158 
   142 
   159 /*!
   143 /*!
   160 	Calculates the remaining time for the given alarm.
   144 	Calculates the remaining time for the given alarm.
   161 
   145 
   162 	\param alarmInfo AlarmInfo containing the active alarm.
   146 	\param alarmInfo AlarmInfo containing the active alarm.
   163  */
   147  */
   164 QString ClockAlarmListModel::calculateRemainingTime(AlarmInfo alarmInfo)
   148 QString ClockAlarmListModel::calculateRemainingTime(AlarmInfo alarmInfo)
   165 {
   149 {
   166 	qDebug() << "clock: ClockAlarmListModel::calculateRemainingTime -->";
       
   167 
       
   168 	QDateTime currentDateTime = QDateTime::currentDateTime();
   150 	QDateTime currentDateTime = QDateTime::currentDateTime();
   169 	QDateTime alarmTime = QDateTime(
   151 	QDateTime alarmTime = QDateTime(
   170 			alarmInfo.alarmDateTime, alarmInfo.nextDueTime);
   152 			alarmInfo.alarmDateTime, alarmInfo.nextDueTime);
   171 	QString timeNote;
   153 	QString timeNote;
   172 
   154 
   215 				QString::number(hourleft), QString::number(minleft));
   197 				QString::number(hourleft), QString::number(minleft));
   216 	} else {
   198 	} else {
   217 		formatTimeNote = hbTrId("txt_clock_main_view_setlabel_in_1days");
   199 		formatTimeNote = hbTrId("txt_clock_main_view_setlabel_in_1days");
   218 		timeNote = formatTimeNote.arg(QString::number(dayleft));
   200 		timeNote = formatTimeNote.arg(QString::number(dayleft));
   219 	}
   201 	}
   220 	qDebug() << "clock: ClockAlarmListModel::calculateRemainingTime <--";
       
   221 
       
   222 	return timeNote;
   202 	return timeNote;
   223 }
   203 }
   224 
   204 
   225 /*!
   205 /*!
   226 	Gets remaining seconds to the alarm time from current date time.
   206 	Gets remaining seconds to the alarm time from current date time.
   262 
   242 
   263 	\param id of alarm, identifies the alarm which was changed.
   243 	\param id of alarm, identifies the alarm which was changed.
   264  */
   244  */
   265 void ClockAlarmListModel::updateSourceModel(int alarmId)
   245 void ClockAlarmListModel::updateSourceModel(int alarmId)
   266 {
   246 {
   267 	qDebug() << "clock: ClockAlarmListModel::updateSourceModel -->";
       
   268 	
       
   269 	Q_UNUSED(alarmId)
   247 	Q_UNUSED(alarmId)
   270 	int alarmInfoCount;
   248 	int alarmInfoCount;
   271 	int modelCount;
   249 	int modelCount;
   272 	bool newAlarm = false;
   250 	bool newAlarm = false;
   273 	bool alarmDeleted = false;
   251 	bool alarmDeleted = false;
   351 		if (mTickTimer->isActive()) {
   329 		if (mTickTimer->isActive()) {
   352 			// Stop the timer if no more active alarms are present.
   330 			// Stop the timer if no more active alarms are present.
   353 			mTickTimer->stop();
   331 			mTickTimer->stop();
   354 		}
   332 		}
   355 	}
   333 	}
   356 
       
   357 	qDebug() << "clock: ClockAlarmListModel::updateSourceModel <--";
       
   358 }
   334 }
   359 
   335 
   360 /*!
   336 /*!
   361 	Slot which Updates the remaining time field in the alarms list for all the
   337 	Slot which Updates the remaining time field in the alarms list for all the
   362 	alarms.
   338 	alarms.
   399 	\return QStringList contains the stringList to be set.
   375 	\return QStringList contains the stringList to be set.
   400  */
   376  */
   401 QStringList ClockAlarmListModel::getDisplayStringListforAlarmItem(
   377 QStringList ClockAlarmListModel::getDisplayStringListforAlarmItem(
   402 		AlarmInfo alarmInfo)
   378 		AlarmInfo alarmInfo)
   403 {
   379 {
   404 	qDebug() << "clock: ClockAlarmListModel::getDisplayStringforAlarmItem -->";
       
   405 	
       
   406 	QStringList displayStringList;
   380 	QStringList displayStringList;
   407 	QString timeString;
   381 	QString timeString;
   408 	if (Snoozed == alarmInfo.alarmState) {
   382 	if (Snoozed == alarmInfo.alarmState) {
   409 		timeString = alarmInfo.nextDueTime.toString(
   383 		timeString = alarmInfo.nextDueTime.toString(
   410 				mAppControllerIf.settingsUtility()->timeFormatString());
   384 				mAppControllerIf.settingsUtility()->timeFormatString());
   424 	
   398 	
   425 	if (Enabled == alarmInfo.alarmStatus) {
   399 	if (Enabled == alarmInfo.alarmStatus) {
   426 		QString remainingTime = calculateRemainingTime(alarmInfo);
   400 		QString remainingTime = calculateRemainingTime(alarmInfo);
   427 		displayStringList.append(remainingTime);
   401 		displayStringList.append(remainingTime);
   428 	} else {
   402 	} else {
   429 		displayStringList.append(QString(" "));
   403 		// TODO: localization
       
   404 		displayStringList.append(QString("In-active"));
   430 	}
   405 	}
   431 
   406 
   432 	QString alarmDescription = alarmInfo.alarmDesc;
   407 	QString alarmDescription = alarmInfo.alarmDesc;
   433 	displayStringList.append(alarmDescription);
   408 	displayStringList.append(alarmDescription);
   434 
   409 
   451 			repeatTypeString.append(
   426 			repeatTypeString.append(
   452 					alarmInfo.alarmDateTime.toString("dddd"));
   427 					alarmInfo.alarmDateTime.toString("dddd"));
   453 		}
   428 		}
   454 	}
   429 	}
   455 	displayStringList.append(repeatTypeString);
   430 	displayStringList.append(repeatTypeString);
   456 	
       
   457 	qDebug() << "clock: ClockAlarmListModel::getDisplayStringforAlarmItem <--";
       
   458 	
       
   459 	return displayStringList;
   431 	return displayStringList;
   460 }
   432 }
   461 
   433 
   462 /*!
   434 /*!
   463 	Appends an alarm to the source model.
   435 	Appends an alarm to the source model.
   477 		// The repeat icon.
   449 		// The repeat icon.
   478 		QList<QVariant> displayiconList;
   450 		QList<QVariant> displayiconList;
   479 		if (Weekly == alarmInfo.repeatType ||
   451 		if (Weekly == alarmInfo.repeatType ||
   480 				Daily == alarmInfo.repeatType ||
   452 				Daily == alarmInfo.repeatType ||
   481 				Workday == alarmInfo.repeatType) {
   453 				Workday == alarmInfo.repeatType) {
   482 			displayiconList.append(HbIcon(":/clock/alarm_repeat"));
   454 			displayiconList.append(HbIcon("qtg_mono_repeat"));
   483 		} else {
   455 		} else {
   484 			displayiconList.append(QVariant());
   456 			displayiconList.append(QVariant());
   485 		}
   457 		}
   486 		item->setData(displayiconList, Qt::DecorationRole);
   458 		item->setData(displayiconList, Qt::DecorationRole);
   487 		
   459 		
   488 		// The status.
   460 
   489 		if (Enabled == alarmInfo.alarmStatus) {
   461 		// Set the icon for active/in-active/snoozed alarm.
   490 			item->setData(QString(":/clock/alarm_active"), AlarmIcon);
   462 		if (Disabled == alarmInfo.alarmStatus) {
       
   463 			item->setData(QString("qtg_mono_alarm_inactive"), AlarmIcon);
       
   464 		} else if (Snoozed == alarmInfo.alarmState) {
       
   465 			// Change the alarm icon also to alarm snooze icon
       
   466 			item->setData(QString("qtg_mono_alarm_snooze"), AlarmIcon);
   491 		} else {
   467 		} else {
   492 			item->setData(QString(":/clock/alarm_inactive"), AlarmIcon);
   468 			item->setData(QString("qtg_mono_alarm"), AlarmIcon);
   493 		}
       
   494 
       
   495 		// If the alarm is snoozed.
       
   496 		if (Snoozed == alarmInfo.alarmState) {
       
   497 			// TODO : Change the alarm icon also to alarm snooze icon
       
   498 		}
   469 		}
   499 
   470 
   500 		// The model for the list item will have:
   471 		// The model for the list item will have:
   501 		// 1. Id of the alarm that the list item represents.
   472 		// 1. Id of the alarm that the list item represents.
   502 		// 2. The repeat type of the alarm (Recurrence type).
   473 		// 2. The repeat type of the alarm (Recurrence type).
   532 		// The repeat icon.
   503 		// The repeat icon.
   533 		QList<QVariant> displayiconList;
   504 		QList<QVariant> displayiconList;
   534 		if (Weekly == alarmInfo.repeatType ||
   505 		if (Weekly == alarmInfo.repeatType ||
   535 				Daily == alarmInfo.repeatType ||
   506 				Daily == alarmInfo.repeatType ||
   536 				Workday == alarmInfo.repeatType) {
   507 				Workday == alarmInfo.repeatType) {
   537 			displayiconList.append(HbIcon(":/clock/alarm_repeat"));
   508 			displayiconList.append(HbIcon("qtg_mono_repeat"));
   538 		} else {
   509 		} else {
   539 			displayiconList.append(QVariant());
   510 			displayiconList.append(QVariant());
   540 		}
   511 		}
   541 		mSourceModel->setData(
   512 		mSourceModel->setData(
   542 				modelIndex, displayiconList, Qt::DecorationRole);
   513 				modelIndex, displayiconList, Qt::DecorationRole);
   543 		// The status.
   514 		
   544 		if (Enabled == alarmInfo.alarmStatus) {
   515 		// Set the icon for active/in-active/snoozed alarm.
   545 			mSourceModel->setData(
   516 		if (Disabled == alarmInfo.alarmStatus) {
   546 					modelIndex, QString(":/clock/alarm_active"), AlarmIcon);
   517 			mSourceModel->setData(modelIndex, 
       
   518 			    QString("qtg_mono_alarm_inactive"), AlarmIcon);
       
   519 		} else if (Snoozed == alarmInfo.alarmState) {
       
   520 			// Change the alarm icon also to alarm snooze icon
       
   521 			mSourceModel->setData(modelIndex, 
       
   522 			    QString("qtg_mono_alarm_snooze"), AlarmIcon);
   547 		} else {
   523 		} else {
   548 			mSourceModel->setData(
   524 			mSourceModel->setData(modelIndex, QString("qtg_mono_alarm"), AlarmIcon);
   549 					modelIndex, QString(":/clock/alarm_inactive"), AlarmIcon);
       
   550 		}
       
   551 
       
   552 		// If the alarm is snoozed.
       
   553 		if (Snoozed == alarmInfo.alarmState) {
       
   554 			// TODO : Change the alarm icon also to alarm snooze icon
       
   555 		}
   525 		}
   556 
   526 
   557 		// The model for the list item will have:
   527 		// The model for the list item will have:
   558 		// 1. Id of the alarm that the list item represents.
   528 		// 1. Id of the alarm that the list item represents.
   559 		// 2. The repeat type of the alarm (Recurrence type).
   529 		// 2. The repeat type of the alarm (Recurrence type).