|
From: <cn...@us...> - 2021-02-18 17:46:07
|
Revision: 1148
http://sourceforge.net/p/seq/svn/1148
Author: cn187
Date: 2021-02-18 17:46:04 +0000 (Thu, 18 Feb 2021)
Log Message:
-----------
Enumerate net devices and prompt for selection if needed
Instead of failing to start if the default/saved net device isn't valid,
enumerate the available devices and present the user with a list of
devices to choose from.
Also update the Network->Select Device menu item to use the new
enumerated list/selector.
Modified Paths:
--------------
showeq/branches/cn187_devel/src/interface.cpp
showeq/branches/cn187_devel/src/interface.h
Modified: showeq/branches/cn187_devel/src/interface.cpp
===================================================================
--- showeq/branches/cn187_devel/src/interface.cpp 2021-02-18 17:45:52 UTC (rev 1147)
+++ showeq/branches/cn187_devel/src/interface.cpp 2021-02-18 17:46:04 UTC (rev 1148)
@@ -71,6 +71,7 @@
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
+#include <ifaddrs.h>
#include <QFont>
#include <QApplication>
@@ -145,7 +146,8 @@
m_combatWindow(0),
m_netDiag(0),
m_messageFilterDialog(0),
- m_guildListWindow(0)
+ m_guildListWindow(0),
+ m_deviceList(enumerateDevices())
{
setObjectName(name);
setWindowFlags(Qt::Window);
@@ -221,10 +223,23 @@
fileInfo2 = m_dataLocationMgr->findExistingFile(".", fileName2);
+ QString net_device = pSEQPrefs->getPrefString("Device", section, "eth0");
+ if (!m_deviceList.contains(net_device))
+ {
+ QString selected = promptForNetDevice();
+
+ if (!selected.isEmpty())
+ {
+ // set it as the device to monitor next session
+ pSEQPrefs->setPrefString("Device", "Network", selected);
+ net_device = selected;
+ }
+ }
+
m_packet = new EQPacket(fileInfo.absoluteFilePath(),
fileInfo2.absoluteFilePath(),
pSEQPrefs->getPrefInt("ArqSeqGiveUp", section, 512),
- pSEQPrefs->getPrefString("Device", section, "eth0"),
+ net_device,
pSEQPrefs->getPrefString("IP", section,
AUTOMATIC_CLIENT_IP),
pSEQPrefs->getPrefString("MAC", section, "0"),
@@ -5149,23 +5164,68 @@
}
}
-void EQInterface::set_net_device()
+QStringList EQInterface::enumerateDevices()
{
- bool ok = false;
- QString dev =
- QInputDialog::getText(this, "ShowEQ - Device",
+ struct ifaddrs *ifaddr, *ifa;
+ int n;
+ QStringList devices;
+
+ if (getifaddrs(&ifaddr) == -1)
+ {
+ seqWarn("Could not enumerate network devices");
+ return QStringList();
+ }
+
+ for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if (ifa->ifa_addr->sa_family == AF_INET)
+ devices.append(ifa->ifa_name);
+ }
+
+ freeifaddrs(ifaddr);
+
+ return devices;
+}
+
+QString EQInterface::promptForNetDevice()
+{
+ m_deviceList = enumerateDevices();
+
+ int current = 0;
+ if (m_packet)
+ current = m_deviceList.indexOf(m_packet->device());
+
+ bool ok = false;
+ QString selected = QInputDialog::getItem(this, "ShowEQ - Device",
"Enter the device to sniff for EQ Packets:",
- QLineEdit::Normal, m_packet->device(),
- &ok);
+ m_deviceList, current, true, &ok);
- if (ok)
- {
- // start monitoring the device
- m_packet->monitorDevice(dev);
+ if (ok)
+ return selected;
+ else
+ return QString();
+}
- // set it as the device to monitor next session
- pSEQPrefs->setPrefString("Device", "Network", m_packet->device());
- }
+
+void EQInterface::set_net_device()
+{
+
+ QString selected = promptForNetDevice();
+
+ if (!selected.isEmpty())
+ {
+ if (m_packet)
+ {
+ // start monitoring the device
+ m_packet->monitorDevice(selected);
+ }
+
+ // set it as the device to monitor next session
+ pSEQPrefs->setPrefString("Device", "Network", selected);
+ }
}
void EQInterface::set_net_arq_giveup(int giveup)
Modified: showeq/branches/cn187_devel/src/interface.h
===================================================================
--- showeq/branches/cn187_devel/src/interface.h 2021-02-18 17:45:52 UTC (rev 1147)
+++ showeq/branches/cn187_devel/src/interface.h 2021-02-18 17:46:04 UTC (rev 1148)
@@ -341,6 +341,8 @@
void insertWindowMenu(SEQWindow* window);
void removeWindowMenu(SEQWindow* window);
void setDockEnabled(QDockWidget* dw, bool enable);
+ QStringList enumerateDevices();
+ QString promptForNetDevice();
public:
Player* m_player;
@@ -415,6 +417,9 @@
MessageFilterDialog* m_messageFilterDialog;
GuildListWindow* m_guildListWindow;
+ QStringList m_deviceList;
+
+
QLabel* m_stsbarSpawns;
QLabel* m_stsbarStatus;
QLabel* m_stsbarZone;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|