"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/network.h" (12 Feb 2021, 3411 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "network.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef NETWORK_H
    8 #define NETWORK_H
    9 
   10 #include <QFile>
   11 #include <QNetworkAccessManager>
   12 #include <QObject>
   13 #include <QProcess>
   14 #include <QUrl>
   15 
   16 
   17 /**
   18     cb2Bib Network file copy/move
   19 
   20     @author Pere Constans
   21 */
   22 class network : public QObject
   23 {
   24 
   25     Q_OBJECT
   26 
   27 public:
   28     explicit network(QObject* parento = 0);
   29     inline ~network() {}
   30 
   31     enum Action
   32     {
   33         Copy,
   34         Move
   35     };
   36 
   37     void getFile(const QString& source, const QString& destination, const Action action = Copy, QObject* receiver = 0,
   38                  const char* callback = 0, const bool overwrite = false);
   39     void headFile(const QString& source, QObject* receiver = 0, const char* callback = 0);
   40 
   41     inline const QString destinationFilename() const
   42     {
   43         return _destination_filename;
   44     }
   45 
   46     inline const QString sourceFilename() const
   47     {
   48         return _source_filename;
   49     }
   50 
   51     inline const QString errorString() const
   52     {
   53         return _request_error_string;
   54     }
   55 
   56     inline const QString mimetypeString() const
   57     {
   58         return _file_mimetype_string;
   59     }
   60 
   61     static inline Action actionType(const QString& action)
   62     {
   63         return action == "move" ? Move : Copy;
   64     }
   65 
   66 
   67 signals:
   68     void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
   69     void proxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* auth);
   70     void requestFinished(bool succeeded);
   71 
   72 
   73 public slots:
   74     void cancelDownload();
   75 
   76 
   77 private:
   78     QByteArray _fetch_url_query;
   79     QFile _destination_file;
   80     QNetworkAccessManager* _fetcher;
   81     QNetworkAccessManager::Operation _fetch_operation;
   82     QNetworkReply* _current_reply;
   83     QProcess* _fetcher_client;
   84     QString FmClientCopyArg;
   85     QString FmClientCopyBin;
   86     QString FmClientMoveArg;
   87     QString FmClientMoveBin;
   88     QString _destination_filename;
   89     QString _file_mimetype_string;
   90     QString _request_error_string;
   91     QString _source_filename;
   92     bool FmClient;
   93     bool _is_fetching;
   94     bool _request_succeeded;
   95     bool checkDestination();
   96     const int _max_redirections;
   97     int _redirection_count;
   98     void _emit_request_finished(bool succeeded);
   99     void _fetch(const QUrl& url);
  100     void _fetch_c2b(const Action action,
  101                     const QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation);
  102     void _fetch_client(const Action action);
  103     void _head(const QUrl& url);
  104     void getFilePrivate(const Action action);
  105     void headFilePrivate();
  106 
  107     inline void setup(const QString& source, const QString& destination = QString())
  108     {
  109         _destination_filename = destination;
  110         _source_filename = source;
  111         _file_mimetype_string.clear();
  112         _request_error_string.clear();
  113         _is_fetching = true;
  114         _redirection_count = 0;
  115     }
  116 
  117 
  118 private slots:
  119     void _client_finished(int exitCode, QProcess::ExitStatus exitStatus);
  120     void _emit_request_finished();
  121     void _fetch_finished();
  122     void _fetch_ready_read();
  123     void _head_finished();
  124     void loadSettings();
  125     void logError();
  126 };
  127 
  128 #endif