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-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:
|
|
|
|
re = QObject::tr("Download");
|
|
|
|
break;
|
|
|
|
case Upload:
|
|
|
|
re = QObject::tr("Upload");
|
|
|
|
break;
|
|
|
|
case Context:
|
|
|
|
re = QObject::tr("Context");
|
|
|
|
break;
|
|
|
|
case Inactive:
|
|
|
|
re = QObject::tr("Inactive");
|
|
|
|
break;
|
|
|
|
case StartDownload:
|
|
|
|
re = QObject::tr("Download");
|
|
|
|
break;
|
|
|
|
case StartUpload:
|
|
|
|
case EndUpload:
|
|
|
|
re = QObject::tr("Upload");
|
|
|
|
break;
|
|
|
|
case StartSync:
|
|
|
|
re = QObject::tr("Start");
|
|
|
|
break;
|
|
|
|
case EndSync:
|
|
|
|
re = QObject::tr("Finished");
|
|
|
|
break;
|
|
|
|
case StartDelete:
|
|
|
|
re = QObject::tr("For deletion");
|
|
|
|
break;
|
|
|
|
case EndDelete:
|
|
|
|
re = QObject::tr("deleted");
|
|
|
|
break;
|
|
|
|
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-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case Upload:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case Context:
|
|
|
|
re = QObject::tr("Context");
|
|
|
|
break;
|
|
|
|
case Inactive:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("inactive");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case StartDownload:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case StartUpload:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case EndDownload:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("downloading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
|
|
|
case EndUpload:
|
2013-07-23 14:23:20 +04:00
|
|
|
re = QObject::tr("uploading");
|
2013-07-18 00:32:47 +04:00
|
|
|
break;
|
2013-07-26 15:44:38 +04:00
|
|
|
case StartSync:
|
|
|
|
re = QObject::tr("starting");
|
|
|
|
break;
|
|
|
|
case EndSync:
|
|
|
|
re = QObject::tr("finished");
|
|
|
|
break;
|
2013-08-03 23:33:19 +04:00
|
|
|
case StartDelete:
|
|
|
|
re = QObject::tr("start delete");
|
|
|
|
break;
|
|
|
|
case EndDelete:
|
|
|
|
re = QObject::tr("deleted");
|
|
|
|
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-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),
|
|
|
|
_problemQueueSize(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
|
|
|
}
|
|
|
|
|
|
|
|
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-07-31 00:22:43 +04:00
|
|
|
Progress::Info newProgress = progress;
|
2013-07-26 15:44:38 +04:00
|
|
|
|
2013-07-30 11:06:18 +04:00
|
|
|
if( newProgress.kind == Progress::Error ) {
|
2013-07-31 00:22:43 +04:00
|
|
|
Progress::SyncProblem err;
|
|
|
|
err.folder = folder;
|
|
|
|
err.current_file = newProgress.current_file;
|
|
|
|
err.error_message = QString::fromLocal8Bit( (const char*)newProgress.file_size );
|
|
|
|
err.error_code = newProgress.file_size;
|
2013-08-01 16:34:31 +04:00
|
|
|
err.timestamp = QTime::currentTime();
|
2013-07-31 00:22:43 +04:00
|
|
|
|
|
|
|
_recentProblems.enqueue( err );
|
|
|
|
if( _recentProblems.size() > _problemQueueSize ) {
|
|
|
|
_recentProblems.dequeue();
|
|
|
|
}
|
|
|
|
emit progressSyncProblem( folder, err );
|
|
|
|
} else {
|
2013-08-02 14:16:21 +04:00
|
|
|
if( newProgress.kind == Progress::StartSync ) {
|
|
|
|
_recentProblems.clear();
|
|
|
|
}
|
2013-07-31 00:22:43 +04:00
|
|
|
if( newProgress.kind == Progress::EndSync ) {
|
|
|
|
newProgress.overall_current_bytes = newProgress.overall_transmission_size;
|
|
|
|
newProgress.current_file_no = newProgress.overall_file_count;
|
|
|
|
}
|
|
|
|
if( newProgress.kind == Progress::EndDownload || newProgress.kind == Progress::EndUpload ) {
|
|
|
|
_recentChanges.enqueue(newProgress);
|
|
|
|
}
|
|
|
|
emit progressInfo( folder, newProgress );
|
2013-07-26 15:44:38 +04:00
|
|
|
}
|
2013-07-19 15:05:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-05 20:46:43 +04:00
|
|
|
}
|