Skip to content
Snippets Groups Projects
Select Git revision
  • b7d4e1128a717364585c2de350c3edec17d61d66
  • master default protected
  • beta/202506161038
  • stable/20250613.0
  • nightly/20250613.0
  • beta/202506101658
  • stable/20250610.0
  • nightly/20250610.0
  • beta/202506091027
  • beta/202506061543
  • nightly/20250605.0
  • beta/202506051039
  • beta/202506051002
  • beta/202506041611
  • beta/202506041335
  • beta/202505231812
  • stable/20250523.0
  • nightly/20250523.0
  • nightly/20250515.0
  • nightly/20250510.0
  • nightly/20250509.1
  • nightly/20250509.0
22 results

networkmanager.h

Blame
    • Andreas Traczyk's avatar
      3b6bbe77
      misc: implement update system · 3b6bbe77
      Andreas Traczyk authored
      - re-introduce a genericized NetworkManager
      - isolate update logic into a qml accessible class derived from
        NetworkManager
      - fix QtWebEngineProcess missing when re-installing over existing
        version
      - provide a command line option to override the base url
        for testing local and remote updates
      - clean-up manual update-check UI
      
      Gitlab: #101
      Change-Id: I9c8d2badae59ec31cab12d38b8470edf2bcad401
      3b6bbe77
      History
      misc: implement update system
      Andreas Traczyk authored
      - re-introduce a genericized NetworkManager
      - isolate update logic into a qml accessible class derived from
        NetworkManager
      - fix QtWebEngineProcess missing when re-installing over existing
        version
      - provide a command line option to override the base url
        for testing local and remote updates
      - clean-up manual update-check UI
      
      Gitlab: #101
      Change-Id: I9c8d2badae59ec31cab12d38b8470edf2bcad401
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    networkmanager.h 2.41 KiB
    /*!
     * Copyright (C) 2019-2020 by Savoir-faire Linux
     * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
     * Author: Andreas Traczyk <andreas.traczyk@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 <http://www.gnu.org/licenses/>.
     */
    
    #pragma once
    
    #include <QObject>
    #include <QFile>
    #include <QSslError>
    #include <QNetworkReply>
    
    class QNetworkAccessManager;
    class ConnectivityMonitor;
    
    class NetWorkManager : public QObject
    {
        Q_OBJECT
    public:
        explicit NetWorkManager(ConnectivityMonitor* cm, QObject* parent = nullptr);
        virtual ~NetWorkManager() = default;
    
        enum GetStatus { IDLE, STARTED, FINISHED };
    
        enum GetError { DISCONNECTED, NETWORK_ERROR, ACCESS_DENIED, SSL_ERROR, CANCELED };
        Q_ENUM(GetError)
    
        using DoneCallBack = std::function<void(const QString&)>;
    
        /*!
         * using qt get request to store the reply in file
         * @param url - network address
         * @param doneCb - done callback
         * @param path - optional file saving path, if empty
         * a string will be passed as the second paramter of doneCb
         */
        void get(const QUrl& url, const DoneCallBack& doneCb = {}, const QString& path = {});
    
        /*!
         * manually abort the current request
         */
        Q_INVOKABLE void cancelRequest();
    
    signals:
        void statusChanged(GetStatus error);
        void downloadProgressChanged(qint64 bytesRead, qint64 totalBytes);
        void errorOccured(GetError error, const QString& msg = {});
    
    private slots:
        void onSslErrors(const QList<QSslError>& sslErrors);
        void onHttpReadyRead();
    
    private:
        void reset(bool flush = true);
    
        QNetworkAccessManager* manager_;
        QNetworkReply* reply_;
        QScopedPointer<QFile> file_;
        ConnectivityMonitor* connectivityMonitor_;
        bool lastConnectionState_;
    };
    Q_DECLARE_METATYPE(NetWorkManager*)