Ask for confirmation before deleting files
This commit is contained in:
@@ -126,6 +126,26 @@ ColumnLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Dialog {
|
||||||
|
parent: window.overlay
|
||||||
|
x: (parent.width - width) / 2
|
||||||
|
y: (parent.height - height) / 2
|
||||||
|
title: qsTr("Following files will be deleted:")
|
||||||
|
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||||
|
onClosed: addon.confirmFileRemove(result == Dialog.Accepted)
|
||||||
|
modal: true
|
||||||
|
visible: addon.filesToRemove != ""
|
||||||
|
closePolicy: Popup.NoAutoClose
|
||||||
|
ScrollView{
|
||||||
|
anchors.fill: parent
|
||||||
|
TextArea {
|
||||||
|
text: addon.filesToRemove
|
||||||
|
readOnly: true
|
||||||
|
anchors.fill: parent
|
||||||
|
wrapMode: Text.NoWrap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScrollBar {id: scrollBar; Layout.fillHeight: true; visible: listView.contentHeight > listView.header}
|
ScrollBar {id: scrollBar; Layout.fillHeight: true; visible: listView.contentHeight > listView.header}
|
||||||
|
|||||||
@@ -354,28 +354,38 @@ void Addon::setSubfolders(QStringList subfolders)
|
|||||||
|
|
||||||
void walkFolders(QFileInfo &info, auto f){
|
void walkFolders(QFileInfo &info, auto f){
|
||||||
if (info.isDir() && !info.isSymLink()) {
|
if (info.isDir() && !info.isSymLink()) {
|
||||||
foreach (QFileInfo sub, QDir(info.filePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden))
|
foreach (QFileInfo sub, QDir(info.absoluteFilePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden))
|
||||||
walkFolders(sub, f);
|
walkFolders(sub, f);
|
||||||
}
|
}
|
||||||
f(info);
|
f(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Addon::removeFolder(QString path) {
|
void Addon::removeFolder(QString path, bool ask) {
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
|
QStringList files;
|
||||||
|
bool ok = ask;
|
||||||
if (info.exists()) {
|
if (info.exists()) {
|
||||||
int i = 0;
|
walkFolders(info, [&files](QFileInfo info){
|
||||||
walkFolders(info, [ &i](QFileInfo /*info*/){
|
files << info.absoluteFilePath();
|
||||||
i++;
|
|
||||||
});
|
|
||||||
emit totalChanged(i);
|
|
||||||
i = 0;
|
|
||||||
walkFolders(info, [this, &i](QFileInfo info){
|
|
||||||
if (!info.isSymLink() && info.isDir())
|
|
||||||
info.dir().rmdir(info.fileName());
|
|
||||||
else
|
|
||||||
QFile(info.filePath()).remove();
|
|
||||||
emit totalChanged(++i);
|
|
||||||
});
|
});
|
||||||
|
if (ask) {
|
||||||
|
m_mutex.lock();
|
||||||
|
m_result = &ok;
|
||||||
|
QMetaObject::invokeMethod(this, "setFilesToRemove", Q_ARG(QString, files.join('\n')));
|
||||||
|
m_wait.wait(&m_mutex);
|
||||||
|
m_mutex.unlock();
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
emit totalChanged(files.size());
|
||||||
|
for (int i = 0; i < files.size(); i++) {
|
||||||
|
QFileInfo info(files[i]);
|
||||||
|
if (!info.isSymLink() && info.isDir())
|
||||||
|
info.dir().rmdir(info.fileName());
|
||||||
|
else
|
||||||
|
QFile(info.absoluteFilePath()).remove();
|
||||||
|
emit totalChanged(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,6 +454,23 @@ void Addon::unpackSubfolders(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Addon::setFilesToRemove(QString filesToRemove)
|
||||||
|
{
|
||||||
|
if (m_filesToRemove == filesToRemove)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_filesToRemove = filesToRemove;
|
||||||
|
emit filesToRemoveChanged(m_filesToRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Addon::confirmFileRemove(bool confirmed)
|
||||||
|
{
|
||||||
|
m_mutex.lock();
|
||||||
|
*static_cast<bool *>(m_result) = confirmed;
|
||||||
|
m_wait.wakeOne();
|
||||||
|
m_mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
QStringList Addon::branches() const
|
QStringList Addon::branches() const
|
||||||
{
|
{
|
||||||
return m_branches;
|
return m_branches;
|
||||||
@@ -489,6 +516,11 @@ QStringList Addon::subfolders() const
|
|||||||
return m_subfolders;
|
return m_subfolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Addon::filesToRemove() const
|
||||||
|
{
|
||||||
|
return m_filesToRemove;
|
||||||
|
}
|
||||||
|
|
||||||
void Addon::closeRepo()
|
void Addon::closeRepo()
|
||||||
{
|
{
|
||||||
m_repo.reset();
|
m_repo.reset();
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QWaitCondition>
|
||||||
|
|
||||||
class git_repository;
|
class git_repository;
|
||||||
using repo_p = std::unique_ptr<git_repository, void(*)(git_repository *)>;
|
using repo_p = std::unique_ptr<git_repository, void(*)(git_repository *)>;
|
||||||
@@ -49,6 +51,9 @@ class Addon : public QObject
|
|||||||
|
|
||||||
int m_total;
|
int m_total;
|
||||||
|
|
||||||
|
QMutex m_mutex;
|
||||||
|
QWaitCondition m_wait;
|
||||||
|
void *m_result;
|
||||||
public:
|
public:
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
Q_PROPERTY(QStringList branches READ branches WRITE setBranches NOTIFY branchesChanged)
|
Q_PROPERTY(QStringList branches READ branches WRITE setBranches NOTIFY branchesChanged)
|
||||||
@@ -58,6 +63,7 @@ public:
|
|||||||
Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged)
|
Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged)
|
||||||
Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged)
|
Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged)
|
||||||
Q_PROPERTY(QStringList subfolders READ subfolders WRITE setSubfolders NOTIFY subfoldersChanged)
|
Q_PROPERTY(QStringList subfolders READ subfolders WRITE setSubfolders NOTIFY subfoldersChanged)
|
||||||
|
Q_PROPERTY(QString filesToRemove READ filesToRemove WRITE setFilesToRemove NOTIFY filesToRemoveChanged)
|
||||||
|
|
||||||
enum class Status {
|
enum class Status {
|
||||||
Error = -1,
|
Error = -1,
|
||||||
@@ -105,6 +111,8 @@ public:
|
|||||||
|
|
||||||
QStringList subfolders() const;
|
QStringList subfolders() const;
|
||||||
|
|
||||||
|
QString filesToRemove() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Status m_status;
|
Status m_status;
|
||||||
@@ -122,7 +130,9 @@ private:
|
|||||||
|
|
||||||
QThreadPool *m_pool;
|
QThreadPool *m_pool;
|
||||||
|
|
||||||
void removeFolder(QString path);
|
void removeFolder(QString path, bool ask = true);
|
||||||
|
QString m_filesToRemove;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void nameChanged(QString name);
|
void nameChanged(QString name);
|
||||||
@@ -145,6 +155,8 @@ signals:
|
|||||||
|
|
||||||
void subfoldersChanged(QStringList subfolders);
|
void subfoldersChanged(QStringList subfolders);
|
||||||
|
|
||||||
|
void filesToRemoveChanged(QString filesToRemove);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
void update();
|
void update();
|
||||||
@@ -164,6 +176,8 @@ public slots:
|
|||||||
void setSubfolders(QStringList subfolders);
|
void setSubfolders(QStringList subfolders);
|
||||||
void removeSubfolders();
|
void removeSubfolders();
|
||||||
void unpackSubfolders();
|
void unpackSubfolders();
|
||||||
|
void setFilesToRemove(QString filesToRemove);
|
||||||
|
void confirmFileRemove(bool confirmed);
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Addon::GitStatus)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Addon::GitStatus)
|
||||||
|
|||||||
Reference in New Issue
Block a user