File indexing completed on 2024-11-24 03:56:29
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QApplication> 0010 #include <QSettings> 0011 #include <QDir> 0012 0013 #include "app/settings/settings.hpp" 0014 #include "app/translation_service.hpp" 0015 0016 namespace app { 0017 0018 class Application : public QApplication 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 using QApplication::QApplication; 0024 0025 virtual QSettings qsettings() const; 0026 0027 void initialize(); 0028 0029 void finalize() 0030 { 0031 app::settings::Settings::instance().save(); 0032 } 0033 0034 static Application* instance() 0035 { 0036 return static_cast<Application *>(QCoreApplication::instance()); 0037 } 0038 0039 0040 /** 0041 * \brief A path to write user preferences into 0042 * \param name Name of the data subdirectory 0043 */ 0044 QString writable_data_path(const QString& name) const; 0045 0046 /** 0047 * \brief Path to get the file from 0048 * \param name Name of the data files 0049 */ 0050 virtual QString data_file(const QString& name) const; 0051 0052 /** 0053 * \brief Get all available directories to search data from 0054 * \param name Name of the data directory 0055 */ 0056 QStringList data_paths(const QString& name) const; 0057 0058 /** 0059 * \brief Get all directories to search data from 0060 * 0061 * This function may include directories that don't exist but that will be 0062 * checked if they existed 0063 * 0064 * \param name Name of the data directory 0065 */ 0066 QStringList data_paths_unchecked(const QString& name) const; 0067 0068 /** 0069 * \brief Get all possible directories to search data from 0070 */ 0071 QList<QDir> data_roots() const; 0072 0073 bool notify(QObject *receiver, QEvent *e) override; 0074 0075 protected: 0076 /** 0077 * \brief Called after construction, before anything else 0078 * \note set application name and stuff in here 0079 */ 0080 virtual void on_initialize() {} 0081 0082 /** 0083 * \brief Called after on_initialize 0084 */ 0085 virtual void on_initialize_translations(); 0086 0087 /** 0088 * \brief Called after on_initialize() and after translations are loaded 0089 */ 0090 virtual void on_initialize_settings() {} 0091 }; 0092 0093 } // namespace app