Skip to content

Commit

Permalink
Merge branch 'jb8860' into 'master'
Browse files Browse the repository at this point in the history
[alarms] Add support for seconds to countdown alarms. Contributes to JB#8860

See merge request mer-core/nemo-qml-plugin-alarms!9
  • Loading branch information
jpetrell committed Sep 16, 2019
2 parents fa9c058 + 1e225ff commit c55d16d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
27 changes: 22 additions & 5 deletions src/alarmobject.cpp
Expand Up @@ -38,14 +38,14 @@
# include <timed-qt5/exception>

AlarmObject::AlarmObject(QObject *parent)
: QObject(parent), m_hour(0), m_minute(0), m_enabled(false),
: QObject(parent), m_hour(0), m_minute(0), m_second(0), m_enabled(false),
m_createdDate(QDateTime::currentDateTime()), m_countdown(false), m_reminder(false), m_triggerTime(0),
m_elapsed(0), m_cookie(0), m_timeoutSnoozeCounter(0), m_maximalTimeoutSnoozeCount(0)
{
}

AlarmObject::AlarmObject(const QMap<QString,QString> &data, QObject *parent)
: QObject(parent), m_hour(0), m_minute(0), m_enabled(false),
: QObject(parent), m_hour(0), m_minute(0), m_second(0), m_enabled(false),
m_createdDate(QDateTime::currentDateTime()), m_countdown(false), m_reminder(false), m_triggerTime(0),
m_elapsed(0), m_cookie(0)
{
Expand All @@ -64,7 +64,12 @@ AlarmObject::AlarmObject(const QMap<QString,QString> &data, QObject *parent)
m_createdDate = QDateTime::fromMSecsSinceEpoch(it.value().toLongLong());
} else if (it.key() == "elapsed")
m_elapsed = it.value().toInt();
else if (it.key() == "timeOfDay") {
else if (it.key() == "timeOfDayWithSeconds") { // new format with seconds support
int value = it.value().toInt();
m_hour = value / 3600;
m_minute = (value % 3600) / 60;
m_second = value % 60;
} else if (it.key() == "timeOfDay") { // old format
int value = it.value().toInt();
m_hour = value / 60;
m_minute = value % 60;
Expand Down Expand Up @@ -131,6 +136,15 @@ void AlarmObject::setMinute(int minute)
emit timeChanged();
}

void AlarmObject::setSecond(int second)
{
if (m_second == second)
return;

m_second = second;
emit timeChanged();
}

void AlarmObject::setDaysOfWeek(const QString &in)
{
QString str;
Expand Down Expand Up @@ -264,7 +278,9 @@ void AlarmObject::save()
if (!m_title.isEmpty())
ev.setAttribute(QLatin1String("TITLE"), m_title);

ev.setAttribute(QLatin1String("timeOfDay"), QString::number(m_hour * 60 + m_minute));
ev.setAttribute(QLatin1String("timeOfDayWithSeconds"),
QString::number(m_hour * 3600 + m_minute * 60 + m_second));

ev.setAttribute(QLatin1String("APPLICATION"), QLatin1String("nemoalarms"));
ev.setAttribute(QLatin1String("createdDate"), QString::number(m_createdDate.toMSecsSinceEpoch()));
ev.setAlarmFlag();
Expand All @@ -278,6 +294,7 @@ void AlarmObject::save()

if (m_enabled) {
Maemo::Timed::Event::Recurrence rec = ev.addRecurrence();

rec.addHour(m_hour);
rec.addMinute(m_minute);
rec.everyDayOfMonth();
Expand All @@ -300,7 +317,7 @@ void AlarmObject::save()
}
ev.setAttribute(QLatin1String("type"), QLatin1String("clock"));
} else {
uint duration = m_hour * 3600 + m_minute * 60;
uint duration = m_hour * 3600 + m_minute * 60 + m_second;
QDateTime now = QDateTime::currentDateTimeUtc();
if (m_enabled) {
QDateTime triggerDateTime = now.addSecs(duration - m_elapsed);
Expand Down
20 changes: 17 additions & 3 deletions src/alarmobject.h
Expand Up @@ -65,7 +65,7 @@ class AlarmObject : public QObject
* Hour component of the alarm time
*
* An alarm will trigger when the device time is next at the specified
* hour and minute, after being enabled. Alarm time is independent of
* hour, minute and second, after being enabled. Alarm time is independent of
* timezones.
*/
Q_PROPERTY(int hour READ hour WRITE setHour NOTIFY timeChanged)
Expand All @@ -77,13 +77,27 @@ class AlarmObject : public QObject
* Minute component of the alarm time
*
* An alarm will trigger when the device time is next at the specified
* hour and minute, after being enabled. Alarm time is independent of
* hour, minute and second, after being enabled. Alarm time is independent of
* timezones.
*/
Q_PROPERTY(int minute READ minute WRITE setMinute NOTIFY timeChanged)
int minute() const { return m_minute; }
void setMinute(int minute);

/*!
* \qmlproperty int Alarm::second
* Second component of the alarm time in a countdown alarm
*
* An countdown alarm will trigger when the device time is next at the specified
* hour, minute and second, after being enabled. Alarm time is independent of
* timezones.
*
* \sa countdown
*/
Q_PROPERTY(int second READ second WRITE setSecond NOTIFY timeChanged)
int second() const { return m_second; }
void setSecond(int second);

/*!
* \qmlproperty string Alarm::daysOfWeek
* List of weekdays when the alarm will be repeated
Expand Down Expand Up @@ -374,7 +388,7 @@ private slots:

protected:
QString m_title;
int m_hour, m_minute;
int m_hour, m_minute, m_second;
QString m_daysOfWeek;
bool m_enabled;
QDateTime m_createdDate;
Expand Down
2 changes: 2 additions & 0 deletions src/alarmsbackendmodel.cpp
Expand Up @@ -52,6 +52,7 @@ QHash<int, QByteArray> AlarmsBackendModel::roleNames() const
roles[EnabledRole] = "enabled";
roles[HourRole] = "hour";
roles[MinuteRole] = "minute";
roles[SecondRole] = "second";
roles[WeekDaysRole] = "daysOfWeek";
return roles;
}
Expand Down Expand Up @@ -106,6 +107,7 @@ QVariant AlarmsBackendModel::data(const QModelIndex &index, int role) const
case EnabledRole: return alarm->isEnabled();
case HourRole: return alarm->hour();
case MinuteRole: return alarm->minute();
case SecondRole: return alarm->second();
case WeekDaysRole: return alarm->daysOfWeek();
}

Expand Down
1 change: 1 addition & 0 deletions src/alarmsbackendmodel.h
Expand Up @@ -49,6 +49,7 @@ class AlarmsBackendModel : public QAbstractListModel, public QQmlParserStatus
EnabledRole,
HourRole,
MinuteRole,
SecondRole,
WeekDaysRole
};

Expand Down

0 comments on commit c55d16d

Please sign in to comment.