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 06e612f commit a83446c
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ set(client_SRCS
translations.cpp
creds/httpcredentialsgui.cpp
updateurldialog.cpp
removeallfileswidget.cpp

models/activitylistmodel.cpp
models/expandingheaderview.cpp
Expand Down
49 changes: 16 additions & 33 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "filesystem.h"
#include "folderman.h"
#include "folderwatcher.h"
#include "gui/accountmodalwidget.h"
#include "gui/accountsettings.h"
#include "gui/removeallfileswidget.h"
#include "libsync/graphapi/spacesmanager.h"
#include "localdiscoverytracker.h"
#include "scheduling/syncscheduler.h"
Expand All @@ -45,14 +47,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 +1226,15 @@ 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.");
}
}();
_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);

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 AccountModalWidget(tr("Remove All Files?"), new RemoveAllFilesWidget(direction, 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 +1252,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
47 changes: 47 additions & 0 deletions src/gui/removeallfileswidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*/
#include "removeallfileswidget.h"
#include "ui_removeallfileswidget.h"

#include "resources/resources.h"

using namespace OCC;

RemoveAllFilesWidget::RemoveAllFilesWidget(SyncFileItem::Direction direction, const QString &path, QWidget *parent)
: QWidget(parent)
, ui(new Ui::RemoveAllFilesWidget)
{
ui->setupUi(this);

ui->trashIcon->setPixmap(Resources::getCoreIcon(QStringLiteral("delete")).pixmap({128, 128}));
if (direction == SyncFileItem::Down) {
ui->label->setText(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.")
.arg(path));
} else {
ui->label->setText(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.")
.arg(path));
}
}

RemoveAllFilesWidget::~RemoveAllFilesWidget()
{
delete ui;
}
40 changes: 40 additions & 0 deletions src/gui/removeallfileswidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.
*/

#pragma once

#include "gui/accountmodalwidget.h"
#include "libsync/syncfileitem.h"

#include <QWidget>

namespace OCC {

namespace Ui {
class RemoveAllFilesWidget;
}


class RemoveAllFilesWidget : public QWidget
{
Q_OBJECT

public:
explicit RemoveAllFilesWidget(SyncFileItem::Direction direction, const QString &path, QWidget *parent = nullptr);
~RemoveAllFilesWidget();

private:
Ui::RemoveAllFilesWidget *ui;
};
}
88 changes: 88 additions & 0 deletions src/gui/removeallfileswidget.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OCC::RemoveAllFilesWidget</class>
<widget class="QWidget" name="OCC::RemoveAllFilesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="trashIcon">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../../../../../../../_/30b36579/owncloud-client/src/resources/client.qrc">:/client/resources/light/delete.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="../../../../../../../_/30b36579/owncloud-client/src/resources/client.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit a83446c

Please sign in to comment.