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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "progressdispatcher.h"
|
|
|
|
|
2013-07-18 00:32:47 +04:00
|
|
|
#include <QObject>
|
2013-07-05 20:46:43 +04:00
|
|
|
#include <QMetaType>
|
2013-07-23 14:23:20 +04:00
|
|
|
#include <QDebug>
|
2013-08-17 13:20:17 +04:00
|
|
|
#include <QCoreApplication>
|
2013-07-05 20:46:43 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
ProgressDispatcher* ProgressDispatcher::_instance = 0;
|
2013-08-06 20:06:39 +04:00
|
|
|
QString Progress::asResultString( Kind kind )
|
|
|
|
{
|
|
|
|
QString re;
|
|
|
|
|
|
|
|
switch(kind) {
|
|
|
|
case Download:
|
|
|
|
case EndDownload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Download");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case Upload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Upload");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case Context:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Context" );
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case Inactive:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Inactive");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case StartDownload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Download");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case StartUpload:
|
|
|
|
case EndUpload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Upload");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case StartSync:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Start");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case EndSync:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Finished");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
|
|
|
case StartDelete:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "For deletion");
|
|
|
|
break;
|
2013-08-06 20:06:39 +04:00
|
|
|
case EndDelete:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "deleted");
|
2013-08-06 20:06:39 +04:00
|
|
|
break;
|
2013-11-08 19:21:59 +04:00
|
|
|
case StartRename:
|
|
|
|
re = QCoreApplication::translate( "progress", "Move");
|
|
|
|
break;
|
|
|
|
case EndRename:
|
|
|
|
re = QCoreApplication::translate( "progress", "Move");
|
|
|
|
break;
|
2013-08-06 20:06:39 +04:00
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
|
|
|
return re;
|
|
|
|
|
|
|
|
}
|
2013-07-05 20:46:43 +04:00
|
|
|
|
2013-08-06 20:06:39 +04:00
|
|
|
QString Progress::asActionString( Kind kind )
|
2013-07-18 00:32:47 +04:00
|
|
|
{
|
|
|
|
QString re;
|
|
|
|
|
|
|
|
switch(kind) {
|
|
|
|
case Download:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case Upload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case Context:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "Context");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case Inactive:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "inactive");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case StartDownload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case StartUpload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case EndDownload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case EndUpload:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
2013-07-26 15:44:38 +04:00
|
|
|
case StartSync:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "starting");
|
2013-07-26 15:44:38 +04:00
|
|
|
break;
|
|
|
|
case EndSync:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "finished");
|
2013-07-26 15:44:38 +04:00
|
|
|
break;
|
2013-08-03 23:33:19 +04:00
|
|
|
case StartDelete:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "delete");
|
2013-08-03 23:33:19 +04:00
|
|
|
break;
|
|
|
|
case EndDelete:
|
2013-08-17 13:20:17 +04:00
|
|
|
re = QCoreApplication::translate( "progress", "deleted");
|
|
|
|
break;
|
2013-11-08 19:21:59 +04:00
|
|
|
case StartRename:
|
|
|
|
re = QCoreApplication::translate( "progress", "move");
|
|
|
|
break;
|
|
|
|
case EndRename:
|
|
|
|
re = QCoreApplication::translate( "progress", "moved");
|
|
|
|
break;
|
2013-07-18 00:32:47 +04:00
|
|
|
default:
|
2013-07-26 17:10:03 +04:00
|
|
|
Q_ASSERT(false);
|
2013-07-18 00:32:47 +04:00
|
|
|
}
|
|
|
|
return re;
|
2013-11-25 19:12:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Progress::isErrorKind( Kind kind )
|
|
|
|
{
|
|
|
|
bool re = false;
|
|
|
|
if( kind == SoftError || kind == NormalError || kind == FatalError ) {
|
|
|
|
re = true;
|
|
|
|
}
|
|
|
|
return re;
|
2013-07-18 00:32:47 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 20:46:43 +04:00
|
|
|
ProgressDispatcher* ProgressDispatcher::instance() {
|
|
|
|
if (!_instance) {
|
|
|
|
_instance = new ProgressDispatcher();
|
|
|
|
}
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressDispatcher::ProgressDispatcher(QObject *parent) :
|
2013-07-31 00:22:43 +04:00
|
|
|
QObject(parent),
|
2013-08-19 15:06:30 +04:00
|
|
|
_QueueSize(50)
|
2013-07-05 20:46:43 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressDispatcher::~ProgressDispatcher()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-31 00:22:43 +04:00
|
|
|
QList<Progress::Info> ProgressDispatcher::recentChangedItems(int count)
|
|
|
|
{
|
2013-08-01 16:34:31 +04:00
|
|
|
if( count > 0 ) {
|
|
|
|
return _recentChanges.mid(0, count);
|
|
|
|
}
|
|
|
|
return _recentChanges;
|
2013-07-31 00:22:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<Progress::SyncProblem> ProgressDispatcher::recentProblems(int count)
|
|
|
|
{
|
2013-08-01 16:34:31 +04:00
|
|
|
if( count > 0 ) {
|
|
|
|
return _recentProblems.mid(0, count);
|
|
|
|
}
|
|
|
|
return _recentProblems;
|
2013-07-31 00:22:43 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 19:16:33 +04:00
|
|
|
void ProgressDispatcher::setProgressProblem(const QString& folder, const Progress::SyncProblem &problem)
|
|
|
|
{
|
|
|
|
Q_ASSERT( Progress::isErrorKind(problem.kind));
|
|
|
|
|
|
|
|
_recentProblems.prepend( problem );
|
|
|
|
if( _recentProblems.size() > _QueueSize ) {
|
|
|
|
_recentProblems.removeLast();
|
|
|
|
}
|
|
|
|
emit progressSyncProblem( folder, problem );
|
|
|
|
}
|
|
|
|
|
2013-07-31 00:22:43 +04:00
|
|
|
void ProgressDispatcher::setProgressInfo(const QString& folder, const Progress::Info& progress)
|
2013-07-05 20:46:43 +04:00
|
|
|
{
|
2013-07-26 15:44:38 +04:00
|
|
|
if( folder.isEmpty() ) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-25 19:16:33 +04:00
|
|
|
Progress::Info newProgress(progress);
|
|
|
|
|
|
|
|
Q_ASSERT( !Progress::isErrorKind(progress.kind));
|
2013-08-13 17:22:03 +04:00
|
|
|
|
2013-11-25 19:16:33 +04:00
|
|
|
if( newProgress.kind == Progress::StartSync ) {
|
|
|
|
_recentProblems.clear();
|
|
|
|
_timer.start();
|
|
|
|
}
|
|
|
|
if( newProgress.kind == Progress::EndSync ) {
|
|
|
|
newProgress.overall_current_bytes = newProgress.overall_transmission_size;
|
|
|
|
newProgress.current_file_no = newProgress.overall_file_count;
|
|
|
|
_currentAction.remove(newProgress.folder);
|
|
|
|
qint64 msecs = _timer.elapsed();
|
|
|
|
|
|
|
|
qDebug()<< "[PROGRESS] progressed " << newProgress.overall_transmission_size
|
|
|
|
<< " bytes in " << newProgress.overall_file_count << " files"
|
|
|
|
<< " in msec " << msecs;
|
|
|
|
}
|
|
|
|
if( newProgress.kind == Progress::EndDownload ||
|
|
|
|
newProgress.kind == Progress::EndUpload ||
|
|
|
|
newProgress.kind == Progress::EndDelete ||
|
|
|
|
newProgress.kind == Progress::EndRename ) {
|
|
|
|
_recentChanges.prepend(newProgress);
|
|
|
|
if( _recentChanges.size() > _QueueSize ) {
|
|
|
|
_recentChanges.removeLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// store the last real action to help clients that start during
|
|
|
|
// the Context-phase of an upload or download.
|
|
|
|
if( newProgress.kind != Progress::Context ) {
|
|
|
|
_currentAction[folder] = newProgress.kind;
|
2013-07-26 15:44:38 +04:00
|
|
|
}
|
2013-11-25 19:16:33 +04:00
|
|
|
|
|
|
|
emit progressInfo( folder, newProgress );
|
|
|
|
|
2013-07-19 15:05:30 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 17:22:03 +04:00
|
|
|
Progress::Kind ProgressDispatcher::currentFolderContext( const QString& folder )
|
|
|
|
{
|
|
|
|
if( _currentAction.contains(folder)) {
|
|
|
|
return _currentAction[folder];
|
|
|
|
}
|
|
|
|
return Progress::Invalid;
|
|
|
|
}
|
|
|
|
|
2013-07-05 20:46:43 +04:00
|
|
|
}
|