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
|
2016-10-25 12:00:07 +03:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2013-07-05 20:46:43 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
#include "owncloudlib.h"
|
2013-07-05 20:46:43 +04:00
|
|
|
#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>
|
2015-01-30 15:36:20 +03:00
|
|
|
#include <QTimer>
|
2014-12-06 14:27:50 +03:00
|
|
|
|
2014-03-14 16:03:16 +04:00
|
|
|
#include "syncfileitem.h"
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2015-06-29 19:56:09 +03:00
|
|
|
/**
|
|
|
|
* @brief The ProgressInfo class
|
|
|
|
* @ingroup libsync
|
2015-06-26 18:07:47 +03:00
|
|
|
*/
|
2015-05-20 12:59:33 +03:00
|
|
|
class OWNCLOUDSYNC_EXPORT ProgressInfo : public QObject
|
2013-07-05 20:46:43 +04:00
|
|
|
{
|
2015-01-30 15:36:20 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2016-05-20 16:07:54 +03:00
|
|
|
ProgressInfo();
|
|
|
|
|
|
|
|
/** Resets for a new sync run.
|
|
|
|
*/
|
|
|
|
void reset();
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2017-07-11 13:52:40 +03:00
|
|
|
/** Records the status of the sync run
|
|
|
|
*/
|
|
|
|
enum Status {
|
|
|
|
/// Emitted once at start
|
|
|
|
Starting,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emitted once without _currentDiscoveredFolder when it starts,
|
|
|
|
* then for each folder.
|
|
|
|
*/
|
|
|
|
Discovery,
|
|
|
|
|
|
|
|
/// Emitted once when reconcile starts
|
|
|
|
Reconcile,
|
|
|
|
|
|
|
|
/// Emitted during propagation, with progress data
|
|
|
|
Propagation,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Emitted once when done
|
|
|
|
*
|
|
|
|
* Except when SyncEngine jumps directly to finalize() without going
|
2019-01-14 17:44:50 +03:00
|
|
|
* through slotPropagationFinished().
|
2017-07-11 13:52:40 +03:00
|
|
|
*/
|
|
|
|
Done
|
|
|
|
};
|
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] Status status() const;
|
2017-07-11 13:52:40 +03:00
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
/**
|
|
|
|
* Called when propagation starts.
|
|
|
|
*
|
2016-05-20 16:07:54 +03:00
|
|
|
* isUpdatingEstimates() will return true afterwards.
|
2015-01-30 15:36:20 +03:00
|
|
|
*/
|
2016-05-20 16:07:54 +03:00
|
|
|
void startEstimateUpdates();
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
/**
|
2016-05-20 16:07:54 +03:00
|
|
|
* Returns true when startEstimateUpdates() was called.
|
2015-01-30 15:36:20 +03:00
|
|
|
*
|
|
|
|
* This is used when the SyncEngine wants to indicate a new sync
|
|
|
|
* is about to start via the transmissionProgress() signal. The
|
2016-05-20 16:07:54 +03:00
|
|
|
* first ProgressInfo will have isUpdatingEstimates() == false.
|
2015-01-30 15:36:20 +03:00
|
|
|
*/
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool isUpdatingEstimates() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase the file and size totals by the amount indicated in item.
|
|
|
|
*/
|
|
|
|
void adjustTotalsForFile(const SyncFileItem &item);
|
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] qint64 totalFiles() const;
|
|
|
|
[[nodiscard]] qint64 completedFiles() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] qint64 totalSize() const;
|
|
|
|
[[nodiscard]] qint64 completedSize() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
/** Number of a file that is currently in progress. */
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] qint64 currentFile() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2015-07-02 14:49:19 +03:00
|
|
|
/** Return true if the size needs to be taken in account in the total amount of time */
|
2015-01-30 11:17:15 +03:00
|
|
|
static inline bool isSizeDependent(const SyncFileItem &item)
|
|
|
|
{
|
2018-12-20 11:45:31 +03:00
|
|
|
return !item.isDirectory()
|
|
|
|
&& (item._instruction == CSYNC_INSTRUCTION_CONFLICT
|
|
|
|
|| item._instruction == CSYNC_INSTRUCTION_SYNC
|
|
|
|
|| item._instruction == CSYNC_INSTRUCTION_NEW
|
|
|
|
|| item._instruction == CSYNC_INSTRUCTION_TYPE_CHANGE)
|
|
|
|
&& !(item._type == ItemTypeVirtualFile
|
|
|
|
|| item._type == ItemTypeVirtualFileDehydration);
|
2014-03-14 16:03:16 +04:00
|
|
|
}
|
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
/**
|
|
|
|
* Holds estimates about progress, returned to the user.
|
|
|
|
*/
|
|
|
|
struct Estimates
|
|
|
|
{
|
|
|
|
/// Estimated completion amount per second. (of bytes or files)
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 estimatedBandwidth;
|
2014-03-14 16:03:16 +04:00
|
|
|
|
2015-07-02 14:49:19 +03:00
|
|
|
/// Estimated time remaining in milliseconds.
|
2015-01-30 15:36:20 +03:00
|
|
|
quint64 estimatedEta;
|
|
|
|
};
|
2014-03-14 16:03:16 +04:00
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
/**
|
|
|
|
* Holds the current state of something making progress and maintains an
|
|
|
|
* estimate of the current progress per second.
|
|
|
|
*/
|
2015-05-20 12:59:33 +03:00
|
|
|
struct OWNCLOUDSYNC_EXPORT Progress
|
2015-01-30 15:36:20 +03:00
|
|
|
{
|
|
|
|
/** Returns the estimates about progress per second and eta. */
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] Estimates estimates() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] qint64 completed() const;
|
|
|
|
[[nodiscard]] qint64 remaining() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
private:
|
2014-04-25 02:08:25 +04:00
|
|
|
/**
|
2015-01-30 15:36:20 +03:00
|
|
|
* Update the exponential moving average estimate of _progressPerSec.
|
2014-04-28 19:49:27 +04:00
|
|
|
*/
|
2015-01-30 15:36:20 +03:00
|
|
|
void update();
|
|
|
|
|
2015-08-11 11:38:04 +03:00
|
|
|
/**
|
|
|
|
* Changes the _completed value and does sanity checks on
|
|
|
|
* _prevCompleted and _total.
|
|
|
|
*/
|
2019-02-13 12:15:33 +03:00
|
|
|
void setCompleted(qint64 completed);
|
2015-08-11 11:38:04 +03:00
|
|
|
|
2015-07-02 14:49:19 +03:00
|
|
|
// Updated by update()
|
2020-05-28 17:59:24 +03:00
|
|
|
double _progressPerSec = 0;
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 _prevCompleted = 0;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
// Used to get to a good value faster when
|
|
|
|
// progress measurement stats. See update().
|
2020-05-28 17:59:24 +03:00
|
|
|
double _initialSmoothing = 1.0;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2015-07-02 14:49:19 +03:00
|
|
|
// Set and updated by ProgressInfo
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 _completed = 0;
|
|
|
|
qint64 _total = 0;
|
2015-07-02 14:49:19 +03:00
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
friend class ProgressInfo;
|
|
|
|
};
|
|
|
|
|
2017-07-11 13:52:40 +03:00
|
|
|
Status _status;
|
|
|
|
|
2015-05-20 12:59:33 +03:00
|
|
|
struct OWNCLOUDSYNC_EXPORT ProgressItem
|
2015-01-30 15:36:20 +03:00
|
|
|
{
|
|
|
|
SyncFileItem _item;
|
|
|
|
Progress _progress;
|
2014-03-14 16:03:16 +04:00
|
|
|
};
|
2015-01-30 15:36:20 +03:00
|
|
|
QHash<QString, ProgressItem> _currentItems;
|
|
|
|
|
|
|
|
SyncFileItem _lastCompletedItem;
|
|
|
|
|
|
|
|
// Used during local and remote update phase
|
2018-02-21 11:39:55 +03:00
|
|
|
QString _currentDiscoveredRemoteFolder;
|
|
|
|
QString _currentDiscoveredLocalFolder;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
void setProgressComplete(const SyncFileItem &item);
|
|
|
|
|
2019-02-13 12:15:33 +03:00
|
|
|
void setProgressItem(const SyncFileItem &item, qint64 completed);
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the total completion estimate
|
|
|
|
*/
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] Estimates totalProgress() const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
2016-08-15 14:36:53 +03:00
|
|
|
/**
|
|
|
|
* Get the optimistic eta.
|
|
|
|
*
|
|
|
|
* This value is based on the highest observed transfer bandwidth
|
|
|
|
* and files-per-second speed.
|
|
|
|
*/
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] quint64 optimisticEta() const;
|
2016-08-15 14:36:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the remaining-time estimate is trusted.
|
|
|
|
*
|
|
|
|
* We don't trust it if it is hugely above the optimistic estimate.
|
|
|
|
* See #5046.
|
|
|
|
*/
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] bool trustEta() const;
|
2016-08-15 14:36:53 +03:00
|
|
|
|
2015-01-30 15:36:20 +03:00
|
|
|
/**
|
|
|
|
* Get the current file completion estimate structure
|
|
|
|
*/
|
2022-09-30 20:12:08 +03:00
|
|
|
[[nodiscard]] Estimates fileProgress(const SyncFileItem &item) const;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
/**
|
|
|
|
* Called every second once started, this function updates the
|
|
|
|
* estimates.
|
|
|
|
*/
|
|
|
|
void updateEstimates();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Sets the completed size by summing finished jobs with the progress
|
|
|
|
// of active ones.
|
|
|
|
void recomputeCompletedSize();
|
|
|
|
|
|
|
|
// Triggers the update() slot every second once propagation started.
|
|
|
|
QTimer _updateEstimatesTimer;
|
|
|
|
|
|
|
|
Progress _sizeProgress;
|
|
|
|
Progress _fileProgress;
|
|
|
|
|
|
|
|
// All size from completed jobs only.
|
2019-02-13 12:15:33 +03:00
|
|
|
qint64 _totalSizeOfCompletedJobs;
|
2015-01-30 15:36:20 +03:00
|
|
|
|
|
|
|
// The fastest observed rate of files per second in this sync.
|
|
|
|
double _maxFilesPerSecond;
|
|
|
|
double _maxBytesPerSecond;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace Progress {
|
2014-03-14 16:03:16 +04:00
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT QString asActionString(const SyncFileItem &item);
|
|
|
|
OWNCLOUDSYNC_EXPORT QString asResultString(const SyncFileItem &item);
|
2014-03-14 16:03:16 +04:00
|
|
|
|
2014-04-29 17:30:19 +04:00
|
|
|
OWNCLOUDSYNC_EXPORT bool isWarningKind(SyncFileItem::Status);
|
2015-01-08 13:42:14 +03:00
|
|
|
OWNCLOUDSYNC_EXPORT bool isIgnoredKind(SyncFileItem::Status);
|
2013-08-17 13:21:32 +04:00
|
|
|
}
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2017-07-11 16:54:01 +03:00
|
|
|
/** Type of error
|
|
|
|
*
|
|
|
|
* Used for ProgressDispatcher::syncError. May trigger error interactivity
|
|
|
|
* in IssuesWidget.
|
|
|
|
*/
|
|
|
|
enum class ErrorCategory {
|
|
|
|
Normal,
|
|
|
|
InsufficientRemoteStorage,
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2014-04-29 17:30:19 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT ProgressDispatcher : public QObject
|
2013-07-05 20:46:43 +04:00
|
|
|
{
|
|
|
|
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();
|
2021-08-17 13:39:31 +03:00
|
|
|
~ProgressDispatcher() override;
|
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
|
2014-03-14 16:03:16 +04:00
|
|
|
@param[out] progress A struct with all progress info.
|
2013-07-23 15:32:24 +04:00
|
|
|
|
|
|
|
*/
|
2022-10-24 17:00:50 +03:00
|
|
|
void progressInfo(const QString &folder, const OCC::ProgressInfo &progress);
|
2014-06-06 17:52:55 +04:00
|
|
|
/**
|
2015-08-11 14:45:02 +03:00
|
|
|
* @brief: the item was completed by a job
|
2014-06-06 17:52:55 +04:00
|
|
|
*/
|
2022-10-24 17:00:50 +03:00
|
|
|
void itemCompleted(const QString &folder, const OCC::SyncFileItemPtr &item);
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2017-06-28 13:45:54 +03:00
|
|
|
/**
|
|
|
|
* @brief A new folder-wide sync error was seen.
|
|
|
|
*/
|
2022-10-24 17:00:50 +03:00
|
|
|
void syncError(const QString &folder, const QString &message, OCC::ErrorCategory category);
|
2017-06-28 13:45:54 +03:00
|
|
|
|
2021-06-08 17:20:07 +03:00
|
|
|
/**
|
|
|
|
* @brief Emitted when an error needs to be added into GUI
|
|
|
|
* @param[out] folder The folder which is being processed
|
|
|
|
* @param[out] status of the error
|
|
|
|
* @param[out] full error message
|
|
|
|
* @param[out] subject (optional)
|
|
|
|
*/
|
2022-10-24 17:00:50 +03:00
|
|
|
void addErrorToGui(const QString &folder, OCC::SyncFileItem::Status status, const QString &errorMessage, const QString &subject);
|
2021-06-08 17:20:07 +03:00
|
|
|
|
2018-02-21 15:55:33 +03:00
|
|
|
/**
|
|
|
|
* @brief Emitted for a folder when a sync is done, listing all pending conflicts
|
|
|
|
*/
|
|
|
|
void folderConflicts(const QString &folder, const QStringList &conflictPaths);
|
|
|
|
|
2013-07-23 15:32:24 +04:00
|
|
|
protected:
|
2015-01-30 15:36:20 +03:00
|
|
|
void setProgressInfo(const QString &folder, const ProgressInfo &progress);
|
2013-07-05 20:46:43 +04:00
|
|
|
|
|
|
|
private:
|
2018-11-12 20:46:39 +03:00
|
|
|
ProgressDispatcher(QObject *parent = nullptr);
|
2013-10-08 16:07:46 +04:00
|
|
|
|
|
|
|
QElapsedTimer _timer;
|
2013-07-05 20:46:43 +04:00
|
|
|
static ProgressDispatcher *_instance;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // PROGRESSDISPATCHER_H
|