← Back to team overview

deja-dup-team team mailing list archive

[Merge] lp:~kaie/deja-dup/deja-dup into lp:deja-dup

 

Kai Engert has proposed merging lp:~kaie/deja-dup/deja-dup into lp:deja-dup.

Requested reviews:
  Déjà Dup Developers (deja-dup-hackers)

For more details, see:
https://code.launchpad.net/~kaie/deja-dup/deja-dup/+merge/156644

Cinnamon forked nautilus and called the fork nemo. As a result, deja-dup's nautilus integration is missing. I copied the nautilus code and renamed as required. No code changes were made. The result builds and works for me in nemo.

I hope it is OK to reuse my older branch? I hope it only contains my latest changes...

-- 
https://code.launchpad.net/~kaie/deja-dup/deja-dup/+merge/156644
Your team Déjà Dup Developers is requested to review the proposed merge of lp:~kaie/deja-dup/deja-dup into lp:deja-dup.
=== modified file 'Makefile.am'
--- Makefile.am	2012-04-13 20:46:19 +0000
+++ Makefile.am	2013-04-02 17:29:28 +0000
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
 
-SUBDIRS = data po vapi common tools widgets monitor preferences deja-dup nautilus help man tests
+SUBDIRS = data po vapi common tools widgets monitor preferences deja-dup nautilus nemo help man tests
 
 # Distribute pot file
 update-pot:

=== modified file 'configure.ac'
--- configure.ac	2013-03-18 19:16:59 +0000
+++ configure.ac	2013-04-02 17:29:28 +0000
@@ -156,6 +156,28 @@
 )
 AM_CONDITIONAL([HAVE_NAUTILUS], [test -n "$NAUTILUS_LIBS"])
 
