Consolidated progress displaying to a single slot from csync.

This commit is contained in:
Klaas Freitag 2013-07-26 13:44:38 +02:00
parent 8f912ca0c5
commit 3a9ab3a86f
11 changed files with 166 additions and 195 deletions

View file

@ -40,8 +40,7 @@ namespace Mirall {
AccountSettings::AccountSettings(QWidget *parent) :
QWidget(parent),
ui(new Ui::AccountSettings),
_item(0),
_overallProgressBase(0)
_item(0)
{
ui->setupUi(this);
@ -203,12 +202,6 @@ void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f )
item->setData( f->secondPath(), FolderStatusDelegate::FolderSecondPathRole );
item->setData( f->alias(), FolderStatusDelegate::FolderAliasRole );
item->setData( f->syncEnabled(), FolderStatusDelegate::FolderSyncEnabled );
item->setData( 0, FolderStatusDelegate::SyncProgressOverallPercent );
item->setData( QVariant(QString::null),FolderStatusDelegate::SyncProgressOverallString );
item->setData( QVariant(QString::null),FolderStatusDelegate::SyncProgressItemString );
item->setData( QVariant(false), FolderStatusDelegate::AddProgressSpace);
SyncResult res = f->syncResult();
SyncResult::Status status = res.status();
@ -477,35 +470,6 @@ QStandardItem* AccountSettings::itemForFolder(const QString& folder)
return item;
}
void AccountSettings::slotSetOverallProgress(const QString& folder, const QString& file, int fileNo, int fileCnt,
qint64 p1, qint64 p2)
{
QStandardItem *item = itemForFolder(folder);
_overallFolder = folder;
_overallFile = file;
_overallFileNo = fileNo;
_overallFileCnt = fileCnt;
_overallFileSize = p2;
if( p1 == 0 ) {
// begin of a sequence of up- and downloads.
_overallProgressBase = 0;
_lastProgress = 0;
_previousFileProgressString = QString::null;
}
if( item ) {
QString s1 = Utility::octetsToString( p1 );
QString s2 = Utility::octetsToString( p2 );
QString overallSyncString = tr("%1 of %2, file %3 of %4").arg(s1).arg(s2).arg(fileNo).arg(fileCnt);
item->setData( overallSyncString, FolderStatusDelegate::SyncProgressOverallString );
int overallPercent = 0;
if( p2 > 0 ) overallPercent = qRound(double(p1)/double(p2) * 100.0);
item->setData( overallPercent, FolderStatusDelegate::SyncProgressOverallPercent);
}
}
QString AccountSettings::shortenFilename( const QString& folder, const QString& file ) const
{
// strip off the server prefix from the file name
@ -528,37 +492,47 @@ QString AccountSettings::shortenFilename( const QString& folder, const QString&
return shortFile;
}
void AccountSettings::slotSetProgress( Progress::Kind kind, const QString& folder, const QString& file, qint64 p1, qint64 p2 )
void AccountSettings::slotSetProgress( const QString& folder, Progress::Info progress )
{
// qDebug() << "================================> Progress for folder " << folder << " file " << file << ": "<< p1;
QStandardItem *item = itemForFolder( folder );
qint64 prog1 = p1;
qint64 prog2 = p2;
qint64 prog1 = progress.current_file_bytes;
qint64 prog2 = progress.file_size;
if( item == NULL ) {
return;
}
QString itemFileName = shortenFilename(folder, file);
QString itemFileName = shortenFilename(folder, progress.current_file);
QString syncFileProgressString;
// Set the verb if up- or download
if( kind != Progress::Context ) {
_kindContext = Progress::asString(kind);
// stay with the previous kind-string for Context.
if( progress.kind != Progress::Context ) {
_kindContext = Progress::asString(progress.kind);
}
QString kindString = _kindContext;
if( kind == Progress::StartDownload || kind == Progress::StartUpload ) { // File upload starts.
switch( progress.kind ) {
case Progress::StartSync:
break;
case Progress::StartDownload:
case Progress::StartUpload:
syncFileProgressString = tr("Start");
if( _hideProgressTimers.contains(item) ) {
// The timer is still running.
QTimer *t = _hideProgressTimers.take(item);
t->stop();
t->deleteLater();
}
syncFileProgressString = tr("Start");
} else if( kind == Progress::EndDownload || kind == Progress::EndUpload ) {
syncFileProgressString = tr("Finished");
break;
case Progress::Context:
syncFileProgressString = tr("Currently");
break;
case Progress::EndDownload:
case Progress::EndUpload:
break;
case Progress::EndSync:
syncFileProgressString = tr("Completely");
// start a timer to stop the progress display
QTimer *timer;
@ -572,35 +546,37 @@ void AccountSettings::slotSetProgress( Progress::Kind kind, const QString& folde
_hideProgressTimers.insert(item, timer);
}
timer->start(5000);
prog1 = prog2 = _lastProgress;
} else if( kind == Progress::Context ) { // File progress
_lastProgress = prog1;
syncFileProgressString = tr("Currently");
break;
}
QString fileProgressString;
QString s1 = Utility::octetsToString( prog1 );
QString s2 = Utility::octetsToString( prog2 );
// switch on extra space.
item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace );
if( progress.kind != Progress::EndSync ) {
// Example text: "Currently uploading foobar.png (1MB of 2MB)"
fileProgressString = tr("%1 %2 %3 (%4 of %5)").arg(syncFileProgressString).arg(kindString).
arg(itemFileName).arg(s1).arg(s2);
// only publish to item if there really is a change
item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace );
if( fileProgressString != _previousFileProgressString || _previousFileProgressString.isNull() ) {
} else {
fileProgressString = tr("Completely finished.");
}
item->setData( fileProgressString,FolderStatusDelegate::SyncProgressItemString);
slotSetOverallProgress(folder, itemFileName, _overallFileNo, _overallFileCnt,
_overallProgressBase + prog1, _overallFileSize);
ui->_folderList->repaint();
}
_previousFileProgressString = fileProgressString;
// move the overall progress on. Don't do before it was set in the item.
if( kind == Progress::EndDownload || kind == Progress::EndUpload ) {
_overallProgressBase += _lastProgress;
// overall progress
s1 = Utility::octetsToString( progress.overall_current_bytes );
s2 = Utility::octetsToString( progress.overall_transmission_size );
QString overallSyncString = tr("%1 of %2, file %3 of %4").arg(s1).arg(s2)
.arg(progress.current_file_no).arg(progress.overall_file_count);
item->setData( overallSyncString, FolderStatusDelegate::SyncProgressOverallString );
int overallPercent = 0;
if( progress.overall_transmission_size > 0 ) {
overallPercent = qRound(double(progress.overall_current_bytes)/double(progress.overall_transmission_size) * 100.0);
}
item->setData( overallPercent, FolderStatusDelegate::SyncProgressOverallPercent);
}
void AccountSettings::slotHideProgress()
@ -621,7 +597,6 @@ void AccountSettings::slotHideProgress()
}
++i;
}
_previousFileProgressString = QString::null;
send_timer->deleteLater();
}

