Skip to content

Commit

Permalink
Update remove all dialog to use AccountModalWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Mar 26, 2024
1 parent 974f0db commit 8f20f8d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ qt_add_qml_module(owncloudCore
QML_FILES
qml/FolderDelegate.qml
qml/FolderError.qml
qml/RemoveAllFiles.qml
)

target_link_libraries(owncloudCore PUBLIC owncloudCoreplugin)
Expand Down
30 changes: 30 additions & 0 deletions src/gui/accountmodalwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,39 @@
#include "accountmodalwidget.h"
#include "ui_accountmodalwidget.h"

#include "resources/resources.h"

#include <QMessageBox>
#include <QPushButton>
#include <QQuickWidget>

namespace OCC {

namespace {
auto *createQmlWidget(const QUrl &url, const QList<QQmlContext::PropertyPair> &properties)
{
auto *widget = new QQuickWidget;
widget->engine()->rootContext()->setContextProperties(properties);
widget->engine()->addImageProvider(QStringLiteral("ownCloud"), new Resources::CoreImageProvider());
widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget->setSource(url);
if (!widget->errors().isEmpty()) {
auto box = new QMessageBox(QMessageBox::Critical, QStringLiteral("QML Error"), QDebug::toString(widget->errors()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
qFatal("A qml error occured %s", qPrintable(QDebug::toString(widget->errors())));
}
return widget;
}
}

AccountModalWidget::AccountModalWidget(
const QString &title, const QUrl &qmlSrc, const QList<QQmlContext::PropertyPair> &properties, const QList<Button> &buttons, QWidget *parent)
: AccountModalWidget(title, createQmlWidget(qmlSrc, properties), buttons, parent)
{
}


AccountModalWidget::AccountModalWidget(const QString &title, QWidget *widget, const QList<Button> &buttons, QWidget *parent)
: QWidget(parent)
, ui(new Ui::AccountModalWidget)
Expand Down
5 changes: 5 additions & 0 deletions src/gui/accountmodalwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
*/

#pragma once

#include <QDialogButtonBox>
#include <QQmlContext>
#include <QWidget>


namespace OCC {

namespace Ui {
Expand All @@ -28,6 +31,8 @@ class AccountModalWidget : public QWidget
public:
using Button = QPair<QPushButton *, QDialogButtonBox::ButtonRole>;

AccountModalWidget(const QString &title, const QUrl &qmlSrc, const QList<QQmlContext::PropertyPair> &properties, const QList<Button> &buttons = {},
QWidget *parent = nullptr);
AccountModalWidget(const QString &title, QWidget *widget, const QList<Button> &buttons = {}, QWidget *parent = nullptr);

QDialogButtonBox *buttons();
Expand Down
48 changes: 16 additions & 32 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "filesystem.h"
#include "folderman.h"
#include "folderwatcher.h"
#include "gui/accountmodalwidget.h"
#include "gui/accountsettings.h"
#include "libsync/graphapi/spacesmanager.h"
#include "localdiscoverytracker.h"
Expand All @@ -45,14 +46,12 @@
#include "common/utility_win.h"
#endif

#include <QTimer>
#include <QUrl>
#include <QApplication>
#include <QDir>
#include <QSettings>

#include <QMessageBox>
#include <QPushButton>
#include <QApplication>
#include <QSettings>
#include <QTimer>
#include <QUrl>

using namespace std::chrono_literals;

Expand Down Expand Up @@ -1226,29 +1225,17 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
ownCloudGui::raise();
return;
}
const QString msg = [direction] {
if (direction == SyncFileItem::Down) {
return tr("All files in the sync folder '%1' folder were deleted on the server.\n"
"These deletes will be synchronized to your local sync folder, making such files "
"unavailable unless you have a right to restore. \n"
"If you decide to keep the files, they will be re-synced with the server if you have rights to do so.\n"
"If you decide to delete the files, they will be unavailable to you, unless you are the owner.");
} else {
return tr("All the files in your local sync folder '%1' were deleted. These deletes will be "
"synchronized with your server, making such files unavailable unless restored.\n"
"Are you sure you want to sync those actions with the server?\n"
"If this was an accident and you decide to keep your files, they will be re-synced from the server.");
}
}();

const QList<AccountModalWidget::Button> buttons = {
{new QPushButton(tr("Remove all files")), QDialogButtonBox::AcceptRole}, {new QPushButton(tr("Keep files")), QDialogButtonBox::RejectRole}};
QPushButton *keepBtn = buttons[1].first;
keepBtn->setDefault(true);

_removeAllFilesDialog =
new QMessageBox(QMessageBox::Warning, tr("Remove All Files?"), msg.arg(shortGuiLocalPath()), QMessageBox::NoButton, ocApp()->gui()->settingsDialog());
_removeAllFilesDialog->setAttribute(Qt::WA_DeleteOnClose);
_removeAllFilesDialog->setWindowFlags(_removeAllFilesDialog->windowFlags() | Qt::WindowStaysOnTopHint);
_removeAllFilesDialog->addButton(tr("Remove all files"), QMessageBox::DestructiveRole);
QPushButton *keepBtn = _removeAllFilesDialog->addButton(tr("Keep files"), QMessageBox::AcceptRole);
_removeAllFilesDialog->setDefaultButton(keepBtn);
new AccountModalWidget(tr("Remove All Files?"), QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/qmlcomponents/qml/RemoveAllFiles.qml")),
{{QStringLiteral("removedOnTheServer"), direction == SyncFileItem::Direction::Down}, {QStringLiteral("path"), shortGuiLocalPath()}}, buttons);
setSyncPaused(true);
connect(_removeAllFilesDialog, &QMessageBox::finished, this, [keepBtn, this] {
connect(_removeAllFilesDialog, &AccountModalWidget::finished, this, [keepBtn, this] {
if (_removeAllFilesDialog->clickedButton() == keepBtn) {
// reset the db upload all local files or download all remote files
FileSystem::setFolderMinimumPermissions(path());
Expand All @@ -1266,11 +1253,8 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction)
}
});
connect(this, &Folder::destroyed, _removeAllFilesDialog, &QMessageBox::deleteLater);
ocApp()
->gui()
->settingsDialog()
->accountSettings(_accountState->account().get())
->addModalLegacyDialog(_removeAllFilesDialog, AccountSettings::ModalWidgetSizePolicy::Minimum);

ocApp()->gui()->settingsDialog()->accountSettings(_accountState->account().get())->addModalWidget(_removeAllFilesDialog);
}

FolderDefinition::FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &spaceId, const QString &displayName)
Expand Down
3 changes: 2 additions & 1 deletion src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SyncEngine;
class SyncRunFileLog;
class FolderWatcher;
class LocalDiscoveryTracker;
class AccountModalWidget;

/**
* @brief The FolderDefinition class
Expand Down Expand Up @@ -517,7 +518,7 @@ private slots:
*/
QSharedPointer<Vfs> _vfs;

QPointer<QMessageBox> _removeAllFilesDialog;
QPointer<AccountModalWidget> _removeAllFilesDialog;

// allow that all files are removed in the next run
bool _allowRemoveAllOnce = false;
Expand Down
48 changes: 48 additions & 0 deletions src/gui/qml/RemoveAllFiles.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@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.
*/

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Pane {

//required property string path
//required property bool removedOnTheServer
GridLayout {
columns: 1
rows: 2

Image {
Layout.alignment: Qt.AlignCenter
source: "image://ownCloud/core/delete"
Layout.maximumHeight: 128
Layout.maximumWidth: 128
}

Label {
text: {
if (removedOnTheServer) {
return qsTr("All files in the sync folder '%1' folder were deleted on the server.\n" + //
"These deletes will be synchronized to your local sync folder, making such files unavailable unless you have a right to restore. \n" + //
"If you decide to keep the files, they will be re-synced with the server if you have rights to do so.\n" + //
"If you decide to delete the files, they will be unavailable to you, unless you are the owner.").arg(path);
}
return qsTr("All the files in your local sync folder '%1' were deleted. These deletes will be synchronized with your server, making such files unavailable unless restored.\n" + //
"Are you sure you want to sync those actions with the server?\n" + //
"If this was an accident and you decide to keep your files, they will be re-synced from the server.").arg(path);
}
}
}
}

0 comments on commit 8f20f8d

Please sign in to comment.