void panel_launcher_create_from_info (PanelToplevel *toplevel, PanelObjectPackType pack_type, int pack_index, gboolean exec_info, const char *exec_or_uri, const char *name, const char *comment, const char *icon) { GKeyFile *key_file; char *location; GError *error; key_file = panel_key_file_new_desktop (); /* set current language and the "C" locale to this name, * this is kind of evil... */ panel_key_file_set_string (key_file, "Name", name); panel_key_file_set_string (key_file, "Comment", comment); panel_key_file_set_string (key_file, "Icon", icon); panel_key_file_set_locale_string (key_file, "Name", name); panel_key_file_set_locale_string (key_file, "Comment", comment); panel_key_file_set_locale_string (key_file, "Icon", icon); if (exec_info) { panel_key_file_set_string (key_file, "Exec", exec_or_uri); panel_key_file_set_string (key_file, "Type", "Application"); } else { panel_key_file_set_string (key_file, "URL", exec_or_uri); panel_key_file_set_string (key_file, "Type", "Link"); } location = panel_make_unique_desktop_uri (NULL, exec_or_uri); error = NULL; if (panel_key_file_to_file (key_file, location, &error)) { panel_launcher_create (toplevel, pack_type, pack_index, location); } else { panel_error_dialog (GTK_WINDOW (toplevel), gtk_window_get_screen (GTK_WINDOW (toplevel)), "cannot_save_launcher", TRUE, _("Could not save launcher"), error->message); g_error_free (error); } g_key_file_free (key_file); }
static char * panel_run_dialog_create_desktop_file (PanelRunDialog *dialog) { GKeyFile *key_file; gboolean exec = FALSE; char *text; char *name; char *disk; char *scheme; char *save_uri; text = g_strdup (panel_run_dialog_get_combo_text (dialog)); if (!text || !text [0]) { g_free (text); return NULL; } key_file = panel_key_file_new_desktop (); disk = g_locale_from_utf8 (text, -1, NULL, NULL, NULL); scheme = g_uri_parse_scheme (disk); /* if it's an absolute path or not a URI, it's possibly an executable */ if (g_path_is_absolute (disk) || !scheme) exec = command_is_executable (disk, NULL, NULL); g_free (scheme); if (exec) { panel_key_file_set_string (key_file, "Type", "Application"); panel_key_file_set_string (key_file, "Exec", text); name = g_strdup (text); } else { GFile *file; char *uri; file = panel_util_get_file_optional_homedir (disk); uri = g_file_get_uri (file); g_object_unref (file); panel_key_file_set_string (key_file, "Type", "Link"); panel_key_file_set_string (key_file, "URL", uri); name = uri; } g_free (disk); panel_key_file_set_locale_string (key_file, "Name", (dialog->item_name) ? dialog->item_name : text); panel_key_file_set_boolean (key_file, "Terminal", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->terminal_checkbox))); if (dialog->icon) { gchar *icon_path = g_icon_to_string (dialog->icon); panel_key_file_set_locale_string (key_file, "Icon", icon_path); g_free (icon_path); } else panel_key_file_set_locale_string (key_file, "Icon", PANEL_ICON_LAUNCHER); save_uri = panel_make_unique_desktop_uri (g_get_tmp_dir (), name); disk = g_filename_from_uri (save_uri, NULL, NULL); if (!disk || !panel_key_file_to_file (key_file, disk, NULL)) { g_free (save_uri); save_uri = NULL; } g_key_file_free (key_file); g_free (disk); g_free (name); g_free (text); return save_uri; }