added 'alarm' columnt to the 'EVENT' table to signalize
authorpavelpa <pavelpa@localhost>
Mon, 18 Jan 2010 15:13:01 +0000 (15:13 +0000)
committerpavelpa <pavelpa@localhost>
Mon, 18 Jan 2010 15:13:01 +0000 (15:13 +0000)
that the event has/hasn't alarm set

src/alarm/alarm.cpp
src/alarm/alarm.h
src/mvc/delegate.cpp
src/mvc/event.cpp
src/mvc/event.h
src/mvc/eventmodel.cpp
src/mvc/treeview.cpp
src/sql/sqlengine.cpp

index af3120e..8355657 100644 (file)
@@ -83,3 +83,43 @@ void Alarm::deleteAlarm(int aEventId)
     alarm_event_delete(event);
 }
 
+bool Alarm::hasEventAlarm(int aEventId)
+{
+    cookie_t *list = 0;
+    cookie_t cookie = 0;
+    alarm_event_t *event = 0;
+
+    bool eventHasAlarm = false;
+
+    // query the APPID's list of alarms
+    if( (list = alarmd_event_query(0,0, 0,0, APPID)) != 0 ) // query OK
+    {
+        for( int i = 0; (cookie = list[i]) != 0; ++i )
+        {
+            alarm_event_delete(event);
+
+            // get the event for specified alarm cookie (alarmId)
+            if( (event = alarmd_event_get(cookie)) == 0 )
+            {
+                // should we inform user about it ???
+                continue;
+            }
+
+            if(aEventId==atoi(alarm_event_get_message(event)))
+            {
+                eventHasAlarm = true;
+                break;
+            }
+        }
+    }
+    else
+    {
+        // query failed
+    }
+
+    free(list);
+    alarm_event_delete(event);
+
+    return eventHasAlarm;
+}
+
index dd19bd9..c68b554 100644 (file)
@@ -19,6 +19,7 @@ class Alarm : public QObject
         ~Alarm() {}
         int addAlarm(int aEventId, const QDateTime &aDateTime); 
         void deleteAlarm(int aEventId);
+        static bool hasEventAlarm(int aEventId);
     signals:
         void alarmAdded(int aEventId);
         void addAlarmFailed(int aEventId);
index 507fae4..d085db9 100644 (file)
@@ -83,11 +83,17 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
         }
 
         // draw Controls
+        // favourite
         if(static_cast<Event*>(index.internalPointer())->isFavourite())
             painter->drawImage(mControls[FavouriteControlOn]->drawPoint(option.rect),*mControls[FavouriteControlOn]->image());
         else
             painter->drawImage(mControls[FavouriteControlOff]->drawPoint(option.rect),*mControls[FavouriteControlOff]->image());
-        painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
+        // alarm
+        if(static_cast<Event*>(index.internalPointer())->hasAlarm())
+            painter->drawImage(mControls[AlarmControlOn]->drawPoint(option.rect),*mControls[AlarmControlOn]->image());
+        else
+            painter->drawImage(mControls[AlarmControlOff]->drawPoint(option.rect),*mControls[AlarmControlOff]->image());
+        // map
         painter->drawImage(mControls[MapControl]->drawPoint(option.rect),*mControls[MapControl]->image());
     }
     else // doesn't have parent - time-groups' elements (top items)
@@ -224,7 +230,7 @@ void Delegate::defineControls()
 
     // ALARM ICONs
     // on
-    control = new Control(AlarmControlOn,QString(":icons/alarm-off.png"));
+    control = new Control(AlarmControlOn,QString(":icons/alarm-on.png"));
     p = mControls[FavouriteControlOn]->drawPoint();
     p.setX(p.x()-control->image()->width()-SPACER);
     control->setDrawPoint(p);
index dbe43cf..fa062ac 100644 (file)
@@ -5,7 +5,7 @@
 // two table names + corresponding parameters/methods, see bellow
 QString const Event::sTable1Name = QString("event");
 QString const Event::sTable2Name = QString("virtual_event");
-int const Event::sTable1ColCount = 8; // see 'toRecord()' for more details
+int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details
 int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
 
 QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
@@ -18,6 +18,7 @@ QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
     << QSqlField("type", QVariant::String)
     << QSqlField("language", QVariant::String)
     << QSqlField("favourite", QVariant::Bool)
+    << QSqlField("alarm", QVariant::Bool)
     /* 'columns' from Table2 */
     << QSqlField("tag", QVariant::String)
     << QSqlField("title", QVariant::String)
index b09daa8..30f0110 100644 (file)
@@ -39,6 +39,7 @@ public:
     QString type() const { return value("type").toString(); }
     QString language() const { return value("language").toString(); }
     bool isFavourite() const { return value("favourite").toBool(); }
+    bool hasAlarm() const { return value("alarm").toBool(); }
     // Table 2 : virtual table for FTS (Full Text Search)
     QString tag() const { return value("tag").toString(); }
     QString title() const { return value("title").toString(); }
@@ -55,6 +56,7 @@ public:
     void setType(const QString& type) { setValue("type", type); }
     void setLanguage(const QString& language) { setValue("language", language); }
     void setFavourite(bool favourite) { setValue("favourite", (int)favourite); }
+    void setHasAlarm(bool alarm) { setValue("alarm", (int)alarm); }
     // Table 2 : virtual table for FTS (Full Text Search)
     void setTag(const QString& tag) { setValue("tag", tag); }
     void setTitle(const QString& title) { setValue("title", title); }
