From ec8fc79dd786c34dec5f3ab17eb1bbce94f1de55 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 13 Aug 2014 07:45:00 +0400 Subject: [PATCH] rewrite library to use pdebug --- sources/gui/src/mainprivateslots.cpp | 4 +- sources/netctlgui/src/netctlinteract.cpp | 133 ++++++++++++----------- sources/netctlgui/src/netctlprofile.cpp | 59 +++++----- sources/netctlgui/src/pdebug.h | 1 + sources/netctlgui/src/wpasupinteract.cpp | 97 +++++++++-------- 5 files changed, 149 insertions(+), 145 deletions(-) create mode 120000 sources/netctlgui/src/pdebug.h diff --git a/sources/gui/src/mainprivateslots.cpp b/sources/gui/src/mainprivateslots.cpp index 80b06f3..0f1a537 100644 --- a/sources/gui/src/mainprivateslots.cpp +++ b/sources/gui/src/mainprivateslots.cpp @@ -963,10 +963,10 @@ void MainWindow::wifiTabContextualMenu(const QPoint &pos) // actions QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos)); if (action == refreshTable) { - if (debug) qDebug() << PDEBUG << "Refresh WiFi"; + if (debug) qDebug() << PDEBUG << ":" << "Refresh WiFi"; updateWifiTab(); } else if (action == startWifi) { - if (debug) qDebug() << PDEBUG << "Start WiFi"; + if (debug) qDebug() << PDEBUG << ":" << "Start WiFi"; wifiTabStart(); } } diff --git a/sources/netctlgui/src/netctlinteract.cpp b/sources/netctlgui/src/netctlinteract.cpp index bea09c4..4d500c3 100644 --- a/sources/netctlgui/src/netctlinteract.cpp +++ b/sources/netctlgui/src/netctlinteract.cpp @@ -26,6 +26,7 @@ #include #include "netctlgui.h" +#include "pdebug.h" #include "taskadds.h" @@ -70,7 +71,7 @@ Netctl::Netctl(const bool debugCmd, const QMap settings) */ Netctl::~Netctl() { - if (debug) qDebug() << "[Netctl]" << "[~Netctl]"; + if (debug) qDebug() << PDEBUG; if (netctlProfile != nullptr) delete netctlProfile; if (ifaceDirectory != nullptr) delete ifaceDirectory; @@ -83,12 +84,12 @@ Netctl::~Netctl() */ bool Netctl::cmdCall(const bool sudo, const QString command, const QString commandLine, const QString argument) { - if (debug) qDebug() << "[Netctl]" << "[cmdCall]"; - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Command" << command; - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Command line" << commandLine; - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Argument" << argument; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Command" << command; + if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine; + if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument; if (command == 0) { - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Could not find command"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find command"; return false; } @@ -98,11 +99,11 @@ bool Netctl::cmdCall(const bool sudo, const QString command, const QString comma cmd += command + QString(" ") + commandLine; if (argument != 0) cmd += QString(" \"") + argument + QString("\""); - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, (useSuid && sudo)); - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode == 0) return true; @@ -116,12 +117,12 @@ bool Netctl::cmdCall(const bool sudo, const QString command, const QString comma */ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QString commandLine, const QString argument) { - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]"; - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Command" << command; - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Command line" << commandLine; - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Argument" << argument; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Command" << command; + if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine; + if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument; if (command == 0) { - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Could not find command"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find command"; return QString(); } @@ -131,11 +132,11 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri cmd += command + QString(" ") + commandLine; if (argument != 0) cmd += QString(" \"") + argument + QString("\""); - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, (useSuid && sudo)); - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; return process.output; } @@ -147,7 +148,7 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri */ QString Netctl::getActiveProfile() { - if (debug) qDebug() << "[Netctl]" << "[getActiveProfile]"; + if (debug) qDebug() << PDEBUG; QString profile = QString(""); QList fullProfilesInfo = getProfileList(); @@ -166,7 +167,7 @@ QString Netctl::getActiveProfile() */ QString Netctl::autoGetActiveProfile() { - if (debug) qDebug() << "[Netctl]" << "[autoGetActiveProfile]"; + if (debug) qDebug() << PDEBUG; QString profile = QString(""); QList fullProfilesInfo = getProfileListFromNetctlAuto(); @@ -185,7 +186,7 @@ QString Netctl::autoGetActiveProfile() */ QList Netctl::getProfileList() { - if (debug) qDebug() << "[Netctl]" << "[getProfileList]"; + if (debug) qDebug() << PDEBUG; QList fullProfilesInfo; QStringList output = getCmdOutput(false, netctlCommand, QString("list")) @@ -211,7 +212,7 @@ QList Netctl::getProfileList() */ QList Netctl::getProfileListFromNetctlAuto() { - if (debug) qDebug() << "[Netctl]" << "[getProfileListFromNetctlAuto]"; + if (debug) qDebug() << PDEBUG; QList fullProfilesInfo; QStringList output = getCmdOutput(false, netctlAutoCommand, QString("list")) @@ -238,10 +239,10 @@ QList Netctl::getProfileListFromNetctlAuto() */ QString Netctl::getProfileDescription(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]"; - if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (netctlProfile == 0) { - if (debug) qDebug() << "[Netctl]" << "[getProfileDescription]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return QString(); } @@ -254,8 +255,8 @@ QString Netctl::getProfileDescription(const QString profile) */ QString Netctl::getProfileStatus(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[getProfileStatus]"; - if (debug) qDebug() << "[Netctl]" << "[getProfileStatus]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; QString status; if (isProfileActive(profile)) @@ -276,8 +277,8 @@ QString Netctl::getProfileStatus(const QString profile) */ bool Netctl::isProfileActive(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[isProfileActive]"; - if (debug) qDebug() << "[Netctl]" << "[isProfileActive]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; bool status = false; QString output = getCmdOutput(false, netctlCommand, QString("status"), profile); @@ -293,8 +294,8 @@ bool Netctl::isProfileActive(const QString profile) */ bool Netctl::isProfileEnabled(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[isProfileEnabled]"; - if (debug) qDebug() << "[Netctl]" << "[isProfileEnabled]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; return cmdCall(false, netctlCommand, QString("is-enabled"), profile); } @@ -305,8 +306,8 @@ bool Netctl::isProfileEnabled(const QString profile) */ bool Netctl::autoIsProfileActive(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[autoIsProfileActive]"; - if (debug) qDebug() << "[Netctl]" << "[autoIsProfileActive]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; bool status = false; QList profiles = getProfileListFromNetctlAuto(); @@ -325,8 +326,8 @@ bool Netctl::autoIsProfileActive(const QString profile) */ bool Netctl::autoIsProfileEnabled(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]"; - if (debug) qDebug() << "[Netctl]" << "[autoIsProfileEnabled]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; bool status = false; QList profiles = getProfileListFromNetctlAuto(); @@ -345,13 +346,13 @@ bool Netctl::autoIsProfileEnabled(const QString profile) */ bool Netctl::isNetctlAutoEnabled() { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]"; + if (debug) qDebug() << PDEBUG; if (netctlAutoService == 0) { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Could not find service"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find service"; return false; } if (getWirelessInterfaceList().isEmpty()) { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoEnabled]" << ":" << "Could not interface"; + if (debug) qDebug() << PDEBUG << ":" << "Could not interface"; return false; } @@ -367,14 +368,14 @@ bool Netctl::isNetctlAutoEnabled() */ bool Netctl::isNetctlAutoRunning() { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]"; + if (debug) qDebug() << PDEBUG; if (netctlAutoService == 0) { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not find service"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find service"; return false; } QStringList interfaces = getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not interface"; + if (debug) qDebug() << PDEBUG << ":" << "Could not interface"; return false; } @@ -390,9 +391,9 @@ bool Netctl::isNetctlAutoRunning() */ QStringList Netctl::getWirelessInterfaceList() { - if (debug) qDebug() << "[Netctl]" << "[getWirelessInterfaceList]"; + if (debug) qDebug() << PDEBUG; if (ifaceDirectory == 0) { - if (debug) qDebug() << "[Netctl]" << "[getWirelessInterfaceList]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return QStringList(); } @@ -401,7 +402,7 @@ QStringList Netctl::getWirelessInterfaceList() interfaces.append(mainInterface); QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); for (int i=0; ipath() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless"); if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless")).exists()) @@ -418,8 +419,8 @@ QStringList Netctl::getWirelessInterfaceList() */ bool Netctl::enableProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[enableProfile]"; - if (debug) qDebug() << "[Netctl]" << "[enableProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (isProfileEnabled(profile)) return cmdCall(true, netctlCommand, QString("disable"), profile); @@ -433,8 +434,8 @@ bool Netctl::enableProfile(const QString profile) */ bool Netctl::restartProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[restartProfile]"; - if (debug) qDebug() << "[Netctl]" << "[restartProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; return cmdCall(true, netctlCommand, QString("restart"), profile); } @@ -445,8 +446,8 @@ bool Netctl::restartProfile(const QString profile) */ bool Netctl::startProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[startProfile]"; - if (debug) qDebug() << "[Netctl]" << "[startProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (isProfileActive(profile)) return cmdCall(true, netctlCommand, QString("stop"), profile); @@ -460,8 +461,8 @@ bool Netctl::startProfile(const QString profile) */ bool Netctl::switchToProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[switchToProfile]"; - if (debug) qDebug() << "[Netctl]" << "[switchToProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (isProfileActive(profile)) return true; @@ -475,7 +476,7 @@ bool Netctl::switchToProfile(const QString profile) */ bool Netctl::autoDisableAllProfiles() { - if (debug) qDebug() << "[Netctl]" << "[autoDisableAllProfiles]"; + if (debug) qDebug() << PDEBUG; return cmdCall(false, netctlAutoCommand, QString("disable-all")); } @@ -486,8 +487,8 @@ bool Netctl::autoDisableAllProfiles() */ bool Netctl::autoEnableProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[autoEnableProfile]"; - if (debug) qDebug() << "[Netctl]" << "[autoEnableProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (autoIsProfileEnabled(profile)) return cmdCall(false, netctlAutoCommand, QString("disable"), profile); @@ -501,7 +502,7 @@ bool Netctl::autoEnableProfile(const QString profile) */ bool Netctl::autoEnableAllProfiles() { - if (debug) qDebug() << "[Netctl]" << "[autoEnableAllProfiles]"; + if (debug) qDebug() << PDEBUG; return cmdCall(false, netctlAutoCommand, QString("enable-all")); } @@ -512,8 +513,8 @@ bool Netctl::autoEnableAllProfiles() */ bool Netctl::autoStartProfile(const QString profile) { - if (debug) qDebug() << "[Netctl]" << "[autoStartProfile]"; - if (debug) qDebug() << "[Netctl]" << "[autoStartProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (autoIsProfileActive(profile)) return true; @@ -527,14 +528,14 @@ bool Netctl::autoStartProfile(const QString profile) */ bool Netctl::autoEnableService() { - if (debug) qDebug() << "[Netctl]" << "[autoEnableService]"; + if (debug) qDebug() << PDEBUG; if (netctlAutoService == 0) { - if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not find service"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find service"; return false; } QStringList interfaces = getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not interface"; + if (debug) qDebug() << PDEBUG << ":" << "Could not interface"; return false; } @@ -553,14 +554,14 @@ bool Netctl::autoEnableService() */ bool Netctl::autoRestartService() { - if (debug) qDebug() << "[Netctl]" << "[autoRestartService]"; + if (debug) qDebug() << PDEBUG; if (netctlAutoService == 0) { - if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not find service"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find service"; return false; } QStringList interfaces = getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not interface"; + if (debug) qDebug() << PDEBUG << ":" << "Could not interface"; return false; } @@ -579,14 +580,14 @@ bool Netctl::autoRestartService() */ bool Netctl::autoStartService() { - if (debug) qDebug() << "[Netctl]" << "[autoStartService]"; + if (debug) qDebug() << PDEBUG; if (netctlAutoService == 0) { - if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not find service"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find service"; return false; } QStringList interfaces = getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not interface"; + if (debug) qDebug() << PDEBUG << ":" << "Could not interface"; return false; } diff --git a/sources/netctlgui/src/netctlprofile.cpp b/sources/netctlgui/src/netctlprofile.cpp index 3e5f820..13504a1 100644 --- a/sources/netctlgui/src/netctlprofile.cpp +++ b/sources/netctlgui/src/netctlprofile.cpp @@ -29,6 +29,7 @@ #include #include "netctlgui.h" +#include "pdebug.h" #include "taskadds.h" @@ -61,7 +62,7 @@ NetctlProfile::NetctlProfile(const bool debugCmd, const QMap s */ NetctlProfile::~NetctlProfile() { - if (debug) qDebug() << "[NetctlProfile]" << "[~NetctlProfile]"; + if (debug) qDebug() << PDEBUG; if (profileDirectory != nullptr) delete profileDirectory; } @@ -72,20 +73,20 @@ NetctlProfile::~NetctlProfile() */ bool NetctlProfile::copyProfile(const QString oldPath) { - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]"; - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Path" << oldPath; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Path" << oldPath; if (profileDirectory == 0) { - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return false; } QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName(); QString cmd = sudoCommand + QString(" /usr/bin/mv \"") + oldPath + QString("\" \"") + newPath + QString("\""); - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, useSuid); - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode == 0) return true; @@ -99,12 +100,12 @@ bool NetctlProfile::copyProfile(const QString oldPath) */ QString NetctlProfile::createProfile(const QString profile, const QMap settings) { - if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]"; - if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; QString profileTempName = QDir::homePath() + QString("/.cache/") + QFileInfo(profile).fileName(); QFile profileFile(profileTempName); - if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Save to" << profileTempName; + if (debug) qDebug() << PDEBUG << ":" << "Save to" << profileTempName; if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text)) return profileTempName; QTextStream out(&profileFile); @@ -136,21 +137,21 @@ QString NetctlProfile::createProfile(const QString profile, const QMap NetctlProfile::getSettingsFromProfile(const QString profile) { - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]"; - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (profileDirectory == 0) { - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return QMap(); } // getting variables list // system variables QString cmd = QString("env -i bash -c \"set\""); - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, false); - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; QStringList output = QString(process.output).trimmed().split(QChar('\n')); QStringList systemVariables; systemVariables.append(QString("PIPESTATUS")); @@ -160,11 +161,11 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi QMap settings; QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName(); cmd = QString("env -i bash -c \"source '") + profileUrl + QString("'; set\""); - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; process = runTask(cmd, false); - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; output = QString(process.output).trimmed().split(QChar('\n')); // gettings variables @@ -178,7 +179,7 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi keys[i] + QString("[$i]}; done\""); process = runTask(cmd, false); settings[keys[i]] = process.output.trimmed(); - if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << keys[i] << "=" << settings[keys[i]]; + if (debug) qDebug() << PDEBUG << ":" << keys[i] << "=" << settings[keys[i]]; } return settings; @@ -190,9 +191,9 @@ QMap NetctlProfile::getSettingsFromProfile(const QString profi */ QString NetctlProfile::getValueFromProfile(const QString profile, const QString key) { - if (debug) qDebug() << "[NetctlProfile]" << "[getValueFromProfile]"; - if (debug) qDebug() << "[NetctlProfile]" << "[getValueFromProfile]" << ":" << "Profile" << profile; - if (debug) qDebug() << "[NetctlProfile]" << "[getValueFromProfile]" << ":" << "Key" << key; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG << ":" << "Key" << key; QMap settings = getSettingsFromProfile(profile); @@ -208,20 +209,20 @@ QString NetctlProfile::getValueFromProfile(const QString profile, const QString */ bool NetctlProfile::removeProfile(const QString profile) { - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]"; - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Profile" << profile; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (profileDirectory == 0) { - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return false; } QString profilePath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName(); QString cmd = sudoCommand + QString(" /usr/bin/rm \"") + profilePath + QString("\""); - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, useSuid); - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode == 0) return true; diff --git a/sources/netctlgui/src/pdebug.h b/sources/netctlgui/src/pdebug.h new file mode 120000 index 0000000..2c26e28 --- /dev/null +++ b/sources/netctlgui/src/pdebug.h @@ -0,0 +1 @@ +../../3rdparty/pdebug/pdebug.h \ No newline at end of file diff --git a/sources/netctlgui/src/wpasupinteract.cpp b/sources/netctlgui/src/wpasupinteract.cpp index 63171db..da1391c 100644 --- a/sources/netctlgui/src/wpasupinteract.cpp +++ b/sources/netctlgui/src/wpasupinteract.cpp @@ -26,6 +26,7 @@ #include #include "netctlgui.h" +#include "pdebug.h" #include "taskadds.h" @@ -69,7 +70,7 @@ WpaSup::WpaSup(const bool debugCmd, const QMap settings) */ WpaSup::~WpaSup() { - if (debug) qDebug() << "[WpaSup]" << "[~WpaSup]"; + if (debug) qDebug() << PDEBUG; if (netctlCommand != nullptr) delete netctlCommand; if (netctlProfile != nullptr) delete netctlProfile; @@ -82,14 +83,14 @@ WpaSup::~WpaSup() */ QString WpaSup::existentProfile(const QString essid) { - if (debug) qDebug() << "[WpaSup]" << "[existentProfile]"; - if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "ESSID" << essid; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return QString(); } if (netctlProfile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[existentProfile]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return QString(); } @@ -108,14 +109,14 @@ QString WpaSup::existentProfile(const QString essid) */ bool WpaSup::isProfileActive(const QString essid) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]"; - if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "ESSID" << essid; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } if (netctlProfile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileActive]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } @@ -136,14 +137,14 @@ bool WpaSup::isProfileActive(const QString essid) */ bool WpaSup::isProfileExists(const QString essid) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]"; - if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "ESSID" << essid; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } if (netctlProfile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[isProfileExists]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } @@ -164,7 +165,7 @@ bool WpaSup::isProfileExists(const QString essid) */ QList WpaSup::scanWifi() { - if (debug) qDebug() << "[WpaSup]" << "[scanWifi]"; + if (debug) qDebug() << PDEBUG; QList scanResults; if (!startWpaSupplicant()) { @@ -228,34 +229,34 @@ QList WpaSup::scanWifi() */ bool WpaSup::startWpaSupplicant() { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]"; + if (debug) qDebug() << PDEBUG; if (ctrlDir == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return false; } if (ctrlGroup == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find group"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find group"; return false; } if (pidFile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find PID file"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file"; return false; } if (wpaDrivers == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find drivers"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find drivers"; return false; } if (wpaSupPath == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find wpa_supplicant"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_supplicant"; return false; } if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } QStringList interfaces = netctlCommand->getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find interfaces"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find interfaces"; return false; } @@ -265,12 +266,12 @@ bool WpaSup::startWpaSupplicant() QString cmd = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile + QString(" -i ") + interface + QString(" -D ") + wpaDrivers + QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\""); - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd, useSuid); waitForProcess(1); - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode == 0) return true; @@ -284,7 +285,7 @@ bool WpaSup::startWpaSupplicant() */ bool WpaSup::stopWpaSupplicant() { - if (debug) qDebug() << "[WpaSup]" << "[stopWpaSupplicant]"; + if (debug) qDebug() << PDEBUG; return wpaCliCall(QString("terminate")); } @@ -296,38 +297,38 @@ bool WpaSup::stopWpaSupplicant() */ QString WpaSup::getWpaCliOutput(const QString commandLine) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]"; - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Command" << commandLine; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine; if (ctrlDir == 0) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return QString(); } if (pidFile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find PID file"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file"; return QString(); } if (wpaCliPath == 0) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find wpa_cli"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli"; return QString(); } if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return QString(); } QStringList interfaces = netctlCommand->getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find interfaces"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find interfaces"; return QString(); } QString interface = interfaces[0]; QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + QString(" -P ") + pidFile + QString(" ") + commandLine; - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd); - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; return process.output; } @@ -338,8 +339,8 @@ QString WpaSup::getWpaCliOutput(const QString commandLine) */ bool WpaSup::waitForProcess(const int sec) { - if (debug) qDebug() << "[WpaSup]" << "[waitForProcess]"; - if (debug) qDebug() << "[WpaSup]" << "[waitForProcess]" << ":" << "Interval" << sec; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Interval" << sec; QString cmd = QString("sleep %1").arg(QString::number(sec)); runTask(cmd); @@ -353,39 +354,39 @@ bool WpaSup::waitForProcess(const int sec) */ bool WpaSup::wpaCliCall(const QString commandLine) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]"; - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Command" << commandLine; + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine; if (ctrlDir == 0) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find directory"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find directory"; return false; } if (pidFile == 0) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find PID file"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file"; return false; } if (wpaCliPath == 0) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find wpa_cli"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli"; return false; } if (netctlCommand == 0) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find library"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find library"; return false; } QStringList interfaces = netctlCommand->getWirelessInterfaceList(); if (interfaces.isEmpty()) { - if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find interfaces"; + if (debug) qDebug() << PDEBUG << ":" << "Could not find interfaces"; return false; } QString interface = interfaces[0]; QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir + QString(" -P ") + pidFile + QString(" ") + commandLine; - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd; + if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; TaskResult process = runTask(cmd); waitForProcess(1); - if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode; + if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (process.exitCode != 0) - if (debug) qDebug() << "[NetctlProfile]" << "[getWpaCliOutput]" << ":" << "Error" << process.error; + if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode == 0) return true;