+AC_ARG_WITH([nemo],
+  [AS_HELP_STRING([--with-nemo],
+    [build nemo plugin @<:@default=check@:>@])],
+  [],
+  [with_nemo=check])
+AS_IF([test "x$with_nemo" != xno],
+  [PKG_CHECK_MODULES(NEMO, libnemo-extension 
+                               glib-2.0 >= $GLIB_REQ_VER,
+    [dnl Get nemo extensions directory
+     AS_IF([test "x$with_extensiondir" != xno],
+       [NEMO_EXTENSION_DIR=`$PKG_CONFIG --variable=extensiondir libnemo-extension`],
+       [NEMO_EXTENSION_DIR="${PREFIX}/lib/nemo/extensions-3.0"])
+     AC_SUBST(NEMO_EXTENSION_DIR)],
+    [if test "x$with_nemo" != xcheck; then
+        AC_MSG_FAILURE(
+          [--with-nemo was given, but test for libnautilus-extension failed])
+      fi
+    ]
+  )]
+)
+AM_CONDITIONAL([HAVE_NEMO], [test -n "$NEMO_LIBS"])
+
 AH_TEMPLATE([HAVE_UNITY], [whether libunity is available])
 AC_ARG_WITH([unity],
   [AS_HELP_STRING([--with-unity],
@@ -183,6 +205,7 @@
                  man/Makefile
                  monitor/Makefile
                  nautilus/Makefile
+                 nemo/Makefile
                  po/Makefile.in
                  preferences/Makefile
                  tests/Makefile

=== added directory 'nemo'
=== added file 'nemo/Makefile.am'
--- nemo/Makefile.am	1970-01-01 00:00:00 +0000
+++ nemo/Makefile.am	2013-04-02 17:29:28 +0000
@@ -0,0 +1,35 @@
+# -*- Mode: Makefile; indent-tabs-mode: t; tab-width: 2 -*-
+#
+# This file is part of Déjà Dup.
+# For copyright information, see AUTHORS.
+#
+# Déjà Dup is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Déjà Dup 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
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
+
+if HAVE_NEMO
+nemodir = $(NEMO_EXTENSION_DIR)
+
+nemo_LTLIBRARIES = libdeja-dup-nemo.la
+
+libdeja_dup_nemo_la_CFLAGS = \
+	-I$(top_srcdir)/common \
+	$(NEMO_CFLAGS) \
+	-DPKG_LIBEXEC_DIR=\"$(pkglibexecdir)\" \
+	-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\"
+
+libdeja_dup_nemo_la_SOURCES = \
+	NemoExtension.c NemoExtension.h
+
+libdeja_dup_nemo_la_LDFLAGS = -module -avoid-version
+libdeja_dup_nemo_la_LIBADD = $(NEMO_LIBS) @INTLLIBS@
+endif

=== added file 'nemo/NemoExtension.c'
--- nemo/NemoExtension.c	1970-01-01 00:00:00 +0000
+++ nemo/NemoExtension.c	2013-04-02 17:29:28 +0000
@@ -0,0 +1,339 @@
+/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 2 -*- */
+/*
+    This file is part of Déjà Dup.
+    © 2004–2005 Free Software Foundation, Inc.
+    © 2009–2011 Michael Terry <mike@xxxxxxxxxxx>
+
+    Déjà Dup is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Déjà Dup 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "DirHandling.c"
+
+#include "NemoExtension.h"
+#include "config.h"
+#include <libnemo-extension/nemo-menu-provider.h>
+#include <glib/gi18n-lib.h>
+
+GList *dirs = NULL;
+GSettings *settings = NULL;
+
+// This will treat a < b iff a is 'lower' in the file tree than b
+static int
+cmp_prefix(GFile *a, GFile *b)
+{
+  if (a == NULL && b == NULL)
+    return 0;
+  else if (b == NULL || g_file_has_prefix(a, b))
+    return -1;
+  else if (a == NULL || g_file_has_prefix(b, a))
+    return 1;
+  else
+    return 0;
+}
+
+/* Do the include/exclude processing up front so that when
+   we query to see if a file is included, it will be fast. */
+static void
+update_include_excludes ()
+{
+  /* Clear any existing dirs */
+  if (dirs != NULL) {
+    g_list_foreach(dirs, (GFunc)g_object_unref, NULL);
+    g_list_free(dirs);
+    dirs = NULL;
+  }
+
+  if (settings == NULL)
+    return;
+
+  gchar **includes_strv = g_settings_get_strv(settings, "include-list");
+  gchar **excludes_strv = g_settings_get_strv(settings, "exclude-list");
+
+  gchar **p;
+  for (p = includes_strv; p && *p; p++) {
+    GFile *file = deja_dup_parse_dir(*p);
+    if (file != NULL) {
+      g_object_set_data(G_OBJECT(file), "included", GINT_TO_POINTER(TRUE));
+      dirs = g_list_insert_sorted(dirs, file, (GCompareFunc)cmp_prefix);
+    }
+  }
+  for (p = excludes_strv; p && *p; p++) {
+    GFile *file = deja_dup_parse_dir(*p);
+    if (file != NULL) {
+      g_object_set_data(G_OBJECT(file), "included", GINT_TO_POINTER(FALSE));
+      dirs = g_list_insert_sorted(dirs, file, (GCompareFunc)cmp_prefix);
+    }
+  }
+
+
+  g_strfreev(includes_strv);
+  g_strfreev(excludes_strv);
+}
+
+static gboolean
+update_include_excludes_idle_cb ()
+{
+  update_include_excludes ();
+  return FALSE;
+}
+
+static gboolean
+is_dir_included(GFile *file)
+{
+  GList *p;
+  for (p = dirs; p; p = p->next) {
+    if (g_file_equal(file, (GFile *)p->data) ||
+        g_file_has_prefix(file, (GFile *)p->data)) {
+      gboolean included;
+      included = GPOINTER_TO_INT(g_object_get_data(p->data, "included"));
+      return included;
+    }
+  }
+  return FALSE;
+}
+
+static void
+make_file_list(NemoFileInfo *info, GString *str)
+{
+  gchar *uri = nemo_file_info_get_uri(info);
+  if (!str->len)
+    g_string_assign(str, uri);
+  else
+    g_string_append_printf(str, " %s", uri);
+  g_free(uri);
+}
+
+static void
+restore_missing_files_callback(NemoMenuItem *item)
+{
+  gchar *cmd;
+  NemoFileInfo *info;
+
+  info = g_object_get_data(G_OBJECT(item), "deja_dup_extension_file");
+
+  cmd = g_strdup_printf("deja-dup --restore-missing %s",
+                        nemo_file_info_get_uri(info));
+
+  g_spawn_command_line_async(cmd, NULL);
+
+  g_free(cmd);
+}
+
+static void
+restore_files_callback(NemoMenuItem *item)
+{
+  GString *str = g_string_new("");
+  gchar *cmd;
+  GList *files;
+
+  files = g_object_get_data(G_OBJECT(item), "deja_dup_extension_files");
+
+  g_list_foreach(files, (GFunc)make_file_list, str);
+  cmd = g_strdup_printf("deja-dup --restore %s", 
+                        str->str);
+
+  g_spawn_command_line_async(cmd, NULL);
+
+  g_free(cmd);
+  g_string_free(str, TRUE);
+}
+
+static GList *
+deja_dup_nemo_extension_get_background_items(NemoMenuProvider *provider,
+                                                 GtkWidget *window,
+                                                 NemoFileInfo *file)
+{
+  NemoMenuItem *item;
+  guint length;
+  GList *file_copies;
+  gchar *path;
+
+  if (file == NULL)
+    return NULL;
+
+  path = g_find_program_in_path("deja-dup");
+  if (!path)
+    return NULL;
+  g_free(path);
+
+  if (!is_dir_included(nemo_file_info_get_location(file)))
+    return NULL;
+
+  item = nemo_menu_item_new("DejaDupNemoExtension::restore_missing_item",
+                                dgettext(GETTEXT_PACKAGE, "Restore Missing Files…"),
+                                dgettext(GETTEXT_PACKAGE, "Restore deleted files from backup"),
+                                "deja-dup");
+
+  g_signal_connect(item, "activate", G_CALLBACK(restore_missing_files_callback), NULL);
+  g_object_set_data_full (G_OBJECT(item), "deja_dup_extension_file",
+                          g_object_ref(file),
+                          (GDestroyNotify)g_object_unref);
+
+  return g_list_append(NULL, item);
+}
+
+static GList *
+deja_dup_nemo_extension_get_file_items(NemoMenuProvider *provider,
+                                           GtkWidget *window,
+                                           GList *files)
+{
+  NemoMenuItem *item;
+  guint length;
+  GList *file_copies;
+  gchar *path;
+
+  if (files == NULL)
+    return NULL;
+
+  path = g_find_program_in_path("deja-dup");
+  if (!path)
+    return NULL;
+  g_free(path);
+
+  gboolean is_one_included = FALSE;
+  GList *p;
+  for (p = files; p; p = p->next) {
+    GFile *gfile = nemo_file_info_get_location((NemoFileInfo *)p->data);
+    if (is_dir_included(gfile))
+      is_one_included = TRUE;
+  }
+  if (!is_one_included)
+    return NULL;
+
+  length = g_list_length(files);
+  item = nemo_menu_item_new("DejaDupNemoExtension::restore_item",
+                                dngettext(GETTEXT_PACKAGE,
+                                          "Revert to Previous Version…",
+                                          "Revert to Previous Versions…",
+                                          length),
+                                dngettext(GETTEXT_PACKAGE,
+                                          "Restore file from backup",
+                                          "Restore files from backup",
+                                          length),
+                                "deja-dup");
+
+  g_signal_connect(item, "activate", G_CALLBACK(restore_files_callback), NULL);
+  g_object_set_data_full (G_OBJECT(item), "deja_dup_extension_files", 
+                          nemo_file_info_list_copy(files),
+                          (GDestroyNotify)nemo_file_info_list_free);
+
+  return g_list_append(NULL, item);
+}
+
+
+enum  {
+  DEJA_DUP_NEMO_EXTENSION_DUMMY_PROPERTY
+};
+static gpointer deja_dup_nemo_extension_parent_class = NULL;
+
+
+static GType deja_dup_nemo_extension_type = 0;
+
+
+DejaDupNemoExtension* deja_dup_nemo_extension_construct (GType object_type) {
+  DejaDupNemoExtension * self;
+  self = g_object_newv (object_type, 0, NULL);
+  return self;
+}
+
+
+DejaDupNemoExtension* deja_dup_nemo_extension_new (void) {
+  return deja_dup_nemo_extension_construct (TYPE_DEJA_DUP_NEMO_EXTENSION);
+}
+
+
+static void deja_dup_nemo_extension_class_init (DejaDupNemoExtensionClass * klass) {
+  deja_dup_nemo_extension_parent_class = g_type_class_peek_parent (klass);
+}
+
+
+static void deja_dup_nemo_extension_instance_init (DejaDupNemoExtension * self) {
+}
+
+
+GType deja_dup_nemo_extension_get_type (void) {
+  return deja_dup_nemo_extension_type;
+}
+
+
+static void
+deja_dup_nemo_extension_menu_provider_iface_init (NemoMenuProviderIface *iface)
+{
+  iface->get_background_items = deja_dup_nemo_extension_get_background_items;
+  iface->get_file_items = deja_dup_nemo_extension_get_file_items;
+}
+
+void deja_dup_nemo_extension_register_type (GTypeModule *module)
+{
+  static const GTypeInfo info = {
+    sizeof (DejaDupNemoExtensionClass),
+    (GBaseInitFunc) NULL,
+    (GBaseFinalizeFunc) NULL,
+    (GClassInitFunc) deja_dup_nemo_extension_class_init,
+    NULL,
+    NULL,
+    sizeof (DejaDupNemoExtension),
+    0,
+    (GInstanceInitFunc) deja_dup_nemo_extension_instance_init,
+  };
+
+  deja_dup_nemo_extension_type = g_type_module_register_type (module,
+    G_TYPE_OBJECT,
+    "DejaDupNemoExtension",
+    &info, 0);
+
+  static const GInterfaceInfo menu_provider_iface_info =
+  {
+    (GInterfaceInitFunc)deja_dup_nemo_extension_menu_provider_iface_init,
+     NULL,
+     NULL
+  };
+
+  g_type_module_add_interface (module, deja_dup_nemo_extension_type,
+    NEMO_TYPE_MENU_PROVIDER, &menu_provider_iface_info);
+}
+
+static GType type_list[1];
+
+void nemo_module_initialize(GTypeModule *module)
+{
+  /*g_print("Initializing Déjà Dup extension\n");*/
+  deja_dup_nemo_extension_register_type(module);
+  type_list[0] = TYPE_DEJA_DUP_NEMO_EXTENSION;
+
+  bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
+  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+
+  settings = g_settings_new("org.gnome.DejaDup");
+  g_signal_connect(settings, "changed::include-list",
+                   update_include_excludes, NULL);
+  g_signal_connect(settings, "changed::exclude-list",
+                   update_include_excludes, NULL);
+  g_idle_add(update_include_excludes_idle_cb, NULL);
+}
+
+void nemo_module_list_types (const GType **types, int *num_types)
+{
+  *types = type_list;
+  *num_types = G_N_ELEMENTS (type_list);
+}
+
+void nemo_module_shutdown(void)
+{
+  g_object_unref(settings);
+  settings = NULL;
+
+  update_include_excludes(); /* will clear it now that settings is NULL */
+}
+

=== added file 'nemo/NemoExtension.h'
--- nemo/NemoExtension.h	1970-01-01 00:00:00 +0000
+++ nemo/NemoExtension.h	2013-04-02 17:29:28 +0000
@@ -0,0 +1,57 @@
+/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 2 -*- */
+/*
+    This file is part of Déjà Dup.
+    © 2009 Michael Terry <mike@xxxxxxxxxxx>
+
+    Déjà Dup is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Déjà Dup 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __NEMOEXTENSION_H__
+#define __NEMOEXTENSION_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+
+#define TYPE_DEJA_DUP_NEMO_EXTENSION (deja_dup_nemo_extension_get_type ())
+#define DEJA_DUP_NEMO_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DEJA_DUP_NEMO_EXTENSION, DejaDupNemoExtension))
+#define DEJA_DUP_NEMO_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DEJA_DUP_NEMO_EXTENSION, DejaDupNemoExtensionClass))
+#define IS_DEJA_DUP_NEMO_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DEJA_DUP_NEMO_EXTENSION))
+#define IS_DEJA_DUP_NEMO_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DEJA_DUP_NEMO_EXTENSION))
+#define DEJA_DUP_NEMO_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DEJA_DUP_NEMO_EXTENSION, DejaDupNemoExtensionClass))
+
+typedef struct _DejaDupNemoExtension DejaDupNemoExtension;
+typedef struct _DejaDupNemoExtensionClass DejaDupNemoExtensionClass;
+typedef struct _DejaDupNemoExtensionPrivate DejaDupNemoExtensionPrivate;
+
+struct _DejaDupNemoExtension {
+	GObject parent_instance;
+	DejaDupNemoExtensionPrivate * priv;
+};
+
+struct _DejaDupNemoExtensionClass {
+	GObjectClass parent_class;
+};
+
+
+DejaDupNemoExtension* deja_dup_nemo_extension_construct (GType object_type);
+DejaDupNemoExtension* deja_dup_nemo_extension_new (void);
+GType deja_dup_nemo_extension_get_type (void);
+
+
+G_END_DECLS
+
+#endif


Follow ups