Commit dbd75641 authored by LordTermor's avatar LordTermor

Unify package API

parent ee990e85
......@@ -8,30 +8,15 @@ class AlpmPackage : public Package
{
Q_GADGET
public:
AlpmPackage(PamacAlpmPackage* package){
m_handle=package;
Package::m_handle = &m_handle->parent_instance;
AlpmPackage(PamacAlpmPackage* package)
:Package(&package->parent_instance),
m_handle(package)
{
}
g_object_ref(m_handle);
static AlpmPackage fromData(void* data){return AlpmPackage(reinterpret_cast<PamacAlpmPackage*>(data));}
}
AlpmPackage(const AlpmPackage& another){
m_handle=another.m_handle;
Package::m_handle = &m_handle->parent_instance;
g_object_ref(m_handle);
}
AlpmPackage operator =(const AlpmPackage& another){
m_handle=another.m_handle;
Package::m_handle = &m_handle->parent_instance;
g_object_ref(m_handle);
return *this;
}
AlpmPackage(void* packageData){
m_handle=reinterpret_cast<PamacAlpmPackage*>(packageData);
Package::m_handle = &m_handle->parent_instance;
g_object_ref(m_handle);
}
AlpmPackage() = default;
AlpmPackage() = default;
PAMAC_QT_STRING_PROPERTY_GET(packager,pamac_alpm_package_get_packager(m_handle))
......@@ -47,6 +32,8 @@ AlpmPackage() = default;
PAMAC_QT_STRINGLIST_PROPERTY_GET(licenses,pamac_alpm_package_get_licenses(m_handle))
PamacAlpmPackage* handle(){return m_handle;}
protected:
PamacAlpmPackage* m_handle;
};
......
......@@ -9,14 +9,16 @@ class AurPackage : public AlpmPackage
Q_GADGET
public:
AurPackage(PamacAURPackage* package):
m_handle(package),
AlpmPackage(&package->parent_instance){}
AurPackage(void* packageData):
m_handle(reinterpret_cast<PamacAURPackage*>(packageData)),
AlpmPackage(&reinterpret_cast<PamacAURPackage*>(packageData)->parent_instance){
}
AlpmPackage(&package->parent_instance),
m_handle(package)
{}
AurPackage() = default;
static AurPackage fromData(void* data){
return AurPackage(reinterpret_cast<PamacAURPackage*>(data));
}
PAMAC_QT_STRING_PROPERTY_GET(packageBase,pamac_aur_package_get_packagebase(m_handle))
PAMAC_QT_DATETIME_PROPERTY_GET(outOfDate,pamac_aur_package_get_outofdate(m_handle))
PAMAC_QT_DOUBLE_PROPERTY_GET(popularity,pamac_aur_package_get_popularity(m_handle))
......
......@@ -67,9 +67,9 @@ public:
Q_INVOKABLE Updates getUpdates();
Q_INVOKABLE Package getInstalledPackage(const QString& name);
Q_INVOKABLE AlpmPackage getInstalledPackage(const QString& name);
Q_INVOKABLE Package getSyncPackage(const QString& name);
Q_INVOKABLE AlpmPackage getSyncPackage(const QString& name);
Q_INVOKABLE AurPackage getAurPackage(const QString& name);
Q_INVOKABLE QVariantList findPackagesByName(const QStringList& names);
......
......@@ -16,21 +16,10 @@ public:
Package(PamacPackage* package){
m_handle=package;
g_object_ref(m_handle);
}
Package(const Package& another){
m_handle=another.m_handle;
g_object_ref(m_handle);
}
Package operator =(const Package& another){
m_handle=another.m_handle;
g_object_ref(m_handle);
return *this;
}
Package(void* packageData){
m_handle=reinterpret_cast<PamacPackage*>(packageData);
g_object_ref(m_handle);
static Package fromData(void* data){
return Package(reinterpret_cast<PamacPackage*>(data));
}
PAMAC_QT_STRING_PROPERTY_GET(name,pamac_package_get_name(m_handle))
......@@ -59,12 +48,9 @@ public:
PAMAC_QT_DATETIME_PROPERTY_GET(installDate,pamac_package_get_installdate(m_handle))
~Package(){
}
operator PamacPackage*(){
return this->m_handle;
}
PamacPackage* handle(){return m_handle;}
protected:
PamacPackage* m_handle;
};
......
......@@ -15,7 +15,9 @@ class SnapPackage: public Package{
public:
SnapPackage() = default;
SnapPackage(PamacSnapPackage* pkg):m_handle(pkg){}
SnapPackage(PamacSnapPackage* pkg):
Package(&pkg->parent_instance),
m_handle(pkg){}
static SnapPackage fromData(void* data){return {reinterpret_cast<PamacSnapPackage*>(data)};};
......
......@@ -139,7 +139,7 @@ QMap<T1,T2> gHashToQMap(GHashTable* table,std::function<QPair<T1,T2>(void*,void*
#define PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(PackageType)\
[](void* data){return QVariant::fromValue(PackageType(data));}
[](void* data){return QVariant::fromValue(PackageType::fromData(data));}
// https://stackoverflow.com/a/48368508
......
......@@ -35,32 +35,32 @@ QStringList Database::getGroups()
QVariantList Database::searchPkgsInAur(const QString &name)
{
return Utils::gListToQList<QVariant>(pamac_database_search_aur_pkgs(handle,name.toUtf8()),[](void* data){return QVariant::fromValue(AurPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_search_aur_pkgs(handle,name.toUtf8()),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AurPackage));
}
QVariantList Database::getCategoryPackages(const QString &category)
{
return Utils::gListToQList<QVariant>(pamac_database_get_category_pkgs(handle,category.toUtf8()),[](void* data){return QVariant::fromValue(AlpmPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_get_category_pkgs(handle,category.toUtf8()),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
QVariantList Database::searchPkgs(const QString &name)
{
return Utils::gListToQList<QVariant>(pamac_database_search_pkgs(handle,name.toUtf8()),[](void* data){return QVariant::fromValue(AlpmPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_search_pkgs(handle,name.toUtf8()),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
QVariantList Database::getGroupPackages(const QString &group)
{
return Utils::gListToQList<QVariant>(pamac_database_get_group_pkgs(handle,group.toUtf8()),[](void* data){return QVariant::fromValue(AlpmPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_get_group_pkgs(handle,group.toUtf8()),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
QVariantList Database::getRepoPackages(const QString &repo)
{
return Utils::gListToQList<QVariant>(pamac_database_get_repo_pkgs(handle,repo.toUtf8()),[](void* data){return QVariant::fromValue(AlpmPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_get_repo_pkgs(handle,repo.toUtf8()),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
QVariantList Database::getInstalledApps(){
return Utils::gListToQList<QVariant>(pamac_database_get_installed_apps(handle),[](void* data){return QVariant::fromValue(AlpmPackage(data));});
return Utils::gListToQList<QVariant>(pamac_database_get_installed_apps(handle),PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
QStringList Database::getPkgFiles(const QString &name){
......@@ -82,21 +82,19 @@ QString Database::getMirrorsChoosenCountry(){
}
Updates Database::getUpdates(){
return Updates(pamac_database_get_updates(handle));
return {pamac_database_get_updates(handle)};
}
Package Database::getInstalledPackage(const QString &name){
AlpmPackage Database::getInstalledPackage(const QString &name){
return {pamac_database_get_installed_pkg(handle,name.toUtf8())};
}
Package Database::getSyncPackage(const QString &name){
AlpmPackage Database::getSyncPackage(const QString &name){
return {pamac_database_get_sync_pkg(handle,name.toUtf8())};
}
AurPackage Database::getAurPackage(const QString &name){
return AurPackage(pamac_database_get_aur_pkg(handle,name.toUtf8()));
return {pamac_database_get_aur_pkg(handle,name.toUtf8())};
}
QVariantList Database::findPackagesByName(const QStringList &names)
......@@ -165,7 +163,7 @@ QVariantList LibQPamac::Database::getInstalledPackages(Database::InstalledPackag
break;
}
return LibQPamac::Utils::gListToQList<QVariant>(result,[](void* value){return QVariant::fromValue(AlpmPackage(value));});
return LibQPamac::Utils::gListToQList<QVariant>(result,PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(AlpmPackage));
}
......@@ -178,14 +176,14 @@ QVariantList Database::getAurPackages(const QStringList &nameList)
auto resultGlist = pamac_database_get_aur_pkgs(handle,list->data(),list->size());
QVariantList result;
for(auto el = g_hash_table_get_values(resultGlist);el!=nullptr;el=el->next){
result.append(QVariant::fromValue(AurPackage(el->data)));
result.append(QVariant::fromValue(AurPackage::fromData(el->data)));
}
return result;
}
AlpmPackage Database::getPkg(const QString &name)
{
return AlpmPackage(pamac_database_get_pkg(handle,name.toUtf8()));
return {pamac_database_get_pkg(handle,name.toUtf8())};
}
} // namespace LibQPamac
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment