-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathmain.cpp
More file actions
695 lines (646 loc) · 25.1 KB
/
main.cpp
File metadata and controls
695 lines (646 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#ifdef USE_KDSINGLEAPPLICATION
#include <kdsingleapplication.h>
#ifdef Q_OS_UNIX
#include "core/signaldaemon.h"
#include "csignal"
#endif
#endif
#include "abstractlogger.h"
#include "src/cli/commandlineparser.h"
#include "src/config/cacheutils.h"
#include "src/config/styleoverride.h"
#include "src/core/capturerequest.h"
#include "src/core/flameshot.h"
#include "src/core/flameshotdaemon.h"
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/pathinfo.h"
#include "src/utils/valuehandler.h"
#include <QApplication>
#include <QDir>
#include <QLibraryInfo>
#include <QSharedMemory>
#include <QTimer>
#include <QTranslator>
#if !(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
#include "src/core/flameshotdbusadapter.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <desktopinfo.h>
#endif
// Required for saving button list QList<CaptureTool::Type>
Q_DECLARE_METATYPE(QList<int>)
#if defined(USE_KDSINGLEAPPLICATION) && defined(Q_OS_UNIX)
static int setup_unix_signal_handlers()
{
struct sigaction sint, term;
sint.sa_handler = SignalDaemon::intSignalHandler;
sigemptyset(&sint.sa_mask);
sint.sa_flags = 0;
sint.sa_flags |= SA_RESTART;
if (sigaction(SIGINT, &sint, 0))
return 1;
term.sa_handler = SignalDaemon::termSignalHandler;
sigemptyset(&term.sa_mask);
term.sa_flags = 0;
term.sa_flags |= SA_RESTART;
if (sigaction(SIGTERM, &term, 0))
return 2;
return 0;
}
#endif
int requestCaptureAndWait(const CaptureRequest& req)
{
Flameshot* flameshot = Flameshot::instance();
flameshot->requestCapture(req);
QObject::connect(flameshot, &Flameshot::captureTaken, [&](const QPixmap&) {
#if defined(Q_OS_MACOS)
// Only useful on MacOS because each instance hosts its own widgets
if (!FlameshotDaemon::isThisInstanceHostingWidgets()) {
qApp->exit(0);
}
#else
// if this instance is not daemon, make sure it exit after caputre finish
if (FlameshotDaemon::instance() == nullptr && !Flameshot::instance()->haveExternalWidget()) {
qApp->exit(E_OK);
}
#endif
});
QObject::connect(flameshot, &Flameshot::captureFailed, []() {
AbstractLogger::Target logTarget = static_cast<AbstractLogger::Target>(
ConfigHandler().showAbortNotification()
? AbstractLogger::Target::Default
: AbstractLogger::Target::Default &
~AbstractLogger::Target::Notification);
AbstractLogger::info(logTarget) << "Screenshot aborted.";
qApp->exit(E_ABORTED);
});
return qApp->exec();
}
QSharedMemory* guiMutexLock()
{
QString key = "org.flameshot.Flameshot-" APP_VERSION;
auto* shm = new QSharedMemory(key);
#ifdef Q_OS_UNIX
// Destroy shared memory if the last instance crashed on Unix
shm->attach();
delete shm;
shm = new QSharedMemory(key);
#endif
if (!shm->create(1)) {
delete shm;
return nullptr;
}
return shm;
}
void configureTranslation(QTranslator& translator, QTranslator& qtTranslator)
{
bool foundTranslation;
// Configure translations
for (const QString& path : PathInfo::translationsPaths()) {
if (ConfigHandler().uiLanguage() == QStringLiteral("auto")) {
// Load language, which was detected from the system
foundTranslation =
translator.load(QLocale(),
QStringLiteral("Internationalization"),
QStringLiteral("_"),
path);
} else {
// Load language from settings
foundTranslation =
translator.load(QStringLiteral("Internationalization_") +
ConfigHandler().uiLanguage(),
path);
}
if (foundTranslation) {
break;
}
}
if (!foundTranslation) {
if (ConfigHandler().uiLanguage() == QStringLiteral("auto")) {
QLocale l;
qWarning() << QStringLiteral(
"No Flameshot translation found for %1")
.arg(l.uiLanguages().join(", "));
} else {
qWarning() << QStringLiteral(
"No Flameshot translation found for %1")
.arg(ConfigHandler().uiLanguage());
}
}
if (ConfigHandler().uiLanguage() == QStringLiteral("auto")) {
foundTranslation =
qtTranslator.load(QLocale::system(),
"qt",
"_",
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
} else {
foundTranslation = qtTranslator.load(
QStringLiteral("qt_") + ConfigHandler().uiLanguage(),
QLibraryInfo::path(QLibraryInfo::TranslationsPath));
}
if (!foundTranslation) {
if (ConfigHandler().uiLanguage() == QStringLiteral("auto")) {
qWarning() << QStringLiteral("No Qt translation found for %1")
.arg(QLocale::languageToString(
QLocale::system().language()));
} else {
qWarning() << QStringLiteral("No Qt translation found for %1")
.arg(ConfigHandler().uiLanguage());
}
}
qApp->installTranslator(&translator);
qApp->installTranslator(&qtTranslator);
}
void configureApp(bool gui, QTranslator& translator, QTranslator& qtTranslator)
{
if (gui) {
#if defined(Q_OS_WIN) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
QApplication::setStyle("Fusion"); // Supports dark scheme on Win 10/11
#else
QApplication::setStyle(new StyleOverride);
#endif
}
auto app = QCoreApplication::instance();
app->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
configureTranslation(translator, qtTranslator);
}
// TODO find a way so we don't have to do this
/// Recreate the application as a QApplication
void reinitializeAsQApplication(int& argc,
char* argv[],
QTranslator& translator,
QTranslator& qtTranslator)
{
delete QCoreApplication::instance();
new QApplication(argc, argv);
configureApp(true, translator, qtTranslator);
}
int main(int argc, char* argv[])
{
QTranslator translator, qtTranslator;
// Required for saving button list QList<CaptureTool::Type>
qRegisterMetaType<QList<int>>();
QCoreApplication::setApplicationVersion(APP_VERSION);
QCoreApplication::setApplicationName(QStringLiteral("flameshot"));
QCoreApplication::setOrganizationName(QStringLiteral("flameshot"));
// no arguments, just launch Flameshot
if (argc == 1) {
QApplication app(argc, argv);
configureTranslation(translator, qtTranslator);
#ifdef USE_KDSINGLEAPPLICATION
#ifdef Q_OS_UNIX
setup_unix_signal_handlers();
auto signalDaemon = SignalDaemon();
#endif
auto kdsa =
KDSingleApplication(QStringLiteral("org.flameshot.Flameshot"));
if (!kdsa.isPrimaryInstance()) {
return 0; // Quit
}
#endif
configureApp(true, translator, qtTranslator);
auto c = Flameshot::instance();
FlameshotDaemon::start();
#if defined(USE_KDSINGLEAPPLICATION) && \
(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
if (kdsa.isPrimaryInstance()) {
QObject::connect(
&kdsa,
&KDSingleApplication::messageReceived,
FlameshotDaemon::instance(),
&FlameshotDaemon::messageReceivedFromSecondaryInstance);
}
#endif
#if !(defined(Q_OS_MACOS) || defined(Q_OS_WIN))
new FlameshotDBusAdapter(c);
QDBusConnection dbus = QDBusConnection::sessionBus();
if (!dbus.isConnected()) {
AbstractLogger::error()
<< QObject::tr("Unable to connect via DBus");
}
dbus.registerObject(QStringLiteral("/"), c);
dbus.registerService(QStringLiteral("org.flameshot.Flameshot"));
#endif
return qApp->exec();
}
/*--------------|
* CLI parsing |
* ------------*/
new QCoreApplication(argc, argv);
configureApp(false, translator, qtTranslator);
CommandLineParser parser;
// Add description
parser.setDescription(
QObject::tr("Powerful yet simple to use screenshot software."));
parser.setGeneralErrorMessage(QObject::tr("See") + " flameshot --help.");
// Arguments
CommandArgument fullArgument(
QStringLiteral("full"),
QObject::tr("Capture screenshot of all monitors at the same time."));
CommandArgument launcherArgument(QStringLiteral("launcher"),
QObject::tr("Open the capture launcher."));
CommandArgument guiArgument(
QStringLiteral("gui"),
QObject::tr("Start a manual capture in GUI mode."));
CommandArgument configArgument(QStringLiteral("config"),
QObject::tr("Configure") + " flameshot.");
CommandArgument screenArgument(
QStringLiteral("screen"),
QObject::tr("Capture a screenshot of the specified monitor."));
// Options
CommandOption pathOption(
{ "p", "path" },
QObject::tr("Existing directory or new file to save to"),
QStringLiteral("path"));
CommandOption clipboardOption(
{ "c", "clipboard" }, QObject::tr("Save the capture to the clipboard"));
CommandOption pinOption("pin",
QObject::tr("Pin the capture to the screen"));
CommandOption uploadOption({ "u", "upload" },
QObject::tr("Upload screenshot"));
CommandOption delayOption({ "d", "delay" },
QObject::tr("Delay time in milliseconds"),
QStringLiteral("milliseconds"));
CommandOption useLastRegionOption(
"last-region",
QObject::tr("Repeat screenshot with previously selected region"));
CommandOption regionOption("region",
QObject::tr("Screenshot region to select"),
QStringLiteral("WxH+X+Y or string"));
CommandOption filenameOption({ "f", "filename" },
QObject::tr("Set the filename pattern"),
QStringLiteral("pattern"));
CommandOption acceptOnSelectOption(
{ "s", "accept-on-select" },
QObject::tr("Accept capture as soon as a selection is made"));
CommandOption trayOption({ "t", "trayicon" },
QObject::tr("Enable or disable the trayicon"),
QStringLiteral("bool"));
CommandOption autostartOption(
{ "a", "autostart" },
QObject::tr("Enable or disable run at startup"),
QStringLiteral("bool"));
CommandOption notificationOption(
{ "n", "notifications" },
QObject::tr("Enable or disable the notifications"),
QStringLiteral("bool"));
CommandOption checkOption(
"check", QObject::tr("Check the configuration for errors"));
CommandOption showHelpOption(
{ "s", "showhelp" },
QObject::tr("Show the help message in the capture mode"),
QStringLiteral("bool"));
CommandOption mainColorOption({ "m", "maincolor" },
QObject::tr("Define the main UI color"),
QStringLiteral("color-code"));
CommandOption contrastColorOption(
{ "k", "contrastcolor" },
QObject::tr("Define the contrast UI color"),
QStringLiteral("color-code"));
CommandOption rawImageOption({ "r", "raw" },
QObject::tr("Print raw PNG capture"));
CommandOption selectionOption(
{ "g", "print-geometry" },
QObject::tr("Print geometry of the selection in the format WxH+X+Y. Does "
"nothing if raw is specified"));
CommandOption screenNumberOption(
{ "n", "number" },
QObject::tr("Define the screen to capture (starting from 0)") + ",\n" +
QObject::tr("default: screen containing the cursor"),
QObject::tr("Screen number"),
QStringLiteral("-1"));
// Add checkers
auto colorChecker = [](const QString& colorCode) -> bool {
QColor parsedColor(colorCode);
return parsedColor.isValid() && parsedColor.alphaF() == 1.0;
};
QString colorErr =
QObject::tr("Invalid color, "
"this flag supports the following formats:\n"
"- #RGB (each of R, G, and B is a single hex digit)\n"
"- #RRGGBB\n- #RRRGGGBBB\n"
"- #RRRRGGGGBBBB\n"
"- Named colors like 'blue' or 'red'\n"
"You may need to escape the '#' sign as in '\\#FFF'");
const QString delayErr =
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 {
bool ok;
int value = delayValue.toInt(&ok);
return ok && value >= 0;
};
auto regionChecker = [](const QString& region) -> bool {
Region valueHandler;
return valueHandler.check(region);
};
const QString pathErr =
QObject::tr("Invalid path, must be an existing directory or a new file "
"in an existing directory");
auto pathChecker = [pathErr](const QString& pathValue) -> bool {
QFileInfo fileInfo(pathValue);
if (fileInfo.isDir() || fileInfo.dir().exists()) {
return true;
} else {
AbstractLogger::error() << QObject::tr(pathErr.toLatin1().data());
return false;
}
};
const QString booleanErr =
QObject::tr("Invalid value, it must be defined as 'true' or 'false'");
auto booleanChecker = [](const QString& value) -> bool {
return value == QLatin1String("true") ||
value == QLatin1String("false");
};
contrastColorOption.addChecker(colorChecker, colorErr);
mainColorOption.addChecker(colorChecker, colorErr);
delayOption.addChecker(numericChecker, delayErr);
regionOption.addChecker(regionChecker, regionErr);
useLastRegionOption.addChecker(booleanChecker, booleanErr);
pathOption.addChecker(pathChecker, pathErr);
trayOption.addChecker(booleanChecker, booleanErr);
autostartOption.addChecker(booleanChecker, booleanErr);
notificationOption.addChecker(booleanChecker, booleanErr);
showHelpOption.addChecker(booleanChecker, booleanErr);
screenNumberOption.addChecker(numericChecker, numberErr);
// Relationships
parser.AddArgument(guiArgument);
parser.AddArgument(screenArgument);
parser.AddArgument(fullArgument);
parser.AddArgument(launcherArgument);
parser.AddArgument(configArgument);
auto helpOption = parser.addHelpOption();
auto versionOption = parser.addVersionOption();
parser.AddOptions({ pathOption,
clipboardOption,
delayOption,
regionOption,
useLastRegionOption,
rawImageOption,
selectionOption,
uploadOption,
pinOption,
acceptOnSelectOption },
guiArgument);
parser.AddOptions({ screenNumberOption,
clipboardOption,
pathOption,
delayOption,
regionOption,
rawImageOption,
uploadOption,
pinOption },
screenArgument);
parser.AddOptions({ pathOption,
clipboardOption,
delayOption,
regionOption,
rawImageOption,
uploadOption },
fullArgument);
parser.AddOptions({ autostartOption,
notificationOption,
filenameOption,
trayOption,
showHelpOption,
mainColorOption,
contrastColorOption,
checkOption },
configArgument);
// Parse
if (!parser.parse(qApp->arguments())) {
goto finish;
}
// PROCESS DATA
//--------------
Flameshot::setOrigin(Flameshot::CLI);
if (parser.isSet(helpOption) || parser.isSet(versionOption)) {
} else if (parser.isSet(launcherArgument)) { // LAUNCHER
reinitializeAsQApplication(argc, argv, translator, qtTranslator);
Flameshot* flameshot = Flameshot::instance();
flameshot->launcher();
qApp->exec();
} else if (parser.isSet(guiArgument)) { // GUI
reinitializeAsQApplication(argc, argv, translator, qtTranslator);
// Prevent multiple instances of 'flameshot gui' from running if not
// configured to do so.
if (!ConfigHandler().allowMultipleGuiInstances()) {
auto* mutex = guiMutexLock();
if (!mutex) {
return 1;
}
QObject::connect(
qApp, &QCoreApplication::aboutToQuit, qApp, [mutex]() {
mutex->detach();
delete mutex;
});
}
// Option values
QString path = parser.value(pathOption);
if (!path.isEmpty()) {
path = QDir(path).absolutePath();
}
int delay = parser.value(delayOption).toInt();
QString region = parser.value(regionOption);
bool useLastRegion = parser.isSet(useLastRegionOption);
bool clipboard = parser.isSet(clipboardOption);
bool raw = parser.isSet(rawImageOption);
bool printGeometry = parser.isSet(selectionOption);
bool pin = parser.isSet(pinOption);
bool upload = parser.isSet(uploadOption);
bool acceptOnSelect = parser.isSet(acceptOnSelectOption);
CaptureRequest req(CaptureRequest::GRAPHICAL_MODE, delay, path);
if (!region.isEmpty()) {
auto selectionRegion = Region().value(region).toRect();
req.setInitialSelection(selectionRegion);
} else if (useLastRegion) {
req.setInitialSelection(getLastRegion());
}
if (clipboard) {
req.addTask(CaptureRequest::COPY);
}
if (raw) {
req.addTask(CaptureRequest::PRINT_RAW);
}
if (!path.isEmpty()) {
req.addSaveTask(path);
}
if (printGeometry) {
req.addTask(CaptureRequest::PRINT_GEOMETRY);
}
if (pin) {
req.addTask(CaptureRequest::PIN);
}
if (upload) {
req.addTask(CaptureRequest::UPLOAD);
}
if (acceptOnSelect) {
req.addTask(CaptureRequest::ACCEPT_ON_SELECT);
if (!clipboard && !raw && path.isEmpty() && !printGeometry &&
!pin && !upload) {
req.addSaveTask();
}
}
int guiExitCode = requestCaptureAndWait(req);
delete qApp;
return guiExitCode;
} else if (parser.isSet(fullArgument)) { // FULL
reinitializeAsQApplication(argc, argv, translator, qtTranslator);
// Option values
QString path = parser.value(pathOption);
if (!path.isEmpty()) {
path = QDir(path).absolutePath();
}
int delay = parser.value(delayOption).toInt();
QString region = parser.value(regionOption);
bool clipboard = parser.isSet(clipboardOption);
bool raw = parser.isSet(rawImageOption);
bool upload = parser.isSet(uploadOption);
// Not a valid command
CaptureRequest req(CaptureRequest::FULLSCREEN_MODE, delay);
if (!region.isEmpty()) {
req.setInitialSelection(Region().value(region).toRect());
}
if (clipboard) {
req.addTask(CaptureRequest::COPY);
}
if (!path.isEmpty()) {
req.addSaveTask(path);
}
if (raw) {
req.addTask(CaptureRequest::PRINT_RAW);
}
if (upload) {
req.addTask(CaptureRequest::UPLOAD);
}
if (!clipboard && path.isEmpty() && !raw && !upload) {
req.addSaveTask();
}
{
int fullExitCode = requestCaptureAndWait(req);
delete qApp;
return fullExitCode;
}
} else if (parser.isSet(screenArgument)) { // SCREEN
reinitializeAsQApplication(argc, argv, translator, qtTranslator);
QString numberStr = parser.value(screenNumberOption);
// Option values
int screenNumber =
numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt();
QString path = parser.value(pathOption);
if (!path.isEmpty()) {
path = QDir(path).absolutePath();
}
int delay = parser.value(delayOption).toInt();
QString region = parser.value(regionOption);
bool clipboard = parser.isSet(clipboardOption);
bool raw = parser.isSet(rawImageOption);
bool pin = parser.isSet(pinOption);
bool upload = parser.isSet(uploadOption);
CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, screenNumber);
if (!region.isEmpty()) {
if (region.startsWith("screen")) {
AbstractLogger::error()
<< "The 'screen' command does not support "
"'--region screen<N>'.\n"
"See flameshot --help.\n";
exit(1);
}
req.setInitialSelection(Region().value(region).toRect());
}
if (clipboard) {
req.addTask(CaptureRequest::COPY);
}
if (raw) {
req.addTask(CaptureRequest::PRINT_RAW);
}
if (!path.isEmpty()) {
req.addSaveTask(path);
}
if (pin) {
req.addTask(CaptureRequest::PIN);
}
if (upload) {
req.addTask(CaptureRequest::UPLOAD);
}
if (!clipboard && !raw && path.isEmpty() && !pin && !upload) {
req.addSaveTask();
}
{
int screenExitCode = requestCaptureAndWait(req);
delete qApp;
return screenExitCode;
}
} else if (parser.isSet(configArgument)) { // CONFIG
bool autostart = parser.isSet(autostartOption);
bool notification = parser.isSet(notificationOption);
bool filename = parser.isSet(filenameOption);
bool tray = parser.isSet(trayOption);
bool mainColor = parser.isSet(mainColorOption);
bool contrastColor = parser.isSet(contrastColorOption);
bool check = parser.isSet(checkOption);
bool someFlagSet = (autostart || notification || filename || tray ||
mainColor || contrastColor || check);
if (check) {
AbstractLogger err = AbstractLogger::error(AbstractLogger::Stderr);
bool ok = ConfigHandler().checkForErrors(&err);
if (ok) {
AbstractLogger::info()
<< QStringLiteral("No errors detected.\n");
goto finish;
} else {
return 1;
}
}
if (!someFlagSet) {
// Open gui when no options are given
reinitializeAsQApplication(argc, argv, translator, qtTranslator);
QObject::connect(
qApp, &QApplication::lastWindowClosed, qApp, &QApplication::quit);
Flameshot::instance()->config();
qApp->exec();
} else {
ConfigHandler config;
if (autostart) {
config.setStartupLaunch(parser.value(autostartOption) ==
"true");
}
if (notification) {
config.setShowDesktopNotification(
parser.value(notificationOption) == "true");
}
if (filename) {
QString newFilename(parser.value(filenameOption));
config.setFilenamePattern(newFilename);
FileNameHandler fh;
QTextStream(stdout)
<< QStringLiteral("The new pattern is '%1'\n"
"Parsed pattern example: %2\n")
.arg(newFilename, fh.parsedPattern());
}
if (tray) {
config.setDisabledTrayIcon(parser.value(trayOption) == "false");
}
if (mainColor) {
// TODO use value handler
QString colorCode = parser.value(mainColorOption);
QColor parsedColor(colorCode);
config.setUiColor(parsedColor);
}
if (contrastColor) {
QString colorCode = parser.value(contrastColorOption);
QColor parsedColor(colorCode);
config.setContrastUiColor(parsedColor);
}
}
}
finish:
delete qApp;
return 0;
}