1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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;
}
|