Various event fixes
authorChristophe Dumez <dchris@gmail.com>
Sat, 10 Jul 2010 23:14:38 +0000 (01:14 +0200)
committerChristophe Dumez <dchris@gmail.com>
Sat, 10 Jul 2010 23:14:38 +0000 (01:14 +0200)
TimedSilencer.pro.user
alarmd_backend.h
profileevent.h
qmaemo5weekdayspickwidget.cpp
switchingeventlist.cpp

index 5f3e98d..c165f54 100644 (file)
@@ -15,7 +15,7 @@
   <valuemap type="QVariantMap">
    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Maemo</value>
    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.MaemoDeviceTarget</value>
-   <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">1</value>
+   <value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
    <value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
    <valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
     <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
     <value key="Qt4ProjectManager.MaemoRunConfiguration.DeviceId" type="qulonglong">16</value>
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployed" type="QVariantMap">
      <value key="192.168.1.4" type="QDateTime">2010-06-29T00:09:20</value>
-     <value key="localhost" type="QDateTime">2010-07-10T22:58:15</value>
+     <value key="localhost" type="QDateTime">2010-07-10T23:49:14</value>
     </valuemap>
    </valuemap>
    <value key="ProjectExplorer.Target.RunConfigurationCount" type="int">1</value>
index 8d8746b..4060bcd 100644 (file)
@@ -155,6 +155,7 @@ public:
 protected:
   static long newProfileEvent(Profile p, const QTime &event_time, QList<int> days) {
     Q_ASSERT(!days.empty());
+    qDebug("Registering an event");
     if(days.empty()) days << NEVER;
     // Create the default alarm struct.
     alarm_event_t *newEvent = alarm_event_create();
@@ -174,12 +175,18 @@ protected:
       if(days.first() == NEVER) {
         newEvent->alarm_time = toTime_t(event_time); // Set event time
       } else {
+        qDebug("Using the new recurrence API");
+        newEvent->recur_count = -1;
         newEvent->recur_secs = 0; // We re not using this way for recurrence
         alarm_recur_t* recur = alarm_event_add_recurrences(newEvent, 1);
         // Set event time
-        recur->mask_hour |= (1ul << event_time.hour());
-        recur->mask_min |= (1ull << event_time.minute());
-        recur->mask_wday |= daysToMask(days);
+        recur->special = ALARM_RECUR_SPECIAL_NONE;
+        recur->mask_mon = ALARM_RECUR_MON_ALL;
+        recur->mask_mday = ALARM_RECUR_MDAY_ALL;
+        recur->mask_hour = (1ul << event_time.hour());
+        recur->mask_min = (1ull << event_time.minute());
+        recur->mask_wday = daysToMask(days);
+        Q_ASSERT(newEvent->recurrence_cnt == 1);
       }
     }
     //Add 1 action to our alarm event, and assign it to the "act" variable
index 643dbfb..4fb502d 100644 (file)
@@ -52,7 +52,7 @@ public:
       foreach(int i, days) hasher.addData(QByteArray::number(i));
       id = hasher.result();
     }
-    qDebug("getID(): %s", id.constData());
+    //qDebug("getID(): %s", id.constData());
     return id;
   }
 
@@ -130,7 +130,7 @@ public:
   static void clearCookies(QByteArray myid) {
     QSettings settings("TimedSilencer", "TimedSilencer");
     QHash<QString, QVariant> events = settings.value("events").toHash();
-    Q_ASSERT(events.contains(myid));
+    //Q_ASSERT(events.contains(myid));
     if(events.contains(myid)) {
       qDebug("Clearing event cookies in QSettings");
       ProfileEvent *pe = load(events.value(myid));
@@ -156,6 +156,20 @@ public:
     }
   }
 
+  static void setStatus(QByteArray myid, bool status) {
+    QSettings settings("TimedSilencer", "TimedSilencer");
+    QHash<QString, QVariant> events = settings.value("events").toHash();
+    Q_ASSERT(events.contains(myid));
+    if(events.contains(myid)) {
+      qDebug("Setting event status in QSettings");
+      ProfileEvent *pe = load(events.value(myid));
+      pe->activated = status;
+      events[myid] = pe->save();
+      settings.setValue("events", events);
+      delete pe;
+    }
+  }
+
 };
 
 #endif // PROFILEEVENT_H
index 6d2b22b..93fcc38 100644 (file)
@@ -91,7 +91,7 @@ void QMaemo5WeekDaysPickWidget::emitSelectionAndClose() {
     // Insert sort
     int i = 0;
     const int row = index.row();
-    while(selected_rows.at(i) < row) ++i;
+    while(i < selected_rows.size() && selected_rows.at(i) < row) ++i;
     selected_rows.insert(i, row);
   }
   emit selectedDays(selected_rows);
index 57514e3..088aa72 100644 (file)
@@ -59,8 +59,8 @@ SwitchingEventList::~SwitchingEventList() {
 
 void SwitchingEventList::updateRow(int row, ProfileEvent *pe) {
   model->setData(model->index(row, EV_STATUS), pe->activated, Qt::UserRole);
-  model->setData(model->index(row, EV_FROM), pe->from_time.toString("HH:MM"));
-  model->setData(model->index(row, EV_TO), pe->to_time.toString("HH:MM"));
+  model->setData(model->index(row, EV_FROM), pe->from_time.toString("HH:mm"));
+  model->setData(model->index(row, EV_TO), pe->to_time.toString("HH:mm"));
   model->setData(model->index(row, EV_REPEAT), ProfileEvent::formatDays(pe->days));
   model->setData(model->index(row, EV_ID), pe->getID());
 }
@@ -72,6 +72,7 @@ void SwitchingEventList::editEvent(QModelIndex index) {
     // Toggle activated state
     const bool new_status = !index.data(Qt::UserRole).toBool();
     model->setData(index, new_status, Qt::UserRole);
+    ProfileEvent::setStatus(edited_id, new_status);
     // Alter Alarmd events
     if(new_status) {
       // Was activated