nextcloud-desktop/src/mirall/owncloudpropagator.h
Olivier Goffart 127055dd70 Refactor a bit the error reporting from the propagator
Add different classes of error failures.
Fatal error means the sync should be stopped.
SoftErrors are not to be displayed to the user.

We still need to make a classification of the errors.
2013-10-04 15:55:59 +02:00

101 lines
3.1 KiB
C++

/*
* Copyright (C) by Olivier Goffart <ogoffart@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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 OWNCLOUDPROPAGATOR_H
#define OWNCLOUDPROPAGATOR_H
#include <neon/ne_request.h>
#include <QHash>
#include <QObject>
#include <qelapsedtimer.h>
#include "syncfileitem.h"
#include "progressdispatcher.h"
struct ne_session_s;
struct ne_decompress_s;
namespace Mirall {
class ProgressDatabase;
class OwncloudPropagator : public QObject {
Q_OBJECT
ne_session_s *_session;
QString _localDir; // absolute path to the local directory. ends with '/'
QString _remoteDir; // path to the root of the remote. ends with '/'
ProgressDatabase *_progressDb;
QString _errorString;
SyncFileItem::Status _status;
bool check_neon_session();
csync_instructions_e localRemove(const SyncFileItem &);
csync_instructions_e localMkdir(const SyncFileItem &);
csync_instructions_e remoteRemove(const SyncFileItem &);
csync_instructions_e remoteMkdir(const SyncFileItem &);
csync_instructions_e downloadFile(const SyncFileItem &, bool isConflict = false);
csync_instructions_e uploadFile(const SyncFileItem &);
csync_instructions_e remoteRename(const SyncFileItem &);
void updateMTimeAndETag(const char *uri, time_t);
/* fetch the error code and string from the session
* updates _status, _httpStatusCode and _errorString. and httpStatusCode
* Returns true if there was an error.
*/
bool updateErrorFromSession(int neon_code = 0, ne_request *req = 0, int *httpStatusCode = 0);
QElapsedTimer _lastTime;
quint64 _lastProgress;
quint64 _chunked_total_size;
quint64 _chunked_done;
QString _currentFile;
static void notify_status_cb (void *userdata, ne_session_status status,
const ne_session_status_info *info);
public:
OwncloudPropagator(ne_session_s *session, const QString &localDir, const QString &remoteDir,
ProgressDatabase *progressDb, QAtomicInt *abortRequested)
: _session(session)
, _localDir(localDir)
, _remoteDir(remoteDir)
, _progressDb(progressDb)
, _abortRequested(abortRequested)
{
if (!localDir.endsWith(QChar('/'))) _localDir+='/';
if (!remoteDir.endsWith(QChar('/'))) _remoteDir+='/';
}
void propagate(const SyncFileItem &);
QByteArray _etag;
int _downloadLimit;
int _uploadLimit;
QAtomicInt *_abortRequested; // boolean set by the main thread to abort.
signals:
void completed(const SyncFileItem &);
void progress(Progress::Kind, const QString &filename, quint64 bytes, quint64 total);
};
}
#endif