diff options
author | Irene Ruengeler <ruengeler@wireshark.org> | 2014-06-24 11:36:51 +0200 |
---|---|---|
committer | Michael Tüxen <tuexen@wireshark.org> | 2014-07-02 20:56:37 +0000 |
commit | f3c5f14bc440f4f8d8c680c4834a59ef5ba606a4 (patch) | |
tree | 50a8f68717109ef299e00e176c4467eaf4832cce | |
parent | 2c9d2bea32238223634ae975cfd4e682ba1a0b2b (diff) |
Manage Interfaces
- Add dialog to manage interfaces
- Add and delete pipes
- Hide local interfaces
Change-Id: I08323c306c2ea736f99e57c28e2fe3170a0c2216
Reviewed-on: https://code.wireshark.org/review/2613
Tested-by: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Tüxen <tuexen@wireshark.org>
-rw-r--r-- | capchild/capture_session.h | 6 | ||||
-rw-r--r-- | ui/capture_ui_utils.c | 9 | ||||
-rw-r--r-- | ui/qt/CMakeLists.txt | 3 | ||||
-rw-r--r-- | ui/qt/Makefile.am | 2 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 4 | ||||
-rw-r--r-- | ui/qt/QtShark.pro | 9 | ||||
-rw-r--r-- | ui/qt/capture_interfaces_dialog.cpp | 18 | ||||
-rw-r--r-- | ui/qt/capture_interfaces_dialog.h | 4 | ||||
-rw-r--r-- | ui/qt/capture_interfaces_dialog.ui | 20 | ||||
-rw-r--r-- | ui/qt/capture_preferences_frame.cpp | 27 | ||||
-rw-r--r-- | ui/qt/interface_tree.cpp | 36 | ||||
-rw-r--r-- | ui/qt/interface_tree.h | 1 | ||||
-rw-r--r-- | ui/qt/main_window.cpp | 2 | ||||
-rw-r--r-- | ui/qt/manage_interfaces_dialog.cpp | 450 | ||||
-rw-r--r-- | ui/qt/manage_interfaces_dialog.h | 106 | ||||
-rw-r--r-- | ui/qt/manage_interfaces_dialog.ui | 327 |
16 files changed, 1009 insertions, 15 deletions
diff --git a/capchild/capture_session.h b/capchild/capture_session.h index 6189590b0d..951b51e499 100644 --- a/capchild/capture_session.h +++ b/capchild/capture_session.h @@ -27,6 +27,12 @@ extern "C" { #endif /* __cplusplus */ +#ifndef _WIN32 +#include <sys/types.h> +#endif + +#include "capture_opts.h" + #ifdef HAVE_LIBPCAP /* Current state of capture engine. XXX - differentiate states */ typedef enum { diff --git a/ui/capture_ui_utils.c b/ui/capture_ui_utils.c index 1cd06c619a..2970ddd5e9 100644 --- a/ui/capture_ui_utils.c +++ b/ui/capture_ui_utils.c @@ -44,7 +44,7 @@ char * capture_dev_user_descr_find(const gchar *if_name) { - char *p; + char *p, *str; char *p2 = NULL; char *descr = NULL; int lp = 0; @@ -56,11 +56,15 @@ capture_dev_user_descr_find(const gchar *if_name) return NULL; } - if ((p = strstr(prefs.capture_devices_descr, if_name)) == NULL) { + /* There might be names like 'lo' and 'nflog' in Ubuntu which can lead to wrong results. + Therefore, the search must be more exact. */ + str = g_strdup_printf(",%s(", if_name); + if ((p = strstr(prefs.capture_devices_descr, str)) == NULL) { /* There are, but there isn't one for this interface. */ return NULL; } + p++; while (*p != '\0') { /* error: ran into next interface description */ if (*p == ',') @@ -85,6 +89,7 @@ capture_dev_user_descr_find(const gchar *if_name) } } + g_free(str); if ((lp == 1) && (ct > 0) && (p2 != NULL)) { /* Allocate enough space to return the string, which runs from p2 to p, plus a terminating diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 055e54b13e..0e01ac0fde 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -63,6 +63,7 @@ set(WIRESHARK_QT_HEADERS main_welcome.h main_window.h main_window_preferences_frame.h + manage_interfaces_dialog.h module_preferences_scroll_area.h packet_comment_dialog.h packet_format_group_box.h @@ -146,6 +147,7 @@ set(WIRESHARK_QT_SRC main_window.cpp main_window_preferences_frame.cpp main_window_slots.cpp + manage_interfaces_dialog.cpp module_preferences_scroll_area.cpp packet_comment_dialog.cpp packet_format_group_box.cpp @@ -217,6 +219,7 @@ set(WIRESHARK_QT_UI main_welcome.ui main_window.ui main_window_preferences_frame.ui + manage_interfaces_dialog.ui module_preferences_scroll_area.ui packet_comment_dialog.ui packet_format_group_box.ui diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index 24d346ac55..04b05786dd 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -169,6 +169,8 @@ main_window.cpp main_window_slots.cpp main_window.h: ui_main_window.h main_window_preferences_frame.cpp main_window_preferences_frame.h: ui_main_window_preferences_frame.h +manage_interfaces_dialog.cpp manage_interfaces_dialog.h: ui_manage_interfaces_dialog.h + module_preferences_scroll_area.cpp module_preferences_scroll_area.h: ui_module_preferences_scroll_area.h packet_comment_dialog.cpp packet_comment_dialog.h: ui_packet_comment_dialog.h diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index de6b6488d8..5c80ae8dbe 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -51,6 +51,7 @@ NODIST_GENERATED_HEADER_FILES = \ ui_main_welcome.h \ ui_main_window.h \ ui_main_window_preferences_frame.h \ + ui_manage_interfaces_dialog.h \ ui_module_preferences_scroll_area.h \ ui_packet_comment_dialog.h \ ui_packet_format_group_box.h \ @@ -148,6 +149,7 @@ MOC_HDRS = \ main_welcome.h \ main_window.h \ main_window_preferences_frame.h \ + manage_interfaces_dialog.h \ module_preferences_scroll_area.h \ packet_comment_dialog.h \ packet_format_group_box.h \ @@ -209,6 +211,7 @@ UI_FILES = \ main_welcome.ui \ main_window.ui \ main_window_preferences_frame.ui \ + manage_interfaces_dialog.ui \ module_preferences_scroll_area.ui \ packet_format_group_box.ui \ packet_range_group_box.ui \ @@ -326,6 +329,7 @@ WIRESHARK_QT_SRC = \ main_window.cpp \ main_window_preferences_frame.cpp \ main_window_slots.cpp \ + manage_interfaces_dialog.cpp \ module_preferences_scroll_area.cpp \ packet_comment_dialog.cpp \ packet_format_group_box.cpp \ diff --git a/ui/qt/QtShark.pro b/ui/qt/QtShark.pro index af47796420..3cbc5565c3 100644 --- a/ui/qt/QtShark.pro +++ b/ui/qt/QtShark.pro @@ -253,7 +253,8 @@ FORMS += \ summary_dialog.ui \ time_shift_dialog.ui \ uat_dialog.ui \ - tcp_stream_dialog.ui + tcp_stream_dialog.ui \ + manage_interfaces_dialog.ui HEADERS += $$HEADERS_WS_C \ about_dialog.h \ @@ -295,7 +296,8 @@ HEADERS += $$HEADERS_WS_C \ summary_dialog.h \ tango_colors.h \ uat_dialog.h \ - tcp_stream_dialog.h + tcp_stream_dialog.h \ + manage_interfaces_dialog.h win32 { OBJECTS_WS_C = $$SOURCES_WS_C @@ -647,4 +649,5 @@ SOURCES += \ time_shift_dialog.cpp \ uat_dialog.cpp \ wireshark_application.cpp \ - tcp_stream_dialog.cpp + tcp_stream_dialog.cpp \ + manage_interfaces_dialog.cpp diff --git a/ui/qt/capture_interfaces_dialog.cpp b/ui/qt/capture_interfaces_dialog.cpp index 4146354dbf..eac07a43a0 100644 --- a/ui/qt/capture_interfaces_dialog.cpp +++ b/ui/qt/capture_interfaces_dialog.cpp @@ -27,6 +27,7 @@ #include "capture_filter_combo.h" #include "ui_capture_interfaces_dialog.h" #include "compiled_filter_output.h" +#include "manage_interfaces_dialog.h" #include "wireshark_application.h" @@ -71,6 +72,7 @@ CaptureInterfacesDialog::CaptureInterfacesDialog(QWidget *parent) : connect(ui->tbInterfaces, SIGNAL(itemSelectionChanged()), this, SLOT(tableSelected())); connect(ui->allFilterComboBox, SIGNAL(captureFilterSyntaxChanged(bool)), this, SLOT(allFilterChanged())); connect(this, SIGNAL(interfacesChanged()), ui->allFilterComboBox, SIGNAL(interfacesChanged())); + connect(this, SIGNAL(ifsChanged()), this, SLOT(refreshInterfaceList())); } void CaptureInterfacesDialog::allFilterChanged() @@ -261,6 +263,7 @@ void CaptureInterfacesDialog::UpdateInterfaces() ui->cbResolveTransportNames->setChecked(gbl_resolv_flags.transport_name); ui->tbInterfaces->setRowCount(0); + ui->tbInterfaces->clearContents(); GList *list; char *snaplen_string, *linkname; @@ -386,7 +389,7 @@ void CaptureInterfacesDialog::UpdateInterfaces() output = QString(device.cfilter); ui->tbInterfaces->setItem(ui->tbInterfaces->rowCount()-1, FILTER, new QTableWidgetItem(output)); - if (strstr(prefs.capture_device, device.name) != NULL) { + if (prefs.capture_device && strstr(prefs.capture_device, device.name) != NULL) { device.selected = TRUE; global_capture_opts.num_selected++; } @@ -413,6 +416,12 @@ void CaptureInterfacesDialog::UpdateInterfaces() } } +void CaptureInterfacesDialog::refreshInterfaceList() +{ + UpdateInterfaces(); + emit interfaceListChanged(); +} + void CaptureInterfacesDialog::updateStatistics(void) { QList<int> *points = NULL; @@ -582,6 +591,13 @@ void CaptureInterfacesDialog::saveOptionsToPreferences() } +void CaptureInterfacesDialog::on_manage_clicked() +{ + saveOptionsToPreferences(); + ManageInterfacesDialog *dlg = new ManageInterfacesDialog(this); + dlg->show(); +} + #include <QComboBox> TbInterfacesDelegate::TbInterfacesDelegate(QObject *parent) diff --git a/ui/qt/capture_interfaces_dialog.h b/ui/qt/capture_interfaces_dialog.h index 32f5b71604..3febeca514 100644 --- a/ui/qt/capture_interfaces_dialog.h +++ b/ui/qt/capture_interfaces_dialog.h @@ -103,6 +103,7 @@ private slots: void on_cbExtraCaptureInfo_toggled(bool checked); void on_cbResolveMacAddresses_toggled(bool checked); void on_compileBPF_clicked(); + void on_manage_clicked(); void on_cbResolveNetworkNames_toggled(bool checked); void on_cbResolveTransportNames_toggled(bool checked); void start_button_clicked(); @@ -112,6 +113,7 @@ private slots: void tableSelected(); void updateStatistics(void); void allFilterChanged(); + void refreshInterfaceList(); signals: void startCapture(); @@ -120,6 +122,8 @@ signals: void setSelectedInterfaces(); void setFilterValid(bool valid); void interfacesChanged(); + void ifsChanged(); + void interfaceListChanged(); private: Ui::CaptureInterfacesDialog *ui; diff --git a/ui/qt/capture_interfaces_dialog.ui b/ui/qt/capture_interfaces_dialog.ui index b92773ac23..24ee978817 100644 --- a/ui/qt/capture_interfaces_dialog.ui +++ b/ui/qt/capture_interfaces_dialog.ui @@ -23,9 +23,15 @@ <attribute name="title"> <string>Input</string> </attribute> - <layout class="QVBoxLayout" name="verticalLayout_10" stretch="1,0"> + <layout class="QVBoxLayout" name="verticalLayout_5"> <item> <widget class="QTableWidget" name="tbInterfaces"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="editTriggers"> <set>QAbstractItemView::DoubleClicked</set> </property> @@ -47,6 +53,9 @@ <property name="columnCount"> <number>8</number> </property> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> <column> <property name="text"> <string>Interface</string> @@ -90,7 +99,7 @@ </widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> + <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0"> <item> <layout class="QVBoxLayout" name="verticalLayout_2"> <item> @@ -142,9 +151,12 @@ <item> <layout class="QVBoxLayout" name="verticalLayout_4"> <item> - <widget class="QPushButton" name="bClose_2"> + <widget class="QPushButton" name="manage"> <property name="enabled"> - <bool>false</bool> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Add a </string> </property> <property name="text"> <string>Manage Interfaces...</string> diff --git a/ui/qt/capture_preferences_frame.cpp b/ui/qt/capture_preferences_frame.cpp index 5aea33ff84..9c5643a5f8 100644 --- a/ui/qt/capture_preferences_frame.cpp +++ b/ui/qt/capture_preferences_frame.cpp @@ -23,6 +23,10 @@ #include <glib.h> +#ifdef HAVE_LIBPCAP +#include "ui/capture_globals.h" +#endif + #include "capture_preferences_frame.h" #include "ui_capture_preferences_frame.h" @@ -73,11 +77,24 @@ void CapturePreferencesFrame::updateWidgets() int err; ui->defaultInterfaceComboBox->clear(); - if_list = capture_interface_list(&err, NULL,main_window_update); - combo_list = build_capture_combo_list(if_list, FALSE); - free_interface_list(if_list); - for (combo_entry = combo_list; combo_entry != NULL && combo_entry->data != NULL; combo_entry = g_list_next(combo_entry)) { - ui->defaultInterfaceComboBox->addItem(QString((const char *)combo_entry->data)); + if (global_capture_opts.all_ifaces->len > 0) { + interface_t device; + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + + /* Continue if capture device is hidden */ + if (device.hidden) { + continue; + } + ui->defaultInterfaceComboBox->addItem(QString((const char *)device.display_name)); + } + } else { + if_list = capture_interface_list(&err, NULL,main_window_update); + combo_list = build_capture_combo_list(if_list, FALSE); + free_interface_list(if_list); + for (combo_entry = combo_list; combo_entry != NULL && combo_entry->data != NULL; combo_entry = g_list_next(combo_entry)) { + ui->defaultInterfaceComboBox->addItem(QString((const char *)combo_entry->data)); + } } if (pref_device_->stashed_val.string) { diff --git a/ui/qt/interface_tree.cpp b/ui/qt/interface_tree.cpp index 20fcd6c791..865d851c47 100644 --- a/ui/qt/interface_tree.cpp +++ b/ui/qt/interface_tree.cpp @@ -331,6 +331,42 @@ void InterfaceTree::setSelectedInterfaces() #endif // HAVE_LIBPCAP } +void InterfaceTree::interfaceListChanged() +{ +#ifdef HAVE_LIBPCAP + interface_t device; + clear(); + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + QList<int> *points; + + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + + /* Continue if capture device is hidden */ + if (device.hidden) { + continue; + } + + QTreeWidgetItem *ti = new QTreeWidgetItem(); + ti->setText(0, QString().fromUtf8(device.display_name)); + ti->setData(0, Qt::UserRole, QString(device.name)); + points = new QList<int>(); + ti->setData(1, Qt::UserRole, qVariantFromValue(points)); + addTopLevelItem(ti); + // XXX Add other device information + resizeColumnToContents(1); + if (strstr(prefs.capture_device, device.name) != NULL) { + device.selected = TRUE; + global_capture_opts.num_selected++; + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); + } + if (device.selected) { + ti->setSelected(true); + } + } +#endif +} + /* * Editor modelines * diff --git a/ui/qt/interface_tree.h b/ui/qt/interface_tree.h index d5b15f6a89..a9055613bc 100644 --- a/ui/qt/interface_tree.h +++ b/ui/qt/interface_tree.h @@ -65,6 +65,7 @@ public slots: //void getPoints(int row, QList<int> *pts); void getPoints(int row, PointList *pts); void setSelectedInterfaces(); + void interfaceListChanged(); private slots: void getInterfaceList(); diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 08adb54322..5d085d39b9 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -303,6 +303,8 @@ MainWindow::MainWindow(QWidget *parent) : this->main_welcome_->getInterfaceTree(), SLOT(getPoints(int,PointList*))); connect(&capture_interfaces_dialog_, SIGNAL(setSelectedInterfaces()), this->main_welcome_->getInterfaceTree(), SLOT(setSelectedInterfaces())); + connect(&capture_interfaces_dialog_, SIGNAL(interfaceListChanged()), + this->main_welcome_->getInterfaceTree(), SLOT(interfaceListChanged())); #endif main_ui_->mainStack->setCurrentWidget(main_welcome_); diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp new file mode 100644 index 0000000000..c11bd8990b --- /dev/null +++ b/ui/qt/manage_interfaces_dialog.cpp @@ -0,0 +1,450 @@ +/* manage_interfaces_dialog.cpp + * + * 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 <glib.h> +#include "manage_interfaces_dialog.h" +#include "ui_manage_interfaces_dialog.h" +#include "epan/prefs.h" +#include "ui/last_open_dir.h" +#include "capture_opts.h" +#include "ui/capture_globals.h" +#include "ui/qt/capture_interfaces_dialog.h" +#include "ui/iface_lists.h" +#include "ui/preference_utils.h" + +#ifdef HAVE_LIBPCAP +#include <QFileDialog> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QCheckBox> + +ManageInterfacesDialog::ManageInterfacesDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::ManageInterfacesDialog) +{ + ui->setupUi(this); + +#ifdef Q_OS_MAC + ui->addButton->setAttribute(Qt::WA_MacSmallSize, true); + ui->delButton->setAttribute(Qt::WA_MacSmallSize, true); +#endif + ui->pipeList->setItemDelegateForColumn(0, &new_pipe_item_delegate_); + new_pipe_item_delegate_.setTable(ui->pipeList); + showPipes(); + connect(this, SIGNAL(ifsChanged()), parent, SIGNAL(ifsChanged())); + + showLocalInterfaces(); + +#if !defined(HAVE_PCAP_REMOTE) + ui->tabWidget->removeTab(2); +#endif +} + +ManageInterfacesDialog::~ManageInterfacesDialog() +{ + delete ui; +} + + +void ManageInterfacesDialog::showPipes() +{ + ui->pipeList->setRowCount(0); + + if (global_capture_opts.all_ifaces->len > 0) { + interface_t device; + + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + + /* Continue if capture device is hidden */ + if (device.hidden || device.type != IF_PIPE) { + continue; + } + ui->pipeList->setRowCount(ui->pipeList->rowCount()+1); + QString output = QString(device.display_name); + ui->pipeList->setItem(ui->pipeList->rowCount()-1, INTERFACE, new QTableWidgetItem(output)); + } + } +} + +void ManageInterfacesDialog::on_addButton_clicked() +{ + ui->pipeList->setRowCount(ui->pipeList->rowCount() + 1); + QTableWidgetItem *widget = new QTableWidgetItem(QString(tr("New Pipe"))); + ui->pipeList->setItem(ui->pipeList->rowCount() - 1 , 0, widget); +} + + +void ManageInterfacesDialog::on_buttonBox_accepted() +{ + interface_t device; + gchar *pipe_name; + + for (int row = 0; row < ui->pipeList->rowCount(); row++) { + pipe_name = g_strdup(ui->pipeList->item(row,0)->text().toUtf8().constData()); + if (!strcmp(pipe_name, "New pipe") || !strcmp(pipe_name, "")) { + g_free(pipe_name); + return; + } + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (strcmp(pipe_name, device.name) == 0) { + g_free(pipe_name); + return; + } + } + device.name = g_strdup(pipe_name); + device.display_name = g_strdup_printf("%s", device.name); + device.hidden = FALSE; + device.selected = TRUE; + device.type = IF_PIPE; + device.pmode = global_capture_opts.default_options.promisc_mode; + device.has_snaplen = global_capture_opts.default_options.has_snaplen; + device.snaplen = global_capture_opts.default_options.snaplen; + device.cfilter = g_strdup(global_capture_opts.default_options.cfilter); + device.addresses = g_strdup(""); + device.no_addresses = 0; + device.last_packets = 0; + device.links = NULL; + #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) + device.buffer = DEFAULT_CAPTURE_BUFFER_SIZE; + #endif + device.active_dlt = -1; + device.locked = FALSE; + device.if_info.name = g_strdup(pipe_name); + device.if_info.friendly_name = NULL; + device.if_info.vendor_description = NULL; + device.if_info.addrs = NULL; + device.if_info.loopback = FALSE; + device.if_info.type = IF_PIPE; + #if defined(HAVE_PCAP_CREATE) + device.monitor_mode_enabled = FALSE; + device.monitor_mode_supported = FALSE; + #endif + global_capture_opts.num_selected++; + g_array_append_val(global_capture_opts.all_ifaces, device); + + g_free(pipe_name); + } + emit ifsChanged(); +} + + + +void ManageInterfacesDialog::on_delButton_clicked() +{ + interface_t device; + bool found = false; + QList<QTableWidgetItem*> selected = ui->pipeList->selectedItems(); + if (selected.length() == 0) { + QMessageBox::warning(this, tr("Error"), + tr("No interface selected.")); + return; + } + QString pipename = selected[0]->text(); + for (guint i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + /* Continue if capture device is hidden or not a pipe*/ + if (device.hidden || device.type != IF_PIPE) { + continue; + } + if (pipename.compare(device.name)) { + continue; + } + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + ui->pipeList->removeRow(selected[0]->row()); + found = true; + break; + } + if (found) + emit ifsChanged(); + else /* pipe has not been saved yet */ + ui->pipeList->removeRow(selected[0]->row()); +} + +void ManageInterfacesDialog::showLocalInterfaces() +{ + guint i; + interface_t device; + QString output; + Qt::ItemFlags eFlags; + gchar *pr_descr = g_strdup(""); + char *comment = NULL; + + ui->localList->setRowCount(0); + for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (device.local && device.type != IF_PIPE && device.type != IF_STDIN) { + ui->localList->setRowCount(ui->localList->rowCount()+1); + QTableWidgetItem *item = new QTableWidgetItem(""); + item->setCheckState(device.hidden?Qt::Checked:Qt::Unchecked); + ui->localList->setItem(ui->localList->rowCount()-1, HIDE, item); + ui->localList->setColumnWidth(HIDE, 40); +#ifdef _WIN32 + output = QString(device.friendly_name); + ui->localList->setItem(ui->localList->rowCount()-1, FRIENDLY, new QTableWidgetItem(output)); + eFlags = ui->localList->item(ui->localList->rowCount()-1, FRIENDLY)->flags(); + eFlags &= Qt::NoItemFlags; + eFlags |= Qt::ItemIsSelectable | Qt::ItemIsEnabled; + ui->localList->item(ui->localList->rowCount()-1, FRIENDLY)->setFlags(eFlags); +#else + ui->localList->setColumnHidden(FRIENDLY, true); +#endif + output = QString(device.name); + ui->localList->setItem(ui->localList->rowCount()-1, LOCAL_NAME, new QTableWidgetItem(output)); + output = QString(""); + eFlags = ui->localList->item(ui->localList->rowCount()-1, FRIENDLY)->flags(); + eFlags &= Qt::NoItemFlags; + eFlags |= Qt::ItemIsSelectable | Qt::ItemIsEnabled; + ui->localList->item(ui->localList->rowCount()-1, LOCAL_NAME)->setFlags(eFlags); + + comment = capture_dev_user_descr_find(device.name); + if (comment) + output = QString(comment); + ui->localList->setItem(ui->localList->rowCount()-1, COMMENT, new QTableWidgetItem(output)); + } else { + continue; + } + } + g_free(pr_descr); +} + +void ManageInterfacesDialog::saveLocalHideChanges(QTableWidgetItem* item) +{ + guint i; + interface_t device; + + if (item->column() != HIDE) { + return; + } + QTableWidgetItem* nameItem = ui->localList->item(item->row(), LOCAL_NAME); + + if (!nameItem) { + return; + } + + QString name = nameItem->text(); + /* See if this is the currently selected capturing device */ + + for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (name.compare(device.name)) { + continue; + } + device.hidden = (item->checkState()==Qt::Checked?true:false); + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); + } +} + +void ManageInterfacesDialog::saveLocalCommentChanges(QTableWidgetItem* item) +{ + guint i; + interface_t device; + + if (item->column() != COMMENT) { + return; + } + QTableWidgetItem* nameItem = ui->localList->item(item->row(), LOCAL_NAME); + + if (!nameItem) { + return; + } + + QString name = nameItem->text(); + QString comment = ui->localList->item(item->row(), COMMENT)->text(); + /* See if this is the currently selected capturing device */ + + for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (name.compare(device.name)) { + continue; + } + if (!comment.compare("")) { + device.display_name = g_strdup_printf("%s", name.toUtf8().constData()); + } else { + device.display_name = g_strdup_printf("%s: %s", comment.toUtf8().constData(), name.toUtf8().constData()); + } + global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i); + g_array_insert_val(global_capture_opts.all_ifaces, i, device); + } +} + + +void ManageInterfacesDialog::checkBoxChanged(QTableWidgetItem* item) +{ + guint i; + interface_t device; + + if (item->column() != HIDE) { + return; + } + QTableWidgetItem* nameItem = ui->localList->item(item->row(), LOCAL_NAME); + + if (!nameItem) { + return; + } + + QString name = nameItem->text(); + /* See if this is the currently selected capturing device */ + + for (i = 0; i < global_capture_opts.all_ifaces->len; i++) { + device = g_array_index(global_capture_opts.all_ifaces, interface_t, i); + if (name.compare(device.name)) { + continue; + } + if (prefs.capture_device && strstr(prefs.capture_device, device.name) && item->checkState() == Qt::Checked) { + /* Don't allow current interface to be hidden */ + QMessageBox::warning(this, tr("Error"), + tr("Default interface cannot be hidden.")); + item->setCheckState(Qt::Unchecked); + return; + } + } +} + +void ManageInterfacesDialog::on_localButtonBox_accepted() +{ + gchar *new_hide = g_strdup(""); + gchar *new_comment = NULL; + QString name; + gchar *tmp_descr = NULL; + + if (global_capture_opts.all_ifaces->len > 0) { + new_hide = (gchar*)g_malloc0(MAX_VAL_LEN); + for (int row = 0; row < ui->localList->rowCount(); row++) { + QTableWidgetItem* hitem = ui->localList->item(row, HIDE); + checkBoxChanged(hitem); + if (hitem->checkState() == Qt::Checked) { + name = ui->localList->item(row, LOCAL_NAME)->text(); + g_strlcat (new_hide, ",", MAX_VAL_LEN); + g_strlcat (new_hide, name.toUtf8().constData(), MAX_VAL_LEN); + } + saveLocalHideChanges(hitem); + } + /* write new "hidden" string to preferences */ + g_free(prefs.capture_devices_hide); + prefs.capture_devices_hide = new_hide; + hide_interface(g_strdup(new_hide)); + + new_comment = (gchar*)g_malloc0(MAX_VAL_LEN); + for (int row = 0; row < ui->localList->rowCount(); row++) { + name = ui->localList->item(row, LOCAL_NAME)->text(); + QTableWidgetItem* citem = ui->localList->item(row, COMMENT); + if (citem->text().compare("")) { + g_strlcat (new_comment, ",", MAX_VAL_LEN); + tmp_descr = g_strdup_printf("%s(%s)", name.toUtf8().constData(), citem->text().toUtf8().constData()); + g_strlcat (new_comment, tmp_descr, MAX_VAL_LEN); + g_free(tmp_descr); + } + saveLocalCommentChanges(citem); + } + /* write new description string to preferences */ + if (prefs.capture_devices_descr) + g_free(prefs.capture_devices_descr); + prefs.capture_devices_descr = new_comment; + } + + /* save changes to the preferences file */ + if (!prefs.gui_use_pref_save) { + prefs_main_write(); + } + emit ifsChanged(); +} + + +NewFileDelegate::NewFileDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{ +} + + +NewFileDelegate::~NewFileDelegate() +{ +} + + +QWidget* NewFileDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const +{ + Q_UNUSED(option); + Q_UNUSED(index); + + QWidget * widg = new QWidget(parent); + QHBoxLayout *hbox = new QHBoxLayout(widg); + widg->setLayout(hbox); + QLineEdit *le = new QLineEdit(widg); + QPushButton *pb = new QPushButton(widg); + pb->setText(QString(tr("Browse..."))); + le->setText(table->currentItem()->text()); + hbox->addWidget(le); + hbox->addWidget(pb); + hbox->setMargin(0); + + connect(le, SIGNAL(textEdited(const QString &)), this, SLOT(setTextField(const QString &))); + connect(le, SIGNAL(editingFinished()), this, SLOT(stopEditor())); + connect(pb, SIGNAL(pressed()), this, SLOT(browse_button_clicked())); + return widg; +} + +void NewFileDelegate::setTextField(const QString &text) +{ + table->currentItem()->setText(text); +} + +void NewFileDelegate::stopEditor() +{ + closeEditor(table->cellWidget(table->currentRow(), 0)); +} + +void NewFileDelegate::browse_button_clicked() +{ + char *open_dir = NULL; + + switch (prefs.gui_fileopen_style) { + + case FO_STYLE_LAST_OPENED: + open_dir = get_last_open_dir(); + break; + + case FO_STYLE_SPECIFIED: + if (prefs.gui_fileopen_dir[0] != '\0') + open_dir = prefs.gui_fileopen_dir; + break; + } + QString file_name = QFileDialog::getOpenFileName(table, tr("Open Pipe"), open_dir); + closeEditor(table->cellWidget(table->currentRow(), 0)); + table->currentItem()->setText(file_name); +} + +#endif /* HAVE_LIBPCAP */ +// +// Editor modelines - http://www.wireshark.org/tools/modelines.html +// +// Local variables: +// c-basic-offset: 4 +// tab-width: 4 +// indent-tabs-mode: nil +// End: +// +// vi: set shiftwidth=4 tabstop=4 expandtab: +// :indentSize=4:tabSize=4:noTabs=true: +// diff --git a/ui/qt/manage_interfaces_dialog.h b/ui/qt/manage_interfaces_dialog.h new file mode 100644 index 0000000000..1b68fe0fd6 --- /dev/null +++ b/ui/qt/manage_interfaces_dialog.h @@ -0,0 +1,106 @@ +/* manage_interfaces_dialog.h + * + * 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. + */ + +#ifndef MANAGE_INTERFACES_DIALOG_H +#define MANAGE_INTERFACES_DIALOG_H + +#include <QDialog> +#include <QLineEdit> +#include <QTableWidget> +#include <QStyledItemDelegate> + +enum +{ + HIDE = 0, + FRIENDLY, + LOCAL_NAME, + COMMENT, + NUM_LOCAL_COLUMNS +}; + + +class NewFileDelegate : public QStyledItemDelegate +{ + Q_OBJECT + +private: + QTableWidget* table; + +public: + NewFileDelegate(QObject *parent = 0); + ~NewFileDelegate(); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; + void setTable(QTableWidget* tb) { table = tb; }; + +private slots: + void browse_button_clicked(); + void setTextField(const QString &text); + void stopEditor(); +}; + + +namespace Ui { +class ManageInterfacesDialog; +} + +class ManageInterfacesDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ManageInterfacesDialog(QWidget *parent = 0); + ~ManageInterfacesDialog(); + +private: + Ui::ManageInterfacesDialog *ui; + NewFileDelegate new_pipe_item_delegate_; + + void showPipes(); + void showLocalInterfaces(); + void saveLocalHideChanges(QTableWidgetItem *item); + void saveLocalCommentChanges(QTableWidgetItem *item); + void checkBoxChanged(QTableWidgetItem *item); + +signals: + void ifsChanged(); + +private slots: + void on_addButton_clicked(); + void on_buttonBox_accepted(); + void on_delButton_clicked(); + void on_localButtonBox_accepted(); +}; + +#endif // MANAGE_INTERFACES_DIALOG_H + +// +// Editor modelines - http://www.wireshark.org/tools/modelines.html +// +// Local variables: +// c-basic-offset: 4 +// tab-width: 4 +// indent-tabs-mode: nil +// End: +// +// vi: set shiftwidth=4 tabstop=4 expandtab: +// :indentSize=4:tabSize=4:noTabs=true: +// diff --git a/ui/qt/manage_interfaces_dialog.ui b/ui/qt/manage_interfaces_dialog.ui new file mode 100644 index 0000000000..f53672b73b --- /dev/null +++ b/ui/qt/manage_interfaces_dialog.ui @@ -0,0 +1,327 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ManageInterfacesDialog</class> + <widget class="QDialog" name="ManageInterfacesDialog"> + <property name="windowModality"> + <enum>Qt::ApplicationModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>574</width> + <height>338</height> + </rect> + </property> + <property name="windowTitle"> + <string>Manage Interfaces</string> + </property> + <property name="toolTip"> + <string><html><head/><body><p><br/></p></body></html></string> + </property> + <property name="modal"> + <bool>false</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="leftMargin"> + <number>3</number> + </property> + <property name="topMargin"> + <number>10</number> + </property> + <property name="rightMargin"> + <number>3</number> + </property> + <property name="bottomMargin"> + <number>3</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>1</number> + </property> + <widget class="QWidget" name="Pipes"> + <property name="toolTip"> + <string><html><head/><body><p>Add a pipe to capture from or remove an existing pipe from the list.</p></body></html></string> + </property> + <attribute name="title"> + <string>Pipes</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>5</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> + <number>5</number> + </property> + <item> + <widget class="QTableWidget" name="pipeList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="baseSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAsNeeded</enum> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="showGrid"> + <bool>false</bool> + </property> + <property name="rowCount"> + <number>1</number> + </property> + <property name="columnCount"> + <number>1</number> + </property> + <attribute name="horizontalHeaderVisible"> + <bool>false</bool> + </attribute> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <row/> + <column> + <property name="text"> + <string>Pipe</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QPushButton" name="addButton"> + <property name="toolTip"> + <string><html><head/><body><p>Add a new pipe using default settings.</p></body></html></string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/plus-8.png</normaloff>:/stock/plus-8.png</iconset> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="delButton"> + <property name="toolTip"> + <string><html><head/><body><p>Remove the selected pipe from the list.</p></body></html></string> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset resource="../../image/toolbar.qrc"> + <normaloff>:/stock/minus-8.png</normaloff>:/stock/minus-8.png</iconset> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QWidget" name="Local"> + <property name="toolTip"> + <string><html><head/><body><p>Click the checkbox to hide or show a hidden interface.</p></body></html></string> + </property> + <attribute name="title"> + <string>Local Interfaces</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>5</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> + <number>5</number> + </property> + <item> + <widget class="QTableWidget" name="localList"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="editTriggers"> + <set>QAbstractItemView::DoubleClicked</set> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::SingleSelection</enum> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string>Hide</string> + </property> + <property name="textAlignment"> + <set>AlignHCenter|AlignVCenter|AlignCenter</set> + </property> + </column> + <column> + <property name="text"> + <string>Friendly Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Interface Name</string> + </property> + </column> + <column> + <property name="text"> + <string>Comment</string> + </property> + </column> + </widget> + </item> + <item> + <widget class="QDialogButtonBox" name="localButtonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="Remote"> + <attribute name="title"> + <string>Remote Interfaces</string> + </attribute> + </widget> + </widget> + </item> + </layout> + </widget> + <resources> + <include location="../../image/toolbar.qrc"/> + </resources> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>ManageInterfacesDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>469</x> + <y>303</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>164</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ManageInterfacesDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>469</x> + <y>303</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>164</y> + </hint> + </hints> + </connection> + <connection> + <sender>localButtonBox</sender> + <signal>rejected()</signal> + <receiver>ManageInterfacesDialog</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>469</x> + <y>303</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>164</y> + </hint> + </hints> + </connection> + <connection> + <sender>localButtonBox</sender> + <signal>accepted()</signal> + <receiver>ManageInterfacesDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>469</x> + <y>303</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>164</y> + </hint> + </hints> + </connection> + </connections> +</ui> |