Add a button to export the addon list (issue #2)

This commit is contained in:
woblight
2024-07-28 18:09:51 +02:00
parent c605139fef
commit a0fdd98a8f
6 changed files with 60 additions and 12 deletions
+7
View File
@@ -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
+4 -2
View File
@@ -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);
+1 -1
View File
@@ -124,7 +124,7 @@ public:
QString path() const;
Q_INVOKABLE QUrl getUrl() const;
Q_INVOKABLE QUrl getUrl(QString name = QString()) const;
private:
+25 -4
View File
@@ -31,6 +31,9 @@
#include <QApplication>
#include <quazip.h>
#include <quazipfile.h>
#include <QTextStream>
#include <ranges>
#include <algorithm>
Control *Control::m_instance = nullptr;
QStringList Control::m_availableStyles;
@@ -129,7 +132,7 @@ Control::~Control()
m_instance = nullptr;
}
QList<QObject *> Control::addons() const
QList<Addon *> Control::addons() const
{
return m_addons;
}
@@ -277,7 +280,7 @@ void Control::completeUpdate(const QString &path)
});
}
void Control::setAddons(QList<QObject *> addons)
void Control::setAddons(QList<Addon *> 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<Addon *> 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;
}
}
+9 -5
View File
@@ -17,6 +17,7 @@
#ifndef GITCONTROL_H
#define GITCONTROL_H
#include "addon.h"
#include <QException>
#include <QObject>
#include <QQueue>
@@ -24,6 +25,7 @@
#include <functional>
class QThreadPool;
class Addon;
class GitException : public QException
{
int m_code;
@@ -50,10 +52,10 @@ class Control : public QObject
using TaskQueue = QQueue<QPair<QString,std::function<void()>>>;
TaskQueue m_tasks;
QList<QObject *> m_addons;
QList<Addon *> m_addons;
public:
Q_PROPERTY(QList<QObject *> addons READ addons WRITE setAddons NOTIFY addonsChanged)
Q_PROPERTY(QList<Addon *> 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<QObject *> addons() const;
QList<Addon *> 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<QObject *> addons);
void addonsChanged(QList<Addon *> addons);
void progressChanged(int progress);
@@ -185,7 +189,7 @@ signals:
void useRepoDirectoryChanged(bool use);
public slots:
void setAddons(QList<QObject *> addons);
void setAddons(QList<Addon *> addons);
void saveAddonsPaths();
void scanForAddons(int i = -1);
void clone(QUrl url, int i);
+14
View File
@@ -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"
}
}