aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/main_titlebar.c
blob: 9b8ee56538ade9ec68517e8e67a3252620a8a5c5 (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
/* main_titlebar.c
 * Main window title bar routines.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/prefs.h>

#include <gtk/gtk.h>

#include "file.h"

#include "gtkglobals.h"
#include "gui_utils.h"
#include "main_titlebar.h"

#include <version_info.h>

/*
 * Key to attach the "un-decorated" title to the window, so that if the
 * user-specified decoration changes, we can correctly update the
 * window title.
 */
#define MAIN_WINDOW_NAME_KEY  "main_window_name"

/* Set the name of the top level main_window_name with the specified string and call
   main_titlebar_update() to construct the full title and display it in the main window. */
static void
main_set_window_name(const gchar *window_name)
{
    gchar *old_window_name;

    /* Attach the new un-decorated window name to the window. */
    old_window_name = (gchar *)g_object_get_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY);
    g_free(old_window_name);
    g_object_set_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY, g_strdup(window_name));

    main_titlebar_update();
}

/* Construct the main window's title with the current main_window_name, optionally appended
   with the user-specified title and/or wireshark version. Display the result in the main
   window title bar. */
void
main_titlebar_update(void)
{
    gchar *window_name;
    gchar *title;

    /* Get the current filename or other title set in main_set_window_name */
    window_name = (gchar *)g_object_get_data(G_OBJECT(top_level), MAIN_WINDOW_NAME_KEY);
    if (window_name != NULL) {
        /* Optionally append the user-defined window title */
        title = create_user_window_title(window_name);

        /* Optionally append the version */
        if ((prefs.gui_version_placement == version_title_only) ||
            (prefs.gui_version_placement == version_both)) {
            gchar *old_title = title;
            title = g_strdup_printf("%s [Wireshark %s]", title, get_ws_vcs_version_info());
            g_free(old_title);
        }
        gtk_window_set_title(GTK_WINDOW(top_level), title);
        g_free(title);
    }
}

/* Set titlebar to reflect the current state of the capture file, if any */
void
set_titlebar_for_capture_file(capture_file *cf)
{
    gchar *display_name;
    gchar *window_name;

    if (cf && cf->filename) {
        display_name = cf_get_display_name(cf);
        window_name = g_strdup_printf("%s%s", cf_has_unsaved_data(cf) ? "*" : "",
                                      display_name);
        g_free(display_name);
        main_set_window_name(window_name);
        g_free(window_name);
    } else {
        main_set_window_name("The Wireshark Network Analyzer");
    }
}

/* Set titlebar to reflect a capture in progress */
void
set_titlebar_for_capture_in_progress(capture_file *cf)
{
    gchar *window_name;

    window_name = g_strdup_printf("Capturing from %s", cf_get_tempfile_source(cf));
    main_set_window_name(window_name);
    g_free(window_name);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */