From 36b3bd9639d353e2f9c31cbd4ba304d7586d12be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Gu=C5=A1i=C4=87?= Date: Tue, 21 Dec 2021 18:59:08 +0100 Subject: [PATCH] Implement abstract logger (#2174) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AbstractLogger base implementation Signed-off-by: Haris Gušić * Switch most system notifications to AbstractLogger Signed-off-by: Haris Gušić * Make CLI parser use AbstractLogger Signed-off-by: Haris Gušić * Fix annoying QPainter warning in QtColorWidgets Signed-off-by: Haris Gušić * Remove obsolete TODOs Signed-off-by: Haris Gušić * Fix failing windows build Signed-off-by: Haris Gušić * Add missing #include Signed-off-by: Haris Gušić --- .../src/QtColorWidgets/color_wheel.cpp | 6 +- src/cli/commandlineparser.cpp | 34 +++-- src/config/configwindow.cpp | 3 +- src/core/controller.cpp | 12 +- src/core/flameshotdaemon.cpp | 6 +- src/main.cpp | 23 ++- src/utils/CMakeLists.txt | 6 +- src/utils/abstractlogger.cpp | 132 ++++++++++++++++++ src/utils/abstractlogger.h | 53 +++++++ src/utils/confighandler.cpp | 15 +- src/utils/confighandler.h | 9 +- src/utils/screengrabber.cpp | 3 +- src/utils/screenshotsaver.cpp | 16 ++- src/widgets/capture/capturewidget.cpp | 3 +- 14 files changed, 259 insertions(+), 62 deletions(-) create mode 100644 src/utils/abstractlogger.cpp create mode 100644 src/utils/abstractlogger.h diff --git a/external/Qt-Color-Widgets/src/QtColorWidgets/color_wheel.cpp b/external/Qt-Color-Widgets/src/QtColorWidgets/color_wheel.cpp index bca13dc0..ec6dd8ca 100644 --- a/external/Qt-Color-Widgets/src/QtColorWidgets/color_wheel.cpp +++ b/external/Qt-Color-Widgets/src/QtColorWidgets/color_wheel.cpp @@ -231,7 +231,11 @@ void ColorWheel::mouseReleaseEvent(QMouseEvent *ev) void ColorWheel::resizeEvent(QResizeEvent *) { - p->render_ring(); + static bool skipFirst = true; + // Skip the first time in order to prevent QPainter warning messages + if (!skipFirst) + p->render_ring(); + skipFirst = false; p->render_inner_selector(); } diff --git a/src/cli/commandlineparser.cpp b/src/cli/commandlineparser.cpp index 87018bfe..2834fd59 100644 --- a/src/cli/commandlineparser.cpp +++ b/src/cli/commandlineparser.cpp @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include "commandlineparser.h" +#include "abstractlogger.h" #include "src/utils/globalvalues.h" #include #include @@ -12,8 +13,9 @@ CommandLineParser::CommandLineParser() namespace { -QTextStream out(stdout); -QTextStream err(stderr); +AbstractLogger out = + AbstractLogger::info(AbstractLogger::Stderr).enableMessageHeader(false); +AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr); auto versionOption = CommandOption({ "v", "version" }, @@ -97,7 +99,7 @@ bool CommandLineParser::processArgs(const QStringList& args, --actualIt; } else { ok = false; - out << QStringLiteral("'%1' is not a valid argument.").arg(argument); + err << QStringLiteral("'%1' is not a valid argument.").arg(argument); } return ok; } @@ -119,7 +121,7 @@ bool CommandLineParser::processOptions(const QStringList& args, bool isDoubleDashed = arg.startsWith(QLatin1String("--")); ok = isDoubleDashed ? arg.length() > 3 : arg.length() == 2; if (!ok) { - out << QStringLiteral("the option %1 has a wrong format.").arg(arg); + err << QStringLiteral("the option %1 has a wrong format.").arg(arg); return ok; } arg = isDoubleDashed ? arg.remove(0, 2) : arg.remove(0, 1); @@ -137,7 +139,7 @@ bool CommandLineParser::processOptions(const QStringList& args, if (argName.isEmpty()) { argName = qApp->applicationName(); } - out << QStringLiteral("the option '%1' is not a valid option " + err << QStringLiteral("the option '%1' is not a valid option " "for the argument '%2'.") .arg(arg) .arg(argName); @@ -148,7 +150,7 @@ bool CommandLineParser::processOptions(const QStringList& args, CommandOption option = *optionIt; bool requiresValue = !(option.valueName().isEmpty()); if (!requiresValue && equalsPos != -1) { - out << QStringLiteral("the option '%1' contains a '=' and it doesn't " + err << QStringLiteral("the option '%1' contains a '=' and it doesn't " "require a value.") .arg(arg); ok = false; @@ -158,7 +160,7 @@ bool CommandLineParser::processOptions(const QStringList& args, if (actualIt + 1 != args.cend()) { ++actualIt; } else { - out << QStringLiteral("Expected value after the option '%1'.") + err << QStringLiteral("Expected value after the option '%1'.") .arg(arg); ok = false; return ok; @@ -169,10 +171,10 @@ bool CommandLineParser::processOptions(const QStringList& args, if (requiresValue) { ok = option.checkValue(valueStr); if (!ok) { - QString err = option.errorMsg(); - if (!err.endsWith(QLatin1String("."))) - err += QLatin1String("."); - out << err; + QString msg = option.errorMsg(); + if (!msg.endsWith(QLatin1String("."))) + msg += QLatin1String("."); + err << msg; return ok; } option.setValue(valueStr); @@ -196,7 +198,7 @@ bool CommandLineParser::parse(const QStringList& args) printVersion(); m_foundOptions << versionOption; } else { - out << "Invalid arguments after the version option."; + err << "Invalid arguments after the version option."; ok = false; } return ok; @@ -214,7 +216,9 @@ bool CommandLineParser::parse(const QStringList& args) } } if (!ok && !m_generalErrorMessage.isEmpty()) { - out << QStringLiteral(" %1\n").arg(m_generalErrorMessage); + err.enableMessageHeader(false); + err << m_generalErrorMessage; + err.enableMessageHeader(true); } return ok; } @@ -306,7 +310,7 @@ QString CommandLineParser::value(const CommandOption& option) const void CommandLineParser::printVersion() { - out << GlobalValues::versionInfo() << QStringLiteral("\n"); + out << GlobalValues::versionInfo(); } void CommandLineParser::printHelp(QStringList args, const Node* node) @@ -397,7 +401,7 @@ bool CommandLineParser::processIfOptionIsHelp( printHelp(args, actualNode); actualIt++; } else { - out << "Invalid arguments after the help option."; + err << "Invalid arguments after the help option."; ok = false; } } diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index de93b081..2f358cb4 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include "configwindow.h" +#include "abstractlogger.h" #include "src/config/filenameeditor.h" #include "src/config/generalconf.h" #include "src/config/shortcutswidget.h" @@ -161,7 +162,7 @@ void ConfigWindow::initErrorIndicator(QWidget* tab, QWidget* widget) connect(btnShowErrors, &QPushButton::clicked, this, [this]() { // Generate error log message QString str; - QTextStream stream(&str); + AbstractLogger stream(str, AbstractLogger::Error); ConfigHandler().checkForErrors(&stream); // Set up dialog diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 487d8973..8b232c51 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -8,6 +8,7 @@ #include "external/QHotkey/QHotkey" #endif +#include "abstractlogger.h" #include "pinwidget.h" #include "screenshotsaver.h" #include "src/config/configwindow.h" @@ -18,14 +19,12 @@ #include "src/utils/globalvalues.h" #include "src/utils/history.h" #include "src/utils/screengrabber.h" -#include "src/utils/systemnotification.h" #include "src/widgets/capture/capturetoolbutton.h" #include "src/widgets/capture/capturewidget.h" #include "src/widgets/capturelauncher.h" #include "src/widgets/historywidget.h" #include "src/widgets/imguploaddialog.h" #include "src/widgets/infowindow.h" -#include "src/widgets/notificationwidget.h" #include #include #include @@ -604,8 +603,8 @@ void Controller::exportCapture(QPixmap capture, if (tasks & CR::PIN) { FlameshotDaemon::createPin(capture, selection); if (mode == CR::SCREEN_MODE || mode == CR::FULLSCREEN_MODE) { - SystemNotification().sendMessage( - QObject::tr("Full screen screenshot pinned to screen")); + AbstractLogger::info() + << QObject::tr("Full screen screenshot pinned to screen"); } } @@ -626,9 +625,8 @@ void Controller::exportCapture(QPixmap capture, widget, &ImgUploaderBase::uploadOk, [=](const QUrl& url) { if (ConfigHandler().copyAndCloseAfterUpload()) { if (!(tasks & CR::COPY)) { - SystemNotification().sendMessage( - QObject::tr("URL copied to clipboard.")); - + AbstractLogger::info() + << QObject::tr("URL copied to clipboard."); QApplication::clipboard()->setText(url.toString()); widget->close(); } else { diff --git a/src/core/flameshotdaemon.cpp b/src/core/flameshotdaemon.cpp index ba66210c..47f38dfc 100644 --- a/src/core/flameshotdaemon.cpp +++ b/src/core/flameshotdaemon.cpp @@ -1,10 +1,10 @@ #include "flameshotdaemon.h" +#include "abstractlogger.h" #include "confighandler.h" #include "controller.h" #include "pinwidget.h" #include "screenshotsaver.h" -#include "systemnotification.h" #include #include #include @@ -228,7 +228,7 @@ void FlameshotDaemon::attachTextToClipboard(QString text, QString notification) m_clipboardSignalBlocked = true; clipboard->setText(text); if (!notification.isEmpty()) { - SystemNotification().sendMessage(notification); + AbstractLogger::info() << notification; } clipboard->blockSignals(false); } @@ -246,7 +246,7 @@ QDBusMessage FlameshotDaemon::createMethodCall(QString method) void FlameshotDaemon::checkDBusConnection(const QDBusConnection& connection) { if (!connection.isConnected()) { - SystemNotification().sendMessage(tr("Unable to connect via DBus")); + AbstractLogger::error() << tr("Unable to connect via DBus"); qApp->exit(1); } } diff --git a/src/main.cpp b/src/main.cpp index ec4fd0f1..e1117961 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include "QtSolutions/qtsingleapplication.h" #endif +#include "abstractlogger.h" #include "src/cli/commandlineparser.h" #include "src/config/styleoverride.h" #include "src/core/capturerequest.h" @@ -15,7 +16,6 @@ #include "src/utils/confighandler.h" #include "src/utils/filenamehandler.h" #include "src/utils/pathinfo.h" -#include "src/utils/systemnotification.h" #include "src/utils/valuehandler.h" #include #include @@ -28,6 +28,7 @@ #include "spdlog/spdlog.h" #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) +#include "abstractlogger.h" #include "src/core/flameshotdbusadapter.h" #include #include @@ -59,9 +60,7 @@ void requestCaptureAndWait(const CaptureRequest& req) } }); QObject::connect(controller, &Controller::captureFailed, []() { - // TODO use abstract logger - // TODO do we have to do more stuff here? - QTextStream(stderr) << "screenshot aborted\n"; + AbstractLogger::info() << "Screenshot aborted."; qApp->exit(1); }); qApp->exec(); @@ -137,8 +136,8 @@ int main(int argc, char* argv[]) new FlameshotDBusAdapter(c); QDBusConnection dbus = QDBusConnection::sessionBus(); if (!dbus.isConnected()) { - SystemNotification().sendMessage( - QObject::tr("Unable to connect via DBus")); + AbstractLogger::error() + << QObject::tr("Unable to connect via DBus"); } dbus.registerObject(QStringLiteral("/"), c); dbus.registerService(QStringLiteral("org.flameshot.Flameshot")); @@ -240,14 +239,15 @@ int main(int argc, char* argv[]) "You may need to escape the '#' sign as in '\\#FFF'"); const QString delayErr = - QObject::tr("Invalid delay, it must be higher than 0"); + QObject::tr("Invalid delay, it must be a number greater than 0"); const QString numberErr = QObject::tr("Invalid screen number, it must be non negative"); const QString regionErr = QObject::tr( "Invalid region, use 'WxH+X+Y' or 'all' or 'screen0/screen1/...'."); auto numericChecker = [](const QString& delayValue) -> bool { - int value = delayValue.toInt(); - return value >= 0; + bool ok; + int value = delayValue.toInt(&ok); + return ok && value >= 0; }; auto regionChecker = [](const QString& region) -> bool { Region valueHandler; @@ -262,8 +262,7 @@ int main(int argc, char* argv[]) if (fileInfo.isDir() || fileInfo.dir().exists()) { return true; } else { - SystemNotification().sendMessage( - QObject::tr(pathErr.toLatin1().data())); + AbstractLogger::error() << QObject::tr(pathErr.toLatin1().data()); return false; } }; @@ -500,7 +499,7 @@ int main(int argc, char* argv[]) bool someFlagSet = (filename || tray || mainColor || contrastColor || check); if (check) { - QTextStream err(stderr); + AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr); bool ok = ConfigHandler(true).checkForErrors(&err); if (ok) { err << QStringLiteral("No errors detected.\n"); diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index dae6ca46..1f787674 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,7 +1,8 @@ # Required to generate MOC target_sources( flameshot - PRIVATE filenamehandler.h + PRIVATE abstractlogger.h + filenamehandler.h screengrabber.h systemnotification.h valuehandler.h @@ -11,7 +12,8 @@ target_sources( target_sources( flameshot - PRIVATE filenamehandler.cpp + PRIVATE abstractlogger.cpp + filenamehandler.cpp screengrabber.cpp confighandler.cpp systemnotification.cpp diff --git a/src/utils/abstractlogger.cpp b/src/utils/abstractlogger.cpp new file mode 100644 index 00000000..57382ec3 --- /dev/null +++ b/src/utils/abstractlogger.cpp @@ -0,0 +1,132 @@ +#include "abstractlogger.h" +#include "systemnotification.h" +#include + +#include + +AbstractLogger::AbstractLogger(Channel channel, int targets) + : m_defaultChannel(channel) + , m_targets(targets) +{ + if (targets & LogFile) { + // TODO + } +} + +/** + * @brief Construct an AbstractLogger with output to a string. + * @param additionalChannels Optional additional targets to output to. + */ +AbstractLogger::AbstractLogger(QString& str, + Channel channel, + int additionalChannels) + : AbstractLogger(channel, additionalChannels) +{ + m_textStreams << new QTextStream(&str); +} + +AbstractLogger::~AbstractLogger() +{ + qDeleteAll(m_textStreams); +} + +AbstractLogger AbstractLogger::info(int targets) +{ + return AbstractLogger(Info, targets); +} + +AbstractLogger AbstractLogger::warning(int targets) +{ + return AbstractLogger(Warning, targets); +} + +AbstractLogger AbstractLogger::error(int targets) +{ + return AbstractLogger(Error, targets); +} + +AbstractLogger& AbstractLogger::sendMessage(QString msg, Channel channel) +{ + if (m_targets & Notification) { + SystemNotification().sendMessage( + msg, messageHeader(channel, Notification), m_notificationPath); + } + if (!m_textStreams.isEmpty()) { + foreach (auto* stream, m_textStreams) { + *stream << messageHeader(channel, String) << msg << "\n"; + } + } + if (m_targets & LogFile) { + // TODO + } + if (m_targets & Stderr) { + QTextStream stream(stderr); + stream << messageHeader(channel, Stderr) << msg << "\n"; + } + return *this; +} + +/** + * @brief Send a message to the default channel of this logger. + * @param msg + * @return + */ +AbstractLogger& AbstractLogger::operator<<(QString msg) +{ + sendMessage(msg, m_defaultChannel); + return *this; +} + +AbstractLogger& AbstractLogger::addOutputString(QString& str) +{ + m_textStreams << new QTextStream(&str); + return *this; +} + +/** + * @brief Attach a path to a notification so it can be dragged and dropped. + */ +AbstractLogger& AbstractLogger::attachNotificationPath(QString path) +{ + if (m_targets & Notification) { + m_notificationPath = path; + } else { + assert("Cannot attach notification path to a logger without a " + "notification channel."); + } + return *this; +} + +/** + * @brief Enable/disable message header (e.g. "flameshot: info:"). + */ +AbstractLogger& AbstractLogger::enableMessageHeader(bool enable) +{ + m_enableMessageHeader = enable; + return *this; +} + +/** + * @brief Generate a message header for the given channel and target. + */ +QString AbstractLogger::messageHeader(Channel channel, Target target) +{ + if (!m_enableMessageHeader) { + return ""; + } + QString messageChannel; + if (channel == Info) { + messageChannel = "info"; + } else if (channel == Warning) { + messageChannel = "warning"; + } else if (channel == Error) { + messageChannel = "error"; + } + + if (target == Notification) { + messageChannel[0] = messageChannel[0].toUpper(); + return "Flameshot " + messageChannel; + } else { + return "flameshot: " + messageChannel + ": "; + } +} diff --git a/src/utils/abstractlogger.h b/src/utils/abstractlogger.h new file mode 100644 index 00000000..7e787cdf --- /dev/null +++ b/src/utils/abstractlogger.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include + +/** + * @brief A class that allows you to log events to where they need to go. + */ +class AbstractLogger +{ +public: + enum Target + { + Notification = 0x01, + Stderr = 0x02, + LogFile = 0x08, + String = 0x10, + Default = Notification | LogFile | Stderr, + }; + + enum Channel + { + Info, + Warning, + Error + }; + + AbstractLogger(Channel channel = Info, int targets = Default); + AbstractLogger(QString& str, + Channel channel, + int additionalTargets = String); + ~AbstractLogger(); + + // Convenience functions + static AbstractLogger info(int targets = Default); + static AbstractLogger warning(int targets = Default); + static AbstractLogger error(int targets = Default); + + AbstractLogger& sendMessage(QString msg, Channel channel); + AbstractLogger& operator<<(QString msg); + AbstractLogger& addOutputString(QString& str); + AbstractLogger& attachNotificationPath(QString path); + AbstractLogger& enableMessageHeader(bool enable); + +private: + QString messageHeader(Channel type, Target channel); + + int m_targets; + Channel m_defaultChannel; + QList m_textStreams; + QString m_notificationPath; + bool m_enableMessageHeader = true; +}; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index e3befa14..843235e2 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -2,8 +2,8 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include "confighandler.h" +#include "abstractlogger.h" #include "src/tools/capturetool.h" -#include "systemnotification.h" #include "valuehandler.h" #include #include @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -510,7 +509,7 @@ QSet ConfigHandler::keysFromGroup(const QString& group) const // ERROR HANDLING -bool ConfigHandler::checkForErrors(QTextStream* log) const +bool ConfigHandler::checkForErrors(AbstractLogger* log) const { return checkUnrecognizedSettings(log) & checkShortcutConflicts(log) & checkSemantics(log); @@ -538,7 +537,7 @@ void ConfigHandler::cleanUnusedKeys(const QString& group, * `recognizedGeneralOptions` or `recognizedShortcutNames` depending on the * group the option belongs to. */ -bool ConfigHandler::checkUnrecognizedSettings(QTextStream* log) const +bool ConfigHandler::checkUnrecognizedSettings(AbstractLogger* log) const { // sort the config keys by group QSet generalKeys = keysFromGroup(CONFIG_GROUP_GENERAL), @@ -595,7 +594,7 @@ bool ConfigHandler::checkUnrecognizedSettings(QTextStream* log) const * is the flameshot default (not because the user explicitly configured it), and * action B uses the same shortcut. */ -bool ConfigHandler::checkShortcutConflicts(QTextStream* log) const +bool ConfigHandler::checkShortcutConflicts(AbstractLogger* log) const { bool ok = true; m_settings.beginGroup(CONFIG_GROUP_SHORTCUTS); @@ -637,7 +636,7 @@ bool ConfigHandler::checkShortcutConflicts(QTextStream* log) const * @brief Check each config value semantically. * @return Whether the config passes this check. */ -bool ConfigHandler::checkSemantics(QTextStream* log) const +bool ConfigHandler::checkSemantics(AbstractLogger* log) const { QStringList allKeys = m_settings.allKeys(); bool ok = true; @@ -698,12 +697,12 @@ void ConfigHandler::setErrorState(bool error) const // Notify user every time m_hasError changes if (!hadError && m_hasError) { QString msg = errorMessage(); - SystemNotification().sendMessage(msg); + AbstractLogger::error() << msg; emit getInstance()->error(); } else if (hadError && !m_hasError) { auto msg = tr("You have successfully resolved the configuration error."); - SystemNotification().sendMessage(msg); + AbstractLogger::info() << msg; emit getInstance()->errorResolved(); } } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index cca5c492..0f9bf681 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -17,6 +17,7 @@ class ValueHandler; template class QSharedPointer; class QTextStream; +class AbstractLogger; /** * Declare and implement a getter for a config option. `KEY` is the option key @@ -141,10 +142,10 @@ public: QSet keysFromGroup(const QString& group) const; // ERROR HANDLING - bool checkForErrors(QTextStream* log = nullptr) const; - bool checkUnrecognizedSettings(QTextStream* log = nullptr) const; - bool checkShortcutConflicts(QTextStream* log = nullptr) const; - bool checkSemantics(QTextStream* log = nullptr) const; + bool checkForErrors(AbstractLogger* log = nullptr) const; + bool checkUnrecognizedSettings(AbstractLogger* log = nullptr) const; + bool checkShortcutConflicts(AbstractLogger* log = nullptr) const; + bool checkSemantics(AbstractLogger* log = nullptr) const; void checkAndHandleError() const; void setErrorState(bool error) const; bool hasError() const; diff --git a/src/utils/screengrabber.cpp b/src/utils/screengrabber.cpp index c870b47a..92b666fa 100644 --- a/src/utils/screengrabber.cpp +++ b/src/utils/screengrabber.cpp @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include "screengrabber.h" +#include "abstractlogger.h" #include "src/core/qguiappcurrentscreen.h" #include "src/utils/filenamehandler.h" #include "src/utils/systemnotification.h" @@ -124,7 +125,7 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok) break; } if (!ok) { - SystemNotification().sendMessage(tr("Unable to capture screen")); + AbstractLogger::error() << tr("Unable to capture screen"); } return res; } diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index b17f5c53..675242e1 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -2,12 +2,12 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include "screenshotsaver.h" +#include "abstractlogger.h" #include "src/core/controller.h" #include "src/core/flameshotdaemon.h" #include "src/utils/confighandler.h" #include "src/utils/filenamehandler.h" #include "src/utils/globalvalues.h" -#include "src/utils/systemnotification.h" #include "utils/desktopinfo.h" #include #include @@ -43,8 +43,8 @@ void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture, mimeData->setData("image/" + imageType, array); QApplication::clipboard()->setMimeData(mimeData); } else { - SystemNotification().sendMessage( - QObject::tr("Error while saving to clipboard")); + AbstractLogger::error() + << QObject::tr("Error while saving to clipboard"); } } @@ -60,8 +60,7 @@ void ScreenshotSaver::saveToClipboard(const QPixmap& capture) ConfigHandler().savePath(), QObject::tr("Capture saved to clipboard.")); } else { - SystemNotification().sendMessage( - QObject::tr("Capture saved to clipboard.")); + AbstractLogger() << QObject::tr("Capture saved to clipboard."); } if (ConfigHandler().useJpgForClipboard()) { // FIXME - it doesn't work on MacOS @@ -97,15 +96,18 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap& capture, if (ok) { saveMessage += QObject::tr("Capture saved as ") + completePath; + AbstractLogger::info().attachNotificationPath(notificationPath) + << saveMessage; } else { saveMessage += QObject::tr("Error trying to save as ") + completePath; if (file.error() != QFile::NoError) { saveMessage += ": " + file.errorString(); } notificationPath = ""; + AbstractLogger::error().attachNotificationPath(notificationPath) + << saveMessage; } - SystemNotification().sendMessage(saveMessage, notificationPath); return ok; } @@ -185,7 +187,7 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap& capture) ConfigHandler().setSavePath(pathNoFile); QString msg = QObject::tr("Capture saved as ") + savePath; - SystemNotification().sendMessage(msg, savePath); + AbstractLogger().attachNotificationPath(savePath) << msg; if (config.copyPathAfterSave()) { FlameshotDaemon::copyToClipboard( diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index ede1f1eb..b45422fd 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -10,6 +10,7 @@ // #include "capturewidget.h" +#include "abstractlogger.h" #include "copytool.h" #include "src/core/controller.h" #include "src/core/qguiappcurrentscreen.h" @@ -100,7 +101,7 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req, bool ok = true; m_context.screenshot = ScreenGrabber().grabEntireDesktop(ok); if (!ok) { - SystemNotification().sendMessage(tr("Unable to capture screen")); + AbstractLogger::error() << tr("Unable to capture screen"); this->close(); } m_context.origScreenshot = m_context.screenshot;