static void thunar_location_entry_activate (GtkWidget *path_entry, ThunarLocationEntry *location_entry) { ThunarFile *file; GError *error = NULL; _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); _thunar_return_if_fail (location_entry->path_entry == path_entry); /* determine the current file from the path entry */ file = thunar_path_entry_get_current_file (THUNAR_PATH_ENTRY (path_entry)); if (G_LIKELY (file != NULL)) { /* check if we have a new directory or a file to launch */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } else { /* try to launch the selected file */ if (!thunar_file_launch (file, path_entry, &error)) { thunar_dialogs_show_error (path_entry, error, _("Failed to launch \"%s\""), thunar_file_get_display_name (file)); g_error_free (error); } /* be sure to reset the current file of the path entry */ if (G_LIKELY (location_entry->current_directory != NULL)) thunar_path_entry_set_current_file (THUNAR_PATH_ENTRY (path_entry), location_entry->current_directory); } } }
static void thunar_chooser_button_activate (ThunarChooserButton *chooser_button, GtkWidget *item) { ThunarVfsMimeApplication *application; ThunarVfsMimeInfo *info; GError *error = NULL; _thunar_return_if_fail (THUNAR_IS_CHOOSER_BUTTON (chooser_button)); _thunar_return_if_fail (GTK_IS_MENU_ITEM (item)); /* verify that we still have a valid file */ if (G_UNLIKELY (chooser_button->file == NULL)) return; /* determine the application that was set for the item */ application = g_object_get_data (G_OBJECT (item), "thunar-vfs-mime-application"); if (G_UNLIKELY (application == NULL)) return; /* determine the mime info for the file */ info = thunar_file_get_mime_info (chooser_button->file); /* try to set application as default for these kind of file */ if (!thunar_vfs_mime_database_set_default_application (chooser_button->database, info, application, &error)) { /* tell the user that it didn't work */ thunar_dialogs_show_error (GTK_WIDGET (chooser_button), error, _("Failed to set default application for \"%s\""), thunar_file_get_display_name (chooser_button->file)); g_error_free (error); } else { /* emit "changed" on the file, so everybody updates its state */ thunar_file_changed (chooser_button->file); } }
static void thunar_location_entry_item_activated (GtkWidget *item, ThunarLocationEntry *location_entry) { ThunarVfsVolume *volume; ThunarFile *file; GtkWidget *window; GError *error = NULL; _thunar_return_if_fail (GTK_IS_MENU_ITEM (item)); _thunar_return_if_fail (THUNAR_IS_LOCATION_ENTRY (location_entry)); /* determine the toplevel window */ window = gtk_widget_get_toplevel (GTK_WIDGET (location_entry)); /* check if the item corresponds to a volume */ volume = g_object_get_data (G_OBJECT (item), "thunar-vfs-volume"); if (G_UNLIKELY (volume != NULL)) { /* check if the volume isn't already mounted */ if (G_LIKELY (!thunar_vfs_volume_is_mounted (volume))) { /* try to mount the volume */ if (!thunar_vfs_volume_mount (volume, window, &error)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to mount \"%s\""), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } /* try to determine the mount point of the volume */ file = thunar_file_get_for_path (thunar_vfs_volume_get_mount_point (volume), &error); if (G_UNLIKELY (file == NULL)) { /* display an error dialog to inform the user */ thunar_dialogs_show_error (window, error, _("Failed to determine the mount point for %s"), thunar_vfs_volume_get_name (volume)); g_error_free (error); return; } } else { /* determine the file from the item */ file = g_object_get_data (G_OBJECT (item), "thunar-file"); if (G_LIKELY (file != NULL)) g_object_ref (G_OBJECT (file)); } /* check if we have a file object now */ if (G_LIKELY (file != NULL)) { /* make sure that this is actually a directory */ if (thunar_file_is_directory (file)) { /* open the new directory */ thunar_navigator_change_directory (THUNAR_NAVIGATOR (location_entry), file); } /* cleanup */ g_object_unref (G_OBJECT (file)); } }
gboolean thunar_dialogs_show_insecure_program (gpointer parent, const gchar *primary, ThunarFile *file, const gchar *command) { GdkScreen *screen; GtkWindow *window; gint response; GtkWidget *dialog; GString *secondary; ThunarFileMode old_mode; ThunarFileMode new_mode; GFileInfo *info; GError *err = NULL; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); _thunar_return_val_if_fail (g_utf8_validate (command, -1, NULL), FALSE); /* parse the parent window and screen */ screen = thunar_util_parse_parent (parent, &window); /* secondary text */ secondary = g_string_new (NULL); g_string_append_printf (secondary, _("The desktop file \"%s\" is in an insecure location " "and not marked as executable. If you do not trust " "this program, click Cancel."), thunar_file_get_display_name (file)); g_string_append (secondary, "\n\n"); if (exo_str_looks_like_an_uri (command)) g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_URL"=%s", command); else g_string_append_printf (secondary, G_KEY_FILE_DESKTOP_KEY_EXEC"=%s", command); /* allocate and display the error message dialog */ dialog = gtk_message_dialog_new (window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "%s", primary); gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Launch Anyway"), GTK_RESPONSE_OK); if (thunar_file_is_chmodable (file)) gtk_dialog_add_button (GTK_DIALOG (dialog), _("Mark _Executable"), GTK_RESPONSE_APPLY); gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); if (screen != NULL && window == NULL) gtk_window_set_screen (GTK_WINDOW (dialog), screen); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", secondary->str); g_string_free (secondary, TRUE); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* check if we should make the file executable */ if (response == GTK_RESPONSE_APPLY) { /* try to query information about the file */ info = g_file_query_info (thunar_file_get_file (file), G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); if (G_LIKELY (info != NULL)) { if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) { /* determine the current mode */ old_mode = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE); /* generate the new mode */ new_mode = old_mode | THUNAR_FILE_MODE_USR_EXEC | THUNAR_FILE_MODE_GRP_EXEC | THUNAR_FILE_MODE_OTH_EXEC; if (old_mode != new_mode) { g_file_set_attribute_uint32 (thunar_file_get_file (file), G_FILE_ATTRIBUTE_UNIX_MODE, new_mode, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); } } else { g_warning ("No %s attribute found", G_FILE_ATTRIBUTE_UNIX_MODE); } g_object_unref (info); } if (err != NULL) { thunar_dialogs_show_error (parent, err, ("Unable to mark launcher executable")); g_error_free (err); } /* just launch */ response = GTK_RESPONSE_OK; } return (response == GTK_RESPONSE_OK); }
/** * thunar_dnd_perform: * @widget : the #GtkWidget on which the drop was done. * @file : the #ThunarFile on which the @file_list was dropped. * @file_list : the list of #GFile<!---->s that was dropped. * @action : the #GdkDragAction that was performed. * @new_files_closure : a #GClosure to connect to the job's "new-files" signal, * which will be emitted when the job finishes with the * list of #GFile<!---->s created by the job, or * %NULL if you're not interested in the signal. * * Performs the drop of @file_list on @file in @widget, as given in * @action and returns %TRUE if the drop was started successfully * (or even completed successfully), else %FALSE. * * Return value: %TRUE if the DnD operation was started * successfully, else %FALSE. **/ gboolean thunar_dnd_perform (GtkWidget *widget, ThunarFile *file, GList *file_list, GdkDragAction action, GClosure *new_files_closure) { ThunarApplication *application; gboolean succeed = TRUE; GError *error = NULL; _thunar_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); _thunar_return_val_if_fail (gtk_widget_get_realized (widget), FALSE); /* query a reference on the application object */ application = thunar_application_get (); /* check if the file is a directory */ if (thunar_file_is_directory (file)) { /* perform the given directory operation */ switch (action) { case GDK_ACTION_COPY: thunar_application_copy_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; case GDK_ACTION_MOVE: thunar_application_move_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; case GDK_ACTION_LINK: thunar_application_link_into (application, widget, file_list, thunar_file_get_file (file), new_files_closure); break; default: succeed = FALSE; } } else if (thunar_file_is_executable (file)) { /* TODO any chance to determine the working dir here? */ succeed = thunar_file_execute (file, NULL, widget, file_list, &error); if (G_UNLIKELY (!succeed)) { /* display an error to the user */ thunar_dialogs_show_error (widget, error, _("Failed to execute file \"%s\""), thunar_file_get_display_name (file)); /* release the error */ g_error_free (error); } } else { succeed = FALSE; } /* release the application reference */ g_object_unref (G_OBJECT (application)); return succeed; }