-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce new jobs to handle lock/unlock of files
close #4382 Signed-off-by: Matthieu Gallien <[email protected]>
- Loading branch information
Showing
6 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) by Matthieu Gallien <[email protected]> | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "ocslockfilejob.h" | ||
|
||
#include "account.h" | ||
|
||
namespace OCC { | ||
|
||
OcsLockFileJob::OcsLockFileJob(AccountPtr account) | ||
: OcsJob(account) | ||
{ | ||
setPath("ocs/v2.php/apps/files_lock/lock/"); | ||
} | ||
|
||
void OCC::OcsLockFileJob::acquireLock(int fileId) | ||
{ | ||
appendPath(QString::number(fileId)); | ||
setVerb("PUT"); | ||
|
||
start(); | ||
} | ||
|
||
void OcsLockFileJob::releaseLock(int fileId) | ||
{ | ||
appendPath(QString::number(fileId)); | ||
setVerb("DELETE"); | ||
|
||
start(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) by Matthieu Gallien <[email protected]> | ||
* | ||
* 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 OCSLOCKFILEJOB_H | ||
#define OCSLOCKFILEJOB_H | ||
|
||
#include "ocsjob.h" | ||
|
||
#include "accountfwd.h" | ||
|
||
#include <QObject> | ||
|
||
class QJsonDocument; | ||
|
||
namespace OCC { | ||
|
||
/** | ||
* @brief The OcsShareJob class | ||
* @ingroup gui | ||
* | ||
* Handle talking to the OCS Share API. | ||
* For creation, deletion and modification of shares. | ||
*/ | ||
class OcsLockFileJob : public OcsJob | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit OcsLockFileJob(AccountPtr account); | ||
|
||
void acquireLock(int fileId); | ||
|
||
void releaseLock(int fileId); | ||
}; | ||
|
||
} | ||
|
||
#endif // OCSLOCKFILEJOB_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) by Matthieu Gallien <[email protected]> | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "lockfilejobs.h" | ||
|
||
namespace OCC { | ||
|
||
LockFileJob::LockFileJob(AccountPtr account, | ||
const QString &path, | ||
SyncFileItem::LockStatus requestedLockState, | ||
QObject *parent) | ||
: AbstractNetworkJob(account, path, parent) | ||
, _requestedLockState(requestedLockState) | ||
{ | ||
} | ||
|
||
void LockFileJob::start() | ||
{ | ||
QNetworkRequest request; | ||
request.setRawHeader("X-User-Lock", "1"); | ||
|
||
QByteArray verb; | ||
switch(_requestedLockState) | ||
{ | ||
case SyncFileItem::LockedItem: | ||
verb = "LOCK"; | ||
break; | ||
case SyncFileItem::UnlockedItem: | ||
verb = "UNLOCK"; | ||
break; | ||
} | ||
sendRequest(verb, makeDavUrl(path()), request); | ||
|
||
AbstractNetworkJob::start(); | ||
} | ||
|
||
bool LockFileJob::finished() | ||
{ | ||
if (reply()->error() != QNetworkReply::NoError) { | ||
Q_EMIT finishedWithError(reply()); | ||
} else { | ||
Q_EMIT finishedWithoutError(); | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef LOCKFILEJOBS_H | ||
#define LOCKFILEJOBS_H | ||
|
||
#include "abstractnetworkjob.h" | ||
|
||
#include "syncfileitem.h" | ||
|
||
namespace OCC { | ||
|
||
class OWNCLOUDSYNC_EXPORT LockFileJob : public AbstractNetworkJob | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit LockFileJob(AccountPtr account, | ||
const QString &path, | ||
SyncFileItem::LockStatus requestedLockState, | ||
QObject *parent = nullptr); | ||
void start() override; | ||
|
||
signals: | ||
void finishedWithError(QNetworkReply *reply); | ||
void finishedWithoutError(); | ||
|
||
private: | ||
bool finished() override; | ||
|
||
SyncFileItem::LockStatus _requestedLockState = SyncFileItem::LockStatus::LockedItem; | ||
}; | ||
|
||
} | ||
|
||
#endif // LOCKFILEJOBS_H |