feat: add plugin interface and data model
This commit is contained in:
1 parent
6743d0b5e7
commit
776662c9ab
3 files changed
+146
No files matched your search
@@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
// Information about a single package
|
||||||
|
struct PackageInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string version;
|
||||||
|
std::string description;
|
||||||
|
std::string repository;
|
||||||
|
std::string size;
|
||||||
|
std::string installedSize;
|
||||||
|
bool installed = false;
|
||||||
|
bool updateAvailable = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Abstract interface for all package manager plugins
|
||||||
|
class IPackageManager {
|
||||||
|
public:
|
||||||
|
virtual ~IPackageManager() = default;
|
||||||
|
|
||||||
|
// Identity
|
||||||
|
virtual std::string getName() const = 0;
|
||||||
|
virtual std::string getVersion() const = 0;
|
||||||
|
virtual std::string getDescription() const = 0;
|
||||||
|
|
||||||
|
// Capabilities
|
||||||
|
virtual bool canSearch() const = 0;
|
||||||
|
virtual bool canInstall() const = 0;
|
||||||
|
virtual bool canRemove() const = 0;
|
||||||
|
virtual bool canUpdate() const = 0;
|
||||||
|
virtual bool canListInstalled() const = 0;
|
||||||
|
|
||||||
|
// Operations
|
||||||
|
virtual std::vector<PackageInfo> search(const std::string& query) = 0;
|
||||||
|
virtual bool install(const std::string& packageName,
|
||||||
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
||||||
|
virtual bool remove(const std::string& packageName,
|
||||||
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
||||||
|
virtual bool update(const std::string& packageName = "",
|
||||||
|
std::function<void(const std::string&)> progressCallback = nullptr) = 0;
|
||||||
|
virtual std::vector<PackageInfo> listInstalled() = 0;
|
||||||
|
|
||||||
|
// Check if the package manager is available on the system
|
||||||
|
virtual bool isAvailable() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Plugin entry point types
|
||||||
|
extern "C" {
|
||||||
|
IPackageManager* createPlugin();
|
||||||
|
void destroyPlugin(IPackageManager* plugin);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QVariant>
|
||||||
|
#include <vector>
|
||||||
|
#include "IPackageManager.h"
|
||||||
|
|
||||||
|
class PackageModel : public QAbstractListModel {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Roles {
|
||||||
|
NameRole = Qt::UserRole + 1,
|
||||||
|
VersionRole,
|
||||||
|
DescriptionRole,
|
||||||
|
RepositoryRole,
|
||||||
|
InstalledRole,
|
||||||
|
SizeRole,
|
||||||
|
UpdateAvailableRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit PackageModel(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
void setPackages(const std::vector<PackageInfo>& packages);
|
||||||
|
void clear();
|
||||||
|
PackageInfo getPackage(int row) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<PackageInfo> m_packages;
|
||||||
|
};
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include "PackageModel.h"
|
||||||
|
|
||||||
|
PackageModel::PackageModel(QObject* parent) : QAbstractListModel(parent) {}
|
||||||
|
|
||||||
|
int PackageModel::rowCount(const QModelIndex& parent) const {
|
||||||
|
Q_UNUSED(parent);
|
||||||
|
return static_cast<int>(m_packages.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant PackageModel::data(const QModelIndex& index, int role) const {
|
||||||
|
if (!index.isValid() || index.row() >= static_cast<int>(m_packages.size())) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
const PackageInfo& pkg = m_packages[index.row()];
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case NameRole: return QString::fromStdString(pkg.name);
|
||||||
|
case VersionRole: return QString::fromStdString(pkg.version);
|
||||||
|
case DescriptionRole: return QString::fromStdString(pkg.description);
|
||||||
|
case RepositoryRole: return QString::fromStdString(pkg.repository);
|
||||||
|
case InstalledRole: return pkg.installed;
|
||||||
|
case SizeRole: return QString::fromStdString(pkg.size);
|
||||||
|
case UpdateAvailableRole: return pkg.updateAvailable;
|
||||||
|
default: return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> PackageModel::roleNames() const {
|
||||||
|
return {
|
||||||
|
{NameRole, "name"},
|
||||||
|
{VersionRole, "version"},
|
||||||
|
{DescriptionRole, "description"},
|
||||||
|
{RepositoryRole, "repository"},
|
||||||
|
{InstalledRole, "installed"},
|
||||||
|
{SizeRole, "size"},
|
||||||
|
{UpdateAvailableRole, "updateAvailable"}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PackageModel::setPackages(const std::vector<PackageInfo>& packages) {
|
||||||
|
beginResetModel();
|
||||||
|
m_packages = packages;
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PackageModel::clear() {
|
||||||
|
beginResetModel();
|
||||||
|
m_packages.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageInfo PackageModel::getPackage(int row) const {
|
||||||
|
if (row >= 0 && row < static_cast<int>(m_packages.size())) {
|
||||||
|
return m_packages[row];
|
||||||
|
}
|
||||||
|
return PackageInfo{};
|
||||||
|
}
|
||||||
Reference in new issue
Block a user