Skip to content

Commit

Permalink
show errors on lock/unlock actions
Browse files Browse the repository at this point in the history
use a native dialog to show users errors when trying to lock/unlock
files

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Apr 20, 2022
1 parent ee69dcf commit 9f53c5e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,19 @@ QString Folder::fileFromLocalPath(const QString &localPath) const
void Folder::setLockFileState(const QString &serverRelativePath, const SyncFileItem::LockStatus lock)
{
const auto job = new LockFileJob(accountState()->account(), &_journal, serverRelativePath, lock);
connect(job, &LockFileJob::finishedWithError, [lock, serverRelativePath](const int httpErrorCode, const QString &errorString, const QString &lockOwnerName) {
auto errorMessage = QString{};
const auto filePath = serverRelativePath.mid(1);

if (httpErrorCode == LockFileJob::LOCKED_HTTP_ERROR_CODE) {
errorMessage = tr("File %1 is already locked by %2.").arg(filePath, lockOwnerName);
} else if (lock == SyncFileItem::LockStatus::LockedItem) {
errorMessage = tr("Lock operation on %1 failed with error %2").arg(filePath, errorString);
} else if (lock == SyncFileItem::LockStatus::UnlockedItem) {
errorMessage = tr("Unlock operation on %1 failed with error %2").arg(filePath, errorString);
}
emit Systray::instance()->showErrorMessageDialog(errorMessage);
});
job->start();
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Systray
void openShareDialog(const QString &sharePath, const QString &localPath);
void showFileActivityDialog(const QString &objectName, const int objectId);
void sendChatMessage(const QString &token, const QString &message, const QString &replyTo);
void showErrorMessageDialog(const QString &error);

public slots:
void slotNewUserSelected();
Expand Down
20 changes: 20 additions & 0 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import QtQuick.Window 2.3
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
import Qt.labs.platform 1.1 as NativeDialogs
import "../"

// Custom qml modules are in /theme (and included by resources.qrc)
Expand Down Expand Up @@ -62,6 +63,19 @@ Window {
}
}

Component {
id: errorMessageDialog

NativeDialogs.MessageDialog {
id: dialog

title: Systray.windowTitle

onAccepted: destroy()
onRejected: destroy()
}
}

Connections {
target: Systray
function onShowWindow() {
Expand All @@ -84,6 +98,12 @@ Window {
function onShowFileActivityDialog(objectName, objectId) {
openFileActivityDialog(objectName, objectId)
}

function onShowErrorMessageDialog(error) {
var newErrorDialog = errorMessageDialog.createObject(trayWindow)
newErrorDialog.text = error
newErrorDialog.open()
}
}

OpacityMask {
Expand Down

0 comments on commit 9f53c5e

Please sign in to comment.