FMH::Downloader

Search for usage in LXR

FMH::Downloader Class Reference

#include <downloader.h>

Inheritance diagram for FMH::Downloader:

Signals

void aborted ()
 
void dataReady (QByteArray array)
 
void done ()
 
void downloadReady ()
 
void fileSaved (QString path)
 
void progress (int percent)
 
void warning (QString warning)
 

Public Member Functions

 Downloader (QObject *parent=nullptr)
 
void downloadFile (const QUrl &source, const QUrl &destination)
 
void getArray (const QUrl &fileURL, const QMap< QString, QString > &headers={})
 
bool isFinished () const
 
bool isRunning () const
 
void stop ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
QBindable< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo () const const
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType)
 
QThreadthread () const const
 

Additional Inherited Members

- Public Types inherited from QObject
typedef  QObjectList
 
- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The Downloader class This is a quick helper to download remote content and save it as local files.

Note
Allows to make get request using optional headers.
#include <QCoreApplication>
#include <QDebug>
#include <QUrl>
#include <QObject>
#include <iostream>
#include <MauiKit4/FileBrowsing/downloader.h>
#include <MauiKit4/FileBrowsing/fmstatic.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QUrl url = u"https://mauikit.org/wp-content/uploads/2021/08/index-1.png"_qs; //The remote file image URL to download.
QString fileName = "/IndexAppDemo.png"; //The new name of the image to save it locally.
QUrl savePath = FMStatic::DownloadsPath+fileName; //The local downloads path where to save the image.
FMH::Downloader downloader;
QObject::connect(&downloader, &FMH::Downloader::progress, [=](int percent) {
qDebug() << "Downloading " << percent << "%"; });
QObject::connect(&downloader, &FMH::Downloader::done, [&a]() {
qDebug() << "Download finished";
a.exit(); });
qDebug() << "Downloaded file has been saved as " << path; });
downloader.downloadFile(url, savePath);
return a.exec();
}
The Downloader class This is a quick helper to download remote content and save it as local files.
Definition downloader.h:57
void downloadFile(const QUrl &source, const QUrl &destination)
Given a source URL to a file it downloads it to a given local destination.
void progress(int percent)
Emitted while the process is ongoing.
void done()
Emitted when the process has been finished.
void fileSaved(QString path)
Emitted after the downloading has finished and the file has been saved successfully.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)

Definition at line 56 of file downloader.h.

Constructor & Destructor Documentation

◆ Downloader()

FMH::Downloader::Downloader ( QObject * parent = nullptr)

Definition at line 13 of file downloader.cpp.

◆ ~Downloader()

FMH::Downloader::~Downloader ( )
virtual

Definition at line 44 of file downloader.cpp.

Member Function Documentation

◆ aborted

void FMH::Downloader::aborted ( )
signal

Emitted when the download or data request has been aborted manually by calling the stop method.

◆ dataReady

void FMH::Downloader::dataReady ( QByteArray array)
signal

Emitted when the data is ready and can be parsed.

Parameters
arraythe array raw data

◆ done

void FMH::Downloader::done ( )
signal

Emitted when the process has been finished.

Emitted as the downloadReady signal.

◆ downloadFile()

void FMH::Downloader::downloadFile ( const QUrl & source,
const QUrl & destination )

Given a source URL to a file it downloads it to a given local destination.

Parameters
sourcethe remote file URL
destinationthe local file URL destination with a name an suffix extension type

Definition at line 97 of file downloader.cpp.

◆ downloadReady

void FMH::Downloader::downloadReady ( )
signal

Emitted when the downloading has finished.

◆ fileSaved

void FMH::Downloader::fileSaved ( QString path)
signal

Emitted after the downloading has finished and the file has been saved successfully.

Parameters
paththe location path of the new saved file

◆ getArray()

void FMH::Downloader::getArray ( const QUrl & fileURL,
const QMap< QString, QString > & headers = {} )

Given a URL make a get request and once the reply is ready emits a signal with the retrieved array data.

Note
Usually this is used to retrieved structured information from a web API, such a a JSON or a XML file, to later be parsed.
See also
dataReady
Parameters
fileURLthe end point URL to make the request
headersthe optional set of HTTP request headers structured as a QMap of a key value pair of plain strings.

Definition at line 143 of file downloader.cpp.

◆ isFinished()

bool FMH::Downloader::isFinished ( ) const

Whether the process has finished successfully.

See also
aborted

Definition at line 50 of file downloader.cpp.

◆ isRunning()

bool FMH::Downloader::isRunning ( ) const

Whether the downloading or current request is still in progress.

Definition at line 60 of file downloader.cpp.

◆ progress

void FMH::Downloader::progress ( int percent)
signal

Emitted while the process is ongoing.

Parameters
percentthe process value from 0 to 100

◆ stop()

void FMH::Downloader::stop ( )

Force to stop the process of the data request or the downloading of the file.

Definition at line 71 of file downloader.cpp.

◆ warning

void FMH::Downloader::warning ( QString warning)
signal

Emitted when there is a warning message, for example when an error has occurred during the process or at the end.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:50:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.