Update Free Software Foundation address.
[metze/wireshark/wip.git] / ui / qt / main_status_bar.cpp
1 /* main_status_bar.cpp
2  *
3  * $Id$
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <glib.h>
29
30 #include "main_status_bar.h"
31
32 #include "wireshark_application.h"
33
34 #include "globals.h"
35
36 #include "ui/main_statusbar.h"
37
38 #include <QSplitter>
39
40 #ifdef HAVE_LIBPCAP
41 #define DEF_READY_MESSAGE QObject::tr(" Ready to load or capture")
42 #else
43 #define DEF_READY_MESSAGE QObject::tr(" Ready to load file")
44 #endif
45
46 // XXX - The GTK+ code assigns priorities to these and pushes/pops accordingly.
47
48 enum StatusContext {
49     STATUS_CTX_MAIN,
50     STATUS_CTX_FILE,
51     STATUS_CTX_FIELD,
52     STATUS_CTX_FILTER,
53     STATUS_CTX_TEMPORARY
54 };
55
56 // If we ever add support for multiple windows this will need to be replaced.
57 // See also: main_window.cpp
58 static MainStatusBar *cur_main_status_bar = NULL;
59
60 /*
61  * Push a formatted temporary message onto the statusbar.
62  */
63 void
64 statusbar_push_temporary_msg(const gchar *msg_format, ...)
65 {
66     va_list ap;
67     gchar *msg;
68     QString pushMsg;
69
70     if (!cur_main_status_bar) return;
71
72     va_start(ap, msg_format);
73     msg = g_strdup_vprintf(msg_format, ap);
74     va_end(ap);
75
76     pushMsg.fromUtf8(msg);
77     g_free(msg);
78
79     cur_main_status_bar->pushTemporaryStatus(pushMsg);
80 }
81
82 /*
83  * Update the packets statusbar to the current values
84  */
85 void
86 packets_bar_update(void)
87 {
88     QString packetsStr = QString("");
89
90     if (!cur_main_status_bar) return;
91
92     cur_main_status_bar->popPacketStatus();
93
94     /* Do we have any packets? */
95     if (cfile.count) {
96         packetsStr.append(QString(QObject::tr("Packets: %1 Displayed: %2 Marked: %3"))
97                           .arg(cfile.count)
98                           .arg(cfile.displayed_count)
99                           .arg(cfile.marked_count));
100         if(cfile.drops_known) {
101             packetsStr.append(QString(QObject::tr(" Dropped: %1")).arg(cfile.drops));
102         }
103         if(cfile.ignored_count > 0) {
104             packetsStr.append(QString(QObject::tr(" Ignored: %1")).arg(cfile.ignored_count));
105         }
106         if(!cfile.is_tempfile) {
107             /* Loading an existing file */
108             gulong computed_elapsed = cf_get_computed_elapsed();
109             packetsStr.append(QString(QObject::tr(" Load time: %1:%2.%3"))
110                                         .arg(computed_elapsed/60000)
111                                         .arg(computed_elapsed%60000/1000)
112                                         .arg(computed_elapsed%1000));
113             /*packetsStr.append(QString().sprintf(QObject::tr(" Load time: %lu:%02lu.%03lu",
114                                         computed_elapsed/60000,
115                                         computed_elapsed%60000/1000,
116                                         computed_elapsed%1000)));
117             */
118         }
119     } else {
120         packetsStr.append(QObject::tr("No Packets"));
121     }
122
123     cur_main_status_bar->pushPacketStatus(packetsStr);
124 }
125
126 MainStatusBar::MainStatusBar(QWidget *parent) :
127     QStatusBar(parent)
128 {
129     QSplitter *splitter = new QSplitter(this);
130     QString readyMsg(DEF_READY_MESSAGE);
131
132     // XXX - Add the expert level icon
133
134     m_infoStatus.setTemporaryContext(STATUS_CTX_TEMPORARY);
135     splitter->addWidget(&m_infoStatus);
136     splitter->addWidget(&m_packetStatus);
137     splitter->addWidget(&m_profileStatus);
138
139     splitter->setStretchFactor(0, 3);
140     splitter->setStretchFactor(1, 3);
141     splitter->setStretchFactor(2, 0);
142
143     addWidget(splitter, 1);
144
145     cur_main_status_bar = this;
146
147     m_infoStatus.pushText(readyMsg, STATUS_CTX_MAIN);
148     packets_bar_update();
149 }
150
151 void MainStatusBar::pushTemporaryStatus(QString &message) {
152     m_infoStatus.pushText(message, STATUS_CTX_TEMPORARY);
153 }
154
155 void MainStatusBar::popTemporaryStatus() {
156     m_infoStatus.popText(STATUS_CTX_TEMPORARY);
157 }
158
159 void MainStatusBar::pushFileStatus(QString &message) {
160     m_infoStatus.pushText(message, STATUS_CTX_FILE);
161 }
162
163 void MainStatusBar::popFileStatus() {
164     m_infoStatus.popText(STATUS_CTX_FILE);
165 }
166
167 void MainStatusBar::pushFieldStatus(QString &message) {
168     m_infoStatus.pushText(message, STATUS_CTX_FIELD);
169 }
170
171 void MainStatusBar::popFieldStatus() {
172     m_infoStatus.popText(STATUS_CTX_FIELD);
173 }
174
175 void MainStatusBar::pushFilterStatus(QString &message) {
176     m_infoStatus.pushText(message, STATUS_CTX_FILTER);
177 }
178
179 void MainStatusBar::popFilterStatus() {
180     m_infoStatus.popText(STATUS_CTX_FILTER);
181 }
182
183 void MainStatusBar::pushPacketStatus(QString &message) {
184     m_packetStatus.pushText(message, STATUS_CTX_MAIN);
185 }
186
187 void MainStatusBar::popPacketStatus() {
188     m_packetStatus.popText(STATUS_CTX_MAIN);
189 }
190
191 void MainStatusBar::pushProfileStatus(QString &message) {
192     m_profileStatus.pushText(message, STATUS_CTX_MAIN);
193 }
194
195 void MainStatusBar::popProfileStatus() {
196     m_profileStatus.popText(STATUS_CTX_MAIN);
197 }
198