diff --git a/sources/netctlgui/include/netctlgui/netctlinteract.h b/sources/netctlgui/include/netctlgui/netctlinteract.h index 369b42a..fbc6844 100644 --- a/sources/netctlgui/include/netctlgui/netctlinteract.h +++ b/sources/netctlgui/include/netctlgui/netctlinteract.h @@ -31,7 +31,7 @@ #include -class WpaSup; +class NetctlProfile; /** * @brief The Netctl class interacts with netctl @@ -85,13 +85,13 @@ public: /** * @brief method which gets description from profile * @param profile profile name - * @return profile description or "" + * @return profile description or "" */ QString getProfileDescription(const QString profile); /** * @brief method which gets descriptions from profile list * @param profileList profile names - * @return list of profile descriptions (if description is not available return "") + * @return list of profile descriptions (if description is not available returns "") */ QStringList getProfileDescriptions(const QStringList profileList); /** @@ -221,6 +221,10 @@ public slots: bool autoStartService(); private: + /** + * @brief NetctlProfile class + */ + NetctlProfile *netctlProfile; /** * @brief show debug messages */ diff --git a/sources/netctlgui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp index fdf58b2..9890d07 100644 --- a/sources/netctlgui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -39,6 +39,8 @@ Netctl::Netctl(const bool debugCmd, const QMap settings) : debug(debugCmd) { + netctlProfile = new NetctlProfile(debug, settings); + if (settings.contains(QString("IFACE_DIR"))) ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]); else @@ -81,6 +83,8 @@ Netctl::~Netctl() { if (debug) qDebug() << "[Netctl]" << "[~Netctl]"; + if (netctlProfile != 0) + delete netctlProfile; if (ifaceDirectory != 0) delete ifaceDirectory; if (profileDirectory != 0) @@ -333,32 +337,12 @@ QString Netctl::getProfileDescription(const QString profile) { if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]"; if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Profile" << profile; - if (profileDirectory == 0) { - if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Could not find directory"; + if (netctlProfile == 0) { + if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Could not find library"; return QString(); } - QString description = QString(""); - QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profile; - if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Check" << profileUrl; - QFile profileFile(profileUrl); - QString fileStr; - if (!profileFile.open(QIODevice::ReadOnly)) - return description; - while (true) { - fileStr = QString(profileFile.readLine()); - if (fileStr.isEmpty()) continue; - if (fileStr[0] == QChar('#')) continue; - if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2) - if (fileStr.split(QChar('='), QString::SkipEmptyParts)[0] == QString("Description")) - description = fileStr.split(QChar('='), QString::SkipEmptyParts)[1].trimmed(); - if (profileFile.atEnd()) - break; - } - profileFile.close(); - description.remove(QChar('\'')).remove(QChar('"')); - - return description; + return netctlProfile->getValueFromProfile(profile, QString("Description")); } @@ -369,35 +353,14 @@ QStringList Netctl::getProfileDescriptions(const QStringList profileList) { if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]"; if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Profile list" << profileList; - if (profileDirectory == 0) { - if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Could not find directory"; + if (netctlProfile == 0) { + if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Could not find library"; return QStringList(); } QStringList descriptions; - for (int i=0; i"); - QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + profileList[i]; - if (debug) qDebug() << "[Netctl]" << "[getProfileDescriptions]" << ":" << "Check" << profileUrl; - QFile profileFile(profileUrl); - QString fileStr; - if (!profileFile.open(QIODevice::ReadOnly)) { - descriptions.append(description); - continue; - } - while (true) { - fileStr = QString(profileFile.readLine()); - if (fileStr[0] == QChar('#')) continue; - if (fileStr.split(QChar('='), QString::SkipEmptyParts).count() == 2) - if (fileStr.split(QChar('='), QString::SkipEmptyParts)[0] == QString("Description")) - description = fileStr.split(QChar('='), QString::SkipEmptyParts)[1].trimmed(); - if (profileFile.atEnd()) - break; - } - profileFile.close(); - description.remove(QChar('\'')).remove(QChar('"')); - descriptions.append(description); - } + for (int i=0; igetValueFromProfile(profileList[i], QString("Description"))); return descriptions; } diff --git a/sources/netctlgui/src/wpasupinteract.cpp b/sources/netctlgui/src/wpasupinteract.cpp index 9c8476c..457dd04 100644 --- a/sources/netctlgui/src/wpasupinteract.cpp +++ b/sources/netctlgui/src/wpasupinteract.cpp @@ -98,6 +98,14 @@ QString WpaSup::existentProfile(const QString essid) { if (debug) qDebug() << "[WpaSup]" << "[existentProfile]"; if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "ESSID" << essid; + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "Could not find library"; + return QString(); + } + if (netctlProfile == 0) { + if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "Could not find library"; + return QString(); + } QString profileFile = QString(""); QList profileList = netctlCommand->getProfileList(); @@ -116,6 +124,14 @@ bool WpaSup::isProfileActive(const QString essid) { if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]"; if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "ESSID" << essid; + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "Could not find library"; + return false; + } + if (netctlProfile == 0) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "Could not find library"; + return false; + } QString profileFile; QList profileList = netctlCommand->getProfileList(); @@ -136,6 +152,14 @@ bool WpaSup::isProfileExists(const QString essid) { if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]"; if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "ESSID" << essid; + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "Could not find library"; + return false; + } + if (netctlProfile == 0) { + if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "Could not find library"; + return false; + } bool exists = false; QList profileList = netctlCommand->getProfileList(); @@ -252,6 +276,10 @@ bool WpaSup::startWpaSupplicant() if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find wpa_supplicant"; return false; } + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find library"; + return false; + } if (netctlCommand->getInterfaceList().isEmpty()) { if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find interfaces"; return false; @@ -308,6 +336,10 @@ QString WpaSup::getWpaCliOutput(const QString commandLine) if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find wpa_cli"; return QString(); } + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find library"; + return QString(); + } if (netctlCommand->getInterfaceList().isEmpty()) { if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find interfaces"; return QString(); @@ -344,6 +376,10 @@ bool WpaSup::wpaCliCall(const QString commandLine) if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find wpa_cli"; return false; } + if (netctlCommand == 0) { + if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find library"; + return false; + } if (netctlCommand->getInterfaceList().isEmpty()) { if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find interfaces"; return false;