Polish translation was updated.
[elinks.git] / src / cache / dialogs.c
blob5a2dc985dd990fec21571844e80ccca39b973e45
1 /* Cache-related dialogs */
3 #ifndef _GNU_SOURCE
4 #define _GNU_SOURCE /* XXX: we _WANT_ strcasestr() ! */
5 #endif
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
11 #include <string.h>
13 #include "elinks.h"
15 #include "bfu/dialog.h"
16 #include "cache/cache.h"
17 #include "cache/dialogs.h"
18 #include "dialogs/edit.h"
19 #include "intl/gettext/libintl.h"
20 #include "main/object.h"
21 #include "protocol/uri.h"
22 #include "session/session.h"
23 #include "terminal/draw.h"
24 #include "terminal/terminal.h"
25 #include "util/conv.h"
26 #include "util/memory.h"
27 #include "util/string.h"
30 static void
31 lock_cache_entry(struct listbox_item *item)
33 object_lock((struct cache_entry *) item->udata);
36 static void
37 unlock_cache_entry(struct listbox_item *item)
39 object_unlock((struct cache_entry *) item->udata);
42 static int
43 is_cache_entry_used(struct listbox_item *item)
45 return is_object_used((struct cache_entry *) item->udata);
48 static unsigned char *
49 get_cache_entry_text(struct listbox_item *item, struct terminal *term)
51 struct cache_entry *cached = item->udata;
53 return get_uri_string(cached->uri, URI_PUBLIC);
56 static unsigned char *
57 get_cache_entry_info(struct listbox_item *item, struct terminal *term)
59 struct cache_entry *cached = item->udata;
60 struct string msg;
62 if (item->type == BI_FOLDER) return NULL;
63 if (!init_string(&msg)) return NULL;
65 add_to_string(&msg, _("URL", term));
66 add_to_string(&msg, ": ");
67 add_uri_to_string(&msg, cached->uri, URI_PUBLIC);
69 /* No need to use compare_uri() here we only want to check whether they
70 * point to the same URI. */
71 if (cached->proxy_uri != cached->uri) {
72 add_format_to_string(&msg, "\n%s: ", _("Proxy URL", term));
73 add_uri_to_string(&msg, cached->proxy_uri, URI_PUBLIC);
76 if (cached->redirect) {
77 add_format_to_string(&msg, "\n%s: ", _("Redirect", term));
78 add_uri_to_string(&msg, cached->redirect, URI_PUBLIC);
80 if (cached->redirect_get) {
81 add_to_string(&msg, " (GET)");
85 add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Size", term),
86 cached->length);
87 add_format_to_string(&msg, "\n%s: %" OFF_T_FORMAT, _("Loaded size", term),
88 cached->data_size);
89 if (cached->content_type) {
90 add_format_to_string(&msg, "\n%s: %s", _("Content type", term),
91 cached->content_type);
93 if (cached->last_modified) {
94 add_format_to_string(&msg, "\n%s: %s", _("Last modified", term),
95 cached->last_modified);
97 if (cached->etag) {
98 add_format_to_string(&msg, "\n%s: %s", "ETag",
99 cached->etag);
101 if (cached->ssl_info) {
102 add_format_to_string(&msg, "\n%s: %s", _("SSL Cipher", term),
103 cached->ssl_info);
105 if (cached->encoding_info) {
106 add_format_to_string(&msg, "\n%s: %s", _("Encoding", term),
107 cached->encoding_info);
110 if (cached->incomplete || !cached->valid) {
111 add_char_to_string(&msg, '\n');
112 add_to_string(&msg, _("Flags", term));
113 add_to_string(&msg, ": ");
114 if (cached->incomplete) {
115 add_to_string(&msg, _("incomplete", term));
116 add_char_to_string(&msg, ' ');
118 if (!cached->valid) add_to_string(&msg, _("invalid", term));
121 #ifdef HAVE_STRFTIME
122 if (cached->expire) {
123 time_t expires = timeval_to_seconds(&cached->max_age);
125 add_format_to_string(&msg, "\n%s: ", _("Expires", term));
126 add_date_to_string(&msg, get_opt_str("ui.date_format"), &expires);
128 #endif
129 #ifdef CONFIG_DEBUG
130 add_format_to_string(&msg, "\n%s: %d", "Refcount", get_object_refcount(cached));
131 add_format_to_string(&msg, "\n%s: %u", _("ID", term), cached->id);
133 if (cached->head && *cached->head) {
134 add_format_to_string(&msg, "\n%s:\n\n%s", _("Header", term),
135 cached->head);
137 #endif
139 return msg.source;
142 static struct uri *
143 get_cache_entry_uri(struct listbox_item *item)
145 struct cache_entry *cached = item->udata;
147 return get_uri_reference(cached->uri);
150 static struct listbox_item *
151 get_cache_entry_root(struct listbox_item *item)
153 return NULL;
156 static int
157 can_delete_cache_entry(struct listbox_item *item)
159 return 1;
162 static void
163 delete_cache_entry_item(struct listbox_item *item, int last)
165 struct cache_entry *cached = item->udata;
167 assert(!is_object_used(cached));
169 delete_cache_entry(cached);
172 static enum listbox_match
173 match_cache_entry(struct listbox_item *item, struct terminal *term,
174 unsigned char *text)
176 struct cache_entry *cached = item->udata;
178 if (strcasestr(struri(cached->uri), text)
179 || (cached->head && strcasestr(cached->head, text)))
180 return LISTBOX_MATCH_OK;
182 return LISTBOX_MATCH_NO;
185 static struct listbox_ops_messages cache_messages = {
186 /* cant_delete_item */
187 N_("Sorry, but cache entry \"%s\" cannot be deleted."),
188 /* cant_delete_used_item */
189 N_("Sorry, but cache entry \"%s\" is being used by something else."),
190 /* cant_delete_folder */
191 NULL,
192 /* cant_delete_used_folder */
193 NULL,
194 /* delete_marked_items_title */
195 N_("Delete marked cache entries"),
196 /* delete_marked_items */
197 N_("Delete marked cache entries?"),
198 /* delete_folder_title */
199 NULL,
200 /* delete_folder */
201 NULL,
202 /* delete_item_title */
203 N_("Delete cache entry"),
204 /* delete_item; xgettext:c-format */
205 N_("Delete this cache entry?"),
206 /* clear_all_items_title */
207 NULL,
208 /* clear_all_items_title */
209 NULL,
212 static struct listbox_ops cache_entry_listbox_ops = {
213 lock_cache_entry,
214 unlock_cache_entry,
215 is_cache_entry_used,
216 get_cache_entry_text,
217 get_cache_entry_info,
218 get_cache_entry_uri,
219 get_cache_entry_root,
220 match_cache_entry,
221 can_delete_cache_entry,
222 delete_cache_entry_item,
223 NULL,
224 &cache_messages,
227 static struct hierbox_browser_button cache_buttons[] = {
228 /* [gettext_accelerator_context(.cache_buttons)] */
229 { N_("~Info"), push_hierbox_info_button, 1 },
230 { N_("~Goto"), push_hierbox_goto_button, 1 },
231 { N_("~Delete"), push_hierbox_delete_button, 1 },
232 { N_("~Search"), push_hierbox_search_button, 1 },
235 struct_hierbox_browser(
236 cache_browser,
237 N_("Cache manager"),
238 cache_buttons,
239 &cache_entry_listbox_ops
242 void
243 cache_manager(struct session *ses)
245 hierbox_browser(&cache_browser, ses);