1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-08-16 04:35:47 +02:00
jami-client-qt/src/networkmanager.h
Andreas Traczyk 3b6bbe772a misc: implement update system
- 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
2020-09-24 12:48:29 -04:00

76 lines
2.4 KiB
C++

/*!
* 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*)