Useless calendar class
authorhanzes <hanzes@localhost>
Tue, 26 Jan 2010 07:56:53 +0000 (07:56 +0000)
committerhanzes <hanzes@localhost>
Tue, 26 Jan 2010 07:56:53 +0000 (07:56 +0000)
src/alarm/calendar.cpp [new file with mode: 0644]
src/alarm/calendar.h [new file with mode: 0644]

diff --git a/src/alarm/calendar.cpp b/src/alarm/calendar.cpp
new file mode 100644 (file)
index 0000000..931569f
--- /dev/null
@@ -0,0 +1,120 @@
+#include "calendar.h"
+#include <qdebug.h>
+#include <qvariant.h>
+
+#include <calendar-backend/CMulticalendar.h>
+#include <calendar-backend/CCalendar.h>
+#include <calendar-backend/CEvent.h>
+#include <calendar-backend/CAlarm.h>
+
+Calendar::Calendar():
+m_pMultiCalendar(0),
+m_pCalendar(0)
+{
+       m_pMultiCalendar = CMulticalendar::MCInstance();
+
+       if(m_pMultiCalendar != NULL)
+               m_pCalendar  = m_pMultiCalendar->getSynchronizedCalendar();
+
+}
+
+Calendar::~Calendar()
+{
+       delete m_pCalendar;
+       delete m_pMultiCalendar;
+}
+
+int Calendar::addCalendarEvent(QString summary, QString description, QString location, uint dateStart, uint  dateEnd, int eventId)
+{
+       int errorCode = 0;
+
+       if(m_pMultiCalendar == NULL)
+               return 0;
+
+       if(m_pCalendar == NULL)
+               return 0;
+
+       // create event
+       CEvent event(summary.toStdString(), description.toStdString(), location.toStdString(),  dateStart, dateEnd);
+
+       // create alarm
+       CAlarm alarm;
+       alarm.setTrigger(dateStart - 15 * 60);
+       alarm.setRepeat(1);
+       alarm.setDuration(3);
+       alarm.setAction(0);
+       alarm.setAttach(QString::number(eventId).toLocal8Bit().data());
+
+       // add alarm to event
+       event.setAlarm(&alarm);
+
+       // register event into calendar
+       m_pMultiCalendar->addEvent(&event,m_pCalendar->getCalendarId(),errorCode);
+
+    return errorCode;
+}
+
+void Calendar::deleteCalendarEvent(uint dateStart, uint dateEnd, int eventId)
+{
+       int errorCode = 0;
+
+       vector< CComponent * > components;
+
+       // get all events
+       components = m_pMultiCalendar->getComponents(m_pCalendar->getCalendarId(), 1, dateStart, dateEnd, errorCode);
+
+       for (vector<CComponent *>::iterator it = components.begin();it!=components.end(); ++it)
+       {
+               // get alarm properties
+               if( (*it)->getAlarmProperties() == true)
+               {
+                       CAlarm * pAlarm = (*it)->getAlarm();
+
+                       bool converted = false;
+                       int tempId = QVariant(pAlarm->getAttach().data()).toInt(&converted);
+
+                       // check event id
+                       if(converted == true)
+                               if(tempId == eventId)
+                               {
+                                       //delete event
+                                       m_pCalendar->deleteComponent((*it)->getId(),errorCode);
+                                       break;
+                               }
+               }
+       }
+}
+
+bool Calendar::hasCalendarEvent(int eventId)
+{
+       bool ret = false;
+       int errorCode = 0;
+
+       vector< CEvent * > events;
+
+       // get all events
+       events = m_pCalendar->getEvents(errorCode);
+
+       if(events.size() > 0)
+       {
+               for (vector<CEvent *>::iterator it = events.begin(); it!=events.end(); ++it)
+               {
+                       // get alarm properties
+                       if( (*it)->getAlarmProperties() == true)
+                       {
+                               CAlarm * pAlarm = (*it)->getAlarm();
+
+                               bool converted = false;
+                               int tempId = QVariant(pAlarm->getAttach().data()).toInt(&converted);
+
+                               // check event id
+                               if(converted == true)
+                                       if(tempId == eventId)
+                                       {
+                                               ret = true;
+                                               break;
+                                       }
+                       }
+               }
+       }
+}
diff --git a/src/alarm/calendar.h b/src/alarm/calendar.h
new file mode 100644 (file)
index 0000000..f2c2d42
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef CALENDAR_H
+#define CALENDAR_H
+
+#include <QObject>
+#include <QDateTime>
+
+class CMulticalendar;
+class CCalendar;
+
+class Calendar : public QObject
+{
+    Q_OBJECT
+    public:
+       Calendar();
+        ~Calendar();
+        int addCalendarEvent(QString summary, QString description, QString location, uint dateStart, uint dateEnd, int eventId);
+        void deleteCalendarEvent(uint dateStart, uint dateEnd, int eventId);
+        bool hasCalendarEvent(int eventId);
+
+        CMulticalendar * m_pMultiCalendar;
+        CCalendar * m_pCalendar;
+//    signals:
+//        void alarmAdded(int aEventId);
+//        void addAlarmFailed(int aEventId);
+//        void alarmDeleted(int aEventId);
+//        void deleteAlarmFailed(int aEventId);
+};
+
+#endif /* CALENDAR_H */