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 {
38  QApplication qa(argc, argv); // needed
39  Q_UNUSED(qa)
40  CGuiApplication a(CApplicationInfo::swiftLauncher(), CApplicationInfo::Launcher, CIcons::swiftLauncher1024());
41  a.addNetworkOptions(); // so it can be passed (hand over) to started applications
42  a.addDBusAddressOption(); // required by the dbus server address selector
43  const QCommandLineOption installerOption { { "i", "installer" },
44  QCoreApplication::translate("main", "Installer setup.") };
45  a.addParserOption(installerOption);
46  if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
48  CDatabaseReaderConfigList::forLauncher());
49 
50  const bool installMode = a.isParserOptionSet(installerOption);
51  if (installMode) initDbCacheFromResourceFileIfRequired(a);
52 
54  if (!a.start())
55  {
56  a.gracefulShutdown();
57  return EXIT_FAILURE;
58  }
59 
60  CSwiftLauncher launcher(installMode);
61  const int res = a.exec();
62  if (res != EXIT_SUCCESS || !launcher.shouldStartAppDetached()) { return res; }
63 
64  const bool s = launcher.startDetached();
65  return s ? EXIT_SUCCESS : EXIT_FAILURE;
66 }
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.
void gracefulShutdown()
Graceful shutdown.
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 addYears(int nyears) const const
QDateTime currentDateTimeUtc()
bool isValid() const const
int main(int argc, char *argv[])
main
Definition: main.cpp:20