nextcloud-desktop/src/mirall/progressdispatcher.h

141 lines
3.6 KiB
C
Raw Normal View History

/*
* Copyright (C) by Klaas Freitag <freitag@owncloud.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; version 2 of the License.
*
* 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.
*/
#ifndef PROGRESSDISPATCHER_H
#define PROGRESSDISPATCHER_H
#include <QObject>
#include <QHash>
#include <QTime>
#include <QQueue>
2013-10-08 16:07:46 +04:00
#include <QElapsedTimer>
namespace Mirall {
/**
* @brief The FolderScheduler class schedules folders for sync
*/
namespace Progress
{
2013-08-14 21:59:16 +04:00
enum Kind {
Invalid,
StartSync,
Download,
Upload,
Context,
Inactive,
StartDownload,
StartUpload,
EndDownload,
EndUpload,
EndSync,
2013-08-03 23:33:19 +04:00
StartDelete,
EndDelete,
StartRename,
EndRename,
SoftError,
NormalError,
FatalError
2013-08-14 21:59:16 +04:00
};
2013-08-14 21:59:16 +04:00
struct Info {
Kind kind;
QString folder;
QString current_file;
qint64 file_size;
qint64 current_file_bytes;
qint64 overall_file_count;
qint64 current_file_no;
qint64 overall_transmission_size;
qint64 overall_current_bytes;
QDateTime timestamp;
2013-08-14 21:59:16 +04:00
Info() : kind(Invalid), file_size(0), current_file_bytes(0),
overall_file_count(0), current_file_no(0),
overall_transmission_size(0), overall_current_bytes(0) { }
};
2013-08-14 21:59:16 +04:00
struct SyncProblem {
Kind kind;
QString folder;
QString current_file;
QString error_message;
int error_code;
QDateTime timestamp;
SyncProblem() : kind(Invalid), error_code(0) {}
2013-08-14 21:59:16 +04:00
};
QString asActionString( Kind );
QString asResultString( Kind );
bool isErrorKind( Kind );
}
2013-07-23 15:32:24 +04:00
/**
* @file progressdispatcher.h
* @brief A singleton class to provide sync progress information to other gui classes.
*
* How to use the ProgressDispatcher:
* Just connect to the two signals either to progress for every individual file
* or the overall sync progress.
*
*/
class ProgressDispatcher : public QObject
{
Q_OBJECT
2013-07-23 15:32:24 +04:00
friend class Folder; // only allow Folder class to access the setting slots.
public:
static ProgressDispatcher* instance();
~ProgressDispatcher();
QList<Progress::Info> recentChangedItems(int count);
QList<Progress::SyncProblem> recentProblems(int count);
Progress::Kind currentFolderContext( const QString& folder );
signals:
2013-07-23 15:32:24 +04:00
/**
@brief Signals the progress of data transmission.
2013-07-23 15:32:24 +04:00
@param[out] folder The folder which is being processed
@param[out] newProgress A struct with all progress info.
2013-07-23 15:32:24 +04:00
*/
void progressInfo( const QString& folder, const Progress::Info& progress );
void progressSyncProblem( const QString& folder, const Progress::SyncProblem& problem );
2013-07-23 15:32:24 +04:00
protected:
void setProgressInfo(const QString& folder, const Progress::Info& progress);
void setProgressProblem( const QString& folder, const Progress::SyncProblem& problem);
private:
ProgressDispatcher(QObject* parent = 0);
const int _QueueSize;
QList<Progress::Info> _recentChanges;
QList<Progress::SyncProblem> _recentProblems;
QHash<QString, Progress::Kind> _currentAction;
2013-10-08 16:07:46 +04:00
QElapsedTimer _timer;
static ProgressDispatcher* _instance;
};
}
#endif // PROGRESSDISPATCHER_H