View file

@ -66,8 +66,8 @@ public slots:
void slotOCInfoFail( QNetworkReply* );
void slotDoubleClicked( const QModelIndex& );
void slotFolderOpenAction( const QString& );
void slotSetProgress( Progress::Kind, const QString&, const QString&, qint64, qint64);
void slotSetOverallProgress( const QString&, const QString&, int, int, qint64, qint64);
void slotSetProgress(const QString&, Progress::Info progress);
void slotUpdateQuota( qint64,qint64 );
void slotIgnoreFilesEditor();
@ -94,19 +94,9 @@ private:
QStandardItemModel *_model;
QListWidgetItem *_item;
QUrl _OCUrl;
double _progressFactor;
QHash<QStandardItem*, QTimer*> _hideProgressTimers;
QTimer *_timer;
QString _previousFileProgressString;
QString _kindContext;
QString _overallFolder;
QString _overallFile;
int _overallFileNo;
int _overallFileCnt;
qint64 _overallFileSize;
qint64 _overallProgressBase;
qint64 _lastProgress;
};
} // namespace Mirall

View file

@ -36,7 +36,6 @@
#include "mirall/utility.h"
#include "mirall/inotify.h"
#include "mirall/connectionvalidator.h"
#include "mirall/progressdispatcher.h"
#if defined(Q_OS_WIN)
#include <windows.h>
@ -123,8 +122,9 @@ Application::Application(int &argc, char **argv) :
this, SLOT(slotShowOptionalTrayMessage(QString,QString)));
ProgressDispatcher *pd = ProgressDispatcher::instance();
connect( pd, SIGNAL(overallProgress(QString,QString,int,int,qint64,qint64)),
SLOT(slotUpdateProgress(QString,QString,int,int,qint64,qint64)));
connect( pd, SIGNAL(progressInfo(QString,Progress::Info)), this,
SLOT(slotUpdateProgress(QString,Progress::Info)) );
// create folder manager for sync folder management
FolderMan *folderMan = FolderMan::instance();
connect( folderMan, SIGNAL(folderSyncStateChange(QString)),
@ -139,7 +139,7 @@ Application::Application(int &argc, char **argv) :
setQuitOnLastWindowClosed(false);
qRegisterMetaType<Progress::Kind>("Progress::Kind");
qRegisterMetaType<Progress::Info>("Progress::Info");
#if 0
qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
foreach (const QNetworkConfiguration& netCfg, _networkMgr->allConfigurations(QNetworkConfiguration::Active)) {
@ -484,16 +484,16 @@ void Application::slotUseMonoIconsChanged(bool)
computeOverallSyncStatus();
}
void Application::slotUpdateProgress(QString folder, QString file, int fileNo, int fileCnt, qlonglong o1, qlonglong o2)
void Application::slotUpdateProgress(const QString &folder, Progress::Info progress)
{
Q_UNUSED(folder)
Q_UNUSED(file)
Q_UNUSED(folder);
QString curAmount = Utility::octetsToString(o1);
QString totalAmount = Utility::octetsToString(o2);
_actionStatus->setText(tr("Syncing %1 of %2 (%3 of %4) ").arg(fileNo).arg(fileCnt).arg(curAmount, totalAmount));
QString curAmount = Utility::octetsToString(progress.overall_current_bytes);
QString totalAmount = Utility::octetsToString(progress.overall_transmission_size);
_actionStatus->setText(tr("Syncing %1 of %2 (%3 of %4) ").arg(progress.current_file_no)
.arg(progress.overall_file_count).arg(curAmount, totalAmount));
if (o1 == o2) {
if (progress.kind == Progress::EndSync) {
QTimer::singleShot(2000, this, SLOT(slotDisplayIdle()));
}
}

View file

@ -26,6 +26,7 @@
#include "mirall/logbrowser.h"
#include "mirall/systray.h"
#include "mirall/connectionvalidator.h"
#include "mirall/progressdispatcher.h"
class QAction;
class QMenu;
@ -97,7 +98,7 @@ protected slots:
void slotSetupProxy();
void slotRefreshQuotaDisplay( qint64 total, qint64 used );
void slotUseMonoIconsChanged( bool );
void slotUpdateProgress(QString,QString,int,int,qlonglong,qlonglong);
void slotUpdateProgress(const QString&,Progress::Info);
void slotDisplayIdle();
void slotHelp();
private:

View file

@ -405,6 +405,42 @@ void CSyncThread::startSync()
qDebug() << Q_FUNC_INFO << "Sync finished";
}
Progress::Kind CSyncThread::csyncToProgressKind( enum csync_notify_type_e kind )
{
Progress::Kind pKind = Progress::Invalid;
switch(kind) {
case CSYNC_NOTIFY_INVALID:
pKind = Progress::Invalid;
break;
case CSYNC_NOTIFY_START_SYNC_SEQUENCE:
pKind = Progress::StartSync;
break;
case CSYNC_NOTIFY_START_DOWNLOAD:
pKind = Progress::StartDownload;
break;
case CSYNC_NOTIFY_START_UPLOAD:
pKind = Progress::StartUpload;
break;
case CSYNC_NOTIFY_PROGRESS:
pKind = Progress::Context;
break;
case CSYNC_NOTIFY_FINISHED_DOWNLOAD:
pKind = Progress::EndDownload;
break;
case CSYNC_NOTIFY_FINISHED_UPLOAD:
pKind = Progress::EndUpload;
break;
case CSYNC_NOTIFY_FINISHED_SYNC_SEQUENCE:
pKind = Progress::EndSync;
break;
default:
pKind = Progress::Invalid;
break;
}
return pKind;
}
void CSyncThread::cb_progress( CSYNC_PROGRESS *progress, void *userdata )
{
if( !progress ) {
@ -415,41 +451,22 @@ void CSyncThread::cb_progress( CSYNC_PROGRESS *progress, void *userdata )
qDebug() << "No thread given in progress callback!";
return;
}
QString path = QUrl::fromEncoded(progress->path).toString();
Progress::Info pInfo;
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
pInfo.kind = thread->csyncToProgressKind( progress->kind );
pInfo.current_file = QUrl::fromEncoded( progress->path ).toString();
pInfo.file_size = progress->file_size;
pInfo.current_file_bytes = progress->curr_bytes;
}
pInfo.overall_file_count = progress->overall_file_count;
pInfo.current_file_no = progress->current_file_no;
pInfo.overall_transmission_size = progress->overall_transmission_size;
pInfo.overall_current_bytes = progress->current_overall_bytes;
void CSyncThread::cb_file_progress(const char *remote_url, enum csync_notify_type_e kind,
long long o1, long long o2, void *userdata)
{
QString path = QUrl::fromEncoded(remote_url).toString();
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
// Connect to something in folder!
thread->transmissionProgress( pInfo );
if (kind == CSYNC_NOTIFY_FINISHED_DOWNLOAD) {
thread->fileTransmissionProgress( Progress::EndDownload, path, (qint64)o2, (qint64)o2 );
thread->fileReceived(path);
} else if( kind == CSYNC_NOTIFY_START_UPLOAD ) {
thread->fileTransmissionProgress( Progress::StartUpload, path, (qint64)0, (qint64)0 ); // indicate the upload start.
} else if( kind == CSYNC_NOTIFY_PROGRESS ) {
thread->fileTransmissionProgress( Progress::Context, path, (qint64)o1, (qint64)o2 );
} else if( kind == CSYNC_NOTIFY_FINISHED_UPLOAD ) {
thread->fileTransmissionProgress( Progress::EndUpload, path, (qint64)o2, (qint64)o2 );
} else if( kind == CSYNC_NOTIFY_START_DOWNLOAD ) {
thread->fileTransmissionProgress( Progress::StartDownload, path, (qint64)0, (qint64)0 );
}
}
void CSyncThread::cb_overall_progress(const char *file_name, int file_no, int file_cnt,
long long o1, long long o2, void *userdata)
{
QString file = QUrl::fromEncoded(file_name).toString();
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
if(thread) {
thread->overallTransmissionProgress( file, file_no, file_cnt, qint64(o1), qint64(o2) );
}
}
void CSyncThread::setLastAuthCookies(QList<QNetworkCookie> c)

View file

@ -55,8 +55,6 @@ signals:
void treeWalkResult(const SyncFileItemVector&);
void transmissionProgress( Progress::Info progress );
void fileTransmissionProgress( Progress::Kind, const QString&, qint64, qint64);
void overallTransmissionProgress( const QString& file, int file_no, int file_cnt, qint64 o1, qint64 o2 );
void csyncStateDbFile( const QString& );
void wipeDb();
@ -67,12 +65,7 @@ signals:
private:
void handleSyncError(CSYNC *ctx, const char *state);
static void cb_file_progress(const char *remote_url,
enum csync_notify_type_e kind,
long long o1, long long o2,
void *userdata);
static void cb_overall_progress(const char *file_name, int file_no,
int file_cnt, long long o1, long long o2, void *userdata);
static void cb_progress( CSYNC_PROGRESS *progress, void *userdata );
static int treewalkLocal( TREE_WALK_FILE*, void *);
@ -80,6 +73,7 @@ private:
int treewalkFile( TREE_WALK_FILE*, bool );
int treewalkError( TREE_WALK_FILE* );
Progress::Kind csyncToProgressKind( enum csync_notify_type_e kind );
static int walkFinalize(TREE_WALK_FILE*, void* );

View file

@ -580,6 +580,8 @@ void Folder::startSync(const QStringList &pathList)
//blocking connection so the message box happens in this thread, but block the csync thread.
connect(_csync, SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)),
SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), Qt::BlockingQueuedConnection);
connect(_csync, SIGNAL(transmissionProgress(Progress::Info)), this, SLOT(slotTransmissionProgress(Progress::Info)));
connect(_csync, SIGNAL(fileTransmissionProgress(Progress::Kind, QString,qint64,qint64)),
SLOT(slotFileTransmissionProgress(Progress::Kind, QString,qint64,qint64)));
connect(_csync, SIGNAL(overallTransmissionProgress(QString, int, int, qint64, qint64)),
@ -632,19 +634,11 @@ void Folder::slotCSyncFinished()
emit syncFinished( _syncResult );
}
void Folder::slotFileTransmissionProgress(Progress::Kind kind, const QString& file ,qint64 p1, qint64 p2)
void Folder::slotTransmissionProgress(Progress::Info progress)
{
ProgressDispatcher::instance()->setFolderProgress( kind, alias(), file, p1, p2 );
ProgressDispatcher::instance()->setProgressInfo(alias(), progress);
}
void Folder::slotOverallTransmissionProgress( const QString& fileName, int fileNo, int fileCnt,
qint64 o1, qint64 o2)
{
ProgressDispatcher::instance()->setOverallProgress( alias(), fileName, fileNo, fileCnt, o1, o2);
}
ServerActionNotifier::ServerActionNotifier(QObject *parent)
: QObject(parent)
{

View file

@ -178,10 +178,7 @@ private slots:
void slotCsyncUnavailable();
void slotCSyncFinished();
void slotFileTransmissionProgress(Progress::Kind kind, const QString& file ,qint64 p1, qint64 p2);
void slotOverallTransmissionProgress( const QString& fileName, int fileNo, int fileCnt,
qint64 o1, qint64 o2);
void slotTransmissionProgress(Progress::Info progress);
void slotPollTimerTimeout();

View file

@ -51,9 +51,16 @@ QString Progress::asString( Kind kind )
case EndUpload:
re = QObject::tr("uploading");
break;
case StartSync:
re = QObject::tr("starting");
break;
case EndSync:
re = QObject::tr("finished");
break;
default:
re = QObject::tr("What do I know?");
}
qDebug() << "PROGRESS: " << re;
return re;
}
@ -75,16 +82,23 @@ ProgressDispatcher::~ProgressDispatcher()
}
void ProgressDispatcher::setFolderProgress( Progress::Kind kind, const QString& folder, const QString& file,
qint64 p1, qint64 p2)
void ProgressDispatcher::setProgressInfo(const QString& folder, Progress::Info newProgress)
{
emit itemProgress( kind, folder, file, p1, p2 );
if( folder.isEmpty() ) {
return;
}
if( newProgress.kind == Progress::EndSync ) {
newProgress.overall_current_bytes = newProgress.overall_transmission_size;
newProgress.current_file_no = newProgress.overall_file_count;
}
_lastProgressHash[folder] = newProgress;
emit progressInfo( folder, newProgress );
}
void ProgressDispatcher::setOverallProgress( const QString& folder, const QString& file, int fileNo, int fileCnt,
qint64 p1, qint64 p2 )
{
emit overallProgress( folder, file, fileNo, fileCnt, p1, p2 );
Progress::Info ProgressDispatcher::lastProgressInfo(const QString& folder) {
return _lastProgressHash[folder];
}
}

