Implement abstract logger (#2174)
* AbstractLogger base implementation Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Switch most system notifications to AbstractLogger Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make CLI parser use AbstractLogger Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix annoying QPainter warning in QtColorWidgets Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Remove obsolete TODOs Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Fix failing windows build Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Add missing #include <cassert> Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
23
src/main.cpp
23
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 <QApplication>
|
||||
#include <QDir>
|
||||
@@ -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 <QApplication>
|
||||
#include <QDBusConnection>
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user