Expose the mtime of the model's entries

This commit is contained in:
Přemysl Eric Janouch 2022-06-04 01:19:56 +02:00
parent efc13db66e
commit 3ddb0cf205
Signed by: p
GPG Key ID: A0420B94F92B9493
5 changed files with 42 additions and 41 deletions

View File

@ -1698,18 +1698,18 @@ on_model_files_changed(FivIoModel *model, FivBrowser *self)
if (self->selected) if (self->selected)
selected_uri = g_strdup(self->selected->uri); selected_uri = g_strdup(self->selected->uri);
// TODO(p): Later implement arguments. // TODO(p): Later implement arguments of this FivIoModel signal.
// Or ensure somehow else that thumbnails won't be reloaded unnecessarily.
thumbnailers_abort(self); thumbnailers_abort(self);
g_array_set_size(self->entries, 0); g_array_set_size(self->entries, 0);
g_array_set_size(self->layouted_rows, 0); g_array_set_size(self->layouted_rows, 0);
GPtrArray *files = fiv_io_model_get_files(self->model); gsize len = 0;
for (guint i = 0; i < files->len; i++) { const FivIoModelEntry *files = fiv_io_model_get_files(self->model, &len);
for (gsize i = 0; i < len; i++) {
g_array_append_val(self->entries, g_array_append_val(self->entries,
((Entry) {.thumbnail = NULL, .uri = files->pdata[i]})); ((Entry) {.thumbnail = NULL, .uri = g_strdup(files[i].uri)}));
files->pdata[i] = NULL;
} }
g_ptr_array_free(files, TRUE);
fiv_browser_select(self, selected_uri); fiv_browser_select(self, selected_uri);
g_free(selected_uri); g_free(selected_uri);

View File

