Index: src/orage-dbus-object.h =================================================================== --- src/orage-dbus-object.h (revision 25178) +++ src/orage-dbus-object.h (working copy) @@ -42,6 +42,10 @@ gboolean orage_dbus_service_load_file(DBusGProxy *proxy, const char * IN_str , GError **error); +gboolean orage_dbus_service_add_foreign(DBusGProxy *proxy, const char * IN_str + , GError **error); +gboolean orage_dbus_service_remove_foreign(DBusGProxy *proxy, const char * IN_str + , GError **error); G_END_DECLS; Index: src/orage-dbus-service.xml =================================================================== --- src/orage-dbus-service.xml (revision 25178) +++ src/orage-dbus-service.xml (working copy) @@ -30,5 +30,11 @@ --> + + + + + + Index: src/orage-dbus-client.c =================================================================== --- src/orage-dbus-client.c (revision 25178) +++ src/orage-dbus-client.c (working copy) @@ -69,3 +69,59 @@ }; } +gboolean orage_dbus_add_foreign(gchar *file_name) +{ + DBusGConnection *connection; + GError *error = NULL; + DBusGProxy *proxy; + + g_type_init(); + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (connection == NULL) { + /* notify the user that D-BUS service won't be available */ + g_warning("Failed to connect to the D-BUS session bus: %s" + , error->message); + return(FALSE); + } + + /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */ + proxy = dbus_g_proxy_new_for_name(connection + , "org.xfce.calendar", "/org/xfce/calendar", "org.xfce.calendar"); + + if (dbus_g_proxy_call(proxy, "AddForeign", &error, G_TYPE_STRING, file_name + , G_TYPE_INVALID, G_TYPE_INVALID)) { + return(TRUE); + } + else { + return(FALSE); + }; +} + +gboolean orage_dbus_remove_foreign(gchar *file_name) +{ + DBusGConnection *connection; + GError *error = NULL; + DBusGProxy *proxy; + + g_type_init(); + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (connection == NULL) { + /* notify the user that D-BUS service won't be available */ + g_warning("Failed to connect to the D-BUS session bus: %s" + , error->message); + return(FALSE); + } + + /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */ + proxy = dbus_g_proxy_new_for_name(connection + , "org.xfce.calendar", "/org/xfce/calendar", "org.xfce.calendar"); + + if (dbus_g_proxy_call(proxy, "RemoveForeign", &error, G_TYPE_STRING, file_name + , G_TYPE_INVALID, G_TYPE_INVALID)) { + return(TRUE); + } + else { + return(FALSE); + }; +} + Index: src/parameters.c =================================================================== --- src/parameters.c (revision 25178) +++ src/parameters.c (working copy) @@ -848,3 +848,81 @@ set_ontop(); xfical_set_local_timezone(); } + +gboolean add_foreign_file(const gchar *file_name, gboolean read_only) +{ + gint i = 0; + gboolean found = FALSE; + + if (file_name == NULL) { + g_warning("File not specified"); + return FALSE; + } + + if (!g_file_test(file_name, G_FILE_TEST_EXISTS)) { + g_warning("New file %s does not exist. New file not added." + , file_name); + return FALSE; + } + + if (!ORAGE_STR_EXISTS(file_name)) { + g_warning("File is empty. New file not added."); + return FALSE; + } + + if (g_par.foreign_count > 9) { + g_warning("Orage can only handle 10 foreign fils. Limit reached. New file not added."); + return FALSE; + } + + for (i = 0; i < g_par.foreign_count; i++) { + if (g_par.foreign_data[i].file != NULL + && strcmp(g_par.foreign_data[i].file, file_name) == 0) { + found = TRUE; + break; + } + } + + if (found) { + g_warning("Foreign file already exists."); + return FALSE; + } + + g_par.foreign_data[g_par.foreign_count].file = g_strdup(file_name); + g_par.foreign_data[g_par.foreign_count].read_only = read_only; + g_par.foreign_count++; + + write_parameters(); + return TRUE; +} + +void remove_foreign_file(const gchar *file_name) +{ + int i = 0; + gboolean found = FALSE; + + if (file_name == NULL) { + g_warning("File not specified"); + return; + } + + for (i = 0; i < g_par.foreign_count; i++) { + if (g_par.foreign_data[i].file != NULL + && strcmp(g_par.foreign_data[i].file, file_name) == 0) { + g_free(g_par.foreign_data[i].file); + found = TRUE; + break; + } + } + + if (!found) + return; + + g_par.foreign_count--; + for (; i < g_par.foreign_count; i++) { + g_par.foreign_data[i].file = g_par.foreign_data[i+1].file; + g_par.foreign_data[i].read_only = g_par.foreign_data[i+1].read_only; + } + + write_parameters(); +} Index: src/parameters.h =================================================================== --- src/parameters.h (revision 25178) +++ src/parameters.h (working copy) @@ -98,5 +98,6 @@ void write_parameters(void); void read_parameters(void); void set_parameters(void); - +gboolean add_foreign_file(const gchar *file_name, gboolean read_only); +void remove_foreign_file(const gchar *file_name); #endif /* !__ORAGE_PARAMETERS_H__ */ Index: src/main.c =================================================================== --- src/main.c (revision 25178) +++ src/main.c (working copy) @@ -279,16 +279,18 @@ { g_print(_("Usage: orage [options] files\n\n")); g_print(_("Options:\n")); - g_print(_("--version (-v) \t\tshow version of orage\n")); - g_print(_("--help (-h) \t\tprint this text\n")); - g_print(_("--preferences (-p) \tshow preferences form\n")); - g_print(_("--toggle (-t) \t\tmake orage visible/unvisible\n")); + g_print(_("--version (-v) \t\t\tshow version of orage\n")); + g_print(_("--help (-h) \t\t\tprint this text\n")); + g_print(_("--preferences (-p) \t\tshow preferences form\n")); + g_print(_("--toggle (-t) \t\t\tmake orage visible/unvisible\n")); + g_print(_("--add-foreign (-a) file \tadd a foreign file\n")); + g_print(_("--remove-foreign (-r) file \tremove a foreign file\n")); g_print("\n"); g_print(_("files=ical files to load into orage\n")); #ifndef HAVE_DBUS g_print(_("\tdbus not included in orage. \n")); g_print(_("\tfiles for running orage not supported without dbus \n")); - g_print(_("\tfiles can only be used when starting orage \n")); + g_print(_("\tfiles and foreign files can only be used when starting orage \n")); #endif g_print("\n"); } @@ -312,6 +314,42 @@ g_warning("import failed file=%s\n", file_name); } +static void add_foreign(gboolean running, char *file_name, gboolean initialized) +{ + if (running && !initialized) + /* let's use dbus since server is running there already */ +#ifdef HAVE_DBUS + if (orage_dbus_add_foreign(file_name)) + orage_message("add done foreign file=%s", file_name); + else + g_warning("add failed foreign file=%s\n", file_name); +#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 */ + add_foreign_file(file_name, TRUE); + exit(0); + } +} + +static void remove_foreign(gboolean running, char *file_name, gboolean initialized) +{ + if (running && !initialized) + /* let's use dbus since server is running there already */ +#ifdef HAVE_DBUS + if (orage_dbus_remove_foreign(file_name)) + orage_message("remove done foreign file=%s", file_name); + else + g_warning("remove failed foreign file=%s\n", file_name); +#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 */ + remove_foreign_file(file_name); + exit(0); + } +} + static gboolean process_args(int argc, char *argv[], gboolean running , gboolean initialized) { @@ -356,6 +394,26 @@ orage_toggle_visible(); end = TRUE; } + else if (!strcmp(argv[argi], "--add-foreign") || + !strcmp(argv[argi], "-a")) { + if (argi+1 >= argc) { + g_print("\nFile not specified\n\n"); + print_help(); + end = TRUE; + } else { + add_foreign(running, argv[++argi], initialized); + } + } + else if (!strcmp(argv[argi], "--remove-foreign") || + !strcmp(argv[argi], "-r")) { + if (argi+1 >= argc) { + g_print("\nFile not specified\n\n"); + print_help(); + end = TRUE; + } else { + remove_foreign(running, argv[++argi], initialized); + } + } else if (argv[argi][0] == '-') { g_print(_("\nUnknown parameter %s\n\n"), argv[argi]); print_help(); Index: src/orage-dbus-service.h =================================================================== --- src/orage-dbus-service.h (revision 25178) +++ src/orage-dbus-service.h (working copy) @@ -53,7 +53,7 @@ #endif /* !G_ENABLE_DEBUG */ -/* BOOLEAN:STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.sI10Xj:1) */ +/* BOOLEAN:STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.SLMEPT:1) */ extern void dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER (GClosure *closure, GValue *return_value, guint n_param_values, @@ -107,13 +107,15 @@ #include 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_POINTER, 38 }, + { (GCallback) orage_dbus_service_remove_foreign, dbus_glib_marshal_orage_BOOLEAN__STRING_POINTER, 78 }, }; const DBusGObjectInfo dbus_glib_orage_object_info = { 0, dbus_glib_orage_methods, - 1, -"org.xfce.calendar\0LoadFile\0S\0str\0I\0s\0\0\0", + 3, +"org.xfce.calendar\0LoadFile\0S\0str\0I\0s\0\0org.xfce.calendar\0AddForeign\0S\0str\0I\0s\0\0org.xfce.calendar\0RemoveForeign\0S\0str\0I\0s\0\0\0", "\0", "\0" }; Index: src/orage-dbus-object.c =================================================================== --- src/orage-dbus-object.c (revision 25178) +++ src/orage-dbus-object.c (working copy) @@ -101,6 +101,28 @@ } } +gboolean orage_dbus_service_add_foreign(DBusGProxy *proxy, const char * IN_str + , GError **error) +{ + if (add_foreign_file(IN_str, TRUE)) { + g_message("Orage **: DBUS Foreign file added %s", IN_str); + return(TRUE); + } + else { + g_warning("DBUS Foreign file add failed %s", IN_str); + return(FALSE); + } + return TRUE; +} + +gboolean orage_dbus_service_remove_foreign(DBusGProxy *proxy, const char * IN_str + , GError **error) +{ + remove_foreign_file(IN_str); + g_message("Orage **: DBUS Foreign file removed %s", IN_str); + return(TRUE); +} + void orage_dbus_start() { orage_dbus = g_object_new(ORAGE_DBUS_TYPE, NULL); Index: src/interface.c =================================================================== --- src/interface.c (revision 25178) +++ src/interface.c (working copy) @@ -575,32 +575,17 @@ void for_add_button_clicked(GtkButton *button, gpointer user_data) { intf_win *intf_w = (intf_win *)user_data; - gchar *entry_filename; + const gchar *entry_filename; gboolean read_only; - if (g_par.foreign_count > 9) { - g_warning("Orage can only handle 10 foreign fils. Limit reached. New file not added."); - return; - } - entry_filename = g_strdup(gtk_entry_get_text( - (GtkEntry *)intf_w->for_new_entry)); - if (!ORAGE_STR_EXISTS(entry_filename)) { - g_warning("File is empty. New file not added."); - return; - } - if (!g_file_test(entry_filename, G_FILE_TEST_EXISTS)) { - g_warning("New file %s does not exist. New file not added." - , entry_filename); - g_free(entry_filename); - return; - } + entry_filename = gtk_entry_get_text( + (GtkEntry *)intf_w->for_new_entry); + read_only = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(intf_w->for_new_read_only)); - g_par.foreign_data[g_par.foreign_count].file = entry_filename; - g_par.foreign_data[g_par.foreign_count].read_only = read_only; - g_par.foreign_count++; - write_parameters(); - refresh_foreign_files(intf_w, FALSE); + + if (add_foreign_file(entry_filename, read_only)) + refresh_foreign_files(intf_w, FALSE); } void close_intf_w(gpointer user_data)