1 /* Form history related dialogs */
11 #include "bfu/dialog.h"
12 #include "formhist/dialogs.h"
13 #include "formhist/formhist.h"
14 #include "dialogs/edit.h"
15 #include "document/forms.h"
16 #include "intl/gettext/libintl.h"
17 #include "main/object.h"
18 #include "protocol/uri.h"
19 #include "session/session.h"
20 #include "terminal/terminal.h"
21 #include "util/lists.h"
22 #include "util/memory.h"
23 #include "util/string.h"
24 #include "viewer/text/form.h"
28 lock_formhist_data(struct listbox_item
*item
)
30 object_lock((struct formhist_data
*) item
->udata
);
34 unlock_formhist_data(struct listbox_item
*item
)
36 object_unlock((struct formhist_data
*) item
->udata
);
40 is_formhist_data_used(struct listbox_item
*item
)
42 return is_object_used((struct formhist_data
*) item
->udata
);
45 static unsigned char *
46 get_formhist_data_text(struct listbox_item
*item
, struct terminal
*term
)
48 struct formhist_data
*formhist_data
= item
->udata
;
50 return stracpy(formhist_data
->url
);
53 static unsigned char *
54 get_formhist_data_info(struct listbox_item
*item
, struct terminal
*term
)
56 struct formhist_data
*formhist_data
= item
->udata
;
58 struct submitted_value
*sv
;
60 if (item
->type
== BI_FOLDER
) return NULL
;
61 if (!init_string(&info
)) return NULL
;
63 add_format_to_string(&info
, "%s: %s", _("URL", term
), formhist_data
->url
);
64 add_char_to_string(&info
, '\n');
66 if (formhist_data
->dontsave
)
67 add_to_string(&info
, _("Forms are never saved for this URL.", term
));
69 add_to_string(&info
, _("Forms are saved for this URL.", term
));
71 add_char_to_string(&info
, '\n');
72 foreach (sv
, *formhist_data
->submit
) {
73 add_format_to_string(&info
, "\n[%8s] ", form_type2str(sv
->type
));
75 add_to_string(&info
, sv
->name
);
76 add_to_string(&info
, " = ");
77 if (sv
->value
&& *sv
->value
) {
78 if (sv
->type
!= FC_PASSWORD
)
79 add_to_string(&info
, sv
->value
);
81 add_to_string(&info
, "********");
89 get_formhist_data_uri(struct listbox_item
*item
)
91 struct formhist_data
*formhist_data
= item
->udata
;
93 return get_uri(formhist_data
->url
, 0);
96 static struct listbox_item
*
97 get_formhist_data_root(struct listbox_item
*item
)
103 can_delete_formhist_data(struct listbox_item
*item
)
109 delete_formhist_data(struct listbox_item
*item
, int last
)
111 struct formhist_data
*formhist_data
= item
->udata
;
113 assert(!is_object_used(formhist_data
));
115 delete_formhist_item(formhist_data
);
118 static struct listbox_ops_messages formhist_messages
= {
119 /* cant_delete_item */
120 N_("Sorry, but form \"%s\" cannot be deleted."),
121 /* cant_delete_used_item */
122 N_("Sorry, but form \"%s\" is being used by something else."),
123 /* cant_delete_folder */
125 /* cant_delete_used_folder */
127 /* delete_marked_items_title */
128 N_("Delete marked forms"),
129 /* delete_marked_items */
130 N_("Delete marked forms?"),
131 /* delete_folder_title */
135 /* delete_item_title */
137 /* delete_item; xgettext:c-format */
138 N_("Delete this form?"),
139 /* clear_all_items_title */
140 N_("Clear all forms"),
141 /* clear_all_items_title */
142 N_("Do you really want to remove all forms?"),
145 static const struct listbox_ops formhist_listbox_ops
= {
147 unlock_formhist_data
,
148 is_formhist_data_used
,
149 get_formhist_data_text
,
150 get_formhist_data_info
,
151 get_formhist_data_uri
,
152 get_formhist_data_root
,
154 can_delete_formhist_data
,
155 delete_formhist_data
,
160 static widget_handler_status_T
161 push_login_button(struct dialog_data
*dlg_data
,
162 struct widget_data
*button
)
164 struct listbox_data
*box
= get_dlg_listbox_data(dlg_data
);
165 struct formhist_data
*formhist_data
;
166 struct terminal
*term
= dlg_data
->win
->term
;
168 if (!box
->sel
|| !box
->sel
->udata
) return EVENT_PROCESSED
;
170 formhist_data
= box
->sel
->udata
;
172 if (formhist_data
->dontsave
) {
173 info_box(term
, 0, N_("Form not saved"), ALIGN_CENTER
,
174 N_("No saved information for this URL.\n"
175 "If you want to save passwords for this URL, enable "
176 "it by pressing the \"Toggle saving\" button."));
177 return EVENT_PROCESSED
;
180 push_hierbox_goto_button(dlg_data
, button
);
182 return EVENT_PROCESSED
;
185 static widget_handler_status_T
186 push_toggle_dontsave_button(struct dialog_data
*dlg_data
,
187 struct widget_data
*button
)
189 struct listbox_data
*box
= get_dlg_listbox_data(dlg_data
);
190 struct formhist_data
*formhist_data
;
192 if (!box
->sel
|| !box
->sel
->udata
) return EVENT_PROCESSED
;
194 formhist_data
= box
->sel
->udata
;
196 formhist_data
->dontsave
= !formhist_data
->dontsave
;
197 return EVENT_PROCESSED
;
200 static widget_handler_status_T
201 push_save_button(struct dialog_data
*dlg_data
, struct widget_data
*button
)
203 save_formhist_to_file();
204 return EVENT_PROCESSED
;
207 static const struct hierbox_browser_button formhist_buttons
[] = {
208 /* [gettext_accelerator_context(.formhist_buttons)] */
209 { N_("~Login"), push_login_button
, 1 },
210 { N_("~Info"), push_hierbox_info_button
, 1 },
211 { N_("~Delete"), push_hierbox_delete_button
, 1 },
212 { N_("~Toggle saving"), push_toggle_dontsave_button
, 0 },
213 { N_("Clea~r"), push_hierbox_clear_button
, 1 },
214 { N_("Sa~ve"), push_save_button
, 0 },
217 struct_hierbox_browser(
219 N_("Form history manager"),
221 &formhist_listbox_ops
225 formhist_manager(struct session
*ses
)
227 load_formhist_from_file();
228 hierbox_browser(&formhist_browser
, ses
);