filechooserDialog::filechooserDialog ( Gtk::Window& parent, const Glib::ustring& title, Gtk::FileChooserAction action, Glib::ustring currentFolder, bool multipleSelection, unsigned int mimeType ) : Gtk::FileChooserDialog (parent, title, action) { // append filechooser buttons and linked events add_button ( Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL ); add_button ( Gtk::Stock::OK, Gtk::RESPONSE_OK ); // set the path to folder of the application as current folder set_current_folder(currentFolder); // Allow the selection of several files set_select_multiple(multipleSelection); // ask confirmation before overwrite an existing file if (action == Gtk::FILE_CHOOSER_ACTION_SAVE) set_do_overwrite_confirmation(true); // mime type file filter setFilters(mimeType); // run the filechooser and grab the result response = run(); // alert dialog if (action != Gtk::FILE_CHOOSER_ACTION_SAVE) { if (response == Gtk::RESPONSE_OK and !genericFeatures::fileExists(get_filename())) { genericAlertWindow * AC = new genericAlertWindow ( *this, "File error" , "The file you are trying to open does not exist" ); delete AC; } } }
static void get_folder_content_done_cb (GError *error, gpointer user_data) { LoadData *load_data = user_data; FrFileSelectorDialog *self = load_data->dialog; GtkListStore *list_store; GList *scan; GtkTreeIter iter; GDateTime *today; int sort_column_id; GtkSortType sort_order; GHashTable *selected_files; if (error != NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) { GMountOperation *operation; operation = gtk_mount_operation_new (GTK_WINDOW (self)); g_file_mount_enclosing_volume (load_data->folder, G_MOUNT_MOUNT_NONE, operation, load_data->cancellable, folder_mount_enclosing_volume_ready_cb, load_data); g_object_unref (operation); return; } if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) _gtk_error_dialog_run (GTK_WINDOW (self), _("Could not load the location"), "%s", error->message); if (load_data->dialog->priv->current_operation == load_data) load_data->dialog->priv->current_operation = NULL; load_data_free (load_data); return; } load_data->files = g_list_reverse (load_data->files); today = g_date_time_new_now_local (); gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), &sort_column_id, &sort_order); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, 0); selected_files = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal); for (scan = load_data->files_to_select; scan; scan = scan->next) g_hash_table_insert(selected_files, scan->data, GINT_TO_POINTER (1)); list_store = GTK_LIST_STORE (GET_WIDGET ("files_liststore")); gtk_list_store_clear (list_store); for (scan = load_data->files; scan; scan = scan->next) { FileInfo *file_info = scan->data; GdkPixbuf *icon_pixbuf; char *size; GTimeVal timeval; GDateTime *datetime; char *modified; char *collate_key; gboolean is_folder; if (! self->priv->show_hidden && g_file_info_get_is_hidden (file_info->info)) continue; gtk_list_store_append (list_store, &iter); icon_pixbuf = gth_icon_cache_get_pixbuf (self->priv->icon_cache, g_file_info_get_icon (file_info->info)); size = g_format_size (g_file_info_get_size (file_info->info)); g_file_info_get_modification_time (file_info->info, &timeval); datetime = g_date_time_new_from_timeval_local (&timeval); modified = g_date_time_format (datetime, _g_date_time_same_day (datetime, today) ? "%X" : "%x"); collate_key = g_utf8_collate_key_for_filename (g_file_info_get_display_name (file_info->info), -1); is_folder = (g_file_info_get_file_type (file_info->info) == G_FILE_TYPE_DIRECTORY); gtk_list_store_set (list_store, &iter, FILE_LIST_COLUMN_ICON, icon_pixbuf, FILE_LIST_COLUMN_NAME, g_file_info_get_display_name (file_info->info), FILE_LIST_COLUMN_SIZE, (is_folder ? "" : size), FILE_LIST_COLUMN_MODIFIED, modified, FILE_LIST_COLUMN_FILE, file_info->file, FILE_LIST_COLUMN_NAME_ORDER, collate_key, FILE_LIST_COLUMN_SIZE_ORDER, g_file_info_get_size (file_info->info), FILE_LIST_COLUMN_MODIFIED_ORDER, timeval.tv_sec, FILE_LIST_COLUMN_IS_FOLDER, is_folder, FILE_LIST_COLUMN_IS_SELECTED, (g_hash_table_lookup (selected_files, file_info->file) != NULL), -1); g_free (collate_key); g_free (modified); g_date_time_unref (datetime); g_free (size); _g_object_unref (icon_pixbuf); } gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("files_liststore")), sort_column_id, sort_order); set_current_folder (self, load_data->folder); if (load_data->dialog->priv->current_operation == load_data) load_data->dialog->priv->current_operation = NULL; g_hash_table_unref (selected_files); g_date_time_unref (today); load_data_free (load_data); }