static void setup_button (Launcher *launcher) { char *comment; char *name; char *str; char *icon; char *unescaped_str; g_return_if_fail (launcher != NULL); 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); else if (!PANEL_GLIB_STR_EMPTY (name)) str = g_strdup (name); else str = g_strdup (comment); g_free (name); g_free (comment); /* If we can unescape the string, then we probably have an escaped * string (a location e.g.). If we can't, then it most probably means * we have a % that is not here to encode a character, and we don't * want to unescape in this case. See bug #170516 for details. */ unescaped_str = g_uri_unescape_string (str, NULL); if (unescaped_str) { g_free (str); str = unescaped_str; } panel_util_set_tooltip_text (launcher->button, str); /* Setup accessible name */ panel_a11y_set_atk_name_desc (launcher->button, str, NULL); g_free (str); /* Setup icon */ icon = panel_key_file_get_locale_string (launcher->key_file, "Icon"); if (icon && icon[0] == '\0') { g_free (icon); icon = NULL; } if (!icon) icon = guess_icon_from_exec (button_widget_get_icon_theme (BUTTON_WIDGET (launcher->button)), launcher->key_file); if (!icon) icon = g_strdup (PANEL_ICON_LAUNCHER); button_widget_set_icon_name (BUTTON_WIDGET (launcher->button), icon); g_free (icon); }
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); }