Add functions to request overriding/reverting folders

This commit is contained in:
Martchus 2023-02-03 12:40:12 +01:00
parent 46c2333230
commit 8d7cfbe0ad
2 changed files with 72 additions and 0 deletions

View File

@ -240,6 +240,8 @@ public Q_SLOTS:
void requestDiskEvents(int limit = 25);
void requestQrCode(const QString &text);
void requestLog();
void requestOverride(const QString &dirId);
void requestRevert(const QString &dirId);
void postConfigFromJsonObject(const QJsonObject &rawConfig);
void postConfigFromByteArray(const QByteArray &rawConfig);
@ -276,6 +278,8 @@ Q_SIGNALS:
void shutdownTriggered();
void logAvailable(const std::vector<SyncthingLogEntry> &logEntries);
void qrCodeAvailable(const QString &text, const QByteArray &qrCodeData);
void overrideTriggered(const QString &dirId);
void revertTriggered(const QString &dirId);
private Q_SLOTS:
// handler to evaluate results from request...() methods
@ -327,6 +331,8 @@ private Q_SLOTS:
void readChangeEvent(CppUtilities::DateTime eventTime, const QString &eventType, const QJsonObject &eventData);
void readLog();
void readQrCode();
void readOverride();
void readRevert();
// internal helper methods
void continueConnecting();

View File

@ -1426,6 +1426,72 @@ void SyncthingConnection::readLog()
}
}
/*!
* \brief Request the override of the send only folder with the specified \a dirId.
* \remarks
* - Override means to make the local version latest, overriding changes made on other devices.
* - This call does nothing if the folder is not a send only folder.
*/
void SyncthingConnection::requestOverride(const QString &dirId)
{
auto query = QUrlQuery();
query.addQueryItem(QStringLiteral("folder"), dirId);
auto *const reply = postData(QStringLiteral("db/override"), query);
reply->setProperty("dirId", dirId);
QObject::connect(reply, &QNetworkReply::finished, this, &SyncthingConnection::readOverride, Qt::QueuedConnection);
}
/*!
* \brief Reads data from requestOverride().
*/
void SyncthingConnection::readOverride()
{
auto const [reply, response] = prepareReply(false);
if (!reply) {
return;
}
switch (reply->error()) {
case QNetworkReply::NoError:
emit overrideTriggered(reply->property("dirId").toString());
break;
default:
emitError(tr("Unable to request directory override: "), SyncthingErrorCategory::SpecificRequest, reply);
}
}
/*!
* \brief Request the revert of the receive only folder with the specified \a dirId.
* \remarks
* - Reverting a folder means to undo all local changes.
* - This call does nothing if the folder is not a receive only folder.
*/
void SyncthingConnection::requestRevert(const QString &dirId)
{
auto query = QUrlQuery();
query.addQueryItem(QStringLiteral("folder"), dirId);
auto *const reply = postData(QStringLiteral("db/revert"), query);
reply->setProperty("dirId", dirId);
QObject::connect(reply, &QNetworkReply::finished, this, &SyncthingConnection::readRevert, Qt::QueuedConnection);
}
/*!
* \brief Reads data from requestOverride().
*/
void SyncthingConnection::readRevert()
{
auto const [reply, response] = prepareReply(false);
if (!reply) {
return;
}
switch (reply->error()) {
case QNetworkReply::NoError:
emit revertTriggered(reply->property("dirId").toString());
break;
default:
emitError(tr("Unable to request directory revert: "), SyncthingErrorCategory::SpecificRequest, reply);
}
}
// post config
/*!