diff options
author | Vivien Kraus <vivien@planete-kraus.eu> | 2023-03-13 19:41:59 +0100 |
---|---|---|
committer | Vivien Kraus <vivien@planete-kraus.eu> | 2023-03-13 20:29:38 +0100 |
commit | c52735ab1431190803923c27a3ac43d7a22d57de (patch) | |
tree | bb63f304ead7a846fbff184be08c745151e13aff | |
parent | 84ed992c30be83e3a79867a827a85108393c63ac (diff) |
Attach an optional file name to a cache entry.
-rw-r--r-- | include/disfluid.h | 8 | ||||
-rw-r--r-- | src/adwaita/disfluid-cache-entry.c | 13 | ||||
-rw-r--r-- | src/adwaita/disfluid-window.c | 2 | ||||
-rw-r--r-- | src/libdisfluid/disfluid-cache-entry.h | 54 | ||||
-rw-r--r-- | src/libdisfluid/main.c | 13 |
5 files changed, 89 insertions, 1 deletions
diff --git a/include/disfluid.h b/include/disfluid.h index c4ddcc8..8c52922 100644 --- a/include/disfluid.h +++ b/include/disfluid.h @@ -165,6 +165,10 @@ extern "C" int invalidated); LIBDISFLUID_API extern void + disfluid_cache_entry_set_file_name (struct disfluid_cache_entry *entry, + const char *filename); + + LIBDISFLUID_API extern void disfluid_cache_entry_get_request_date (const struct disfluid_cache_entry *entry, struct timespec *date); @@ -176,6 +180,10 @@ extern "C" disfluid_cache_entry_invalidated (const struct disfluid_cache_entry *entry); + LIBDISFLUID_API LIBDISFLUID_DEALLOC_WITH_FREE extern char + *disfluid_cache_entry_get_file_name (const struct disfluid_cache_entry + *entry); + LIBDISFLUID_API extern int disfluid_cache_entry_save_other_file_name (const struct disfluid_cache_entry *entry, diff --git a/src/adwaita/disfluid-cache-entry.c b/src/adwaita/disfluid-cache-entry.c index e0245c4..060fb96 100644 --- a/src/adwaita/disfluid-cache-entry.c +++ b/src/adwaita/disfluid-cache-entry.c @@ -235,6 +235,19 @@ disfluid_adw_cache_entry_set_cache_entry (DisfluidAdwCacheEntry * self, gtk_label_set_label (self->row_response_date, response_title); gtk_label_set_label (self->row_invalidation_status, invalidation_status_title); + char *file_name = + disfluid_cache_entry_get_file_name (self->cache_entry); + if (file_name == NULL) + { + adw_preferences_group_set_title (ADW_PREFERENCES_GROUP (self), + _("Unknown cache entry")); + } + else + { + adw_preferences_group_set_title (ADW_PREFERENCES_GROUP (self), + file_name); + } + free (file_name); g_free (request_title); g_free (response_title); g_free (invalidation_status_title); diff --git a/src/adwaita/disfluid-window.c b/src/adwaita/disfluid-window.c index 8f9d87f..bb8d592 100644 --- a/src/adwaita/disfluid-window.c +++ b/src/adwaita/disfluid-window.c @@ -58,6 +58,8 @@ disfluid_adw_window_init (DisfluidAdwWindow * self) { abort (); } + disfluid_cache_entry_set_file_name (cache_entry, + "/tmp/test.disfluid-cache-entry"); GtkWidget *unique_content = g_object_new (DISFLUID_ADW_TYPE_CACHE_ENTRY, NULL); disfluid_adw_cache_entry_set_cache_entry (DISFLUID_ADW_CACHE_ENTRY diff --git a/src/libdisfluid/disfluid-cache-entry.h b/src/libdisfluid/disfluid-cache-entry.h index 3f9123c..272c9e8 100644 --- a/src/libdisfluid/disfluid-cache-entry.h +++ b/src/libdisfluid/disfluid-cache-entry.h @@ -37,6 +37,10 @@ cache_entry_set_invalidated (struct disfluid_cache_entry *entry, bool invalidated); MAYBE_UNUSED static void +cache_entry_set_file_name (struct disfluid_cache_entry *entry, + const char *file_name); + +MAYBE_UNUSED static void cache_entry_get_request_date (const struct disfluid_cache_entry *entry, struct timespec *date); @@ -47,13 +51,18 @@ cache_entry_get_response_date (const struct disfluid_cache_entry *entry, MAYBE_UNUSED static bool cache_entry_invalidated (const struct disfluid_cache_entry *entry); +MAYBE_UNUSED static char *cache_entry_get_file_name (const struct + disfluid_cache_entry + *entry); + # include <assert.h> # include "disfluid-init.h" struct disfluid_cache_entry { - int fd; + char *file_name; /* Might be NULL */ + int fd; /* Might be < 0, but must be >= 0 if there is a file_name. */ off_t start; off_t header_stop; struct timespec request_date; @@ -71,6 +80,7 @@ cache_entry_alloc (void) { abort (); } + ret->file_name = NULL; ret->fd = -1; ret->start = 0; ret->header_stop = 0; @@ -87,6 +97,7 @@ cache_entry_free (struct disfluid_cache_entry *entry) { if (entry != NULL) { + free (entry->file_name); if (entry->fd >= 0) { close (entry->fd); @@ -108,6 +119,7 @@ cache_entry_from_file_name (const char *file_name) { abort (); } + cache_entry_set_file_name (ret, file_name); return ret; } @@ -124,6 +136,15 @@ cache_entry_dup (const struct disfluid_cache_entry *entry) ret = NULL; } } + if (ret != NULL && entry->file_name != NULL) + { + ret->file_name = strdup (entry->file_name); + if ((ret->file_name == NULL) != (entry->file_name == NULL)) + { + cache_entry_free (ret); + ret = NULL; + } + } if (ret != NULL) { ret->start = entry->start; @@ -509,6 +530,22 @@ cache_entry_set_invalidated (struct disfluid_cache_entry *entry, } static void +cache_entry_set_file_name (struct disfluid_cache_entry *entry, + const char *file_name) +{ + free (entry->file_name); + entry->file_name = NULL; + if (file_name != NULL) + { + entry->file_name = strdup (file_name); + if (entry->file_name == NULL) + { + abort (); + } + } +} + +static void cache_entry_get_request_date (const struct disfluid_cache_entry *entry, struct timespec *date) { @@ -530,4 +567,19 @@ cache_entry_invalidated (const struct disfluid_cache_entry *entry) return entry->invalidated; } +static char * +cache_entry_get_file_name (const struct disfluid_cache_entry *entry) +{ + if (entry->file_name == NULL) + { + return NULL; + } + char *ret = strdup (entry->file_name); + if (ret == NULL) + { + abort (); + } + return ret; +} + #endif /* DISFLUID_DISFLUID_CACHE_ENTRY_INCLUDED */ diff --git a/src/libdisfluid/main.c b/src/libdisfluid/main.c index 8acf4f7..c254a4a 100644 --- a/src/libdisfluid/main.c +++ b/src/libdisfluid/main.c @@ -186,6 +186,13 @@ disfluid_cache_entry_set_invalidated (struct disfluid_cache_entry *entry, } void +disfluid_cache_entry_set_file_name (struct disfluid_cache_entry *entry, + const char *file_name) +{ + return cache_entry_set_file_name (entry, file_name); +} + +void disfluid_cache_entry_get_request_date (const struct disfluid_cache_entry *entry, struct timespec *date) { @@ -204,3 +211,9 @@ disfluid_cache_entry_invalidated (const struct disfluid_cache_entry *entry) { return cache_entry_invalidated (entry); } + +char * +disfluid_cache_entry_get_file_name (const struct disfluid_cache_entry *entry) +{ + return cache_entry_get_file_name (entry); +} |