Handle progress through ProgressDispatcher class, WIP.

This commit is contained in:
Klaas Freitag 2013-07-05 18:46:43 +02:00
parent eb39d144e4
commit 6b5b9db20a
12 changed files with 198 additions and 35 deletions

View file

@ -76,6 +76,7 @@ set(libsync_SRCS
mirall/logger.cpp mirall/logger.cpp
mirall/utility.cpp mirall/utility.cpp
mirall/connectionvalidator.cpp mirall/connectionvalidator.cpp
mirall/progressdispatcher.cpp
) )
set(libsync_HEADERS set(libsync_HEADERS
mirall/folderman.h mirall/folderman.h
@ -89,6 +90,7 @@ set(libsync_HEADERS
mirall/credentialstore.h mirall/credentialstore.h
mirall/logger.h mirall/logger.h
mirall/connectionvalidator.h mirall/connectionvalidator.h
mirall/progressdispatcher.h
) )
IF( INOTIFY_FOUND ) IF( INOTIFY_FOUND )

View file

@ -459,25 +459,28 @@ void AccountSettings::slotOpenOC()
QDesktopServices::openUrl( _OCUrl ); QDesktopServices::openUrl( _OCUrl );
} }
void AccountSettings::slotSetProgress( const QString& folder, const QString& file, long p1, long p2 ) void AccountSettings::slotSetProgress( Progress::Kind, const QString& folder, const QString& file, long p1, long p2 )
{ {
// if( p1 == 0 && p2 > 0 ) { qDebug() << "================================> Progress for folder " << folder << " file " << file << ": "<< p1;
// // sync start #if 0
// ui->progressBar->setMaximum( p2 ); if( p1 == 0 && p2 > 0 ) {
// ui->progressBar->setValue( p1 ); // sync start
// ui->progressBar->setEnabled(true); ui->progressBar->setMaximum( p2 );
// ui->fileProgressLabel->setText(tr("Uploading %1").arg(file)); ui->progressBar->setValue( p1 );
// // ui->progressBar->show(); ui->progressBar->setEnabled(true);
// } else if( p1 == p2 ) { ui->fileProgressLabel->setText(tr("Uploading %1").arg(file));
// // sync end // ui->progressBar->show();
// // ui->progressBar->setMaximum(0); } else if( p1 == p2 ) {
// ui->progressBar->setValue(0); // sync end
// ui->progressBar->setEnabled(false); // ui->progressBar->setMaximum(0);
// ui->fileProgressLabel->setText(tr("No activity.")); ui->progressBar->setValue(0);
// // ui->progressBar->hide(); ui->progressBar->setEnabled(false);
// } else { ui->fileProgressLabel->setText(tr("No activity."));
// ui->progressBar->setValue( p1 ); // ui->progressBar->hide();
// } } else {
ui->progressBar->setValue( p1 );
}
#endif
} }
void AccountSettings::slotUpdateQuota(qint64 total, qint64 used) void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)

View file

@ -19,6 +19,7 @@
#include <QPointer> #include <QPointer>
#include "mirall/folder.h" #include "mirall/folder.h"
#include "mirall/progressdispatcher.h"
class QStandardItemModel; class QStandardItemModel;
class QModelIndex; class QModelIndex;
@ -61,7 +62,7 @@ public slots:
void slotOCInfoFail( QNetworkReply* ); void slotOCInfoFail( QNetworkReply* );
void slotDoubleClicked( const QModelIndex& ); void slotDoubleClicked( const QModelIndex& );
void slotFolderOpenAction( const QString& ); void slotFolderOpenAction( const QString& );
void slotSetProgress( const QString&, const QString&, long, long ); void slotSetProgress( Progress::Kind, const QString&, const QString&, long, long );
void slotUpdateQuota( qint64,qint64 ); void slotUpdateQuota( qint64,qint64 );
protected slots: protected slots:

View file

@ -134,6 +134,8 @@ Application::Application(int &argc, char **argv) :
setQuitOnLastWindowClosed(false); setQuitOnLastWindowClosed(false);
qRegisterMetaType<Progress::Kind>("Progress::Kind");
#if 0 #if 0
#if QT_VERSION >= 0x040700 #if QT_VERSION >= 0x040700
qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline"); qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");

