aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorXan Lopez <xlopez@igalia.com>2011-09-02 03:06:05 +0800
committerXan Lopez <xlopez@igalia.com>2011-09-02 03:07:41 +0800
commit459f7eab590f49340962cdf6bc3d4d66b3356109 (patch)
tree0361643db81b93c56bf4f2de916cb3ec786219f7 /embed
parent996bf1df4981e87d507e3fc8940d0c84b7d8ba9f (diff)
downloadgsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar.gz
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar.bz2
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar.lz
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar.xz
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.tar.zst
gsoc2013-epiphany-459f7eab590f49340962cdf6bc3d4d66b3356109.zip
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.
Diffstat (limited to 'embed')
-rw-r--r--embed/Makefile.am4
-rw-r--r--embed/ephy-web-app-utils.c136
-rw-r--r--embed/ephy-web-app-utils.h36
3 files changed, 175 insertions, 1 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am
index d517fb480..30beac028 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 000000000..e64eb1ac0
--- /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 000000000..39399dd0b
--- /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
+