aboutsummaryrefslogtreecommitdiffstats
path: root/gtk/main_welcome.c
blob: cc413e69b8f1c4cdb6ccf108ef900a8f3ffc6c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
/* main_welcome.c
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */


#include <gtk/gtk.h>

#include "gui_utils.h"
#include "recent.h"
#include "main_welcome.h"


#ifdef SHOW_WELCOME_PAGE
#include "../image/wssplash.xpm"
#endif


/*#define SHOW_WELCOME_PAGE*/
#ifdef SHOW_WELCOME_PAGE
/* XXX - There seems to be some disagreement about if and how this feature should be implemented.
   As I currently don't have the time to continue this, it's temporarily disabled. - ULFL */
GtkWidget *
welcome_item(const gchar *stock_item, const gchar * label, const gchar * message, const gchar * tooltip,
			 GtkSignalFunc callback, void *callback_data)
{
    GtkWidget *w, *item_hb;
#if GTK_MAJOR_VERSION >= 2
    gchar *formatted_message;
    GtkTooltips *tooltips;

    tooltips = gtk_tooltips_new();
#endif

    item_hb = gtk_hbox_new(FALSE, 1);

    w = BUTTON_NEW_FROM_STOCK(stock_item);
    WIDGET_SET_SIZE(w, 80, 40);
#if GTK_MAJOR_VERSION >= 2
    gtk_button_set_label(GTK_BUTTON(w), label);
    gtk_tooltips_set_tip(tooltips, w, tooltip, NULL);
#endif
    gtk_box_pack_start(GTK_BOX(item_hb), w, FALSE, FALSE, 0);
    SIGNAL_CONNECT(w, "clicked", callback, callback_data);

    w = gtk_label_new(message);
    gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.5);
#if GTK_MAJOR_VERSION >= 2
    formatted_message = g_strdup_printf("<span weight=\"bold\" size=\"x-large\">%s</span>", message);
    gtk_label_set_markup(GTK_LABEL(w), formatted_message);
    g_free(formatted_message);
#endif

    gtk_box_pack_start(GTK_BOX(item_hb), w, FALSE, FALSE, 10);

    return item_hb;
}


GtkWidget *
welcome_header_new(void)
{
    GtkWidget *item_vb;
    GtkWidget *item_hb;
    GtkWidget *eb;
    GdkColor bg;
    GtkWidget *icon;
    gchar *message;
    GtkWidget *w;


    /* background color of the header bar */
    bg.pixel = 0;
    bg.red = 154 * 255;
    bg.green = 210 * 255;
    bg.blue = 229 * 255;

    item_vb = gtk_vbox_new(FALSE, 0);

    /* colorize vbox */
    get_color(&bg);
    eb = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(eb), item_vb);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &bg);
#endif

    item_hb = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(item_vb), item_hb, FALSE, FALSE, 10);

    icon = xpm_to_widget_from_parent(top_level, wssplash_xpm);
    /*icon = xpm_to_widget_from_parent(top_level, wsicon64_xpm);*/
    gtk_box_pack_start(GTK_BOX(item_hb), icon, FALSE, FALSE, 10);

#if GTK_MAJOR_VERSION < 2
    message = "The World's Most Popular Network Protocol Analyzer";
#else
    message = "<span weight=\"bold\" size=\"x-large\">" "The World's Most Popular Network Protocol Analyzer" "</span>";
#endif
    w = gtk_label_new(message);
#if GTK_MAJOR_VERSION >= 2
    gtk_label_set_markup(GTK_LABEL(w), message);
#endif
    gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.5);
    gtk_box_pack_start(GTK_BOX(item_hb), w, TRUE, TRUE, 5);

    gtk_widget_show_all(eb);

    return eb;
}

