Code cleanup around glib version check (2.28 minimum).
[claws.git] / src / plugins / vcalendar / vcal_dbus.c
index dad54c12cf611d7265b828f2b4be2fcc07156686..f60987252657675a067c18df2f1fef020720559e 100644 (file)
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <ical.h>
+#include <libical/ical.h>
 #include <gtk/gtk.h>
 
 #include "utils.h"
 #include "vcal_manager.h"
 #include "vcal_folder.h"
 
-#if(GLIB_CHECK_VERSION(2,26,0))
-
 static guint dbus_own_id;
 
 static void add_event_to_builder_if_match(VCalEvent *event, GVariantBuilder *array,
@@ -103,11 +101,15 @@ static void handle_method_call (GDBusConnection       *connection,
                /* Don't free that, it's done when subscriptions are
                 * fetched */
                icalcomponent *ical = (icalcomponent *)cur->data;
-               VCalEvent *event = vcal_get_event_from_ical(
-                       icalcomponent_as_ical_string(ical), NULL);
-
-               add_event_to_builder_if_match(event, array, start, end);
-               g_free(event);
+               if (ical != NULL) {
+                       VCalEvent *event = vcal_get_event_from_ical(
+                               icalcomponent_as_ical_string(ical), NULL);
+                       if (event != NULL) {
+                               add_event_to_builder_if_match(
+                                       event, array, start, end);
+                               g_free(event);
+                       }
+               }
        }
        g_slist_free(list);
 
@@ -121,12 +123,7 @@ static void handle_method_call (GDBusConnection       *connection,
 }
 
 
-static const GDBusInterfaceVTable interface_vtable =
-{
-       handle_method_call,
-       NULL,
-       NULL
-};
+static GDBusInterfaceVTable* interface_vtable = NULL;
 
 static GDBusNodeInfo *introspection_data = NULL;
 static GDBusInterfaceInfo *interface_info = NULL;
@@ -162,23 +159,32 @@ static void bus_acquired(GDBusConnection *connection,
                         gpointer         user_data)
 {
        GError *err = NULL;
+
+       cm_return_if_fail(interface_vtable);
+
        g_dbus_connection_register_object(connection,
                "/org/gnome/Shell/CalendarServer",
                introspection_data->interfaces[0],
-               &interface_vtable, NULL, NULL, &err);
+               (const GDBusInterfaceVTable *)interface_vtable, NULL, NULL, &err);
        if (err != NULL)
                debug_print("Error: %s\n", err->message);
 }
 
 void connect_dbus(void)
 {
+       debug_print("connect_dbus() invoked\n");
+
+       interface_vtable = g_malloc0(sizeof(GDBusInterfaceVTable));
+       cm_return_if_fail(interface_vtable);
+       interface_vtable->method_call = (GDBusInterfaceMethodCallFunc)handle_method_call;
+
        introspection_data = g_dbus_node_info_new_for_xml(
                                introspection_xml, NULL);
        if (introspection_data == NULL) {
-               debug_print("Couldn't figure out XML.");
+               debug_print("Couldn't figure out XML.\n");
                return;
        }
-       
+
        interface_info = g_dbus_node_info_lookup_interface(
                                introspection_data,
                                "org.gnome.Shell.CalendarServer");
@@ -194,16 +200,9 @@ void connect_dbus(void)
 
 void disconnect_dbus(void)
 {
+       debug_print("disconnect_dbus() invoked\n");
        g_bus_unown_name(dbus_own_id);
-}
 
-#else
-void connect_dbus(void)
-{
-       debug_print("DBUS calendar export is not supported with Glib < 2.26\n");
+       g_free(interface_vtable);
+       interface_vtable = NULL;
 }
-void disconnect_dbus(void)
-{
-       debug_print("DBUS calendar export is not supported with Glib < 2.26\n");
-}
-#endif