diff --git a/calendaring/calendaring.cpp b/calendaring/calendaring.cpp index e8260d7..470c257 100644 --- a/calendaring/calendaring.cpp +++ b/calendaring/calendaring.cpp @@ -1,119 +1,123 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include "calendaring.h" #include #include #include #include #include #include #include "conversion/kcalconversion.h" #include "conversion/commonconversion.h" namespace Kolab { namespace Calendaring { +void dummy() +{ +} + // bool conflicts(const Kolab::Event &e1, const Kolab::Event &e2) // { // KCalCore::Event::Ptr k1 = Kolab::Conversion::toKCalCore(e1); // KCalCore::Event::Ptr k2 = Kolab::Conversion::toKCalCore(e2); // if (k2->dtEnd() > k1->dtStart()) { // return false; // } else if (k1->dtEnd() > k2->dtStart()) { // return false; // } // return true; // } // std::vector< std::vector< Event > > getConflictingSets(const std::vector< Event > &events, const std::vector< Event > &events2) // { // std::vector< std::vector< Kolab::Event > > ret; // for(std::size_t i = 0; i < events.size(); i++) { // std::vector set; // const Kolab::Event &event = events.at(i); // set.push_back(event); // for(std::size_t q = i+1; q < events.size(); q++) { // const Kolab::Event &e2 = events.at(q); // if (conflicts(event, e2)) { // set.push_back(e2); // } // } // for(std::size_t m = 0; m < events2.size(); m++) { // const Kolab::Event &e2 = events2.at(m); // if (conflicts(event, e2)) { // set.push_back(e2); // } // } // if (set.size() > 1) { // ret.push_back(set); // } // } // return ret; // } // std::vector timeInInterval(const Kolab::Event &e, const Kolab::cDateTime &start, const Kolab::cDateTime &end) // { // KCalCore::Event::Ptr k = Kolab::Conversion::toKCalCore(e); // KCalCore::DateTimeList list = k->recurrence()->timesInInterval(Kolab::Conversion::toDate(start), Kolab::Conversion::toDate(end)); // std::vector dtList; // foreach(const QDateTime &dt, list) { // dtList.push_back(Kolab::Conversion::fromDate(dt)); // } // return dtList; // } Calendar::Calendar() : mCalendar(new KCalCore::MemoryCalendar(QTimeZone::utc())) //Always utc as it doesn't change anything anyways { } void Calendar::addEvent(const Kolab::Event &event) { KCalCore::Event::Ptr k = Kolab::Conversion::toKCalCore(event); if (!mCalendar->addEvent(k)) { qWarning() << "failed to add event"; } } std::vector Calendar::getEvents(const Kolab::cDateTime& start, const Kolab::cDateTime& end, bool sort) { const QDateTime s = Kolab::Conversion::toDate(start); const QDateTime e = Kolab::Conversion::toDate(end); const QTimeZone timeSpec = s.timeZone(); KCalCore::Event::List list = mCalendar->events(s.date(), e.date(), timeSpec, true); if (sort) { list = mCalendar->sortEvents(list, KCalCore::EventSortStartDate, KCalCore::SortDirectionAscending); } std::vector eventlist; foreach (const KCalCore::Event::Ptr &event, list) { //We have to filter the list by time if (event->dtEnd() >= s && event->dtStart() <= e) { eventlist.push_back(Kolab::Conversion::fromKCalCore(*event)); } } return eventlist; } } //Namespace } //Namespace diff --git a/calendaring/calendaring.h b/calendaring/calendaring.h index 2a73bc7..a75cae7 100644 --- a/calendaring/calendaring.h +++ b/calendaring/calendaring.h @@ -1,61 +1,66 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef KOLABCALENDARING_H #define KOLABCALENDARING_H #ifndef SWIG #include "kolab_export.h" #else /* No export/import SWIG interface files */ #define KOLAB_EXPORT #endif #include #include #include #include namespace Kolab { namespace Calendaring { +/** + * Dummy function to ensure the kolabcalendaring class is created in the php module. + */ +KOLAB_EXPORT void dummy(); + /** * In-Memory Calendar Cache */ class KOLAB_EXPORT Calendar { public: explicit Calendar(); /** * Add an event to the in-memory calendar. */ void addEvent(const Kolab::Event &); /** * Returns all events within the specified interval (start and end inclusive). * * @param sort controls if the resulting event set is sorted in ascending order according to the start date */ std::vector getEvents(const Kolab::cDateTime &start, const Kolab::cDateTime &end, bool sort); private: Calendar(const Calendar &); void operator=(const Calendar &); QSharedPointer mCalendar; }; }; //Namespace }; //Namespace #endif diff --git a/calendaring/calendaring.i b/calendaring/calendaring.i index 4d23fe5..fc935e4 100644 --- a/calendaring/calendaring.i +++ b/calendaring/calendaring.i @@ -1,19 +1,19 @@ %{ /* This macro ensures that return vectors remain a vector also in python and are not converted to tuples */ #define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS #include "../calendaring/calendaring.h" #include "../calendaring/event.h" %} %include "std_string.i" %include "std_vector.i" %import(module="kolabformat") %import "../shared.i" %rename(EventCal) Kolab::Calendaring::Event; -/* %rename(KolabCalendar) Kolab::Calendaring::Calendar; */ +%rename(KolabCalendar) Kolab::Calendaring::Calendar; -/* %include "../calendaring/calendaring.h" */ +%include "../calendaring/calendaring.h" %include "../calendaring/event.h"