1 /* Global history dialogs */
11 #include "bfu/dialog.h"
12 #include "bookmarks/dialogs.h"
13 #include "dialogs/edit.h"
14 #include "globhist/dialogs.h"
15 #include "globhist/globhist.h"
16 #include "intl/gettext/libintl.h"
17 #include "main/object.h"
18 #include "protocol/uri.h"
19 #include "terminal/terminal.h"
20 #include "util/memory.h"
21 #include "util/string.h"
24 /* Implementation of the listbox operations */
26 static void lock_globhist_item(struct listbox_item
*item
)
28 object_lock((struct global_history_item
*) item
->udata
);
31 static void unlock_globhist_item(struct listbox_item
*item
)
33 object_unlock((struct global_history_item
*) item
->udata
);
36 static int is_globhist_item_used(struct listbox_item
*item
)
38 return is_object_used((struct global_history_item
*) item
->udata
);
41 static unsigned char *
42 get_globhist_item_text(struct listbox_item
*box_item
, struct terminal
*term
)
44 struct global_history_item
*item
= box_item
->udata
;
47 if (get_opt_int("document.history.global.display_type")
49 return stracpy(item
->title
);
51 if (!init_string(&info
)) return NULL
;
52 add_string_uri_to_string(&info
, item
->url
, URI_PUBLIC
);
56 static unsigned char *
57 get_globhist_item_info(struct listbox_item
*box_item
, struct terminal
*term
)
59 struct global_history_item
*item
= box_item
->udata
;
62 if (box_item
->type
== BI_FOLDER
) return NULL
;
63 if (!init_string(&info
)) return NULL
;
65 add_format_to_string(&info
, "%s: %s", _("Title", term
), item
->title
);
66 add_format_to_string(&info
, "\n%s: %s", _("URL", term
), item
->url
);
67 add_format_to_string(&info
, "\n%s: %s", _("Last visit time", term
),
68 ctime(&item
->last_visit
));
73 static struct listbox_item
*
74 get_globhist_item_root(struct listbox_item
*box_item
)
80 get_globhist_item_uri(struct listbox_item
*item
)
82 struct global_history_item
*historyitem
= item
->udata
;
84 return get_uri(historyitem
->url
, 0);
88 can_delete_globhist_item(struct listbox_item
*item
)
94 delete_globhist_item(struct listbox_item
*item
, int last
)
96 struct global_history_item
*historyitem
= item
->udata
;
98 assert(!is_object_used(historyitem
));
100 delete_global_history_item(historyitem
);
103 static struct listbox_ops_messages globhist_messages
= {
104 /* cant_delete_item */
105 N_("Sorry, but history entry \"%s\" cannot be deleted."),
106 /* cant_delete_used_item */
107 N_("Sorry, but history entry \"%s\" is being used by something else."),
108 /* cant_delete_folder */
110 /* cant_delete_used_folder */
112 /* delete_marked_items_title */
113 N_("Delete marked history entries"),
114 /* delete_marked_items */
115 N_("Delete marked history entries?"),
116 /* delete_folder_title */
120 /* delete_item_title */
121 N_("Delete history entry"),
122 /* delete_item; xgettext:c-format */
123 N_("Delete this history entry?"),
124 /* clear_all_items_title */
125 N_("Clear all history entries"),
126 /* clear_all_items_title */
127 N_("Do you really want to remove all history entries?"),
130 static const struct listbox_ops gh_listbox_ops
= {
132 unlock_globhist_item
,
133 is_globhist_item_used
,
134 get_globhist_item_text
,
135 get_globhist_item_info
,
136 get_globhist_item_uri
,
137 get_globhist_item_root
,
139 can_delete_globhist_item
,
140 delete_globhist_item
,
148 history_search_do(void *data
)
150 struct dialog
*dlg
= data
;
151 struct listbox_item
*item
= globhist_browser
.root
.child
.next
;
152 struct listbox_data
*box
;
154 if (!globhist_simple_search(dlg
->widgets
[1].data
, dlg
->widgets
[0].data
)) return;
155 if (list_empty(globhist_browser
.root
.child
)) return;
157 /* Shouldn't we rather do this only for the specific listbox_data box
158 * in dlg->widget->data so only the current dialog is updated? --jonas */
159 foreach (box
, globhist_browser
.boxes
) {
166 launch_search_dialog(struct terminal
*term
, struct dialog_data
*parent
,
169 do_edit_dialog(term
, 1, N_("Search history"), gh_last_searched_title
,
170 gh_last_searched_url
, ses
, parent
, history_search_do
,
171 NULL
, NULL
, EDIT_DLG_SEARCH
);
174 static widget_handler_status_T
175 push_search_button(struct dialog_data
*dlg_data
, struct widget_data
*widget_data
)
177 launch_search_dialog(dlg_data
->win
->term
, dlg_data
,
178 (struct session
*) dlg_data
->dlg
->udata
);
179 return EVENT_PROCESSED
;
184 static widget_handler_status_T
185 push_toggle_display_button(struct dialog_data
*dlg_data
, struct widget_data
*widget_data
)
189 display_type
= &get_opt_int("document.history.global.display_type");
190 *display_type
= !*display_type
;
192 update_hierbox_browser(&globhist_browser
);
194 return EVENT_PROCESSED
;
199 #ifdef CONFIG_BOOKMARKS
200 static widget_handler_status_T
201 push_bookmark_button(struct dialog_data
*dlg_data
,
202 struct widget_data
*some_useless_info_button
)
204 struct listbox_data
*box
= get_dlg_listbox_data(dlg_data
);
205 struct terminal
*term
= dlg_data
->win
->term
;
206 struct global_history_item
*historyitem
;
208 if (!box
->sel
) return EVENT_PROCESSED
;
210 historyitem
= box
->sel
->udata
;
211 if (!historyitem
) return EVENT_PROCESSED
;
213 launch_bm_add_dialog(term
, NULL
, NULL
,
214 historyitem
->title
, historyitem
->url
);
216 return EVENT_PROCESSED
;
220 /* The global history manager: */
222 static const struct hierbox_browser_button globhist_buttons
[] = {
223 /* [gettext_accelerator_context(.globhist_buttons)] */
224 { N_("~Goto"), push_hierbox_goto_button
, 1 },
225 { N_("~Info"), push_hierbox_info_button
, 1 },
226 #ifdef CONFIG_BOOKMARKS
227 { N_("~Bookmark"), push_bookmark_button
, 0 },
229 { N_("~Delete"), push_hierbox_delete_button
, 0 },
230 { N_("~Search"), push_search_button
, 1 },
231 { N_("~Toggle display"), push_toggle_display_button
, 1 },
232 { N_("C~lear"), push_hierbox_clear_button
, 0 },
234 /* TODO: Would this be useful? --jonas */
235 { N_("Save"), push_save_button
, 0 },
239 struct_hierbox_browser(
241 N_("Global history manager"),
247 history_manager(struct session
*ses
)
249 mem_free_set(&gh_last_searched_title
, NULL
);
250 mem_free_set(&gh_last_searched_url
, NULL
);
251 hierbox_browser(&globhist_browser
, ses
);