[epiphany] Add --delete--application command line option to delete WebApps



commit 459f7eab590f49340962cdf6bc3d4d66b3356109
Author: Xan Lopez <xlopez igalia com>
Date:   Thu Sep 1 21:06:05 2011 +0200

    Add --delete--application command line option to delete WebApps
    
    Plus the necessary code to implement some sort of UI to do this for the
    3.2 time frame. Hopefully for 3.4 we'll have a GNOME-wide system to
    deal with applications.

 embed/Makefile.am          |    4 +-
 embed/ephy-web-app-utils.c |  136 ++++++++++++++++++++++++++++++++++++++++++++
 embed/ephy-web-app-utils.h |   36 ++++++++++++
 src/ephy-main.c            |   16 +++++
 4 files changed, 191 insertions(+), 1 deletions(-)
---
diff --git a/embed/Makefile.am b/embed/Makefile.am
index d517fb4..30beac0 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -10,7 +10,8 @@ header_DATA = \
 NOINST_H_FILES = \
 	ephy-embed-dialog.h		\
 	ephy-encodings.h		\
-	ephy-favicon-cache.h
+	ephy-favicon-cache.h		\
+	ephy-web-app-utils.h
 
 INST_H_FILES = \
 	ephy-adblock.h			\
@@ -48,6 +49,7 @@ libephyembed_la_SOURCES = \
 	ephy-history.c			\
 	ephy-permission-manager.c	\
 	ephy-embed-prefs.c		\
+	ephy-web-app-utils.c		\
 	ephy-web-view.c			\
 	$(INST_H_FILES)			\
 	$(NOINST_H_FILES)