View file

@ -315,11 +315,12 @@ void CSyncThread::startSync()
// cleans up behind us and emits finished() to ease error handling // cleans up behind us and emits finished() to ease error handling
CSyncRunScopeHelper helper(_csync_ctx, this); CSyncRunScopeHelper helper(_csync_ctx, this);
csync_set_progress_callback( _csync_ctx, cb_progress );
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
csync_set_userdata(_csync_ctx, this); csync_set_userdata(_csync_ctx, this);
// csync_set_auth_callback( _csync_ctx, getauth ); // csync_set_auth_callback( _csync_ctx, getauth );
csync_set_progress_callback( _csync_ctx, progress );
qDebug() << "#### Update start #################################################### >>"; qDebug() << "#### Update start #################################################### >>";
if( csync_update(_csync_ctx) < 0 ) { if( csync_update(_csync_ctx) < 0 ) {
@ -373,14 +374,24 @@ void CSyncThread::startSync()
qDebug() << Q_FUNC_INFO << "Sync finished"; qDebug() << Q_FUNC_INFO << "Sync finished";
} }
void CSyncThread::progress(const char *remote_url, enum csync_notify_type_e kind, void CSyncThread::cb_progress(const char *remote_url, enum csync_notify_type_e kind,
long long o1, long long o2, void *userdata) long long o1, long long o2, void *userdata)
{ {
(void) o1; (void) o2; QString path = QUrl::fromEncoded(remote_url).toString();
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
if (kind == CSYNC_NOTIFY_FINISHED_DOWNLOAD) { if (kind == CSYNC_NOTIFY_FINISHED_DOWNLOAD) {
QString path = QUrl::fromEncoded(remote_url).toString();
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
thread->fileReceived(path); thread->fileReceived(path);
} else if( kind == CSYNC_NOTIFY_START_UPLOAD ) {
thread->transmissionProgress( Progress::StartUpload, path, (long)0, (long)0 ); // indicate the upload start.
} else if( kind == CSYNC_NOTIFY_PROGRESS ) {
thread->transmissionProgress( Progress::Context, path, o1, o2 );
} else if( kind == CSYNC_NOTIFY_FINISHED_UPLOAD ) {
thread->transmissionProgress( Progress::EndUpload, path, o2, o2 );
} else if( kind == CSYNC_NOTIFY_START_DOWNLOAD ) {
thread->transmissionProgress( Progress::StartDownload, path, 0, 0 );
} else if( kind == CSYNC_NOTIFY_FINISHED_DOWNLOAD ) {
thread->transmissionProgress( Progress::EndDownload, path, o2, o2 );
} }
} }

View file

@ -26,6 +26,7 @@
#include <csync.h> #include <csync.h>
#include "mirall/syncfileitem.h" #include "mirall/syncfileitem.h"
#include "mirall/progressdispatcher.h"
class QProcess; class QProcess;
@ -50,6 +51,8 @@ signals:
void csyncUnavailable(); void csyncUnavailable();
void treeWalkResult(const SyncFileItemVector&); void treeWalkResult(const SyncFileItemVector&);
void transmissionProgress( Progress::Kind, const QString&, long, long);
void csyncStateDbFile( const QString& ); void csyncStateDbFile( const QString& );
void wipeDb(); void wipeDb();
@ -60,10 +63,10 @@ signals:
private: private:
void handleSyncError(CSYNC *ctx, const char *state); void handleSyncError(CSYNC *ctx, const char *state);
static void progress(const char *remote_url, static void cb_progress(const char *remote_url,
enum csync_notify_type_e kind, enum csync_notify_type_e kind,
long long o1, long long o2, long long o1, long long o2,
void *userdata); void *userdata);
static int treewalkLocal( TREE_WALK_FILE*, void *); static int treewalkLocal( TREE_WALK_FILE*, void *);
static int treewalkRemote( TREE_WALK_FILE*, void *); static int treewalkRemote( TREE_WALK_FILE*, void *);

View file

