From a0fdd98a8f90904a278015821ade736be6aa1b70 Mon Sep 17 00:00:00 2001 From: woblight Date: Sun, 28 Jul 2024 18:09:51 +0200 Subject: [PATCH] Add a button to export the addon list (issue #2) --- AddonsPanel.qml | 7 +++++++ addon.cpp | 6 ++++-- addon.h | 2 +- control.cpp | 29 +++++++++++++++++++++++++---- control.h | 14 +++++++++----- main.qml | 14 ++++++++++++++ 6 files changed, 60 insertions(+), 12 deletions(-) diff --git a/AddonsPanel.qml b/AddonsPanel.qml index 47b7efa..fe269be 100644 --- a/AddonsPanel.qml +++ b/AddonsPanel.qml @@ -32,6 +32,13 @@ Page { ToolTip.text: "Download a new addon from a git repository" //Material.foreground: Material.background } + ToolButton { + hoverEnabled: true + action: exportList + ToolTip.visible: hovered + ToolTip.text: "Export the list of installed addons" + //Material.foreground: Material.background + } ToolButton { hoverEnabled: true action: updateAllAction diff --git a/addon.cpp b/addon.cpp index a721a6a..90b3972 100644 --- a/addon.cpp +++ b/addon.cpp @@ -640,10 +640,12 @@ QString Addon::path() const return m_path; } -QUrl Addon::getUrl() const +QUrl Addon::getUrl(QString name) const { git_remote *remote = nullptr; - if (git_remote_lookup(&remote, m_repo.get(), m_remote.toLocal8Bit())) + if (name.isNull()) + name = m_remote; + if (git_remote_lookup(&remote, m_repo.get(), name.toLocal8Bit())) return QUrl(); auto url = QUrl(git_remote_url(remote)); git_remote_free(remote); diff --git a/addon.h b/addon.h index bc3fe37..6c7a4cd 100644 --- a/addon.h +++ b/addon.h @@ -124,7 +124,7 @@ public: QString path() const; - Q_INVOKABLE QUrl getUrl() const; + Q_INVOKABLE QUrl getUrl(QString name = QString()) const; private: diff --git a/control.cpp b/control.cpp index 4d9ada0..a765a77 100644 --- a/control.cpp +++ b/control.cpp @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include Control *Control::m_instance = nullptr; QStringList Control::m_availableStyles; @@ -129,7 +132,7 @@ Control::~Control() m_instance = nullptr; } -QList Control::addons() const +QList Control::addons() const { return m_addons; } @@ -277,7 +280,7 @@ void Control::completeUpdate(const QString &path) }); } -void Control::setAddons(QList addons) +void Control::setAddons(QList addons) { if (m_addons == addons) return; @@ -337,9 +340,9 @@ void Control::saveAddonsPaths() void Control::scanForAddons(int i) { if (i == -1) { - foreach (QObject *addon, m_addons) + foreach (Addon *addon, m_addons) addon->deleteLater(); - QObjectList ol; + QList ol; setAddons(ol); for (int k = 0; k < m_addonsPaths.size(); ++k) scanForAddons(k); @@ -668,3 +671,21 @@ void Control::setUseRepoDirectory(bool newUseRepoDirectory) m_useRepoDirectory = newUseRepoDirectory; emit useRepoDirectoryChanged(newUseRepoDirectory); } + +void Control::exportAddonList(const QUrl &path) +{ + QFile outFile(path.toLocalFile()); + outFile.open(QFile::WriteOnly); + QTextStream out(&outFile); + out << Qt::endl; + foreach (auto addon, m_addons) { + QStringList remotes; + foreach (auto remote, addon->remotes()) { + if (remote == addon->remote()) + remotes << addon->getUrl(remote).toString().prepend("*"); + else + remotes << addon->getUrl(remote).toString(); + } + out << addon->path() << " " << addon->name() << " " << remotes.join(" ") << " " << addon->currentBranch() << Qt::endl; + } +} diff --git a/control.h b/control.h index d1555c9..a17f89d 100644 --- a/control.h +++ b/control.h @@ -17,6 +17,7 @@ #ifndef GITCONTROL_H #define GITCONTROL_H +#include "addon.h" #include #include #include @@ -24,6 +25,7 @@ #include class QThreadPool; +class Addon; class GitException : public QException { int m_code; @@ -50,10 +52,10 @@ class Control : public QObject using TaskQueue = QQueue>>; TaskQueue m_tasks; - QList m_addons; + QList m_addons; public: - Q_PROPERTY(QList addons READ addons WRITE setAddons NOTIFY addonsChanged) + Q_PROPERTY(QList addons READ addons WRITE setAddons NOTIFY addonsChanged) Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged) Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged) Q_PROPERTY(QString statusMessage READ statusMessage WRITE setStatusMessage NOTIFY statusMessageChanged) @@ -95,7 +97,7 @@ public: }; Q_ENUM(UpdateStatus) Q_PROPERTY(UpdateStatus updateStatus READ updateStatus WRITE setUpdateStatus NOTIFY updateStatusChanged) - QList addons() const; + QList addons() const; static Control *instance(); @@ -128,6 +130,8 @@ public: bool useRepoDirectory() const; void setUseRepoDirectory(bool newUseRepoDirectory); + Q_INVOKABLE void exportAddonList(const QUrl &path); + private: static Control *m_instance; explicit Control(QObject *parent = nullptr); @@ -158,7 +162,7 @@ private: bool m_useRepoDirectory; signals: - void addonsChanged(QList addons); + void addonsChanged(QList addons); void progressChanged(int progress); @@ -185,7 +189,7 @@ signals: void useRepoDirectoryChanged(bool use); public slots: - void setAddons(QList addons); + void setAddons(QList addons); void saveAddonsPaths(); void scanForAddons(int i = -1); void clone(QUrl url, int i); diff --git a/main.qml b/main.qml index 6acbe5d..c460c79 100644 --- a/main.qml +++ b/main.qml @@ -89,6 +89,14 @@ ApplicationWindow { onTriggered: addDialog.visible = true shortcut: StandardKey.New } + Action { + id: exportList + icon.name: "export-symbolic" + onTriggered: exportListDialog.visible = true + + enabled: Control.status == Control.Ready && addonsReady + shortcut: StandardKey.SaveAs + } Action { id: updateAllAction onTriggered: updateAll() @@ -412,4 +420,10 @@ ApplicationWindow { closePolicy: Engine.updateStatus !== Engine.DownloadingUpdate ? Dialog.CloseOnPressOutside | Dialog.CloseOnEscape : Dialog.NoAutoClose standardButtons: Engine.updateStatus !== Engine.DownloadingUpdate ? Dialog.Close : Dialog.NoButton } + FileDialog { + id: exportListDialog + onAccepted: Engine.exportAddonList(selectedFile) + fileMode: FileDialog.SaveFile + defaultSuffix: "txt" + } }