diff --git a/CMakeLists.txt b/CMakeLists.txt index 74ce25ab7676a4579b6246761d298f52f4c35a43..226d5a3356999cbdc6de57a3c14a940a24f15b15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,44 +7,20 @@ if(DEFINED ENV{OSXCROSS_HOST}) SET(Qt5_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5") SET(Qt5Core_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Core") - SET(Qt5Qml_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Qml") SET(Qt5Network_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Network") - SET(Qt5Quick_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Quick") - SET(Qt5Gui_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Gui") SET(Qt5PacketProtocol_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5PacketProtocol") - SET(Qt5AccessibilitySupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5AccessibilitySupport") - SET(Qt5ThemeSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5ThemeSupport") - SET(Qt5FontDatabaseSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5FontDatabaseSupport") - SET(Qt5GraphicsSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5GraphicsSupport") - SET(Qt5PrintSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5PrintSupport") - SET(Qt5Widgets_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Widgets") - SET(Qt5ClipboardSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5ClipboardSupport") - SET(Qt5EventDispatcherSupport_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5EventDispatcherSupport") - SET(Qt5Svg_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Svg") SET(Qt5Zlib_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5Zlib") - SET(Qt5VirtualKeyboard_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5VirtualKeyboard") - SET(Qt5QmlModels_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5QmlModels") - SET(Qt5WebSockets_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5WebSockets") - SET(Qt5QuickWidgets_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5QuickWidgets") - SET(Qt5QuickControls2_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5QuickControls2") - SET(Qt5QmlWorkerScript_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5QmlWorkerScript") - set(Qt5QmlImportScanner_DIR "/opt/osxcross/qt-5.15.13/lib/cmake/Qt5QmlImportScanner") + endif() find_package(Qt5 5.15 REQUIRED COMPONENTS Core - Qml - Quick - Widgets - QuickWidgets - QuickControls2 - QmlWorkerScript - ) + Network +) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) - if(UNIX) if(DARWIN) add_definitions(-DCLI_PATH="./cellframe-node-cli") @@ -54,9 +30,6 @@ if(UNIX) ./CellframeNodeDiagtool/AbstractDiagnostic.cpp ./CellframeNodeDiagtool/MacDiagnostic.cpp ./CellframeNodeDiagtool/NotifyWorker.cpp - ./CellframeNodeTray/NodeTrayCommandController.cpp - ./CellframeNodeTray/qml.qrc - ./CellframeNodeTray/Resources.qrc ./main.cpp ) endif() @@ -69,9 +42,6 @@ if(UNIX) ./CellframeNodeDiagtool/AbstractDiagnostic.cpp ./CellframeNodeDiagtool/LinuxDiagnostic.cpp ./CellframeNodeDiagtool/NotifyWorker.cpp - ./CellframeNodeTray/NodeTrayCommandController.cpp - ./CellframeNodeTray/qml.qrc - ./CellframeNodeTray/Resources.qrc ./main.cpp ) endif() @@ -87,29 +57,14 @@ if(WIN32) ./CellframeNodeDiagtool/registry.c ./CellframeNodeDiagtool/WinDiagnostic.cpp ./CellframeNodeDiagtool/NotifyWorker.cpp - ./CellframeNodeTray/NodeTrayCommandController.cpp - ./CellframeNodeTray/qml.qrc - ./CellframeNodeTray/Resources.qrc ./main.cpp ) - - endif() target_include_directories(${PROJECT_NAME} PRIVATE ./CellframeNodeDiagtool) -target_include_directories(${PROJECT_NAME} PRIVATE ./CellframeNodeTray) - -find_package(Qt5 COMPONENTS QmlImportScanner) -qt5_import_qml_plugins(${PROJECT_NAME}) - -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Widgets Qt5::Core - Qt5::Network - Qt5::Quick - Qt5::QuickControls2 - Qt5::QmlWorkerScript -) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network) if (WIN32) -target_link_libraries(${PROJECT_NAME} PUBLIC psapi) + target_link_libraries(${PROJECT_NAME} PUBLIC psapi) endif() diff --git a/CellframeNodeDiagtool/DiagnosticWorker.cpp b/CellframeNodeDiagtool/DiagnosticWorker.cpp index b427aa7ce5a724503c1dc9c0790e946008966060..f73c25ed80c16f563ef2b129a71984377c0fed10 100644 --- a/CellframeNodeDiagtool/DiagnosticWorker.cpp +++ b/CellframeNodeDiagtool/DiagnosticWorker.cpp @@ -55,34 +55,6 @@ void DiagnosticWorker::init() emit sigInitStatusChanged(m_initStatus); } -void DiagnosticWorker::switchSendData() -{ - m_isSendData = !m_isSendData; - - if(!m_isSendData) - m_diagnostic->stop_diagnostic(); - else - m_diagnostic->start_diagnostic(); - - QSettings().setValue("diag_send_data", m_isSendData); - - emit sigSendDataStatusChanged(m_isSendData); -} - -void DiagnosticWorker::openConfigFile() -{ - QDesktopServices::openUrl(m_diagnostic->s_jsonFilePath); -} - -void DiagnosticWorker::getSendedData() -{ - QFile sndData(m_diagnostic->s_sendedDataFilePath); - sndData.open(QIODevice::WriteOnly); - sndData.write(m_lastSendedPack.toJson()); - - QDesktopServices::openUrl(m_diagnostic->s_sendedDataFilePath); -} - DiagnosticWorker &DiagnosticWorker::getInstance() { static DiagnosticWorker instance; diff --git a/CellframeNodeDiagtool/DiagnosticWorker.h b/CellframeNodeDiagtool/DiagnosticWorker.h index 7bce4a1952a44070dc8c1083f44b180228b11d38..4c27b13e0d39ae6189d9e2b170d1f7de990fec31 100644 --- a/CellframeNodeDiagtool/DiagnosticWorker.h +++ b/CellframeNodeDiagtool/DiagnosticWorker.h @@ -6,7 +6,6 @@ #include <QElapsedTimer> #include <QSettings> #include <QThread> -#include <QDesktopServices> #include <QSettings> #include <unistd.h> @@ -39,12 +38,6 @@ public: void init(); - Q_INVOKABLE bool getInitStatus(){return m_initStatus;} - Q_INVOKABLE bool getSendDataStatus(){return m_isSendData;} - Q_INVOKABLE void switchSendData(); - Q_INVOKABLE void openConfigFile(); - Q_INVOKABLE void getSendedData(); - private: QString m_node_version{""}; QSettings m_settings; diff --git a/CellframeNodeDiagtool/NotifyWorker.cpp b/CellframeNodeDiagtool/NotifyWorker.cpp index b5c275ff6decec40e1c74a19c7f7de2d859ac424..09ce94df3c3ea9ca621361bcc6c11057f7af1702 100644 --- a/CellframeNodeDiagtool/NotifyWorker.cpp +++ b/CellframeNodeDiagtool/NotifyWorker.cpp @@ -1,5 +1,73 @@ #include "NotifyWorker.h" -#include "NodeTrayCommandController.h" +#include <QDir> + +#ifdef WIN32 +#include "registry.h" +#endif + + +bool NotifyWorker::initConfTool() +{ + m_configDir = getConfigPath(); + + if(!QDir(m_configDir).exists()){ + qWarning()<<"Could not find config path"; + } + + QString pathConftool; +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + pathConftool = "/opt/cellframe-node/bin/cellframe-node-config"; +#elif defined (Q_OS_MACOS) + pathConftool = "/Applications/CellframeNode.app/Contents/MacOS/cellframe-node-config"; +#elif defined (Q_OS_WIN) + //HKLM "Software\${APP_NAME}" "Path" + HKEY hKey; + LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\cellframe-node\\", 0, KEY_READ, &hKey); + bool bExistsAndSuccess (lRes == ERROR_SUCCESS); + bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND); + std::wstring path; + GetStringRegKey(hKey, L"Path", path, L""); + std::string stdpath(path.begin(),path.end()); + + pathConftool = QString(QString::fromWCharArray(path.c_str()) + "/cellframe-node-config.exe"); +#endif + + QFileInfo confTool(pathConftool); + if(!confTool.exists()) + { + qWarning()<<"Could not find cellframe-node-config"; + return false; + } + else + { + m_configWorkerPath = confTool.absoluteFilePath(); + return true; + } +} + +QString NotifyWorker::getConfigPath() +{ +#ifdef __linux__ + return "/opt/cellframe-node/"; +#endif + +#ifdef __APPLE__ + return "/Library/Application Support/CellframeNode/"; +#endif + +#ifdef WIN32 + HKEY hKey; + LONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ, &hKey); + bool bExistsAndSuccess (lRes == ERROR_SUCCESS); + bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND); + std::wstring path; + GetStringRegKey(hKey, L"Common Documents", path, L""); + std::string stdpath(path.begin(),path.end()); + return QString(QString::fromWCharArray(path.c_str()) + "/cellframe-node"); +#endif +} + + QByteArrayList NotifyWorker::jsonListFromData(QByteArray data) { @@ -9,11 +77,8 @@ QByteArrayList NotifyWorker::jsonListFromData(QByteArray data) NotifyWorker::NotifyWorker(QObject *parent) :QObject(parent) { - NodeTrayCommandController *m_trayCtrl = &NodeTrayCommandController::getInstance(); - - if(m_trayCtrl->initConfTool()) + if(initConfTool()) { - m_configWorkerPath = m_trayCtrl->m_confToolPath; m_initTimer = new QTimer(this); m_reconnectTimer = new QTimer(this); diff --git a/CellframeNodeDiagtool/NotifyWorker.h b/CellframeNodeDiagtool/NotifyWorker.h index dc780cfa18ea8d7ccf54c7990386d9c4d7ffa4b2..4650cb894fb7cd3d42ee461b276c7e2774ee2ae5 100644 --- a/CellframeNodeDiagtool/NotifyWorker.h +++ b/CellframeNodeDiagtool/NotifyWorker.h @@ -53,7 +53,11 @@ private: QByteArrayList jsonListFromData(QByteArray data); void procNotifyData(const QJsonObject &rcvObj); + + bool initConfTool(); + QString getConfigPath(); private: + QString m_configDir; QString m_configWorkerPath; QIODevice *m_socket; QString m_listenPath; diff --git a/cellfram-node-diagtool.pro b/cellfram-node-diagtool.pro deleted file mode 100644 index 9665ba334832678d90c4628c3c2ce38e505eccbd..0000000000000000000000000000000000000000 --- a/cellfram-node-diagtool.pro +++ /dev/null @@ -1,61 +0,0 @@ -QT += qml quick widgets quickwidgets - -CONFIG += c++17 - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -INCLUDEPATH += CellframeNodeTray \ - CellframeNodeDiagtool - -SOURCES += \ - CellframeNodeDiagtool/NotifyWorker.cpp \ - CellframeNodeTray/NodeTrayCommandController.cpp \ - main.cpp \ - CellframeNodeDiagtool/AbstractDiagnostic.cpp \ - CellframeNodeDiagtool/DiagnosticWorker.cpp - -HEADERS += \ - CellframeNodeDiagtool/NotifyWorker.h \ - CellframeNodeTray/NodeTrayCommandController.h \ - CellframeNodeDiagtool/AbstractDiagnostic.h \ - CellframeNodeDiagtool/DiagnosticWorker.h - -win32 { - DEFINES += CLI_PATH=\\\"cellframe-node-cli.exe\\\" - HEADERS += CellframeNodeDiagtool/WinDiagnostic.h \ - CellframeNodeDiagtool/registry.h - SOURCES += CellframeNodeDiagtool/WinDiagnostic.cpp \ - CellframeNodeDiagtool/registry.c \ -} - -mac { - DEFINES += CLI_PATH=\\\"./cellframe-node-cli\\\" - HEADERS += CellframeNodeDiagtool/MacDiagnostic.h - SOURCES += CellframeNodeDiagtool/MacDiagnostic.cpp -} - -else: !win32 { - DEFINES += CLI_PATH=\\\"/opt/cellframe-node/bin/cellframe-node-cli\\\" - HEADERS += CellframeNodeDiagtool/LinuxDiagnostic.h - SOURCES += CellframeNodeDiagtool/LinuxDiagnostic.cpp -} - -RESOURCES += CellframeNodeTray/qml.qrc \ - CellframeNodeTray/Resources.qrc - - -# Additional import path used to resolve QML modules in Qt Creator's code model -QML_IMPORT_PATH = - -# Additional import path used to resolve QML modules just for Qt Quick Designer -QML_DESIGNER_IMPORT_PATH = - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - - -DISTFILES += diff --git a/main.cpp b/main.cpp index c774b349e59f98985bd1ddd4146121a70eb46b3d..ee4ec83afbe11a15a9fe27b1f8657ac7023dce26 100644 --- a/main.cpp +++ b/main.cpp @@ -1,17 +1,12 @@ -#include <QApplication> -#include <QQmlApplicationEngine> #include <QDebug> #include <QSystemSemaphore> #include <QSharedMemory> -#include <QScreen> #include <sys/stat.h> #include <memory> -#include "NodeTrayCommandController.h" #include "DiagnosticWorker.h" - bool SingleApplicationTest(const QString &appName) { static QSystemSemaphore semaphore("<"+appName+" uniq semaphore id>", 1); @@ -41,30 +36,19 @@ bool SingleApplicationTest(const QString &appName) if(is_running) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText(QObject::tr("The application '%1' is already running.").arg(appName)); - msgBox.exec(); + qWarning() << QString("The application '%1' is already running.").arg(appName); return false; } return true; } -bool findArg(char** begin, char** end, const std::string& option) -{ - return std::find(begin, end, option) != end; -} - -QString getDesctopSession() -{ - return qgetenv("DESKTOP_SESSION"); -} - int main(int argc, char *argv[]) { + QCoreApplication app(argc, argv); + app.setApplicationName("cellframe-diagtool"); - qSetMessagePattern(QLatin1String( + qSetMessagePattern(QStringLiteral( "[%{time h:mm:ss}] " "%{if-debug}\x1b[36m[DBG]\x1b[37m%{endif}" "%{if-info}\x1b[32m[INF]\x1b[37m%{endif}" @@ -76,28 +60,11 @@ int main(int argc, char *argv[]) " %{if-category}%{category} %{endif}%{message}" "\x1b[0m" )); - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); -#endif - bool start_tray = findArg(argv, argv+argc,"--tray"); - - QCoreApplication *app = start_tray?(new QApplication(argc, argv)):(new QCoreApplication(argc, argv)); - if(!start_tray) DiagnosticWorker::getInstance().init(); - else - { - QString appName = "cellframe-node-tray"; - - if (!SingleApplicationTest(appName)) - return 1; - - QCoreApplication::setApplicationName(appName); - - NodeTrayCommandController::getInstance().init(); - } + if (!SingleApplicationTest(app.applicationName())) + return 1; - qDebug() << "Desctop session" << getDesctopSession(); + DiagnosticWorker::getInstance().init(); - return app->exec(); + return app.exec(); }