@ -19,6 +19,7 @@
#include "mirall/credentialstore.h" #include "mirall/credentialstore.h"
#include "mirall/logger.h" #include "mirall/logger.h"
#include "mirall/utility.h" #include "mirall/utility.h"
#include "mirall/progressdispatcher.h"
#include <csync.h> #include <csync.h>
@ -152,8 +153,6 @@ void ownCloudFolder::setProxy()
csync_set_module_property(_csync_ctx, "proxy_port", &proxyPort ); csync_set_module_property(_csync_ctx, "proxy_port", &proxyPort );
csync_set_module_property(_csync_ctx, "proxy_user", proxy.user().toUtf8().data() ); csync_set_module_property(_csync_ctx, "proxy_user", proxy.user().toUtf8().data() );
csync_set_module_property(_csync_ctx, "proxy_pwd" , proxy.password().toUtf8().data() ); csync_set_module_property(_csync_ctx, "proxy_pwd" , proxy.password().toUtf8().data() );
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
} }
} }
@ -307,6 +306,8 @@ void ownCloudFolder::startSync(const QStringList &pathList)
//blocking connection so the message box happens in this thread, but block the csync thread. //blocking connection so the message box happens in this thread, but block the csync thread.
connect(_csync, SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), connect(_csync, SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)),
SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), Qt::BlockingQueuedConnection); SLOT(slotAboutToRemoveAllFiles(SyncFileItem::Direction,bool*)), Qt::BlockingQueuedConnection);
connect(_csync, SIGNAL(transmissionProgress(Progress::Kind, QString,long,long)),
SLOT(slotTransmissionProgress(Progress::Kind, QString,long,long)));
_thread->start(); _thread->start();
QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection); QMetaObject::invokeMethod(_csync, "startSync", Qt::QueuedConnection);
@ -411,6 +412,24 @@ void ownCloudFolder::slotLocalPathChanged( const QString& dir )
} }
} }
void ownCloudFolder::slotTransmissionProgress(Progress::Kind kind, const QString& file ,long p1, long p2)
{
if( kind == Progress::StartDownload ) {
_progressKind = Progress::Download;
}
if( kind == Progress::StartUpload ) {
_progressKind = Progress::Upload;
}
// qDebug() << "Upload Progress: " << file << p1 << p2;
ProgressDispatcher::instance()->setFolderProgress( _progressKind, alias(), file, p1, p2 );
if( kind == Progress::EndDownload || kind == Progress::EndUpload ) {
_progressKind = Progress::Inactive;
}
}
// This removes the csync File database if the sync folder definition is removed // This removes the csync File database if the sync folder definition is removed
// permanentely. This is needed to provide a clean startup again in case another // permanentely. This is needed to provide a clean startup again in case another
// local folder is synced to the same ownCloud. // local folder is synced to the same ownCloud.

View file

@ -21,6 +21,7 @@
#include "mirall/folder.h" #include "mirall/folder.h"
#include "mirall/csyncthread.h" #include "mirall/csyncthread.h"
#include "mirall/progressdispatcher.h"
class QProcess; class QProcess;
class QTimer; class QTimer;
@ -89,6 +90,8 @@ private slots:
void slotCsyncUnavailable(); void slotCsyncUnavailable();
void slotCSyncFinished(); void slotCSyncFinished();
void slotTransmissionProgress(Progress::Kind, const QString&,long, long);
private: private:
static int getauth(const char *prompt, static int getauth(const char *prompt,
char *buf, char *buf,
@ -109,6 +112,7 @@ private:
bool _csyncUnavail; bool _csyncUnavail;
bool _wipeDb; bool _wipeDb;
SyncFileItemVector _items; SyncFileItemVector _items;
Progress::Kind _progressKind;
CSYNC *_csync_ctx; CSYNC *_csync_ctx;
}; };

View file