@ -2795,14 +2795,8 @@ fiv_io_deserialize(GBytes *bytes)
#include <fnmatch.h> #include <fnmatch.h>
typedef struct {
gchar *uri; ///< GIO URI
gchar *collate_key; ///< Collate key for the filename
gint64 mtime_msec; ///< Modification time in milliseconds
} ModelEntry;
static void static void
model_entry_finalize(ModelEntry *entry) model_entry_finalize(FivIoModelEntry *entry)
{ {
g_free(entry->uri); g_free(entry->uri);
g_free(entry->collate_key); g_free(entry->collate_key);
@ -2867,8 +2861,9 @@ model_supports(FivIoModel *self, const gchar *filename)
} }
static inline int static inline int
model_compare_entries(FivIoModel *self, const ModelEntry *entry1, GFile *file1, model_compare_entries(FivIoModel *self,
const ModelEntry *entry2, GFile *file2) const FivIoModelEntry *entry1, GFile *file1,
const FivIoModelEntry *entry2, GFile *file2)
{ {
if (g_file_has_prefix(file1, file2)) if (g_file_has_prefix(file1, file2))
return +1; return +1;
@ -2894,8 +2889,8 @@ model_compare_entries(FivIoModel *self, const ModelEntry *entry1, GFile *file1,
static gint static gint
model_compare(gconstpointer a, gconstpointer b, gpointer user_data) model_compare(gconstpointer a, gconstpointer b, gpointer user_data)
{ {
const ModelEntry *entry1 = a; const FivIoModelEntry *entry1 = a;
const ModelEntry *entry2 = b; const FivIoModelEntry *entry2 = b;
GFile *file1 = g_file_new_for_uri(entry1->uri); GFile *file1 = g_file_new_for_uri(entry1->uri);
GFile *file2 = g_file_new_for_uri(entry2->uri); GFile *file2 = g_file_new_for_uri(entry2->uri);
int result = model_compare_entries(user_data, entry1, file1, entry2, file2); int result = model_compare_entries(user_data, entry1, file1, entry2, file2);
@ -2939,7 +2934,7 @@ model_reload(FivIoModel *self, GError **error)
if (self->filtering && g_file_info_get_is_hidden(info)) if (self->filtering && g_file_info_get_is_hidden(info))
continue; continue;
ModelEntry entry = {.uri = g_file_get_uri(child)}; FivIoModelEntry entry = {.uri = g_file_get_uri(child)};
GDateTime *mtime = g_file_info_get_modification_date_time(info); GDateTime *mtime = g_file_info_get_modification_date_time(info);
if (mtime) { if (mtime) {
entry.mtime_msec = g_date_time_to_unix(mtime) * 1000 + entry.mtime_msec = g_date_time_to_unix(mtime) * 1000 +
@ -3076,8 +3071,8 @@ fiv_io_model_init(FivIoModel *self)
self->supported_globs = extract_mime_globs((const char **) types); self->supported_globs = extract_mime_globs((const char **) types);
g_strfreev(types); g_strfreev(types);
self->files = g_array_new(FALSE, TRUE, sizeof(ModelEntry)); self->files = g_array_new(FALSE, TRUE, sizeof(FivIoModelEntry));
self->subdirs = g_array_new(FALSE, TRUE, sizeof(ModelEntry)); self->subdirs = g_array_new(FALSE, TRUE, sizeof(FivIoModelEntry));
g_array_set_clear_func( g_array_set_clear_func(
self->subdirs, (GDestroyNotify) model_entry_finalize); self->subdirs, (GDestroyNotify) model_entry_finalize);
g_array_set_clear_func( g_array_set_clear_func(
@ -3107,24 +3102,18 @@ fiv_io_model_get_location(FivIoModel *self)
return self->directory; return self->directory;
} }
GPtrArray * const FivIoModelEntry *
fiv_io_model_get_files(FivIoModel *self) fiv_io_model_get_files(FivIoModel *self, gsize *len)
{ {
GPtrArray *a = g_ptr_array_new_full(self->files->len, g_free); *len = self->files->len;
for (guint i = 0; i < self->files->len; i++) return (const FivIoModelEntry *) self->files->data;
g_ptr_array_add(
a, g_strdup(g_array_index(self->files, ModelEntry, i).uri));
return a;
} }
GPtrArray * const FivIoModelEntry *
fiv_io_model_get_subdirectories(FivIoModel *self) fiv_io_model_get_subdirs(FivIoModel *self, gsize *len)
{ {
GPtrArray *a = g_ptr_array_new_full(self->subdirs->len, g_free); *len = self->subdirs->len;
for (guint i = 0; i < self->subdirs->len; i++) return (const FivIoModelEntry *) self->subdirs->data;
g_ptr_array_add(
a, g_strdup(g_array_index(self->subdirs, ModelEntry, i).uri));
return a;
} }
// --- Export ------------------------------------------------------------------ // --- Export ------------------------------------------------------------------

View File

@ -122,8 +122,14 @@ gboolean fiv_io_model_open(FivIoModel *self, GFile *directory, GError **error);
/// There is no ownership transfer, and the object may be NULL. /// There is no ownership transfer, and the object may be NULL.
GFile *fiv_io_model_get_location(FivIoModel *self); GFile *fiv_io_model_get_location(FivIoModel *self);
GPtrArray *fiv_io_model_get_files(FivIoModel *self); typedef struct {
GPtrArray *fiv_io_model_get_subdirectories(FivIoModel *self); gchar *uri; ///< GIO URI
gchar *collate_key; ///< Collate key for the filename
gint64 mtime_msec; ///< Modification time in milliseconds
} FivIoModelEntry;
const FivIoModelEntry *fiv_io_model_get_files(FivIoModel *self, gsize *len);
const FivIoModelEntry *fiv_io_model_get_subdirs(FivIoModel *self, gsize *len);
// --- Export ------------------------------------------------------------------ // --- Export ------------------------------------------------------------------

View File

@ -241,14 +241,15 @@ update_location(FivSidebar *self)
if ((row = create_row(self, location, "circle-filled-symbolic"))) if ((row = create_row(self, location, "circle-filled-symbolic")))
gtk_container_add(GTK_CONTAINER(self->listbox), row); gtk_container_add(GTK_CONTAINER(self->listbox), row);
GPtrArray *subdirs = fiv_io_model_get_subdirectories(self->model); gsize len = 0;
for (guint i = 0; i < subdirs->len; i++) { const FivIoModelEntry *subdirs =
GFile *file = g_file_new_for_uri(subdirs->pdata[i]); fiv_io_model_get_subdirs(self->model, &len);
for (gsize i = 0; i < len; i++) {
GFile *file = g_file_new_for_uri(subdirs[i].uri);
if ((row = create_row(self, file, "go-down-symbolic"))) if ((row = create_row(self, file, "go-down-symbolic")))
gtk_container_add(GTK_CONTAINER(self->listbox), row); gtk_container_add(GTK_CONTAINER(self->listbox), row);
g_object_unref(file); g_object_unref(file);
} }
g_ptr_array_free(subdirs, TRUE);
} }
static void static void

7
fiv.c
View File

@ -702,8 +702,13 @@ on_model_files_changed(FivIoModel *model, G_GNUC_UNUSED gpointer user_data)
{ {
g_return_if_fail(model == g.model); g_return_if_fail(model == g.model);
gsize len = 0;
const FivIoModelEntry *files = fiv_io_model_get_files(g.model, &len);
g_ptr_array_free(g.files, TRUE); g_ptr_array_free(g.files, TRUE);
g.files = fiv_io_model_get_files(g.model); g.files = g_ptr_array_new_full(len, g_free);
for (gsize i = 0; i < len; i++)
g_ptr_array_add(g.files, g_strdup(files[i].uri));
update_files_index(); update_files_index();
gtk_widget_set_sensitive( gtk_widget_set_sensitive(