[Xfce4-commits] <orage:master> 4.8.1.4 Implemented enhancement bug 7612 Export .ics programatically
Juha Kautto
noreply at xfce.org
Sat Jul 16 13:02:01 CEST 2011
Updating branch refs/heads/master
to f0c6e4fefff2a7d09f6cc41756ed0a8f863d40cf (commit)
from d5a4100532b62f045e85e786f99850049afc44c8 (commit)
commit f0c6e4fefff2a7d09f6cc41756ed0a8f863d40cf
Author: Juha Kautto <juha at xfce.org>
Date: Sat Jul 16 13:57:02 2011 +0300
4.8.1.4 Implemented enhancement bug 7612 Export .ics programatically
Added startup parameter -e which can be used to export either all or only
named appointments.
configure.in.in | 2 +-
src/ical-expimp.c | 14 ++++++--
src/interface.c | 4 +-
src/interface.h | 1 +
src/main.c | 53 ++++++++++++++++++++++++++++++-
src/orage-dbus-client.c | 28 ++++++++++++++++
src/orage-dbus-client.h | 43 +++++++++++++++++++++++++
src/orage-dbus-object.c | 19 ++++++++++-
src/orage-dbus-object.h | 5 ++-
src/orage-dbus-service.h | 75 +++++++++++++++++++++++++++++++++++++-------
src/orage-dbus-service.xml | 5 +++
src/orage-dbus.h | 1 +
12 files changed, 226 insertions(+), 24 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index de82fff..7658a03 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -9,7 +9,7 @@ dnl Written for Xfce by Juha Kautto <juha at xfce.org>
dnl
dnl Version information
-m4_define([orage_version], [4.8.1.3-git])
+m4_define([orage_version], [4.8.1.4-git])
m4_define([gtk_minimum_version], [2.10.0])
m4_define([xfce_minimum_version], [4.6.0])
diff --git a/src/ical-expimp.c b/src/ical-expimp.c
index 606bed9..f7b1a00 100644
--- a/src/ical-expimp.c
+++ b/src/ical-expimp.c
@@ -313,8 +313,10 @@ static gboolean export_prepare_write_file(char *file_name)
return(FALSE);
}
g_free(tmp);
- if (g_remove(file_name) == -1) { /* note that it may not exist */
- orage_message(150, P_N "Failed to remove export file %s", file_name);
+ if (g_file_test(file_name, G_FILE_TEST_EXISTS)) {
+ if (g_remove(file_name) == -1) {
+ orage_message(150, P_N "Failed to remove export file %s", file_name);
+ }
}
return(TRUE);
}
@@ -405,6 +407,10 @@ static gboolean export_selected(char *file_name, char *uids)
/* checks done, let's start the real work */
more_uids = TRUE;
for (uid = uids; more_uids; ) {
+ if (strlen(uid) < 5) {
+ orage_message(150, P_N "unknown appointment name %s", uid);
+ return(FALSE);
+ }
uid_int = uid+4;
uid_end = g_strstr_len((const gchar *)uid, strlen(uid), ",");
if (uid_end != NULL)
@@ -419,13 +425,13 @@ static gboolean export_selected(char *file_name, char *uids)
export_selected_uid(ic_f_ical[i].ical, uid_int, x_ical);
}
else {
- orage_message(250, P_N "unknown foreign file number %s", uid);
+ orage_message(150, P_N "unknown foreign file number %s", uid);
return(FALSE);
}
}
else {
- orage_message(250, P_N "Unknown uid type %s", uid);
+ orage_message(150, P_N "Unknown uid type %s", uid);
}
if (uid_end != NULL) /* we have more uids */
diff --git a/src/interface.c b/src/interface.c
index 312e86e..e2b742d 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -456,9 +456,9 @@ gboolean orage_import_file(gchar *entry_filename)
return(FALSE);
}
-static gboolean orage_export_file(gchar *entry_filename, gint count, gchar *uids)
+gboolean orage_export_file(gchar *entry_filename, gint type, gchar *uids)
{
- return(xfical_export_file(entry_filename, count, uids));
+ return(xfical_export_file(entry_filename, type, uids));
}
static void imp_save_button_clicked(GtkButton *button, gpointer user_data)
diff --git a/src/interface.h b/src/interface.h
index 495ae2f..e9494c8 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -101,5 +101,6 @@ gboolean orage_foreign_files_check(gpointer user_data);
gboolean orage_foreign_file_add(gchar *filename, gboolean read_only);
gboolean orage_foreign_file_remove(gchar *filename);
gboolean orage_import_file(gchar *entry_filename);
+gboolean orage_export_file(gchar *entry_filename, gint type, gchar *uids);
#endif /* !__INTERFACE_H__ */
diff --git a/src/main.c b/src/main.c
index d7049e2..1bed05a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -236,6 +236,7 @@ static void print_help(void)
g_print(_("--toggle (-t) \t\tmake orage visible/unvisible\n"));
g_print(_("--add-foreign (-a) file [RW] \tadd a foreign file\n"));
g_print(_("--remove-foreign (-r) file \tremove a foreign file\n"));
+ g_print(_("--export (-e) file [appointment...] \texport appointments from Orage to file\n"));
g_print("\n");
g_print(_("files=ical files to load into orage\n"));
#ifndef HAVE_DBUS
@@ -266,10 +267,39 @@ static void import_file(gboolean running, char *file_name, gboolean initialized)
}
}
+static void export_file(gboolean running, char *file_name, gboolean initialized
+ , gchar *uid_list)
+{
+ gint type = 0;
+
+ if (uid_list)
+ type = 1;
+ else
+ type = 0;
+ g_print("export_file: running=%d initialized= %d type=%d, file=%s, uids=%s\n", running, initialized, type, file_name, uid_list);
+ if (running && !initialized) {
+ /* let's use dbus since server is running there already */
+#ifdef HAVE_DBUS
+ if (orage_dbus_export_file(file_name, type, uid_list))
+ orage_message(40, "export done to file=%s", file_name);
+ else
+ g_warning("export failed file=%s\n", file_name);
+#else
+ g_warning("Can not do export without dbus. failed file=%s\n", file_name);
+#endif
+ }
+ else if (!running && initialized) { /* do it self directly */
+ if (xfical_export_file(file_name, type, uid_list))
+ orage_message(40, "export done to file=%s", file_name);
+ else
+ g_warning("export failed file=%s\n", file_name);
+ }
+}
+
static void add_foreign(gboolean running, char *file_name, gboolean initialized
, gboolean read_only)
{
- if (running && !initialized)
+ if (running && !initialized) {
/* let's use dbus since server is running there already */
#ifdef HAVE_DBUS
if (orage_dbus_foreign_add(file_name, read_only))
@@ -279,6 +309,7 @@ static void add_foreign(gboolean running, char *file_name, gboolean initialized
#else
g_warning("Can not do add foreign file without dbus. failed file=%s\n", file_name);
#endif
+ }
else if (!running && initialized) { /* do it self directly */
if (orage_foreign_file_add(file_name, read_only))
orage_message(40, "add done foreign file=%s", file_name);
@@ -289,7 +320,7 @@ static void add_foreign(gboolean running, char *file_name, gboolean initialized
static void remove_foreign(gboolean running, char *file_name, gboolean initialized)
{
- if (running && !initialized)
+ if (running && !initialized) {
/* let's use dbus since server is running there already */
#ifdef HAVE_DBUS
if (orage_dbus_foreign_remove(file_name))
@@ -299,6 +330,7 @@ static void remove_foreign(gboolean running, char *file_name, gboolean initializ
#else
g_warning("Can not do remove foreign file without dbus. failed file=%s\n", file_name);
#endif
+ }
else if (!running && initialized) { /* do it self directly */
if (orage_foreign_file_remove(file_name))
orage_message(40, "remove done foreign file=%s", file_name);
@@ -313,6 +345,8 @@ static gboolean process_args(int argc, char *argv[], gboolean running
int argi;
gboolean end = FALSE;
gboolean foreign_file_read_only = TRUE;
+ gchar *export_uid_list = NULL;
+ gchar *file_name = NULL;
if (running && argc == 1) { /* no parameters */
raise_orage();
@@ -383,6 +417,21 @@ static gboolean process_args(int argc, char *argv[], gboolean running
remove_foreign(running, argv[++argi], initialized);
}
}
+ else if (!strcmp(argv[argi], "--export") ||
+ !strcmp(argv[argi], "-e")) {
+ if (argi+1 >= argc) {
+ g_print("\nFile not specified\n\n");
+ print_help();
+ end = TRUE;
+ }
+ else {
+ file_name = argv[++argi];
+ if (argi+1 < argc) {
+ export_uid_list = argv[++argi];
+ }
+ export_file(running, file_name, initialized, export_uid_list);
+ }
+ }
else if (argv[argi][0] == '-') {
g_print(_("\nUnknown option %s\n\n"), argv[argi]);
print_help();
diff --git a/src/orage-dbus-client.c b/src/orage-dbus-client.c
index 52815ac..bd7cb85 100644
--- a/src/orage-dbus-client.c
+++ b/src/orage-dbus-client.c
@@ -71,6 +71,34 @@ gboolean orage_dbus_import_file(gchar *file_name)
};
}
+gboolean orage_dbus_export_file(gchar *file_name, gint type, gchar *uids)
+{
+ DBusGConnection *connection;
+ GError *error = NULL;
+ DBusGProxy *proxy;
+
+ g_type_init();
+ connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (connection == NULL) {
+ g_warning("Failed to connect to the D-BUS session bus: %s"
+ , error->message);
+ return(FALSE);
+ }
+
+ proxy = dbus_g_proxy_new_for_name(connection
+ , "org.xfce.calendar", "/org/xfce/calendar", "org.xfce.calendar");
+ if (dbus_g_proxy_call(proxy, "ExportFile", &error
+ , G_TYPE_STRING, file_name
+ , G_TYPE_INT, type
+ , G_TYPE_STRING, uids
+ , G_TYPE_INVALID, G_TYPE_INVALID)) {
+ return(TRUE);
+ }
+ else {
+ return(FALSE);
+ };
+}
+
gboolean orage_dbus_foreign_add(gchar *file_name, gboolean read_only)
{
DBusGConnection *connection;
diff --git a/src/orage-dbus-client.h b/src/orage-dbus-client.h
index 9915741..3da3ecc 100644
--- a/src/orage-dbus-client.h
+++ b/src/orage-dbus-client.h
@@ -46,6 +46,47 @@ org_xfce_calendar_load_file_async (DBusGProxy *proxy, const char * IN_file, org_
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "LoadFile", org_xfce_calendar_load_file_async_callback, stuff, g_free, G_TYPE_STRING, IN_file, G_TYPE_INVALID);
}
+
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+org_xfce_calendar_export_file (DBusGProxy *proxy, const char * IN_file, const gint IN_type, const char * IN_uids, GError **error)
+
+{
+ return dbus_g_proxy_call (proxy, "ExportFile", error, G_TYPE_STRING, IN_file, G_TYPE_INT, IN_type, G_TYPE_STRING, IN_uids, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*org_xfce_calendar_export_file_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+org_xfce_calendar_export_file_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+ DBusGAsyncData *data = user_data;
+ GError *error = NULL;
+ dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+ (*(org_xfce_calendar_export_file_reply)data->cb) (proxy, error, data->userdata);
+ return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+org_xfce_calendar_export_file_async (DBusGProxy *proxy, const char * IN_file, const int IN_type, const char * IN_uids, org_xfce_calendar_export_file_reply callback, gpointer userdata)
+
+{
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ return dbus_g_proxy_begin_call (proxy, "ExportFile", org_xfce_calendar_export_file_async_callback, stuff, g_free, G_TYPE_STRING, IN_file, G_TYPE_INT, IN_type,G_TYPE_STRING, IN_uids, G_TYPE_INVALID);
+}
+
+
static
#ifdef G_HAVE_INLINE
inline
@@ -83,6 +124,8 @@ org_xfce_calendar_add_foreign_async (DBusGProxy *proxy, const char * IN_file, co
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "AddForeign", org_xfce_calendar_add_foreign_async_callback, stuff, g_free, G_TYPE_STRING, IN_file, G_TYPE_BOOLEAN, IN_mode, G_TYPE_INVALID);
}
+
+
static
#ifdef G_HAVE_INLINE
inline
diff --git a/src/orage-dbus-object.c b/src/orage-dbus-object.c
index 3570c61..ba58eca 100644
--- a/src/orage-dbus-object.c
+++ b/src/orage-dbus-object.c
@@ -33,6 +33,7 @@
/* defined in interface.c */
gboolean orage_import_file(gchar *entry_filename);
+gboolean orage_export_file(gchar *filename, gint type, gchar *uids);
gboolean orage_foreign_file_add(gchar *filename, gboolean read_only);
gboolean orage_foreign_file_remove(gchar *filename);
@@ -103,11 +104,25 @@ gboolean orage_dbus_service_load_file(DBusGProxy *proxy
}
}
+gboolean orage_dbus_service_export_file(DBusGProxy *proxy
+ , const char *IN_file, const int IN_type, const char *IN_uids
+ , GError **error)
+{
+ if (orage_export_file((char *)IN_file, (gint)IN_type, (char *)IN_uids)) {
+ g_message("Orage **: DBUS File exported %s", IN_file);
+ return(TRUE);
+ }
+ else {
+ g_warning("DBUS File export failed %s", IN_file);
+ return(FALSE);
+ }
+}
+
gboolean orage_dbus_service_add_foreign(DBusGProxy *proxy
- , const char *IN_file, const gboolean *IN_mode
+ , const char *IN_file, const gboolean IN_mode
, GError **error)
{
- if (orage_foreign_file_add((char *)IN_file, (gboolean)*IN_mode)) {
+ if (orage_foreign_file_add((char *)IN_file, (gboolean)IN_mode)) {
g_message("Orage **: DBUS Foreign file added %s", IN_file);
return(TRUE);
}
diff --git a/src/orage-dbus-object.h b/src/orage-dbus-object.h
index 4d5ad9d..8eba47f 100644
--- a/src/orage-dbus-object.h
+++ b/src/orage-dbus-object.h
@@ -43,8 +43,11 @@ GType orage_dbus_get_type(void);
gboolean orage_dbus_service_load_file(DBusGProxy *proxy
, const char *IN_file
, GError **error);
+gboolean orage_dbus_service_export_file(DBusGProxy *proxy
+ , const char *IN_file, const gint IN_type, const char *IN_uids
+ , GError **error);
gboolean orage_dbus_service_add_foreign(DBusGProxy *proxy
- , const char *IN_file, const gboolean *IN_mode
+ , const char *IN_file, const gboolean IN_mode
, GError **error);
gboolean orage_dbus_service_remove_foreign(DBusGProxy *proxy
, const char *IN_file
diff --git a/src/orage-dbus-service.h b/src/orage-dbus-service.h
index d179b02..645695d 100644
--- a/src/orage-dbus-service.h
+++ b/src/orage-dbus-service.h
@@ -53,7 +53,7 @@ G_BEGIN_DECLS
#endif /* !G_ENABLE_DEBUG */
-/* BOOLEAN:STRING,BOOLEAN,POINTER (/tmp/dbus-binding-tool-c-marshallers.q1gxbp:1) */
+/* BOOLEAN:STRING,BOOLEAN,POINTER */
extern void dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -62,10 +62,10 @@ extern void dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER (GClosure
gpointer marshal_data);
void
dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER (GClosure *closure,
- GValue *return_value,
+ GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
- gpointer invocation_hint,
+ gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_BOOLEAN_POINTER) (gpointer data1,
@@ -102,7 +102,7 @@ dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
-/* BOOLEAN:STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.q1gxbp:2) */
+/* BOOLEAN:STRING,POINTER */
extern void dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER (GClosure *closure,
GValue *return_value,
guint n_param_values,
@@ -111,10 +111,10 @@ extern void dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER (GClosure *closu
gpointer marshal_data);
void
dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER (GClosure *closure,
- GValue *return_value,
+ GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
- gpointer invocation_hint,
+ gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_POINTER) (gpointer data1,
@@ -149,6 +149,57 @@ dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER (GClosure *closure,
g_value_set_boolean (return_value, v_return);
}
+/* BOOLEAN:STRING,INT,STRING,POINTER */
+extern void dbus_glib_marshal_orage_BOOLEAN__STRING_INT_STRING_POINTER (GClosure *closure,
+ GValue *return_value,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data);
+void
+dbus_glib_marshal_orage_BOOLEAN__STRING_INT_STRING_POINTER (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_INT_STRING_POINTER) (gpointer data1,
+ gpointer arg_1,
+ gint arg_2,
+ gpointer arg_3,
+ gpointer arg_4,
+ gpointer data2);
+ register GMarshalFunc_BOOLEAN__STRING_INT_STRING_POINTER callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+ gboolean v_return;
+
+ g_return_if_fail (return_value != NULL);
+ g_return_if_fail (n_param_values == 5);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_BOOLEAN__STRING_INT_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+ v_return = callback (data1,
+ g_marshal_value_peek_string (param_values + 1),
+ g_marshal_value_peek_int (param_values + 2),
+ g_marshal_value_peek_string (param_values + 3),
+ g_marshal_value_peek_pointer (param_values + 4),
+ data2);
+
+ g_value_set_boolean (return_value, v_return);
+}
+
G_END_DECLS
#endif /* __dbus_glib_marshal_orage_MARSHAL_H__ */
@@ -156,15 +207,15 @@ G_END_DECLS
#include <dbus/dbus-glib.h>
static const DBusGMethodInfo dbus_glib_orage_methods[] = {
{ (GCallback) orage_dbus_service_load_file, dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER, 0 },
- { (GCallback) orage_dbus_service_add_foreign, dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER, 39 },
- { (GCallback) orage_dbus_service_remove_foreign, dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER, 89 },
+ { (GCallback) orage_dbus_service_export_file, dbus_glib_marshal_orage_BOOLEAN__STRING_INT_STRING_POINTER, 39 },
+ { (GCallback) orage_dbus_service_add_foreign, dbus_glib_marshal_orage_BOOLEAN__STRING_BOOLEAN_POINTER, 98 },
+ { (GCallback) orage_dbus_service_remove_foreign, dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER, 148 },
};
-const DBusGObjectInfo dbus_glib_orage_object_info = {
- 0,
+const DBusGObjectInfo dbus_glib_orage_object_info = { 1,
dbus_glib_orage_methods,
- 3,
-"org.xfce.calendar\0LoadFile\0S\0file\0I\0s\0\0org.xfce.calendar\0AddForeign\0S\0file\0I\0s\0mode\0I\0b\0\0org.xfce.calendar\0RemoveForeign\0S\0file\0I\0s\0\0\0",
+ 4,
+"org.xfce.calendar\0LoadFile\0S\0file\0I\0s\0\0org.xfce.calendar\0ExportFile\0S\0file\0I\0s\0type\0I\0i\0uids\0I\0s\0\0org.xfce.calendar\0AddForeign\0S\0file\0I\0s\0mode\0I\0b\0\0org.xfce.calendar\0RemoveForeign\0S\0file\0I\0s\0\0\0",
"\0",
"\0"
};
diff --git a/src/orage-dbus-service.xml b/src/orage-dbus-service.xml
index 27e1ca5..a9f6dcd 100644
--- a/src/orage-dbus-service.xml
+++ b/src/orage-dbus-service.xml
@@ -30,6 +30,11 @@
-->
<arg type="s" name="file" direction="in" />
</method>
+ <method name="ExportFile">
+ <arg type="s" name="file" direction="in" />
+ <arg type="i" name="type" direction="in" />
+ <arg type="s" name="uids" direction="in" />
+ </method>
<method name="AddForeign">
<arg type="s" name="file" direction="in" />
<arg type="b" name="mode" direction="in" />
diff --git a/src/orage-dbus.h b/src/orage-dbus.h
index 87f5794..1b7c28e 100644
--- a/src/orage-dbus.h
+++ b/src/orage-dbus.h
@@ -25,6 +25,7 @@
void orage_dbus_start(void);
gboolean orage_dbus_import_file(gchar *file_name);
+gboolean orage_dbus_export_file(gchar *file_name, gint type, gchar *uids);
gboolean orage_dbus_foreign_add(gchar *file_name, gboolean read_only);
gboolean orage_dbus_foreign_remove(gchar *file_name);
More information about the Xfce4-commits
mailing list