summaryrefslogtreecommitdiff
path: root/mate-panel/launcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'mate-panel/launcher.c')
-rw-r--r--mate-panel/launcher.c206
1 files changed, 125 insertions, 81 deletions
diff --git a/mate-panel/launcher.c b/mate-panel/launcher.c
index c59b67a8..07e52e40 100644
--- a/mate-panel/launcher.c
+++ b/mate-panel/launcher.c
@@ -105,10 +105,10 @@ launch_url (Launcher *launcher)
GdkScreen *screen;
g_return_if_fail (launcher != NULL);
- g_return_if_fail (launcher->app_info != NULL);
+ g_return_if_fail (launcher->key_file != NULL);
/* FIXME panel_ditem_launch() should be enough for this! */
- url = g_desktop_app_info_get_string (launcher->app_info, G_KEY_FILE_DESKTOP_KEY_URL);
+ url = panel_key_file_get_string (launcher->key_file, "URL");
screen = launcher_get_screen (launcher);
@@ -136,10 +136,10 @@ launcher_launch (Launcher *launcher,
char *type;
g_return_if_fail (launcher != NULL);
- g_return_if_fail (launcher->app_info != NULL);
+ g_return_if_fail (launcher->key_file != NULL);
if (action == NULL) {
- type = g_desktop_app_info_get_string (launcher->app_info, G_KEY_FILE_DESKTOP_KEY_TYPE);
+ type = panel_key_file_get_string (launcher->key_file, "Type");
} else {
type = NULL;
}
@@ -149,7 +149,7 @@ launcher_launch (Launcher *launcher,
else {
GError *error = NULL;
- panel_app_info_launch (launcher->app_info, NULL,
+ panel_launch_key_file (launcher->key_file, NULL,
launcher_get_screen (launcher), action, &error);
if (error) {
GtkWidget *error_dialog;
@@ -199,7 +199,7 @@ drag_data_received_cb (GtkWidget *widget,
file_list = g_list_prepend (file_list, uris[i]);
file_list = g_list_reverse (file_list);
- panel_app_info_launch (launcher->app_info, file_list,
+ panel_launch_key_file (launcher->key_file, file_list,
launcher_get_screen (launcher), NULL, &error);
g_list_free (file_list);
@@ -245,7 +245,13 @@ free_launcher (gpointer data)
{
Launcher *launcher = data;
- g_clear_object(&launcher->app_info);
+ if (launcher->key_file)
+ g_key_file_free (launcher->key_file);
+ launcher->key_file = NULL;
+
+ if (launcher->location != NULL)
+ g_free (launcher->location);
+ launcher->location = NULL;
g_free (launcher);
}
@@ -253,18 +259,15 @@ free_launcher (gpointer data)
void
panel_launcher_delete (Launcher *launcher)
{
- const gchar *location;
-
- location = g_desktop_app_info_get_filename (launcher->app_info);
- if (!location)
+ if (!launcher->location)
return;
/* do not remove the file if it's not in the user's launchers path */
- if (panel_launcher_is_in_personal_path (location)) {
+ if (panel_launcher_is_in_personal_path (launcher->location)) {
GError *error;
GFile *file;
- file = panel_launcher_get_gfile (location);
+ file = panel_launcher_get_gfile (launcher->location);
error = NULL;
if (!g_file_delete (file, NULL, &error)) {
@@ -371,12 +374,11 @@ drag_data_get_cb (GtkWidget *widget,
guint time,
Launcher *launcher)
{
- const char *location;
+ char *location;
g_return_if_fail (launcher != NULL);
- g_return_if_fail (launcher->app_info != NULL);
- location = g_desktop_app_info_get_filename (launcher->app_info);
+ location = launcher->location;
if (info == TARGET_URI_LIST) {
char *uri[2];
@@ -433,15 +435,20 @@ clicked_cb (Launcher *launcher,
static Launcher *
create_launcher (const char *location)
{
- GDesktopAppInfo *app_info;
+ GKeyFile *key_file;
+ gboolean loaded = FALSE;
Launcher *launcher;
+ GError *error = NULL;
+ char *new_location;
if (!location) {
g_printerr (_("No URI provided for panel launcher desktop file\n"));
return NULL;
}
- app_info = NULL;
+ new_location = NULL;
+ key_file = g_key_file_new ();
+
if (!strchr (location, G_DIR_SEPARATOR)) {
/* try to first load a file in our config directory, and if it
* doesn't exist there, try to find it in the xdg data dirs */
@@ -452,26 +459,49 @@ create_launcher (const char *location)
if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
g_free (path);
path = panel_g_lookup_in_applications_dirs (location);
+ /* it's important to keep the full path if the desktop
+ * file comes from a data dir: when the user will edit
+ * it, we'll want to save it in PANEL_LAUNCHERS_PATH
+ * with a random name (and not evolution.desktop, eg)
+ * and having only a basename as location will make
+ * this impossible */
+ if (path)
+ new_location = g_strdup (path);
}
if (path) {
- app_info = g_desktop_app_info_new_from_filename (path);
+ loaded = g_key_file_load_from_file (key_file, path,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ &error);
g_free (path);
}
} else
- app_info = g_desktop_app_info_new_from_filename (location);
+ loaded = panel_key_file_load_from_uri (key_file, location,
+ G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS,
+ &error);
+
+ if (!loaded) {
+ g_printerr (_("Unable to open desktop file %s for panel launcher%s%s\n"),
+ location,
+ error ? ": " : "",
+ error ? error->message : "");
+ if (error)
+ g_error_free (error);
- if (!app_info) {
- g_printerr (_("Unable to open desktop file %s for panel launcher\n"),
- location);
+ g_key_file_free (key_file);
+ g_free (new_location);
return NULL; /*button is null*/
}
+ if (!new_location)
+ new_location = g_strdup (location);
+
launcher = g_new0 (Launcher, 1);
launcher->info = NULL;
launcher->button = NULL;
- launcher->app_info = app_info;
+ launcher->location = new_location;
+ launcher->key_file = key_file;
launcher->prop_dialog = NULL;
launcher->destroy_handler = 0;
@@ -510,36 +540,24 @@ create_launcher (const char *location)
return launcher;
}
+#if GLIB_CHECK_VERSION (2, 38, 0)
static void
-setup_button (Launcher *launcher)
+setup_actions (Launcher *launcher)
{
- const char *comment;
- const char *name;
- char *str;
- char *icon;
- char *unescaped_str;
-#if GLIB_CHECK_VERSION (2, 38, 0)
+ GDesktopAppInfo *app_info;
const gchar * const *actions;
const gchar * const *ptr;
-#endif
-
- g_return_if_fail (launcher != NULL);
- mate_panel_applet_clear_user_menu (launcher->info);
-
- mate_panel_applet_add_callback (launcher->info,
- "launch",
- "system-run",
- _("_Launch"),
- NULL);
+ app_info = g_desktop_app_info_new_from_keyfile (launcher->key_file);
+ if (app_info == NULL)
+ return;
-#if GLIB_CHECK_VERSION (2, 38, 0)
- actions = g_desktop_app_info_list_actions (launcher->app_info);
+ actions = g_desktop_app_info_list_actions (app_info);
ptr = actions;
for(; *ptr != NULL; ptr++) {
const gchar *action = *ptr;
gchar *callback = g_strdup_printf("launch-action_%s", action);
- gchar *action_name = g_desktop_app_info_get_action_name (launcher->app_info, action);
+ gchar *action_name = g_desktop_app_info_get_action_name (app_info, action);
mate_panel_applet_add_callback (launcher->info,
callback,
NULL,
@@ -548,6 +566,32 @@ setup_button (Launcher *launcher)
g_free (callback);
g_free (action_name);
}
+
+ g_object_unref (app_info);
+}
+#endif
+
+static void
+setup_button (Launcher *launcher)
+{
+ char *comment;
+ char *name;
+ char *str;
+ char *icon;
+ char *unescaped_str;
+
+ g_return_if_fail (launcher != NULL);
+
+ mate_panel_applet_clear_user_menu (launcher->info);
+
+ mate_panel_applet_add_callback (launcher->info,
+ "launch",
+ "system-run",
+ _("_Launch"),
+ NULL);
+
+#if GLIB_CHECK_VERSION (2, 38, 0)
+ setup_actions (launcher);
#endif
mate_panel_applet_add_callback (launcher->info,
@@ -556,8 +600,10 @@ setup_button (Launcher *launcher)
_("_Properties"),
launcher_properties_enabled);
- name = g_app_info_get_name (G_APP_INFO(launcher->app_info));
- comment = g_app_info_get_description (G_APP_INFO(launcher->app_info));
+ name = panel_key_file_get_locale_string (launcher->key_file, "Name");
+ comment = panel_key_file_get_locale_string (launcher->key_file,
+ "Comment");
+
/* Setup tooltip */
if (!PANEL_GLIB_STR_EMPTY (name) && !PANEL_GLIB_STR_EMPTY (comment))
str = g_strdup_printf ("%s\n%s", name, comment);
@@ -585,7 +631,7 @@ setup_button (Launcher *launcher)
g_free (str);
/* Setup icon */
- icon = g_desktop_app_info_get_string (launcher->app_info, G_KEY_FILE_DESKTOP_KEY_ICON);
+ icon = panel_key_file_get_locale_string (launcher->key_file, "Icon");
if (icon && icon[0] == '\0') {
g_free (icon);
icon = NULL;
@@ -593,11 +639,15 @@ setup_button (Launcher *launcher)
if (!icon) {
gchar *exec;
- exec = g_desktop_app_info_get_string (launcher->app_info, G_KEY_FILE_DESKTOP_KEY_EXEC);
- icon = guess_icon_from_exec (button_widget_get_icon_theme (BUTTON_WIDGET (launcher->button)),
- exec);
+ exec = panel_key_file_get_string (launcher->key_file, "Exec");
+ if (exec && exec[0] != '\0') {
+ icon = guess_icon_from_exec (button_widget_get_icon_theme (BUTTON_WIDGET (launcher->button)),
+ exec);
+ }
+
g_free (exec);
}
+
if (!icon)
icon = g_strdup (PANEL_ICON_LAUNCHER);
@@ -654,18 +704,16 @@ launcher_command_changed (PanelDItemEditor *dialog,
{
char *exec;
char *old_exec;
- GKeyFile *key_file;
GKeyFile *revert_key_file;
- key_file = panel_ditem_editor_get_key_file (dialog);
revert_key_file = panel_ditem_editor_get_revert_key_file (dialog);
if (revert_key_file) {
- exec = panel_key_file_get_string (key_file, "Exec");
+ exec = panel_key_file_get_string (launcher->key_file, "Exec");
old_exec = panel_key_file_get_string (revert_key_file, "Exec");
if (!old_exec || !exec || strcmp (old_exec, exec))
- panel_key_file_remove_key (key_file,
+ panel_key_file_remove_key (launcher->key_file,
"StartupNotify");
g_free (exec);
@@ -697,8 +745,7 @@ launcher_save_uri (PanelDItemEditor *dialog,
launcher = (Launcher *) data;
if (launcher) {
- const gchar *location = g_desktop_app_info_get_filename (launcher->app_info);
- new_uri = panel_launcher_find_writable_uri (location,
+ new_uri = panel_launcher_find_writable_uri (launcher->location,
exec_or_uri);
}
else
@@ -721,23 +768,24 @@ launcher_saved (GtkWidget *dialog,
Launcher *launcher)
{
const char *uri;
- gchar *location;
char *filename;
uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
filename = panel_launcher_get_filename(uri);
+ if (filename)
+ uri = filename;
- g_settings_set_string (launcher->info->settings, PANEL_OBJECT_LAUNCHER_LOCATION_KEY, filename);
-
- g_free (filename);
+ if (uri && launcher->location && strcmp (uri, launcher->location)) {
+ g_settings_set_string (launcher->info->settings, PANEL_OBJECT_LAUNCHER_LOCATION_KEY, uri);
- g_object_unref (launcher->app_info);
+ if (launcher->location)
+ g_free (launcher->location);
- location = g_filename_from_uri (uri, NULL, NULL);
- launcher->app_info = g_desktop_app_info_new_from_filename (location);
- g_free (location);
+ launcher->location = g_strdup (uri);
+ }
- setup_button (launcher);
+ if (filename)
+ g_free (filename);
}
static void
@@ -754,8 +802,6 @@ launcher_error_reported (GtkWidget *dialog,
void
launcher_properties (Launcher *launcher)
{
- gchar *uri;
-
if (launcher->prop_dialog != NULL) {
gtk_window_set_screen (GTK_WINDOW (launcher->prop_dialog),
gtk_widget_get_screen (launcher->button));
@@ -763,15 +809,10 @@ launcher_properties (Launcher *launcher)
return;
}
- g_return_if_fail (launcher->app_info != NULL);
-
- const gchar *location = g_desktop_app_info_get_filename (launcher->app_info);
-
- uri = g_filename_to_uri (location, NULL, NULL);
launcher->prop_dialog = panel_ditem_editor_new (NULL,
- uri,
+ launcher->key_file,
+ launcher->location,
_("Launcher Properties"));
- g_free (uri);
panel_widget_register_open_dialog (PANEL_WIDGET
(gtk_widget_get_parent (launcher->info->widget)),
@@ -905,9 +946,13 @@ launcher_new_saved (GtkWidget *dialog,
uri = panel_ditem_editor_get_uri (PANEL_DITEM_EDITOR (dialog));
filename = panel_launcher_get_filename (uri);
- panel_launcher_create (panel->toplevel, pos, filename);
+ if (filename)
+ uri = filename;
- g_free (filename);
+ panel_launcher_create (panel->toplevel, pos, uri);
+
+ if (filename)
+ g_free (filename);
}
void
@@ -922,7 +967,7 @@ ask_about_launcher (const char *file,
if (panel_lockdown_get_disable_command_line ())
return;
- dialog = panel_ditem_editor_new (NULL, NULL,
+ dialog = panel_ditem_editor_new (NULL, NULL, NULL,
_("Create Launcher"));
panel_widget_register_open_dialog (panel, dialog);
@@ -1101,12 +1146,11 @@ find_launcher (const char *path)
launcher = info->data;
- if (launcher->app_info == NULL)
+ if (launcher->key_file == NULL)
continue;
- const gchar *location = g_desktop_app_info_get_filename (launcher->app_info);
- if (location != NULL &&
- strcmp (location, path) == 0)
+ if (launcher->location != NULL &&
+ strcmp (launcher->location, path) == 0)
return launcher;
}