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}
|
||||
|
||||
@@ -354,28 +354,38 @@ void Addon::setSubfolders(QStringList subfolders)
|
||||
|
||||
void walkFolders(QFileInfo &info, auto f){
|
||||
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);
|
||||
}
|
||||
f(info);
|
||||
}
|
||||
|
||||
void Addon::removeFolder(QString path) {
|
||||
void Addon::removeFolder(QString path, bool ask) {
|
||||
QFileInfo info(path);
|
||||
QStringList files;
|
||||
bool ok = ask;
|
||||
if (info.exists()) {
|
||||
int i = 0;
|
||||
walkFolders(info, [ &i](QFileInfo /*info*/){
|
||||
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);
|
||||
walkFolders(info, [&files](QFileInfo info){
|
||||
files << info.absoluteFilePath();
|
||||
});
|
||||
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
|
||||
{
|
||||
return m_branches;
|
||||
@@ -489,6 +516,11 @@ QStringList Addon::subfolders() const
|
||||
return m_subfolders;
|
||||
}
|
||||
|
||||
QString Addon::filesToRemove() const
|
||||
{
|
||||
return m_filesToRemove;
|
||||
}
|
||||
|
||||
void Addon::closeRepo()
|
||||
{
|
||||
m_repo.reset();
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <QQueue>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
|
||||
class git_repository;
|
||||
using repo_p = std::unique_ptr<git_repository, void(*)(git_repository *)>;
|
||||
@@ -49,6 +51,9 @@ class Addon : public QObject
|
||||
|
||||
int m_total;
|
||||
|
||||
QMutex m_mutex;
|
||||
QWaitCondition m_wait;
|
||||
void *m_result;
|
||||
public:
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
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 total READ total WRITE setTotal NOTIFY totalChanged)
|
||||
Q_PROPERTY(QStringList subfolders READ subfolders WRITE setSubfolders NOTIFY subfoldersChanged)
|
||||
Q_PROPERTY(QString filesToRemove READ filesToRemove WRITE setFilesToRemove NOTIFY filesToRemoveChanged)
|
||||
|
||||
enum class Status {
|
||||
Error = -1,
|
||||
@@ -105,6 +111,8 @@ public:
|
||||
|
||||
QStringList subfolders() const;
|
||||
|
||||
QString filesToRemove() const;
|
||||
|
||||
private:
|
||||
|
||||
Status m_status;
|
||||
@@ -122,7 +130,9 @@ private:
|
||||
|
||||
QThreadPool *m_pool;
|
||||
|
||||
void removeFolder(QString path);
|
||||
void removeFolder(QString path, bool ask = true);
|
||||
QString m_filesToRemove;
|
||||
|
||||
signals:
|
||||
|
||||
void nameChanged(QString name);
|
||||
@@ -145,6 +155,8 @@ signals:
|
||||
|
||||
void subfoldersChanged(QStringList subfolders);
|
||||
|
||||
void filesToRemoveChanged(QString filesToRemove);
|
||||
|
||||
public slots:
|
||||
void setName(QString name);
|
||||
void update();
|
||||
@@ -164,6 +176,8 @@ public slots:
|
||||
void setSubfolders(QStringList subfolders);
|
||||
void removeSubfolders();
|
||||
void unpackSubfolders();
|
||||
void setFilesToRemove(QString filesToRemove);
|
||||
void confirmFileRemove(bool confirmed);
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Addon::GitStatus)
|
||||
|
||||
Reference in New Issue
Block a user