Changeset View
Changeset View
Standalone View
Standalone View
src/main.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include <QQmlEngine> | 21 | #include <QQmlEngine> | ||
22 | #include <QQmlContext> | 22 | #include <QQmlContext> | ||
23 | #include <QQmlComponent> | 23 | #include <QQmlComponent> | ||
24 | 24 | | |||
25 | #include <QStandardPaths> | 25 | #include <QStandardPaths> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <QThread> | 27 | #include <QThread> | ||
28 | #include <QDir> | ||||
28 | 29 | | |||
29 | #include <KDBusService> | 30 | #include <KDBusService> | ||
30 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
31 | #include <KLocalizedContext> | 32 | #include <KLocalizedContext> | ||
32 | 33 | | |||
33 | #include <QApplication> | 34 | #include <QApplication> | ||
34 | #include <QCommandLineParser> | 35 | #include <QCommandLineParser> | ||
35 | #include <QCommandLineOption> | 36 | #include <QCommandLineOption> | ||
Show All 20 Lines | 47 | { | |||
56 | parser.addHelpOption(); | 57 | parser.addHelpOption(); | ||
57 | parser.process(app); | 58 | parser.process(app); | ||
58 | 59 | | |||
59 | if (parser.positionalArguments().size() > 1) { | 60 | if (parser.positionalArguments().size() > 1) { | ||
60 | parser.showHelp(1); | 61 | parser.showHelp(1); | ||
61 | } | 62 | } | ||
62 | 63 | | |||
63 | if (parser.isSet("reset")) { | 64 | if (parser.isSet("reset")) { | ||
64 | KokoConfig config; | 65 | KokoConfig config; | ||
mart: you are still accessing positionalArguments().first() without checking it exists, this will… | |||||
65 | config.reset(); | 66 | config.reset(); | ||
66 | 67 | | |||
67 | ImageStorage::reset(); | 68 | ImageStorage::reset(); | ||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | QThread trackerThread; | 71 | QThread trackerThread; | ||
71 | 72 | | |||
72 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | 73 | QStringList locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); | ||
73 | Q_ASSERT(locations.size() >= 1); | 74 | Q_ASSERT(locations.size() >= 1); | ||
74 | qDebug() << locations; | 75 | qDebug() << locations; | ||
75 | 76 | | |||
77 | QUrl currentDirPath = QUrl::fromLocalFile(QDir::currentPath().append('/')); | ||||
78 | QUrl resolvedImagePath = parser.positionalArguments().isEmpty() | ||||
79 | ? QUrl(locations.first().append('/')) | ||||
80 | : currentDirPath.resolved( parser.positionalArguments().first()); | ||||
81 | | ||||
76 | FileSystemTracker tracker; | 82 | FileSystemTracker tracker; | ||
77 | tracker.setFolder(locations.first()); | 83 | tracker.setFolder(locations.first()); | ||
78 | tracker.moveToThread(&trackerThread); | 84 | tracker.moveToThread(&trackerThread); | ||
79 | 85 | | |||
80 | Koko::Processor processor; | 86 | Koko::Processor processor; | ||
81 | QObject::connect(&tracker, &FileSystemTracker::imageAdded, &processor, &Koko::Processor::addFile); | 87 | QObject::connect(&tracker, &FileSystemTracker::imageAdded, &processor, &Koko::Processor::addFile); | ||
82 | QObject::connect(&tracker, &FileSystemTracker::imageRemoved, &processor, &Koko::Processor::removeFile); | 88 | QObject::connect(&tracker, &FileSystemTracker::imageRemoved, &processor, &Koko::Processor::removeFile); | ||
83 | QObject::connect(&tracker, &FileSystemTracker::initialScanComplete, &processor, &Koko::Processor::initialScanCompleted); | 89 | QObject::connect(&tracker, &FileSystemTracker::initialScanComplete, &processor, &Koko::Processor::initialScanCompleted); | ||
84 | 90 | | |||
85 | trackerThread.start(); | 91 | trackerThread.start(); | ||
86 | tracker.setSubFolder(tracker.folder()); | 92 | tracker.setSubFolder(tracker.folder()); | ||
87 | 93 | | |||
88 | KokoConfig config; | 94 | KokoConfig config; | ||
89 | 95 | | |||
90 | QQmlEngine engine; | 96 | QQmlEngine engine; | ||
91 | QQmlContext* objectContext = engine.rootContext(); | 97 | QQmlContext* objectContext = engine.rootContext(); | ||
92 | objectContext->setContextProperty("kokoProcessor", &processor); | 98 | objectContext->setContextProperty("kokoProcessor", &processor); | ||
93 | objectContext->setContextProperty("kokoConfig", &config); | 99 | objectContext->setContextProperty("kokoConfig", &config); | ||
94 | objectContext->setContextProperty("imagePathArgument", parser.positionalArguments().isEmpty() ? QString() : parser.positionalArguments().first()); | 100 | objectContext->setContextProperty("imagePathArgument", resolvedImagePath.toString()); | ||
the check on positionalarguments is useless here now, as you access it before and not here mart: the check on positionalarguments is useless here now, as you access it before and not here | |||||
95 | 101 | | |||
96 | QString path; | 102 | QString path; | ||
97 | //we want different main files on desktop or mobile | 103 | //we want different main files on desktop or mobile | ||
98 | //very small difference as they as they are subclasses of the same thing | 104 | //very small difference as they as they are subclasses of the same thing | ||
99 | if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE") && | 105 | if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE") && | ||
100 | (QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("1") || | 106 | (QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("1") || | ||
101 | QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("true"))) { | 107 | QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_MOBILE")) == QStringLiteral("true"))) { | ||
102 | path = QStandardPaths::locate(QStandardPaths::DataLocation, "ui/mobileMain.qml"); | 108 | path = QStandardPaths::locate(QStandardPaths::DataLocation, "ui/mobileMain.qml"); | ||
Show All 21 Lines |
you are still accessing positionalArguments().first() without checking it exists, this will crash