diff --git a/embed/ephy-web-app-utils.c b/embed/ephy-web-app-utils.c
new file mode 100644
index 0000000..e64eb1a
--- /dev/null
+++ b/embed/ephy-web-app-utils.c
@@ -0,0 +1,136 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright  2011 Igalia S.L.
+ *
+ *  This program 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 2, or (at your option)
+ *  any later version.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "ephy-web-app-utils.h"
+
+#include "ephy-file-helpers.h"
+#include "ephy-web-view.h"
+
+static gboolean
+_g_directory_delete_recursively (GFile *directory, GError **error)
+{
+  GFileEnumerator *children = NULL;
+  GFileInfo *info;
+  gboolean ret = TRUE;
+
+  children = g_file_enumerate_children (directory,
+                                        "standard::name,standard::type",
+                                        0, NULL, error);
+  if (error)
+    goto out;
+
+  info = g_file_enumerator_next_file (children, NULL, error);
+  while (info || error) {
+    GFile *child;
+    const char *name;
+    GFileType type;
+
+    if (error)
+      goto out;
+
+    name = g_file_info_get_name (info);
+    child = g_file_get_child (directory, name);
+    type = g_file_info_get_file_type (info);
+
+    if (type == G_FILE_TYPE_DIRECTORY)
+      ret = _g_directory_delete_recursively (child, error);
+    else if (type == G_FILE_TYPE_REGULAR)
+      ret =  g_file_delete (child, NULL, error);
+
+    g_object_unref (info);
+
+    if (!ret)
+      goto out;
+
+    info = g_file_enumerator_next_file (children, NULL, error);
+  }
+
+  ret = TRUE;
+
+  g_file_delete (directory, NULL, error);
+
+out:
+
+  if (children)
+    g_object_unref (children);
+
+  return ret;
+}
+
+/**
+ * ephy_delete_web_application:
+ * @name: the name of the web application do delete
+ * 
+ * Deletes all the data associated with a Web Application created by
+ * Epiphany.
+ * 
+ * Returns: %TRUE if the web app was succesfully deleted, %FALSE otherwise
+ **/
+gboolean
+ephy_delete_web_application (const char *name)
+{
+  char *app_dir = NULL, *profile_dir = NULL;
+  char *desktop_file = NULL, *desktop_path = NULL;
+  GFile *profile = NULL, *launcher = NULL;
+  gboolean return_value = FALSE;
+
+  g_return_val_if_fail (name, FALSE);
+
+  app_dir = g_strconcat (EPHY_WEB_APP_PREFIX, name, NULL);
+  profile_dir = g_build_filename (ephy_dot_dir (), app_dir, NULL);
+
+  /* If there's no profile dir for this app, it means it does not
+   * exist. */
+  if (!g_file_test (profile_dir, G_FILE_TEST_IS_DIR)) {
+    g_print ("No application with name '%s' is installed.\n", name);
+    goto out;
+  }
+
+  profile = g_file_new_for_path (profile_dir);
+  if (!_g_directory_delete_recursively (profile, NULL))
+    goto out;
+  g_print ("Deleted application profile.\n");
+
+  desktop_file = g_strconcat (name, ".desktop", NULL);
+  desktop_path = g_build_filename (g_get_user_data_dir (), "applications", desktop_file, NULL);
+  launcher = g_file_new_for_path (desktop_path);
+  if (!g_file_delete (launcher, NULL, NULL))
+    goto out;
+  g_print ("Deleted application launcher.\n");
+
+  return_value = TRUE;
+
+out:
+
+  if (profile)
+    g_object_unref (profile);
+  g_free (profile_dir);
+  g_free (app_dir);
+
+  if (launcher)
+    g_object_unref (launcher);
+  g_free (desktop_file);
+  g_free (desktop_path);
+
+  return return_value;
+}
diff --git a/embed/ephy-web-app-utils.h b/embed/ephy-web-app-utils.h
new file mode 100644
index 0000000..39399dd
--- /dev/null
+++ b/embed/ephy-web-app-utils.h
@@ -0,0 +1,36 @@
+/*
+ *  Copyright  2011 Igalia S.L.
+ *
+ *  This program 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 2, or (at your option)
+ *  any later version.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#if !defined (__EPHY_EPIPHANY_H_INSIDE__) && !defined (EPIPHANY_COMPILATION)
+#error "Only <epiphany/epiphany.h> can be included directly."
+#endif
+
+#ifndef EPHY_WEB_APP_UTILS_H
+#define EPHY_WEB_APP_UTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean ephy_delete_web_application (const char *name);
+
+G_END_DECLS
+
+#endif
+
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 19b4100..1d1e28a 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -30,6 +30,7 @@
 #include "ephy-stock-icons.h"
 #include "ephy-session.h"
 #include "ephy-shell.h"
+#include "ephy-web-app-utils.h"
 #include "ephy-debug.h"
 #include "ephy-string.h"
 #include "eggsmclient.h"
@@ -61,6 +62,7 @@ static char *session_filename = NULL;
 static char *bookmark_url = NULL;
 static char *bookmarks_file = NULL;
 static char **arguments = NULL;
+static char *application_to_delete = NULL;
 
 /* Only set from options in debug builds */
 static gboolean private_instance = FALSE;
@@ -104,6 +106,8 @@ static const GOptionEntry option_entries[] =
     "", N_("URL â")},
   { "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, 
     G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
+  { "delete-application", 0, 0, G_OPTION_ARG_STRING | G_OPTION_FLAG_HIDDEN,
+    &application_to_delete, NULL, NULL },
   { NULL }
 };
 
@@ -359,6 +363,11 @@ main (int argc,
   g_option_context_free (option_context);
 
   /* Some argument sanity checks*/
+  if (application_to_delete != NULL && argc > 3) {
+    g_print ("Cannot pass any other parameter when using --delete-application\n");
+    exit (1);
+  }
+
   if (arguments != NULL && (session_filename != NULL || open_as_bookmarks_editor)) {
     g_print ("Cannot use --bookmarks-editor or --load-session with URL arguments  \n");
     exit (1);
@@ -416,6 +425,13 @@ main (int argc,
     exit (1);
   }
 
+  /* Delete the requested web application, if any. Must happen after
+   * ephy_file_helpers_init (). */
+  if (application_to_delete) {
+    ephy_delete_web_application (application_to_delete);
+    exit (0);
+  }
+
   ephy_stock_icons_init ();
   ephy_file_load_accels ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]