GtkWidget *
welcome_topic_header_new(const char *header)
{
    GtkWidget *w;
    GdkColor bg;
    GtkWidget *eb;
#if GTK_MAJOR_VERSION >= 2
    gchar *formatted_message;
#endif


    w = gtk_label_new(header);
#if GTK_MAJOR_VERSION >= 2
    formatted_message = g_strdup_printf("<span weight=\"bold\" size=\"x-large\">%s</span>", header);
    gtk_label_set_markup(GTK_LABEL(w), formatted_message);
    g_free(formatted_message);
#endif

    /* topic header background color */
    bg.pixel = 0;
    bg.red = 24 * 255;
    bg.green = 151 * 255;
    bg.blue = 192 * 255;

    /* colorize vbox */
    get_color(&bg);
    eb = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(eb), w);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(eb, GTK_STATE_NORMAL, &bg);
#endif

    return eb;
}


GtkWidget *
welcome_topic_new(const char *header, GtkWidget **to_fill)
{
    GtkWidget *topic_vb;
    GtkWidget *layout_vb;
    GtkWidget *topic_eb;
    GtkWidget *topic_header;
    GdkColor bg;

    topic_vb = gtk_vbox_new(FALSE, 0);

	/* topic content background color */
    bg.pixel = 0;
    bg.red = 221 * 255;
    bg.green = 226 * 255;
    bg.blue = 228 * 255;

    topic_header = welcome_topic_header_new(header);
    gtk_box_pack_start(GTK_BOX(topic_vb), topic_header, FALSE, FALSE, 0);

    layout_vb = gtk_vbox_new(FALSE, 5);
    gtk_container_border_width(GTK_CONTAINER(layout_vb), 10);
    gtk_box_pack_start(GTK_BOX(topic_vb), layout_vb, FALSE, FALSE, 0);

    /* colorize vbox (we need an event box for this!) */
    get_color(&bg);
    topic_eb = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(topic_eb), topic_vb);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(topic_eb, GTK_STATE_NORMAL, &bg);
#endif
    *to_fill = layout_vb;

    return topic_eb;
}


#if GTK_MAJOR_VERSION >= 2
static gboolean
welcome_link_enter_cb(GtkWidget *widget _U_, GdkEventCrossing *event _U_, gpointer user_data)
{
    gchar *message;
    GtkWidget *w = user_data;

    message = g_strdup_printf("<span foreground='blue' underline='single'>%s</span>", OBJECT_GET_DATA(w,"TEXT"));
#if GTK_MAJOR_VERSION >= 2
    gtk_label_set_markup(GTK_LABEL(w), message);
#endif
    g_free(message);

    return FALSE;
}

static gboolean
welcome_link_leave_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer user_data)
{
    gchar *message;
    GtkWidget *w = user_data;

    message = g_strdup_printf("<span foreground='blue'>%s</span>", OBJECT_GET_DATA(w,"TEXT"));
#if GTK_MAJOR_VERSION >= 2
    gtk_label_set_markup(GTK_LABEL(w), message);
#endif
    g_free(message);

    return FALSE;
}
#endif


static gboolean
welcome_link_press_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer data _U_) {

    g_warning("TBD: link pressed");

    return FALSE;
}

GtkWidget *
welcome_link_new(const gchar *text, GtkWidget **label /*, void *callback, void *private_data */)
{
    gchar *message;
    GtkWidget *w;
    GtkWidget *eb;

#if GTK_MAJOR_VERSION < 2
    message = g_strdup(text);
#else
    message = g_strdup_printf("<span foreground='blue'>%s</span>", text);
#endif
    w = gtk_label_new(message);
    *label = w;
#if GTK_MAJOR_VERSION >= 2
    gtk_label_set_markup(GTK_LABEL(w), message);
#endif
    g_free(message);

	/* event box */
    eb = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(eb), w);

#if GTK_MAJOR_VERSION >= 2
    SIGNAL_CONNECT(eb, "enter-notify-event", welcome_link_enter_cb, w);
    SIGNAL_CONNECT(eb, "leave-notify-event", welcome_link_leave_cb, w);
#endif
    SIGNAL_CONNECT(eb, "button-press-event", welcome_link_press_cb, w);

    /* XXX - memleak */
    OBJECT_SET_DATA(w, "TEXT", g_strdup(text));

    return eb;
}

GtkWidget *
welcome_filename_link_new(const char *filename, GtkWidget **label)
{
    GString		*str;
    GtkWidget	*w;
    const unsigned int max = 60;


    str = g_string_new(filename);

    if(str->len > max) {
        g_string_erase(str, 0, str->len-max /*cut*/);
        g_string_prepend(str, "... ");
    }

    w = welcome_link_new(str->str, label);

    g_string_free(str, TRUE);

    return w;
}


