5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #include "main_status_bar.h"
32 #include "wireshark_application.h"
36 #include "epan/expert.h"
38 #include "ui/main_statusbar.h"
39 #include "ui/utf8_entities.h"
42 #include <QHBoxLayout>
45 #define DEF_READY_MESSAGE QObject::tr(" Ready to load or capture")
47 #define DEF_READY_MESSAGE QObject::tr(" Ready to load file")
50 // XXX - The GTK+ code assigns priorities to these and pushes/pops accordingly.
60 // If we ever add support for multiple windows this will need to be replaced.
61 // See also: main_window.cpp
62 static MainStatusBar *cur_main_status_bar = NULL;
65 * Push a formatted temporary message onto the statusbar.
68 statusbar_push_temporary_msg(const gchar *msg_format, ...)
74 if (!cur_main_status_bar) return;
76 va_start(ap, msg_format);
77 msg = g_strdup_vprintf(msg_format, ap);
80 pushMsg.fromUtf8(msg);
83 cur_main_status_bar->pushTemporaryStatus(pushMsg);
87 * Update the packets statusbar to the current values
90 packets_bar_update(void)
92 QString packetsStr = QString("");
94 if (!cur_main_status_bar) return;
96 cur_main_status_bar->popPacketStatus();
98 /* Do we have any packets? */
100 packetsStr.append(QString("Packets: %1 " UTF8_MIDDLE_DOT " Displayed: %2 " UTF8_MIDDLE_DOT " Marked: %3")
101 // packetsStr.append(QString(QObject::tr("Packets: %1 Displayed: %2 Marked: %3"))
103 .arg(cfile.displayed_count)
104 .arg(cfile.marked_count));
105 if(cfile.drops_known) {
106 packetsStr.append(QString(" " UTF8_MIDDLE_DOT " Dropped: %1")).arg(cfile.drops);
108 if(cfile.ignored_count > 0) {
109 packetsStr.append(QString(" " UTF8_MIDDLE_DOT " Ignored: %1").arg(cfile.ignored_count));
111 if(!cfile.is_tempfile) {
112 /* Loading an existing file */
113 gulong computed_elapsed = cf_get_computed_elapsed();
114 packetsStr.append(QString(" " UTF8_MIDDLE_DOT " Load time: %1:%2.%3")
115 .arg(computed_elapsed/60000)
116 .arg(computed_elapsed%60000/1000)
117 .arg(computed_elapsed%1000));
118 /*packetsStr.append(QString().sprintf(QObject::tr(" Load time: %lu:%02lu.%03lu",
119 computed_elapsed/60000,
120 computed_elapsed%60000/1000,
121 computed_elapsed%1000)));
125 packetsStr.append(QObject::tr("No Packets"));
128 cur_main_status_bar->pushPacketStatus(packetsStr);
131 MainStatusBar::MainStatusBar(QWidget *parent) :
134 QSplitter *splitter = new QSplitter(this);
135 QString readyMsg(DEF_READY_MESSAGE);
136 QWidget *infoProgress = new QWidget(this);
137 QHBoxLayout *infoProgressHB = new QHBoxLayout(infoProgress);
139 #if defined(Q_WS_WIN)
140 // Handles are the same color as widgets, at least on Windows 7.
141 splitter->setHandleWidth(3);
142 splitter->setStyleSheet(QString(
143 "QSplitter::handle {"
144 " border-left: 1px solid palette(mid);"
145 " border-right: 1px solid palette(mid);"
148 #elif defined(Q_WS_MAC)
149 m_expertStatus.setAttribute(Qt::WA_MacSmallSize, true);
152 // infoProgress->setStyleSheet("QWidget { border: 0.5px dotted red; }"); // Debug layout
153 m_expertStatus.setTextFormat(Qt::RichText);
154 m_expertStatus.hide();
156 // XXX Add the comment icon
158 infoProgressHB->setMargin(0);
159 infoProgressHB->setContentsMargins(0, 0, 0, 0);
161 m_infoStatus.setTemporaryContext(STATUS_CTX_TEMPORARY);
163 infoProgressHB->addWidget(&m_expertStatus);
164 infoProgressHB->addWidget(&m_infoStatus);
165 infoProgressHB->addWidget(&m_progressBar);
166 infoProgressHB->addStretch(10);
168 splitter->addWidget(infoProgress);
169 splitter->addWidget(&m_packetStatus);
170 splitter->addWidget(&m_profileStatus);
172 splitter->setStretchFactor(0, 3);
173 splitter->setStretchFactor(1, 3);
174 splitter->setStretchFactor(2, 1);
176 addWidget(splitter, 1);
178 cur_main_status_bar = this;
180 m_infoStatus.pushText(readyMsg, STATUS_CTX_MAIN);
181 packets_bar_update();
184 void MainStatusBar::showExpert() {
188 void MainStatusBar::hideExpert() {
189 m_expertStatus.hide();
192 void MainStatusBar::expertUpdate() {
193 QString imgText = "<img src=\":/expert/expert_";
194 QString ttText = " is the highest expert info level";
196 switch(expert_get_highest_severity()) {
198 imgText.append("error");
199 ttText.prepend("ERROR");
202 imgText.append("warn");
203 ttText.prepend("WARNING");
206 imgText.append("note");
207 ttText.prepend("NOTE");
210 imgText.append("chat");
211 ttText.prepend("CHAT");
214 // m_expertStatus.setText("<img src=\":/expert/expert_comment.png\"></img>");
217 imgText.append("none");
218 ttText = "No expert info";
222 imgText.append(".png\"></img>");
223 m_expertStatus.setText(imgText);
224 m_expertStatus.setToolTip(ttText);
225 m_expertStatus.show();
228 void MainStatusBar::pushTemporaryStatus(QString &message) {
229 m_infoStatus.pushText(message, STATUS_CTX_TEMPORARY);
232 void MainStatusBar::popTemporaryStatus() {
233 m_infoStatus.popText(STATUS_CTX_TEMPORARY);
236 void MainStatusBar::pushFileStatus(QString &message) {
237 m_infoStatus.pushText(message, STATUS_CTX_FILE);
241 void MainStatusBar::popFileStatus() {
242 m_infoStatus.popText(STATUS_CTX_FILE);
245 void MainStatusBar::pushFieldStatus(QString &message) {
246 if (message.isNull()) {
249 m_infoStatus.pushText(message, STATUS_CTX_FIELD);
253 void MainStatusBar::popFieldStatus() {
254 m_infoStatus.popText(STATUS_CTX_FIELD);
257 void MainStatusBar::pushFilterStatus(QString &message) {
258 m_infoStatus.pushText(message, STATUS_CTX_FILTER);
262 void MainStatusBar::popFilterStatus() {
263 m_infoStatus.popText(STATUS_CTX_FILTER);
266 void MainStatusBar::pushPacketStatus(QString &message) {
267 m_packetStatus.pushText(message, STATUS_CTX_MAIN);
270 void MainStatusBar::popPacketStatus() {
271 m_packetStatus.popText(STATUS_CTX_MAIN);
274 void MainStatusBar::pushProfileStatus(QString &message) {
275 m_profileStatus.pushText(message, STATUS_CTX_MAIN);
278 void MainStatusBar::popProfileStatus() {
279 m_profileStatus.popText(STATUS_CTX_MAIN);