summaryrefslogtreecommitdiffstats
path: root/src/net/pvsNetworkInterfaceListModel.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-06 00:04:49 +0200
committerSebastien Braun2010-10-06 00:04:49 +0200
commitf07fc3b426815e28fde23313242fbbb998a08d45 (patch)
treeba9eda1a83135a1727d2d35661d6facabee53b95 /src/net/pvsNetworkInterfaceListModel.cpp
parentFix recognition of letters in keyboard handler (diff)
parentMerge remote branch 'openslx/master' into mcastft (diff)
downloadpvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.gz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.xz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.zip
Merge remote branch 'openslx/mcastft' into input
Conflicts: CMakeLists.txt i18n/pvs_ar_JO.ts i18n/pvs_de_DE.ts i18n/pvs_es_MX.ts i18n/pvs_fr_FR.ts i18n/pvs_pl_PL.ts i18n/pvsmgr_ar_JO.ts i18n/pvsmgr_de_DE.ts i18n/pvsmgr_es_MX.ts i18n/pvsmgr_fr_FR.ts i18n/pvsmgr_pl_PL.ts icons/README pvsmgr.qrc src/gui/mainWindow.cpp src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/util/clientGUIUtils.h
Diffstat (limited to 'src/net/pvsNetworkInterfaceListModel.cpp')
-rw-r--r--src/net/pvsNetworkInterfaceListModel.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/net/pvsNetworkInterfaceListModel.cpp b/src/net/pvsNetworkInterfaceListModel.cpp
new file mode 100644
index 0000000..67d0c0a
--- /dev/null
+++ b/src/net/pvsNetworkInterfaceListModel.cpp
@@ -0,0 +1,81 @@
+/*
+ * pvsNetworkInterfaceListModel.cpp
+ *
+ * Created on: 04.08.2010
+ * Author: brs
+ */
+
+#include "pvsNetworkInterfaceListModel.h"
+#include <QStringList>
+
+PVSNetworkInterfaceListModel::PVSNetworkInterfaceListModel(QObject* parent) :
+ QAbstractListModel(parent)
+{
+ reloadInterfaceList();
+}
+
+PVSNetworkInterfaceListModel::~PVSNetworkInterfaceListModel()
+{
+}
+
+void PVSNetworkInterfaceListModel::reloadInterfaceList()
+{
+ _interfaces = QNetworkInterface::allInterfaces();
+ reset();
+}
+
+QVariant PVSNetworkInterfaceListModel::data(QModelIndex const& index, int role) const
+{
+ int i = index.row();
+ if(0 > i || i >= _interfaces.size())
+ {
+ return QVariant();
+ }
+ QNetworkInterface intf = _interfaces.at(i);
+
+ switch(role)
+ {
+ case Qt::DisplayRole:
+ {
+ QString name = intf.humanReadableName();
+ QList<QNetworkAddressEntry> addresses = intf.addressEntries();
+ QStringList l;
+
+ foreach(QNetworkAddressEntry addr, addresses)
+ {
+ l.append(addr.ip().toString());
+ }
+
+ return QString("%1 (%2)").arg(name).arg(l.join(", "));
+ }
+ case Qt::EditRole:
+ case Qt::UserRole:
+ return intf.name();
+ default:
+ return QVariant();
+ }
+}
+
+QVariant PVSNetworkInterfaceListModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if(section == 0 && orientation == Qt::Vertical && role == Qt::DisplayRole)
+ {
+ return tr("Interface");
+ }
+ else
+ {
+ return QVariant();
+ }
+}
+
+int PVSNetworkInterfaceListModel::rowCount(QModelIndex const& parent) const
+{
+ if(parent.isValid())
+ {
+ return 0;
+ }
+ else
+ {
+ return _interfaces.size();
+ }
+}