2012-01-04 22:13:01 +00:00
|
|
|
/* interface_tree.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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "interface_tree.h"
|
|
|
|
|
2012-08-03 23:30:47 +00:00
|
|
|
#include "ui/capture_globals.h"
|
|
|
|
#include "ui/iface_lists.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-03 23:30:47 +00:00
|
|
|
#include "epan/prefs.h"
|
|
|
|
|
|
|
|
#include "sparkline_delegate.h"
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QHeaderView>
|
2012-08-03 23:30:47 +00:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
#include <QDebug>
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
InterfaceTree::InterfaceTree(QWidget *parent) :
|
|
|
|
QTreeWidget(parent)
|
|
|
|
{
|
|
|
|
GList *if_list;
|
|
|
|
QTreeWidgetItem *ti;
|
|
|
|
int err;
|
|
|
|
gchar *err_str = NULL;
|
|
|
|
|
|
|
|
header()->setVisible(false);
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setUniformRowHeights(true);
|
2012-08-03 23:30:47 +00:00
|
|
|
setColumnCount(2);
|
2012-03-07 10:16:33 +00:00
|
|
|
setAccessibleName(tr("Welcome screen list"));
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
stat_cache_ = NULL;
|
|
|
|
stat_timer_ = new QTimer(this);
|
|
|
|
connect(stat_timer_, SIGNAL(timeout()), this, SLOT(updateStatistics()));
|
2012-08-03 23:30:47 +00:00
|
|
|
|
|
|
|
setItemDelegateForColumn(1, new SparkLineDelegate());
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
if_list = capture_interface_list(&err, &err_str);
|
2012-08-03 23:30:47 +00:00
|
|
|
if_list = g_list_sort(if_list, if_list_comparator_alph);
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) {
|
|
|
|
setDisabled(true);
|
2012-08-17 00:58:50 +00:00
|
|
|
ti = new QTreeWidgetItem();
|
|
|
|
ti->setText(0, QString(tr("No interfaces found\n%1")).arg(QString().fromUtf8(err_str)));
|
2012-01-04 22:13:01 +00:00
|
|
|
addTopLevelItem(ti);
|
|
|
|
return;
|
|
|
|
} else if (err_str) {
|
|
|
|
g_free(err_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Do we need to check for this? capture_interface_list returns an error if the length is 0.
|
|
|
|
if (g_list_length(if_list) > 0) {
|
|
|
|
if_info_t *if_info;
|
|
|
|
GList *curr;
|
|
|
|
setDisabled(false);
|
|
|
|
|
|
|
|
for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
|
2012-08-03 23:30:47 +00:00
|
|
|
QList<int> *points;
|
|
|
|
QVariant v;
|
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
if_info = (if_info_t *) curr->data;
|
|
|
|
/* Continue if capture device is hidden */
|
2012-08-03 23:30:47 +00:00
|
|
|
if (prefs_is_capture_device_hidden(if_info->name)) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
|
|
|
|
ti = new QTreeWidgetItem();
|
2012-08-04 00:37:04 +00:00
|
|
|
// XXX Using if_info->name is amazingly ugly under Windows but it's needed for
|
|
|
|
// statistics updates
|
|
|
|
// ti->setText(0, QString().fromUtf8(if_info->description ? if_info->description : if_info->name));
|
|
|
|
ti->setText(0, QString().fromUtf8(if_info->name));
|
2012-08-03 23:30:47 +00:00
|
|
|
points = new QList<int>();
|
|
|
|
v.setValue(points);
|
|
|
|
ti->setData(1, Qt::UserRole, v);
|
2012-01-04 22:13:01 +00:00
|
|
|
addTopLevelItem(ti);
|
2012-08-17 19:37:18 +00:00
|
|
|
resizeColumnToContents(1);
|
2012-08-03 23:30:47 +00:00
|
|
|
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
free_interface_list(if_list);
|
|
|
|
}
|
2012-08-03 23:30:47 +00:00
|
|
|
|
|
|
|
InterfaceTree::~InterfaceTree() {
|
|
|
|
QTreeWidgetItemIterator iter(this);
|
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
if (stat_cache_) {
|
|
|
|
capture_stat_stop(stat_cache_);
|
|
|
|
stat_cache_ = NULL;
|
2012-08-03 23:30:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*iter) {
|
|
|
|
QList<int> *points;
|
|
|
|
QVariant v;
|
|
|
|
|
|
|
|
v = (*iter)->data(1, Qt::UserRole);
|
|
|
|
points = v.value<QList<int> *>();
|
|
|
|
delete(points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
#include <QDebug>
|
2012-08-03 23:30:47 +00:00
|
|
|
void InterfaceTree::hideEvent(QHideEvent *evt) {
|
|
|
|
Q_UNUSED(evt);
|
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
stat_timer_->stop();
|
|
|
|
if (stat_cache_) {
|
|
|
|
capture_stat_stop(stat_cache_);
|
|
|
|
stat_cache_ = NULL;
|
2012-08-03 23:30:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceTree::showEvent(QShowEvent *evt) {
|
|
|
|
Q_UNUSED(evt);
|
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
stat_timer_->start(1000);
|
2012-08-03 23:30:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceTree::updateStatistics(void) {
|
|
|
|
interface_t device;
|
|
|
|
guint diff, if_idx;
|
|
|
|
struct pcap_stat stats;
|
|
|
|
|
2012-08-31 22:25:51 +00:00
|
|
|
if (!stat_cache_) {
|
2012-08-03 23:30:47 +00:00
|
|
|
// Start gathering statistics using dumpcap
|
|
|
|
// We crash (on OS X at least) if we try to do this from ::showEvent.
|
2012-08-31 22:25:51 +00:00
|
|
|
stat_cache_ = capture_stat_start(&global_capture_opts);
|
2012-08-03 23:30:47 +00:00
|
|
|
}
|
2012-08-31 22:25:51 +00:00
|
|
|
if (!stat_cache_) return;
|
2012-08-03 23:30:47 +00:00
|
|
|
|
|
|
|
QTreeWidgetItemIterator iter(this);
|
|
|
|
while (*iter) {
|
|
|
|
QList<int> *points;
|
|
|
|
QVariant v;
|
|
|
|
|
|
|
|
for (if_idx = 0; if_idx < global_capture_opts.all_ifaces->len; if_idx++) {
|
|
|
|
device = g_array_index(global_capture_opts.all_ifaces, interface_t, if_idx);
|
|
|
|
if ((*iter)->text(0).compare(QString().fromUtf8(device.name)) || device.hidden || device.type == IF_PIPE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
diff = 0;
|
2012-08-31 22:25:51 +00:00
|
|
|
if (capture_stats(stat_cache_, device.name, &stats)) {
|
2012-08-03 23:30:47 +00:00
|
|
|
if ((int)(stats.ps_recv - device.last_packets) >= 0) {
|
|
|
|
diff = stats.ps_recv - device.last_packets;
|
|
|
|
}
|
|
|
|
device.last_packets = stats.ps_recv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v = (*iter)->data(1, Qt::UserRole);
|
|
|
|
points = v.value<QList<int> *>();
|
|
|
|
points->append(diff);
|
|
|
|
update(indexFromItem((*iter), 1));
|
|
|
|
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, if_idx);
|
|
|
|
g_array_insert_val(global_capture_opts.all_ifaces, if_idx, device);
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|