File indexing completed on 2024-04-21 04:49:07
0001 /* 0002 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <georgefb899@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef APPLICATION_H 0008 #define APPLICATION_H 0009 0010 #include <QAbstractItemModel> 0011 #include <QApplication> 0012 #include <QFont> 0013 #include <QObject> 0014 #include <QQmlApplicationEngine> 0015 0016 #include <KAboutData> 0017 #include <KSharedConfig> 0018 0019 class QQuickWindow; 0020 class KActionCollection; 0021 class KConfigDialog; 0022 class KColorSchemeManager; 0023 0024 class ApplicationEventFilter : public QObject 0025 { 0026 Q_OBJECT 0027 0028 Q_SIGNALS: 0029 void applicationMouseLeave(); 0030 void applicationMouseEnter(); 0031 0032 protected: 0033 bool eventFilter(QObject *obj, QEvent *event) override 0034 { 0035 if (event->type() == QEvent::Leave) { 0036 Q_EMIT applicationMouseLeave(); 0037 } 0038 if (event->type() == QEvent::Enter) { 0039 Q_EMIT applicationMouseEnter(); 0040 } 0041 return QObject::eventFilter(obj, event); 0042 } 0043 }; 0044 0045 class Application : public QObject 0046 { 0047 Q_OBJECT 0048 Q_PROPERTY(QAbstractItemModel *colorSchemesModel READ colorSchemesModel CONSTANT) 0049 0050 public: 0051 static Application *instance(); 0052 0053 Q_INVOKABLE bool urlExists(const QUrl &url); 0054 Q_INVOKABLE bool pathExists(const QString &url); 0055 Q_INVOKABLE QUrl configFilePath(); 0056 Q_INVOKABLE QUrl ccConfigFilePath(); 0057 Q_INVOKABLE QUrl configFolderPath(); 0058 Q_INVOKABLE QUrl pathToUrl(const QString &path); 0059 Q_INVOKABLE void restoreWindowGeometry(QQuickWindow *window) const; 0060 Q_INVOKABLE void saveWindowGeometry(QQuickWindow *window); 0061 Q_INVOKABLE bool configFolderExists(); 0062 Q_INVOKABLE QUrl parentUrl(const QString &path); 0063 Q_INVOKABLE QUrl url(int key); 0064 Q_INVOKABLE void addUrl(int key, const QString &value); 0065 Q_INVOKABLE QString getFileContent(const QString &file); 0066 Q_INVOKABLE QStringList availableGuiStyles(); 0067 Q_INVOKABLE void setGuiStyle(const QString &style); 0068 Q_INVOKABLE void activateColorScheme(const QString &name); 0069 Q_INVOKABLE void openDocs(const QString &page); 0070 Q_INVOKABLE QStringList getFonts(); 0071 Q_INVOKABLE int frameworksVersionMinor(); 0072 Q_INVOKABLE int qtMajorVersion(); 0073 Q_INVOKABLE QString platformName(); 0074 Q_INVOKABLE void raiseWindow(); 0075 0076 static QString version(); 0077 Q_INVOKABLE static bool hasYoutubeDl(); 0078 Q_INVOKABLE static QString youtubeDlExecutable(); 0079 Q_INVOKABLE static bool isYoutubePlaylist(const QString &path); 0080 Q_INVOKABLE static QString formatTime(const double time); 0081 Q_INVOKABLE static QString mimeType(QUrl url); 0082 0083 void handleSecondayInstanceMessage(const QByteArray &message); 0084 QCommandLineParser *parser() const; 0085 0086 QQmlApplicationEngine *qmlEngine() const; 0087 void setQmlEngine(QQmlApplicationEngine *_qmlEngine); 0088 0089 Q_SIGNALS: 0090 void qmlApplicationMouseLeave(); 0091 void qmlApplicationMouseEnter(); 0092 void error(const QString &message); 0093 void saveWindowGeometryAsync(QQuickWindow *window); 0094 void openUrl(const QUrl &url); 0095 0096 private: 0097 explicit Application(); 0098 ~Application() = default; 0099 0100 Application(const Application &) = delete; 0101 Application &operator=(const Application &) = delete; 0102 Application(Application &&) = delete; 0103 Application &operator=(Application &&) = delete; 0104 0105 void setupWorkerThread(); 0106 void setupAboutData(); 0107 void setupCommandLineParser(); 0108 void setupQmlSettingsTypes(); 0109 QAbstractItemModel *colorSchemesModel(); 0110 QApplication *m_app{nullptr}; 0111 KAboutData m_aboutData; 0112 KSharedConfig::Ptr m_config; 0113 QCommandLineParser *m_parser{nullptr}; 0114 QMap<int, QUrl> m_urls; 0115 KColorSchemeManager *m_schemes{nullptr}; 0116 QString m_systemDefaultStyle; 0117 QQmlApplicationEngine *m_qmlEngine{nullptr}; 0118 }; 0119 0120 #endif // APPLICATION_H