diff --git a/include/Diagnostic.hpp b/include/Diagnostic.hpp index 85722a1122f138fa1e5274448b430c106abda7ea..7c6e1aeec4a8f3f82972bc95ff5fc9277605eebd 100644 --- a/include/Diagnostic.hpp +++ b/include/Diagnostic.hpp @@ -6,26 +6,26 @@ #define DIAGNOSTIC_HPP class Diagnostic : public QObject { - Q_OBJECT + Q_OBJECT private: - typedef QString (Diagnostic::*function_t)(); - QVector<function_t> func_vec; - QString separator; - QString tab; + typedef QString (Diagnostic::*function_t)(); + QVector<function_t> func_vec; + QString separator; + QString tab; public slots: - void onStarted(); + void onStarted(); signals: - void Ready(); - void Update(int, const QString); - void Quit(); + void Ready(); + void Update(int, const QString); + void Quit(); public: - Diagnostic(); - QString getRoutingInfo(); - QString getInterfaceInfo(); - QString getDGPingOutput(); - QString getODPingOutput(); - QString getOsInfo(); - QString getDNSLookup(); + Diagnostic(); + QString getRoutingInfo(); + QString getInterfaceInfo(); + QString getDGPingOutput(); + QString getODPingOutput(); + QString getOsInfo(); + QString getDNSLookup(); }; #endif diff --git a/include/Globals.hpp b/include/Globals.hpp index 966fec80322e5921915d1c379eeaea24e0c37e8e..cb2c4cc443fbd46f221d61c0210b88138b27d49e 100644 --- a/include/Globals.hpp +++ b/include/Globals.hpp @@ -10,13 +10,13 @@ enum OS_TYPE {OS_WINDOWS, OS_LINUX, OS_OSX, OS_UNKNOWN}; #if defined(Q_OS_WIN) - constexpr enum OS_TYPE CURRENT_OS = OS_WINDOWS; + constexpr enum OS_TYPE CURRENT_OS = OS_WINDOWS; #elif defined(Q_OS_LINUX) - constexpr enum OS_TYPE CURRENT_OS = OS_LINUX; + constexpr enum OS_TYPE CURRENT_OS = OS_LINUX; #elif defined(Q_OS_OSX) - constexpr enum OS_TYPE CURRENT_OS = OS_OSX; + constexpr enum OS_TYPE CURRENT_OS = OS_OSX; #else - constexpr enum OS_TYPE CURRENT_OS = OS_UNKNOWN; + constexpr enum OS_TYPE CURRENT_OS = OS_UNKNOWN; #endif // diff --git a/include/NetCheckerWindow.hpp b/include/NetCheckerWindow.hpp index 36b2373e286c7194c1aa36841b72f25405941629..6f07fd858a6acf90ff1c536b0847ca428588c0ba 100644 --- a/include/NetCheckerWindow.hpp +++ b/include/NetCheckerWindow.hpp @@ -21,56 +21,56 @@ QT_END_NAMESPACE class NetCheckerWindow : public QDialog { - Q_OBJECT + Q_OBJECT private: - /* widget structure --> */ - QStackedWidget *global_w; QVBoxLayout *global_l; - QWidget *welcome_page_w; QHBoxLayout *welcome_page_l; - QWidget *logo_side_w; QVBoxLayout *logo_side_l; - QLabel *logo_image_w; - QWidget *readme_side_w; QVBoxLayout *readme_side_l; - QTextEdit *text_w; - QPushButton *next_button_w; - QWidget *diagnostic_page_w; QVBoxLayout *diagnostic_page_l; - QGroupBox *progressbar_holder_w; QVBoxLayout *progressbar_holder_l; - QProgressBar *progressbar_w; - QLabel *progress_info; - QLabel *progress_info_time; - QGroupBox *log_holder_w; QVBoxLayout *log_holder_l; - QTextEdit *log_w; - QWidget *button_holder_w; QHBoxLayout *button_holder_l; - QPushButton* clipboard_button_w; - QPushButton* save_button_w; - /* <-- widget structure */ - QTimer *progress_timer; - int lang; - Diagnostic *diag_obj; + /* widget structure --> */ + QStackedWidget *global_w; QVBoxLayout *global_l; + QWidget *welcome_page_w; QHBoxLayout *welcome_page_l; + QWidget *logo_side_w; QVBoxLayout *logo_side_l; + QLabel *logo_image_w; + QWidget *readme_side_w; QVBoxLayout *readme_side_l; + QTextEdit *text_w; + QPushButton *next_button_w; + QWidget *diagnostic_page_w; QVBoxLayout *diagnostic_page_l; + QGroupBox *progressbar_holder_w; QVBoxLayout *progressbar_holder_l; + QProgressBar *progressbar_w; + QLabel *progress_info; + QLabel *progress_info_time; + QGroupBox *log_holder_w; QVBoxLayout *log_holder_l; + QTextEdit *log_w; + QWidget *button_holder_w; QHBoxLayout *button_holder_l; + QPushButton* clipboard_button_w; + QPushButton* save_button_w; + /* <-- widget structure */ + QTimer *progress_timer; + int lang; + Diagnostic *diag_obj; QThread *diag_thread; public: NetCheckerWindow(); public slots: void show(); - void nextPage(); - void copyClipboard(); - void saveToFile(); - void changeToHun(); - void changeToEng(); - void incrementTime(); - void finishAction(); - void updateInfos(int, const QString); + void nextPage(); + void copyClipboard(); + void saveToFile(); + void changeToHun(); + void changeToEng(); + void incrementTime(); + void finishAction(); + void updateInfos(int, const QString); private: - void initStackedWindow(); - void initWelcomePage(); - void initLogoSide(); - void initReadmeSide(); - void initDiagnosticPage(); - void initText(); - enum { - WINDOW_WIDTH = 380, - WINDOW_HEIGHT = 420, - LOGO_WIDTH = 120, - README_WIDTH = (WINDOW_WIDTH-LOGO_WIDTH) - }; + void initStackedWindow(); + void initWelcomePage(); + void initLogoSide(); + void initReadmeSide(); + void initDiagnosticPage(); + void initText(); + enum { + WINDOW_WIDTH = 650, + WINDOW_HEIGHT = 420, + LOGO_WIDTH = 120, + README_WIDTH = (WINDOW_WIDTH-LOGO_WIDTH) + }; }; #endif diff --git a/include/Privileges.hpp b/include/Privileges.hpp index d45d06fb153199d41c1962e33775b34b4c981eef..18a7f82caabbddf392e3a7c4a0321c0e0d420085 100644 --- a/include/Privileges.hpp +++ b/include/Privileges.hpp @@ -7,9 +7,9 @@ class Privileges { public: - static void checkPrivileges(QWidget*, const QString, const QString); + static void checkPrivileges(QWidget*, const QString, const QString); - static bool isRoot(); + static bool isRoot(); }; #endif // PRIVILEGES_HPP diff --git a/include/ProcessHandler.hpp b/include/ProcessHandler.hpp index 4fc5fc4def72c9b766c6a67fe113ec2b3e6c41c4..dec13b652a2941453ebd1f41d0d4f81bb1371a5a 100644 --- a/include/ProcessHandler.hpp +++ b/include/ProcessHandler.hpp @@ -6,11 +6,11 @@ #define PROCESSHANDLER_HPP class ProcessHandler : protected QProcess { - Q_OBJECT + Q_OBJECT public: - ProcessHandler(QProcess::OpenMode mode); + ProcessHandler(QProcess::OpenMode mode); public: - QString exec(QString commands); + QString exec(QString commands); }; #endif diff --git a/include/Translation.hpp b/include/Translation.hpp index 8ac06c7dbe3bfd7d109b9094a1998d9587fe97e3..13d9753c95e4e44c45bbfcb73c5fb3db68f44bae 100644 --- a/include/Translation.hpp +++ b/include/Translation.hpp @@ -4,19 +4,19 @@ #include <QString> struct LANG { - enum {ENG = 0, HUN = 1}; + enum {ENG = 0, HUN = 1}; }; -QString TXT_APP_TITLE[] = { "SCH NetChecker", "SCH NetChecker" }; -QString README_URL[] = { ":/res/readme_en.html", ":/res/readme_hu.html" }; -QString TXT_NEXT_BTN[] = { "Next", "Tovább" }; -QString TXT_DIAG_GROUP[] = { "Running diagnostics", "Diagnosztika futtatása" }; +QString TXT_APP_TITLE[] = { "SCH NetChecker", "SCH NetChecker" }; +QString README_URL[] = { ":/res/readme_en.html", ":/res/readme_hu.html" }; +QString TXT_NEXT_BTN[] = { "Next", "Tovább" }; +QString TXT_DIAG_GROUP[] = { "Running diagnostics", "Diagnosztika futtatása" }; QString TXT_EST_TIME[] = { "Estimated time", "Várható befejezés" }; QString TXT_ALMOST_END[] = { "Please be patient...", "Kérem várjon türelemmel..." }; QString TXT_FINISHED[] = { "Finished.", "Művelet befejeződött." }; -QString TXT_LOG_GROUP[] = { "Log", "Napló" }; -QString TXT_CLIPB_BTN[] = { "Copy to clipboard", "Másolás vágólapra" }; -QString TXT_SAVE_BTN[] = { "Save to file...", "Mentés fájlba..." }; -QString TXT_SAVE_DIALOG[] = { "Save to...", "Mentés helye..." }; +QString TXT_LOG_GROUP[] = { "Log", "Napló" }; +QString TXT_CLIPB_BTN[] = { "Copy to clipboard", "Másolás vágólapra" }; +QString TXT_SAVE_BTN[] = { "Save to file...", "Mentés fájlba..." }; +QString TXT_SAVE_DIALOG[] = { "Save to...", "Mentés helye..." }; QString TXT_ROOT_MSG_TITLE_WIN[] ={ "Error", "Error" diff --git a/main.cpp b/main.cpp index c70ecec99ee78bfe586ad1ef6096242ecdc53987..a96f836e10befec311655bc92fa088616ead4ee5 100644 --- a/main.cpp +++ b/main.cpp @@ -4,8 +4,8 @@ int main(int argc, char *argv[]) { - QApplication app(argc, argv); + QApplication app(argc, argv); NetCheckerWindow ncw; ncw.show(); - return app.exec(); + return app.exec(); } diff --git a/netchecker.pro b/netchecker.pro index b7b625935c17ac8c599fbba0907f2a90f66703d7..a1d0069d2c67fda605ee0add074706f9e36a6805 100644 --- a/netchecker.pro +++ b/netchecker.pro @@ -6,7 +6,7 @@ macx:ICON = res/app.hqx HEADERS = \ include/NetCheckerWindow.hpp \ include/Diagnostic.hpp \ - include/Globals.hpp \ + include/Globals.hpp \ include/Translation.hpp \ include/ProcessHandler.hpp \ include/Privileges.hpp @@ -16,7 +16,7 @@ SOURCES = \ src/Globals.cpp \ src/NetCheckerWindow.cpp \ src/Privileges.cpp \ - src/ProcessHandler.cpp + src/ProcessHandler.cpp # install target.path = bin diff --git a/res/readme_en.html b/res/readme_en.html index eeb684753e965b5613a8ee1857ba8972a528d7e9..6b3c23e26cb0dba9395177c4986438cf8a6feffa 100644 --- a/res/readme_en.html +++ b/res/readme_en.html @@ -1,5 +1,5 @@ <h3 align="center">Very English</h3> <p> - Big localization. <u>Bilingual as hell.</u><br/> - <b>Easy to youze.</b> + Big localization. <u>Bilingual as hell.</u><br/> + <b>Easy to youze.</b> </p> diff --git a/res/readme_hu.html b/res/readme_hu.html index f88d2524ea863eb0e2d80c2413d61bc3b42f4cb6..a12ae3e8c468361f81cb8457f157f2ce096daf42 100644 --- a/res/readme_hu.html +++ b/res/readme_hu.html @@ -1,5 +1,5 @@ <h3 align="center">Magyar leírás</h3> <p> - Unicode, ékezetek, HTML. <u>Kezelhetőség.</u><br/> - <b>Na még mit mondjak...</b> + Unicode, ékezetek, HTML. <u>Kezelhetőség.</u><br/> + <b>Na még mit mondjak...</b> </p> diff --git a/src/Diagnostic.cpp b/src/Diagnostic.cpp index baeeb40c9ffa1291c66fc25f92e1b002bb075875..6903c4dde4a73e6af792e4568d8b4ec3645e8155 100644 --- a/src/Diagnostic.cpp +++ b/src/Diagnostic.cpp @@ -13,194 +13,194 @@ #include <include/ProcessHandler.hpp> void Diagnostic::onStarted(){ - double step = 100.0/func_vec.size(); - double i = 1.0; - foreach (function_t fn, func_vec) { - emit Update(static_cast<int>(ceil(step*i)), (this->*fn)()); - i += 1.0; - } - emit Quit(); + double step = 100.0/func_vec.size(); + double i = 1.0; + foreach (function_t fn, func_vec) { + emit Update(static_cast<int>(ceil(step*i)), (this->*fn)()); + i += 1.0; + } + emit Quit(); } Diagnostic::Diagnostic() - : func_vec({ - &Diagnostic::getOsInfo, - &Diagnostic::getInterfaceInfo, - &Diagnostic::getRoutingInfo, - &Diagnostic::getDGPingOutput, - &Diagnostic::getODPingOutput, - &Diagnostic::getDNSLookup - }), tab(2, ' ') + : func_vec({ + &Diagnostic::getOsInfo, + &Diagnostic::getInterfaceInfo, + &Diagnostic::getRoutingInfo, + &Diagnostic::getDGPingOutput, + &Diagnostic::getODPingOutput, + &Diagnostic::getDNSLookup + }), tab(2, ' ') { - INIT_GLOBALS(); + INIT_GLOBALS(); } QString Diagnostic::getRoutingInfo(){ - ProcessHandler proc(QIODevice::ReadOnly); - QStringList out; - - out << "- - - Routing - - - \n"; - - switch (CURRENT_OS){ - case OS_WINDOWS: - out << proc.exec("netsh interface ipv4 show route"); - //out << proc.exec("netsh interface ipv6 show route"); - break; - case OS_LINUX: - out << proc.exec("netstat -A inet -rn"); - //out << proc.exec("netstat -A inet6 -rn"); - break; - case OS_OSX: - out << proc.exec("/usr/sbin/netstat -f inet -rn"); - //out << proc.exec("/usr/sbin/netstat -f inet6 -rn"); - break; - default: - static_assert(true, "This OS is not supported"); - break; - } - return out.join(separator); + ProcessHandler proc(QIODevice::ReadOnly); + QStringList out; + + out << "- - - Routing - - - \n"; + + switch (CURRENT_OS){ + case OS_WINDOWS: + out << proc.exec("netsh interface ipv4 show route"); + //out << proc.exec("netsh interface ipv6 show route"); + break; + case OS_LINUX: + out << proc.exec("netstat -A inet -rn"); + //out << proc.exec("netstat -A inet6 -rn"); + break; + case OS_OSX: + out << proc.exec("/usr/sbin/netstat -f inet -rn"); + //out << proc.exec("/usr/sbin/netstat -f inet6 -rn"); + break; + default: + static_assert(true, "This OS is not supported"); + break; + } + return out.join(separator); } QString Diagnostic::getInterfaceInfo(){ - QList<QNetworkInterface> ifList = QNetworkInterface::allInterfaces(); - QStringList out; - - out << "- - - Interface Info - - - \n"; - out << "\n"; - foreach (QNetworkInterface iface, ifList){ - out << QString("%1\n").arg(iface.humanReadableName()); - out << QString("%1Address entries:\n").arg(tab); - { - int address_cntr = 0; - foreach (QNetworkAddressEntry netAddr, iface.addressEntries()){ - out << QString("%1%1entry #%2\n").arg(tab).arg(address_cntr++); - out << QString("%1%1%1- broadcast addr: %2\n").arg(tab).arg(netAddr.broadcast().toString()); - out << QString("%1%1%1- ip addr: %2\n").arg(tab).arg(netAddr.ip().toString()); - out << QString("%1%1%1- subnetmask: %2\n").arg(tab).arg(netAddr.netmask().toString()); - } - } - out << QString("%1- can broadcast? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::CanBroadcast)? "yes" : "no"); - out << QString("%1- can multicast? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::CanMulticast)? "yes" : "no"); - out << QString("%1- HW address: %2\n").arg(tab).arg(iface.hardwareAddress()); - out << QString("%1- is loopback? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsLoopBack)? "yes" : "no"); - out << QString("%1- is point-to-point? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsPointToPoint)? "yes" : "no"); - out << QString("%1- is running? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsRunning)? "yes" : "no"); - out << QString("%1- is up? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsUp)? "yes" : "no"); - out << QString("%1- is valid? %2\n").arg(tab).arg(iface.isValid()? "yes" : "no"); - out << QString("%1- internal name: %2\n").arg(tab).arg(iface.name()); - } - out << QString("Local addresses:\n"); - foreach (QHostAddress hostAddr, QNetworkInterface::allAddresses()){ - out << QString("%1- %2\n").arg(tab).arg(hostAddr.toString()); - } - return out.join(separator); + QList<QNetworkInterface> ifList = QNetworkInterface::allInterfaces(); + QStringList out; + + out << "- - - Interface Info - - - \n"; + out << "\n"; + foreach (QNetworkInterface iface, ifList){ + out << QString("%1\n").arg(iface.humanReadableName()); + out << QString("%1Address entries:\n").arg(tab); + { + int address_cntr = 0; + foreach (QNetworkAddressEntry netAddr, iface.addressEntries()){ + out << QString("%1%1entry #%2\n").arg(tab).arg(address_cntr++); + out << QString("%1%1%1- broadcast addr: %2\n").arg(tab).arg(netAddr.broadcast().toString()); + out << QString("%1%1%1- ip addr: %2\n").arg(tab).arg(netAddr.ip().toString()); + out << QString("%1%1%1- subnetmask: %2\n").arg(tab).arg(netAddr.netmask().toString()); + } + } + out << QString("%1- can broadcast? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::CanBroadcast)? "yes" : "no"); + out << QString("%1- can multicast? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::CanMulticast)? "yes" : "no"); + out << QString("%1- HW address: %2\n").arg(tab).arg(iface.hardwareAddress()); + out << QString("%1- is loopback? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsLoopBack)? "yes" : "no"); + out << QString("%1- is point-to-point? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsPointToPoint)? "yes" : "no"); + out << QString("%1- is running? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsRunning)? "yes" : "no"); + out << QString("%1- is up? %2\n").arg(tab).arg(iface.flags().testFlag(QNetworkInterface::IsUp)? "yes" : "no"); + out << QString("%1- is valid? %2\n").arg(tab).arg(iface.isValid()? "yes" : "no"); + out << QString("%1- internal name: %2\n").arg(tab).arg(iface.name()); + } + out << QString("Local addresses:\n"); + foreach (QHostAddress hostAddr, QNetworkInterface::allAddresses()){ + out << QString("%1- %2\n").arg(tab).arg(hostAddr.toString()); + } + return out.join(separator); } QString Diagnostic::getDGPingOutput(){ - ProcessHandler proc(QIODevice::ReadOnly); - QStringList out; - - out << "- - - Pinging Default Gateways - - -\n"; - - foreach (QString ip, DEF_GATEWAYS) { - switch (CURRENT_OS){ - case OS_WINDOWS: - out << proc.exec(QString("ping -n 4 -w 1 %1").arg(ip)); - break; - case OS_LINUX: - out << proc.exec(QString("ping -n -c 4 -W 1 %1").arg(ip)); - break; + ProcessHandler proc(QIODevice::ReadOnly); + QStringList out; + + out << "- - - Pinging Default Gateways - - -\n"; + + foreach (QString ip, DEF_GATEWAYS) { + switch (CURRENT_OS){ + case OS_WINDOWS: + out << proc.exec(QString("ping -n 4 -w 1 %1").arg(ip)); + break; + case OS_LINUX: + out << proc.exec(QString("ping -n -c 4 -W 1 %1").arg(ip)); + break; case OS_OSX: out << proc.exec(QString("ping -n -c 4 -W 1 %1").arg(ip)); break; - default: - static_assert(true, "This OS is not supported"); - break; - } - } - return out.join(separator); + default: + static_assert(true, "This OS is not supported"); + break; + } + } + return out.join(separator); } QString Diagnostic::getODPingOutput(){ - ProcessHandler proc(QIODevice::ReadOnly); - QStringList out; - - out << "- - - Pinging Outer Destinations - - -\n"; - - foreach (QString ip, OUTER_DEST) { - switch (CURRENT_OS){ - case OS_WINDOWS: - out << proc.exec(QString("ping -n 4 -w 1 %1").arg(ip)); - break; - case OS_LINUX: - out << proc.exec(QString("ping -c 4 -W 1 %1").arg(ip)); - break; - case OS_OSX: - out << proc.exec(QString("ping -c 4 -W 1 %1").arg(ip)); - break; - default: - static_assert(true, "This OS is not supported"); - break; - } - } - return out.join(separator); + ProcessHandler proc(QIODevice::ReadOnly); + QStringList out; + + out << "- - - Pinging Outer Destinations - - -\n"; + + foreach (QString ip, OUTER_DEST) { + switch (CURRENT_OS){ + case OS_WINDOWS: + out << proc.exec(QString("ping -n 4 -w 1 %1").arg(ip)); + break; + case OS_LINUX: + out << proc.exec(QString("ping -c 4 -W 1 %1").arg(ip)); + break; + case OS_OSX: + out << proc.exec(QString("ping -c 4 -W 1 %1").arg(ip)); + break; + default: + static_assert(true, "This OS is not supported"); + break; + } + } + return out.join(separator); } QString Diagnostic::getOsInfo(){ - ProcessHandler proc(QIODevice::ReadOnly); - QStringList out; - out << "- - - OS Version - - -\n"; - - switch (CURRENT_OS) { - case OS_WINDOWS: - { - /* this pattern removes leading/trailing/middle empty lines - * it is tested to work without escaping the backslashes. - * if the output is malformed feel free to escape them! */ - QRegExp e("(?:^[\r\n]+)|(?:[\r\n]{2}(?=[\r\n]))|(?:[\r\n]+$)"); - out << proc.exec("wmic os get Caption,CSDVersion /value").replace(e, ""); - } - break; - case OS_LINUX: - out << proc.exec("lsb_release -a"); - break; - case OS_OSX: - out << proc.exec("sw_vers"); - break; - default: - static_assert(true, "This OS is not supported"); - break; - } - return out.join(separator); + ProcessHandler proc(QIODevice::ReadOnly); + QStringList out; + out << "- - - OS Version - - -\n"; + + switch (CURRENT_OS) { + case OS_WINDOWS: + { + /* this pattern removes leading/trailing/middle empty lines + * it is tested to work without escaping the backslashes. + * if the output is malformed feel free to escape them! */ + QRegExp e("(?:^[\r\n]+)|(?:[\r\n]{2}(?=[\r\n]))|(?:[\r\n]+$)"); + out << proc.exec("wmic os get Caption,CSDVersion /value").replace(e, ""); + } + break; + case OS_LINUX: + out << proc.exec("lsb_release -a"); + break; + case OS_OSX: + out << proc.exec("sw_vers"); + break; + default: + static_assert(true, "This OS is not supported"); + break; + } + return out.join(separator); } QString Diagnostic::getDNSLookup(){ - QStringList out; - out << "- - - DNS Lookup for sch.bme.hu - - -\n"; - QEventLoop dns_event; - QDnsLookup dns_handle(QDnsLookup::ANY, DNS_ADDR); - - dns_event.connect(&dns_handle, SIGNAL(finished()), &dns_event, SLOT(quit())); - - foreach (QString nameserver, NS_ADDRS) { - dns_handle.setNameserver(QHostAddress(nameserver)); - dns_handle.lookup(); - dns_event.exec(); - if (dns_handle.error() == QDnsLookup::NoError) { - out << QString("nameserver: %1\n").arg(nameserver); - foreach (const QDnsHostAddressRecord &record, dns_handle.hostAddressRecords()) { - out << QString("%1- %2\n").arg(tab).arg(record.value().toString()); - } - } - else { - out << QString("nameserver: %1 - failed\n").arg(nameserver); - } - } - return out.join(separator); + QStringList out; + out << "- - - DNS Lookup for sch.bme.hu - - -\n"; + QEventLoop dns_event; + QDnsLookup dns_handle(QDnsLookup::ANY, DNS_ADDR); + + dns_event.connect(&dns_handle, SIGNAL(finished()), &dns_event, SLOT(quit())); + + foreach (QString nameserver, NS_ADDRS) { + dns_handle.setNameserver(QHostAddress(nameserver)); + dns_handle.lookup(); + dns_event.exec(); + if (dns_handle.error() == QDnsLookup::NoError) { + out << QString("nameserver: %1\n").arg(nameserver); + foreach (const QDnsHostAddressRecord &record, dns_handle.hostAddressRecords()) { + out << QString("%1- %2\n").arg(tab).arg(record.value().toString()); + } + } + else { + out << QString("nameserver: %1 - failed\n").arg(nameserver); + } + } + return out.join(separator); } diff --git a/src/Globals.cpp b/src/Globals.cpp index 6606578e45f7685dd33cd950e0985b9ebd7f94a6..7531b095c0cceb46a77019f12167479e9eb291b8 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -9,27 +9,27 @@ QStringList NS_ADDRS; QString DNS_ADDR; void INIT_GLOBALS(){ - DEF_GATEWAYS << "152.66.176.254"; - DEF_GATEWAYS << "152.66.178.254"; - DEF_GATEWAYS << "152.66.179.254"; - DEF_GATEWAYS << "152.66.180.254"; - DEF_GATEWAYS << "152.66.181.254"; - DEF_GATEWAYS << "152.66.182.254"; - DEF_GATEWAYS << "152.66.183.254"; - DEF_GATEWAYS << "152.66.210.254"; - DEF_GATEWAYS << "10.66.255.254"; - - OUTER_DEST << "152.66.0.1"; - OUTER_DEST << "152.66.0.15"; - OUTER_DEST << "8.8.8.8"; - OUTER_DEST << "8.8.4.4"; - - NS_ADDRS << "152.66.208.1"; - NS_ADDRS << "152.66.208.7"; - NS_ADDRS << "8.8.8.8"; - NS_ADDRS << "8.8.4.4"; - - DNS_ADDR = "sch.bme.hu"; + DEF_GATEWAYS << "152.66.176.254"; + DEF_GATEWAYS << "152.66.178.254"; + DEF_GATEWAYS << "152.66.179.254"; + DEF_GATEWAYS << "152.66.180.254"; + DEF_GATEWAYS << "152.66.181.254"; + DEF_GATEWAYS << "152.66.182.254"; + DEF_GATEWAYS << "152.66.183.254"; + DEF_GATEWAYS << "152.66.210.254"; + DEF_GATEWAYS << "10.66.255.254"; + + OUTER_DEST << "152.66.0.1"; + OUTER_DEST << "152.66.0.15"; + OUTER_DEST << "8.8.8.8"; + OUTER_DEST << "8.8.4.4"; + + NS_ADDRS << "152.66.208.1"; + NS_ADDRS << "152.66.208.7"; + NS_ADDRS << "8.8.8.8"; + NS_ADDRS << "8.8.4.4"; + + DNS_ADDR = "sch.bme.hu"; } #endif // GLOBALS_CPP diff --git a/src/NetCheckerWindow.cpp b/src/NetCheckerWindow.cpp index e543ef60ae90866e6d3c99b47f789b8e76684ddd..6fe54c8e425ed730a825dabf6b11a0d19512a151 100644 --- a/src/NetCheckerWindow.cpp +++ b/src/NetCheckerWindow.cpp @@ -8,327 +8,328 @@ #include <include/Translation.hpp> NetCheckerWindow::NetCheckerWindow(){ - /* default language is hungarian */ - lang = LANG::HUN; - setWindowFlags(Qt::WindowCloseButtonHint); - this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT); - /* initialize stacked window structure */ - initStackedWindow(); - /* localization for texts in program */ - initText(); + /* default language is hungarian */ + lang = LANG::HUN; + setWindowFlags(Qt::WindowCloseButtonHint); + this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT); + this->setAttribute(Qt::WA_QuitOnClose, false); + /* initialize stacked window structure */ + initStackedWindow(); + /* localization for texts in program */ + initText(); } void NetCheckerWindow::initStackedWindow(){ - global_l = new QVBoxLayout; - global_w = new QStackedWidget; - global_l->addWidget(global_w); + global_l = new QVBoxLayout; + global_w = new QStackedWidget; + global_l->addWidget(global_w); - /* remove margins and spacing from global layout */ - global_l->setMargin(0); - global_l->setSpacing(0); + /* remove margins and spacing from global layout */ + global_l->setMargin(0); + global_l->setSpacing(0); - initWelcomePage(); - initDiagnosticPage(); + initWelcomePage(); + initDiagnosticPage(); - setLayout(global_l); + setLayout(global_l); } void NetCheckerWindow::initWelcomePage(){ - /* initialization */ - welcome_page_l = new QHBoxLayout; - welcome_page_w = new QWidget; + /* initialization */ + welcome_page_l = new QHBoxLayout; + welcome_page_w = new QWidget; - /* remove margins and spacing from welcome page layout */ - welcome_page_l->setMargin(0); - welcome_page_l->setSpacing(0); + /* remove margins and spacing from welcome page layout */ + welcome_page_l->setMargin(0); + welcome_page_l->setSpacing(0); - /* init the two sides: logo and readme */ - initLogoSide(); - initReadmeSide(); + /* init the two sides: logo and readme */ + initLogoSide(); + initReadmeSide(); - welcome_page_w->setLayout(welcome_page_l); - global_w->addWidget(welcome_page_w); + welcome_page_w->setLayout(welcome_page_l); + global_w->addWidget(welcome_page_w); } void NetCheckerWindow::initLogoSide(){ - logo_side_w = new QWidget; - logo_side_l = new QVBoxLayout; - - logo_side_l->setContentsMargins(9, 9, 0, 0); - logo_side_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - logo_side_w->setFixedWidth(LOGO_WIDTH); - - /* logo image at the left */ - logo_image_w = new QLabel; - QSvgRenderer renderer(tr(":/res/logo.svg")); - int image_width = LOGO_WIDTH - 9; - QImage image(image_width, static_cast<int>(1.376888*image_width), QImage::Format_ARGB32); - image.fill(Qt::transparent); - QPainter painter(&image); - renderer.render(&painter); - QPixmap pix_logo = QPixmap::fromImage(image); - logo_image_w->setPixmap(pix_logo); - logo_image_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - - /* flags for choosing language */ - QWidget *flag_holder_w = new QWidget; - QHBoxLayout *flag_holder_l = new QHBoxLayout; - QPushButton *flag_eng_w = new QPushButton; - QPushButton *flag_hun_w = new QPushButton; - QPixmap pix_flag_eng(":/res/flag_eng.gif"); - QPixmap pix_flag_hun(":/res/flag_hun.gif"); - QIcon icon_eng(pix_flag_eng); - QIcon icon_hun(pix_flag_hun); - QSize icon_size(pix_flag_eng.width(), pix_flag_eng.height()); - - flag_eng_w->setIconSize(icon_size); - flag_eng_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - flag_eng_w->setFixedSize(icon_size.width()+6, icon_size.height()+6); - flag_eng_w->setIcon(icon_eng); - - flag_hun_w->setIconSize(icon_size); - flag_hun_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - flag_hun_w->setFixedSize(icon_size.width()+6, icon_size.height()+6); - flag_hun_w->setIcon(icon_hun); - - connect(flag_eng_w, SIGNAL(released()), this, SLOT(changeToEng())); - connect(flag_hun_w, SIGNAL(released()), this, SLOT(changeToHun())); - - flag_holder_l->addWidget(flag_hun_w); - flag_holder_l->addWidget(flag_eng_w); - flag_holder_w->setLayout(flag_holder_l); - - logo_side_l->addWidget(logo_image_w); - logo_side_l->addWidget(flag_holder_w); - logo_side_w->setLayout(logo_side_l); - - welcome_page_l->addWidget(logo_side_w); + logo_side_w = new QWidget; + logo_side_l = new QVBoxLayout; + + logo_side_l->setContentsMargins(9, 9, 0, 0); + logo_side_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + logo_side_w->setFixedWidth(LOGO_WIDTH); + + /* logo image at the left */ + logo_image_w = new QLabel; + QSvgRenderer renderer(tr(":/res/logo.svg")); + int image_width = LOGO_WIDTH - 9; + QImage image(image_width, static_cast<int>(1.376888*image_width), QImage::Format_ARGB32); + image.fill(Qt::transparent); + QPainter painter(&image); + renderer.render(&painter); + QPixmap pix_logo = QPixmap::fromImage(image); + logo_image_w->setPixmap(pix_logo); + logo_image_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + /* flags for choosing language */ + QWidget *flag_holder_w = new QWidget; + QHBoxLayout *flag_holder_l = new QHBoxLayout; + QPushButton *flag_eng_w = new QPushButton; + QPushButton *flag_hun_w = new QPushButton; + QPixmap pix_flag_eng(":/res/flag_eng.gif"); + QPixmap pix_flag_hun(":/res/flag_hun.gif"); + QIcon icon_eng(pix_flag_eng); + QIcon icon_hun(pix_flag_hun); + QSize icon_size(pix_flag_eng.width(), pix_flag_eng.height()); + + flag_eng_w->setIconSize(icon_size); + flag_eng_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + flag_eng_w->setFixedSize(icon_size.width()+6, icon_size.height()+6); + flag_eng_w->setIcon(icon_eng); + + flag_hun_w->setIconSize(icon_size); + flag_hun_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + flag_hun_w->setFixedSize(icon_size.width()+6, icon_size.height()+6); + flag_hun_w->setIcon(icon_hun); + + connect(flag_eng_w, SIGNAL(released()), this, SLOT(changeToEng())); + connect(flag_hun_w, SIGNAL(released()), this, SLOT(changeToHun())); + + flag_holder_l->addWidget(flag_hun_w); + flag_holder_l->addWidget(flag_eng_w); + flag_holder_w->setLayout(flag_holder_l); + + logo_side_l->addWidget(logo_image_w); + logo_side_l->addWidget(flag_holder_w); + logo_side_w->setLayout(logo_side_l); + + welcome_page_l->addWidget(logo_side_w); } void NetCheckerWindow::initReadmeSide(){ - readme_side_w = new QWidget; - readme_side_l = new QVBoxLayout; + readme_side_w = new QWidget; + readme_side_l = new QVBoxLayout; - readme_side_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + readme_side_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - /* textbox at the right */ - text_w = new QTextEdit; - text_w->setReadOnly(true); + /* textbox at the right */ + text_w = new QTextEdit; + text_w->setReadOnly(true); - /* next button */ - next_button_w = new QPushButton; - next_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(next_button_w, SIGNAL(released()), this, SLOT(nextPage())); + /* next button */ + next_button_w = new QPushButton; + next_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(next_button_w, SIGNAL(released()), this, SLOT(nextPage())); - readme_side_l->addWidget(text_w); - readme_side_l->addWidget(next_button_w, 0, Qt::AlignRight); - readme_side_w->setLayout(readme_side_l); + readme_side_l->addWidget(text_w); + readme_side_l->addWidget(next_button_w, 0, Qt::AlignRight); + readme_side_w->setLayout(readme_side_l); - welcome_page_l->addWidget(readme_side_w); + welcome_page_l->addWidget(readme_side_w); } void NetCheckerWindow::initDiagnosticPage(){ - diagnostic_page_w = new QWidget; - diagnostic_page_l = new QVBoxLayout; - - /* progress bar */ - progressbar_holder_w = new QGroupBox; - progressbar_holder_l = new QVBoxLayout; - progressbar_w = new QProgressBar; - progressbar_w->setRange(0, 100); - progressbar_w->setAlignment(Qt::AlignHCenter); - - /* progress bar info */ - QWidget *progress_info_holder_w = new QWidget; - QHBoxLayout *progress_info_holder_l = new QHBoxLayout; - progress_info = new QLabel; - progress_info_time = new QLabel; - progress_info->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - progress_info_time->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - progress_info_time->setFixedWidth(20); - progress_info_time->setAlignment(Qt::AlignRight); - progress_info->setAlignment(Qt::AlignRight); - - progress_info_holder_l->addWidget(progress_info); - progress_info_holder_l->addWidget(progress_info_time, 0, Qt::AlignRight); - progress_info_holder_l->setContentsMargins(0, 3, 3, 3); - - progress_info_holder_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - progress_info_holder_w->setLayout(progress_info_holder_l); - - progressbar_holder_w->setLayout(progressbar_holder_l); - progressbar_holder_l->addWidget(progressbar_w); - progressbar_holder_l->addWidget(progress_info_holder_w); - progressbar_holder_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - - /* log */ - log_holder_w = new QGroupBox; - log_holder_l = new QVBoxLayout; - log_w = new QTextEdit; - log_w->setReadOnly(true); - log_w->setLineWrapMode(QTextEdit::NoWrap); + diagnostic_page_w = new QWidget; + diagnostic_page_l = new QVBoxLayout; + + /* progress bar */ + progressbar_holder_w = new QGroupBox; + progressbar_holder_l = new QVBoxLayout; + progressbar_w = new QProgressBar; + progressbar_w->setRange(0, 100); + progressbar_w->setAlignment(Qt::AlignHCenter); + + /* progress bar info */ + QWidget *progress_info_holder_w = new QWidget; + QHBoxLayout *progress_info_holder_l = new QHBoxLayout; + progress_info = new QLabel; + progress_info_time = new QLabel; + progress_info->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + progress_info_time->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + progress_info_time->setFixedWidth(20); + progress_info_time->setAlignment(Qt::AlignRight); + progress_info->setAlignment(Qt::AlignRight); + + progress_info_holder_l->addWidget(progress_info); + progress_info_holder_l->addWidget(progress_info_time, 0, Qt::AlignRight); + progress_info_holder_l->setContentsMargins(0, 3, 3, 3); + + progress_info_holder_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + progress_info_holder_w->setLayout(progress_info_holder_l); + + progressbar_holder_w->setLayout(progressbar_holder_l); + progressbar_holder_l->addWidget(progressbar_w); + progressbar_holder_l->addWidget(progress_info_holder_w); + progressbar_holder_w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + + /* log */ + log_holder_w = new QGroupBox; + log_holder_l = new QVBoxLayout; + log_w = new QTextEdit; + log_w->setReadOnly(true); + log_w->setLineWrapMode(QTextEdit::NoWrap); log_w->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); log_w->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - log_w->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); - log_holder_w->setLayout(log_holder_l); - log_holder_l->addWidget(log_w); - - /* buttons */ - button_holder_w = new QWidget; - button_holder_l = new QHBoxLayout; - clipboard_button_w = new QPushButton; - save_button_w = new QPushButton; - clipboard_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - save_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - clipboard_button_w->setEnabled(false); - save_button_w->setEnabled(false); - - connect(clipboard_button_w, SIGNAL(released()), this, SLOT(copyClipboard())); - connect(save_button_w, SIGNAL(released()), this, SLOT(saveToFile())); - - button_holder_l->addWidget(clipboard_button_w); - button_holder_l->addWidget(save_button_w); - button_holder_w->setLayout(button_holder_l); - - /* trying to align buttons */ - button_holder_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - button_holder_l->setContentsMargins(12, 0, 12, 0); - - diagnostic_page_l->addWidget(progressbar_holder_w); - diagnostic_page_l->addWidget(log_holder_w); - diagnostic_page_l->addWidget(button_holder_w, 0, Qt::AlignRight); - diagnostic_page_w->setLayout(diagnostic_page_l); - - global_w->addWidget(diagnostic_page_w); + log_w->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); + log_holder_w->setLayout(log_holder_l); + log_holder_l->addWidget(log_w); + + /* buttons */ + button_holder_w = new QWidget; + button_holder_l = new QHBoxLayout; + clipboard_button_w = new QPushButton; + save_button_w = new QPushButton; + clipboard_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + save_button_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + clipboard_button_w->setEnabled(false); + save_button_w->setEnabled(false); + + connect(clipboard_button_w, SIGNAL(released()), this, SLOT(copyClipboard())); + connect(save_button_w, SIGNAL(released()), this, SLOT(saveToFile())); + + button_holder_l->addWidget(clipboard_button_w); + button_holder_l->addWidget(save_button_w); + button_holder_w->setLayout(button_holder_l); + + /* trying to align buttons */ + button_holder_w->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + button_holder_l->setContentsMargins(12, 0, 12, 0); + + diagnostic_page_l->addWidget(progressbar_holder_w); + diagnostic_page_l->addWidget(log_holder_w); + diagnostic_page_l->addWidget(button_holder_w, 0, Qt::AlignRight); + diagnostic_page_w->setLayout(diagnostic_page_l); + + global_w->addWidget(diagnostic_page_w); } void NetCheckerWindow::initText(){ - /* set program title */ - setWindowTitle(TXT_APP_TITLE[lang]); - - /* set next button label */ - next_button_w->setText(TXT_NEXT_BTN[lang]); - - /* change the readme text but also cache it */ - static QString readme_txt[2] = {QString(), QString()}; - if (readme_txt[0].isEmpty()){ - QFile readme_file_hun(README_URL[LANG::HUN]); - QFile readme_file_eng(README_URL[LANG::ENG]); - readme_file_hun.open(QIODevice::ReadOnly); - readme_file_eng.open(QIODevice::ReadOnly); - QTextStream readme_file_str_hun(&readme_file_hun); - QTextStream readme_file_str_eng(&readme_file_eng); - readme_file_str_hun.setCodec("UTF-8"); - readme_file_str_eng.setCodec("UTF-8"); - readme_txt[LANG::ENG] = readme_file_eng.readAll(); - readme_txt[LANG::HUN] = readme_file_str_hun.readAll(); - readme_file_hun.close(); - readme_file_eng.close(); - } - text_w->setHtml(readme_txt[lang]); - - /* progress bar and buttons region */ - progress_info->setText(TXT_EST_TIME[lang].append(":")); - progressbar_holder_w->setTitle(TXT_DIAG_GROUP[lang]); - log_holder_w->setTitle(TXT_LOG_GROUP[lang]); - clipboard_button_w->setText(TXT_CLIPB_BTN[lang]); - save_button_w->setText(TXT_SAVE_BTN[lang]); + /* set program title */ + setWindowTitle(TXT_APP_TITLE[lang]); + + /* set next button label */ + next_button_w->setText(TXT_NEXT_BTN[lang]); + + /* change the readme text but also cache it */ + static QString readme_txt[2] = {QString(), QString()}; + if (readme_txt[0].isEmpty()){ + QFile readme_file_hun(README_URL[LANG::HUN]); + QFile readme_file_eng(README_URL[LANG::ENG]); + readme_file_hun.open(QIODevice::ReadOnly); + readme_file_eng.open(QIODevice::ReadOnly); + QTextStream readme_file_str_hun(&readme_file_hun); + QTextStream readme_file_str_eng(&readme_file_eng); + readme_file_str_hun.setCodec("UTF-8"); + readme_file_str_eng.setCodec("UTF-8"); + readme_txt[LANG::ENG] = readme_file_eng.readAll(); + readme_txt[LANG::HUN] = readme_file_str_hun.readAll(); + readme_file_hun.close(); + readme_file_eng.close(); + } + text_w->setHtml(readme_txt[lang]); + + /* progress bar and buttons region */ + progress_info->setText(TXT_EST_TIME[lang].append(":")); + progressbar_holder_w->setTitle(TXT_DIAG_GROUP[lang]); + log_holder_w->setTitle(TXT_LOG_GROUP[lang]); + clipboard_button_w->setText(TXT_CLIPB_BTN[lang]); + save_button_w->setText(TXT_SAVE_BTN[lang]); } void NetCheckerWindow::nextPage(){ - /* turns page */ - global_w->setCurrentIndex(1); - - /* set up diagnostic + wiring some shit */ - Diagnostic *diag_obj = new Diagnostic; - QThread *diag_thread = new QThread(); - diag_obj->moveToThread(diag_thread); - - /* thread start -> diagnostic start */ - QObject::connect(diag_thread, SIGNAL(started()), diag_obj, SLOT(onStarted())); - /* update -> window */ - QObject::connect(diag_obj, SIGNAL(Update(int,QString)), this, SLOT(updateInfos(int,QString))); - /* quit diagnostic -> quit thread */ - QObject::connect(diag_obj, SIGNAL(Quit()), diag_thread, SLOT(quit())); - /* thread finished -> window's finish action */ - QObject::connect(diag_thread, SIGNAL(finished()), this, SLOT(finishAction())); - diag_thread->start(); - - /* set up timer */ - progress_timer = new QTimer(this); - connect(progress_timer, SIGNAL(timeout()), this, SLOT(incrementTime())); - progress_timer->setSingleShot(true); - progress_timer->start(); + /* turns page */ + global_w->setCurrentIndex(1); + + /* set up diagnostic + wiring some shit */ + Diagnostic *diag_obj = new Diagnostic; + QThread *diag_thread = new QThread(); + diag_obj->moveToThread(diag_thread); + + /* thread start -> diagnostic start */ + QObject::connect(diag_thread, SIGNAL(started()), diag_obj, SLOT(onStarted())); + /* update -> window */ + QObject::connect(diag_obj, SIGNAL(Update(int,QString)), this, SLOT(updateInfos(int,QString))); + /* quit diagnostic -> quit thread */ + QObject::connect(diag_obj, SIGNAL(Quit()), diag_thread, SLOT(quit())); + /* thread finished -> window's finish action */ + QObject::connect(diag_thread, SIGNAL(finished()), this, SLOT(finishAction())); + diag_thread->start(); + + /* set up timer */ + progress_timer = new QTimer(this); + connect(progress_timer, SIGNAL(timeout()), this, SLOT(incrementTime())); + progress_timer->setSingleShot(true); + progress_timer->start(); } void NetCheckerWindow::updateInfos(int progress_value, const QString info){ - progressbar_w->setValue(progress_value); - log_w->append(info); + progressbar_w->setValue(progress_value); + log_w->append(info); } void NetCheckerWindow::finishAction(){ - /* if diagnostic is over, stop the timer and change text to finished */ - progress_timer->stop(); - if (!progress_info_time->isHidden()){ - progress_info_time->hide(); - } - progress_info->setText(TXT_FINISHED[lang]); - - /* enable save buttons */ - clipboard_button_w->setEnabled(true); - save_button_w->setEnabled(true); + /* if diagnostic is over, stop the timer and change text to finished */ + progress_timer->stop(); + if (!progress_info_time->isHidden()){ + progress_info_time->hide(); + } + progress_info->setText(TXT_FINISHED[lang]); + + /* enable save buttons */ + clipboard_button_w->setEnabled(true); + save_button_w->setEnabled(true); } void NetCheckerWindow::copyClipboard(){ - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(log_w->toPlainText()); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(log_w->toPlainText()); } void NetCheckerWindow::saveToFile(){ - QString username = qgetenv("USER"); - if (username.isEmpty()) - username = qgetenv("USERNAME"); - QString filename = QFileDialog::getExistingDirectory(0, TXT_SAVE_DIALOG[lang]); - filename.append(tr("/%1_%2.txt").arg(username).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_h-m-s"))); - if (!filename.isEmpty()){ - QFile file(filename); - if (file.open(QIODevice::WriteOnly | QIODevice::Text)){ - QTextStream stream(&file); - stream.setCodec("UTF-8"); - stream << log_w->toPlainText(); - stream.flush(); - file.close(); - } - } + QString username = qgetenv("USER"); + if (username.isEmpty()) + username = qgetenv("USERNAME"); + QString filename = QFileDialog::getExistingDirectory(0, TXT_SAVE_DIALOG[lang]); + filename.append(tr("/%1_%2.txt").arg(username).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_h-m-s"))); + if (!filename.isEmpty()){ + QFile file(filename); + if (file.open(QIODevice::WriteOnly | QIODevice::Text)){ + QTextStream stream(&file); + stream.setCodec("UTF-8"); + stream << log_w->toPlainText(); + stream.flush(); + file.close(); + } + } } void NetCheckerWindow::changeToHun(){ - if (lang != LANG::HUN){ - lang = LANG::HUN; - initText(); - } + if (lang != LANG::HUN){ + lang = LANG::HUN; + initText(); + } } void NetCheckerWindow::changeToEng(){ - if (lang != LANG::ENG){ - lang = LANG::ENG; - initText(); - } + if (lang != LANG::ENG){ + lang = LANG::ENG; + initText(); + } } void NetCheckerWindow::incrementTime(){ - static int count = 53; - if (count >= 0){ - progress_info_time->setText(QString("%1s").arg(count--)); - progress_timer->start(1000); - } - else { - progress_info->setText(TXT_ALMOST_END[lang]); - if (!progress_info_time->isHidden()){ - progress_info_time->hide(); - } - } + static int count = 53; + if (count >= 0){ + progress_info_time->setText(QString("%1s").arg(count--)); + progress_timer->start(1000); + } + else { + progress_info->setText(TXT_ALMOST_END[lang]); + if (!progress_info_time->isHidden()){ + progress_info_time->hide(); + } + } } void NetCheckerWindow::show(){ diff --git a/src/Privileges.cpp b/src/Privileges.cpp index 75859b49d904d3bcfa570b834ab3631bd45718ba..d9527523f1112274651aa4c58bd5de7515a69f70 100644 --- a/src/Privileges.cpp +++ b/src/Privileges.cpp @@ -9,33 +9,33 @@ #define PRIVILEGES_CPP void Privileges::checkPrivileges(QWidget *parent, const QString title, const QString message){ - if (!isRoot()){ + if (!isRoot()){ QMessageBox::critical(parent, title, message, QMessageBox::Ok, QMessageBox::NoButton); parent->close(); - } + } } #if defined(Q_OS_WIN) - #include <windows.h> - bool Privileges::isRoot(){ - BOOL fRet = FALSE; - HANDLE hToken = NULL; - if( OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)){ - TOKEN_ELEVATION Elevation; - DWORD cbSize = sizeof(TOKEN_ELEVATION); - if(GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation),&cbSize)){ - fRet = Elevation.TokenIsElevated; - } - } - if(hToken){ - CloseHandle(hToken); - } - return fRet; - } + #include <windows.h> + bool Privileges::isRoot(){ + BOOL fRet = FALSE; + HANDLE hToken = NULL; + if( OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)){ + TOKEN_ELEVATION Elevation; + DWORD cbSize = sizeof(TOKEN_ELEVATION); + if(GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation),&cbSize)){ + fRet = Elevation.TokenIsElevated; + } + } + if(hToken){ + CloseHandle(hToken); + } + return fRet; + } #elif defined(Q_OS_LINUX) - #include <unistd.h> - bool Privileges::isRoot(){ - return !(getuid() && geteuid()); + #include <unistd.h> + bool Privileges::isRoot(){ + return !(getuid() && geteuid()); } #elif defined(Q_OS_OSX) #include <unistd.h> @@ -43,7 +43,7 @@ void Privileges::checkPrivileges(QWidget *parent, const QString title, const QSt return !(getuid() && geteuid()); } #else - #error "This OS is not supported yet!" + #error "This OS is not supported yet!" #endif #endif // PRIVILEGES_CPP diff --git a/src/ProcessHandler.cpp b/src/ProcessHandler.cpp index c7122ac298be32e8dfea3408eb252d166d5ae692..c3ed36445d150ba2df670fa01710f0bf2535a828 100644 --- a/src/ProcessHandler.cpp +++ b/src/ProcessHandler.cpp @@ -8,15 +8,15 @@ #define PROCESSHANDLER_CPP ProcessHandler::ProcessHandler(QProcess::OpenMode mode): QProcess() { - setOpenMode(mode); + setOpenMode(mode); } QString ProcessHandler::exec(QString commands){ - start(commands); - if (!waitForFinished()){ - return tr("Error occured. Command was: %1\n").arg(commands); - } - QByteArray ba = readAllStandardOutput(); - return ba; + start(commands); + if (!waitForFinished()){ + return tr("Error occured. Command was: %1\n").arg(commands); + } + QByteArray ba = readAllStandardOutput(); + return ba; } #endif