static char * panel_launcher_find_writable_uri (const char *launcher_location, const char *source) { char *path; char *uri; if (!launcher_location) return panel_make_unique_desktop_uri (NULL, source); if (!strchr (launcher_location, G_DIR_SEPARATOR)) { path = panel_make_full_path (NULL, launcher_location); uri = g_filename_to_uri (path, NULL, NULL); g_free (path); return uri; } if (panel_launcher_get_filename (launcher_location) != NULL) { /* we have a file in the user directory. We either have a path * or an URI */ if (g_path_is_absolute (launcher_location)) return g_filename_to_uri (launcher_location, NULL, NULL); else return g_strdup (launcher_location); } return panel_make_unique_desktop_uri (NULL, source); }
gboolean panel_launcher_create_copy (PanelToplevel *toplevel, PanelObjectPackType pack_type, int pack_index, const char *location) { char *new_location; GFile *source; GFile *dest; gboolean copied; const char *filename; new_location = panel_make_unique_desktop_uri (NULL, location); source = panel_launcher_get_gfile (location); dest = g_file_new_for_uri (new_location); copied = g_file_copy (source, dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); if (!copied) { g_free (new_location); return FALSE; } filename = panel_launcher_get_filename (new_location); panel_launcher_create (toplevel, pack_type, pack_index, filename); g_free (new_location); return TRUE; }
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 void add_app_to_desktop (GtkWidget *item, MateMenuTreeEntry *entry) { char *source_uri; const char *source; char *target_dir; char *target_uri; char *target; GError *error; g_return_if_fail (entry != NULL); if (desktop_is_home_dir ()) { target_dir = g_build_filename (g_get_home_dir (), NULL); } else { target_dir = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)); } source = matemenu_tree_entry_get_desktop_file_path (entry); source_uri = g_filename_to_uri (source, NULL, NULL); target_uri = panel_make_unique_desktop_uri (target_dir, source_uri); g_free (target_dir); g_free (source_uri); g_return_if_fail (target_uri != NULL); target = g_filename_from_uri (target_uri, NULL, NULL); g_free (target_uri); error = NULL; panel_key_file_copy_and_mark_trusted (source, target, &error); g_free (target); if (error != NULL) { g_warning ("Problem while copying launcher to desktop: %s", error->message); g_error_free (error); } }
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; }