diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-03-26 06:19:01 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-06-03 11:00:41 +0800 |
commit | cd3759369b675e754dbed5ba19894cdd87a63a88 (patch) | |
tree | 3eaca93bd8630675c57896da239f5ade32300e40 /plugins/backup-restore | |
parent | 71f5369ebfe5ee1d06b0bd1936cca80abc58e60a (diff) | |
download | gsoc2013-evolution-cd3759369b675e754dbed5ba19894cdd87a63a88.tar.gz gsoc2013-evolution-cd3759369b675e754dbed5ba19894cdd87a63a88.tar.zst gsoc2013-evolution-cd3759369b675e754dbed5ba19894cdd87a63a88.zip |
Add 'backup-restore' module.
Replaces the 'backup-restore' plugin.
Diffstat (limited to 'plugins/backup-restore')
-rw-r--r-- | plugins/backup-restore/Makefile.am | 66 | ||||
-rw-r--r-- | plugins/backup-restore/backup-restore.c | 497 | ||||
-rw-r--r-- | plugins/backup-restore/backup.c | 926 | ||||
-rw-r--r-- | plugins/backup-restore/org-gnome-backup-restore.eplug.xml | 32 | ||||
-rw-r--r-- | plugins/backup-restore/org-gnome-backup-restore.error.xml | 24 |
5 files changed, 0 insertions, 1545 deletions
diff --git a/plugins/backup-restore/Makefile.am b/plugins/backup-restore/Makefile.am deleted file mode 100644 index acf960525f..0000000000 --- a/plugins/backup-restore/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -@EVO_PLUGIN_RULE@ - -error_DATA = org-gnome-backup-restore.error -errordir = $(privdatadir)/errors - -plugin_DATA = org-gnome-backup-restore.eplug -plugin_LTLIBRARIES = liborg-gnome-backup-restore.la - -liborg_gnome_backup_restore_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ - -DEVOLUTION_TOOLSDIR=\""$(privlibexecdir)"\" \ - -DPREFIX=\""$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DDATADIR=\""$(datadir)"\" \ - -DLIBDIR=\""$(libdir)"\" \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) \ - $(GTKHTML_CFLAGS) - -liborg_gnome_backup_restore_la_SOURCES = backup-restore.c -liborg_gnome_backup_restore_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED) -liborg_gnome_backup_restore_la_LIBADD = \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/shell/libeshell.la \ - $(top_builddir)/libevolution-utils/libevolution-utils.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) \ - $(GTKHTML_LIBS) - -privlibexec_PROGRAMS = evolution-backup -evolution_backup_SOURCES = backup.c -evolution_backup_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ - -DEVOLUTION_TOOLSDIR=\""$(privlibexecdir)"\" \ - -DPREFIX=\""$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DDATADIR=\""$(datadir)"\" \ - -DLIBDIR=\""$(libdir)"\" \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) - -evolution_backup_LDADD = \ - $(top_builddir)/e-util/libeutil.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) - -if OS_WIN32 -evolution_backup_LDFLAGS = -mwindows -endif - -EXTRA_DIST = \ - org-gnome-backup-restore.eplug.xml \ - org-gnome-backup-restore.error.xml - -BUILT_SOURCES = org-gnome-backup-restore.eplug \ - org-gnome-backup-restore.error - -CLEANFILES = $(BUILT_SOURCES) - --include $(top_srcdir)/git.mk diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c deleted file mode 100644 index e821113a88..0000000000 --- a/plugins/backup-restore/backup-restore.c +++ /dev/null @@ -1,497 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <unistd.h> -#include <sys/types.h> -#ifdef HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif -#include <stdlib.h> -#include <gtk/gtk.h> -#include <glib/gi18n.h> -#include <glib/gstdio.h> -#include "mail/em-config.h" -#include "mail/em-account-editor.h" -#include "libevolution-utils/e-alert-dialog.h" -#include "e-util/e-util.h" -#include "e-util/e-dialog-utils.h" -#include "shell/e-shell-utils.h" -#include "shell/e-shell-window.h" - -#ifdef G_OS_WIN32 -#ifdef localtime_r -#undef localtime_r -#endif -/* The localtime() in Microsoft's C library *is* thread-safe */ -#define localtime_r(timep, result) \ - (localtime (timep) ? memcpy ( \ - (result), localtime (timep), sizeof (*(result))) : 0) -#endif - -gboolean e_plugin_ui_init (GtkUIManager *ui_manager, - EShellWindow *shell_window); -GtkWidget * backup_restore_page (EPlugin *ep, - EConfigHookItemFactoryData *hook_data); -void backup_restore_commit (EPlugin *ep, - EMConfigTargetSettings *target); -void backup_restore_abort (EPlugin *ep, - EMConfigTargetSettings *target); - -typedef enum _br_flags { - BR_OK = 1 << 0, - BR_START = 1 << 1 -}br_flags; - -gint e_plugin_lib_enable (EPlugin *ep, gint enable); - -gint -e_plugin_lib_enable (EPlugin *ep, - gint enable) -{ - return 0; -} - -static void -backup (const gchar *filename, - gboolean restart) -{ - if (restart) - execl ( - EVOLUTION_TOOLSDIR "/evolution-backup", - "evolution-backup", - "--gui", - "--backup", - "--restart", - filename, - NULL); - else - execl ( - EVOLUTION_TOOLSDIR "/evolution-backup", - "evolution-backup", - "--gui", - "--backup", - filename, - NULL); -} - -static void -restore (const gchar *filename, - gboolean restart) -{ - if (restart) - execl ( - EVOLUTION_TOOLSDIR "/evolution-backup", - "evolution-backup", - "--gui", - "--restore", - "--restart", - filename, - NULL); - else - execl ( - EVOLUTION_TOOLSDIR "/evolution-backup", - "evolution-backup", - "--gui", - "--restore", - filename, - NULL); -} - -static gboolean -sanity_check (const gchar *filename) -{ - gchar *command; - gint result; - gchar *quotedfname, *toolfname; - - quotedfname = g_shell_quote (filename); - toolfname = g_build_filename (EVOLUTION_TOOLSDIR, "evolution-backup", NULL); - - command = g_strdup_printf("%s --check %s", toolfname, quotedfname); - result = system (command); - g_free (command); - g_free (quotedfname); - g_free (toolfname); - -#ifdef HAVE_SYS_WAIT_H - g_message ( - "Sanity check result %d:%d %d", - WIFEXITED (result), WEXITSTATUS (result), result); - - return WIFEXITED (result) && (WEXITSTATUS (result) == 0); -#else - return result; -#endif -} - -static guint32 -dialog_prompt_user (GtkWindow *parent, - const gchar *string, - const gchar *tag, - ...) -{ - GtkWidget *dialog; - GtkWidget *check = NULL; - GtkWidget *container; - va_list ap; - gint button; - guint32 mask = 0; - EAlert *alert = NULL; - - va_start (ap, tag); - alert = e_alert_new_valist (tag, ap); - va_end (ap); - - dialog = e_alert_dialog_new (parent, alert); - g_object_unref (alert); - - container = e_alert_dialog_get_content_area (E_ALERT_DIALOG (dialog)); - - check = gtk_check_button_new_with_mnemonic (string); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); - gtk_box_pack_start (GTK_BOX (container), check, FALSE, FALSE, 0); - gtk_widget_show (check); - - button = gtk_dialog_run (GTK_DIALOG (dialog)); - - if (button == GTK_RESPONSE_YES) - mask |= BR_OK; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check))) - mask |= BR_START; - - gtk_widget_destroy (dialog); - - return mask; -} - -static void -set_local_only (GtkFileChooser *file_chooser) -{ - /* XXX Has to be a local file, since the backup utility - * takes a filename argument, not a URI. */ - gtk_file_chooser_set_local_only (file_chooser, TRUE); -} - -static gchar * -suggest_file_name (void) -{ - time_t t; - struct tm tm; - - t = time (NULL); - localtime_r (&t, &tm); - - return g_strdup_printf ( - "evolution-backup-%04d%02d%02d.tar.gz", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); -} - -static void -action_settings_backup_cb (GtkAction *action, - EShellWindow *shell_window) -{ - GFile *file; - GFile *parent; - GFileInfo *file_info; - const gchar *attribute; - GError *error = NULL; - gchar *suggest; - - suggest = suggest_file_name (); - - file = e_shell_run_save_dialog ( - e_shell_window_get_shell (shell_window), - _("Select name of the Evolution backup file"), - suggest, "*.tar.gz", (GtkCallback) - set_local_only, NULL); - - g_free (suggest); - - if (file == NULL) - return; - - /* Make sure the parent directory can be written to. */ - - parent = g_file_get_parent (file); - attribute = G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE; - - /* XXX The query operation blocks the main loop but we - * know it's a local file, so let it slide for now. */ - file_info = g_file_query_info ( - parent, attribute, G_FILE_QUERY_INFO_NONE, NULL, &error); - - g_object_unref (parent); - - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - return; - } - - if (g_file_info_get_attribute_boolean (file_info, attribute)) { - guint32 mask; - gchar *path; - - mask = dialog_prompt_user ( - GTK_WINDOW (shell_window), - _("_Restart Evolution after backup"), - "org.gnome.backup-restore:backup-confirm", NULL); - if (mask & BR_OK) { - path = g_file_get_path (file); - backup (path, (mask & BR_START) ? TRUE: FALSE); - g_free (path); - } - } else { - e_alert_run_dialog_for_args ( - GTK_WINDOW (shell_window), - "org.gnome.backup-restore:insufficient-permissions", - NULL); - } - - g_object_unref (file_info); - g_object_unref (file); -} - -static void -action_settings_restore_cb (GtkAction *action, - EShellWindow *shell_window) -{ - GFile *file; - gchar *path; - - file = e_shell_run_open_dialog ( - e_shell_window_get_shell (shell_window), - _("Select name of the Evolution backup file to restore"), - (GtkCallback) set_local_only, NULL); - - if (file == NULL) - return; - - path = g_file_get_path (file); - - if (sanity_check (path)) { - guint32 mask; - - mask = dialog_prompt_user ( - GTK_WINDOW (shell_window), - _("_Restart Evolution after restore"), - "org.gnome.backup-restore:restore-confirm", NULL); - if (mask & BR_OK) - restore (path, mask & BR_START); - } else { - e_alert_run_dialog_for_args ( - GTK_WINDOW (shell_window), - "org.gnome.backup-restore:invalid-backup", NULL); - } - - g_object_unref (file); - g_free (path); -} - -static void -check_toggled (GtkToggleButton *button, - GObject *assistant) -{ - EConfig *config; - GtkWidget *box; - gboolean active; - - active = gtk_toggle_button_get_active (button); - box = g_object_get_data (G_OBJECT (button), "box"); - gtk_widget_set_sensitive (box, active); - - g_object_set_data ( - assistant, "restore", - GINT_TO_POINTER (active ? 1 : 0)); - - config = g_object_get_data (assistant, "restore-config"); - - e_config_target_changed ( - config, E_CONFIG_TARGET_CHANGED_STATE); -} - -static void -file_changed (GtkFileChooser *chooser, - GObject *assistant) -{ - EConfig *config; - gchar *file = NULL, *prevfile = NULL; - - file = gtk_file_chooser_get_filename (chooser); - prevfile = g_object_get_data (assistant, "restore-file"); - g_object_set_data (assistant, "restore-file", file); - g_free (prevfile); - - config = g_object_get_data (assistant, "restore-config"); - - e_config_target_changed ( - config, E_CONFIG_TARGET_CHANGED_STATE); -} - -static gboolean -backup_restore_check (EConfig *ec, - const gchar *pageid, - gpointer data) -{ - GObject *assistant = data; - gboolean do_restore; - gchar *file; - - g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (GTK_IS_ASSISTANT (data), FALSE); - - do_restore = (g_object_get_data (assistant, "restore") != NULL); - file = g_object_get_data (assistant, "restore-file"); - - e_config_set_page_is_finish ( - ec, "0.startup_page.10.backup_restore", do_restore); - - return !do_restore || file; -} - -GtkWidget * -backup_restore_page (EPlugin *ep, - EConfigHookItemFactoryData *hook_data) -{ - GtkWidget *page, *hbox, *label, *cbox, *button; - GObject *assistant = G_OBJECT (hook_data->parent); - - page = gtk_vbox_new (FALSE, 6); - gtk_container_set_border_width (GTK_CONTAINER (page), 12); - - hbox = gtk_hbox_new (FALSE, 6); - label = gtk_label_new ( - _("You can restore Evolution from your backup. It can restore " - "all the Mails, Calendars, Tasks, Memos, Contacts. It also " - "restores all your personal settings, mail filters etc.")); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_single_line_mode (GTK_LABEL (label), FALSE); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - gtk_box_pack_start (GTK_BOX (page), hbox, FALSE, FALSE, 0); - - hbox = gtk_hbox_new (FALSE, 6); - cbox = gtk_check_button_new_with_mnemonic ( - _("_Restore Evolution from the backup file")); - g_signal_connect ( - cbox, "toggled", - G_CALLBACK (check_toggled), assistant); - gtk_box_pack_start (GTK_BOX (hbox), cbox, FALSE, FALSE, 6); - gtk_box_pack_start (GTK_BOX (page), hbox, FALSE, FALSE, 0); - - hbox = gtk_hbox_new (FALSE, 6); - g_object_set_data ((GObject *)cbox, "box", hbox); - label = gtk_label_new ( - _("Please select an Evolution Archive to restore:")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 12); - - button = gtk_file_chooser_button_new ( - _("Choose a file to restore"), - GTK_FILE_CHOOSER_ACTION_OPEN); - g_signal_connect ( - button, "selection-changed", - G_CALLBACK (file_changed), assistant); - gtk_file_chooser_button_set_width_chars ( - GTK_FILE_CHOOSER_BUTTON (button), 20); - gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (page), hbox, FALSE, FALSE, 0); - gtk_widget_set_sensitive (hbox, FALSE); - - gtk_assistant_append_page (GTK_ASSISTANT (assistant), page); - gtk_assistant_set_page_title ( - GTK_ASSISTANT (assistant), - page, _("Restore from backup")); - gtk_widget_show_all (page); - - g_object_set_data (assistant, "restore", GINT_TO_POINTER (FALSE)); - g_object_set_data (assistant, "restore-config", hook_data->config); - - e_config_add_page_check ( - hook_data->config, - "0.startup_page.10.backup_restore", - backup_restore_check, assistant); - - return GTK_WIDGET (page); -} - -void -backup_restore_commit (EPlugin *ep, - EMConfigTargetSettings *target) -{ - GObject *assistant; - gchar *file; - - assistant = G_OBJECT (target->target.config->widget); - file = g_object_get_data (assistant, "restore-file"); - - if (g_object_get_data (assistant, "restore") != NULL) { - if (file == NULL || !sanity_check (file)) { - e_alert_run_dialog_for_args ( - GTK_WINDOW (assistant), - "org.gnome.backup-restore:invalid-backup", - NULL); - } else { - restore (file, TRUE); - } - } -} - -void -backup_restore_abort (EPlugin *ep, - EMConfigTargetSettings *target) -{ - /* Nothing really */ -} - -static GtkActionEntry entries[] = { - - { "settings-backup", - NULL, - N_("_Back up Evolution Data..."), - NULL, - N_("Back up Evolution data and settings to an archive file"), - G_CALLBACK (action_settings_backup_cb) }, - - { "settings-restore", - NULL, - N_("R_estore Evolution Data..."), - NULL, - N_("Restore Evolution data and settings from an archive file"), - G_CALLBACK (action_settings_restore_cb) } -}; - -gboolean -e_plugin_ui_init (GtkUIManager *ui_manager, - EShellWindow *shell_window) -{ - GtkActionGroup *action_group; - - action_group = e_shell_window_get_action_group (shell_window, "shell"); - - /* Add actions to the "shell" action group. */ - gtk_action_group_add_actions ( - action_group, entries, - G_N_ELEMENTS (entries), shell_window); - - return TRUE; -} diff --git a/plugins/backup-restore/backup.c b/plugins/backup-restore/backup.c deleted file mode 100644 index bfbdf85be3..0000000000 --- a/plugins/backup-restore/backup.c +++ /dev/null @@ -1,926 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <glib/gi18n.h> -#include <glib/gstdio.h> -#include <gtk/gtk.h> - -#include <libedataserver/e-data-server-util.h> - -#ifdef G_OS_WIN32 -#ifdef DATADIR -#undef DATADIR -#endif -#include <windows.h> -#include <conio.h> -#ifndef PROCESS_DEP_ENABLE -#define PROCESS_DEP_ENABLE 0x00000001 -#endif -#ifndef PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION -#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002 -#endif -#endif - -#include "e-util/e-util-private.h" -#include "e-util/e-util.h" - -#define EVOUSERDATADIR_MAGIC "#EVO_USERDATADIR#" - -#define EVOLUTION "evolution" -#define EVOLUTION_DIR "$DATADIR/" -#define EVOLUTION_DIR_FILE EVOLUTION ".dir" -#define GCONF_DUMP_FILE "backup-restore-gconf.xml" -#define GCONF_DIR "/apps/evolution" - -static gboolean backup_op = FALSE; -static gchar *bk_file = NULL; -static gboolean restore_op = FALSE; -static gchar *res_file = NULL; -static gboolean check_op = FALSE; -static gchar *chk_file = NULL; -static gboolean restart_arg = FALSE; -static gboolean gui_arg = FALSE; -static gchar **opt_remaining = NULL; -static gint result = 0; -static GtkWidget *progress_dialog; -static GtkWidget *pbar; -static gchar *txt = NULL; - -static GOptionEntry options[] = { - { "backup", '\0', 0, G_OPTION_ARG_NONE, &backup_op, - N_("Back up Evolution directory"), NULL }, - { "restore", '\0', 0, G_OPTION_ARG_NONE, &restore_op, - N_("Restore Evolution directory"), NULL }, - { "check", '\0', 0, G_OPTION_ARG_NONE, &check_op, - N_("Check Evolution Back up"), NULL }, - { "restart", '\0', 0, G_OPTION_ARG_NONE, &restart_arg, - N_("Restart Evolution"), NULL }, - { "gui", '\0', 0, G_OPTION_ARG_NONE, &gui_arg, - N_("With Graphical User Interface"), NULL }, - { G_OPTION_REMAINING, '\0', 0, - G_OPTION_ARG_STRING_ARRAY, &opt_remaining }, - { NULL } -}; - -#define d(x) - -#define print_and_run(x) \ - G_STMT_START { g_message ("%s", x); system (x); } G_STMT_END - -static gboolean check (const gchar *filename, gboolean *is_new_format); - -static GString * -replace_string (const gchar *text, - const gchar *find, - const gchar *replace) -{ - const gchar *p, *next; - GString *str; - gint find_len; - - g_return_val_if_fail (text != NULL, NULL); - g_return_val_if_fail (find != NULL, NULL); - g_return_val_if_fail (*find, NULL); - - find_len = strlen (find); - str = g_string_new (""); - - p = text; - while (next = strstr (p, find), next) { - if (p < next) - g_string_append_len (str, p, next - p); - - if (replace && *replace) - g_string_append (str, replace); - - p = next + find_len; - } - - g_string_append (str, p); - - return str; -} - -static const gchar * -strip_home_dir (const gchar *dir) -{ - const gchar *home_dir, *res; - - g_return_val_if_fail (dir != NULL, NULL); - - home_dir = g_get_home_dir (); - g_return_val_if_fail (home_dir != NULL, dir); - g_return_val_if_fail (*home_dir != '\0', dir); - - res = dir; - if (g_str_has_prefix (res, home_dir)) - res += strlen (home_dir); - - if (*res == G_DIR_SEPARATOR) - res++; - - return res; -} - -static GString * -replace_variables (const gchar *str) -{ - GString *res = NULL, *use; - const gchar *strip_datadir, *strip_configdir; - - g_return_val_if_fail (str != NULL, NULL); - - strip_datadir = strip_home_dir (e_get_user_data_dir ()); - strip_configdir = strip_home_dir (e_get_user_config_dir ()); - - #define repl(_find, _replace) \ - use = replace_string (res ? res->str : str, _find, _replace); \ - g_return_val_if_fail (use != NULL, NULL); \ - if (res) \ - g_string_free (res, TRUE); \ - res = use; - - repl ("$HOME", g_get_home_dir ()); - repl ("$TMP", g_get_tmp_dir ()); - repl ("$DATADIR", e_get_user_data_dir ()); - repl ("$CONFIGDIR", e_get_user_config_dir ()); - repl ("$STRIPDATADIR", strip_datadir); - repl ("$STRIPCONFIGDIR", strip_configdir); - - #undef repl - - g_return_val_if_fail (res != NULL, NULL); - - /* remove trailing dir separator */ - while (res->len > 0 && res->str[res->len - 1] == G_DIR_SEPARATOR) { - g_string_truncate (res, res->len - 1); - } - - return res; -} - -static void -replace_in_file (const gchar *filename, - const gchar *find, - const gchar *replace) -{ - gchar *content = NULL; - GError *error = NULL; - GString *filenamestr = NULL; - - g_return_if_fail (filename != NULL); - g_return_if_fail (find != NULL); - g_return_if_fail (*find); - g_return_if_fail (replace != NULL); - - if (strstr (filename, "$")) { - filenamestr = replace_variables (filename); - - if (!filenamestr) { - g_warning ( - "%s: Replace variables in '%s' failed!", - G_STRFUNC, filename); - return; - } - - filename = filenamestr->str; - } - - if (g_file_get_contents (filename, &content, NULL, &error)) { - GString *str = replace_string (content, find, replace); - - if (str) { - if (!g_file_set_contents (filename, str->str, -1, &error) && error) { - g_warning ( - "%s: cannot write file content, " - "error: %s", G_STRFUNC, error->message); - g_error_free (error); - } - - g_string_free (str, TRUE); - } else { - g_warning ( - "%s: Replace of '%s' to '%s' failed!", - G_STRFUNC, find, replace); - } - - g_free (content); - } else if (error) { - g_warning ( - "%s: Cannot read file content, error: %s", - G_STRFUNC, error->message); - g_error_free (error); - } - - if (filenamestr) - g_string_free (filenamestr, TRUE); -} - -static void -run_cmd (const gchar *cmd) -{ - if (!cmd) - return; - - if (strstr (cmd, "$") != NULL) { - /* read the doc for g_get_home_dir to know why replacing it here */ - GString *str = replace_variables (cmd); - - if (str) { - print_and_run (str->str); - g_string_free (str, TRUE); - } - } else - print_and_run (cmd); -} - -static void -run_evolution_no_wait (void) -{ - g_spawn_command_line_async (EVOLUTION, NULL); -} - -static void -write_dir_file (void) -{ - GString *content, *filename; - GError *error = NULL; - - filename = replace_variables ("$HOME/" EVOLUTION_DIR_FILE); - g_return_if_fail (filename != NULL); - - content = replace_variables ( - "[dirs]\n" - "data=$STRIPDATADIR\n" - "config=$STRIPCONFIGDIR\n"); - g_return_if_fail (content != NULL); - - g_file_set_contents (filename->str, content->str, content->len, &error); - - if (error) { - g_warning ("Failed to write file '%s': %s\n", filename->str, error->message); - g_error_free (error); - } - - g_string_free (filename, TRUE); - g_string_free (content, TRUE); -} - -static void -backup (const gchar *filename, - GCancellable *cancellable) -{ - gchar *command; - gchar *quotedfname; - - g_return_if_fail (filename && *filename); - quotedfname = g_shell_quote (filename); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Shutting down Evolution"); - /* FIXME Will the versioned setting always work? */ - run_cmd (EVOLUTION " --quit"); - - run_cmd ("rm $DATADIR/.running"); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Backing Evolution accounts and settings"); - run_cmd ("gconftool-2 --dump " GCONF_DIR " > " EVOLUTION_DIR GCONF_DUMP_FILE); - - replace_in_file ( - EVOLUTION_DIR GCONF_DUMP_FILE, - e_get_user_data_dir (), EVOUSERDATADIR_MAGIC); - - write_dir_file (); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Backing Evolution data (Mails, Contacts, Calendar, Tasks, Memos)"); - - /* FIXME stay on this file system ,other options?" */ - /* FIXME compression type?" */ - /* FIXME date/time stamp?" */ - /* FIXME backup location?" */ - command = g_strdup_printf ( - "cd $HOME && tar chf - $STRIPDATADIR " - "$STRIPCONFIGDIR .camel_certs " EVOLUTION_DIR_FILE " | " - "gzip > %s", quotedfname); - run_cmd (command); - g_free (command); - g_free (quotedfname); - - run_cmd ("rm $HOME/" EVOLUTION_DIR_FILE); - - txt = _("Back up complete"); - - if (restart_arg) { - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Restarting Evolution"); - run_evolution_no_wait (); - } - -} - -static void -extract_backup_dirs (const gchar *filename, - gchar **data_dir, - gchar **config_dir) -{ - GKeyFile *key_file; - GError *error = NULL; - - g_return_if_fail (filename != NULL); - g_return_if_fail (data_dir != NULL); - g_return_if_fail (config_dir != NULL); - - key_file = g_key_file_new (); - g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &error); - - if (error) { - g_warning ("Failed to read '%s': %s", filename, error->message); - g_error_free (error); - } else { - gchar *tmp; - - tmp = g_key_file_get_value (key_file, "dirs", "data", NULL); - if (tmp) - *data_dir = g_shell_quote (tmp); - g_free (tmp); - - tmp = g_key_file_get_value (key_file, "dirs", "config", NULL); - if (tmp) - *config_dir = g_shell_quote (tmp); - g_free (tmp); - } - - g_key_file_free (key_file); -} - -static gint -get_dir_level (const gchar *dir) -{ - gint res = 0, i; - - g_return_val_if_fail (dir != NULL, -1); - - for (i = 0; dir[i]; i++) { - if (dir[i] == '/' || dir[i] == '\\') - res++; - } - - if (i > 0) - res++; - - return res; -} - -static void -restore (const gchar *filename, - GCancellable *cancellable) -{ - gchar *command; - gchar *quotedfname; - gboolean is_new_format = FALSE; - - g_return_if_fail (filename && *filename); - - if (!check (filename, &is_new_format)) { - g_message ("Cannot restore from an incorrect archive '%s'.", filename); - goto end; - } - - quotedfname = g_shell_quote (filename); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - /* FIXME Will the versioned setting always work? */ - txt = _("Shutting down Evolution"); - run_cmd (EVOLUTION " --quit"); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Back up current Evolution data"); - run_cmd ("mv $DATADIR $DATADIR_old"); - run_cmd ("mv $CONFIGDIR $CONFIGDIR_old"); - run_cmd ("mv $HOME/.camel_certs $HOME/.camel_certs_old"); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Extracting files from back up"); - - if (is_new_format) { - GString *dir_fn; - gchar *data_dir = NULL, *config_dir = NULL; - - command = g_strdup_printf ( - "cd $TMP && tar xzf %s " - EVOLUTION_DIR_FILE, quotedfname); - run_cmd (command); - g_free (command); - - dir_fn = replace_variables ("$TMP" G_DIR_SEPARATOR_S EVOLUTION_DIR_FILE); - if (!dir_fn) { - g_warning ("Failed to create evolution's dir filename"); - goto end; - } - - /* data_dir and config_dir are quoted inside extract_backup_dirs */ - extract_backup_dirs (dir_fn->str, &data_dir, &config_dir); - - g_unlink (dir_fn->str); - g_string_free (dir_fn, TRUE); - - if (!data_dir || !config_dir) { - g_warning ( - "Failed to get old data_dir (%p)/" - "config_dir (%p)", data_dir, config_dir); - g_free (data_dir); - g_free (config_dir); - goto end; - } - - g_mkdir_with_parents (e_get_user_data_dir (), 0700); - g_mkdir_with_parents (e_get_user_config_dir (), 0700); - - command = g_strdup_printf ( - "cd $DATADIR && tar xzf %s %s --strip-components=%d", - quotedfname, data_dir, get_dir_level (data_dir)); - run_cmd (command); - g_free (command); - - command = g_strdup_printf ( - "cd $CONFIGDIR && tar xzf %s %s --strip-components=%d", - quotedfname, config_dir, get_dir_level (config_dir)); - run_cmd (command); - g_free (command); - - command = g_strdup_printf ( - "cd $HOME && tar xzf %s .camel_certs", quotedfname); - run_cmd (command); - g_free (command); - - g_free (data_dir); - g_free (config_dir); - } else { - run_cmd ("mv $HOME/.evolution $HOME/.evolution_old"); - - command = g_strdup_printf ( - "cd $HOME && gzip -cd %s | tar xf -", quotedfname); - run_cmd (command); - g_free (command); - } - - g_free (quotedfname); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Loading Evolution settings"); - - if (is_new_format) { - /* new format has it in DATADIR... */ - replace_in_file ( - EVOLUTION_DIR GCONF_DUMP_FILE, - EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); - run_cmd ("gconftool-2 --load " EVOLUTION_DIR GCONF_DUMP_FILE); - run_cmd ("rm " EVOLUTION_DIR GCONF_DUMP_FILE); - } else { - gchar *gconf_dump_file; - - /* ... old format in ~/.evolution */ - gconf_dump_file = g_build_filename ( - "$HOME", ".evolution", GCONF_DUMP_FILE, NULL); - - replace_in_file ( - gconf_dump_file, - EVOUSERDATADIR_MAGIC, - e_get_user_data_dir ()); - - command = g_strconcat ( - "gconftool-2 --load ", gconf_dump_file, NULL); - run_cmd (command); - g_free (command); - - command = g_strconcat ("rm ", gconf_dump_file, NULL); - run_cmd (command); - g_free (command); - - g_free (gconf_dump_file); - } - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Removing temporary back up files"); - run_cmd ("rm -rf $DATADIR_old"); - run_cmd ("rm -rf $CONFIGDIR_old"); - run_cmd ("rm -rf $HOME/.camel_certs_old"); - run_cmd ("rm $DATADIR/.running"); - - if (!is_new_format) - run_cmd ("rm -rf $HOME/.evolution_old"); - - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Ensuring local sources"); - -end: - if (restart_arg) { - if (g_cancellable_is_cancelled (cancellable)) - return; - - txt = _("Restarting Evolution"); - run_evolution_no_wait (); - } -} - -static gboolean -check (const gchar *filename, - gboolean *is_new_format) -{ - gchar *command; - gchar *quotedfname; - gboolean is_new = TRUE; - - g_return_val_if_fail (filename && *filename, FALSE); - quotedfname = g_shell_quote (filename); - - if (is_new_format) - *is_new_format = FALSE; - - command = g_strdup_printf ("tar ztf %s 1>/dev/null", quotedfname); - result = system (command); - g_free (command); - - g_message ("First result %d", result); - if (result) { - g_free (quotedfname); - return FALSE; - } - - command = g_strdup_printf ( - "tar ztf %s | grep -e \"%s$\"", - quotedfname, EVOLUTION_DIR_FILE); - result = system (command); - g_free (command); - - if (result) { - command = g_strdup_printf ( - "tar ztf %s | grep -e \"^\\.evolution/$\"", - quotedfname); - result = system (command); - g_free (command); - is_new = FALSE; - } - - g_message ("Second result %d", result); - if (result) { - g_free (quotedfname); - return FALSE; - } - - if (is_new) { - if (is_new_format) - *is_new_format = TRUE; - g_free (quotedfname); - return TRUE; - } - - command = g_strdup_printf ( - "tar ztf %s | grep -e \"^\\.evolution/%s$\"", - quotedfname, GCONF_DUMP_FILE); - result = system (command); - g_free (command); - g_free (quotedfname); - - g_message ("Third result %d", result); - - return result == 0; -} - -static gboolean -pbar_update (GCancellable *cancellable) -{ - gtk_progress_bar_pulse ((GtkProgressBar *) pbar); - gtk_progress_bar_set_text ((GtkProgressBar *) pbar, txt); - - /* Return TRUE to reschedule the timeout. */ - return !g_cancellable_is_cancelled (cancellable); -} - -static gboolean -finish_job (gpointer user_data) -{ - gtk_main_quit (); - - return FALSE; -} - -static gboolean -start_job (GIOSchedulerJob *job, - GCancellable *cancellable, - gpointer user_data) -{ - if (backup_op) - backup (bk_file, cancellable); - else if (restore_op) - restore (res_file, cancellable); - else if (check_op) - check (chk_file, NULL); /* not cancellable */ - - g_io_scheduler_job_send_to_mainloop_async ( - job, finish_job, NULL, (GDestroyNotify) NULL); - - return FALSE; -} - -static void -dlg_response (GtkWidget *dlg, - gint response, - GCancellable *cancellable) -{ - /* We will cancel only backup/restore - * operations and not the check operation. */ - g_cancellable_cancel (cancellable); - - /* If the response is not of delete_event then destroy the event. */ - if (response != GTK_RESPONSE_NONE) - gtk_widget_destroy (dlg); - - /* We will kill just the tar operation. Rest of - * them will be just a second of microseconds.*/ - run_cmd ("pkill tar"); - - if (bk_file && backup_op && response == GTK_RESPONSE_REJECT) { - /* Backup was canceled, delete the - * backup file as it is not needed now. */ - gchar *cmd, *filename; - - g_message ("Back up canceled, removing partial back up file."); - - filename = g_shell_quote (bk_file); - cmd = g_strconcat ("rm ", filename, NULL); - - run_cmd (cmd); - - g_free (cmd); - g_free (filename); - } - - gtk_main_quit (); -} - -gint -main (gint argc, - gchar **argv) -{ - GCancellable *cancellable; - gchar *file = NULL, *oper = NULL; - const gchar *title = NULL; - gint ii; - GError *error = NULL; - -#ifdef G_OS_WIN32 - /* Reduce risks */ - { - typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName); - t_SetDllDirectoryA p_SetDllDirectoryA; - - p_SetDllDirectoryA = GetProcAddress ( - GetModuleHandle ("kernel32.dll"), - "SetDllDirectoryA"); - - if (p_SetDllDirectoryA != NULL) - p_SetDllDirectoryA (""); - } -#ifndef _WIN64 - { - typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags); - t_SetProcessDEPPolicy p_SetProcessDEPPolicy; - - p_SetProcessDEPPolicy = GetProcAddress ( - GetModuleHandle ("kernel32.dll"), - "SetProcessDEPPolicy"); - - if (p_SetProcessDEPPolicy) - p_SetProcessDEPPolicy ( - PROCESS_DEP_ENABLE | - PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION); - } -#endif -#endif - - bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - gtk_init_with_args ( - &argc, &argv, NULL, options, GETTEXT_PACKAGE, &error); - - if (error != NULL) { - g_printerr ("%s\n", error->message); - g_error_free (error); - exit (EXIT_FAILURE); - } - - if (opt_remaining != NULL) { - for (ii = 0; ii < g_strv_length (opt_remaining); ii++) { - if (backup_op) { - title = _("Evolution Back Up"); - oper = _("Backing up to the folder %s"); - bk_file = g_strdup ((gchar *) opt_remaining[ii]); - file = bk_file; - } else if (restore_op) { - title = _("Evolution Restore"); - oper = _("Restoring from the folder %s"); - res_file = g_strdup ((gchar *) opt_remaining[ii]); - file = res_file; - } else if (check_op) { - d(g_message ("Checking %s", (gchar *) opt_remaining[ii])); - chk_file = g_strdup ((gchar *) opt_remaining[ii]); - } - } - } - - cancellable = g_cancellable_new (); - - if (gui_arg && !check_op) { - GtkWidget *widget, *container; - GtkWidget *action_area; - GtkWidget *content_area; - const gchar *txt, *txt2; - gchar *str = NULL; - gchar *markup; - - gtk_window_set_default_icon_name ("evolution"); - - /* Backup / Restore only can have GUI. - * We should restrict the rest. */ - progress_dialog = gtk_dialog_new_with_buttons ( - title, NULL, - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, - NULL); - - gtk_container_set_border_width ( - GTK_CONTAINER (progress_dialog), 12); - gtk_window_set_default_size ( - GTK_WINDOW (progress_dialog), 450, 120); - - action_area = gtk_dialog_get_action_area ( - GTK_DIALOG (progress_dialog)); - content_area = gtk_dialog_get_content_area ( - GTK_DIALOG (progress_dialog)); - - /* Override GtkDialog defaults */ - gtk_box_set_spacing (GTK_BOX (content_area), 12); - gtk_container_set_border_width (GTK_CONTAINER (content_area), 0); - gtk_box_set_spacing (GTK_BOX (action_area), 12); - gtk_container_set_border_width (GTK_CONTAINER (action_area), 0); - - if (oper && file) - str = g_strdup_printf (oper, file); - - container = gtk_table_new (2, 3, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (container), 12); - gtk_table_set_row_spacings (GTK_TABLE (container), 12); - gtk_widget_show (container); - - gtk_box_pack_start ( - GTK_BOX (content_area), container, FALSE, TRUE, 0); - - widget = gtk_image_new_from_stock ( - GTK_STOCK_COPY, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0); - gtk_widget_show (widget); - - gtk_table_attach ( - GTK_TABLE (container), widget, 0, 1, 0, 3, - GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - - if (backup_op) { - txt = _("Backing up Evolution Data"); - txt2 = _("Please wait while Evolution is backing up your data."); - } else if (restore_op) { - txt = _("Restoring Evolution Data"); - txt2 = _("Please wait while Evolution is restoring your data."); - } else { - g_return_val_if_reached (EXIT_FAILURE); - } - - markup = g_markup_printf_escaped ("<b><big>%s</big></b>", txt); - widget = gtk_label_new (markup); - gtk_label_set_line_wrap (GTK_LABEL (widget), FALSE); - gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); - gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0); - gtk_widget_show (widget); - g_free (markup); - - gtk_table_attach ( - GTK_TABLE (container), widget, 1, 2, 0, 1, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - - markup = g_strconcat ( - txt2, " ", _("This may take a while depending " - "on the amount of data in your account."), NULL); - widget = gtk_label_new (markup); - gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); - gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); - gtk_widget_show (widget); - g_free (markup); - - gtk_table_attach ( - GTK_TABLE (container), widget, 1, 2, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - - pbar = gtk_progress_bar_new (); - - if (str != NULL) { - markup = g_markup_printf_escaped ("<i>%s</i>", str); - widget = gtk_label_new (markup); - gtk_label_set_use_markup (GTK_LABEL (widget), TRUE); - gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5); - g_free (markup); - g_free (str); - - gtk_table_attach ( - GTK_TABLE (container), widget, 1, 2, 2, 3, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - gtk_table_set_row_spacing (GTK_TABLE (container), 2, 6); - - gtk_table_attach ( - GTK_TABLE (container), pbar, 1, 2, 3, 4, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - } else - gtk_table_attach ( - GTK_TABLE (container), pbar, 1, 2, 2, 3, - GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0); - - g_signal_connect ( - progress_dialog, "response", - G_CALLBACK (dlg_response), cancellable); - gtk_widget_show_all (progress_dialog); - - } else if (check_op) { - /* For sanity we don't need gui */ - check (chk_file, NULL); - exit (result == 0 ? 0 : 1); - } - - if (gui_arg) - g_timeout_add_full ( - G_PRIORITY_DEFAULT, 50, - (GSourceFunc) pbar_update, - g_object_ref (cancellable), - (GDestroyNotify) g_object_unref); - - g_io_scheduler_push_job ( - start_job, NULL, - (GDestroyNotify) NULL, - G_PRIORITY_DEFAULT, cancellable); - - gtk_main (); - - g_object_unref (cancellable); - - return result; -} diff --git a/plugins/backup-restore/org-gnome-backup-restore.eplug.xml b/plugins/backup-restore/org-gnome-backup-restore.eplug.xml deleted file mode 100644 index 4899b2dd8a..0000000000 --- a/plugins/backup-restore/org-gnome-backup-restore.eplug.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0"?> -<e-plugin-list> - <!-- the path to the shared library --> - <e-plugin - id="org.gnome.plugin.backup.restore" - type="shlib" - location="@PLUGINDIR@/liborg-gnome-backup-restore@SOEXT@" - _name="Back up and Restore"> - <author name="JP Rosevear" email="jpr@novell.com"/> - <_description>Back up and restore your Evolution data and settings.</_description> - - <hook class="org.gnome.evolution.ui:1.0"> - <ui-manager id="org.gnome.evolution.shell"> - <menubar name='main-menu'> - <menu action='file-menu'> - <placeholder name='file-actions'> - <menuitem action='settings-backup'/> - <menuitem action='settings-restore'/> - </placeholder> - </menu> - </menubar> - </ui-manager> - </hook> - - <hook class="org.gnome.evolution.mail.config:1.0"> - <group target="settings" id="org.gnome.evolution.mail.config.accountWizard" commit="backup_restore_commit" abort="backup_restore_abort"> - <item type="page" path="0.startup_page.10.backup_restore" factory="backup_restore_page"/> - </group> - </hook> - - </e-plugin> -</e-plugin-list> diff --git a/plugins/backup-restore/org-gnome-backup-restore.error.xml b/plugins/backup-restore/org-gnome-backup-restore.error.xml deleted file mode 100644 index 10a9966339..0000000000 --- a/plugins/backup-restore/org-gnome-backup-restore.error.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<error-list domain="org.gnome.backup-restore"> - - <error id="invalid-backup" type="warning"> - <_primary>Invalid Evolution backup file</_primary> - <_secondary>Please select a valid backup file to restore.</_secondary> - </error> - <error id="backup-confirm" type="warning" default="GTK_RESPONSE_CANCEL"> - <_primary>Are you sure you want to close Evolution?</_primary> - <_secondary xml:space="preserve">To back up your data and settings, you must first close Evolution. Please make sure that you save any unsaved data before proceeding.</_secondary> - <button _label="Close and Back up Evolution" response="GTK_RESPONSE_YES"/> - <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/> - </error> - <error id="restore-confirm" type="warning" default="GTK_RESPONSE_CANCEL"> - <_primary>Are you sure you want to restore Evolution from the selected backup file?</_primary> - <_secondary xml:space="preserve">To restore your data and settings, you must first close Evolution. Please make sure that you save any unsaved data before proceeding. This will delete all your current Evolution data and settings and restore them from your backup.</_secondary> - <button stock="gtk-cancel" response="GTK_RESPONSE_CANCEL"/> - <button _label="Close and Restore Evolution" response="GTK_RESPONSE_YES"/> - </error> - <error id="insufficient-permissions" type="error"> - <_primary>Insufficient Permissions</_primary> - <_secondary>The selected folder is not writable.</_secondary> - </error> -</error-list> |