swift
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 
10 #include "core/webdataservices.h"
11 #include "gui/guiapplication.h"
12 #include "misc/directoryutils.h"
13 #include "misc/icons.h"
14 #include "swiftlauncher.h"
15 
16 using namespace swift::gui;
17 using namespace swift::misc;
18 using namespace swift::core;
19 using namespace swift::core::db;
20 
22 void 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 
36 int main(int argc, char *argv[])
37 {
39  QApplication qa(argc, argv); // needed
40  Q_UNUSED(qa)
41  CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Launcher, CIcons::swiftLauncher1024());
42  a.addNetworkOptions(); // so it can be passed (hand over) to started applications
43  a.addDBusAddressOption(); // required by the dbus server address selector
44  const QCommandLineOption installerOption { { "i", "installer" },
45  QCoreApplication::translate("main", "Installer setup.") };
46  a.addParserOption(installerOption);
47  if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
49  CDatabaseReaderConfigList::forLauncher());
50 
51  const bool installMode = a.isParserOptionSet(installerOption);
52  if (installMode) initDbCacheFromResourceFileIfRequired(a);
53 
55  if (!a.start())
56  {
57  a.gracefulShutdown();
58  return EXIT_FAILURE;
59  }
60 
61  CSwiftLauncher launcher(installMode);
62  const int res = a.exec();
63  if (res != EXIT_SUCCESS || !launcher.shouldStartAppDetached()) { return res; }
64 
65  const bool s = launcher.startDetached();
66  return s ? EXIT_SUCCESS : EXIT_FAILURE;
67 }
swift launcher tool
Definition: swiftlauncher.h:51
swift::misc::CStatusMessageList startCoreFacadeWithoutContexts()
Starts the core facade without any contexts.
void addNetworkOptions()
Add the network options.
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
GUI application, a specialized version of swift::core::CApplication for GUI applications.
static QString scaleFactor(int argc, char *argv[])
Get the scale factor.
void gracefulShutdown()
Graceful shutdown.
static void highDpiScreenSupport(const QString &scaleFactor={})
Support for high DPI screens.
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.
int main(int argc, char *argv[])
main
Definition: main.cpp:20