2013-07-05 20:46:43 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
2013-07-26 15:44:38 +04:00
|
|
|
#include <QHash>
|
2013-07-31 00:22:43 +04:00
|
|
|
#include <QTime>
|
|
|
|
#include <QQueue>
|
2013-10-08 16:07:46 +04:00
|
|
|
#include <QElapsedTimer>
|
2013-07-05 20:46:43 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The FolderScheduler class schedules folders for sync
|
|
|
|
*/
|
2013-08-17 13:21:32 +04:00
|
|
|
namespace Progress
|
2013-07-05 20:46:43 +04:00
|
|
|
{
|
2013-08-14 21:59:16 +04:00
|
|
|
enum Kind {
|
2013-07-26 15:44:38 +04:00
|
|
|
Invalid,
|
|
|
|
StartSync,
|
2013-07-05 20:46:43 +04:00
|
|
|
Download,
|
|
|
|
Upload,
|
|
|
|
Context,
|
|
|
|
Inactive,
|
|
|
|
StartDownload,
|
|
|
|
StartUpload,
|
|
|
|
EndDownload,
|
2013-07-26 15:44:38 +04:00
|
|
|
EndUpload,
|
2013-07-30 11:06:18 +04:00
|
|
|
EndSync,
|
2013-08-03 23:33:19 +04:00
|
|
|
StartDelete,
|
|
|
|
EndDelete,
|
2013-11-08 19:21:59 +04:00
|
|
|
StartRename,
|
|
|
|
EndRename,
|
2013-11-25 19:12:25 +04:00
|
|
|
SoftError,
|
|
|
|
NormalError,
|
|
|
|
FatalError
|
2013-08-14 21:59:16 +04:00
|
|
|
};
|
2013-07-18 00:32:47 +04:00
|
|
|
|
2013-08-14 21:59:16 +04:00
|
|
|
struct Info {
|
2013-07-25 18:28:36 +04:00
|
|
|
Kind kind;
|
2013-07-31 00:22:43 +04:00
|
|
|
QString folder;
|
2013-07-26 15:44:38 +04:00
|
|
|
QString current_file;
|
|
|
|
qint64 file_size;
|
|
|
|
qint64 current_file_bytes;
|
|
|
|
|
|
|
|
qint64 overall_file_count;
|
2013-07-25 18:28:36 +04:00
|
|
|
qint64 current_file_no;
|
2013-07-26 15:44:38 +04:00
|
|
|
qint64 overall_transmission_size;
|
|
|
|
qint64 overall_current_bytes;
|
2013-07-25 18:28:36 +04:00
|
|
|
|
2013-08-13 18:53:39 +04:00
|
|
|
QDateTime timestamp;
|
2013-07-31 00:22:43 +04:00
|
|
|
|
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-07-31 00:22:43 +04:00
|
|
|
|
2013-08-14 21:59:16 +04:00
|
|
|
struct SyncProblem {
|
2013-11-25 19:16:33 +04:00
|
|
|
Kind kind;
|
2013-07-31 00:22:43 +04:00
|
|
|
QString folder;
|
|
|
|
QString current_file;
|
|
|
|
QString error_message;
|
|
|
|
int error_code;
|
2013-08-13 18:53:39 +04:00
|
|
|
QDateTime timestamp;
|
2013-11-25 19:16:33 +04:00
|
|
|
|
|
|
|
SyncProblem() : kind(Invalid), error_code(0) {}
|
2013-08-14 21:59:16 +04:00
|
|
|
};
|
2013-07-25 18:28:36 +04:00
|
|
|
|
2013-08-17 13:21:32 +04:00
|
|
|
QString asActionString( Kind );
|
|
|
|
QString asResultString( Kind );
|
2013-11-25 19:16:33 +04:00
|
|
|
|
|
|
|
bool isErrorKind( Kind );
|
2013-08-17 13:21:32 +04:00
|
|
|
}
|
2013-07-05 20:46:43 +04:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2013-07-05 20:46:43 +04:00
|
|
|
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.
|
2013-07-05 20:46:43 +04:00
|
|
|
public:
|
|
|
|
static ProgressDispatcher* instance();
|
|
|
|
~ProgressDispatcher();
|
|
|
|
|
2013-07-31 00:22:43 +04:00
|
|
|
QList<Progress::Info> recentChangedItems(int count);
|
|
|
|
QList<Progress::SyncProblem> recentProblems(int count);
|
2013-08-13 17:22:03 +04:00
|
|
|
|
|
|
|
Progress::Kind currentFolderContext( const QString& folder );
|
2013-11-25 19:16:33 +04:00
|
|
|
|
2013-07-05 20:46:43 +04:00
|
|
|
signals:
|
2013-07-23 15:32:24 +04:00
|
|
|
/**
|
2013-07-26 15:44:38 +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
|
2013-07-26 15:44:38 +04:00
|
|
|
@param[out] newProgress A struct with all progress info.
|
2013-07-23 15:32:24 +04:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-07-31 00:22:43 +04:00
|
|
|
void progressInfo( const QString& folder, const Progress::Info& progress );
|
|
|
|
void progressSyncProblem( const QString& folder, const Progress::SyncProblem& problem );
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2013-07-23 15:32:24 +04:00
|
|
|
protected:
|
2013-11-25 19:16:33 +04:00
|
|
|
void setProgressInfo(const QString& folder, const Progress::Info& progress);
|
|
|
|
void setProgressProblem( const QString& folder, const Progress::SyncProblem& problem);
|
2013-07-05 20:46:43 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProgressDispatcher(QObject* parent = 0);
|
2013-08-19 15:06:30 +04:00
|
|
|
const int _QueueSize;
|
|
|
|
QList<Progress::Info> _recentChanges;
|
|
|
|
QList<Progress::SyncProblem> _recentProblems;
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2013-08-13 17:22:03 +04:00
|
|
|
QHash<QString, Progress::Kind> _currentAction;
|
2013-10-08 16:07:46 +04:00
|
|
|
|
|
|
|
QElapsedTimer _timer;
|
2013-07-05 20:46:43 +04:00
|
|
|
static ProgressDispatcher* _instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // PROGRESSDISPATCHER_H
|