GtkWidget *
welcome_if_new(const char *if_name, GdkColor *topic_bg, gboolean active)
{
    GtkWidget *interface_hb;
    GtkWidget *w;
    GtkWidget *label;
    GtkTooltips *tooltips;
    GString   *message;


    tooltips = gtk_tooltips_new();

    interface_hb = gtk_hbox_new(FALSE, 5);

    w = welcome_link_new("START", &label);
    gtk_tooltips_set_tip(tooltips, w, "Immediately start a capture on this interface", NULL);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 0);

    w = welcome_link_new("OPTIONS", &label);
    gtk_tooltips_set_tip(tooltips, w, "Show the capture options of this interface", NULL);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 0);

    w = welcome_link_new("DETAILS", &label);
    gtk_tooltips_set_tip(tooltips, w, "Show detailed information about this interface", NULL);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 0);

    message = g_string_new(if_name);

    /* truncate string if it's too long */
    if(message->len > 38) {
        g_string_truncate(message, 35);
        g_string_append  (message, " ...");
    }
#if GTK_MAJOR_VERSION >= 2
    /* if this is the "active" interface, display it bold */
    if(active) {
        g_string_prepend(message, "<span weight=\"bold\">");
        g_string_append (message, "</span>");
	}
#endif
    w = gtk_label_new(message->str);
#if GTK_MAJOR_VERSION >= 2
    gtk_label_set_markup(GTK_LABEL(w), message->str);
#endif
    g_string_free(message, TRUE);

    gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(interface_hb), w, FALSE, FALSE, 0);

    return interface_hb;
}

/* XXX - the layout has to be improved */
GtkWidget *
welcome_new(void)
{
    GtkWidget *welcome_scrollw;
    GtkWidget *welcome_vb;
    GtkWidget *welcome_hb;
    GtkWidget *column_vb;
    GtkWidget *item_hb;
    GtkWidget *w;
    GtkWidget *label;
    GtkWidget *header;
    GtkWidget *topic_vb;
    GtkWidget *topic_to_fill;
    GtkWidget *interface_hb;
    GdkColor  topic_bg;


    /* topic content background color */
    topic_bg.pixel = 0;
    topic_bg.red = 221 * 255;
    topic_bg.green = 226 * 255;
    topic_bg.blue = 228 * 255;

    welcome_scrollw = scrolled_window_new(NULL, NULL);

    welcome_vb = gtk_vbox_new(FALSE, 0);

    /* header */
    header = welcome_header_new();
    gtk_box_pack_start(GTK_BOX(welcome_vb), header, FALSE, FALSE, 0);

    /* content */
    welcome_hb = gtk_hbox_new(FALSE, 10);
    gtk_container_border_width(GTK_CONTAINER(welcome_hb), 10);
    gtk_box_pack_start(GTK_BOX(welcome_vb), welcome_hb, TRUE, TRUE, 0);

    /* column capture */
    column_vb = gtk_vbox_new(FALSE, 10);
    gtk_box_pack_start(GTK_BOX(welcome_hb), column_vb, TRUE, TRUE, 0);

    /* capture topic */
    topic_vb = welcome_topic_new("Capture", &topic_to_fill);
    gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);

#ifdef HAVE_LIBPCAP
    item_hb = welcome_item(WIRESHARK_STOCK_CAPTURE_INTERFACES,
        "Interfaces...",
        "Interface Life List",
		"Show a life list of the available capture interfaces",
        GTK_SIGNAL_FUNC(capture_if_cb), NULL);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
#endif

    w = gtk_label_new("Available Interfaces:");
    gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 5);

    interface_hb = welcome_if_new("Generic dialup adapter", &topic_bg, FALSE);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), interface_hb, FALSE, FALSE, 0);

    /* Marvell interface (currently "active") */
    interface_hb = welcome_if_new("Marvell Gigabit Ethernet Controller", &topic_bg, TRUE);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), interface_hb, FALSE, FALSE, 0);

    /* Wireless interface */
    interface_hb = welcome_if_new("Intel(R) PRO/Wireless 3945ABG Network Connection", &topic_bg, FALSE);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), interface_hb, FALSE, FALSE, 0);


    /* capture help topic */
    topic_vb = welcome_topic_new("Capture Help", &topic_to_fill);
    gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);

