PATCH: Backup conduit exclude files
- From: Paul Warren <pdw ferret lmh ox ac uk>
- To: gnome-pilot-list gnome org
- Subject: PATCH: Backup conduit exclude files
- Date: Fri, 31 Mar 2000 03:01:51 +0100 (BST)
Hiya,
I tried gnome-pilot for the time in a few months after failing to get it
to work well last time, and it looks a lot better :-) It still segfaults
a bit though :-( I'll send bug reports once I can figure out how to
segfault it repeatably.
Anyway, I put together this patch which adds a control to the
backup conduit capplet to handle excluding files from the backup. Most of
the code was already there, it just needed the capplet.
This is my first attempt at any GTK programming, so you'll probably want
to read over the patch :-)
thanks for a great program,
Paul
Index: conduits/backup/backup-conduit-control-applet.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/conduits/backup/backup-conduit-control-applet.c,v
retrieving revision 1.23
diff -c -r1.23 backup-conduit-control-applet.c
*** conduits/backup/backup-conduit-control-applet.c 2000/03/12 02:17:52 1.23
--- conduits/backup/backup-conduit-control-applet.c 2000/03/31 01:47:33
***************
*** 59,66 ****
load_configuration(ConduitCfg **c,guint32 pilotId)
{
gchar *prefix;
! gchar *exclude;
! gchar **excs;
guint i;
*c = g_new0(ConduitCfg,1);
--- 59,66 ----
load_configuration(ConduitCfg **c,guint32 pilotId)
{
gchar *prefix;
! gchar **exclude_files;
! guint num_of_exclude_files =0;
guint i;
*c = g_new0(ConduitCfg,1);
***************
*** 72,88 ****
(*c)->backup_dir = gnome_config_get_string("backup_dir");
(*c)->updated_only = gnome_config_get_bool("updated_only=TRUE");
(*c)->remove_deleted = gnome_config_get_bool("remove_deleted=FALSE");
! exclude = gnome_config_get_string("exclude_files");
! if(exclude != NULL) {
! (*c)->exclude_files = NULL;
! excs = g_strsplit( exclude, ",", 0 );
! for( i = 0; excs[i] != NULL ; i++ ) {
! (*c)->exclude_files = g_list_insert_sorted( (*c)->exclude_files ,
! g_strdup(excs[i]),
! (GCompareFunc)g_strcasecmp);
! }
! g_strfreev(excs);
}
gnome_config_pop_prefix();
(*c)->files_in_backup = NULL;
--- 72,85 ----
(*c)->backup_dir = gnome_config_get_string("backup_dir");
(*c)->updated_only = gnome_config_get_bool("updated_only=TRUE");
(*c)->remove_deleted = gnome_config_get_bool("remove_deleted=FALSE");
! gnome_config_get_vector("exclude_files",&num_of_exclude_files,&exclude_files);
! for( i = 0; i<num_of_exclude_files ; i++ ) {
! if (strlen(exclude_files[i]))
! (*c)->exclude_files = g_list_insert_sorted( (*c)->exclude_files ,
! g_strdup(exclude_files[i]),
! (GCompareFunc)g_strcasecmp);
}
+ g_free(exclude_files);
gnome_config_pop_prefix();
(*c)->files_in_backup = NULL;
***************
*** 110,116 ****
save_configuration(ConduitCfg *c)
{
gchar *prefix;
! gchar **exclude;
gchar *exc=NULL;
GList *iterator;
guint i;
--- 107,113 ----
save_configuration(ConduitCfg *c)
{
gchar *prefix;
! gchar **exclude = NULL;
gchar *exc=NULL;
GList *iterator;
guint i;
***************
*** 126,142 ****
exclude[i] = iterator->data;
}
exclude[i] = NULL;
- exc = g_strjoinv( ",", exclude);
- g_free(exclude);
}
gnome_config_push_prefix(prefix);
gnome_config_set_string("backup_dir",c->backup_dir);
gnome_config_set_bool("updated_only",c->updated_only);
gnome_config_set_bool("remove_deleted",c->remove_deleted);
! gnome_config_set_string("exclude_files",exc);
gnome_config_pop_prefix();
gnome_config_sync();
gnome_config_drop_all();
g_free(prefix);
g_free(exc);
}
--- 123,139 ----
exclude[i] = iterator->data;
}
exclude[i] = NULL;
}
gnome_config_push_prefix(prefix);
gnome_config_set_string("backup_dir",c->backup_dir);
gnome_config_set_bool("updated_only",c->updated_only);
gnome_config_set_bool("remove_deleted",c->remove_deleted);
! g_message("length: %d",g_list_length(c->exclude_files));
! gnome_config_set_vector("exclude_files",g_list_length(c->exclude_files),(const gchar**)exclude);
gnome_config_pop_prefix();
gnome_config_sync();
gnome_config_drop_all();
+ if (exclude) g_free(exclude);
g_free(prefix);
g_free(exc);
}
***************
*** 199,205 ****
doTrySettings(GtkWidget *widget, gpointer whatever)
{
readStateCfg(cfgStateWindow, curState,&activated);
! readOptionsCfg(cfgOptionsWindow, curState);
setSettings(curState,activated);
}
--- 196,202 ----
doTrySettings(GtkWidget *widget, gpointer whatever)
{
readStateCfg(cfgStateWindow, curState,&activated);
! readOptionsCfg(capplet, curState);
setSettings(curState,activated);
}
***************
*** 220,226 ****
{
activated = org_activation_state;
copy_configuration(curState,origState);
! setOptionsCfg(cfgOptionsWindow, curState);
setStateCfg(cfgStateWindow, curState,activated);
setSettings(curState,activated);
}
--- 217,223 ----
{
activated = org_activation_state;
copy_configuration(curState,origState);
! setOptionsCfg(capplet, curState);
setStateCfg(cfgStateWindow, curState,activated);
setSettings(curState,activated);
}
***************
*** 289,294 ****
--- 286,349 ----
capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
}
}
+
+ static void
+ new_exclude_file_cb (gchar * string,gpointer data)
+ {
+ if(!ignore_changes && string && strlen(string)) {
+ GtkCList * list;
+ gint row;
+ curState->exclude_files = g_list_insert_sorted( curState->exclude_files ,
+ string,
+ (GCompareFunc)g_strcasecmp);
+ list = gtk_object_get_data(GTK_OBJECT(capplet),"exclude_list");
+ row = gtk_clist_append(GTK_CLIST(list),&string);
+ gtk_clist_set_row_data(GTK_CLIST(list),row,string);
+ capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
+ }
+ }
+
+ static void
+ add_exclude_file_cb (GtkButton * button, gpointer data)
+ {
+ if(!ignore_changes) {
+ gnome_request_dialog(FALSE,"File to exclude from backups","",40,GTK_SIGNAL_FUNC(new_exclude_file_cb),NULL,NULL);
+ }
+ }
+
+ static void
+ delete_exclude_file_cb (GtkButton * button, gpointer data)
+ {
+ if(!ignore_changes) {
+ gint row;
+ GtkCList * list;
+ list = gtk_object_get_data(GTK_OBJECT(capplet),"exclude_list");
+ row = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(list),"selected"));
+
+ if (row != -1) {
+ gpointer data;
+ data = gtk_clist_get_row_data(GTK_CLIST(list),row);
+ gtk_clist_remove(GTK_CLIST(list),row);
+ curState->exclude_files=g_list_remove(curState->exclude_files,data);
+ capplet_widget_state_changed(CAPPLET_WIDGET(capplet), TRUE);
+ }
+ }
+ }
+
+ static void
+ list_select_cb (GtkCList *clist, gint row,gint column,GdkEventButton *event,gpointer user_data)
+ {
+ gtk_object_set_data(GTK_OBJECT(clist),"selected",GINT_TO_POINTER(row));
+ }
+
+ static void
+ list_unselect_cb (GtkCList *clist, gint row, gint column, GdkEventButton *event, gpointer user_data)
+ {
+ gtk_object_set_data(GTK_OBJECT(clist),"selected",GINT_TO_POINTER(-1));
+ }
+
+
+
static GtkWidget
*createStateCfgWindow(void)
{
***************
*** 348,354 ****
/* "userid" - entry box for pilot user id */
/* "username" - entry box for pilot user name */
static GtkWidget
! *createCfgWindow(void)
{
GtkWidget *vbox, *table;
GtkWidget *entry, *label;
--- 403,409 ----
/* "userid" - entry box for pilot user id */
/* "username" - entry box for pilot user name */
static GtkWidget
! *createCfgWindow(GtkObject * cfgObject)
{
GtkWidget *vbox, *table;
GtkWidget *entry, *label;
***************
*** 365,371 ****
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
entry = gtk_entry_new_with_max_length(128);
! gtk_object_set_data(GTK_OBJECT(vbox), "dir", entry);
gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 0, 1);
gtk_signal_connect(GTK_OBJECT(entry), "insert_text",
GTK_SIGNAL_FUNC(insert_dir_callback),
--- 420,426 ----
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
entry = gtk_entry_new_with_max_length(128);
! gtk_object_set_data(GTK_OBJECT(cfgObject), "dir", entry);
gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 0, 1);
gtk_signal_connect(GTK_OBJECT(entry), "insert_text",
GTK_SIGNAL_FUNC(insert_dir_callback),
***************
*** 381,387 ****
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1,2);
button = gtk_check_button_new();
! gtk_object_set_data(GTK_OBJECT(vbox), "only_changed", button);
gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 1,2);
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(button_toggled_cb),
--- 436,442 ----
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1,2);
button = gtk_check_button_new();
! gtk_object_set_data(GTK_OBJECT(cfgObject), "only_changed", button);
gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 1,2);
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(button_toggled_cb),
***************
*** 391,397 ****
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2,3);
button = gtk_check_button_new();
! gtk_object_set_data(GTK_OBJECT(vbox), "remove_local", button);
gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 2,3);
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(button_toggled_cb),
--- 446,452 ----
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2,3);
button = gtk_check_button_new();
! gtk_object_set_data(GTK_OBJECT(cfgObject), "remove_local", button);
gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 2,3);
gtk_signal_connect(GTK_OBJECT(button), "toggled",
GTK_SIGNAL_FUNC(button_toggled_cb),
***************
*** 401,425 ****
return vbox;
}
static void
setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
{
! GtkWidget *dir,*updated_only,*remove_deleted;
dir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "dir");
updated_only = gtk_object_get_data(GTK_OBJECT(pilotcfg), "only_changed");
remove_deleted = gtk_object_get_data(GTK_OBJECT(pilotcfg), "remove_local");
g_assert(dir!=NULL);
g_assert(updated_only!=NULL);
g_assert(remove_deleted!=NULL);
ignore_changes = TRUE;
gtk_entry_set_text(GTK_ENTRY(dir), state->backup_dir);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(updated_only), state->updated_only);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remove_deleted), state->remove_deleted);
ignore_changes = FALSE;
}
--- 456,535 ----
return vbox;
}
+ static GtkWidget
+ * createExcludeCfgWindow(GtkObject * cfgObject)
+ {
+ GtkWidget * vbox, * hbox;
+ GtkWidget * label, * list;
+ GtkWidget * button;
+ GtkWidget * scrolled_window;
+
+ vbox = gtk_vbox_new(FALSE, GNOME_PAD);
+ label = gtk_label_new(_("Do not backup these files:"));
+
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, GNOME_PAD);
+
+ scrolled_window = gtk_scrolled_window_new(NULL,NULL);
+
+
+ list = gtk_clist_new(1);
+
+ gtk_box_pack_start(GTK_BOX(vbox), list, TRUE, TRUE, 0);
+
+ gtk_signal_connect(GTK_OBJECT(list),"select-row",GTK_SIGNAL_FUNC(list_select_cb),NULL);
+ gtk_signal_connect(GTK_OBJECT(list),"unselect-row",GTK_SIGNAL_FUNC(list_unselect_cb),NULL);
+ gtk_object_set_data(GTK_OBJECT(list),"selected",GINT_TO_POINTER(-1));
+ gtk_object_set_data(GTK_OBJECT(cfgObject),"exclude_list",list);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, GNOME_PAD);
+
+ button = gtk_button_new_with_label(_("Add..."));
+ gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, GNOME_PAD);
+ gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(add_exclude_file_cb),NULL);
+
+ button = gtk_button_new_with_label(_("Delete"));
+ gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, GNOME_PAD);
+ gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(delete_exclude_file_cb),NULL);
+
+ return vbox;
+ }
+
static void
setOptionsCfg(GtkWidget *pilotcfg, ConduitCfg *state)
{
! GtkWidget *dir,*updated_only,*remove_deleted,*exclude_list;
!
dir = gtk_object_get_data(GTK_OBJECT(pilotcfg), "dir");
updated_only = gtk_object_get_data(GTK_OBJECT(pilotcfg), "only_changed");
remove_deleted = gtk_object_get_data(GTK_OBJECT(pilotcfg), "remove_local");
+ exclude_list = gtk_object_get_data(GTK_OBJECT(pilotcfg),"exclude_list");
g_assert(dir!=NULL);
g_assert(updated_only!=NULL);
g_assert(remove_deleted!=NULL);
+ g_assert(exclude_list!=NULL);
ignore_changes = TRUE;
gtk_entry_set_text(GTK_ENTRY(dir), state->backup_dir);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(updated_only), state->updated_only);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remove_deleted), state->remove_deleted);
+ gtk_clist_clear(GTK_CLIST(exclude_list));
+ if (state->exclude_files != NULL)
+ {
+ GList * i;
+ for (i = state->exclude_files; i != NULL ; i = i->next)
+ {
+ gint row;
+ row = gtk_clist_append(GTK_CLIST(exclude_list),(gchar**)&(i->data));
+ gtk_clist_set_row_data(GTK_CLIST(exclude_list),row,i->data);
+ }
+ }
+
ignore_changes = FALSE;
}
***************
*** 442,453 ****
pilot_capplet_setup(void)
{
GtkWidget *frame, *table;
capplet = capplet_widget_new();
table = gtk_table_new(1, 2, FALSE);
gtk_container_border_width(GTK_CONTAINER(table), GNOME_PAD);
! gtk_container_add(GTK_CONTAINER(capplet), table);
frame = gtk_frame_new(_("Conduit state"));
gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL);
--- 552,570 ----
pilot_capplet_setup(void)
{
GtkWidget *frame, *table;
+ GtkWidget *notebook, *label;
capplet = capplet_widget_new();
+ notebook = gtk_notebook_new();
+
table = gtk_table_new(1, 2, FALSE);
+ label = gtk_label_new(_("General"));
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, label);
+
gtk_container_border_width(GTK_CONTAINER(table), GNOME_PAD);
! gtk_container_add(GTK_CONTAINER(capplet), notebook);
frame = gtk_frame_new(_("Conduit state"));
gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL);
***************
*** 458,466 ****
frame = gtk_frame_new(_("Backup options"));
gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL);
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 1, 2);
! cfgOptionsWindow = createCfgWindow();
gtk_container_add(GTK_CONTAINER(frame), cfgOptionsWindow);
gtk_signal_connect(GTK_OBJECT(capplet), "try",
GTK_SIGNAL_FUNC(doTrySettings), NULL);
gtk_signal_connect(GTK_OBJECT(capplet), "revert",
--- 575,586 ----
frame = gtk_frame_new(_("Backup options"));
gtk_container_border_width(GTK_CONTAINER(frame), GNOME_PAD_SMALL);
gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 1, 1, 2);
! cfgOptionsWindow = createCfgWindow(GTK_OBJECT(capplet));
gtk_container_add(GTK_CONTAINER(frame), cfgOptionsWindow);
+ label = gtk_label_new(_("Exclude Files"));
+ gtk_notebook_append_page(GTK_NOTEBOOK(notebook), createExcludeCfgWindow(GTK_OBJECT(capplet)), label);
+
gtk_signal_connect(GTK_OBJECT(capplet), "try",
GTK_SIGNAL_FUNC(doTrySettings), NULL);
gtk_signal_connect(GTK_OBJECT(capplet), "revert",
***************
*** 474,480 ****
setStateCfg(cfgStateWindow, curState,activated);
! setOptionsCfg(cfgOptionsWindow, curState);
gtk_widget_show_all(capplet);
}
--- 594,600 ----
setStateCfg(cfgStateWindow, curState,activated);
! setOptionsCfg(capplet, curState);
gtk_widget_show_all(capplet);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]