test: The CGI script showing POST DATA sent to it.
[elinks.git] / src / dialogs / info.c
blobf9b6e8b4d83fec55410b77978d3110ecc350d704
1 /* Info dialogs */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #ifdef HAVE_UNISTD_H
11 #include <unistd.h>
12 #endif
14 #include "elinks.h"
16 #include "bfu/dialog.h"
17 #include "cache/cache.h"
18 #include "config/kbdbind.h"
19 #include "config/options.h"
20 #include "dialogs/info.h"
21 #include "document/html/renderer.h"
22 #include "intl/gettext/libintl.h"
23 #include "main/select.h"
24 #include "main/timer.h"
25 #include "main/version.h"
26 #include "network/connection.h"
27 #include "session/session.h"
28 #include "terminal/terminal.h"
29 #include "util/conv.h"
30 #ifdef DEBUG_MEMLEAK
31 #include "util/memdebug.h"
32 #endif
33 #include "util/memlist.h"
34 #include "util/memory.h"
35 #include "util/string.h"
37 void
38 menu_about(struct terminal *term, void *xxx, void *xxxx)
40 info_box(term, MSGBOX_FREE_TEXT,
41 N_("About"), ALIGN_CENTER,
42 get_dyn_full_version(term, 1));
45 struct keys_toggle_info {
46 struct terminal *term;
47 int toggle;
50 static void
51 push_toggle_keys_display_button(void *data)
53 struct keys_toggle_info *info = data;
55 menu_keys(info->term, (void *) (long) !info->toggle, NULL);
58 void
59 menu_keys(struct terminal *term, void *d_, void *xxx)
61 /* [gettext_accelerator_context(menu_keys)] */
62 int d = (long) d_;
64 /* We scale by main mapping because it has the most actions */
65 action_id_T action_ids[MAIN_ACTIONS] = {
66 ACT_MAIN_MENU,
67 ACT_MAIN_QUIT,
68 ACT_MAIN_MOVE_LINK_NEXT,
69 ACT_MAIN_MOVE_LINK_PREV,
70 ACT_MAIN_SCROLL_DOWN,
71 ACT_MAIN_SCROLL_UP,
72 ACT_MAIN_SCROLL_LEFT,
73 ACT_MAIN_SCROLL_RIGHT,
74 ACT_MAIN_HISTORY_MOVE_BACK,
75 ACT_MAIN_GOTO_URL,
76 ACT_MAIN_GOTO_URL_CURRENT,
77 ACT_MAIN_DOCUMENT_INFO,
78 ACT_MAIN_HEADER_INFO,
79 ACT_MAIN_SEARCH,
80 ACT_MAIN_SEARCH_BACK,
81 ACT_MAIN_FIND_NEXT,
82 ACT_MAIN_FIND_NEXT_BACK,
83 ACT_MAIN_LINK_FOLLOW,
84 ACT_MAIN_LINK_DOWNLOAD,
85 ACT_MAIN_TOGGLE_HTML_PLAIN,
87 ACT_MAIN_NONE,
89 struct string keys;
90 struct keys_toggle_info *info;
92 info = mem_calloc(1, sizeof(*info));
94 if (!info || !init_string(&keys)) {
95 mem_free_if(info);
96 return;
99 info->term = term;
100 info->toggle = d;
102 if (info->toggle) {
103 action_id_T action_id;
104 enum keymap_id keymap_id;
106 for (action_id = 0; action_id < MAIN_ACTIONS - 1; action_id++) {
107 action_ids[action_id] = action_id + 1;
110 for (keymap_id = 0; keymap_id < KEYMAP_MAX; keymap_id++) {
111 add_actions_to_string(&keys, action_ids, keymap_id, term);
112 if (keymap_id + 1 < KEYMAP_MAX)
113 add_to_string(&keys, "\n\n");
115 /* Just a little reminder that the following code takes
116 * the easy way. */
117 assert(MAIN_ACTIONS > EDIT_ACTIONS);
118 assert(EDIT_ACTIONS > MENU_ACTIONS);
120 if (keymap_id == KEYMAP_MAIN) {
121 action_ids[EDIT_ACTIONS] = ACT_EDIT_NONE;
122 } else if (keymap_id == KEYMAP_EDIT) {
123 action_ids[MENU_ACTIONS] = ACT_MENU_NONE;
126 } else {
127 add_actions_to_string(&keys, action_ids, KEYMAP_MAIN, term);
130 msg_box(term, getml(info, NULL), MSGBOX_FREE_TEXT | MSGBOX_SCROLLABLE,
131 N_("Keys"), ALIGN_LEFT,
132 keys.source,
133 info, 2,
134 N_("~OK"), NULL, B_ENTER | B_ESC,
135 N_("~Toggle display"), push_toggle_keys_display_button, B_ENTER);
138 void
139 menu_copying(struct terminal *term, void *xxx, void *xxxx)
141 info_box(term, MSGBOX_FREE_TEXT,
142 N_("Copying"), ALIGN_CENTER,
143 msg_text(term, N_("ELinks %s\n"
144 "\n"
145 "(C) 1999 - 2002 Mikulas Patocka\n"
146 "(C) 2001 - 2004 Petr Baudis\n"
147 "(C) 2002 - 2006 Jonas Fonseca\n"
148 "and others\n"
149 "\n"
150 "This program is free software; you can redistribute it "
151 "and/or modify it under the terms of the GNU General Public "
152 "License as published by the Free Software Foundation, "
153 "specifically version 2 of the License."),
154 VERSION_STRING));
158 static unsigned char *
159 get_resource_info(struct terminal *term, void *data)
161 struct string info;
162 long val;
163 unsigned longlong bigval;
165 if (!init_string(&info))
166 return NULL;
168 #define val_add(text) \
169 add_format_to_string(&info, text, val);
171 add_to_string(&info, _("Resources", term));
172 add_to_string(&info, ": ");
174 val = get_file_handles_count();
175 val_add(n_("%ld handle", "%ld handles", val, term));
176 add_to_string(&info, ", ");
178 val = get_timers_count();
179 val_add(n_("%ld timer", "%ld timers", val, term));
180 add_to_string(&info, ".\n");
182 add_to_string(&info, _("Connections", term));
183 add_to_string(&info, ": ");
185 val = get_connections_count();
186 val_add(n_("%ld connection", "%ld connections", val, term));
187 add_to_string(&info, ", ");
189 val = get_connections_connecting_count();
190 val_add(n_("%ld connecting", "%ld connecting", val, term));
191 add_to_string(&info, ", ");
193 val = get_connections_transfering_count();
194 val_add(n_("%ld transferring", "%ld transferring", val, term));
195 add_to_string(&info, ", ");
197 val = get_keepalive_connections_count();
198 val_add(n_("%ld keepalive", "%ld keepalive", val, term));
199 add_to_string(&info, ".\n");
201 add_to_string(&info, _("Memory cache", term));
202 add_to_string(&info, ": ");
204 /* What about just using Kibi/Mebi representation here? --jonas */
205 bigval = get_cache_size();
206 add_format_to_string(&info, n_("%ld byte", "%ld bytes", bigval, term), bigval);
207 add_to_string(&info, ", ");
209 val = get_cache_entry_count();
210 val_add(n_("%ld file", "%ld files", val, term));
211 add_to_string(&info, ", ");
213 val = get_cache_entry_used_count();
214 val_add(n_("%ld in use", "%ld in use", val, term));
215 add_to_string(&info, ", ");
217 val = get_cache_entry_loading_count();
218 val_add(n_("%ld loading", "%ld loading", val, term));
219 add_to_string(&info, ".\n");
221 add_to_string(&info, _("Document cache", term));
222 add_to_string(&info, ": ");
224 val = get_format_cache_size();
225 val_add(n_("%ld formatted", "%ld formatted", val, term));
226 add_to_string(&info, ", ");
228 val = get_format_cache_used_count();
229 val_add(n_("%ld in use", "%ld in use", val, term));
230 add_to_string(&info, ", ");
232 val = get_format_cache_refresh_count();
233 val_add(n_("%ld refreshing", "%ld refreshing", val, term));
234 add_to_string(&info, ".\n");
236 add_to_string(&info, _("Interlinking", term));
237 add_to_string(&info, ": ");
238 if (term->master)
239 add_to_string(&info, _("master terminal", term));
240 else
241 add_to_string(&info, _("slave terminal", term));
242 add_to_string(&info, ", ");
244 val = list_size(&terminals);
245 val_add(n_("%ld terminal", "%ld terminals", val, term));
246 add_to_string(&info, ", ");
248 val = list_size(&sessions);
249 val_add(n_("%ld session", "%ld sessions", val, term));
250 add_char_to_string(&info, '.');
252 #ifdef DEBUG_MEMLEAK
253 add_char_to_string(&info, '\n');
254 add_to_string(&info, _("Memory allocated", term));
255 add_to_string(&info, ": ");
257 val = mem_stats.amount;
258 val_add(n_("%ld byte", "%ld bytes", val, term));
259 add_to_string(&info, ", ");
261 val = mem_stats.true_amount - mem_stats.amount;
262 val_add(n_("%ld byte overhead", "%ld bytes overhead", val, term));
264 add_format_to_string(&info, " (%0.2f%%).",
265 (double) (mem_stats.true_amount - mem_stats.amount) / (double) mem_stats.amount * 100);
266 #endif /* DEBUG_MEMLEAK */
268 #undef val_add
270 return info.source;
273 void
274 resource_info(struct terminal *term)
276 refreshed_msg_box(term, 0, N_("Resources"), ALIGN_LEFT,
277 get_resource_info, NULL);