summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/qt/interface_frame.cpp102
-rw-r--r--ui/qt/interface_sort_filter_model.cpp62
-rw-r--r--ui/qt/interface_sort_filter_model.h10
-rw-r--r--ui/qt/interface_tree_model.cpp125
-rw-r--r--ui/qt/interface_tree_model.h11
5 files changed, 210 insertions, 100 deletions
diff --git a/ui/qt/interface_frame.cpp b/ui/qt/interface_frame.cpp
index 82cbda8116..a9088f490a 100644
--- a/ui/qt/interface_frame.cpp
+++ b/ui/qt/interface_frame.cpp
@@ -83,10 +83,19 @@ InterfaceFrame::InterfaceFrame(QWidget * parent)
proxyModel = new InterfaceSortFilterModel(this);
sourceModel = new InterfaceTreeModel(this);
+
+ QList<InterfaceTreeColumns> columns;
+#ifdef HAVE_EXTCAP
+ columns.append(IFTREE_COL_EXTCAP);
+#endif
+ columns.append(IFTREE_COL_NAME);
+ columns.append(IFTREE_COL_STATS);
+ proxyModel->setColumns(columns);
+
proxyModel->setSourceModel(sourceModel);
ui->interfaceTree->setModel(proxyModel);
- ui->interfaceTree->setItemDelegateForColumn(IFTREE_COL_STATS, new SparkLineDelegate(this));
+ ui->interfaceTree->setItemDelegateForColumn(proxyModel->mapSourceToColumn(IFTREE_COL_STATS), new SparkLineDelegate(this));
buttonLayout = new QHBoxLayout(ui->wdgButtons);
@@ -147,21 +156,12 @@ QAbstractButton * InterfaceFrame::createButton(QString text, QString prop, QVari
void InterfaceFrame::interfaceListChanged()
{
- if ( sourceModel->rowCount() == 0 )
+ if ( proxyModel->rowCount() == 0 )
{
ui->interfaceTree->setHidden(true);
ui->lblNoInterfaces->setHidden(false);
-#ifdef HAVE_LIBPCAP
- if ( global_capture_opts.ifaces_err != 0 )
- {
- ui->lblNoInterfaces->setText(tr(global_capture_opts.ifaces_err_info));
- }
- else
-#endif
- {
- ui->lblNoInterfaces->setText(tr("No interfaces found"));
- }
+ ui->lblNoInterfaces->setText( sourceModel->interfaceError() );
}
else
{
@@ -220,25 +220,8 @@ void InterfaceFrame::updateSelectedInterfaces()
if ( sourceModel->rowCount() == 0 )
return;
#ifdef HAVE_LIBPCAP
- QItemSelection mySelection;
-
- for( int idx = 0; idx < sourceModel->rowCount(); idx++ )
- {
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
-
- if ( device.selected )
- {
- QModelIndex selectIndex = proxyModel->mapFromSource(sourceModel->index(idx, 0));
- /* Proxy model has masked out the interface */
- if ( !selectIndex.isValid() )
- continue;
-
- mySelection.merge(
- QItemSelection( selectIndex, proxyModel->index(selectIndex.row(), sourceModel->columnCount() - 1) ),
- QItemSelectionModel::SelectCurrent
- );
- }
- }
+ QItemSelection sourceSelection = sourceModel->selectedDevices();
+ QItemSelection mySelection = proxyModel->mapSelectionFromSource(sourceSelection);
ui->interfaceTree->selectionModel()->clearSelection();
ui->interfaceTree->selectionModel()->select(mySelection, QItemSelectionModel::SelectCurrent );
@@ -251,54 +234,13 @@ void InterfaceFrame::interfaceTreeSelectionChanged(const QItemSelection & select
return;
if ( sourceModel->rowCount() == 0 )
return;
-#ifdef HAVE_LIBPCAP
- QList<int> selectedIndices;
+#ifdef HAVE_LIBPCAP
/* Take all selected interfaces, not just the newly ones */
QItemSelection allSelected = ui->interfaceTree->selectionModel()->selection();
QItemSelection sourceSelection = proxyModel->mapSelectionToSource(allSelected);
- foreach(QItemSelectionRange selection, sourceSelection)
- {
- foreach(QModelIndex index, selection.indexes())
- {
- if ( ! selectedIndices.contains(index.row()) )
- {
- selectedIndices.append(index.row());
- }
- }
- }
-
- global_capture_opts.num_selected = 0;
- bool selectionHasChanged = false;
-
- 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.locked )
- {
- if ( selectedIndices.contains(idx) )
- {
- if (! device.selected )
- selectionHasChanged = true;
- device.selected = TRUE;
- global_capture_opts.num_selected++;
- } else {
- if ( device.selected )
- selectionHasChanged = true;
- device.selected = FALSE;
- }
- device.locked = TRUE;
- 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);
-
- device.locked = FALSE;
- 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);
- }
- }
-
- if ( selectionHasChanged )
+ if ( sourceModel->updateSelectedDevices(sourceSelection) )
emit itemSelectionChanged();
#endif
}
@@ -311,15 +253,14 @@ void InterfaceFrame::on_interfaceTree_doubleClicked(const QModelIndex &index)
return;
#if defined(HAVE_EXTCAP) && defined(HAVE_LIBPCAP)
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, realIndex.row());
- QString extcap_string = device.if_info.extcap;
+ QString device_name = sourceModel->getColumnContent(realIndex.row(), IFTREE_COL_INTERFACE_NAME).toString();
+ QString extcap_string = sourceModel->getColumnContent(realIndex.row(), IFTREE_COL_EXTCAP_PATH).toString();
/* We trust the string here. If this interface is really extcap, the string is
* being checked immediatly before the dialog is being generated */
if ( extcap_string.length() > 0 )
{
- QString device_name = device.name;
/* this checks if configuration is required and not yet provided or saved via prefs */
if ( extcap_has_configuration((const char *)(device_name.toStdString().c_str()), TRUE) )
{
@@ -341,16 +282,13 @@ void InterfaceFrame::on_interfaceTree_clicked(const QModelIndex &index)
if ( ! realIndex.isValid() )
return;
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, realIndex.row());
-
- QString extcap_string = device.if_info.extcap;
+ QString device_name = sourceModel->getColumnContent(realIndex.row(), IFTREE_COL_INTERFACE_NAME).toString();
+ QString extcap_string = sourceModel->getColumnContent(realIndex.row(), IFTREE_COL_EXTCAP_PATH).toString();
/* We trust the string here. If this interface is really extcap, the string is
* being checked immediatly before the dialog is being generated */
if ( extcap_string.length() > 0 )
{
- QString device_name = device.name;
-
/* this checks if configuration is required and not yet provided or saved via prefs */
if ( extcap_has_configuration((const char *)(device_name.toStdString().c_str()), FALSE) )
{
diff --git a/ui/qt/interface_sort_filter_model.cpp b/ui/qt/interface_sort_filter_model.cpp
index 9503fb16cc..5a1823a398 100644
--- a/ui/qt/interface_sort_filter_model.cpp
+++ b/ui/qt/interface_sort_filter_model.cpp
@@ -20,8 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "interface_tree_model.h"
-#include "interface_sort_filter_model.h"
+#include "ui/qt/interface_tree_model.h"
+#include "ui/qt/interface_sort_filter_model.h"
#include <glib.h>
@@ -38,6 +38,10 @@ InterfaceSortFilterModel::InterfaceSortFilterModel(QObject *parent) :
{
_filterHidden = true;
+ /* Adding all columns, to have a default setting */
+ for ( int col = 0; col < IFTREE_COL_MAX; col++ )
+ _columns.append((InterfaceTreeColumns)col);
+
connect(wsApp, SIGNAL(preferencesChanged()), this, SLOT(resetPreferenceData()));
resetPreferenceData();
@@ -86,20 +90,22 @@ int InterfaceSortFilterModel::interfacesHidden()
QList<int> InterfaceSortFilterModel::typesDisplayed()
{
QList<int> shownTypes;
-#ifdef HAVE_LIBPCAP
- if ( ! global_capture_opts.all_ifaces )
+
+ if ( sourceModel()->rowCount() == 0 )
return shownTypes;
- for(unsigned int idx = 0; idx < global_capture_opts.all_ifaces->len; idx++)
+ for (int idx = 0; idx < sourceModel()->rowCount(); idx++)
{
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
- if ( ! device.hidden )
+ int type = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_TYPE).toInt();
+ bool hidden = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_HIDDEN).toBool();
+
+ if ( ! hidden )
{
- if ( ! shownTypes.contains(device.if_info.type) )
- shownTypes.append(device.if_info.type);
+ if ( ! shownTypes.contains(type) )
+ shownTypes.append(type);
}
}
-#endif
+
return shownTypes;
}
@@ -147,21 +153,49 @@ bool InterfaceSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex
int idx = realIndex.row();
/* No data loaded, we do not display anything */
- if ( ! global_capture_opts.all_ifaces || global_capture_opts.all_ifaces->len <= (guint) idx )
+ if ( sourceModel()->rowCount() == 0 )
return false;
- interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
+ int type = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_TYPE).toInt();
+ bool hidden = ((InterfaceTreeModel *)sourceModel())->getColumnContent(idx, IFTREE_COL_HIDDEN).toBool();
- if ( device.hidden && _filterHidden )
+ if ( hidden && _filterHidden )
return false;
- if ( ! isInterfaceTypeShown(device.if_info.type) )
+ if ( ! isInterfaceTypeShown(type) )
return false;
#endif
return true;
}
+bool InterfaceSortFilterModel::filterAcceptsColumn(int sourceColumn, const QModelIndex & sourceParent) const
+{
+ QModelIndex realIndex = sourceModel()->index(0, sourceColumn, sourceParent);
+
+ if ( ! realIndex.isValid() )
+ return false;
+
+ if ( ! _columns.contains((InterfaceTreeColumns)sourceColumn) )
+ return false;
+
+ return true;
+}
+
+void InterfaceSortFilterModel::setColumns(QList<InterfaceTreeColumns> columns)
+{
+ _columns.clear();
+ _columns.append(columns);
+}
+
+int InterfaceSortFilterModel::mapSourceToColumn(InterfaceTreeColumns mdlIndex)
+{
+ if ( ! _columns.contains(mdlIndex) )
+ return -1;
+
+ return _columns.indexOf(mdlIndex, 0);
+}
+
/*
* Editor modelines
*
diff --git a/ui/qt/interface_sort_filter_model.h b/ui/qt/interface_sort_filter_model.h
index 08a217747b..d0489cb3e5 100644
--- a/ui/qt/interface_sort_filter_model.h
+++ b/ui/qt/interface_sort_filter_model.h
@@ -25,9 +25,7 @@
#include <config.h>
-#ifdef HAVE_LIBPCAP
-#include "ui/capture_globals.h"
-#endif
+#include "ui/qt/interface_tree_model.h"
#include <glib.h>
@@ -48,14 +46,20 @@ public:
QList<int> typesDisplayed();
+ void setColumns(QList<InterfaceTreeColumns> columns);
+ int mapSourceToColumn(InterfaceTreeColumns mdlIndex);
+
protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
+ bool filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const;
private:
bool _filterHidden;
QList<int> displayHiddenTypes;
+ QList<InterfaceTreeColumns> _columns;
+
private slots:
void resetPreferenceData();
};
diff --git a/ui/qt/interface_tree_model.cpp b/ui/qt/interface_tree_model.cpp
index 94e94113d8..ab1ee1d612 100644
--- a/ui/qt/interface_tree_model.cpp
+++ b/ui/qt/interface_tree_model.cpp
@@ -71,6 +71,23 @@ InterfaceTreeModel::~InterfaceTreeModel(void)
#endif // HAVE_LIBPCAP
}
+QString InterfaceTreeModel::interfaceError()
+{
+ QString errorText;
+ if ( rowCount() == 0 )
+ {
+ errorText = tr("No Interfaces found!");
+ }
+#ifdef HAVE_LIBPCAP
+ else if ( global_capture_opts.ifaces_err != 0 )
+ {
+ errorText = tr(global_capture_opts.ifaces_err_info);
+ }
+#endif
+
+ return errorText;
+}
+
int InterfaceTreeModel::rowCount(const QModelIndex & parent) const
{
Q_UNUSED(parent);
@@ -115,7 +132,22 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
{
return QString(device.display_name);
}
-
+ else if ( col == IFTREE_COL_INTERFACE_NAME )
+ {
+ return QString(device.name);
+ }
+ else if ( col == IFTREE_COL_EXTCAP_PATH )
+ {
+ return QString(device.if_info.extcap);
+ }
+ 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);
+ }
}
/* Return empty string for every other DisplayRole */
@@ -160,6 +192,11 @@ QVariant InterfaceTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}
+QVariant InterfaceTreeModel::getColumnContent(int idx, int col)
+{
+ return InterfaceTreeModel::data(index(idx, col), Qt::DisplayRole);
+}
+
/**
* The interface list has changed. global_capture_opts.all_ifaces may have been reloaded
* or changed with current data. beginResetModel() and endResetModel() will signalize the
@@ -300,3 +337,89 @@ void InterfaceTreeModel::getPoints(int idx, PointList *pts)
Q_UNUSED(pts);
#endif
}
+
+QItemSelection InterfaceTreeModel::selectedDevices()
+{
+ QItemSelection mySelection;
+
+ for( int idx = 0; idx < rowCount(); idx++ )
+ {
+ interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
+
+ if ( device.selected )
+ {
+ QModelIndex selectIndex = index(idx, 0);
+ /* Proxy model has masked out the interface */
+ if ( !selectIndex.isValid() )
+ continue;
+
+ mySelection.merge(
+ QItemSelection( selectIndex, index(selectIndex.row(), columnCount() - 1) ),
+ QItemSelectionModel::SelectCurrent
+ );
+ }
+ }
+
+ return mySelection;
+}
+
+bool InterfaceTreeModel::updateSelectedDevices(QItemSelection sourceSelection)
+{
+ bool selectionHasChanged = false;
+ QList<int> selectedIndices;
+
+ foreach(QItemSelectionRange selection, sourceSelection)
+ {
+ foreach(QModelIndex index, selection.indexes())
+ {
+ if ( ! selectedIndices.contains(index.row()) )
+ {
+ selectedIndices.append(index.row());
+ }
+ }
+ }
+
+ global_capture_opts.num_selected = 0;
+
+ 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.locked )
+ {
+ if ( selectedIndices.contains(idx) )
+ {
+ if (! device.selected )
+ selectionHasChanged = true;
+ device.selected = TRUE;
+ global_capture_opts.num_selected++;
+ } else {
+ if ( device.selected )
+ selectionHasChanged = true;
+ device.selected = FALSE;
+ }
+ device.locked = TRUE;
+ 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);
+
+ device.locked = FALSE;
+ 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);
+ }
+ }
+
+ return selectionHasChanged;
+}
+
+
+/*
+ * 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:
+ */
diff --git a/ui/qt/interface_tree_model.h b/ui/qt/interface_tree_model.h
index 9e1b7808ca..0e5e9e6aac 100644
--- a/ui/qt/interface_tree_model.h
+++ b/ui/qt/interface_tree_model.h
@@ -35,6 +35,7 @@
#include <QAbstractTableModel>
#include <QList>
#include <QMap>
+#include <QItemSelection>
typedef QList<int> PointList;
@@ -42,8 +43,12 @@ enum InterfaceTreeColumns
{
#ifdef HAVE_EXTCAP
IFTREE_COL_EXTCAP,
+ IFTREE_COL_EXTCAP_PATH,
#endif
IFTREE_COL_NAME,
+ IFTREE_COL_INTERFACE_NAME,
+ IFTREE_COL_HIDDEN,
+ IFTREE_COL_TYPE,
IFTREE_COL_STATS,
IFTREE_COL_MAX /* is not being displayed, it is the definition for the maximum numbers of columns */
};
@@ -64,6 +69,12 @@ public:
void stopStatistic();
#endif
+ QString interfaceError();
+ QItemSelection selectedDevices();
+ bool updateSelectedDevices(QItemSelection sourceSelection);
+
+ QVariant getColumnContent(int idx, int col);
+
public slots:
void getPoints(int idx, PointList *pts);