aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/main_status_bar.cpp
blob: 8627c3c14eda1c0f3aa53786b5f2f4848a5e9fa9 (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
/* main_status_bar.cpp
 *
 * $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.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <glib.h>

#include "main_status_bar.h"

#include "wireshark_application.h"

#include "globals.h"

#include "ui/main_statusbar.h"

#include <QSplitter>

#ifdef HAVE_LIBPCAP
#define DEF_READY_MESSAGE QObject::tr(" Ready to load or capture")
#else
#define DEF_READY_MESSAGE QObject::tr(" Ready to load file")
#endif

// XXX - The GTK+ code assigns priorities to these and pushes/pops accordingly.

enum StatusContext {
    STATUS_CTX_MAIN,
    STATUS_CTX_FILE,
    STATUS_CTX_FIELD,
    STATUS_CTX_FILTER,
    STATUS_CTX_TEMPORARY
};

// If we ever add support for multiple windows this will need to be replaced.
// See also: main_window.cpp
static MainStatusBar *cur_main_status_bar = NULL;

/*
 * Push a formatted temporary message onto the statusbar.
 */
void
statusbar_push_temporary_msg(const gchar *msg_format, ...)
{
    va_list ap;
    gchar *msg;
    QString pushMsg;

    if (!cur_main_status_bar) return;

    va_start(ap, msg_format);
    msg = g_strdup_vprintf(msg_format, ap);
    va_end(ap);

    pushMsg.fromUtf8(msg);
    g_free(msg);

    cur_main_status_bar->pushTemporaryStatus(pushMsg);
}

/*
 * Update the packets statusbar to the current values
 */
void
packets_bar_update(void)
{
    QString packetsStr = QString("");

    if (!cur_main_status_bar) return;

    cur_main_status_bar->popPacketStatus();

    /* Do we have any packets? */
    if (cfile.count) {
        packetsStr.append(QString(QObject::tr("Packets: %1 Displayed: %2 Marked: %3"))
                          .arg(cfile.count)
                          .arg(cfile.displayed_count)
                          .arg(cfile.marked_count));
        if(cfile.drops_known) {
            packetsStr.append(QString(QObject::tr(" Dropped: %1")).arg(cfile.drops));
        }
        if(cfile.ignored_count > 0) {
            packetsStr.append(QString(QObject::tr(" Ignored: %1")).arg(cfile.ignored_count));
        }
        if(!cfile.is_tempfile) {
            /* Loading an existing file */
            gulong computed_elapsed = cf_get_computed_elapsed();
            packetsStr.append(QString(QObject::tr(" Load time: %1:%2.%3"))
                                        .arg(computed_elapsed/60000)
                                        .arg(computed_elapsed%60000/1000)
                                        .arg(computed_elapsed%1000));
            /*packetsStr.append(QString().sprintf(QObject::tr(" Load time: %lu:%02lu.%03lu",
                                        computed_elapsed/60000,
                                        computed_elapsed%60000/1000,
                                        computed_elapsed%1000)));
            */
        }
    } else {
        packetsStr.append(QObject::tr("No Packets"));
    }

    cur_main_status_bar->pushPacketStatus(packetsStr);
}

MainStatusBar::MainStatusBar(QWidget *parent) :
    QStatusBar(parent)
{
    QSplitter *splitter = new QSplitter(this);
    QString readyMsg(DEF_READY_MESSAGE);

    // XXX - Add the expert level icon

    m_infoStatus.setTemporaryContext(STATUS_CTX_TEMPORARY);
    splitter->addWidget(&m_infoStatus);
    splitter->addWidget(&m_packetStatus);
    splitter->addWidget(&m_profileStatus);

    splitter->setStretchFactor(0, 3);
    splitter->setStretchFactor(1, 3);
    splitter->setStretchFactor(2, 0);

    addWidget(splitter, 1);

    cur_main_status_bar = this;

    m_infoStatus.pushText(readyMsg, STATUS_CTX_MAIN);
    packets_bar_update();
}

void MainStatusBar::pushTemporaryStatus(QString &message) {
    m_infoStatus.pushText(message, STATUS_CTX_TEMPORARY);
}

void MainStatusBar::popTemporaryStatus() {
    m_infoStatus.popText(STATUS_CTX_TEMPORARY);
}

void MainStatusBar::pushFileStatus(QString &message) {
    m_infoStatus.pushText(message, STATUS_CTX_FILE);
}

void MainStatusBar::popFileStatus() {
    m_infoStatus.popText(STATUS_CTX_FILE);
}

void MainStatusBar::pushFieldStatus(QString &message) {
    m_infoStatus.pushText(message, STATUS_CTX_FIELD);
}

void MainStatusBar::popFieldStatus() {
    m_infoStatus.popText(STATUS_CTX_FIELD);
}

void MainStatusBar::pushFilterStatus(QString &message) {
    m_infoStatus.pushText(message, STATUS_CTX_FILTER);
}

void MainStatusBar::popFilterStatus() {
    m_infoStatus.popText(STATUS_CTX_FILTER);
}

void MainStatusBar::pushPacketStatus(QString &message) {
    m_packetStatus.pushText(message, STATUS_CTX_MAIN);
}

void MainStatusBar::popPacketStatus() {
    m_packetStatus.popText(STATUS_CTX_MAIN);
}

void MainStatusBar::pushProfileStatus(QString &message) {
    m_profileStatus.pushText(message, STATUS_CTX_MAIN);
}

void MainStatusBar::popProfileStatus() {
    m_profileStatus.popText(STATUS_CTX_MAIN);
}