char * guess_icon_from_exec (GtkIconTheme *icon_theme, GKeyFile *key_file) { char *exec; char *icon_name; char *path; exec = panel_key_file_get_string (key_file, "Exec"); if (!exec || !exec [0]) { g_free (exec); return NULL; } icon_name = g_path_get_basename (exec); g_free (exec); path = panel_find_icon (icon_theme, icon_name, 48); if (!path) { g_free (icon_name); return NULL; } return icon_name; }
void launcher_launch (Launcher *launcher, GtkWidget *widget) { char *type; g_return_if_fail (launcher != NULL); g_return_if_fail (launcher->key_file != NULL); launcher_do_zoom_animation (widget); type = panel_key_file_get_string (launcher->key_file, "Type"); if (type && !strcmp (type, "Link")) launch_url (launcher); else { GError *error = NULL; panel_launch_key_file (launcher->key_file, NULL, launcher_get_screen (launcher), &error); if (error) { GtkWidget *error_dialog; error_dialog = panel_error_dialog ( NULL, launcher_get_screen (launcher), "cannot_launch_application", TRUE, _("Could not launch application"), error->message); launcher_register_error_dialog (launcher, error_dialog); g_clear_error (&error); } } g_free (type); }
static void launch_url (Launcher *launcher) { char *url; GdkScreen *screen; g_return_if_fail (launcher != NULL); g_return_if_fail (launcher->key_file != NULL); /* FIXME panel_ditem_launch() should be enough for this! */ url = panel_key_file_get_string (launcher->key_file, "URL"); screen = launcher_get_screen (launcher); if (!url || *url == 0) { GtkWidget *error_dialog; error_dialog = panel_error_dialog (NULL, screen, "no_url_dialog", TRUE, _("Could not show this URL"), _("No URL was specified.")); launcher_register_error_dialog (launcher, error_dialog); g_free (url); return; } panel_show_uri (screen, url, gtk_get_current_event_time (), NULL); g_free (url); }
static char * launcher_save_uri (PanelDItemEditor *dialog, gpointer data) { GKeyFile *key_file; char *type; char *exec_or_uri; Launcher *launcher; char *new_uri; const char *uri; key_file = panel_ditem_editor_get_key_file (dialog); type = panel_key_file_get_string (key_file, "Type"); if (type && !strcmp (type, "Application")) exec_or_uri = panel_key_file_get_string (key_file, "Exec"); else if (type && !strcmp (type, "Link")) exec_or_uri = panel_key_file_get_string (key_file, "URL"); else exec_or_uri = panel_key_file_get_string (key_file, "Name"); g_free (type); launcher = (Launcher *) data; if (launcher) new_uri = panel_launcher_find_writable_uri (launcher->location, exec_or_uri); else new_uri = panel_launcher_find_writable_uri (NULL, exec_or_uri); g_free (exec_or_uri); uri = panel_ditem_editor_get_uri (dialog); if (!uri || (new_uri && strcmp (new_uri, uri))) return new_uri; g_free (new_uri); return NULL; }
static void launcher_command_changed (PanelDItemEditor *dialog, const char *command, Launcher *launcher) { char *exec; char *old_exec; GKeyFile *revert_key_file; revert_key_file = panel_ditem_editor_get_revert_key_file (dialog); if (revert_key_file) { 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 (launcher->key_file, "StartupNotify"); g_free (exec); g_free (old_exec); } }
void panel_key_file_ensure_C_key (GKeyFile *keyfile, const char *key) { char *C_value; char *buffer; /* Make sure we set the "C" locale strings to the terms we set here. * This is so that if the user logs into another locale they get their * own description there rather then empty. It is not the C locale * however, but the user created this entry herself so it's OK */ C_value = panel_key_file_get_string (keyfile, key); if (C_value == NULL || C_value [0] == '\0') { buffer = panel_key_file_get_locale_string (keyfile, key); if (buffer) { panel_key_file_set_string (keyfile, key, buffer); g_free (buffer); } } g_free (C_value); }
static void panel_menu_items_append_from_desktop (GtkWidget *menu, char *path, char *force_name, gboolean use_icon) { GKeyFile *key_file; gboolean loaded; GtkWidget *item; char *path_freeme; char *full_path; char *uri; char *type; gboolean is_application; char *tryexec; char *icon; char *name; char *comment; path_freeme = NULL; key_file = g_key_file_new (); if (g_path_is_absolute (path)) { loaded = g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL); full_path = path; } else { char *lookup_file; char *desktop_path; if (!g_str_has_suffix (path, ".desktop")) { desktop_path = g_strconcat (path, ".desktop", NULL); } else { desktop_path = path; } lookup_file = g_strconcat ("applications", G_DIR_SEPARATOR_S, desktop_path, NULL); loaded = g_key_file_load_from_data_dirs (key_file, lookup_file, &path_freeme, G_KEY_FILE_NONE, NULL); full_path = path_freeme; g_free (lookup_file); if (desktop_path != path) g_free (desktop_path); } if (!loaded) { g_key_file_free (key_file); if (path_freeme) g_free (path_freeme); return; } /* For Application desktop files, respect TryExec */ type = panel_key_file_get_string (key_file, "Type"); if (!type) { g_key_file_free (key_file); if (path_freeme) g_free (path_freeme); return; } is_application = (strcmp (type, "Application") == 0); g_free (type); if (is_application) { tryexec = panel_key_file_get_string (key_file, "TryExec"); if (tryexec) { char *prog; prog = g_find_program_in_path (tryexec); g_free (tryexec); if (!prog) { /* FIXME: we could add some file monitor magic, * so that the menu items appears when the * program appears, but that's really complex * for not a huge benefit */ g_key_file_free (key_file); if (path_freeme) g_free (path_freeme); return; } g_free (prog); } } /* Now, simply build the menu item */ icon = panel_key_file_get_locale_string (key_file, "Icon"); comment = panel_key_file_get_locale_string (key_file, "Comment"); if (PANEL_GLIB_STR_EMPTY (force_name)) name = panel_key_file_get_locale_string (key_file, "Name"); else name = g_strdup (force_name); if (use_icon) { item = panel_image_menu_item_new (); } else { item = gtk_image_menu_item_new (); } setup_menu_item_with_icon (item, panel_menu_icon_get_size (), icon, NULL, NULL, name); panel_util_set_tooltip_text (item, comment); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); g_signal_connect_data (item, "activate", G_CALLBACK (panel_menu_item_activate_desktop_file), g_strdup (full_path), (GClosureNotify) g_free, 0); g_signal_connect (G_OBJECT (item), "button_press_event", G_CALLBACK (menu_dummy_button_press_event), NULL); uri = g_filename_to_uri (full_path, NULL, NULL); setup_uri_drag (item, uri, icon, GDK_ACTION_COPY); g_free (uri); g_key_file_free (key_file); if (icon) g_free (icon); if (name) g_free (name); if (comment) g_free (comment); if (path_freeme) g_free (path_freeme); }
static void program_list_selection_changed (GtkTreeSelection *selection, PanelRunDialog *dialog) { GtkTreeModel *filter_model; GtkTreeModel *child_model; GtkTreeIter iter; GtkTreeIter filter_iter; char *temp; char *path, *stripped; gboolean terminal; GKeyFile *key_file; GtkWidget *entry; if (!gtk_tree_selection_get_selected (selection, &filter_model, &filter_iter)) return; gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (filter_model), &iter, &filter_iter); path = NULL; child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model)); gtk_tree_model_get (child_model, &iter, COLUMN_PATH, &path, -1); if (!path) return; key_file = g_key_file_new (); if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL)) { g_key_file_free (key_file); g_free (path); return; } dialog->use_program_list = TRUE; if (dialog->desktop_path) g_free (dialog->desktop_path); dialog->desktop_path = g_strdup (path); if (dialog->item_name) g_free (dialog->item_name); dialog->item_name = NULL; /* Order is important here. We have to set the text first so that the * drag source is enabled, otherwise the drag icon can't be set by * panel_run_dialog_set_icon. */ entry = gtk_bin_get_child (GTK_BIN (dialog->combobox)); temp = panel_key_file_get_string (key_file, "Exec"); if (temp) { stripped = remove_parameters (temp); gtk_entry_set_text (GTK_ENTRY (entry), stripped); g_free (stripped); } else { temp = panel_key_file_get_string (key_file, "URL"); gtk_entry_set_text (GTK_ENTRY (entry), sure_string (temp)); } g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Icon"); GIcon *icon = panel_gicon_from_icon_name (temp); panel_run_dialog_set_icon (dialog, icon, FALSE); g_object_unref (icon); g_free (temp); temp = panel_key_file_get_locale_string (key_file, "Comment"); //FIXME: if sure_string () == "", we should display "Will run..." as in entry_changed() gtk_label_set_text (GTK_LABEL (dialog->program_label), sure_string (temp)); g_free (temp); terminal = panel_key_file_get_boolean (key_file, "Terminal", FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox), terminal); g_key_file_free (key_file); g_free (path); }