ManageInterfacesDialog: Implement View/Data Model
Implement the same interface view/data model as used for the interface_tree selection in this dialog, to encapsulate all access to global_capture_devices from the dialog. Change-Id: I0e568fe236d077befa2a79765638db8bb3ed1a3f Reviewed-on: https://code.wireshark.org/review/18062 Petri-Dish: Roland Knall <rknall@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
5cbdbecc35
commit
864f750be5
|
@ -81,6 +81,7 @@ set(WIRESHARK_QT_HEADERS
|
|||
iax2_analysis_dialog.h
|
||||
import_text_dialog.h
|
||||
interface_tree_model.h
|
||||
interface_tree_cache_model.h
|
||||
interface_sort_filter_model.h
|
||||
interface_frame.h
|
||||
io_graph_dialog.h
|
||||
|
@ -241,6 +242,7 @@ set(WIRESHARK_QT_SRC
|
|||
iax2_analysis_dialog.cpp
|
||||
import_text_dialog.cpp
|
||||
interface_tree_model.cpp
|
||||
interface_tree_cache_model.cpp
|
||||
interface_sort_filter_model.cpp
|
||||
interface_frame.cpp
|
||||
label_stack.cpp
|
||||
|
|
|
@ -211,6 +211,7 @@ MOC_HDRS = \
|
|||
import_text_dialog.h \
|
||||
interface_frame.h \
|
||||
interface_tree_model.h \
|
||||
interface_tree_cache_model.h \
|
||||
interface_sort_filter_model.h \
|
||||
io_graph_dialog.h \
|
||||
label_stack.h \
|
||||
|
@ -486,6 +487,7 @@ WIRESHARK_QT_SRC = \
|
|||
import_text_dialog.cpp \
|
||||
interface_frame.cpp \
|
||||
interface_tree_model.cpp \
|
||||
interface_tree_cache_model.cpp \
|
||||
interface_sort_filter_model.cpp \
|
||||
label_stack.cpp \
|
||||
layout_preferences_frame.cpp \
|
||||
|
|
|
@ -0,0 +1,261 @@
|
|||
/* interface_tree_cache_model.cpp
|
||||
* Model caching interface changes before sending them to global storage
|
||||
*
|
||||
* 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 "ui/qt/interface_tree_cache_model.h"
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
#include "epan/prefs.h"
|
||||
|
||||
#include "qt_ui_utils.h"
|
||||
#include "wireshark_application.h"
|
||||
|
||||
InterfaceTreeCacheModel::InterfaceTreeCacheModel(QObject *parent) :
|
||||
QIdentityProxyModel(parent)
|
||||
{
|
||||
/* ATTENTION: This cache model is not intended to be used with anything
|
||||
* else then InterfaceTreeModel, and will break with anything else
|
||||
* leading to unintended results. */
|
||||
sourceModel = new InterfaceTreeModel(parent);
|
||||
|
||||
QIdentityProxyModel::setSourceModel(sourceModel);
|
||||
storage = new QMap<int, QMap<InterfaceTreeColumns, QVariant> *>();
|
||||
|
||||
checkableColumns << IFTREE_COL_HIDDEN;
|
||||
|
||||
editableColumns << IFTREE_COL_INTERFACE_COMMENT;
|
||||
}
|
||||
|
||||
InterfaceTreeCacheModel::~InterfaceTreeCacheModel()
|
||||
{
|
||||
delete storage;
|
||||
delete sourceModel;
|
||||
}
|
||||
|
||||
void InterfaceTreeCacheModel::reset(int row)
|
||||
{
|
||||
if ( row < 0 )
|
||||
{
|
||||
delete storage;
|
||||
storage = new QMap<int, QMap<InterfaceTreeColumns, QVariant> *>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( storage->count() > row )
|
||||
storage->remove(storage->keys().at(row));
|
||||
}
|
||||
}
|
||||
|
||||
QVariant InterfaceTreeCacheModel::getColumnContent(int idx, int col, int role)
|
||||
{
|
||||
return InterfaceTreeCacheModel::data(index(idx, col), role);
|
||||
}
|
||||
|
||||
void InterfaceTreeCacheModel::save()
|
||||
{
|
||||
if ( storage->count() == 0 )
|
||||
return;
|
||||
|
||||
QStringList hideList;
|
||||
QStringList commentList;
|
||||
|
||||
for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++)
|
||||
{
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
|
||||
if (! device.name )
|
||||
continue;
|
||||
|
||||
/* Try to load a saved value row for this index */
|
||||
QMap<InterfaceTreeColumns, QVariant> * dataField = storage->value(idx, 0);
|
||||
|
||||
/* Handle the storing of values for this device here */
|
||||
if ( dataField )
|
||||
{
|
||||
QMap<InterfaceTreeColumns, QVariant>::const_iterator it = dataField->constBegin();
|
||||
while ( it != dataField->constEnd() )
|
||||
{
|
||||
InterfaceTreeColumns col = it.key();
|
||||
QVariant saveValue = it.value();
|
||||
|
||||
/* Setting the field values for each individual saved value cannot be generic, as the
|
||||
* struct cannot be accessed generically. Therefore below, each individually changed
|
||||
* value has to be handled separately */
|
||||
|
||||
if ( col == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
device.hidden = saveValue.toBool();
|
||||
}
|
||||
|
||||
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, idx);
|
||||
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
|
||||
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant content = getColumnContent(idx, IFTREE_COL_HIDDEN, Qt::CheckStateRole);
|
||||
if ( content.isValid() && static_cast<Qt::CheckState>(content.toInt()) == Qt::Unchecked )
|
||||
hideList << QString(device.name);
|
||||
|
||||
content = getColumnContent(idx, IFTREE_COL_INTERFACE_COMMENT);
|
||||
if ( content.isValid() && content.toString().size() > 0 )
|
||||
commentList << QString("%1(%2)").arg(device.name).arg(content.toString());
|
||||
}
|
||||
|
||||
g_free(prefs.capture_devices_hide);
|
||||
prefs.capture_devices_hide = qstring_strdup(hideList.join(","));
|
||||
|
||||
g_free(prefs.capture_devices_descr);
|
||||
prefs.capture_devices_descr = qstring_strdup(commentList.join(","));
|
||||
}
|
||||
|
||||
int InterfaceTreeCacheModel::rowCount(const QModelIndex & parent) const
|
||||
{
|
||||
return sourceModel->rowCount(parent);
|
||||
}
|
||||
|
||||
bool InterfaceTreeCacheModel::changeIsAllowed(InterfaceTreeColumns col) const
|
||||
{
|
||||
if ( editableColumns.contains(col) || checkableColumns.contains(col) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InterfaceTreeCacheModel::isAllowedToBeChanged(const QModelIndex &index) const
|
||||
{
|
||||
if ( ! index.isValid() || ! global_capture_opts.all_ifaces )
|
||||
return false;
|
||||
|
||||
int idx = index.row();
|
||||
if ( (unsigned int) idx >= global_capture_opts.all_ifaces->len )
|
||||
return false;
|
||||
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
|
||||
|
||||
InterfaceTreeColumns col = (InterfaceTreeColumns) index.column();
|
||||
if ( col == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
if ( prefs.capture_device )
|
||||
{
|
||||
if ( ! g_strcmp0(prefs.capture_device, device.display_name) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Qt::ItemFlags InterfaceTreeCacheModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if ( ! index.isValid() )
|
||||
return 0;
|
||||
|
||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
|
||||
InterfaceTreeColumns col = (InterfaceTreeColumns) index.column();
|
||||
|
||||
if ( changeIsAllowed(col) && isAllowedToBeChanged(index) )
|
||||
{
|
||||
if ( checkableColumns.contains(col) )
|
||||
{
|
||||
flags = Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
||||
}
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
bool InterfaceTreeCacheModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if ( ! index.isValid() )
|
||||
return false;
|
||||
|
||||
if ( ! isAllowedToBeChanged(index) )
|
||||
return false;
|
||||
|
||||
int row = index.row();
|
||||
InterfaceTreeColumns col = (InterfaceTreeColumns)index.column();
|
||||
|
||||
if ( role == Qt::CheckStateRole || role == Qt::EditRole )
|
||||
{
|
||||
if ( changeIsAllowed( col ) )
|
||||
{
|
||||
QMap<InterfaceTreeColumns, QVariant> * dataField = 0;
|
||||
/* obtain the list of already stored changes for this row. If none exist
|
||||
* create a new storage row for this entry */
|
||||
if ( ( dataField = storage->value(row, 0) ) == 0 )
|
||||
{
|
||||
dataField = new QMap<InterfaceTreeColumns, QVariant>();
|
||||
storage->insert(row, dataField);
|
||||
}
|
||||
|
||||
dataField->insert(col, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if ( ! index.isValid() )
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
InterfaceTreeColumns col = (InterfaceTreeColumns)index.column();
|
||||
|
||||
if ( ( role == Qt::DisplayRole && editableColumns.contains(col) ) ||
|
||||
( role == Qt::CheckStateRole && checkableColumns.contains(col) ) )
|
||||
{
|
||||
QMap<InterfaceTreeColumns, QVariant> * dataField = 0;
|
||||
if ( ( dataField = storage->value(row, 0) ) != 0 )
|
||||
{
|
||||
if ( dataField->contains(col) )
|
||||
{
|
||||
return dataField->value(col, QVariant());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sourceModel->data(index, role);
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/* interface_tree_cache_model.h
|
||||
* Model caching interface changes before sending them to global storage
|
||||
*
|
||||
* 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 INTERFACE_TREE_CACHE_MODEL_H_
|
||||
#define INTERFACE_TREE_CACHE_MODEL_H_
|
||||
|
||||
#include "ui/qt/interface_tree_model.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QIdentityProxyModel>
|
||||
|
||||
class InterfaceTreeCacheModel : public QIdentityProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InterfaceTreeCacheModel(QObject *parent);
|
||||
~InterfaceTreeCacheModel();
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
QVariant getColumnContent(int idx, int col, int role = Qt::DisplayRole);
|
||||
|
||||
void reset(int row);
|
||||
void save();
|
||||
|
||||
private:
|
||||
InterfaceTreeModel * sourceModel;
|
||||
|
||||
QMap<int, QMap<InterfaceTreeColumns, QVariant> *> * storage;
|
||||
QList<InterfaceTreeColumns> editableColumns;
|
||||
QList<InterfaceTreeColumns> checkableColumns;
|
||||
|
||||
bool changeIsAllowed(InterfaceTreeColumns col) const;
|
||||
bool isAllowedToBeChanged(const QModelIndex &index) const;
|
||||
|
||||
};
|
||||
#endif /* INTERFACE_TREE_CACHE_MODEL_H_ */
|
||||
|
||||
/*
|
||||
* Editor modelines
|
||||
*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
||||
* :indentSize=4:tabSize=8:noTabs=true:
|
||||
*/
|
||||
|
|
@ -115,14 +115,15 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
InterfaceTreeColumns col = (InterfaceTreeColumns) index.column();
|
||||
|
||||
/* Data for display in cell */
|
||||
if ( role == Qt::DisplayRole )
|
||||
if ( interfacesLoaded )
|
||||
{
|
||||
if ( interfacesLoaded )
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
|
||||
|
||||
/* Data for display in cell */
|
||||
if ( role == Qt::DisplayRole )
|
||||
{
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
|
||||
/* Only the name is being displayed */
|
||||
if ( col == IFTREE_COL_NAME )
|
||||
{
|
||||
|
@ -138,50 +139,69 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
|
|||
return QString(device.if_info.extcap);
|
||||
}
|
||||
#endif
|
||||
else if ( col == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
return QVariant::fromValue((bool)device.hidden);
|
||||
}
|
||||
|
||||
else if ( col == IFTREE_COL_TYPE )
|
||||
{
|
||||
return QVariant::fromValue((int)device.if_info.type);
|
||||
}
|
||||
else if ( col == IFTREE_COL_INTERFACE_COMMENT )
|
||||
{
|
||||
QString comment = gchar_free_to_qstring(capture_dev_user_descr_find(device.name));
|
||||
if ( comment.length() > 0 )
|
||||
return comment;
|
||||
else
|
||||
return QString(device.if_info.vendor_description);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Return empty string for every other DisplayRole */
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
else if ( role == Qt::CheckStateRole )
|
||||
{
|
||||
if ( col == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
/* Hidden is a de-selection, therefore inverted logic here */
|
||||
return device.hidden ? Qt::Unchecked : Qt::Checked;
|
||||
}
|
||||
}
|
||||
/* Used by SparkLineDelegate for loading the data for the statistics line */
|
||||
else if ( role == Qt::UserRole )
|
||||
{
|
||||
if ( col == IFTREE_COL_STATS )
|
||||
{
|
||||
if ( points.contains(device.name) )
|
||||
return qVariantFromValue(points[device.name]);
|
||||
}
|
||||
else if ( col == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
return QVariant::fromValue((bool)device.hidden);
|
||||
}
|
||||
}
|
||||
|
||||
/* Return empty string for every other DisplayRole */
|
||||
return QVariant();
|
||||
}
|
||||
/* Used by SparkLineDelegate for loading the data for the statistics line */
|
||||
else if ( role == Qt::UserRole && col == IFTREE_COL_STATS && interfacesLoaded )
|
||||
{
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
|
||||
if ( points.contains(device.name) )
|
||||
return qVariantFromValue(points[device.name]);
|
||||
}
|
||||
#ifdef HAVE_EXTCAP
|
||||
/* Displays the configuration icon for extcap interfaces */
|
||||
else if ( role == Qt::DecorationRole && interfacesLoaded )
|
||||
{
|
||||
if ( col == IFTREE_COL_EXTCAP )
|
||||
/* Displays the configuration icon for extcap interfaces */
|
||||
else if ( role == Qt::DecorationRole )
|
||||
{
|
||||
QIcon extcap_icon(StockIcon("x-capture-options"));
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, row);
|
||||
if ( device.if_info.type == IF_EXTCAP )
|
||||
return extcap_icon;
|
||||
if ( col == IFTREE_COL_EXTCAP )
|
||||
{
|
||||
if ( device.if_info.type == IF_EXTCAP )
|
||||
return QIcon(StockIcon("x-capture-options"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( role == Qt::TextAlignmentRole)
|
||||
{
|
||||
if ( col == IFTREE_COL_EXTCAP )
|
||||
else if ( role == Qt::TextAlignmentRole )
|
||||
{
|
||||
return Qt::AlignRight;
|
||||
if ( col == IFTREE_COL_EXTCAP )
|
||||
{
|
||||
return Qt::AlignRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Displays the tooltip for each row */
|
||||
else if ( role == Qt::ToolTipRole )
|
||||
{
|
||||
return toolTipForInterface(row);
|
||||
/* Displays the tooltip for each row */
|
||||
else if ( role == Qt::ToolTipRole )
|
||||
{
|
||||
return toolTipForInterface(row);
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(index);
|
||||
|
@ -191,6 +211,34 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant InterfaceTreeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if ( orientation == Qt::Horizontal )
|
||||
{
|
||||
if ( role == Qt::DisplayRole )
|
||||
{
|
||||
if ( section == IFTREE_COL_HIDDEN )
|
||||
{
|
||||
return tr("Show");
|
||||
}
|
||||
else if ( section == IFTREE_COL_INTERFACE_NAME )
|
||||
{
|
||||
return tr("Friendly Name");
|
||||
}
|
||||
else if ( section == IFTREE_COL_INTERFACE_NAME )
|
||||
{
|
||||
return tr("Interface Name");
|
||||
}
|
||||
else if ( section == IFTREE_COL_INTERFACE_COMMENT )
|
||||
{
|
||||
return tr("Comment");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant InterfaceTreeModel::getColumnContent(int idx, int col, int role)
|
||||
{
|
||||
return InterfaceTreeModel::data(index(idx, col), role);
|
||||
|
|
|
@ -47,6 +47,7 @@ enum InterfaceTreeColumns
|
|||
#endif
|
||||
IFTREE_COL_NAME,
|
||||
IFTREE_COL_INTERFACE_NAME,
|
||||
IFTREE_COL_INTERFACE_COMMENT,
|
||||
IFTREE_COL_HIDDEN,
|
||||
IFTREE_COL_TYPE,
|
||||
IFTREE_COL_STATS,
|
||||
|
@ -63,6 +64,7 @@ public:
|
|||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
void updateStatistic(unsigned int row);
|
||||
#ifdef HAVE_LIBPCAP
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "capture_opts.h"
|
||||
#include "ui/capture_globals.h"
|
||||
#include "ui/qt/capture_interfaces_dialog.h"
|
||||
#include "ui/qt/interface_tree_cache_model.h"
|
||||
#include "ui/qt/interface_sort_filter_model.h"
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
#include "ui/qt/remote_capture_dialog.h"
|
||||
#include "ui/qt/remote_settings_dialog.h"
|
||||
|
@ -66,13 +68,6 @@ enum {
|
|||
col_p_pipe_
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
col_l_show_,
|
||||
col_l_friendly_name_,
|
||||
col_l_local_name_,
|
||||
col_l_comment_
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -100,19 +95,29 @@ ManageInterfacesDialog::ManageInterfacesDialog(QWidget *parent) :
|
|||
ui->delRemote->setAttribute(Qt::WA_MacSmallSize, true);
|
||||
#endif
|
||||
|
||||
int one_em = fontMetrics().height();
|
||||
sourceModel = new InterfaceTreeCacheModel(this);
|
||||
|
||||
ui->localList->setColumnWidth(col_l_show_, one_em * 3);
|
||||
#ifndef Q_OS_WIN
|
||||
ui->localList->setColumnHidden(col_l_friendly_name_, true);
|
||||
proxyModel = new InterfaceSortFilterModel(this);
|
||||
QList<InterfaceTreeColumns> columns;
|
||||
columns.append(IFTREE_COL_HIDDEN);
|
||||
columns.append(IFTREE_COL_INTERFACE_NAME);
|
||||
#ifdef Q_OS_WIN
|
||||
columns.append(IFTREE_COL_NAME);
|
||||
#endif
|
||||
ui->localList->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
columns.append(IFTREE_COL_INTERFACE_COMMENT);
|
||||
proxyModel->setColumns(columns);
|
||||
proxyModel->setSourceModel(sourceModel);
|
||||
proxyModel->setFilterHidden(false);
|
||||
proxyModel->setFilterByType(false);
|
||||
|
||||
|
||||
ui->localView->setModel(proxyModel);
|
||||
ui->localView->resizeColumnToContents(proxyModel->mapSourceToColumn(IFTREE_COL_HIDDEN));
|
||||
ui->localView->resizeColumnToContents(proxyModel->mapSourceToColumn(IFTREE_COL_INTERFACE_NAME));
|
||||
ui->pipeList->setItemDelegateForColumn(col_p_pipe_, &new_pipe_item_delegate_);
|
||||
new_pipe_item_delegate_.setTree(ui->pipeList);
|
||||
|
||||
showPipes();
|
||||
showLocalInterfaces();
|
||||
|
||||
#if defined(HAVE_PCAP_REMOTE)
|
||||
// The default indentation (20) means our checkboxes are shifted too far on Windows.
|
||||
|
@ -127,7 +132,6 @@ ManageInterfacesDialog::ManageInterfacesDialog(QWidget *parent) :
|
|||
|
||||
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateWidgets()));
|
||||
connect(this, SIGNAL(ifsChanged()), parent, SIGNAL(ifsChanged()));
|
||||
connect(ui->localList, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this, SLOT(localListItemDoubleClicked(QTreeWidgetItem *, int)));
|
||||
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
connect(this, SIGNAL(remoteAdded(GList*, remote_options*)), this, SLOT(addRemoteInterfaces(GList*, remote_options*)));
|
||||
|
@ -214,11 +218,12 @@ void ManageInterfacesDialog::showPipes()
|
|||
void ManageInterfacesDialog::on_buttonBox_accepted()
|
||||
{
|
||||
pipeAccepted();
|
||||
localAccepted();
|
||||
sourceModel->save();
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
remoteAccepted();
|
||||
#endif
|
||||
prefs_main_write();
|
||||
wsApp->refreshLocalInterfaces();
|
||||
emit ifsChanged();
|
||||
}
|
||||
|
||||
|
@ -316,169 +321,11 @@ void ManageInterfacesDialog::on_pipeList_currentItemChanged(QTreeWidgetItem *, Q
|
|||
updateWidgets();
|
||||
}
|
||||
|
||||
void ManageInterfacesDialog::showLocalInterfaces()
|
||||
{
|
||||
guint i;
|
||||
interface_t device;
|
||||
gchar *pr_descr = g_strdup("");
|
||||
char *comment = NULL;
|
||||
|
||||
ui->localList->clear();
|
||||
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) {
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->localList);
|
||||
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
if (prefs.capture_device && strstr(prefs.capture_device, device.name)) {
|
||||
// Force the default device to be checked.
|
||||
item->setFlags(item->flags() ^ Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(col_l_show_, Qt::Checked);
|
||||
} else {
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(col_l_show_, device.hidden ? Qt::Unchecked : Qt::Checked);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
item->setText(col_l_friendly_name_, device.friendly_name);
|
||||
#endif
|
||||
item->setText(col_l_local_name_, device.name);
|
||||
|
||||
comment = capture_dev_user_descr_find(device.name);
|
||||
if (comment) {
|
||||
item->setText(col_l_comment_, comment);
|
||||
g_free(comment);
|
||||
} else if (device.if_info.vendor_description) {
|
||||
item->setText(col_l_comment_, device.if_info.vendor_description);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
g_free(pr_descr);
|
||||
}
|
||||
|
||||
void ManageInterfacesDialog::saveLocalHideChanges(QTreeWidgetItem *item)
|
||||
{
|
||||
guint i;
|
||||
interface_t device;
|
||||
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString name = item->text(col_l_local_name_);
|
||||
/* 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(col_l_show_) == Qt::Checked ? false : true);
|
||||
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(QTreeWidgetItem* item)
|
||||
{
|
||||
guint i;
|
||||
interface_t device;
|
||||
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString name = item->text(col_l_local_name_);
|
||||
QString comment = item->text(col_l_comment_);
|
||||
/* 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;
|
||||
}
|
||||
|
||||
g_free(device.display_name);
|
||||
device.display_name = get_iface_display_name(comment.toUtf8().constData(), &device.if_info);
|
||||
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 0 // Not needed?
|
||||
void ManageInterfacesDialog::checkBoxChanged(QTreeWidgetItem* item)
|
||||
{
|
||||
guint i;
|
||||
interface_t device;
|
||||
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString name = item->text(col_l_local_name_);
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // checkBoxChanged not needed?
|
||||
|
||||
void ManageInterfacesDialog::localAccepted()
|
||||
{
|
||||
|
||||
if (global_capture_opts.all_ifaces->len > 0) {
|
||||
QStringList hide_list;
|
||||
QStringList comment_list;
|
||||
QTreeWidgetItemIterator it(ui->localList);
|
||||
while (*it) {
|
||||
if ((*it)->checkState(col_l_show_) != Qt::Checked) {
|
||||
hide_list << (*it)->text(col_l_local_name_);
|
||||
}
|
||||
|
||||
if (!(*it)->text(col_l_local_name_).isEmpty()) {
|
||||
comment_list << QString("%1(%2)").arg((*it)->text(col_l_local_name_)).arg((*it)->text(col_l_comment_));
|
||||
}
|
||||
|
||||
saveLocalHideChanges(*it);
|
||||
saveLocalCommentChanges(*it);
|
||||
++it;
|
||||
}
|
||||
/* write new "hidden" string to preferences */
|
||||
g_free(prefs.capture_devices_hide);
|
||||
gchar *new_hide = qstring_strdup(hide_list.join(","));
|
||||
prefs.capture_devices_hide = new_hide;
|
||||
hide_interface(g_strdup(new_hide));
|
||||
|
||||
/* write new description string to preferences */
|
||||
if (prefs.capture_devices_descr)
|
||||
g_free(prefs.capture_devices_descr);
|
||||
prefs.capture_devices_descr = qstring_strdup(comment_list.join(","));
|
||||
}
|
||||
}
|
||||
|
||||
void ManageInterfacesDialog::on_buttonBox_helpRequested()
|
||||
{
|
||||
wsApp->helpTopicAction(HELP_CAPTURE_MANAGE_INTERFACES_DIALOG);
|
||||
}
|
||||
|
||||
void ManageInterfacesDialog::localListItemDoubleClicked(QTreeWidgetItem * item, int column)
|
||||
{
|
||||
if (column == col_l_comment_) {
|
||||
ui->localList->editItem(item, column);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
void ManageInterfacesDialog::remoteSelectionChanged(QTreeWidgetItem*, int)
|
||||
{
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <glib.h>
|
||||
#include "capture_opts.h"
|
||||
|
||||
#include "ui/qt/interface_tree_cache_model.h"
|
||||
#include "ui/qt/interface_sort_filter_model.h"
|
||||
|
||||
#include "geometry_state_dialog.h"
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
|
@ -78,14 +81,10 @@ private:
|
|||
Ui::ManageInterfacesDialog *ui;
|
||||
PathChooserDelegate new_pipe_item_delegate_;
|
||||
|
||||
InterfaceTreeCacheModel * sourceModel;
|
||||
InterfaceSortFilterModel * proxyModel;
|
||||
void showPipes();
|
||||
void showLocalInterfaces();
|
||||
void showRemoteInterfaces();
|
||||
void saveLocalHideChanges(QTreeWidgetItem *item);
|
||||
void saveLocalCommentChanges(QTreeWidgetItem *item);
|
||||
#if 0 // Not needed?
|
||||
void checkBoxChanged(QTreeWidgetItem *item);
|
||||
#endif
|
||||
|
||||
signals:
|
||||
void ifsChanged();
|
||||
|
@ -104,8 +103,6 @@ private slots:
|
|||
void pipeAccepted();
|
||||
void on_pipeList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
void localAccepted();
|
||||
void localListItemDoubleClicked(QTreeWidgetItem * item, int column);
|
||||
|
||||
#ifdef HAVE_PCAP_REMOTE
|
||||
void on_addRemote_clicked();
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="localTab">
|
||||
<property name="toolTip">
|
||||
|
@ -34,7 +34,7 @@
|
|||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="localList">
|
||||
<widget class="QTreeView" name="localView">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
|
@ -50,26 +50,6 @@
|
|||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</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>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue