2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
6 * fosdem-schedule is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
11 * fosdem-schedule is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
23 #include <calendar-backend/CMulticalendar.h>
24 #include <calendar-backend/CCalendar.h>
25 #include <calendar-backend/CEvent.h>
26 #include <calendar-backend/CAlarm.h>
32 m_pMultiCalendar = CMulticalendar::MCInstance();
34 if(m_pMultiCalendar != NULL)
35 m_pCalendar = m_pMultiCalendar->getSynchronizedCalendar();
42 delete m_pMultiCalendar;
45 int Calendar::addCalendarEvent(QString summary, QString description, QString location, uint dateStart, uint dateEnd, int eventId)
49 if(m_pMultiCalendar == NULL)
52 if(m_pCalendar == NULL)
56 CEvent event(summary.toStdString(), description.toStdString(), location.toStdString(), dateStart, dateEnd);
60 alarm.setTrigger(dateStart - 15 * 60);
64 alarm.setAttach(QString::number(eventId).toLocal8Bit().data());
67 event.setAlarm(&alarm);
69 // register event into calendar
70 m_pMultiCalendar->addEvent(&event,m_pCalendar->getCalendarId(),errorCode);
75 void Calendar::deleteCalendarEvent(uint dateStart, uint dateEnd, int eventId)
79 vector< CComponent * > components;
82 components = m_pMultiCalendar->getComponents(m_pCalendar->getCalendarId(), 1, dateStart, dateEnd, errorCode);
84 for (vector<CComponent *>::iterator it = components.begin();it!=components.end(); ++it)
86 // get alarm properties
87 if( (*it)->getAlarmProperties() == true)
89 CAlarm * pAlarm = (*it)->getAlarm();
91 bool converted = false;
92 int tempId = QVariant(pAlarm->getAttach().data()).toInt(&converted);
99 m_pCalendar->deleteComponent((*it)->getId(),errorCode);
106 bool Calendar::hasCalendarEvent(int eventId)
111 vector< CEvent * > events;
114 events = m_pCalendar->getEvents(errorCode);
116 if(events.size() > 0)
118 for (vector<CEvent *>::iterator it = events.begin(); it!=events.end(); ++it)
120 // get alarm properties
121 if( (*it)->getAlarmProperties() == true)
123 CAlarm * pAlarm = (*it)->getAlarm();
125 bool converted = false;
126 int tempId = QVariant(pAlarm->getAttach().data()).toInt(&converted);
129 if(converted == true)
130 if(tempId == eventId)