From 2c98c6ee8fc7e1433b6e6d6b7abdb8d9d9c0b0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Thu, 10 Feb 2022 22:58:04 +0100 Subject: [PATCH 1/4] Remove method unused outside of events.cpp from header (to avoid mess) --- src/event.cpp | 67 +++++++++++++++++++++++++++------------------------ src/event.h | 6 ----- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index c0900a60e..e2424f9fa 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -95,38 +95,9 @@ void fakeAbsMouseCoordinates(double springX, double springY, int width, int heig finaly = (screenMidheight + (springY * destMidHeight) + deskRect.y()); } -// Create the event used by the operating system. -void sendevent(JoyButtonSlot *slot, bool pressed) -{ - JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); - - if (device == JoyButtonSlot::JoyKeyboard) - { - EventHandlerFactory::getInstance()->handler()->sendKeyboardEvent(slot, pressed); - } else if (device == JoyButtonSlot::JoyMouseButton) - { - EventHandlerFactory::getInstance()->handler()->sendMouseButtonEvent(slot, pressed); - } else if ((device == JoyButtonSlot::JoyTextEntry) && pressed && !slot->getTextData().isEmpty()) - { - EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData()); - } else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty()) - { - QString argumentsString = ""; - if (slot->getExtraData().canConvert()) - { - argumentsString = slot->getExtraData().toString(); - // QStringList argumentsTempList(PadderCommon::parseArgumentsString(argumentsString)); - } - - QString launched_command = - QString("%1 %2 %3").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData()).arg(argumentsString); - qInfo() << "Executing command: " << launched_command; - bool success = QProcess::startDetached(launched_command); - if (!success) - qWarning() << "Command cannot be executed"; - } -} - +/** + * @brief detects executor for selected file (for .py files python, for .exe "" etc) + */ QString detectedScriptExt(QString file) { QFileInfo fileinfo(file); @@ -165,6 +136,38 @@ QString detectedScriptExt(QString file) return ""; } +// Create the event used by the operating system. +void sendevent(JoyButtonSlot *slot, bool pressed) +{ + JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode(); + + if (device == JoyButtonSlot::JoyKeyboard) + { + EventHandlerFactory::getInstance()->handler()->sendKeyboardEvent(slot, pressed); + } else if (device == JoyButtonSlot::JoyMouseButton) + { + EventHandlerFactory::getInstance()->handler()->sendMouseButtonEvent(slot, pressed); + } else if ((device == JoyButtonSlot::JoyTextEntry) && pressed && !slot->getTextData().isEmpty()) + { + EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData()); + } else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty()) + { + QString argumentsString = ""; + if (slot->getExtraData().canConvert()) + { + argumentsString = slot->getExtraData().toString(); + // QStringList argumentsTempList(PadderCommon::parseArgumentsString(argumentsString)); + } + + QString launched_command = + QString("%1 %2 %3").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData()).arg(argumentsString); + qInfo() << "Executing command: " << launched_command; + bool success = QProcess::startDetached(launched_command); + if (!success) + qWarning() << "Command cannot be executed"; + } +} + // Create the relative mouse event used by the operating system. void sendevent(int code1, int code2) { EventHandlerFactory::getInstance()->handler()->sendMouseEvent(code1, code2); } diff --git a/src/event.h b/src/event.h index f6e91a4a3..879edd0a0 100644 --- a/src/event.h +++ b/src/event.h @@ -26,16 +26,10 @@ void sendevent(JoyButtonSlot *slot, bool pressed = true); void sendevent(int code1, int code2); void sendKeybEvent(JoyButtonSlot *slot, bool pressed = true); -void sendSpringEventRefactor(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring = 0, - int *const mousePosX = 0, int *const mousePos = 0); void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, PadderCommon::springModeInfo *relativeSpring = 0, int *const mousePosX = 0, int *const mousePos = 0); -void fakeAbsMouseCoordinates(double springX, double springY, int width, int height, int &finalx, int &finaly, - int screen = -1); - -QString detectedScriptExt(QString file); int X11KeySymToKeycode(QString key); QString keycodeToKeyString(int keycode, int alias = 0); int X11KeyCodeToX11KeySym(int keycode); From 7ba1a6ee367735ac3f6710a710b472dec5b8dd23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Thu, 10 Feb 2022 23:09:10 +0100 Subject: [PATCH 2/4] Rename isDebugLevel to more descriptive name --- src/joybutton.cpp | 2 +- src/logger.cpp | 2 +- src/logger.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/joybutton.cpp b/src/joybutton.cpp index c36fe88de..7c6cab5e7 100644 --- a/src/joybutton.cpp +++ b/src/joybutton.cpp @@ -170,7 +170,7 @@ void JoyButton::vdpadPassEvent(bool pressed, bool ignoresets) void JoyButton::joyEvent(bool pressed, bool ignoresets) { - if (Logger::isDebugLevel()) + if (Logger::isDebugEnabled()) DEBUG() << "Processing joyEvent for: " << getName(); if ((m_vdpad != nullptr) && !pendingEvent) diff --git a/src/logger.cpp b/src/logger.cpp index 2367e2793..0ea33388e 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -243,7 +243,7 @@ Logger *Logger::createInstance(QTextStream *stream, LogLevel outputLevel, QObjec return instance; } -bool Logger::isDebugLevel() +bool Logger::isDebugEnabled() { if (instance != nullptr) { diff --git a/src/logger.h b/src/logger.h index 0d67bc0eb..a1b785c45 100644 --- a/src/logger.h +++ b/src/logger.h @@ -77,7 +77,7 @@ class Logger : public QObject static void setLogLevel(LogLevel level); LogLevel getCurrentLogLevel(); - static bool isDebugLevel(); + static bool isDebugEnabled(); static void setCurrentStream(QTextStream *stream); static void setCurrentLogFile(QString filename); From 22e36cf5034dc9abacdd6ab3a15a3f366f53efdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Thu, 10 Feb 2022 23:31:05 +0100 Subject: [PATCH 3/4] Add getting log file to logger --- src/logger.cpp | 9 +++++++++ src/logger.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/logger.cpp b/src/logger.cpp index 0ea33388e..d934c94ca 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -251,3 +251,12 @@ bool Logger::isDebugEnabled() } return false; } + +QString Logger::getCurrentLogFile() +{ + Q_ASSERT(instance != nullptr); + if (instance->outputFile.exists()) + return instance->outputFile.fileName(); + else + return ""; +} \ No newline at end of file diff --git a/src/logger.h b/src/logger.h index a1b785c45..a319786f6 100644 --- a/src/logger.h +++ b/src/logger.h @@ -81,6 +81,7 @@ class Logger : public QObject static void setCurrentStream(QTextStream *stream); static void setCurrentLogFile(QString filename); + static QString getCurrentLogFile(); bool isWritingToFile(); static QTextStream *getCurrentStream(); From 61fda62f45ef8713a44f3efe330d0af2f1ec59a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Fri, 11 Feb 2022 23:15:23 +0100 Subject: [PATCH 4/4] Change way of command execution - PID of launched executables will be visible in logs - their working directory will be in file location --- src/event.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index e2424f9fa..50cc6d0bb 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -32,6 +32,7 @@ #include "eventhandlerfactory.h" #include "globalvariables.h" #include "joybutton.h" +#include "logger.h" #if defined(Q_OS_UNIX) #if defined(WITH_X11) @@ -152,19 +153,32 @@ void sendevent(JoyButtonSlot *slot, bool pressed) EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData()); } else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty()) { - QString argumentsString = ""; + QStringList argumentsTempList = {}; + QString argumentsString = slot->getExtraData().toString(); if (slot->getExtraData().canConvert()) { - argumentsString = slot->getExtraData().toString(); - // QStringList argumentsTempList(PadderCommon::parseArgumentsString(argumentsString)); + argumentsTempList = PadderCommon::parseArgumentsString(argumentsString); } - QString launched_command = - QString("%1 %2 %3").arg(detectedScriptExt(slot->getTextData())).arg(slot->getTextData()).arg(argumentsString); - qInfo() << "Executing command: " << launched_command; - bool success = QProcess::startDetached(launched_command); - if (!success) - qWarning() << "Command cannot be executed"; + QProcess process; + QString process_executor = detectedScriptExt(slot->getTextData()); + if (process_executor.isEmpty()) + process.setProgram(slot->getTextData()); + else + { + process.setProgram(process_executor); + argumentsTempList.prepend(slot->getTextData()); + } + process.setArguments(argumentsTempList); + + process.setWorkingDirectory(QFileInfo(slot->getTextData()).absoluteDir().path()); + qint64 pid = 0; + bool success = process.startDetached(&pid); + if (success) + qInfo() << "Command: " << slot->getTextData() << " " << argumentsString + << " executed successfully with pid: " << pid; + else + qWarning() << "Command " << slot->getTextData() << " " << argumentsString << " cannot be executed, pid: " << pid; } }