#ifdef HAVE_LIBPCAP
    item_hb = welcome_item(WIRESHARK_STOCK_CAPTURE_START,
        "Setup",
		"How To: Setup a Capture",
		"How To: Setup a Capture (online from the Wiki)",
        GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_USERGUIDE));
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);

    item_hb = welcome_item(WIRESHARK_STOCK_CAPTURE_START,
        "Examples",
		"Capture Filter Examples",
		"Capture Filter Examples (online from the Wiki)",
        GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_USERGUIDE));
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
#endif

    /* fill bottom space */
    w = gtk_label_new("");
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, TRUE, TRUE, 0);


    /* column files */
    topic_vb = welcome_topic_new("Files", &topic_to_fill);
    gtk_box_pack_start(GTK_BOX(welcome_hb), topic_vb, TRUE, TRUE, 0);

    item_hb = welcome_item(GTK_STOCK_OPEN,
        "Open...",
        "Open a Capture File",
		"Open a previously captured file",
        GTK_SIGNAL_FUNC(file_open_cmd_cb), NULL);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);

    item_hb = welcome_item(GTK_STOCK_OPEN,
        "Examples",
        "Download Examples",
		"Download Example Capture Files (from the Wiki)",
        GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_USERGUIDE));
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);

    w = gtk_label_new("Recent Files:");
    gtk_misc_set_alignment (GTK_MISC(w), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 5);

    w = welcome_link_new("C:\\Testfiles\\hello.pcap", &label);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 0);

    w = welcome_filename_link_new("C:\\Testfiles\\hello2.pcap", &label);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 0);

    w = welcome_filename_link_new(
		"C:\\Testfiles\\to avoid screen garbage\\Unfortunately this is a very long filename which had to be truncated.pcap",
		&label);
#if GTK_MAJOR_VERSION >= 2
    gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &topic_bg);
#endif
    gtk_misc_set_alignment (GTK_MISC(label), 0.0, 0.0);
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, FALSE, FALSE, 0);

    w = gtk_label_new("");
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, TRUE, TRUE, 0);


    /* column online */
    column_vb = gtk_vbox_new(FALSE, 10);
    gtk_box_pack_start(GTK_BOX(welcome_hb), column_vb, TRUE, TRUE, 0);

    /* topic online */
    topic_vb = welcome_topic_new("Online", &topic_to_fill);
    gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);

#if (GLIB_MAJOR_VERSION >= 2)
    item_hb = welcome_item(WIRESHARK_STOCK_WEB_SUPPORT,
        "Help",
        "Show the User's Guide",
		"Show the User's Guide (local version, if available)",
        GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_USERGUIDE));
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);

    item_hb = welcome_item(GTK_STOCK_HOME,
        "Home",
        "Projects Home Page",
		"Visit www.wireshark.org, the project's home page",
        GTK_SIGNAL_FUNC(topic_cb), GINT_TO_POINTER(ONLINEPAGE_HOME));
    gtk_box_pack_start(GTK_BOX(topic_to_fill), item_hb, FALSE, FALSE, 5);
#endif

    /* topic updates */
    topic_vb = welcome_topic_new("Updates", &topic_to_fill);
    gtk_box_pack_start(GTK_BOX(column_vb), topic_vb, TRUE, TRUE, 0);

    w = gtk_label_new("No updates available!");
    gtk_box_pack_start(GTK_BOX(topic_to_fill), w, TRUE, TRUE, 0);


    /* the end */
    gtk_widget_show_all(welcome_vb);

    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(welcome_scrollw),
                                          welcome_vb);
    gtk_widget_show_all(welcome_scrollw);

    return welcome_scrollw;
}
#else
GtkWidget *
welcome_new(void)
{
    /* this is just a dummy to fill up window space, simply showing nothing */
    return scrolled_window_new(NULL, NULL);
}
#endif