swift
Loading...
Searching...
No Matches
main.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include <QApplication>
5#include <QCommandLineParser>
6#include <QPushButton>
7#include <QtGlobal>
8
11#include "gui/guiapplication.h"
12#include "misc/directoryutils.h"
13#include "misc/icons.h"
14#include "swiftlauncher.h"
15
16using namespace swift::gui;
17using namespace swift::misc;
18using namespace swift::core;
19using namespace swift::core::db;
20
22void initDbCacheFromResourceFileIfRequired(CGuiApplication &a)
23{
24 Q_ASSERT_X(a.hasWebDataServices(), Q_FUNC_INFO, "Requires web services");
25
26 CWebDataServices *webDataServices = a.getWebDataServices();
27
28 // caches from local files (i.e. the files delivered)
29 const QDateTime ts = webDataServices->getLatestDbEntityCacheTimestamp();
30 if (!ts.isValid() || ts < QDateTime::currentDateTimeUtc().addYears(-2))
31 {
32 webDataServices->initDbCachesFromLocalResourceFiles(false);
33 }
34}
35
36int main(int argc, char *argv[])
37{
38 QApplication qa(argc, argv); // needed
39 Q_UNUSED(qa)
41 a.addDBusAddressOption(); // required by the dbus server address selector
42 const QCommandLineOption installerOption { { "i", "installer" },
43 QCoreApplication::translate("main", "Installer setup.") };
44 a.addParserOption(installerOption);
46 {
47 return EXIT_FAILURE;
48 }
51
52 const bool installMode = a.isParserOptionSet(installerOption);
53 if (installMode) initDbCacheFromResourceFileIfRequired(a);
54
56 if (!a.start())
57 {
59 return EXIT_FAILURE;
60 }
61
62 CSwiftLauncher launcher(installMode);
63 const int res = a.exec();
64 if (res != EXIT_SUCCESS || !launcher.shouldStartAppDetached())
65 {
66 return res;
67 }
68
69 const bool s = launcher.startDetached();
70 return s ? EXIT_SUCCESS : EXIT_FAILURE;
71}
swift launcher tool
swift::misc::CStatusMessageList startCoreFacadeWithoutContexts()
Starts the core facade without any contexts.
bool isParserOptionSet(const QString &option) const
Delegates to QCommandLineParser::isSet.
swift::misc::CStatusMessageList initAndStartWebDataServices(CWebReaderFlags::WebReader webReader, const db::CDatabaseReaderConfigList &dbReaderConfig)
Init web data services and start them.
bool parseCommandLineArgsAndLoadSetup()
Combined function that does a startup check, parses the command line arguments and loads the setup.
void addDBusAddressOption()
CMD line argument for DBus address.
bool hasWebDataServices() const
Web data services available?
bool addParserOption(const QCommandLineOption &option)
virtual bool start()
Start services, if not yet parsed call CApplication::parse.
CWebDataServices * getWebDataServices() const
Get the web data services.
int exec()
Finishes initialization and executes the event loop.
Encapsulates reading data from web sources.
QDateTime getLatestDbEntityCacheTimestamp() const
Latest DB object timestamp, or null if there is no such timestamp.
swift::misc::CStatusMessageList initDbCachesFromLocalResourceFiles(bool inBackground)
Init caches from local DB files.
@ AllSwiftDbReaders
all swift data
static CDatabaseReaderConfigList forLauncher()
Init for launcher.
GUI application, a specialized version of swift::core::CApplication for GUI applications.
void gracefulShutdown()
Graceful shutdown.
static const QString & swiftLauncher()
Name of swift launcher.
static const QPixmap & swiftLauncher1024()
swift icon
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
GUI related classes.
Free functions in swift::misc.
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
QDateTime currentDateTimeUtc()
bool isValid() const const