aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Rosevear <jpr@novell.com>2004-12-17 11:15:54 +0800
committerJP Rosevear <jpr@src.gnome.org>2004-12-17 11:15:54 +0800
commitb8cafeb987c18d7bdad2fd45d2e7c4613df04b74 (patch)
treefd39a4c0908f76179a067222dc7bff5a76dc30db
parent75d011570d92f39fac17fdb59eb678efba6d6fb4 (diff)
downloadgsoc2013-evolution-b8cafeb987c18d7bdad2fd45d2e7c4613df04b74.tar.gz
gsoc2013-evolution-b8cafeb987c18d7bdad2fd45d2e7c4613df04b74.tar.zst
gsoc2013-evolution-b8cafeb987c18d7bdad2fd45d2e7c4613df04b74.zip
Imported backup/restore plugin
2004-12-16 JP Rosevear <jpr@novell.com> * Imported backup/restore plugin svn path=/trunk/; revision=28140
-rw-r--r--plugins/backup-restore/.cvsignore6
-rw-r--r--plugins/backup-restore/ChangeLog4
-rw-r--r--plugins/backup-restore/Makefile.am26
-rw-r--r--plugins/backup-restore/backup-restore.c122
-rw-r--r--plugins/backup-restore/backup.c153
-rw-r--r--plugins/backup-restore/org-gnome-backup-restore.eplug.in33
-rw-r--r--plugins/backup-restore/org-gnome-backup-restore.xml21
7 files changed, 365 insertions, 0 deletions
diff --git a/plugins/backup-restore/.cvsignore b/plugins/backup-restore/.cvsignore
new file mode 100644
index 0000000000..76bd16c42d
--- /dev/null
+++ b/plugins/backup-restore/.cvsignore
@@ -0,0 +1,6 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.eplug
+backup \ No newline at end of file
diff --git a/plugins/backup-restore/ChangeLog b/plugins/backup-restore/ChangeLog
new file mode 100644
index 0000000000..df66bd61fc
--- /dev/null
+++ b/plugins/backup-restore/ChangeLog
@@ -0,0 +1,4 @@
+2004-12-16 JP Rosevear <jpr@novell.com>
+
+ * Imported backup/restore plugin
+
diff --git a/plugins/backup-restore/Makefile.am b/plugins/backup-restore/Makefile.am
new file mode 100644
index 0000000000..3627d1c69a
--- /dev/null
+++ b/plugins/backup-restore/Makefile.am
@@ -0,0 +1,26 @@
+INCLUDES = \
+ -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \
+ -DEVOLUTION_TOOLSDIR=\""$(privlibexecdir)"\" \
+ -DPREFIX=\""$(prefix)"\" \
+ -DSYSCONFDIR=\""$(sysconfdir)"\" \
+ -DDATADIR=\""$(datadir)"\" \
+ -DLIBDIR=\""$(libdir)"\" \
+ -I$(top_srcdir) \
+ $(SHELL_CFLAGS) \
+ $(E_UTIL_CFLAGS)
+
+@EVO_PLUGIN_RULE@
+
+plugin_DATA = org-gnome-backup-restore.eplug org-gnome-backup-restore.xml
+plugin_LTLIBRARIES = liborg-gnome-backup-restore.la
+
+liborg_gnome_backup_restore_la_SOURCES = backup-restore.c
+liborg_gnome_backup_restore_la_LDFLAGS = -module -avoid-version
+
+privlibexec_PROGRAMS = backup
+backup_SOURCES = backup.c
+backup_LDADD = $(SHELL_LIBS)
+
+EXTRA_DIST = \
+ org-gnome-backup-restore.eplug.in \
+ org-gnome-backup-restore.xml \ No newline at end of file
diff --git a/plugins/backup-restore/backup-restore.c b/plugins/backup-restore/backup-restore.c
new file mode 100644
index 0000000000..7344806e83
--- /dev/null
+++ b/plugins/backup-restore/backup-restore.c
@@ -0,0 +1,122 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <gtk/gtk.h>
+#include <libgnome/gnome-i18n.h>
+#include "shell/es-menu.h"
+
+void org_gnome_backup_restore_backup (EPlugin *ep, ESMenuTargetShell *target);
+void org_gnome_backup_restore_restore (EPlugin *ep, ESMenuTargetShell *target);
+
+static void
+backup (const char *filename, gboolean restart)
+{
+ if (restart)
+ execl (EVOLUTION_TOOLSDIR "/backup", "backup", "--backup", "--restart", filename, NULL);
+ else
+ execl (EVOLUTION_TOOLSDIR "/backup", "backup", "--backup", filename, NULL);
+}
+
+static void
+restore (const char *filename, gboolean restart)
+{
+ if (restart)
+ execl (EVOLUTION_TOOLSDIR "/backup", "backup", "--restore", "--restart", filename, NULL);
+ else
+ execl (EVOLUTION_TOOLSDIR "/backup", "backup", "--restore", filename, NULL);
+}
+
+static gboolean
+sanity_check (const char *filename)
+{
+ char *command;
+ int result;
+
+ command = g_strdup_printf ("%s/backup --check %s", EVOLUTION_TOOLSDIR, filename);
+ result = system (command);
+ g_free (command);
+
+ g_message ("Sanity check result %d:%d", WIFEXITED (result), WEXITSTATUS (result));
+
+ return WIFEXITED (result) && (WEXITSTATUS (result) == 0);
+}
+
+void
+org_gnome_backup_restore_backup (EPlugin *ep, ESMenuTargetShell *target)
+{
+ GtkWidget *dlg;
+ GtkWidget *vbox, *check;
+ int response;
+
+ dlg = gtk_file_chooser_dialog_new (_("Select name of Evolution archive"), GTK_WINDOW (target->target.widget),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dlg), "evolution-backup.tar.gz");
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_widget_show (vbox);
+
+ check = gtk_check_button_new_with_mnemonic (_("_Restart Evolution after backup"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
+ gtk_widget_show (check);
+
+ gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 0);
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dlg), vbox);
+
+ response = gtk_dialog_run (GTK_DIALOG (dlg));
+ if (response == GTK_RESPONSE_OK) {
+ char *filename;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
+
+ backup (filename, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+
+ g_free (filename);
+ }
+
+ gtk_widget_destroy (dlg);
+}
+
+void
+org_gnome_backup_restore_restore (EPlugin *ep, ESMenuTargetShell *target)
+{
+ GtkWidget *dlg;
+ GtkWidget *vbox, *check;
+ int response;
+
+ dlg = gtk_file_chooser_dialog_new (_("Select Evolution archive to restore"), GTK_WINDOW (target->target.widget),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+
+ vbox = gtk_vbox_new (FALSE, 6);
+ gtk_widget_show (vbox);
+
+ check = gtk_check_button_new_with_mnemonic (_("_Restart Evolution after restore"));
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
+ gtk_widget_show (check);
+
+ gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 0);
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dlg), vbox);
+
+ response = gtk_dialog_run (GTK_DIALOG (dlg));
+ if (response == GTK_RESPONSE_OK) {
+ char *filename;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dlg));
+
+ if (sanity_check (filename)) {
+ restore (filename, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+ } else {
+ g_message ("Invalid archive");
+ }
+
+ g_free (filename);
+ }
+
+ gtk_widget_destroy (dlg);
+}
+
+
diff --git a/plugins/backup-restore/backup.c b/plugins/backup-restore/backup.c
new file mode 100644
index 0000000000..9048ee2928
--- /dev/null
+++ b/plugins/backup-restore/backup.c
@@ -0,0 +1,153 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+
+#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-util.h>
+
+#define EVOLUTION "evolution-" BASE_VERSION
+#define EVOLUTION_DIR "~/.evolution/"
+#define EVOLUTION_DIR_BACKUP "~/.evolution-old/"
+#define GCONF_DUMP_FILE "backup-restore-gconf.xml"
+#define GCONF_DUMP_PATH EVOLUTION_DIR GCONF_DUMP_FILE
+#define GCONF_DIR "/apps/evolution"
+#define ARCHIVE_NAME "evolution-backup.tar.gz"
+
+static gboolean backup_op = FALSE;
+static gboolean restore_op = FALSE;
+static gboolean check_op = FALSE;
+static gboolean restart_arg = FALSE;
+
+#define d(x) x
+
+/* #define s(x) system (x) */
+#define s(x) G_STMT_START { g_message (x); system (x); } G_STMT_END
+
+static void
+backup (const char *filename)
+{
+ char *command;
+
+ /* FIXME Will the versioned setting always work? */
+ s (EVOLUTION " --force-shutdown");
+
+ s ("gconftool-2 --dump " GCONF_DIR " > " GCONF_DUMP_PATH);
+
+ /* FIXME stay on this file system ,other options?" */
+ /* FIXME compression type?" */
+ /* FIXME date/time stamp?" */
+ /* FIXME archive location?" */
+ command = g_strdup_printf ("cd ~ && tar zpcf %s .evolution", filename);
+ s (command);
+ g_free (command);
+
+ if (restart_arg)
+ s (EVOLUTION);
+}
+
+static void
+restore (const char *filename)
+{
+ char *command;
+
+ /* FIXME Will the versioned setting always work? */
+ s (EVOLUTION " --force-shutdown");
+
+ s ("mv " EVOLUTION_DIR " " EVOLUTION_DIR_BACKUP);
+
+ command = g_strdup_printf ("cd ~ && tar zxf %s", filename);
+ s (command);
+ g_free (command);
+
+ s ("gconftool-2 --load " GCONF_DUMP_PATH);
+ s ("rm -rf " GCONF_DUMP_PATH);
+ s ("rm -rf " EVOLUTION_DIR_BACKUP);
+
+ if (restart_arg)
+ s (EVOLUTION);
+}
+
+static void
+check (const char *filename)
+{
+ char *command;
+ int result;
+
+ command = g_strdup_printf ("tar ztf %s | grep -e \"^\\.evolution/$\"", filename);
+ result = system (command);
+ g_free (command);
+
+ g_message ("First result %d", result);
+ if (result)
+ exit (result);
+
+ command = g_strdup_printf ("tar ztf %s | grep -e \"^\\.evolution/%s$\"", filename, GCONF_DUMP_FILE);
+ result = system (command);
+ g_free (command);
+
+ g_message ("Second result %d", result);
+
+ exit (result);
+}
+
+int
+main (int argc, char **argv)
+{
+ GValue popt_context_value = { 0, };
+ GnomeProgram *program;
+ poptContext popt_context;
+ const char **args;
+
+ struct poptOption options[] = {
+ { "backup", '\0', POPT_ARG_NONE, &backup_op, 0,
+ N_("Backup Evolution directory"), NULL },
+ { "restore", '\0', POPT_ARG_NONE, &restore_op, 0,
+ N_("Restore Evolution directory"), NULL },
+ { "check", '\0', POPT_ARG_NONE, &check_op, 0,
+ N_("Check Evolution archive"), NULL },
+ { "restart", '\0', POPT_ARG_NONE, &restart_arg, 0,
+ N_("Restart Evolution"), NULL },
+ { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ };
+
+ bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ program = gnome_program_init (PACKAGE, VERSION, LIBGNOME_MODULE, argc, argv,
+ GNOME_PROGRAM_STANDARD_PROPERTIES,
+ GNOME_PARAM_POPT_TABLE, options,
+ NULL);
+
+ g_value_init (&popt_context_value, G_TYPE_POINTER);
+ g_object_get_property (G_OBJECT (program), GNOME_PARAM_POPT_CONTEXT, &popt_context_value);
+ popt_context = g_value_get_pointer (&popt_context_value);
+ args = poptGetArgs (popt_context);
+
+ if (args != NULL) {
+ const char **p;
+
+ for (p = args; *p != NULL; p++) {
+ if (backup_op) {
+ d(g_message ("Backing up to %s", (char *) *p));
+ backup ((char *) *p);
+ } else if (restore_op) {
+ d(g_message ("Restoring from %s", (char *) *p));
+ restore ((char *) *p);
+ } else if (check_op) {
+ d(g_message ("Checking %s", (char *) *p));
+ check ((char *) *p);
+ }
+ }
+ }
+
+ g_value_unset (&popt_context_value);
+
+ return 0;
+}
diff --git a/plugins/backup-restore/org-gnome-backup-restore.eplug.in b/plugins/backup-restore/org-gnome-backup-restore.eplug.in
new file mode 100644
index 0000000000..09a080bf91
--- /dev/null
+++ b/plugins/backup-restore/org-gnome-backup-restore.eplug.in
@@ -0,0 +1,33 @@
+<?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.so"
+ name="Backup and restore plugin"
+ description="A plugin for backing up and restore Evolution data and settings.">
+
+ <hook class="org.gnome.evolution.shell.bonobomenu:1.0">
+
+ <menu id="org.gnome.evolution.shell" target="shell">
+ <!-- the path to the bonobo menu description -->
+ <ui file="@PLUGINDIR@/org-gnome-backup-restore.xml"/>
+ <item
+ type="item"
+ verb="EPBRBackup"
+ path="/commands/EPBRBackup"
+ enable="one"
+ activate="org_gnome_backup_restore_backup"/>
+ <item
+ type="item"
+ verb="EPBRRestore"
+ path="/commands/EPBRRestore"
+ enable="one"
+ activate="org_gnome_backup_restore_restore"/>
+ </menu>
+
+ </hook>
+
+ </e-plugin>
+</e-plugin-list>
diff --git a/plugins/backup-restore/org-gnome-backup-restore.xml b/plugins/backup-restore/org-gnome-backup-restore.xml
new file mode 100644
index 0000000000..9af58343d1
--- /dev/null
+++ b/plugins/backup-restore/org-gnome-backup-restore.xml
@@ -0,0 +1,21 @@
+<Root>
+ <commands>
+ <cmd name="EPBRBackup" _label="Backup Settings..."
+ _tip="Backup and restore Evolution data and settings"
+ pixtype="pixmap"/>
+
+ <cmd name="EPBRRestore" _label="Restore Settings..."
+ _tip="Backup and restore Evolution data and settings"
+ pixtype="pixmap"/>
+
+ </commands>
+
+ <menu>
+ <submenu name="File">
+ <placeholder name="FileOps">
+ <menuitem name="EPBRBackup" verb=""/>
+ <menuitem name="EPBRRestore" verb=""/>
+ </placeholder>
+ </submenu>
+ </menu>
+</Root>