mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
Handle progress through ProgressDispatcher class, WIP.
This commit is contained in:
parent
eb39d144e4
commit
6b5b9db20a
12 changed files with 198 additions and 35 deletions
|
@ -76,6 +76,7 @@ set(libsync_SRCS
|
|||
mirall/logger.cpp
|
||||
mirall/utility.cpp
|
||||
mirall/connectionvalidator.cpp
|
||||
mirall/progressdispatcher.cpp
|
||||
)
|
||||
set(libsync_HEADERS
|
||||
mirall/folderman.h
|
||||
|
@ -89,6 +90,7 @@ set(libsync_HEADERS
|
|||
mirall/credentialstore.h
|
||||
mirall/logger.h
|
||||
mirall/connectionvalidator.h
|
||||
mirall/progressdispatcher.h
|
||||
)
|
||||
|
||||
IF( INOTIFY_FOUND )
|
||||
|
|
|
@ -459,25 +459,28 @@ void AccountSettings::slotOpenOC()
|
|||
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 ) {
|
||||
// // sync start
|
||||
// ui->progressBar->setMaximum( p2 );
|
||||
// ui->progressBar->setValue( p1 );
|
||||
// ui->progressBar->setEnabled(true);
|
||||
// ui->fileProgressLabel->setText(tr("Uploading %1").arg(file));
|
||||
// // ui->progressBar->show();
|
||||
// } else if( p1 == p2 ) {
|
||||
// // sync end
|
||||
// // ui->progressBar->setMaximum(0);
|
||||
// ui->progressBar->setValue(0);
|
||||
// ui->progressBar->setEnabled(false);
|
||||
// ui->fileProgressLabel->setText(tr("No activity."));
|
||||
// // ui->progressBar->hide();
|
||||
// } else {
|
||||
// ui->progressBar->setValue( p1 );
|
||||
// }
|
||||
qDebug() << "================================> Progress for folder " << folder << " file " << file << ": "<< p1;
|
||||
#if 0
|
||||
if( p1 == 0 && p2 > 0 ) {
|
||||
// sync start
|
||||
ui->progressBar->setMaximum( p2 );
|
||||
ui->progressBar->setValue( p1 );
|
||||
ui->progressBar->setEnabled(true);
|
||||
ui->fileProgressLabel->setText(tr("Uploading %1").arg(file));
|
||||
// ui->progressBar->show();
|
||||
} else if( p1 == p2 ) {
|
||||
// sync end
|
||||
// ui->progressBar->setMaximum(0);
|
||||
ui->progressBar->setValue(0);
|
||||
ui->progressBar->setEnabled(false);
|
||||
ui->fileProgressLabel->setText(tr("No activity."));
|
||||
// ui->progressBar->hide();
|
||||
} else {
|
||||
ui->progressBar->setValue( p1 );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <QPointer>
|
||||
|
||||
#include "mirall/folder.h"
|
||||
#include "mirall/progressdispatcher.h"
|
||||
|
||||
class QStandardItemModel;
|
||||
class QModelIndex;
|
||||
|
@ -61,7 +62,7 @@ public slots:
|
|||
void slotOCInfoFail( QNetworkReply* );
|
||||
void slotDoubleClicked( const QModelIndex& );
|
||||
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 );
|
||||
|
||||
protected slots:
|
||||
|
|
|
@ -134,6 +134,8 @@ Application::Application(int &argc, char **argv) :
|
|||
|
||||
setQuitOnLastWindowClosed(false);
|
||||
|
||||
qRegisterMetaType<Progress::Kind>("Progress::Kind");
|
||||
|
||||
#if 0
|
||||
#if QT_VERSION >= 0x040700
|
||||
qDebug() << "* Network is" << (_networkMgr->isOnline() ? "online" : "offline");
|
||||
|
|
|
@ -315,11 +315,12 @@ void CSyncThread::startSync()
|
|||
// cleans up behind us and emits finished() to ease error handling
|
||||
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_userdata(_csync_ctx, this);
|
||||
|
||||
// csync_set_auth_callback( _csync_ctx, getauth );
|
||||
csync_set_progress_callback( _csync_ctx, progress );
|
||||
|
||||
qDebug() << "#### Update start #################################################### >>";
|
||||
if( csync_update(_csync_ctx) < 0 ) {
|
||||
|
@ -373,14 +374,24 @@ void CSyncThread::startSync()
|
|||
qDebug() << Q_FUNC_INFO << "Sync finished";
|
||||
}
|
||||
|
||||
void CSyncThread::progress(const char *remote_url, enum csync_notify_type_e kind,
|
||||
long long o1, long long o2, void *userdata)
|
||||
void CSyncThread::cb_progress(const char *remote_url, enum csync_notify_type_e kind,
|
||||
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) {
|
||||
QString path = QUrl::fromEncoded(remote_url).toString();
|
||||
CSyncThread *thread = static_cast<CSyncThread*>(userdata);
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <csync.h>
|
||||
|
||||
#include "mirall/syncfileitem.h"
|
||||
#include "mirall/progressdispatcher.h"
|
||||
|
||||
class QProcess;
|
||||
|
||||
|
@ -50,6 +51,8 @@ signals:
|
|||
void csyncUnavailable();
|
||||
void treeWalkResult(const SyncFileItemVector&);
|
||||
|
||||
void transmissionProgress( Progress::Kind, const QString&, long, long);
|
||||
|
||||
void csyncStateDbFile( const QString& );
|
||||
void wipeDb();
|
||||
|
||||
|
@ -60,10 +63,10 @@ signals:
|
|||
|
||||
private:
|
||||
void handleSyncError(CSYNC *ctx, const char *state);
|
||||
static void progress(const char *remote_url,
|
||||
enum csync_notify_type_e kind,
|
||||
long long o1, long long o2,
|
||||
void *userdata);
|
||||
static void cb_progress(const char *remote_url,
|
||||
enum csync_notify_type_e kind,
|
||||
long long o1, long long o2,
|
||||
void *userdata);
|
||||
|
||||
static int treewalkLocal( TREE_WALK_FILE*, void *);
|
||||
static int treewalkRemote( TREE_WALK_FILE*, void *);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "mirall/credentialstore.h"
|
||||
#include "mirall/logger.h"
|
||||
#include "mirall/utility.h"
|
||||
#include "mirall/progressdispatcher.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_user", proxy.user().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.
|
||||
connect(_csync, SIGNAL(aboutToRemoveAllFiles(SyncFileItem::Direction,bool*)),
|
||||
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();
|
||||
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
|
||||
// permanentely. This is needed to provide a clean startup again in case another
|
||||
// local folder is synced to the same ownCloud.
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "mirall/folder.h"
|
||||
#include "mirall/csyncthread.h"
|
||||
#include "mirall/progressdispatcher.h"
|
||||
|
||||
class QProcess;
|
||||
class QTimer;
|
||||
|
@ -89,6 +90,8 @@ private slots:
|
|||
void slotCsyncUnavailable();
|
||||
void slotCSyncFinished();
|
||||
|
||||
void slotTransmissionProgress(Progress::Kind, const QString&,long, long);
|
||||
|
||||
private:
|
||||
static int getauth(const char *prompt,
|
||||
char *buf,
|
||||
|
@ -109,6 +112,7 @@ private:
|
|||
bool _csyncUnavail;
|
||||
bool _wipeDb;
|
||||
SyncFileItemVector _items;
|
||||
Progress::Kind _progressKind;
|
||||
|
||||
CSYNC *_csync_ctx;
|
||||
};
|
||||
|
|
46
src/mirall/progressdispatcher.cpp
Normal file
46
src/mirall/progressdispatcher.cpp
Normal 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 );
|
||||
}
|
||||
|
||||
}
|
63
src/mirall/progressdispatcher.h
Normal file
63
src/mirall/progressdispatcher.h
Normal 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
|
|
@ -20,6 +20,7 @@
|
|||
#include "mirall/application.h"
|
||||
#include "mirall/ignorelisteditor.h"
|
||||
#include "mirall/mirallconfigfile.h"
|
||||
#include "mirall/progressdispatcher.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStandardItemModel>
|
||||
|
@ -71,6 +72,12 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent) :
|
|||
connect( _accountSettings, SIGNAL(openFolderAlias(const 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));
|
||||
|
||||
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;
|
||||
_accountSettings->slotSetProgress(folderAlias, file, p1, p2);
|
||||
qDebug() << " SettingsDialog: XXOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO - File " << file << p1 << p2;
|
||||
_accountSettings->slotSetProgress(kind, folderAlias, file, p1, p2);
|
||||
}
|
||||
|
||||
void SettingsDialog::closeEvent(QCloseEvent *event)
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include <QDialog>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "mirall/progressdispatcher.h"
|
||||
|
||||
class QStandardItemModel;
|
||||
class QListWidgetItem;
|
||||
|
||||
|
@ -41,7 +43,7 @@ public slots:
|
|||
// Progress, parameter is
|
||||
// - filename
|
||||
// - progress bytes, overall size.
|
||||
void slotFolderUploadProgress( const QString&, const QString&, long, long );
|
||||
void slotFolderProgress( Progress::Kind, const QString&, const QString&, long, long );
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
|
Loading…
Reference in a new issue