Added spanish translation
[timedsilencer] / switchingeventlist.cpp
index 8773bcb..18111a4 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());
-  model->setData(model->index(row, EV_TO), pe->to_time.toString());
+  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());
 }
@@ -70,8 +70,9 @@ void SwitchingEventList::editEvent(QModelIndex index) {
   QByteArray edited_id = model->data(model->index(index.row(), EV_ID)).toByteArray();
   if(index.column() == EV_STATUS) {
     // Toggle activated state
-    const bool new_status = !index.data().toBool();
-    model->setData(index, new_status);
+    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
@@ -92,6 +93,7 @@ void SwitchingEventList::editEvent(QModelIndex index) {
 void SwitchingEventList::loadSavedEvents() {
   qDebug("Loading saved events");
   QSettings settings("TimedSilencer", "TimedSilencer");
+  QList<long> known_cookies;
   QHash<QString, QVariant> events = settings.value("events").toHash();
   // Check for < v0.6 settings
   if(!settings.value("from_time", QTime()).toTime().isNull()) {
@@ -108,6 +110,7 @@ void SwitchingEventList::loadSavedEvents() {
     long to_cookie = settings.value("unsilencing_cookie", 0).toLongLong();
     if(to_cookie > 0)
       pe.alarmd_cookies << to_cookie;
+    known_cookies << pe.alarmd_cookies;
     if(to_cookie <= 0 || from_cookie <= 0)
       pe.activated = false;
     events.insert(pe.getID(), pe.save());
@@ -120,6 +123,7 @@ void SwitchingEventList::loadSavedEvents() {
   bool settings_change = false;
   foreach(QVariant e, events.values()) {
     ProfileEvent *pe = ProfileEvent::load(e);
+    known_cookies << pe->alarmd_cookies;
     // Check if still active
     if(pe->activated && !AlarmdBackend::checkIfStillActive(pe)) {
       qDebug("An existing profile switching event is no longer active, updating its status");
@@ -134,6 +138,8 @@ void SwitchingEventList::loadSavedEvents() {
     // Clean up
     delete pe;
   }
+  // Delete possible orphan events
+  AlarmdBackend::deleteOrphanEvents(known_cookies);
   if(settings_change)
     settings.setValue("events", events);
 }