Commit 90f92366 authored by LordTermor's avatar LordTermor Committed by LordTermor

Fixed preferences window

parent 1f3d9db9
import QtQuick 2.4
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.3
import QPamac.Config 1.0
import QPamac.Database 1.0
import QPamac.PackageModel 1.0
......
......@@ -2,7 +2,6 @@ import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.3
import Qt.labs.platform 1.0 as Labs
import QPamac.Config 1.0
import QPamac.Database 1.0
import QPamac.PackageModel 1.0
import QPamac.Transaction 1.0
......@@ -311,11 +310,11 @@ Page{
text: modelData
}
model:Database.getIgnorePkgs()
model:config.getIgnorePkgs()
Connections{
target: transaction
onWriteAlpmConfigFinished:{
listView.model=Database.getIgnorePkgs();
listView.model=config.getIgnorePkgs();
}
}
}
......@@ -361,7 +360,7 @@ Page{
Button{
icon.name: "list-remove"
onClicked: {
var list = Database.getIgnorePkgs();
var list = config.getIgnorePkgs();
list.splice(listView.currentIndex,1);
var string = list.join(" ");
......
......@@ -7,29 +7,18 @@
namespace LibQPamac{
class Config
class Config : public QObject
{
Q_GADGET
Q_OBJECT
public:
Config(const QString& str,QObject* parent = nullptr):QObject(parent){
m_handle = pamac_config_new(str.toUtf8());
}
Config(PamacConfig* cfg)
{
m_handle = cfg;
g_object_ref(m_handle);
}
Config(const QString& str)
{
m_handle = pamac_config_new(str.toUtf8());
}
Config()=default;
Config(const Config& another){
m_handle=another.m_handle;
g_object_ref(m_handle);
}
Config operator =(const Config& another){
m_handle=another.m_handle;
g_object_ref(m_handle);
return *this;
}
~Config(){
g_object_unref(m_handle);
}
......@@ -63,9 +52,13 @@ public:
PAMAC_QT_STRING_PROPERTY_GET_SET(aurBuildDirectory,pamac_config_get_aur_build_dir(m_handle),
setAurBuildDirectory,pamac_config_set_aur_build_dir(m_handle,aurBuildDirectory.toUtf8()))
operator PamacConfig*(){
Q_INVOKABLE QStringList getIgnorePkgs();
PamacConfig* handle(){
return m_handle;
}
private:
PamacConfig* m_handle;
};
......
......@@ -14,7 +14,7 @@ namespace LibQPamac {
class Database:public QObject
{
Q_OBJECT
Q_PROPERTY(Config config READ config WRITE setConfig NOTIFY configChanged)
Q_PROPERTY(Config* config READ config WRITE setConfig NOTIFY configChanged)
public:
......@@ -41,8 +41,6 @@ public:
Q_INVOKABLE QStringList getRepos();
Q_INVOKABLE QStringList getGroups();
Q_INVOKABLE QStringList getIgnorePkgs();
Q_INVOKABLE QVariantList searchPkgsInAur(const QString &name);
Q_INVOKABLE QVariantList getCategoryPackages(const QString &category);
......@@ -55,7 +53,7 @@ public:
Q_INVOKABLE QStringList getPkgFiles(const QString &name);
Config config() const
Config* config()
{
return m_config;
}
......@@ -79,12 +77,13 @@ public:
inline void refresh(){
pamac_database_refresh(handle);
}
Q_INVOKABLE QList<QVariant> getHistory();
public Q_SLOTS:
void setConfig(const Config& config);
void setConfig(Config *config);
Q_SIGNALS:
void updatesReady(Updates upds);
......@@ -93,13 +92,13 @@ Q_SIGNALS:
void checkspaceChanged(bool checkspace);
void configChanged(Config config);
void configChanged(Config* config);
private:
PamacDatabase* handle;
void init();
Config m_config;
Config* m_config = nullptr;
bool m_asynchronous;
};
......
......@@ -117,6 +117,27 @@ QList<T> gListToQList(GList* list,std::function<T(void*)> wrapFunction,GDestroyN
return result;
}
template <typename T1,typename T2>
QMap<T1,T2> gHashToQMap(GHashTable* table,std::function<QPair<T1,T2>(void*,void*)> wrapFunction,GHRFunc freeFunc = nullptr)
{
QMap<T1,T2> result;
GList* list = g_hash_table_get_keys(table);
for(auto el = list;el!=nullptr;el=el->next)
{
QPair<T1,T2> pair = wrapFunction(el->data,g_hash_table_lookup(table,el->data));
result[pair.first] = pair.second;
}
if(freeFunc){
g_hash_table_foreach_remove(table,freeFunc,nullptr);
}
return result;
}
#define PAMAC_QT_PACKAGE_TO_VARIANT_WRAP(PackageType)\
[](void* data){return QVariant::fromValue(PackageType(data));}
......
#include <Config.h>
QStringList LibQPamac::Config::getIgnorePkgs()
{
return Utils::gHashToQMap<QString,QString>(pamac_config_get_ignorepkgs(m_handle),[](void* key,void* value){
auto keyString = QString::fromUtf8(reinterpret_cast<gchar*>(key));
auto valueString = QString::fromUtf8(reinterpret_cast<gchar*>(value));
return QPair(keyString,valueString);
}).values();
}
......@@ -8,9 +8,10 @@ Database::Database(PamacDatabase *db, QObject *parent):
}
Database::Database(const QString& configFile, QObject *parent):
QObject(parent){
m_config = Config(configFile);
handle = pamac_database_new(m_config);
QObject(parent)
{
m_config = new Config(configFile,this);
handle = pamac_database_new(m_config->handle());
init();
}
......@@ -31,11 +32,6 @@ QStringList Database::getGroups()
return Utils::gListToQStringList(pamac_database_get_groups_names(handle),true);
}
QStringList Database::getIgnorePkgs()
{
// return Utils::gListToQStringList(pamac_database_get_ignorepkgs(handle),true);
}
QVariantList Database::searchPkgsInAur(const QString &name)
{
......@@ -134,7 +130,7 @@ QList<QVariant> Database::getHistory(){
return HistoryItem::fromStringList(list);
}
void Database::setConfig(const Config &config)
void Database::setConfig(Config *config)
{
m_config = config;
Q_EMIT configChanged(config);
......
......@@ -18,7 +18,6 @@ void LibQPamacModule::registerTypes(const char *uri)
qRegisterMetaType<AlpmPackage>("AlpmPackage");
qRegisterMetaType<Package>("Package");
qRegisterMetaType<Updates>("Updates");
qRegisterMetaType<Config>("Config");
qRegisterMetaType<TransactionSummary>("TransactionSummary");
qRegisterMetaType<GenericQmlFuture>("Future");
qRegisterMetaType<QList<HistoryItem>>("QList<HistoryItem>");
......@@ -41,6 +40,5 @@ void LibQPamacModule::registerTypes(const char *uri)
qmlRegisterType<AurPackageModel>("QPamac.AUR.PackageModel",1,0,"AURPackageModel");
qmlRegisterUncreatableType<Updates>("QPamac.Database",1,0,"Updates","");
qmlRegisterType<Transaction>("QPamac.Transaction",1,0,"Transaction");
qmlRegisterUncreatableType<Config>("QPamac.Config",1,0,"Config","");
qmlRegisterUncreatableType<TransactionSummary>("QPamac.Transaction",1,0,"TransactionSummary","");
}
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