Skip to content
Snippets Groups Projects
Select Git revision
  • 41138a968204148e642fb0094bd6a9ce12285f44
  • master default protected
  • beta/202508201613
  • stable/20250815.1
  • stable/20250815.0
  • nightly/20250815.0
  • nightly/20250806.0
  • nightly/20250805.0
  • beta/202508051403
  • beta/202508051107
  • nightly/20250722.0
  • beta/202507211539
  • stable/20250718.0
  • nightly/20250718.0
  • nightly/20250714.0
  • beta/202507141552
  • beta/202506161038
  • stable/20250613.0
  • nightly/20250613.0
  • beta/202506101658
  • stable/20250610.0
  • nightly/20250610.0
22 results

mainapplication.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    mainapplication.h 2.79 KiB
    /*!
     * Copyright (C) 2020 by Savoir-faire Linux
     * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
     * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
     * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
     *
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 3 of the License, or
     * (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
     */
    
    #pragma once
    
    #include "lrcinstance.h"
    
    #include <QFile>
    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlEngine>
    #include <QScreen>
    #include <QWindow>
    
    #include <memory>
    
    class ConnectivityMonitor;
    class AppSettingsManager;
    class SystemTray;
    class CallAdapter;
    
    // Provides information about the screen the app is displayed on
    class ScreenInfo : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(double devicePixelRatio MEMBER devicePixelRatio_ NOTIFY devicePixelRatioChanged)
    public:
        void setCurrentFocusWindow(QWindow* window);
        void setDevicePixelRatio(double ratio)
        {
            if (ratio != devicePixelRatio_) {
                devicePixelRatio_ = ratio;
    
                Q_EMIT devicePixelRatioChanged();
            }
        }
    
    Q_SIGNALS:
        void devicePixelRatioChanged();
    
    private:
        double devicePixelRatio_ {0.0};
    
        QMetaObject::Connection currentFocusWindowScreenConnection_;
        QMetaObject::Connection devicePixelRatioConnection_;
    
        QWindow* currentFocusWindow_ {nullptr};
        QScreen* currentFocusWindowScreen_ {nullptr};
    };
    
    class MainApplication : public QApplication
    {
        Q_OBJECT
    
    public:
        explicit MainApplication(int& argc, char** argv);
        ~MainApplication();
    
        bool init();
        void restoreApp();
    
    private:
        void vsConsoleDebug();
        void fileDebug(QFile* debugFile);
    
        void loadTranslations();
        void initLrc(const QString& downloadUrl, ConnectivityMonitor* cm, bool muteDaemon);
        const QVariantMap parseArguments();
        void setApplicationFont();
        void initQmlLayer();
        void initSystray();
        void cleanup();
    
    private:
        QScopedPointer<QFile> debugFile_;
        QScopedPointer<QQmlApplicationEngine> engine_;
    
        QScopedPointer<LRCInstance> lrcInstance_;
    
        QScopedPointer<ConnectivityMonitor> connectivityMonitor_;
        QScopedPointer<AppSettingsManager> settingsManager_;
        QScopedPointer<SystemTray> systemTray_;
    
        ScreenInfo screenInfo_;
    
        CallAdapter* callAdapter_;
    };