aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-web-app-utils.c
diff options
context:
space:
mode:
authorClaudio Saavedra <csaavedra@igalia.com>2011-09-10 00:29:15 +0800
committerClaudio Saavedra <csaavedra@igalia.com>2012-02-08 20:42:09 +0800
commitdb10ae9888b32a8a1bcccdaba36cec15375b67be (patch)
treea233abc99c648ba07adc7f67415928345d85e3a9 /embed/ephy-web-app-utils.c
parent33af7ef9f0b521d1924ab11198ad46536f22b830 (diff)
downloadgsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar.gz
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar.bz2
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar.lz
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar.xz
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.tar.zst
gsoc2013-epiphany-db10ae9888b32a8a1bcccdaba36cec15375b67be.zip
Convert app names to the proper encoding before using them as filenames
Also add proper conversion error handling where needed. https://bugzilla.gnome.org/show_bug.cgi?id=658028
Diffstat (limited to 'embed/ephy-web-app-utils.c')
-rw-r--r--embed/ephy-web-app-utils.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/embed/ephy-web-app-utils.c b/embed/ephy-web-app-utils.c
index 8d6a52dbb..b72eca795 100644
--- a/embed/ephy-web-app-utils.c
+++ b/embed/ephy-web-app-utils.c
@@ -52,6 +52,27 @@ get_wm_class_from_app_title (const char *title)
return wm_class;
}
+/* Gets the proper .desktop filename from a WM_CLASS string,
+ converting to the local charset when needed. */
+static char *
+desktop_filename_from_wm_class (char *wm_class)
+{
+ char *encoded;
+ char *filename = NULL;
+ GError *error = NULL;
+
+ encoded = g_filename_from_utf8 (wm_class, -1, NULL, NULL, &error);
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+ filename = g_strconcat (encoded, ".desktop", NULL);
+ g_free (encoded);
+
+ return filename;
+}
+
/**
* ephy_web_application_get_profile_directory:
* @app_name: the application name
@@ -64,12 +85,22 @@ get_wm_class_from_app_title (const char *title)
char *
ephy_web_application_get_profile_directory (const char *app_name)
{
- char *app_dir, *wm_class, *profile_dir;
+ char *app_dir, *wm_class, *profile_dir, *encoded;
+ GError *error = NULL;
wm_class = get_wm_class_from_app_title (app_name);
- app_dir = g_strconcat (EPHY_WEB_APP_PREFIX, wm_class, NULL);
- profile_dir = g_build_filename (ephy_dot_dir (), app_dir, NULL);
+ encoded = g_filename_from_utf8 (wm_class, -1, NULL, NULL, &error);
g_free (wm_class);
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ app_dir = g_strconcat (EPHY_WEB_APP_PREFIX, encoded, NULL);
+ profile_dir = g_build_filename (ephy_dot_dir (), app_dir, NULL);
+ g_free (encoded);
g_free (app_dir);
return profile_dir;
@@ -96,6 +127,9 @@ ephy_web_application_delete (const char *name)
g_return_val_if_fail (name, FALSE);
profile_dir = ephy_web_application_get_profile_directory (name);
+ if (!profile_dir)
+ goto out;
+
/* 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)) {
@@ -109,8 +143,10 @@ ephy_web_application_delete (const char *name)
g_print ("Deleted application profile.\n");
wm_class = get_wm_class_from_app_title (name);
- desktop_file = g_strconcat (wm_class, ".desktop", NULL);
+ desktop_file = desktop_filename_from_wm_class (wm_class);
g_free (wm_class);
+ if (!desktop_file)
+ goto out;
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))
@@ -154,7 +190,7 @@ create_desktop_file (EphyWebView *view,
GKeyFile *file;
char *exec_string;
char *data;
- char *filename, *apps_path, *desktop_file_path;
+ char *filename, *apps_path, *desktop_file_path = NULL;
char *link_path;
char *wm_class;
GFile *link;
@@ -162,6 +198,12 @@ create_desktop_file (EphyWebView *view,
g_return_val_if_fail (profile_dir, NULL);
+ wm_class = get_wm_class_from_app_title (title);
+ filename = desktop_filename_from_wm_class (wm_class);
+
+ if (!filename)
+ goto out;
+
file = g_key_file_new ();
g_key_file_set_value (file, "Desktop Entry", "Name", title);
exec_string = g_strdup_printf ("epiphany --application-mode --profile=\"%s\" %s",
@@ -190,22 +232,16 @@ create_desktop_file (EphyWebView *view,
g_free (path);
}
- wm_class = get_wm_class_from_app_title (title);
g_key_file_set_value (file, "Desktop Entry", "StartupWMClass", wm_class);
-
data = g_key_file_to_data (file, NULL, NULL);
- filename = g_strconcat (wm_class, ".desktop", NULL);
- g_free (wm_class);
+
desktop_file_path = g_build_filename (profile_dir, filename, NULL);
- g_key_file_free (file);
if (!g_file_set_contents (desktop_file_path, data, -1, NULL)) {
g_free (desktop_file_path);
desktop_file_path = NULL;
}
- g_free (data);
-
/* Create a symlink in XDG_DATA_DIR/applications for the Shell to
* pick up this application. */
apps_path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
@@ -222,6 +258,11 @@ create_desktop_file (EphyWebView *view,
g_free (apps_path);
g_free (filename);
+out:
+ g_free (wm_class);
+ g_free (data);
+ g_key_file_free (file);
+
return desktop_file_path;
}