mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
add FindSettings key
This commit is contained in:
parent
b63d883eb2
commit
d3e1c4bca0
@ -71,6 +71,11 @@ th.sub {
|
|||||||
<td><code>true</code> and closes the helper</td>
|
<td><code>true</code> and closes the helper</td>
|
||||||
<td>no</td>
|
<td>no</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>QStringList FindSettings()</td>
|
||||||
|
<td>scans system and suggests the recommended configuration which will be used by the library</td>
|
||||||
|
<td>no</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>QString LibraryDocs()</td>
|
<td>QString LibraryDocs()</td>
|
||||||
<td>returns path to the library documentation</td>
|
<td>returns path to the library documentation</td>
|
||||||
|
@ -64,6 +64,31 @@ bool ControlAdaptor::Close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList ControlAdaptor::FindSettings()
|
||||||
|
{
|
||||||
|
QMap<QString, QString> configuration;
|
||||||
|
// apply settings from Netctl class
|
||||||
|
QMap<QString, QString> librarySettings = netctlCommand->getRecommendedConfiguration();
|
||||||
|
for (int i=0; i<librarySettings.keys().count(); i++)
|
||||||
|
configuration[librarySettings.keys()[i]] = librarySettings[librarySettings.keys()[i]];
|
||||||
|
// apply settings from NetctlProfile class
|
||||||
|
librarySettings = netctlProfile->getRecommendedConfiguration();
|
||||||
|
for (int i=0; i<librarySettings.keys().count(); i++)
|
||||||
|
configuration[librarySettings.keys()[i]] = librarySettings[librarySettings.keys()[i]];
|
||||||
|
// apply settings from WpaSup class
|
||||||
|
librarySettings = wpaCommand->getRecommendedConfiguration();
|
||||||
|
for (int i=0; i<librarySettings.keys().count(); i++)
|
||||||
|
configuration[librarySettings.keys()[i]] = librarySettings[librarySettings.keys()[i]];
|
||||||
|
|
||||||
|
QStringList settingsList;
|
||||||
|
for (int i=0; i<configuration.keys().count(); i++)
|
||||||
|
settingsList.append(configuration.keys()[i] + QString("==") +
|
||||||
|
configuration[configuration.keys()[i]]);
|
||||||
|
|
||||||
|
return settingsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ControlAdaptor::LibraryDocs()
|
QString ControlAdaptor::LibraryDocs()
|
||||||
{
|
{
|
||||||
return (QString(DOCS_PATH) + QString("html/index.html"));
|
return (QString(DOCS_PATH) + QString("html/index.html"));
|
||||||
|
@ -41,6 +41,7 @@ public slots:
|
|||||||
bool Active();
|
bool Active();
|
||||||
QString ApiDocs();
|
QString ApiDocs();
|
||||||
bool Close();
|
bool Close();
|
||||||
|
QStringList FindSettings();
|
||||||
QString LibraryDocs();
|
QString LibraryDocs();
|
||||||
QString Pony();
|
QString Pony();
|
||||||
QString SecurityDocs();
|
QString SecurityDocs();
|
||||||
|
@ -155,6 +155,11 @@ public:
|
|||||||
* @return true if netctl-auto is active
|
* @return true if netctl-auto is active
|
||||||
*/
|
*/
|
||||||
bool isNetctlAutoRunning();
|
bool isNetctlAutoRunning();
|
||||||
|
/**
|
||||||
|
* @brief method which check system configuration and return recommended values to keys
|
||||||
|
* @return recommended parametrs
|
||||||
|
*/
|
||||||
|
static QMap<QString, QString> getRecommendedConfiguration();
|
||||||
/**
|
/**
|
||||||
* @brief method which gets wireless interface list from PREFERED_IFACE and IFACE_DIR
|
* @brief method which gets wireless interface list from PREFERED_IFACE and IFACE_DIR
|
||||||
* @return interface list. If PREFERED_IFACE is not empty it will be first element
|
* @return interface list. If PREFERED_IFACE is not empty it will be first element
|
||||||
|
@ -67,6 +67,11 @@ public:
|
|||||||
* @return temporary profile name
|
* @return temporary profile name
|
||||||
*/
|
*/
|
||||||
QString createProfile(const QString profile, const QMap<QString, QString> settings);
|
QString createProfile(const QString profile, const QMap<QString, QString> settings);
|
||||||
|
/**
|
||||||
|
* @brief method which check system configuration and return recommended values to keys
|
||||||
|
* @return recommended parametrs
|
||||||
|
*/
|
||||||
|
static QMap<QString, QString> getRecommendedConfiguration();
|
||||||
/**
|
/**
|
||||||
* @brief method which reads settings from profile
|
* @brief method which reads settings from profile
|
||||||
* @param profile profile name
|
* @param profile profile name
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDirIterator>
|
||||||
|
|
||||||
#include "netctlgui.h"
|
#include "netctlgui.h"
|
||||||
#include "pdebug.h"
|
#include "pdebug.h"
|
||||||
@ -386,6 +387,120 @@ bool Netctl::isNetctlAutoRunning()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn getRecommendedConfiguration
|
||||||
|
*/
|
||||||
|
QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
||||||
|
{
|
||||||
|
QMap<QString, QString> settings;
|
||||||
|
QString cmd;
|
||||||
|
TaskResult process;
|
||||||
|
QStringList recommended;
|
||||||
|
// force sudo
|
||||||
|
// find out helper exe
|
||||||
|
settings[QString("FORCE_SUDO")] = QString("true");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append(QString("netctlgui-helper"));
|
||||||
|
recommended.append(QString("netctlgui-helper-suid"));
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("FORCE_SUDO")] = QString("false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// interfaces
|
||||||
|
// find out dircetory which contains wireless subdirectory
|
||||||
|
// I don't think that this parametr may change =)
|
||||||
|
settings[QString("IFACE_DIR")] = QString("/sys/class/net");
|
||||||
|
settings[QString("PREFERED_IFACE")] = QString("");
|
||||||
|
QDirIterator sysIterator(QDir("/sys"), QDirIterator::Subdirectories);
|
||||||
|
while (sysIterator.hasNext()) {
|
||||||
|
sysIterator.next();
|
||||||
|
if (!sysIterator.fileInfo().isDir()) continue;
|
||||||
|
QString name = sysIterator.filePath();
|
||||||
|
if (name.contains(QString("wireless"))) {
|
||||||
|
QString interfaceDir = QFileInfo(name).path();
|
||||||
|
settings[QString("PREFERED_IFACE")] = QFileInfo(interfaceDir).fileName();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// netctl path
|
||||||
|
// find out netctl exe
|
||||||
|
settings[QString("NETCTL_PATH")] = QString("");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append("netctl");
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("NETCTL_PATH")] = process.output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// netctl-auto path
|
||||||
|
// find out netctl-auto exe
|
||||||
|
settings[QString("NETCTLAUTO_PATH")] = QString("");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append("netctl-auto");
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("NETCTLAUTO_PATH")] = process.output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// netctl-auto service
|
||||||
|
// usually it has the same name as netctl-auto
|
||||||
|
settings[QString("NETCTLAUTO_SERVICE")] = QFileInfo(settings[QString("NETCTLAUTO_PATH")]).fileName();
|
||||||
|
// profile path
|
||||||
|
// find out netctl directory into /etc
|
||||||
|
settings[QString("PROFILE_DIR")] = QString("");
|
||||||
|
QDirIterator iterator(QDir("/etc"), QDirIterator::Subdirectories);
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
iterator.next();
|
||||||
|
if (!iterator.fileInfo().isDir()) continue;
|
||||||
|
QString name = iterator.filePath();
|
||||||
|
if (name.contains(QString("netctl"))) {
|
||||||
|
settings[QString("PROFILE_DIR")] = name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sudo path
|
||||||
|
// find out sudo, kdesu, gksu exes
|
||||||
|
settings[QString("SUDO_PATH")] = QString("");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append("sudo");
|
||||||
|
recommended.append("kdesu");
|
||||||
|
recommended.append("gksu");
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// systemctl path
|
||||||
|
// find out systemctl exe
|
||||||
|
settings[QString("SYSTEMCTL_PATH")] = QString("");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append("systemctl");
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("SYSTEMCTL_PATH")] = process.output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getWirelessInterfaceList
|
* @fn getWirelessInterfaceList
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
@ -132,6 +133,62 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn getRecommendedConfiguration
|
||||||
|
*/
|
||||||
|
QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
|
||||||
|
{
|
||||||
|
QMap<QString, QString> settings;
|
||||||
|
QString cmd;
|
||||||
|
TaskResult process;
|
||||||
|
QStringList recommended;
|
||||||
|
// force sudo
|
||||||
|
// find out helper exe
|
||||||
|
settings[QString("FORCE_SUDO")] = QString("true");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append(QString("netctlgui-helper"));
|
||||||
|
recommended.append(QString("netctlgui-helper-suid"));
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("FORCE_SUDO")] = QString("false");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// profile path
|
||||||
|
// find out netctl directory into /etc
|
||||||
|
settings[QString("PROFILE_DIR")] = QString("");
|
||||||
|
QDirIterator iterator(QDir("/etc"), QDirIterator::Subdirectories);
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
iterator.next();
|
||||||
|
if (!iterator.fileInfo().isDir()) continue;
|
||||||
|
QString name = iterator.filePath();
|
||||||
|
if (name.contains(QString("netctl"))) {
|
||||||
|
settings[QString("PROFILE_DIR")] = name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sudo path
|
||||||
|
// find out sudo, kdesu, gksu exes
|
||||||
|
settings[QString("SUDO_PATH")] = QString("");
|
||||||
|
recommended.clear();
|
||||||
|
recommended.append("sudo");
|
||||||
|
recommended.append("kdesu");
|
||||||
|
recommended.append("gksu");
|
||||||
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
|
cmd = QString("which ") + recommended[i];
|
||||||
|
process = runTask(cmd, false);
|
||||||
|
if (process.exitCode == 0) {
|
||||||
|
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getSettingsFromProfile
|
* @fn getSettingsFromProfile
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user