index f00750d..e3ad84f 100644 (file)
@@ -124,7 +124,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
         QModelIndex idx = index(i,0);
         Group group = mGroups[i];
         beginRemoveRows(idx,0,group.mChildCount-1);
-        bool ok = removeRows(0,group.mChildCount,idx);
+        removeRows(0,group.mChildCount,idx);
         endRemoveRows();
         //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
     }
@@ -147,7 +147,7 @@ void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
         QModelIndex idx = index(i,0);
         Group group = mGroups[i];
         beginRemoveRows(idx,0,group.mChildCount-1);
-        bool ok = removeRows(0,group.mChildCount,idx);
+        removeRows(0,group.mChildCount,idx);
         endRemoveRows();
         //qDebug() << "removing " << group.mChildCount << " events from group:" << i << idx.data() << ":" << ok;
     }
index 595bc21..4d1bc30 100644 (file)
@@ -57,7 +57,22 @@ void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP
         case Delegate::AlarmControlOff:
             {
                 // handle Alarm Control clicked
-                qDebug() << "ALARM CLICKED: " << qVariantValue<QString>(aIndex.data());
+                Event event = Event::getById(aIndex.data().toInt(),1);
+                if(event.hasAlarm())
+                {
+                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(false); // list of events
+                    event.setHasAlarm(false); // update DB
+                }
+                else
+                {
+                    static_cast<Event*>(aIndex.internalPointer())->setHasAlarm(true); // list of events
+                    event.setHasAlarm(true);
+                }
+                qDebug() << " ALARM [" << qVariantValue<QString>(aIndex.data()) << "] -> " << event.hasAlarm();
+                event.update("alarm");
+                // since the Alarm icon has changed, update TreeView accordingly
+                static_cast<EventModel*>(model())->emitDataChangedSignal(aIndex,aIndex);
+
             }
             break;
         case Delegate::MapControl:
index a70a5f3..73c4497 100644 (file)
@@ -90,7 +90,7 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
         // The items of the Event are divided into the two tables EVENT and VIRTUAL_EVENT
         // VIRTUAL_EVENT is for Full-Text-Serach Support
         QDateTime startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT));
-        QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8'") \
+        QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9'") \
                          .arg(aEvent["conference_id"]) \
                          .arg(aEvent["id"]) \
                          .arg(QString::number(startDateTime.toTime_t())) \
@@ -98,9 +98,10 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
                          .arg("123456") \
                          .arg(aEvent["type"]) \
                          .arg(aEvent["language"]) \
-                         .arg("0"); // not favourite when added
+                         .arg("0") \
+                         .arg("0");
 
-        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language, favourite) VALUES (%1)").arg(values);
+        QString query = QString("INSERT INTO EVENT (xid_conference, id, start, duration, xid_activity, type, language, favourite, alarm) VALUES (%1)").arg(values);
         QSqlQuery result (query, db);
         //LOG_AUTOTEST(query);
 
@@ -119,9 +120,7 @@ void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent)
         result2.bindValue(2,aEvent["abstract"]);
         result2.bindValue(3,aEvent["description"]);
         result2.exec();
-
-         //LOG_AUTOTEST(query2);
-        qDebug() << query2;
+        //LOG_AUTOTEST(query2);
     }
 }
 
@@ -234,12 +233,15 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             type VARCHAR, \
             language VARCHAR, \
             favourite INTEGER DEFAULT 0, \
+            alarm INTEGER DEFAULT 0, \
             PRIMARY KEY (xid_conference,id), \
             FOREIGN KEY(xid_conference) REFERENCES CONFERENCE(id) \
             FOREIGN KEY(xid_activity) REFERENCES ACTIVITY(id))");
 
-        // TBD Virtual tables compatibility (waiting for Marek). Temporary non virtual VIRTUAL_TABLE below: To be deleted
-/*        query.exec("CREATE VIRTUAL TABLE VIRTUAL_EVENT using fts3 ( \
+#ifdef MAEMO
+        // TBD: MAEMO Virtual tables compatibility (waiting for Marek).
+        // MAEMO sqlite Qt driver doesn't provide FTS support by default - use the following HACK
+        query.exec("CREATE TABLE VIRTUAL_EVENT ( \
             xid_conference INTEGER  NOT NULL, \
             id INTEGER NOT NULL , \
             tag VARCHAR,title VARCHAR NOT NULL , \
@@ -247,8 +249,8 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             abstract VARCHAR, \
             description VARCHAR, \
             PRIMARY KEY (xid_conference,id))");
-*/
-        query.exec("CREATE TABLE VIRTUAL_EVENT ( \
+#else
+        query.exec("CREATE VIRTUAL TABLE VIRTUAL_EVENT using fts3 ( \
             xid_conference INTEGER  NOT NULL, \
             id INTEGER NOT NULL , \
             tag VARCHAR,title VARCHAR NOT NULL , \
@@ -256,6 +258,7 @@ bool SqlEngine::createTables(QSqlDatabase &aDatabase)
             abstract VARCHAR, \
             description VARCHAR, \
             PRIMARY KEY (xid_conference,id))");
+#endif
 
         query.exec("CREATE TABLE EVENT_PERSON ( \
             xid_conference INTEGER NOT NULL , \