View file

@ -15,6 +15,7 @@
#define PROGRESSDISPATCHER_H
#include <QObject>
#include <QHash>
namespace Mirall {
@ -26,6 +27,8 @@ class Progress
{
public:
enum ProgressKind_s {
Invalid,
StartSync,
Download,
Upload,
Context,
@ -33,17 +36,21 @@ public:
StartDownload,
StartUpload,
EndDownload,
EndUpload
EndUpload,
EndSync
};
typedef ProgressKind_s Kind;
struct ProgressInfo_s {
QString file;
Kind kind;
qint64 file_count;
QString current_file;
qint64 file_size;
qint64 current_file_bytes;
qint64 overall_file_count;
qint64 current_file_no;
qint64 byte_sum;
qint64 byte_current;
qint64 overall_transmission_size;
qint64 overall_current_bytes;
};
typedef ProgressInfo_s Info;
@ -69,43 +76,27 @@ public:
static ProgressDispatcher* instance();
~ProgressDispatcher();
Progress::Info lastProgressInfo(const QString& folder);
signals:
/**
@brief Signals the progress of a single file item.
@param[out] kind The progress kind
@param[out] folder The folder which is being processed
@param[out] file The current file.
@param[out] p1 The current progress in byte.
@param[out] p2 The maximum progress in byte.
*/
void itemProgress( Progress::Kind kind, const QString& folder, const QString& file, qint64 p1, qint64 p2);
/**
@brief Signals the overall progress of a sync run.
This signals the overall sync progress of a single sync run.
If p1 == 0, the sync starts.
If p1 == p2, the sync is finished.
@brief Signals the progress of data transmission.
@param[out] folder The folder which is being processed
@param[out] file The current file.
@param[out] fileNo The current file number
@param[out] fileNo The overall file count to process.
@param[out] p1 The current progress in byte.
@param[out] p2 The maximum progress in byte.
@param[out] newProgress A struct with all progress info.
*/
void overallProgress(const QString& folder, const QString& file, int fileNo, int fileCnt, qint64 p1, qint64 p2);
void progressInfo( const QString& folder, Progress::Info progress );
protected:
void setFolderProgress(Progress::Kind, const QString&, const QString&, qint64, qint64);
void setOverallProgress(const QString&, const QString&, int, int, qint64, qint64);
void setProgressInfo(const QString &folder, Progress::Info newProgress);
private:
ProgressDispatcher(QObject* parent = 0);
static ProgressDispatcher* _instance;
QHash<QString, Progress::Info> _lastProgressHash;
};
}

View file

@ -78,10 +78,8 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent) :
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
app, SLOT(slotFolderOpenAction(QString)));
connect( ProgressDispatcher::instance(), SIGNAL(itemProgress(Progress::Kind, QString,QString,qint64,qint64)),
_accountSettings, SLOT(slotSetProgress(Progress::Kind, QString,QString,qint64,qint64)));
connect( ProgressDispatcher::instance(), SIGNAL(overallProgress(QString,QString, int,int,qint64,qint64)),
_accountSettings, SLOT(slotSetOverallProgress( const QString&, const QString&, int, int, qint64, qint64)));
connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, Progress::Info)),
_accountSettings, SLOT(slotSetProgress(QString, Progress::Info)) );
_ui->labelWidget->setCurrentRow(_ui->labelWidget->row(general));