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;
|
|
|
|
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-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),
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2013-08-14 20:23:40 +04:00
|
|
|
// its really
|
2013-07-31 00:22:43 +04:00
|
|
|
err.error_message = QString::fromLocal8Bit( (const char*)newProgress.file_size );
|
2013-08-14 20:23:40 +04:00
|
|
|
err.error_code = newProgress.current_file_bytes;
|
2013-08-13 18:53:39 +04:00
|
|
|
err.timestamp = QDateTime::currentDateTime();
|
2013-07-31 00:22:43 +04:00
|
|
|
|
2013-08-19 15:06:30 +04:00
|
|
|
_recentProblems.prepend( err );
|
|
|
|
if( _recentProblems.size() > _QueueSize ) {
|
|
|
|
_recentProblems.removeLast();
|
2013-07-31 00:22:43 +04:00
|
|
|
}
|
|
|
|
emit progressSyncProblem( folder, err );
|
|
|
|
} else {
|
2013-08-02 14:16:21 +04:00
|
|
|
if( newProgress.kind == Progress::StartSync ) {
|
|
|
|
_recentProblems.clear();
|
2013-10-08 16:07:46 +04:00
|
|
|
_timer.start();
|
2013-08-02 14:16:21 +04:00
|
|
|
}
|
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;
|
2013-08-13 17:22:03 +04:00
|
|
|
_currentAction.remove(newProgress.folder);
|
2013-10-08 17:41:15 +04:00
|
|
|
qint64 msecs = _timer.elapsed();
|
2013-10-08 16:07:46 +04:00
|
|
|
|
|
|
|
qDebug()<< "[PROGRESS] progressed " << newProgress.overall_transmission_size
|
|
|
|
<< " bytes in " << newProgress.overall_file_count << " files"
|
|
|
|
<< " in msec " << msecs;
|
2013-07-31 00:22:43 +04:00
|
|
|
}
|
2013-08-14 20:23:40 +04:00
|
|
|
if( newProgress.kind == Progress::EndDownload ||
|
|
|
|
newProgress.kind == Progress::EndUpload ||
|
2013-08-06 20:06:54 +04:00
|
|
|
newProgress.kind == Progress::EndDelete ) {
|
2013-08-19 15:06:30 +04:00
|
|
|
_recentChanges.prepend(newProgress);
|
|
|
|
if( _recentChanges.size() > _QueueSize ) {
|
|
|
|
_recentChanges.removeLast();
|
|
|
|
}
|
2013-07-31 00:22:43 +04:00
|
|
|
}
|
2013-08-13 17:22:03 +04:00
|
|
|
// 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-31 00:22:43 +04:00
|
|
|
emit progressInfo( folder, newProgress );
|
2013-07-26 15:44:38 +04:00
|
|
|
}
|
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
|
|
|
}
|