1 /* Cache-related dialogs */
4 #define _GNU_SOURCE /* XXX: we _WANT_ strcasestr() ! */
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"
31 lock_cache_entry(struct listbox_item
*item
)
33 object_lock((struct cache_entry
*) item
->udata
);
37 unlock_cache_entry(struct listbox_item
*item
)
39 object_unlock((struct cache_entry
*) item
->udata
);
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
;
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: %" PRId64
, _("Size", term
),
87 add_format_to_string(&msg
, "\n%s: %" PRId64
, _("Loaded size", term
),
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
);
98 add_format_to_string(&msg
, "\n%s: %s", "ETag",
101 if (cached
->ssl_info
) {
102 add_format_to_string(&msg
, "\n%s: %s", _("SSL Cipher", term
),
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
));
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
);
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
),
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
)
157 can_delete_cache_entry(struct listbox_item
*item
)
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
,
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 */
192 /* cant_delete_used_folder */
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 */
202 /* delete_item_title */
203 N_("Delete cache entry"),
205 N_("Delete this cache entry?"),
206 /* clear_all_items_title */
208 /* clear_all_items_title */
212 static struct listbox_ops cache_entry_listbox_ops
= {
216 get_cache_entry_text
,
217 get_cache_entry_info
,
219 get_cache_entry_root
,
221 can_delete_cache_entry
,
222 delete_cache_entry_item
,
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(
239 &cache_entry_listbox_ops
243 cache_manager(struct session
*ses
)
245 hierbox_browser(&cache_browser
, ses
);