@ -0,0 +1,46 @@
/*
* 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"
#include <QMetaType>
namespace Mirall {
ProgressDispatcher* ProgressDispatcher::_instance = 0;
ProgressDispatcher* ProgressDispatcher::instance() {
if (!_instance) {
_instance = new ProgressDispatcher();
}
return _instance;
}
ProgressDispatcher::ProgressDispatcher(QObject *parent) :
QObject(parent)
{
}
ProgressDispatcher::~ProgressDispatcher()
{
}
void ProgressDispatcher::setFolderProgress( Progress::Kind kind, const QString& alias, const QString& folder, long p1, long p2)
{
emit folderProgress( kind, alias, folder, p1, p2 );
}
}

View file

@ -0,0 +1,63 @@
/*
* 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.
*/
#ifndef PROGRESSDISPATCHER_H
#define PROGRESSDISPATCHER_H
#include <QObject>
namespace Mirall {
/**
* @brief The FolderScheduler class schedules folders for sync
*/
class Progress
{
public:
enum ProgressKind_s {
Download,
Upload,
Context,
Inactive,
StartDownload,
StartUpload,
EndDownload,
EndUpload
};
typedef ProgressKind_s Kind;
};
class ProgressDispatcher : public QObject
{
Q_OBJECT
public:
static ProgressDispatcher* instance();
~ProgressDispatcher();
public:
void setFolderProgress( Progress::Kind, const QString&, const QString&, long, long );
signals:
void folderProgress( Progress::Kind, const QString&, const QString&, long, long );
public slots:
private:
ProgressDispatcher(QObject* parent = 0);
static ProgressDispatcher* _instance;
};
}
#endif // PROGRESSDISPATCHER_H

View file

@ -20,6 +20,7 @@
#include "mirall/application.h" #include "mirall/application.h"
#include "mirall/ignorelisteditor.h" #include "mirall/ignorelisteditor.h"
#include "mirall/mirallconfigfile.h" #include "mirall/mirallconfigfile.h"
#include "mirall/progressdispatcher.h"
#include <QLabel> #include <QLabel>
#include <QStandardItemModel> #include <QStandardItemModel>
@ -71,6 +72,12 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent) :
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)), connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
app, SLOT(slotFolderOpenAction(QString))); app, SLOT(slotFolderOpenAction(QString)));
connect( ProgressDispatcher::instance(), SIGNAL(folderProgress(Progress::Kind, QString,QString,long,long)),
this, SLOT(slotFolderProgress(Progress::Kind, QString,QString,long,long)));
connect(ProgressDispatcher::instance(), SIGNAL(shortFolderProgress(QString, QString)),
this, SLOT(slotShortFolderProgress(QString, QString)));
_ui->labelWidget->setCurrentRow(_ui->labelWidget->row(general)); _ui->labelWidget->setCurrentRow(_ui->labelWidget->row(general));
connect(_ui->labelWidget, SIGNAL(currentRowChanged(int)), connect(_ui->labelWidget, SIGNAL(currentRowChanged(int)),
@ -98,10 +105,10 @@ void SettingsDialog::addAccount(const QString &title, QWidget *widget)
} }
void SettingsDialog::slotFolderUploadProgress( const QString& folderAlias, const QString& file, long p1, long p2) void SettingsDialog::slotFolderProgress( Progress::Kind kind, const QString& folderAlias, const QString& file, long p1, long p2)
{ {
qDebug() << " SettingsDialog: XX - File " << file << p1 << p2; qDebug() << " SettingsDialog: XXOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO - File " << file << p1 << p2;
_accountSettings->slotSetProgress(folderAlias, file, p1, p2); _accountSettings->slotSetProgress(kind, folderAlias, file, p1, p2);
} }
void SettingsDialog::closeEvent(QCloseEvent *event) void SettingsDialog::closeEvent(QCloseEvent *event)

View file

@ -17,6 +17,8 @@
#include <QDialog> #include <QDialog>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include "mirall/progressdispatcher.h"
class QStandardItemModel; class QStandardItemModel;
class QListWidgetItem; class QListWidgetItem;
@ -41,7 +43,7 @@ public slots:
// Progress, parameter is // Progress, parameter is
// - filename // - filename
// - progress bytes, overall size. // - progress bytes, overall size.
void slotFolderUploadProgress( const QString&, const QString&, long, long ); void slotFolderProgress( Progress::Kind, const QString&, const QString&, long, long );
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);