2 * saveactions.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2007-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 #include "geanyplugin.h"
30 #include <glib/gstdio.h>
33 GeanyData
*geany_data
;
34 GeanyFunctions
*geany_functions
;
37 PLUGIN_VERSION_CHECK(GEANY_API_VERSION
)
39 PLUGIN_SET_INFO(_("Save Actions"), _("This plugin provides different actions related to saving of files."),
40 VERSION
, _("The Geany developer team"))
45 NOTEBOOK_PAGE_AUTOSAVE
= 0,
46 NOTEBOOK_PAGE_INSTANTSAVE
,
47 NOTEBOOK_PAGE_BACKUPCOPY
52 GtkWidget
*checkbox_enable_autosave
;
53 GtkWidget
*checkbox_enable_instantsave
;
54 GtkWidget
*checkbox_enable_backupcopy
;
56 GtkWidget
*autosave_interval_spin
;
57 GtkWidget
*autosave_print_msg_checkbox
;
58 GtkWidget
*autosave_save_all_radio1
;
59 GtkWidget
*autosave_save_all_radio2
;
61 GtkWidget
*instantsave_ft_combo
;
63 GtkWidget
*backupcopy_entry_dir
;
64 GtkWidget
*backupcopy_entry_time
;
65 GtkWidget
*backupcopy_spin_dir_levels
;
70 static gboolean enable_autosave
;
71 static gboolean enable_instantsave
;
72 static gboolean enable_backupcopy
;
74 static gint autosave_interval
;
75 static gboolean autosave_print_msg
;
76 static gboolean autosave_save_all
;
77 static guint autosave_src_id
= G_MAXUINT
;
79 static gchar
*instantsave_default_ft
;
81 static gchar
*backupcopy_backup_dir
; /* path to an existing directory in locale encoding */
82 static gchar
*backupcopy_time_fmt
;
83 static gint backupcopy_dir_levels
;
85 static gchar
*config_file
;
88 /* Ensures utf8_dir exists and is writable and
89 * set backup_dir to the locale encoded form of utf8_dir */
90 static gboolean
backupcopy_set_backup_dir(const gchar
*utf8_dir
)
97 tmp
= utils_get_locale_from_utf8(utf8_dir
);
99 if (! g_path_is_absolute(tmp
) ||
100 ! g_file_test(tmp
, G_FILE_TEST_EXISTS
) ||
101 ! g_file_test(tmp
, G_FILE_TEST_IS_DIR
))
106 /** TODO add utils_is_file_writeable() to the plugin API and make use of it **/
108 setptr(backupcopy_backup_dir
, tmp
);
114 static gchar
*backupcopy_skip_root(gchar
*filename
)
116 /* first skip the root (e.g. c:\ on windows) */
117 const gchar
*dir
= g_path_skip_root(filename
);
119 /* if this has failed, use the filename again */
122 /* check again for leading / or \ */
123 while (*dir
== G_DIR_SEPARATOR
)
126 return (gchar
*) dir
;
130 static gchar
*backupcopy_create_dir_parts(const gchar
*filename
)
132 gint cnt_dir_parts
= 0;
140 if (backupcopy_dir_levels
== 0)
143 dirname
= g_path_get_dirname(filename
);
146 /* walk to the end of the string */
150 /* walk backwards to find directory parts */
153 if (*cp
== G_DIR_SEPARATOR
&& last_char
!= G_DIR_SEPARATOR
)
156 if (cnt_dir_parts
== backupcopy_dir_levels
)
163 result
= backupcopy_skip_root(cp
); /* skip leading slash/backslash and c:\ */
164 target_dir
= g_build_filename(backupcopy_backup_dir
, result
, NULL
);
166 error
= utils_mkdir(target_dir
, TRUE
);
169 ui_set_statusbar(FALSE
, _("Backup Copy: Directory could not be created (%s)."),
172 result
= g_strdup(""); /* return an empty string in case of an error */
175 result
= g_strdup(result
);
184 static void backupcopy_document_save_cb(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
)
187 gchar
*locale_filename_src
;
188 gchar
*locale_filename_dst
;
190 gchar
*dir_parts_src
;
193 if (! enable_backupcopy
)
196 locale_filename_src
= utils_get_locale_from_utf8(doc
->file_name
);
198 if ((src
= g_fopen(locale_filename_src
, "r")) == NULL
)
200 /* it's unlikely that this happens */
201 ui_set_statusbar(FALSE
, _("Backup Copy: File could not be read (%s)."),
203 g_free(locale_filename_src
);
207 stamp
= utils_get_date_time(backupcopy_time_fmt
, NULL
);
208 basename_src
= g_path_get_basename(locale_filename_src
);
209 dir_parts_src
= backupcopy_create_dir_parts(locale_filename_src
);
210 locale_filename_dst
= g_strconcat(
211 backupcopy_backup_dir
, G_DIR_SEPARATOR_S
,
212 dir_parts_src
, G_DIR_SEPARATOR_S
,
213 basename_src
, ".", stamp
, NULL
);
214 g_free(basename_src
);
215 g_free(dir_parts_src
);
217 if ((dst
= g_fopen(locale_filename_dst
, "wb")) == NULL
)
219 ui_set_statusbar(FALSE
, _("Backup Copy: File could not be saved (%s)."),
221 g_free(locale_filename_src
);
222 g_free(locale_filename_dst
);
228 while (fgets(stamp
, sizeof(stamp
), src
) != NULL
)
235 g_free(locale_filename_src
);
236 g_free(locale_filename_dst
);
241 static void instantsave_document_new_cb(GObject
*obj
, GeanyDocument
*doc
, gpointer user_data
)
243 if (enable_instantsave
&& doc
->file_name
== NULL
)
247 GeanyFiletype
*ft
= doc
->file_type
;
249 fd
= g_file_open_tmp("gis_XXXXXX", &new_filename
, NULL
);
251 close(fd
); /* close the returned file descriptor as we only need the filename */
253 if (ft
== NULL
|| ft
->id
== GEANY_FILETYPES_NONE
)
254 /* ft is NULL when a new file without template was opened, so use the
255 * configured default file type */
256 ft
= filetypes_lookup_by_name(instantsave_default_ft
);
259 /* add the filetype's default extension to the new filename */
260 setptr(new_filename
, g_strconcat(new_filename
, ".", ft
->extension
, NULL
));
262 doc
->file_name
= new_filename
;
264 if (FILETYPE_ID(doc
->file_type
) == GEANY_FILETYPES_NONE
)
265 document_set_filetype(doc
, filetypes_lookup_by_name(instantsave_default_ft
));
267 /* force saving the file to enable all the related actions(tab name, filetype, etc.) */
268 document_save_file(doc
, TRUE
);
273 PluginCallback plugin_callbacks
[] =
275 { "document-new", (GCallback
) &instantsave_document_new_cb
, FALSE
, NULL
},
276 { "document-save", (GCallback
) &backupcopy_document_save_cb
, FALSE
, NULL
},
277 { NULL
, NULL
, FALSE
, NULL
}
281 gboolean
auto_save(gpointer data
)
284 GeanyDocument
*cur_doc
= document_get_current();
285 gint i
, max
= gtk_notebook_get_n_pages(GTK_NOTEBOOK(geany
->main_widgets
->notebook
));
286 gint saved_files
= 0;
291 if (autosave_save_all
)
293 for (i
= 0; i
< max
; i
++)
295 doc
= document_get_from_page(i
);
297 /* skip current file to save it lastly, skip files without name */
298 if (doc
!= cur_doc
&& cur_doc
->file_name
!= NULL
)
299 if (document_save_file(doc
, FALSE
))
303 /* finally save current file, do it after all other files to get correct window title and
305 if (cur_doc
->file_name
!= NULL
)
306 if (document_save_file(cur_doc
, FALSE
))
309 if (saved_files
> 0 && autosave_print_msg
)
310 ui_set_statusbar(FALSE
, ngettext(
311 "Autosave: Saved %d file automatically.",
312 "Autosave: Saved %d files automatically.", saved_files
),
319 void autosave_set_timeout(void)
321 if (! enable_autosave
)
324 if (autosave_src_id
!= G_MAXUINT
)
325 g_source_remove(autosave_src_id
);
326 autosave_src_id
= g_timeout_add(autosave_interval
* 1000, (GSourceFunc
) auto_save
, NULL
);
330 void plugin_init(GeanyData
*data
)
332 GKeyFile
*config
= g_key_file_new();
335 config_file
= g_strconcat(geany
->app
->configdir
, G_DIR_SEPARATOR_S
, "plugins",
336 G_DIR_SEPARATOR_S
, "saveactions", G_DIR_SEPARATOR_S
, "saveactions.conf", NULL
);
338 g_key_file_load_from_file(config
, config_file
, G_KEY_FILE_NONE
, NULL
);
340 enable_autosave
= utils_get_setting_boolean(
341 config
, "saveactions", "enable_autosave", FALSE
);
342 enable_instantsave
= utils_get_setting_boolean(
343 config
, "saveactions", "enable_instantsave", FALSE
);
344 enable_backupcopy
= utils_get_setting_boolean(
345 config
, "saveactions", "enable_backupcopy", FALSE
);
347 instantsave_default_ft
= utils_get_setting_string(config
, "instantsave", "default_ft",
348 filetypes
[GEANY_FILETYPES_NONE
]->name
);
350 autosave_src_id
= G_MAXUINT
; /* mark as invalid */
351 autosave_interval
= utils_get_setting_integer(config
, "autosave", "interval", 300);
352 autosave_print_msg
= utils_get_setting_boolean(config
, "autosave", "print_messages", FALSE
);
353 autosave_save_all
= utils_get_setting_boolean(config
, "autosave", "save_all", FALSE
);
355 autosave_set_timeout();
357 backupcopy_dir_levels
= utils_get_setting_integer(config
, "backupcopy", "dir_levels", 0);
358 backupcopy_time_fmt
= utils_get_setting_string(
359 config
, "backupcopy", "time_fmt", "%Y-%m-%d-%H-%M-%S");
360 tmp
= utils_get_setting_string(config
, "backupcopy", "backup_dir", g_get_tmp_dir());
361 backupcopy_set_backup_dir(tmp
);
363 g_key_file_free(config
);
368 static void backupcopy_dir_button_clicked_cb(GtkButton
*button
, gpointer item
)
370 /** TODO add win32_show_pref_file_dialog to the plugin API and use it **/
373 win32_show_pref_file_dialog(item);
379 /* initialize the dialog */
380 dialog
= gtk_file_chooser_dialog_new(_("Select Directory"), NULL
,
381 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
,
382 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
383 GTK_STOCK_OPEN
, GTK_RESPONSE_ACCEPT
, NULL
);
385 text
= utils_get_locale_from_utf8(gtk_entry_get_text(GTK_ENTRY(item
)));
387 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog
), text
);
390 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_ACCEPT
)
392 gchar
*utf8_filename
, *tmp
;
394 tmp
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
395 utf8_filename
= utils_get_utf8_from_locale(tmp
);
397 gtk_entry_set_text(GTK_ENTRY(item
), utf8_filename
);
399 g_free(utf8_filename
);
403 gtk_widget_destroy(dialog
);
407 static void configure_response_cb(GtkDialog
*dialog
, gint response
, G_GNUC_UNUSED gpointer data
)
409 if (response
== GTK_RESPONSE_OK
|| response
== GTK_RESPONSE_APPLY
)
411 GKeyFile
*config
= g_key_file_new();
413 const gchar
*text_dir
, *text_time
;
414 gchar
*config_dir
= g_path_get_dirname(config_file
);
416 enable_autosave
= gtk_toggle_button_get_active(
417 GTK_TOGGLE_BUTTON(pref_widgets
.checkbox_enable_autosave
));
418 enable_instantsave
= gtk_toggle_button_get_active(
419 GTK_TOGGLE_BUTTON(pref_widgets
.checkbox_enable_instantsave
));
420 enable_backupcopy
= gtk_toggle_button_get_active(
421 GTK_TOGGLE_BUTTON(pref_widgets
.checkbox_enable_backupcopy
));
423 autosave_interval
= gtk_spin_button_get_value_as_int(
424 GTK_SPIN_BUTTON(pref_widgets
.autosave_interval_spin
));
425 autosave_print_msg
= gtk_toggle_button_get_active(
426 GTK_TOGGLE_BUTTON(pref_widgets
.autosave_print_msg_checkbox
));
427 autosave_save_all
= gtk_toggle_button_get_active(
428 GTK_TOGGLE_BUTTON(pref_widgets
.autosave_save_all_radio2
));
430 g_free(instantsave_default_ft
);
431 instantsave_default_ft
= gtk_combo_box_get_active_text(
432 GTK_COMBO_BOX(pref_widgets
.instantsave_ft_combo
));
434 text_dir
= gtk_entry_get_text(GTK_ENTRY(pref_widgets
.backupcopy_entry_dir
));
435 text_time
= gtk_entry_get_text(GTK_ENTRY(pref_widgets
.backupcopy_entry_time
));
436 backupcopy_dir_levels
= gtk_spin_button_get_value_as_int(
437 GTK_SPIN_BUTTON(pref_widgets
.backupcopy_spin_dir_levels
));
440 g_key_file_load_from_file(config
, config_file
, G_KEY_FILE_NONE
, NULL
);
442 g_key_file_set_boolean(config
, "saveactions", "enable_autosave", enable_autosave
);
443 g_key_file_set_boolean(config
, "saveactions", "enable_instantsave", enable_instantsave
);
444 g_key_file_set_boolean(config
, "saveactions", "enable_backupcopy", enable_backupcopy
);
446 g_key_file_set_boolean(config
, "autosave", "print_messages", autosave_print_msg
);
447 g_key_file_set_boolean(config
, "autosave", "save_all", autosave_save_all
);
448 g_key_file_set_integer(config
, "autosave", "interval", autosave_interval
);
450 if (instantsave_default_ft
!= NULL
)
451 g_key_file_set_string(config
, "instantsave", "default_ft", instantsave_default_ft
);
453 g_key_file_set_integer(config
, "backupcopy", "dir_levels", backupcopy_dir_levels
);
454 g_key_file_set_string(config
, "backupcopy", "time_fmt", text_time
);
455 setptr(backupcopy_time_fmt
, g_strdup(text_time
));
456 if (*text_dir
!= '\0' && backupcopy_set_backup_dir(text_dir
))
458 g_key_file_set_string(config
, "backupcopy", "backup_dir", text_dir
);
462 dialogs_show_msgbox(GTK_MESSAGE_ERROR
,
463 _("Backup directory does not exist or is not writable."));
467 if (! g_file_test(config_dir
, G_FILE_TEST_IS_DIR
) && utils_mkdir(config_dir
, TRUE
) != 0)
469 dialogs_show_msgbox(GTK_MESSAGE_ERROR
,
470 _("Plugin configuration directory could not be created."));
474 /* write config to file */
475 str
= g_key_file_to_data(config
, NULL
, NULL
);
476 utils_write_file(config_file
, str
);
481 autosave_set_timeout(); /* apply the changes */
484 g_key_file_free(config
);
489 static void checkbox_toggled_cb(GtkToggleButton
*tb
, gpointer data
)
491 gboolean enable
= gtk_toggle_button_get_active(tb
);
493 switch (GPOINTER_TO_INT(data
))
495 case NOTEBOOK_PAGE_AUTOSAVE
:
497 gtk_widget_set_sensitive(pref_widgets
.autosave_interval_spin
, enable
);
498 gtk_widget_set_sensitive(pref_widgets
.autosave_print_msg_checkbox
, enable
);
499 gtk_widget_set_sensitive(pref_widgets
.autosave_save_all_radio1
, enable
);
500 gtk_widget_set_sensitive(pref_widgets
.autosave_save_all_radio2
, enable
);
503 case NOTEBOOK_PAGE_INSTANTSAVE
:
505 gtk_widget_set_sensitive(pref_widgets
.instantsave_ft_combo
, enable
);
508 case NOTEBOOK_PAGE_BACKUPCOPY
:
510 gtk_widget_set_sensitive(pref_widgets
.backupcopy_entry_dir
, enable
);
511 gtk_widget_set_sensitive(pref_widgets
.backupcopy_entry_time
, enable
);
512 gtk_widget_set_sensitive(pref_widgets
.backupcopy_spin_dir_levels
, enable
);
520 GtkWidget
*plugin_configure(GtkDialog
*dialog
)
522 GtkWidget
*vbox
, *label
, *notebook_vbox
, *checkbox_enable
;
523 GtkWidget
*notebook
, *inner_vbox
;
525 vbox
= gtk_vbox_new(FALSE
, 6);
527 notebook
= gtk_notebook_new();
528 GTK_WIDGET_UNSET_FLAGS(notebook
, GTK_CAN_FOCUS
);
529 gtk_container_set_border_width(GTK_CONTAINER(notebook
), 5);
530 gtk_box_pack_start(GTK_BOX(vbox
), notebook
, FALSE
, TRUE
, 0);
536 GtkWidget
*spin
, *hbox
, *checkbox
, *radio1
, *radio2
;
538 notebook_vbox
= gtk_vbox_new(FALSE
, 2);
539 inner_vbox
= gtk_vbox_new(FALSE
, 5);
540 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox
), 5);
541 gtk_box_pack_start(GTK_BOX(notebook_vbox
), inner_vbox
, TRUE
, TRUE
, 5);
542 gtk_notebook_insert_page(GTK_NOTEBOOK(notebook
),
543 notebook_vbox
, gtk_label_new(_("Auto Save")), NOTEBOOK_PAGE_AUTOSAVE
);
545 checkbox_enable
= gtk_check_button_new_with_mnemonic(_("_Enable"));
546 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox_enable
), FALSE
);
547 pref_widgets
.checkbox_enable_autosave
= checkbox_enable
;
548 gtk_box_pack_start(GTK_BOX(inner_vbox
), checkbox_enable
, FALSE
, FALSE
, 6);
549 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox_enable
), enable_autosave
);
550 g_signal_connect(checkbox_enable
, "toggled",
551 G_CALLBACK(checkbox_toggled_cb
), GINT_TO_POINTER(NOTEBOOK_PAGE_AUTOSAVE
));
553 label
= gtk_label_new_with_mnemonic(_("Auto save _interval:"));
554 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
555 gtk_container_add(GTK_CONTAINER(inner_vbox
), label
);
557 pref_widgets
.autosave_interval_spin
= spin
= gtk_spin_button_new_with_range(1, 1800, 1);
558 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin
), autosave_interval
);
559 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), spin
);
561 label
= gtk_label_new(_("seconds"));
563 hbox
= gtk_hbox_new(FALSE
, 5);
564 gtk_box_pack_start(GTK_BOX(hbox
), spin
, TRUE
, TRUE
, 0);
565 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
567 gtk_box_pack_start(GTK_BOX(inner_vbox
), hbox
, FALSE
, FALSE
, 5);
569 checkbox
= gtk_check_button_new_with_mnemonic(
570 _("_Print status message if files have been automatically saved"));
571 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox
), FALSE
);
572 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox
), autosave_print_msg
);
573 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), checkbox
);
574 gtk_box_pack_start(GTK_BOX(inner_vbox
), checkbox
, FALSE
, FALSE
, 5);
575 pref_widgets
.autosave_print_msg_checkbox
= checkbox
;
577 radio1
= gtk_radio_button_new_with_mnemonic(NULL
,
578 _("Save only current open _file"));
579 pref_widgets
.autosave_save_all_radio1
= radio1
;
580 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), radio1
);
581 gtk_button_set_focus_on_click(GTK_BUTTON(radio1
), FALSE
);
582 gtk_container_add(GTK_CONTAINER(inner_vbox
), radio1
);
584 radio2
= gtk_radio_button_new_with_mnemonic_from_widget(
585 GTK_RADIO_BUTTON(radio1
), _("Sa_ve all open files"));
586 pref_widgets
.autosave_save_all_radio2
= radio2
;
587 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), radio2
);
588 gtk_button_set_focus_on_click(GTK_BUTTON(radio2
), FALSE
);
589 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2
), autosave_save_all
);
590 gtk_container_add(GTK_CONTAINER(inner_vbox
), radio2
);
600 notebook_vbox
= gtk_vbox_new(FALSE
, 2);
601 inner_vbox
= gtk_vbox_new(FALSE
, 5);
602 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox
), 5);
603 gtk_box_pack_start(GTK_BOX(notebook_vbox
), inner_vbox
, TRUE
, TRUE
, 5);
604 gtk_notebook_insert_page(GTK_NOTEBOOK(notebook
),
605 notebook_vbox
, gtk_label_new(_("Instant Save")), NOTEBOOK_PAGE_INSTANTSAVE
);
607 checkbox_enable
= gtk_check_button_new_with_mnemonic(_("_Enable"));
608 pref_widgets
.checkbox_enable_instantsave
= checkbox_enable
;
609 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox_enable
), FALSE
);
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox_enable
), enable_instantsave
);
611 gtk_box_pack_start(GTK_BOX(inner_vbox
), checkbox_enable
, FALSE
, FALSE
, 6);
612 g_signal_connect(checkbox_enable
, "toggled",
613 G_CALLBACK(checkbox_toggled_cb
), GINT_TO_POINTER(NOTEBOOK_PAGE_INSTANTSAVE
));
615 label
= gtk_label_new_with_mnemonic(_("_Filetype to use for newly opened files:"));
616 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
617 gtk_box_pack_start(GTK_BOX(inner_vbox
), label
, FALSE
, FALSE
, 0);
619 pref_widgets
.instantsave_ft_combo
= combo
= gtk_combo_box_new_text();
621 foreach_slist(node
, geany
->filetypes_by_title
)
623 GeanyFiletype
*ft
= node
->data
;
625 gtk_combo_box_append_text(GTK_COMBO_BOX(combo
), ft
->name
);
627 if (utils_str_equal(ft
->name
, instantsave_default_ft
))
628 gtk_combo_box_set_active(GTK_COMBO_BOX(combo
), i
);
631 gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo
), 3);
632 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), combo
);
633 gtk_box_pack_start(GTK_BOX(inner_vbox
), combo
, FALSE
, FALSE
, 0);
639 GtkWidget
*hbox
, *entry_dir
, *entry_time
, *button
, *image
, *spin_dir_levels
;
641 notebook_vbox
= gtk_vbox_new(FALSE
, 2);
642 inner_vbox
= gtk_vbox_new(FALSE
, 5);
643 gtk_container_set_border_width(GTK_CONTAINER(inner_vbox
), 5);
644 gtk_box_pack_start(GTK_BOX(notebook_vbox
), inner_vbox
, TRUE
, TRUE
, 5);
645 gtk_notebook_insert_page(GTK_NOTEBOOK(notebook
),
646 notebook_vbox
, gtk_label_new(_("Backup Copy")), NOTEBOOK_PAGE_BACKUPCOPY
);
648 checkbox_enable
= gtk_check_button_new_with_mnemonic(_("_Enable"));
649 pref_widgets
.checkbox_enable_backupcopy
= checkbox_enable
;
650 gtk_button_set_focus_on_click(GTK_BUTTON(checkbox_enable
), FALSE
);
651 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbox_enable
), enable_backupcopy
);
652 gtk_box_pack_start(GTK_BOX(inner_vbox
), checkbox_enable
, FALSE
, FALSE
, 6);
653 g_signal_connect(checkbox_enable
, "toggled",
654 G_CALLBACK(checkbox_toggled_cb
), GINT_TO_POINTER(NOTEBOOK_PAGE_BACKUPCOPY
));
656 label
= gtk_label_new_with_mnemonic(_("_Directory to save backup files in:"));
657 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
658 gtk_box_pack_start(GTK_BOX(inner_vbox
), label
, FALSE
, FALSE
, 0);
660 pref_widgets
.backupcopy_entry_dir
= entry_dir
= gtk_entry_new();
661 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), entry_dir
);
662 if (NZV(backupcopy_backup_dir
))
663 gtk_entry_set_text(GTK_ENTRY(entry_dir
), backupcopy_backup_dir
);
665 button
= gtk_button_new();
666 g_signal_connect(button
, "clicked",
667 G_CALLBACK(backupcopy_dir_button_clicked_cb
), entry_dir
);
669 image
= gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_BUTTON
);
670 gtk_container_add(GTK_CONTAINER(button
), image
);
672 hbox
= gtk_hbox_new(FALSE
, 6);
673 gtk_box_pack_start_defaults(GTK_BOX(hbox
), entry_dir
);
674 gtk_box_pack_start(GTK_BOX(hbox
), button
, FALSE
, FALSE
, 0);
676 gtk_box_pack_start(GTK_BOX(inner_vbox
), hbox
, FALSE
, FALSE
, 0);
678 label
= gtk_label_new_with_mnemonic(
679 _("Date/_Time format for backup files (\"man strftime\" for details):"));
680 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
681 gtk_box_pack_start(GTK_BOX(inner_vbox
), label
, FALSE
, FALSE
, 7);
683 pref_widgets
.backupcopy_entry_time
= entry_time
= gtk_entry_new();
684 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), entry_time
);
685 if (NZV(backupcopy_time_fmt
))
686 gtk_entry_set_text(GTK_ENTRY(entry_time
), backupcopy_time_fmt
);
687 gtk_box_pack_start(GTK_BOX(inner_vbox
), entry_time
, FALSE
, FALSE
, 0);
689 hbox
= gtk_hbox_new(FALSE
, 6);
691 label
= gtk_label_new_with_mnemonic(
692 _("Directory _levels to include in the backup destination:"));
693 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
694 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
696 spin_dir_levels
= gtk_spin_button_new_with_range(0, 20, 1);
697 pref_widgets
.backupcopy_spin_dir_levels
= spin_dir_levels
;
698 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_dir_levels
), backupcopy_dir_levels
);
699 gtk_label_set_mnemonic_widget(GTK_LABEL(label
), spin_dir_levels
);
700 gtk_box_pack_start(GTK_BOX(hbox
), spin_dir_levels
, FALSE
, FALSE
, 0);
702 gtk_box_pack_start(GTK_BOX(inner_vbox
), hbox
, FALSE
, FALSE
, 7);
705 /* manually emit the toggled signal of the enable checkboxes to update the widget sensitivity */
706 g_signal_emit_by_name(pref_widgets
.checkbox_enable_autosave
, "toggled");
707 g_signal_emit_by_name(pref_widgets
.checkbox_enable_instantsave
, "toggled");
708 g_signal_emit_by_name(pref_widgets
.checkbox_enable_backupcopy
, "toggled");
710 gtk_widget_show_all(vbox
);
711 g_signal_connect(dialog
, "response", G_CALLBACK(configure_response_cb
), NULL
);
717 void plugin_cleanup(void)
719 if (autosave_src_id
!= G_MAXUINT
)
720 g_source_remove(autosave_src_id
);
722 g_free(instantsave_default_ft
);
724 g_free(backupcopy_backup_dir
);
725 g_free(backupcopy_time_fmt
);