diff --git a/thunar/Makefile.am b/thunar/Makefile.am index ed622ec55635c9ea07bdd8fed0e62fdbbcf1cf41..fda98a72e15d61c8692b00a7c71758b863bf744d 100644 --- a/thunar/Makefile.am +++ b/thunar/Makefile.am @@ -186,6 +186,8 @@ thunar_SOURCES = \ thunar-size-label.h \ thunar-standard-view.c \ thunar-standard-view.h \ + thunar-standard-view-model.c \ + thunar-standard-view-model.h \ thunar-statusbar.c \ thunar-statusbar.h \ thunar-toolbar-editor.c \ diff --git a/thunar/thunar-list-model.c b/thunar/thunar-list-model.c index 2ac4d63365b55d79e9f5c1809db138253d6c11cc..f96de2f1e302af47084f5ee04c2c2f60dc76b60a 100644 --- a/thunar/thunar-list-model.c +++ b/thunar/thunar-list-model.c @@ -42,6 +42,7 @@ #include <thunar/thunar-user.h> #include <thunar/thunar-simple-job.h> #include <thunar/thunar-util.h> +#include <thunar/thunar-standard-view-model.h> @@ -61,20 +62,13 @@ enum N_PROPERTIES }; -/* Signal identifiers */ -enum -{ - ERROR, - SEARCH_DONE, - LAST_SIGNAL, -}; - typedef gint (*ThunarSortFunc) (const ThunarFile *a, const ThunarFile *b, gboolean case_sensitive); +static void thunar_list_model_standard_view_model_init (ThunarStandardViewModelIface *iface); static void thunar_list_model_tree_model_init (GtkTreeModelIface *iface); static void thunar_list_model_drag_dest_init (GtkTreeDragDestIface *iface); static void thunar_list_model_sortable_init (GtkTreeSortableIface *iface); @@ -224,7 +218,7 @@ static void thunar_list_model_search_folder (ThunarL ThunarJob *job, gchar *uri, gchar **search_query_c_terms, - enum ThunarListModelSearch search_type, + enum ThunarStandardViewModelSearch search_type, gboolean show_hidden); static void thunar_list_model_cancel_search_job (ThunarListModel *model); static gchar** thunar_list_model_split_search_query (const gchar *search_query, @@ -243,6 +237,31 @@ static void thunar_list_model_set_folder_item_count (ThunarL static void thunar_list_model_file_count_callback (ExoJob *job, gpointer model); +static ThunarFolder *thunar_list_model_get_folder (ThunarStandardViewModel *store); +static void thunar_list_model_set_folder (ThunarStandardViewModel *store, + ThunarFolder *folder, + gchar *search_query); +static void thunar_list_model_set_folders_first (ThunarStandardViewModel *store, + gboolean folders_first); +static gboolean thunar_list_model_get_show_hidden (ThunarStandardViewModel *store); +static void thunar_list_model_set_show_hidden (ThunarStandardViewModel *store, + gboolean show_hidden); +static gboolean thunar_list_model_get_file_size_binary (ThunarStandardViewModel *store); +static void thunar_list_model_set_file_size_binary (ThunarStandardViewModel *store, + gboolean file_size_binary); +static ThunarFile *thunar_list_model_get_file (ThunarStandardViewModel *store, + GtkTreeIter *iter); +static GList *thunar_list_model_get_paths_for_files (ThunarStandardViewModel *store, + GList *files); +static GList *thunar_list_model_get_paths_for_pattern (ThunarStandardViewModel *store, + const gchar *pattern, + gboolean case_sensitive, + gboolean match_diacritics); +static gchar *thunar_list_model_get_statusbar_text (ThunarStandardViewModel *store, + GList *selected_items); +static ThunarJob *thunar_list_model_get_job (ThunarStandardViewModel *store); +static void thunar_list_model_set_job (ThunarStandardViewModel *store, + ThunarJob *job); struct _ThunarListModelClass { @@ -313,7 +332,7 @@ struct _ThunarListModel -static guint list_model_signals[LAST_SIGNAL]; +static guint list_model_signals[THUNAR_STANDARD_VIEW_MODEL_LAST_SIGNAL]; static GParamSpec *list_model_props[N_PROPERTIES] = { NULL, }; @@ -321,7 +340,8 @@ static GParamSpec *list_model_props[N_PROPERTIES] = { NULL, }; G_DEFINE_TYPE_WITH_CODE (ThunarListModel, thunar_list_model, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, thunar_list_model_tree_model_init) G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_DEST, thunar_list_model_drag_dest_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE, thunar_list_model_sortable_init)) + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE, thunar_list_model_sortable_init) + G_IMPLEMENT_INTERFACE (THUNAR_TYPE_STANDARD_VIEW_MODEL, thunar_list_model_standard_view_model_init)) @@ -448,39 +468,26 @@ thunar_list_model_class_init (ThunarListModelClass *klass) /* install properties */ g_object_class_install_properties (gobject_class, N_PROPERTIES, list_model_props); +} - /** - * ThunarListModel::error: - * @store : a #ThunarListModel. - * @error : a #GError that describes the problem. - * - * Emitted when an error occurs while loading the - * @store content. - **/ - list_model_signals[ERROR] = - g_signal_new (I_("error"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ThunarListModelClass, error), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, G_TYPE_POINTER); - /** - * ThunarListModel::search-done: - * @store : a #ThunarListModel. - * @error : a #GError that describes the problem. - * - * Emitted when a recursive search finishes. - **/ - list_model_signals[SEARCH_DONE] = - g_signal_new (I_("search-done"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ThunarListModelClass, search_done), - NULL, NULL, - NULL, - G_TYPE_NONE, 0); + +static void +thunar_list_model_standard_view_model_init (ThunarStandardViewModelIface *iface) +{ + iface->get_job = thunar_list_model_get_job; + iface->set_job = thunar_list_model_set_job; + iface->get_file = thunar_list_model_get_file; + iface->get_folder = thunar_list_model_get_folder; + iface->set_folder = thunar_list_model_set_folder; + iface->get_show_hidden = thunar_list_model_get_show_hidden; + iface->set_show_hidden = thunar_list_model_set_show_hidden; + iface->get_paths_for_files = thunar_list_model_get_paths_for_files; + iface->get_paths_for_pattern = thunar_list_model_get_paths_for_pattern; + iface->get_file_size_binary = thunar_list_model_get_file_size_binary; + iface->set_file_size_binary = thunar_list_model_set_file_size_binary; + iface->set_folders_first = thunar_list_model_set_folders_first; + iface->get_statusbar_text = thunar_list_model_get_statusbar_text; } @@ -559,7 +566,7 @@ static void thunar_list_model_dispose (GObject *object) { /* unlink from the folder (if any) */ - thunar_list_model_set_folder (THUNAR_LIST_MODEL (object), NULL, NULL); + thunar_list_model_set_folder (THUNAR_STANDARD_VIEW_MODEL (object), NULL, NULL); (*G_OBJECT_CLASS (thunar_list_model_parent_class)->dispose) (object); } @@ -620,7 +627,7 @@ thunar_list_model_get_property (GObject *object, break; case PROP_FOLDER: - g_value_set_object (value, thunar_list_model_get_folder (store)); + g_value_set_object (value, thunar_list_model_get_folder (THUNAR_STANDARD_VIEW_MODEL (store))); break; case PROP_FOLDERS_FIRST: @@ -632,11 +639,11 @@ thunar_list_model_get_property (GObject *object, break; case PROP_SHOW_HIDDEN: - g_value_set_boolean (value, thunar_list_model_get_show_hidden (store)); + g_value_set_boolean (value, thunar_list_model_get_show_hidden (THUNAR_STANDARD_VIEW_MODEL (store))); break; case PROP_FILE_SIZE_BINARY: - g_value_set_boolean (value, thunar_list_model_get_file_size_binary (store)); + g_value_set_boolean (value, thunar_list_model_get_file_size_binary THUNAR_STANDARD_VIEW_MODEL (store)); break; case PROP_FOLDER_ITEM_COUNT: @@ -674,19 +681,19 @@ thunar_list_model_set_property (GObject *object, break; case PROP_FOLDER: - thunar_list_model_set_folder (store, g_value_get_object (value), NULL); + thunar_list_model_set_folder (THUNAR_STANDARD_VIEW_MODEL (store), g_value_get_object (value), NULL); break; case PROP_FOLDERS_FIRST: - thunar_list_model_set_folders_first (store, g_value_get_boolean (value)); + thunar_list_model_set_folders_first (THUNAR_STANDARD_VIEW_MODEL (store), g_value_get_boolean (value)); break; case PROP_SHOW_HIDDEN: - thunar_list_model_set_show_hidden (store, g_value_get_boolean (value)); + thunar_list_model_set_show_hidden (THUNAR_STANDARD_VIEW_MODEL (store), g_value_get_boolean (value)); break; case PROP_FILE_SIZE_BINARY: - thunar_list_model_set_file_size_binary (store, g_value_get_boolean (value)); + thunar_list_model_set_file_size_binary (THUNAR_STANDARD_VIEW_MODEL (store), g_value_get_boolean (value)); break; case PROP_FOLDER_ITEM_COUNT: @@ -1514,7 +1521,7 @@ thunar_list_model_folder_destroy (ThunarFolder *folder, _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); _thunar_return_if_fail (THUNAR_IS_FOLDER (folder)); - thunar_list_model_set_folder (store, NULL, NULL); + thunar_list_model_set_folder (THUNAR_STANDARD_VIEW_MODEL (store), NULL, NULL); /* TODO: What to do when the folder is deleted? */ } @@ -1531,10 +1538,10 @@ thunar_list_model_folder_error (ThunarFolder *folder, _thunar_return_if_fail (error != NULL); /* reset the current folder */ - thunar_list_model_set_folder (store, NULL, NULL); + thunar_list_model_set_folder (THUNAR_STANDARD_VIEW_MODEL (store), NULL, NULL); /* forward the error signal */ - g_signal_emit (G_OBJECT (store), list_model_signals[ERROR], 0, error); + g_signal_emit (G_OBJECT (store), list_model_signals[THUNAR_STANDARD_VIEW_MODEL_ERROR], 0, error); } @@ -2072,7 +2079,7 @@ sort_by_type (const ThunarFile *a, * * Return value: the newly allocated #ThunarListModel. **/ -ThunarListModel* +ThunarStandardViewModel* thunar_list_model_new (void) { return g_object_new (THUNAR_TYPE_LIST_MODEL, NULL); @@ -2234,18 +2241,20 @@ thunar_list_model_set_date_custom_style (ThunarListModel *store, -ThunarJob* -thunar_list_model_get_job (ThunarListModel *store) +static ThunarJob* +thunar_list_model_get_job (ThunarStandardViewModel *model) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); return store->recursive_search_job; } -void -thunar_list_model_set_job (ThunarListModel *store, +static void +thunar_list_model_set_job (ThunarStandardViewModel *model, ThunarJob *job) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); store->recursive_search_job = job; } @@ -2336,10 +2345,10 @@ _thunar_job_search_directory (ThunarJob *job, ThunarPreferences *preferences; gboolean is_source_device_local; ThunarRecursiveSearchMode mode; - enum ThunarListModelSearch search_type; + enum ThunarStandardViewModelSearch search_type; gboolean show_hidden; - search_type = THUNAR_LIST_MODEL_SEARCH_NON_RECURSIVE; + search_type = THUNAR_STANDARD_VIEW_MODEL_SEARCH_NON_RECURSIVE; /* grab a reference on the preferences */ preferences = thunar_preferences_get (); @@ -2363,7 +2372,7 @@ _thunar_job_search_directory (ThunarJob *job, is_source_device_local = thunar_g_file_is_on_local_device (thunar_file_get_file (directory)); if (mode == THUNAR_RECURSIVE_SEARCH_ALWAYS || (mode == THUNAR_RECURSIVE_SEARCH_LOCAL && is_source_device_local)) - search_type = THUNAR_LIST_MODEL_SEARCH_RECURSIVE; + search_type = THUNAR_STANDARD_VIEW_MODEL_SEARCH_RECURSIVE; thunar_list_model_search_folder (model, job, thunar_file_dup_uri (directory), search_query_c_terms, search_type, show_hidden); @@ -2442,7 +2451,7 @@ thunar_list_model_search_folder (ThunarListModel *model, ThunarJob *job, gchar *uri, gchar **search_query_c_terms, - enum ThunarListModelSearch search_type, + enum ThunarStandardViewModelSearch search_type, gboolean show_hidden) { GCancellable *cancellable; @@ -2511,7 +2520,7 @@ thunar_list_model_search_folder (ThunarListModel *model, type = g_file_info_get_file_type (info); /* handle directories */ - if (type == G_FILE_TYPE_DIRECTORY && search_type == THUNAR_LIST_MODEL_SEARCH_RECURSIVE) + if (type == G_FILE_TYPE_DIRECTORY && search_type == THUNAR_STANDARD_VIEW_MODEL_SEARCH_RECURSIVE) { thunar_list_model_search_folder (model, job, g_file_get_uri (file), search_query_c_terms, search_type, show_hidden); } @@ -2550,9 +2559,10 @@ thunar_list_model_search_folder (ThunarListModel *model, * Return value: the #ThunarFolder @store is associated with * or %NULL if @store has no folder. **/ -ThunarFolder* -thunar_list_model_get_folder (ThunarListModel *store) +static ThunarFolder* +thunar_list_model_get_folder (ThunarStandardViewModel *model) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), NULL); return store->folder; } @@ -2565,11 +2575,12 @@ thunar_list_model_get_folder (ThunarListModel *store) * @folder : a #ThunarFolder or %NULL. * @search_query : a #string or %NULL. **/ -void -thunar_list_model_set_folder (ThunarListModel *store, +static void +thunar_list_model_set_folder (ThunarStandardViewModel *model, ThunarFolder *folder, gchar *search_query) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); GtkTreePath *path; gboolean has_handler; GList *files; @@ -2722,10 +2733,11 @@ thunar_list_model_get_folders_first (ThunarListModel *store) * @store : a #ThunarListModel. * @folders_first : %TRUE to let @store list folders first. **/ -void -thunar_list_model_set_folders_first (ThunarListModel *store, +static void +thunar_list_model_set_folders_first (ThunarStandardViewModel *model, gboolean folders_first) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); /* check if the new setting differs */ @@ -2753,9 +2765,10 @@ thunar_list_model_set_folders_first (ThunarListModel *store, * * Return value: %TRUE if hidden files will be shown, else %FALSE. **/ -gboolean -thunar_list_model_get_show_hidden (ThunarListModel *store) +static gboolean +thunar_list_model_get_show_hidden (ThunarStandardViewModel *model) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); return store->show_hidden; } @@ -2767,10 +2780,11 @@ thunar_list_model_get_show_hidden (ThunarListModel *store) * @store : a #ThunarListModel. * @show_hidden : %TRUE if hidden files should be shown, else %FALSE. **/ -void -thunar_list_model_set_show_hidden (ThunarListModel *store, +static void +thunar_list_model_set_show_hidden (ThunarStandardViewModel *model, gboolean show_hidden) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); GtkTreePath *path; GtkTreeIter iter; ThunarFile *file; @@ -2859,9 +2873,10 @@ thunar_list_model_set_show_hidden (ThunarListModel *store, * * Return value: %TRUE if file size format is binary. **/ -gboolean -thunar_list_model_get_file_size_binary (ThunarListModel *store) +static gboolean +thunar_list_model_get_file_size_binary (ThunarStandardViewModel *model) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), FALSE); return store->file_size_binary; } @@ -2876,10 +2891,11 @@ thunar_list_model_get_file_size_binary (ThunarListModel *store) * If @file_size_binary is %TRUE the file size should be * formatted as binary. **/ -void -thunar_list_model_set_file_size_binary (ThunarListModel *store, +static void +thunar_list_model_set_file_size_binary (ThunarStandardViewModel *model, gboolean file_size_binary) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (store)); /* normalize the setting */ @@ -2963,10 +2979,11 @@ thunar_list_model_set_folder_item_count (ThunarListModel *store, * * Return value: the #ThunarFile. **/ -ThunarFile* -thunar_list_model_get_file (ThunarListModel *store, +static ThunarFile* +thunar_list_model_get_file (ThunarStandardViewModel *model, GtkTreeIter *iter) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); _thunar_return_val_if_fail (THUNAR_IS_LIST_MODEL (store), NULL); _thunar_return_val_if_fail (iter->stamp == store->stamp, NULL); @@ -3011,10 +3028,11 @@ thunar_list_model_get_num_files (ThunarListModel *store) * * Return value: the list of #GtkTreePath<!---->s for @files. **/ -GList* -thunar_list_model_get_paths_for_files (ThunarListModel *store, +static GList* +thunar_list_model_get_paths_for_files (ThunarStandardViewModel *model, GList *files) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); GList *paths = NULL; GSequenceIter *row; GSequenceIter *end; @@ -3060,12 +3078,13 @@ thunar_list_model_get_paths_for_files (ThunarListModel *store, * * Return value: the list of #GtkTreePath<!---->s that match @pattern. **/ -GList* -thunar_list_model_get_paths_for_pattern (ThunarListModel *store, +static GList* +thunar_list_model_get_paths_for_pattern (ThunarStandardViewModel *model, const gchar *pattern, gboolean case_sensitive, gboolean match_diacritics) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); GPatternSpec *pspec; gchar *normalized_pattern; GList *paths = NULL; @@ -3248,10 +3267,11 @@ thunar_list_model_get_statusbar_text_for_files (ThunarListModel *store, * Return value: the statusbar text for @store with the given * @selected_items. **/ -gchar* -thunar_list_model_get_statusbar_text (ThunarListModel *store, +static gchar* +thunar_list_model_get_statusbar_text (ThunarStandardViewModel *model, GList *selected_items) { + ThunarListModel *store = THUNAR_LIST_MODEL (model); const gchar *content_type; const gchar *original_path; GtkTreeIter iter; @@ -3281,7 +3301,7 @@ thunar_list_model_get_statusbar_text (ThunarListModel *store, show_filetype = thunar_status_bar_info_check_active (active, THUNAR_STATUS_BAR_INFO_FILETYPE); show_display_name = thunar_status_bar_info_check_active (active, THUNAR_STATUS_BAR_INFO_DISPLAY_NAME); show_last_modified = thunar_status_bar_info_check_active (active, THUNAR_STATUS_BAR_INFO_LAST_MODIFIED); - show_file_size_binary_format = thunar_list_model_get_file_size_binary(store); + show_file_size_binary_format = thunar_list_model_get_file_size_binary(model); if (selected_items == NULL) /* nothing selected */ { diff --git a/thunar/thunar-list-model.h b/thunar/thunar-list-model.h index f20907f205ddb16f56874f14d0546b703e64fdb1..e010b3f538194e5df4da02a2858cbbab7d5433ec 100644 --- a/thunar/thunar-list-model.h +++ b/thunar/thunar-list-model.h @@ -20,20 +20,13 @@ #ifndef __THUNAR_LIST_MODEL_H__ #define __THUNAR_LIST_MODEL_H__ -#include <thunar/thunar-folder.h> -#include <thunar/thunar-job.h> +#include <thunar/thunar-standard-view-model.h> G_BEGIN_DECLS; typedef struct _ThunarListModelClass ThunarListModelClass; typedef struct _ThunarListModel ThunarListModel; -typedef enum ThunarListModelSearch -{ - THUNAR_LIST_MODEL_SEARCH_RECURSIVE, - THUNAR_LIST_MODEL_SEARCH_NON_RECURSIVE -} ThunarListModelSearch; - #define THUNAR_TYPE_LIST_MODEL (thunar_list_model_get_type ()) #define THUNAR_LIST_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_LIST_MODEL, ThunarListModel)) #define THUNAR_LIST_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_LIST_MODEL, ThunarListModelClass)) @@ -43,40 +36,8 @@ typedef enum ThunarListModelSearch GType thunar_list_model_get_type (void) G_GNUC_CONST; -ThunarListModel *thunar_list_model_new (void); - -ThunarFolder *thunar_list_model_get_folder (ThunarListModel *store); -void thunar_list_model_set_folder (ThunarListModel *store, - ThunarFolder *folder, - gchar *search_query); - -void thunar_list_model_set_folders_first (ThunarListModel *store, - gboolean folders_first); - -gboolean thunar_list_model_get_show_hidden (ThunarListModel *store); -void thunar_list_model_set_show_hidden (ThunarListModel *store, - gboolean show_hidden); - -gboolean thunar_list_model_get_file_size_binary (ThunarListModel *store); -void thunar_list_model_set_file_size_binary (ThunarListModel *store, - gboolean file_size_binary); - -ThunarFile *thunar_list_model_get_file (ThunarListModel *store, - GtkTreeIter *iter); - - -GList *thunar_list_model_get_paths_for_files (ThunarListModel *store, - GList *files); -GList *thunar_list_model_get_paths_for_pattern (ThunarListModel *store, - const gchar *pattern, - gboolean case_sensitive, - gboolean match_diacritics); +ThunarStandardViewModel *thunar_list_model_new (void); -gchar *thunar_list_model_get_statusbar_text (ThunarListModel *store, - GList *selected_items); -ThunarJob *thunar_list_model_get_job (ThunarListModel *store); -void thunar_list_model_set_job (ThunarListModel *store, - ThunarJob *job); G_END_DECLS; diff --git a/thunar/thunar-path-entry.c b/thunar/thunar-path-entry.c index 4ea05dfa07b94f388f81c431f29bd25627e6a08e..4ff8dea404246c2336b6642afa1f999423bfb19d 100644 --- a/thunar/thunar-path-entry.c +++ b/thunar/thunar-path-entry.c @@ -231,7 +231,7 @@ thunar_path_entry_init (ThunarPathEntry *path_entry) { GtkEntryCompletion *completion; GtkCellRenderer *renderer; - ThunarListModel *store; + ThunarStandardViewModel *store; path_entry->check_completion_idle_id = 0; path_entry->working_directory = NULL; @@ -254,8 +254,8 @@ thunar_path_entry_init (ThunarPathEntry *path_entry) /* allocate a new list mode for the completion */ store = thunar_list_model_new (); - thunar_list_model_set_show_hidden (store, TRUE); - thunar_list_model_set_folders_first (store, TRUE); + thunar_standard_view_model_set_show_hidden (store, TRUE); + thunar_standard_view_model_set_folders_first (store, TRUE); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), THUNAR_COLUMN_FILE_NAME, GTK_SORT_ASCENDING); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); g_object_unref (G_OBJECT (store)); @@ -669,7 +669,7 @@ thunar_path_entry_changed (GtkEditable *editable) model = gtk_entry_completion_get_model (completion); g_object_ref (G_OBJECT (model)); gtk_entry_completion_set_model (completion, NULL); - thunar_list_model_set_folder (THUNAR_LIST_MODEL (model), folder, NULL); + thunar_standard_view_model_set_folder (THUNAR_STANDARD_VIEW_MODEL (model), folder, NULL); gtk_entry_completion_set_model (completion, model); g_object_unref (G_OBJECT (model)); diff --git a/thunar/thunar-standard-view-model.c b/thunar/thunar-standard-view-model.c new file mode 100644 index 0000000000000000000000000000000000000000..450a65aa3be1a26192de169e1db8e7e132a5b985 --- /dev/null +++ b/thunar/thunar-standard-view-model.c @@ -0,0 +1,444 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2023 Amrit Borah <elessar1802@gmail.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <thunar/thunar-private.h> +#include <thunar/thunar-standard-view-model.h> + +static void thunar_standard_view_model_class_init (gpointer klass); + +GType +thunar_standard_view_model_get_type (void) +{ + static gsize type__static = 0; + GType type; + + if (g_once_init_enter (&type__static)) + { + type = g_type_register_static_simple (G_TYPE_INTERFACE, + I_("ThunarStandardViewModel"), + sizeof (ThunarStandardViewModelIface), + (GClassInitFunc) (void (*)(void)) thunar_standard_view_model_class_init, + 0, + NULL, + 0); + + g_type_interface_add_prerequisite (type, GTK_TYPE_TREE_MODEL); + g_type_interface_add_prerequisite (type, GTK_TYPE_TREE_DRAG_DEST); + g_type_interface_add_prerequisite (type, GTK_TYPE_TREE_SORTABLE); + + g_once_init_leave (&type__static, type); + } + + return type__static; +} + +static guint model_signals[THUNAR_STANDARD_VIEW_MODEL_LAST_SIGNAL]; + +static void thunar_standard_view_model_class_init (gpointer klass) +{ + static gboolean initialized = FALSE; + + if (! initialized) + { + /** + * ThunarStandardViewModel:case-sensitive: + * + * Tells whether the sorting should be case sensitive. + **/ + g_object_interface_install_property (klass, + g_param_spec_boolean ("case-sensitive", + "case-sensitive", + "case-sensitive", + TRUE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel:date-style: + * + * The style used to format dates. + **/ + g_object_interface_install_property (klass, + g_param_spec_enum ("date-style", + "date-style", + "date-style", + THUNAR_TYPE_DATE_STYLE, + THUNAR_DATE_STYLE_SIMPLE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel:date-custom-style: + * + * The style used for custom format of dates. + **/ + g_object_interface_install_property (klass, + g_param_spec_string ("date-custom-style", + "DateCustomStyle", + NULL, + "%Y-%m-%d %H:%M:%S", + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel:folder: + * + * The folder presented by this #ThunarStandardViewModel. + **/ + g_object_interface_install_property (klass, + g_param_spec_object ("folder", + "folder", + "folder", + THUNAR_TYPE_FOLDER, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel::folders-first: + * + * Tells whether to always sort folders before other files. + **/ + g_object_interface_install_property (klass, + g_param_spec_boolean ("folders-first", + "folders-first", + "folders-first", + TRUE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel::num-files: + * + * The number of files in the folder presented by this #ThunarStandardViewModel. + **/ + g_object_interface_install_property (klass, + g_param_spec_uint ("num-files", + "num-files", + "num-files", + 0, G_MAXUINT, 0, + EXO_PARAM_READABLE)); + + /** + * ThunarStandardViewModel::show-hidden: + * + * Tells whether to include hidden (and backup) files. + **/ + g_object_interface_install_property (klass, + g_param_spec_boolean ("show-hidden", + "show-hidden", + "show-hidden", + FALSE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel::misc-file-size-binary: + * + * Tells whether to format file size in binary. + **/ + g_object_interface_install_property (klass, + g_param_spec_boolean ("file-size-binary", + "file-size-binary", + "file-size-binary", + TRUE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel:folder-item-count: + * + * Tells when the size column of folders should show the number of containing files + **/ + g_object_interface_install_property (klass, + g_param_spec_enum ("folder-item-count", + "folder-item-count", + "folder-item-count", + THUNAR_TYPE_FOLDER_ITEM_COUNT, + TRUE, + EXO_PARAM_READWRITE)); + + /** + * ThunarStandardViewModel::error: + * @store : a #ThunarStandardViewModel. + * @error : a #GError that describes the problem. + * + * Emitted when an error occurs while loading the + * @store content. + **/ + model_signals[THUNAR_STANDARD_VIEW_MODEL_ERROR] = + g_signal_new (I_("error"), + G_TYPE_FROM_INTERFACE (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(ThunarStandardViewModelIface, error), + NULL, NULL, + g_cclosure_marshal_VOID__POINTER, + G_TYPE_NONE, 1, G_TYPE_POINTER); + + /** + * ThunarStandardViewModel::search-done: + * @store : a #ThunarStandardViewModel. + * @error : a #GError that describes the problem. + * + * Emitted when a recursive search finishes. + **/ + model_signals[THUNAR_STANDARD_VIEW_MODEL_SEARCH_DONE] = + g_signal_new (I_("search-done"), + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(ThunarStandardViewModelIface, search_done), + NULL, NULL, + NULL, + G_TYPE_NONE, 0); + + } +} + + + +// TODO: Make more detailed documentation for this. + +/** + * thunar_standard_view_model_get_folder: + * @store : a valid #ThunarStandardViewModel object. + * + * Return value: the #ThunarFolder @store is associated with + * or %NULL if @store has no folder. + **/ +ThunarFolder* +thunar_standard_view_model_get_folder (ThunarStandardViewModel *model) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_folder) (model); +} + + + +/** + * thunar_standard_view_model_set_folder: + * @store : a valid #ThunarStandardViewModel. + * @folder : a #ThunarFolder or %NULL. + * @search_query : a #string or %NULL. + **/ +void +thunar_standard_view_model_set_folder (ThunarStandardViewModel *model, + ThunarFolder *folder, + gchar *search_query) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); + _thunar_return_if_fail (folder == NULL || THUNAR_IS_FOLDER (folder)); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->set_folder) (model, folder, search_query); +} + + + +/** + * thunar_standard_view_model_set_folders_first: + * @store : a #ThunarStandardViewModel. + * @folders_first : %TRUE to let @store list folders first. + **/ +void +thunar_standard_view_model_set_folders_first (ThunarStandardViewModel *model, + gboolean folders_first) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->set_folders_first) (model, folders_first); + +} + + + +/** + * thunar_standard_view_model_get_show_hidden: + * @store : a #ThunarStandardViewModel. + * + * Return value: %TRUE if hidden files will be shown, else %FALSE. + **/ +gboolean +thunar_standard_view_model_get_show_hidden (ThunarStandardViewModel *model) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), FALSE); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_show_hidden) (model); +} + + + +/** + * thunar_standard_view_model_set_show_hidden: + * @store : a #ThunarStandardViewModel. + * @show_hidden : %TRUE if hidden files should be shown, else %FALSE. + **/ +void +thunar_standard_view_model_set_show_hidden (ThunarStandardViewModel *model, + gboolean show_hidden) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->set_show_hidden) (model, show_hidden); +} + + + +/** + * thunar_standard_view_model_get_file_size_binary: + * @store : a valid #ThunarStandardViewModel object. + * + * Returns %TRUE if the file size should be formatted + * as binary. + * + * Return value: %TRUE if file size format is binary. + **/ +gboolean +thunar_standard_view_model_get_file_size_binary (ThunarStandardViewModel *model) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), FALSE); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_file_size_binary) (model); +} + + + +/** + * thunar_standard_view_model_set_file_size_binary: + * @store : a valid #ThunarStandardViewModel object. + * @file_size_binary : %TRUE to format file size as binary. + * + * If @file_size_binary is %TRUE the file size should be + * formatted as binary. + **/ +void +thunar_standard_view_model_set_file_size_binary (ThunarStandardViewModel *model, + gboolean file_size_binary) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->set_file_size_binary) (model, file_size_binary); +} + + + +/** + * thunar_standard_view_model_get_file: + * @store : a #ThunarStandardViewModel. + * @iter : a valid #GtkTreeIter for @store. + * + * Returns the #ThunarFile referred to by @iter. Free + * the returned object using #g_object_unref() when + * you are done with it. + * + * Return value: the #ThunarFile. + **/ +ThunarFile* +thunar_standard_view_model_get_file (ThunarStandardViewModel *model, + GtkTreeIter *iter) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_file) (model, iter); +} + + + +/** + * thunar_standard_view_model_get_paths_for_files: + * @store : a #ThunarStandardViewModel instance. + * @files : a list of #ThunarFile<!---->s. + * + * Determines the list of #GtkTreePath<!---->s for the #ThunarFile<!---->s + * found in the @files list. If a #ThunarFile from the @files list is not + * available in @store, no #GtkTreePath will be returned for it. So, in effect, + * only #GtkTreePath<!---->s for the subset of @files available in @store will + * be returned. + * + * The caller is responsible to free the returned list using: + * <informalexample><programlisting> + * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + * </programlisting></informalexample> + * + * Return value: the list of #GtkTreePath<!---->s for @files. + **/ +GList* +thunar_standard_view_model_get_paths_for_files (ThunarStandardViewModel *model, + GList *files) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_paths_for_files) (model, files); +} + + + +/** + * thunar_standard_view_model_get_paths_for_pattern: + * @store : a #ThunarStandardViewModel instance. + * @pattern : the pattern to match. + * @case_sensitive : %TRUE to use case sensitive search. + * @match_diacritics : %TRUE to use case sensitive search. + * + * Looks up all rows in the @store that match @pattern and returns + * a list of #GtkTreePath<!---->s corresponding to the rows. + * + * The caller is responsible to free the returned list using: + * <informalexample><programlisting> + * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); + * </programlisting></informalexample> + * + * Return value: the list of #GtkTreePath<!---->s that match @pattern. + **/ +GList* +thunar_standard_view_model_get_paths_for_pattern (ThunarStandardViewModel *model, + const gchar *pattern, + gboolean case_sensitive, + gboolean match_diacritics) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_paths_for_pattern) (model, pattern, case_sensitive, match_diacritics); +} + + + +/** + * thunar_standard_view_model_get_statusbar_text_for_files: + * @files : list of files for which a text is requested + * @show_file_size_binary_format : weather the file size should be displayed in binary format + * + * Generates the statusbar text for the given @files. + * + * The caller is reponsible to free the returned text using + * g_free() when it's no longer needed. + * + * Return value: the statusbar text for @store with the given @files. + **/ +gchar* +thunar_standard_view_model_get_statusbar_text (ThunarStandardViewModel *model, + GList *selected_items) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_statusbar_text) (model, selected_items); +} + + + +ThunarJob* +thunar_standard_view_model_get_job (ThunarStandardViewModel *model) +{ + _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model), NULL); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->get_job) (model); +} + + + +void +thunar_standard_view_model_set_job (ThunarStandardViewModel *model, + ThunarJob *job) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); + return (*THUNAR_STANDARD_VIEW_MODEL_GET_IFACE (model)->set_job) (model, job); +} diff --git a/thunar/thunar-standard-view-model.h b/thunar/thunar-standard-view-model.h new file mode 100644 index 0000000000000000000000000000000000000000..7dddc98690076e4aef14aad17601e6c7f6cdbc0f --- /dev/null +++ b/thunar/thunar-standard-view-model.h @@ -0,0 +1,160 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2023 Amrit Borah <elessar1802@gmail.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + + +--------------------------------------------+ + | | + | | + | ThunarStandardViewModel | + | (Interface) | + | | + +---------------------+----------------------+ + | + +------------------------implemented by-------------------------+ + | | | + v v v ++--------------+------------+ +----------------------------+ +--------------+---------------+ +| | | | | | +| ThunarListModel | | ThunarTreeViewModel | | | +| | | | | | +|---------------------------| |----------------------------| | | +| + Used by | | + Used by | | | +| | | | | New models for new views | +| - IconView | | - DetailsView | | E.g Miller View. | +| | | | | | +| - CompactView | | | | | +| | | | | | +| - ThunarPathEntry | | | | | +| | | | | | ++---------------------------+ +----------------------------+ +------------------------------+ + + */ + +#ifndef __THUNAR_STANDARD_VIEW_MODEL__ +#define __THUNAR_STANDARD_VIEW_MODEL__ + +#include <thunar/thunar-folder.h> +#include <thunar/thunar-job.h> + +G_BEGIN_DECLS; + +typedef struct _ThunarStandardViewModelIface ThunarStandardViewModelIface; +typedef struct _ThunarStandardViewModel ThunarStandardViewModel; + +typedef enum ThunarStandardViewModelSearch +{ + THUNAR_STANDARD_VIEW_MODEL_SEARCH_RECURSIVE, + THUNAR_STANDARD_VIEW_MODEL_SEARCH_NON_RECURSIVE +} ThunarStandardViewModelSearch; + +/* Signal identifiers */ +typedef enum ThunarStandardViewModelSignals +{ + THUNAR_STANDARD_VIEW_MODEL_ERROR, + THUNAR_STANDARD_VIEW_MODEL_SEARCH_DONE, + THUNAR_STANDARD_VIEW_MODEL_LAST_SIGNAL, +} ThunarStandardViewModelSignals; + +#define THUNAR_TYPE_STANDARD_VIEW_MODEL (thunar_standard_view_model_get_type ()) +#define THUNAR_STANDARD_VIEW_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_STANDARD_VIEW_MODEL, ThunarStandardViewModel)) +#define THUNAR_IS_STANDARD_VIEW_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_STANDARD_VIEW_MODEL)) +#define THUNAR_STANDARD_VIEW_MODEL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), THUNAR_TYPE_STANDARD_VIEW_MODEL, ThunarStandardViewModelIface)) + +struct _ThunarStandardViewModelIface +{ + GTypeInterface __parent__; + /* signals */ + void (*error) (ThunarStandardViewModel *model, + const GError *error); + void (*search_done) (void); + + /* virtual methods */ + ThunarFolder *(*get_folder) (ThunarStandardViewModel *model); + void (*set_folder) (ThunarStandardViewModel *model, + ThunarFolder *folder, + gchar *search_query); + + void (*set_folders_first) (ThunarStandardViewModel *model, + gboolean folders_first); + + gboolean (*get_show_hidden) (ThunarStandardViewModel *model); + void (*set_show_hidden) (ThunarStandardViewModel *model, + gboolean show_hidden); + + gboolean (*get_file_size_binary) (ThunarStandardViewModel *model); + void (*set_file_size_binary) (ThunarStandardViewModel *model, + gboolean file_size_binary); + + ThunarFile *(*get_file) (ThunarStandardViewModel *model, + GtkTreeIter *iter); + + + GList *(*get_paths_for_files) (ThunarStandardViewModel *model, + GList *files); + GList *(*get_paths_for_pattern) (ThunarStandardViewModel *model, + const gchar *pattern, + gboolean case_sensitive, + gboolean match_diacritics); + + gchar *(*get_statusbar_text) (ThunarStandardViewModel *model, + GList *selected_items); + ThunarJob *(*get_job) (ThunarStandardViewModel *model); + void (*set_job) (ThunarStandardViewModel *model, + ThunarJob *job); +}; + +GType thunar_standard_view_model_get_type (void) G_GNUC_CONST; + +ThunarFolder *thunar_standard_view_model_get_folder (ThunarStandardViewModel *model); +void thunar_standard_view_model_set_folder (ThunarStandardViewModel *model, + ThunarFolder *folder, + gchar *search_query); + +void thunar_standard_view_model_set_folders_first (ThunarStandardViewModel *model, + gboolean folders_first); + +gboolean thunar_standard_view_model_get_show_hidden (ThunarStandardViewModel *model); +void thunar_standard_view_model_set_show_hidden (ThunarStandardViewModel *model, + gboolean show_hidden); + +gboolean thunar_standard_view_model_get_file_size_binary (ThunarStandardViewModel *model); +void thunar_standard_view_model_set_file_size_binary (ThunarStandardViewModel *model, + gboolean file_size_binary); + +ThunarFile *thunar_standard_view_model_get_file (ThunarStandardViewModel *model, + GtkTreeIter *iter); + + +GList *thunar_standard_view_model_get_paths_for_files (ThunarStandardViewModel *model, + GList *files); +GList *thunar_standard_view_model_get_paths_for_pattern (ThunarStandardViewModel *model, + const gchar *pattern, + gboolean case_sensitive, + gboolean match_diacritics); + +gchar *thunar_standard_view_model_get_statusbar_text (ThunarStandardViewModel *model, + GList *selected_items); +ThunarJob *thunar_standard_view_model_get_job (ThunarStandardViewModel *model); +void thunar_standard_view_model_set_job (ThunarStandardViewModel *model, + ThunarJob *job); + +G_END_DECLS; + +#endif /* __THUNAR_STANDARD_VIEW_MODEL__ */ diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 20098021f76dd338fe6dcd7481fb59b8e95def67..867b8d37fa3e0cc0d01ca47b4632cfc1cc43a3c1 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -237,22 +237,22 @@ static void thunar_standard_view_drag_data_delete (Gtk static void thunar_standard_view_drag_end (GtkWidget *view, GdkDragContext *context, ThunarStandardView *standard_view); -static void thunar_standard_view_select_after_row_deleted (ThunarListModel *model, +static void thunar_standard_view_select_after_row_deleted (ThunarStandardViewModel *model, GtkTreePath *path, ThunarStandardView *standard_view); -static void thunar_standard_view_row_changed (ThunarListModel *model, +static void thunar_standard_view_row_changed (ThunarStandardViewModel *model, GtkTreePath *path, GtkTreeIter *iter, ThunarStandardView *standard_view); -static void thunar_standard_view_rows_reordered (ThunarListModel *model, +static void thunar_standard_view_rows_reordered (ThunarStandardViewModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer new_order, ThunarStandardView *standard_view); -static void thunar_standard_view_error (ThunarListModel *model, +static void thunar_standard_view_error (ThunarStandardViewModel *model, const GError *error, ThunarStandardView *standard_view); -static void thunar_standard_view_search_done (ThunarListModel *model, +static void thunar_standard_view_search_done (ThunarStandardViewModel *model, ThunarStandardView *standard_view); static void thunar_standard_view_sort_column_changed (GtkTreeSortable *tree_sortable, ThunarStandardView *standard_view); @@ -1415,7 +1415,7 @@ thunar_standard_view_set_selected_files_component (ThunarComponent *component, (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->unselect_all) (standard_view); /* determine the tree paths for the given files */ - paths = thunar_list_model_get_paths_for_files (standard_view->model, selected_files); + paths = thunar_standard_view_model_get_paths_for_files (standard_view->model, selected_files); if (G_LIKELY (paths != NULL)) { /* determine the first path */ @@ -1593,7 +1593,7 @@ thunar_standard_view_set_current_directory (ThunarNavigator *navigator, g_object_set (G_OBJECT (gtk_bin_get_child (GTK_BIN (standard_view))), "model", NULL, NULL); /* reset the folder for the model */ - thunar_list_model_set_folder (standard_view->model, NULL, NULL); + thunar_standard_view_model_set_folder (standard_view->model, NULL, NULL); /* reconnect the model to the view */ g_object_set (G_OBJECT (gtk_bin_get_child (GTK_BIN (standard_view))), "model", standard_view->model, NULL); @@ -1637,7 +1637,7 @@ thunar_standard_view_set_current_directory (ThunarNavigator *navigator, /* apply the new folder, ignore removal of any old files */ g_signal_handler_block (standard_view->model, standard_view->priv->row_deleted_id); - thunar_list_model_set_folder (standard_view->model, folder, NULL); + thunar_standard_view_model_set_folder (standard_view->model, folder, NULL); g_signal_handler_unblock (standard_view->model, standard_view->priv->row_deleted_id); g_object_unref (G_OBJECT (folder)); @@ -1812,7 +1812,7 @@ thunar_standard_view_get_statusbar_text (ThunarView *view) if (items == NULL && standard_view->loading) return _("Loading folder contents..."); - standard_view->priv->statusbar_text = thunar_list_model_get_statusbar_text (standard_view->model, items); + standard_view->priv->statusbar_text = thunar_standard_view_model_get_statusbar_text (standard_view->model, items); g_list_free_full (items, (GDestroyNotify) gtk_tree_path_free); } @@ -1824,7 +1824,7 @@ thunar_standard_view_get_statusbar_text (ThunarView *view) static gboolean thunar_standard_view_get_show_hidden (ThunarView *view) { - return thunar_list_model_get_show_hidden (THUNAR_STANDARD_VIEW (view)->model); + return thunar_standard_view_model_get_show_hidden (THUNAR_STANDARD_VIEW (view)->model); } @@ -1833,7 +1833,7 @@ static void thunar_standard_view_set_show_hidden (ThunarView *view, gboolean show_hidden) { - thunar_list_model_set_show_hidden (THUNAR_STANDARD_VIEW (view)->model, show_hidden); + thunar_standard_view_model_set_show_hidden (THUNAR_STANDARD_VIEW (view)->model, show_hidden); } @@ -2024,7 +2024,7 @@ thunar_standard_view_reload (ThunarView *view, ThunarFile *file; /* determine the folder for the view model */ - folder = thunar_list_model_get_folder (standard_view->model); + folder = thunar_standard_view_model_get_folder (standard_view->model); if (G_LIKELY (folder != NULL)) { file = thunar_folder_get_corresponding_file (folder); @@ -2064,14 +2064,14 @@ thunar_standard_view_get_visible_range (ThunarView *view, if (G_LIKELY (start_file != NULL)) { gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, start_path); - *start_file = thunar_list_model_get_file (standard_view->model, &iter); + *start_file = thunar_standard_view_model_get_file (standard_view->model, &iter); } /* determine the file for the end path */ if (G_LIKELY (end_file != NULL)) { gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, end_path); - *end_file = thunar_list_model_get_file (standard_view->model, &iter); + *end_file = thunar_standard_view_model_get_file (standard_view->model, &iter); } /* release the tree paths */ @@ -2123,7 +2123,7 @@ thunar_standard_view_scroll_to_file (ThunarView *view, files.prev = NULL; /* determine the path for the file */ - paths = thunar_list_model_get_paths_for_files (standard_view->model, &files); + paths = thunar_standard_view_model_get_paths_for_files (standard_view->model, &files); if (G_LIKELY (paths != NULL)) { /* scroll to the path */ @@ -2226,7 +2226,7 @@ thunar_standard_view_get_drop_file (ThunarStandardView *standard_view, { /* determine the file for the path */ gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, path); - file = thunar_list_model_get_file (standard_view->model, &iter); + file = thunar_standard_view_model_get_file (standard_view->model, &iter); /* we can only drop to directories and executable files */ if (!thunar_file_is_directory (file) && !thunar_file_can_execute (file)) @@ -2536,7 +2536,7 @@ thunar_standard_view_select_by_pattern (ThunarView *view) match_diacritics = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (match_diacritics_button)); /* select all files that match pattern */ - paths = thunar_list_model_get_paths_for_pattern (standard_view->model, pattern, case_sensitive, match_diacritics); + paths = thunar_standard_view_model_get_paths_for_pattern (standard_view->model, pattern, case_sensitive, match_diacritics); THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->unselect_all (standard_view); /* set the cursor and scroll to the first selected item */ @@ -3535,13 +3535,13 @@ thunar_standard_view_restore_selection_idle (gpointer user_data) static void -thunar_standard_view_rows_reordered (ThunarListModel *model, +thunar_standard_view_rows_reordered (ThunarStandardViewModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer new_order, ThunarStandardView *standard_view) { - _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); _thunar_return_if_fail (standard_view->model == model); @@ -3560,14 +3560,14 @@ thunar_standard_view_rows_reordered (ThunarListModel *model, static void -thunar_standard_view_row_changed (ThunarListModel *model, +thunar_standard_view_row_changed (ThunarStandardViewModel *model, GtkTreePath *path, GtkTreeIter *iter, ThunarStandardView *standard_view) { ThunarFile *file; - _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); _thunar_return_if_fail (path != NULL); _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); _thunar_return_if_fail (standard_view->model == model); @@ -3585,7 +3585,7 @@ thunar_standard_view_row_changed (ThunarListModel *model, return; /* queue a thumbnail request */ - file = thunar_list_model_get_file (standard_view->model, iter); + file = thunar_standard_view_model_get_file (standard_view->model, iter); if (thunar_file_get_thumb_state (file) == THUNAR_FILE_THUMB_STATE_UNKNOWN) { thunar_standard_view_cancel_thumbnailing (standard_view); @@ -3598,7 +3598,7 @@ thunar_standard_view_row_changed (ThunarListModel *model, static void -thunar_standard_view_select_after_row_deleted (ThunarListModel *model, +thunar_standard_view_select_after_row_deleted (ThunarStandardViewModel *model, GtkTreePath *path, ThunarStandardView *standard_view) { @@ -3623,13 +3623,13 @@ thunar_standard_view_select_after_row_deleted (ThunarListModel *model, static void -thunar_standard_view_error (ThunarListModel *model, +thunar_standard_view_error (ThunarStandardViewModel *model, const GError *error, ThunarStandardView *standard_view) { ThunarFile *file; - _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); _thunar_return_if_fail (standard_view->model == model); @@ -3647,10 +3647,10 @@ thunar_standard_view_error (ThunarListModel *model, static void -thunar_standard_view_search_done (ThunarListModel *model, +thunar_standard_view_search_done (ThunarStandardViewModel *model, ThunarStandardView *standard_view) { - _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model)); + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW_MODEL (model)); _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); _thunar_return_if_fail (standard_view->model == model); @@ -3979,7 +3979,7 @@ thunar_standard_view_request_thumbnails_real (ThunarStandardView *standard_view, while (valid_iter) { /* prepend the file to the visible items list */ - file = thunar_list_model_get_file (standard_view->model, &iter); + file = thunar_standard_view_model_get_file (standard_view->model, &iter); visible_files = g_list_prepend (visible_files, file); /* check if we've reached the end of the visible range */ @@ -4272,7 +4272,7 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) gtk_tree_path_free (lp->data); /* ...and replace it with the file */ - lp->data = thunar_list_model_get_file (standard_view->model, &iter); + lp->data = thunar_standard_view_model_get_file (standard_view->model, &iter); } /* and setup the new selected files list */ @@ -4510,7 +4510,7 @@ _thunar_standard_view_open_on_middle_click (ThunarStandardView *standard_view, /* determine the file for the path */ gtk_tree_model_get_iter (GTK_TREE_MODEL (standard_view->model), &iter, tree_path); - file = thunar_list_model_get_file (standard_view->model, &iter); + file = thunar_standard_view_model_get_file (standard_view->model, &iter); if (G_LIKELY (file != NULL)) { if (thunar_file_is_directory (file)) @@ -4561,9 +4561,9 @@ thunar_standard_view_set_searching (ThunarStandardView *standard_view, /* set_folder() can emit a large number of row-deleted signals for large folders, * to the extent it degrades performance: https://gitlab.xfce.org/xfce/thunar/-/issues/914 */ g_signal_handler_block (standard_view->model, standard_view->priv->row_deleted_id); - g_object_ref (G_OBJECT (thunar_list_model_get_folder (standard_view->model))); /* temporarily hold a reference so the folder doesn't get deleted */ - thunar_list_model_set_folder (standard_view->model, thunar_list_model_get_folder (standard_view->model), search_query); - g_object_unref (G_OBJECT (thunar_list_model_get_folder (standard_view->model))); /* reference no longer needed */ + g_object_ref (G_OBJECT (thunar_standard_view_model_get_folder (standard_view->model))); /* temporarily hold a reference so the folder doesn't get deleted */ + thunar_standard_view_model_set_folder (standard_view->model, thunar_standard_view_model_get_folder (standard_view->model), search_query); + g_object_unref (G_OBJECT (thunar_standard_view_model_get_folder (standard_view->model))); /* reference no longer needed */ g_signal_handler_unblock (standard_view->model, standard_view->priv->row_deleted_id); /* change the display name in the tab */ @@ -4680,7 +4680,7 @@ thunar_standard_view_cell_layout_data_func (GtkCellLayout *layout, GtkTreeIter *iter, gpointer data) { - ThunarFile *file = THUNAR_FILE (thunar_list_model_get_file (THUNAR_LIST_MODEL (model), iter)); + ThunarFile *file = THUNAR_FILE (thunar_standard_view_model_get_file (THUNAR_STANDARD_VIEW_MODEL (model), iter)); const gchar *background = NULL; const gchar *foreground = NULL; GdkRGBA foreground_rgba; diff --git a/thunar/thunar-standard-view.h b/thunar/thunar-standard-view.h index 349dc4fec0dcdcfd67ccf26072e8e1e935171eab..e9d4f95ff0c3df10ee649ba8102b1dc63e463e97 100644 --- a/thunar/thunar-standard-view.h +++ b/thunar/thunar-standard-view.h @@ -20,6 +20,7 @@ #ifndef __THUNAR_STANDARD_VIEW_H__ #define __THUNAR_STANDARD_VIEW_H__ +#include "thunar-standard-view-model.h" #include <thunar/thunar-clipboard-manager.h> #include <thunar/thunar-history.h> #include <thunar/thunar-icon-factory.h> @@ -158,7 +159,7 @@ struct _ThunarStandardView ThunarPreferences *preferences; - ThunarListModel *model; + ThunarStandardViewModel *model; ThunarIconFactory *icon_factory; GtkCellRenderer *icon_renderer; diff --git a/thunar/thunar-tree-view-model.c b/thunar/thunar-tree-view-model.c new file mode 100644 index 0000000000000000000000000000000000000000..751a9104050ffaa422b71e30e94e98479541c76a --- /dev/null +++ b/thunar/thunar-tree-view-model.c @@ -0,0 +1,211 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2023 Amrit Borah <elessar1802@gmail.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <thunar/thunar-tree-view-model.h> +#include <thunar/thunar-standard-view-model.h> + +static void thunar_list_model_standard_view_model_init (ThunarStandardViewModelIface *iface); +static void thunar_list_model_tree_model_init (GtkTreeModelIface *iface); +static void thunar_list_model_drag_dest_init (GtkTreeDragDestIface *iface); +static void thunar_list_model_sortable_init (GtkTreeSortableIface *iface); +static void thunar_list_model_dispose (GObject *object); +static void thunar_list_model_finalize (GObject *object); +static void thunar_list_model_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void thunar_list_model_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static ThunarFolder *thunar_tree_view_model_get_folder (ThunarStandardViewModel *model); +static void thunar_tree_view_model_set_folder (ThunarStandardViewModel *model, + ThunarFolder *folder, + gchar *search_query); + +static void thunar_tree_view_model_set_folders_first (ThunarStandardViewModel *model, + gboolean folders_first); + +static gboolean thunar_tree_view_model_get_show_hidden (ThunarStandardViewModel *model); +static void thunar_tree_view_model_set_show_hidden (ThunarStandardViewModel *model, + gboolean show_hidden); + +static gboolean thunar_tree_view_model_get_file_size_binary (ThunarStandardViewModel *model); +static void thunar_tree_view_model_set_file_size_binary (ThunarStandardViewModel *model, + gboolean file_size_binary); + +static ThunarFile *thunar_tree_view_model_get_file (ThunarStandardViewModel *model, + GtkTreeIter *iter); + + +static GList *thunar_tree_view_model_get_paths_for_files (ThunarStandardViewModel *model, + GList *files); +static GList *thunar_tree_view_model_get_paths_for_pattern (ThunarStandardViewModel *model, + const gchar *pattern, + gboolean case_sensitive, + gboolean match_diacritics); + +static gchar *thunar_tree_view_model_get_statusbar_text (ThunarStandardViewModel *model, + GList *selected_items); +static ThunarJob *thunar_tree_view_model_get_job (ThunarStandardViewModel *model); +static void thunar_tree_view_model_set_job (ThunarStandardViewModel *model, + ThunarJob *job); + +/* Property identifiers */ +enum +{ + PROP_0, + PROP_CASE_SENSITIVE, + PROP_DATE_STYLE, + PROP_DATE_CUSTOM_STYLE, + PROP_FOLDER, + PROP_FOLDERS_FIRST, + PROP_NUM_FILES, + PROP_SHOW_HIDDEN, + PROP_FOLDER_ITEM_COUNT, + PROP_FILE_SIZE_BINARY, + N_PROPERTIES +}; + +static GParamSpec *tree_view_model_props[N_PROPERTIES] = { NULL, }; + +static void +thunar_standard_view_model_class_init (ThunarStandardViewModel *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->dispose = thunar_tree_view_model_dispose; + gobject_class->finalize = thunar_tree_view_model_finalize; + gobject_class->get_property = thunar_tree_view_model_get_property; + gobject_class->set_property = thunar_tree_view_model_set_property; + + /** + * ThunarListModel:case-sensitive: + * + * Tells whether the sorting should be case sensitive. + **/ + tree_view_model_props[PROP_CASE_SENSITIVE] = + g_param_spec_boolean ("case-sensitive", + "case-sensitive", + "case-sensitive", + TRUE, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel:date-style: + * + * The style used to format dates. + **/ + tree_view_model_props[PROP_DATE_STYLE] = + g_param_spec_enum ("date-style", + "date-style", + "date-style", + THUNAR_TYPE_DATE_STYLE, + THUNAR_DATE_STYLE_SIMPLE, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel:date-custom-style: + * + * The style used for custom format of dates. + **/ + tree_view_model_props[PROP_DATE_CUSTOM_STYLE] = + g_param_spec_string ("date-custom-style", + "DateCustomStyle", + NULL, + "%Y-%m-%d %H:%M:%S", + EXO_PARAM_READWRITE); + + /** + * ThunarListModel:folder: + * + * The folder presented by this #ThunarListModel. + **/ + tree_view_model_props[PROP_FOLDER] = + g_param_spec_object ("folder", + "folder", + "folder", + THUNAR_TYPE_FOLDER, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel::folders-first: + * + * Tells whether to always sort folders before other files. + **/ + tree_view_model_props[PROP_FOLDERS_FIRST] = + g_param_spec_boolean ("folders-first", + "folders-first", + "folders-first", + TRUE, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel::num-files: + * + * The number of files in the folder presented by this #ThunarListModel. + **/ + tree_view_model_props[PROP_NUM_FILES] = + g_param_spec_uint ("num-files", + "num-files", + "num-files", + 0, G_MAXUINT, 0, + EXO_PARAM_READABLE); + + /** + * ThunarListModel::show-hidden: + * + * Tells whether to include hidden (and backup) files. + **/ + tree_view_model_props[PROP_SHOW_HIDDEN] = + g_param_spec_boolean ("show-hidden", + "show-hidden", + "show-hidden", + FALSE, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel::misc-file-size-binary: + * + * Tells whether to format file size in binary. + **/ + tree_view_model_props[PROP_FILE_SIZE_BINARY] = + g_param_spec_boolean ("file-size-binary", + "file-size-binary", + "file-size-binary", + TRUE, + EXO_PARAM_READWRITE); + + /** + * ThunarListModel:folder-item-count: + * + * Tells when the size column of folders should show the number of containing files + **/ + tree_view_model_props[PROP_FOLDER_ITEM_COUNT] = + g_param_spec_enum ("folder-item-count", + "folder-item-count", + "folder-item-count", + THUNAR_TYPE_FOLDER_ITEM_COUNT, + TRUE, + EXO_PARAM_READWRITE); + + /* install properties */ + g_object_class_install_properties (gobject_class, N_PROPERTIES, tree_view_model_props); +} diff --git a/thunar/thunar-tree-view-model.h b/thunar/thunar-tree-view-model.h new file mode 100644 index 0000000000000000000000000000000000000000..e81749d93cb91b38d7636ddd886790e0d6e0580b --- /dev/null +++ b/thunar/thunar-tree-view-model.h @@ -0,0 +1,44 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2023 Amrit Borah <elessar1802@gmail.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __THUNAR_TREE_VIEW_MODEL_H__ +#define __THUNAR_TREE_VIEW_MODEL_H__ + +#include <thunar/thunar-standard-view-model.h> + +G_BEGIN_DECLS; + +typedef struct _ThunarTreeViewModelClass ThunarTreeViewModelClass; +typedef struct _ThunarTreeViewModel ThunarTreeViewModel; + +#define THUNAR_TYPE_TREE_VIEW_MODEL (thunar_tree_view_model_get_type ()) +#define THUNAR_TREE_VIEW_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_TREE_VIEW_MODEL, ThunarTreeViewModel)) +#define THUNAR_TREE_VIEW_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_TREE_VIEW_MODEL, ThunarTreeViewModelClass)) +#define THUNAR_IS_TREE_VIEW_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_TREE_VIEW_MODEL)) +#define THUNAR_IS_TREE_VIEW_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_TREE_VIEW_MODEL)) +#define THUNAR_TREE_VIEW_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_TREE_VIEW_MODEL, ThunarTreeViewModelClass)) + +GType thunar_tree_view_model_get_type (void) G_GNUC_CONST; + +ThunarStandardViewModel *thunar_tree_view_model_new (void); + + +G_END_DECLS; + +#endif /* !__THUNAR_TREE_VIEW_MODEL_H__ */ diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index a08a7af20c980506caa8664d5261e647160efdb2..8a91d0755e50cb62e5467c2efa2445c987c11e91 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -4053,7 +4053,7 @@ thunar_window_replace_view (ThunarWindow *window, history = thunar_standard_view_copy_history (THUNAR_STANDARD_VIEW (view)); /* Transfer ownership of the search-job to the new view. It is the new view's responsibility to cancel the search. */ - job = thunar_list_model_get_job (THUNAR_STANDARD_VIEW (view)->model); + job = thunar_standard_view_model_get_job (THUNAR_STANDARD_VIEW (view)->model); } } @@ -4118,7 +4118,7 @@ thunar_window_replace_view (ThunarWindow *window, window); } - thunar_list_model_set_job (THUNAR_STANDARD_VIEW (new_view)->model, job); + thunar_standard_view_model_set_job (THUNAR_STANDARD_VIEW (new_view)->model, job); }