mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-09 20:05:53 +00:00
rewrite mainwindow to use helper
This commit is contained in:
@ -27,6 +27,7 @@ ControlAdaptor::ControlAdaptor(NetctlHelper *parent, const QMap<QString, QString
|
||||
{
|
||||
netctlCommand = new Netctl(false, configuration);
|
||||
netctlProfile = new NetctlProfile(false, configuration);
|
||||
wpaCommand = new WpaSup(false, configuration);
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +35,7 @@ ControlAdaptor::~ControlAdaptor()
|
||||
{
|
||||
delete netctlCommand;
|
||||
delete netctlProfile;
|
||||
delete wpaCommand;
|
||||
}
|
||||
|
||||
|
||||
@ -119,7 +121,40 @@ bool ControlAdaptor::SwitchTo(const QString profile)
|
||||
|
||||
|
||||
// netctlProfile
|
||||
bool ControlAdaptor::Create(const QString profile, const QStringList settingsList)
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
for (int i=0; i<settingsList.count(); i++) {
|
||||
QString key = settingsList[i].split(QString("=="))[0];
|
||||
QString value = settingsList[i].split(QString("=="))[1];
|
||||
settings[key] = value;
|
||||
}
|
||||
QString temporaryProfile = netctlProfile->createProfile(profile, settings);
|
||||
|
||||
return netctlProfile->copyProfile(temporaryProfile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Remove(const QString profile)
|
||||
{
|
||||
return netctlProfile->removeProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
// wpaCommand
|
||||
QStringList ControlAdaptor::WiFi()
|
||||
{
|
||||
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
|
||||
QStringList info;
|
||||
for (int i=0; i<wifiPoints.count(); i++) {
|
||||
QStringList point;
|
||||
point.append(wifiPoints[i].name);
|
||||
point.append(wifiPoints[i].security);
|
||||
point.append(wifiPoints[i].signal);
|
||||
point.append(QString::number(wifiPoints[i].active));
|
||||
point.append(QString::number(wifiPoints[i].exists));
|
||||
info.append(point.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
@ -52,12 +52,16 @@ public slots:
|
||||
bool Start(const QString profile);
|
||||
bool SwitchTo(const QString profile);
|
||||
// netctlProfile
|
||||
bool Create(const QString profile, const QStringList settingsList);
|
||||
bool Remove(const QString profile);
|
||||
// wpaCommand
|
||||
QStringList WiFi();
|
||||
|
||||
private:
|
||||
NetctlHelper *helper;
|
||||
Netctl *netctlCommand;
|
||||
NetctlProfile *netctlProfile;
|
||||
WpaSup *wpaCommand;
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,15 +41,12 @@ bool checkExistSession()
|
||||
QString("Active"));
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
return ((arguments.size() == 1) && arguments[0].toBool());
|
||||
return !arguments.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// setuid(getuid());
|
||||
// qDebug() << getuid();
|
||||
// qDebug() << geteuid();
|
||||
// detach from console
|
||||
bool isDaemon = true;
|
||||
for (int i=0; i<argc; i++)
|
||||
|
@ -122,7 +122,7 @@ QStringList NetctlAdaptor::Profile(const QString profile)
|
||||
QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile);
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(settings.keys()[i] + QString("=") +
|
||||
settingsList.append(settings.keys()[i] + QString("==") +
|
||||
settings[settings.keys()[i]]);
|
||||
|
||||
return settingsList;
|
||||
@ -142,19 +142,7 @@ QString NetctlAdaptor::ProfileByEssid(const QString essid)
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlAdaptor::WiFi()
|
||||
QStringList NetctlAdaptor::WirelessInterfaces()
|
||||
{
|
||||
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
|
||||
QStringList info;
|
||||
for (int i=0; i<wifiPoints.count(); i++) {
|
||||
QStringList point;
|
||||
point.append(wifiPoints[i].name);
|
||||
point.append(wifiPoints[i].security);
|
||||
point.append(wifiPoints[i].signal);
|
||||
point.append(QString::number(wifiPoints[i].active));
|
||||
point.append(QString::number(wifiPoints[i].exists));
|
||||
info.append(point.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
return netctlCommand->getWirelessInterfaceList();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public slots:
|
||||
QString ProfileValue(const QString profile, const QString key);
|
||||
// wpaCommand
|
||||
QString ProfileByEssid(const QString essid);
|
||||
QStringList WiFi();
|
||||
QStringList WirelessInterfaces();
|
||||
|
||||
private:
|
||||
Netctl *netctlCommand;
|
||||
|
@ -114,7 +114,7 @@ void NetctlHelper::quitHelper()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[quitHelper]";
|
||||
|
||||
QCoreApplication::quit();
|
||||
QCoreApplication::instance()->quit();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user