Add calendar-backend adapter
authorPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 24 Nov 2009 13:50:23 +0000 (14:50 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 24 Nov 2009 14:54:52 +0000 (15:54 +0100)
This wraps the calendar-backend C++ API for adding events to the calendar.

Makefile.am
configure.ac
src/plugins/calendar-backend-adapter.cc [new file with mode: 0644]
src/plugins/calendar-backend.vala [new file with mode: 0644]

index 0845f33..81c66d9 100644 (file)
@@ -129,16 +129,20 @@ src/plugins/catalog-plugin.c: ${libcatalog_plugin_la_VALASOURCES}
 
 libgoogle_plugin_la_SOURCES = \
        src/plugins/google-plugin.c \
+       src/plugins/calendar-backend-adapter.cc \
+       src/plugins/calendar-backend.c \
        src/plugins/google-parser.c
 
 libgoogle_plugin_la_VALASOURCES = \
        src/plugins/google-plugin.vala \
+       src/plugins/calendar-backend.vala \
        src/plugins/google-parser.vala
 
 libgoogle_plugin_la_VALAFLAGS = --vapidir ./vapi --pkg config --pkg cinaest \
        --pkg hildon-1 --pkg libosso
 libgoogle_plugin_la_CFLAGS = ${CINAEST_CFLAGS} ${HILDON_CFLAGS} ${OSSO_CFLAGS}
-libgoogle_plugin_la_LIBADD = ${CINAEST_LIBS} ${HILDON_LIBS} ${OSSO_LIBS}
+libgoogle_plugin_la_CPPFLAGS = ${CALENDAR_CFLAGS}
+libgoogle_plugin_la_LIBADD = ${CALENDAR_LIBS} ${CINAEST_LIBS} ${HILDON_LIBS} ${OSSO_LIBS}
 libgoogle_plugin_la_LDFLAGS = -module
 
 src/plugins/google-plugin.c: ${libgoogle_plugin_la_VALASOURCES}
@@ -209,7 +213,7 @@ ACLOCAL_AMFLAGS = -Im4
 CLEANFILES = \
        ${cinaest_SOURCES} \
        ${libcatalog_plugin_la_SOURCES} \
-       ${libgoogle_plugin_la_SOURCES} \
+       $(patsubst %.vala,%.c,${libgoogle_plugin_la_VALASOURCES}) \
        ${libimdb_plugin_la_SOURCES} \
        ${imdb_plaintext_downloader_SOURCES} \
        ${google_poster_downloader_SOURCES}
index 1d7eb29..191fbf4 100644 (file)
@@ -19,6 +19,10 @@ CFLAGS="$CFLAGS -Wall -ansi -Wmissing-prototypes -Wmissing-declarations"
 AC_OUTPUT(cinaest.pc)
 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:.
 
+PKG_CHECK_MODULES(CALENDAR, calendar-backend)
+AC_SUBST(CALENDAR_LIBS)
+AC_SUBST(CALENDAR_CFLAGS)
+
 PKG_CHECK_MODULES(CINAEST, cinaest)
 AC_SUBST(CINAEST_LIBS)
 AC_SUBST(CINAEST_CFLAGS)
diff --git a/src/plugins/calendar-backend-adapter.cc b/src/plugins/calendar-backend-adapter.cc
new file mode 100644 (file)
index 0000000..c9ca8e7
--- /dev/null
@@ -0,0 +1,52 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <CEvent.h>
+#include <CMulticalendar.h>
+#include <CalendarErrors.h>
+#include <ctime>
+
+using namespace std;
+
+extern "C" {
+
+       int calendar_backend_add_event (char* summary,
+                                       char* description,
+                                       char* location,
+                                       time_t start,
+                                       time_t end)
+       {
+               CMulticalendar* MC = CMulticalendar::MCInstance ();
+               CCalendar* C = MC->getDefaultCalendar ();
+               int id = C->getCalendarId ();
+               int error = 0;
+
+               CEvent* E = new CEvent (summary, description, location, start, end);
+
+               MC->addEvent (E, id, error);
+
+               delete E;
+
+               if (error != CALENDAR_OPERATION_SUCCESSFUL) {
+                       return error;
+               } else {
+                       return 0;
+               }
+       }
+
+}
diff --git a/src/plugins/calendar-backend.vala b/src/plugins/calendar-backend.vala
new file mode 100644 (file)
index 0000000..0805956
--- /dev/null
@@ -0,0 +1,23 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Calendar {
+       [CCode (cname = "calendar_backend_add_event")]
+       extern int add_event (char* summary, char* description, char* location, time_t start, time_t end);
+}
+