aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiorgos Tsiapaliwkas <terietor@gmail.com>2011-10-10 10:42:26 +0300
committerGiorgos Tsiapaliwkas <terietor@gmail.com>2011-10-10 10:42:26 +0300
commitb93479e65f05e35320423969c25ad22e54239a68 (patch)
tree721cce45e81ff3c40dd8a61849687a7917e788ec
parentinit the terietor_interegation branch (diff)
downloadc-portage-b93479e65f05e35320423969c25ad22e54239a68.tar.gz
c-portage-b93479e65f05e35320423969c25ad22e54239a68.tar.bz2
c-portage-b93479e65f05e35320423969c25ad22e54239a68.zip
add 2 new class,qlistconverter and qpackageproperties
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Qt/CMakeLists.txt9
-rw-r--r--src/Qt/qlistconverter.cpp47
-rw-r--r--src/Qt/qlistconverter.h19
-rw-r--r--src/Qt/qpackageproperties.cpp30
-rw-r--r--src/Qt/qpackageproperties.h2
-rw-r--r--src/Qt/qportagesettings.cpp89
-rw-r--r--src/Qt/qportagesettings.h43
8 files changed, 112 insertions, 129 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 637e697..22e27c7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,4 +18,4 @@ option(CppPortage "Enable c++ wrapper for c-portage (uses Qt4)")
if (CppPortage)
add_subdirectory(Qt)
-endif(CppPortage) \ No newline at end of file
+endif(CppPortage)
diff --git a/src/Qt/CMakeLists.txt b/src/Qt/CMakeLists.txt
index 2a19c3e..3159bfc 100644
--- a/src/Qt/CMakeLists.txt
+++ b/src/Qt/CMakeLists.txt
@@ -2,11 +2,14 @@ find_package(Qt4 REQUIRED)
include_directories(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})
remove_definitions(-std=c99)
-set(cpp-portage_SRCS qportagesettings.cpp)
-set(cpp-portage_HDRS qportagesettings.h)
+set(cpp-portage_SRCS qportagesettings.cpp qpackageproperties.cpp)
+set(cpp-portage_HDRS qportagesettings.h qpackageproperties.h)
QT4_WRAP_CPP(cpp-portage_MOC_SRCS ${cpp-portage_HDRS})
add_library(cpp-portage qportagesettings.cpp ${cpp-portage_MOC_SRCS})
+
install(TARGETS cpp-portage DESTINATION lib)
-install(FILES ${cpp-portage_HDRS} DESTINATION include/cpp-portage) \ No newline at end of file
+install(FILES ${cpp-portage_HDRS} DESTINATION include/cpp-portage)
+
+add_subdirectory(tests) \ No newline at end of file
diff --git a/src/Qt/qlistconverter.cpp b/src/Qt/qlistconverter.cpp
index 4f3855c..4ce0845 100644
--- a/src/Qt/qlistconverter.cpp
+++ b/src/Qt/qlistconverter.cpp
@@ -3,43 +3,38 @@
#include <QStringList>
#include <QString>
-namespace CppPortage{
-
-QListConverter::QListConverter(StringList *stringList, QObject *parent)
- :QObject(parent)
+struct StringList
{
- m_stringlist = stringList;
-}
-
-QListConverter::QListConverter(QStringList *stringList, QObject* parent)
- : QObject(parent)
-{
- m_qstringlist = stringList;
-}
+ char **list;
+ unsigned int count;
+};
+namespace CppPortage{
+QListConverter::QListConverter(QObject *parent)
+ :QObject(parent)
+{}
-QListConverter::~QListConverter()
+StringList* QListConverter::QStringListToStringList(QStringList qstringList)
{
-}
+ StringList *stringList = stringListCreate(qstringList.size());//create a new StringList
-StringList* QListConverter::QStringListToStringList()
-{
- for (int i = 0; i <= m_qstringlist->size(); i++) {
- char c = m_qstringlist->at(i).data()->toAscii();
- stringListInsertAt(m_stringlist, i, &c);
+ for (int i = 0; i <= qstringList.size(); i++) {
+ char c = *(qstringList.at(i).toUtf8().data());
+ stringListInsertAt(stringList, i, &c);
}
- return m_stringlist;
+ return stringList;
}
-QStringList QListConverter::StringListToQStringList()
+QStringList QListConverter::StringListToQStringList(StringList *stringList)
{
- for (int i = 0; i <= m_stringlist->count(); i++) {
- m_qstringlist->insert(i, stringListGetAt(m_stringlist, i));
+ QStringList qstringList;
+
+ for (int i = 0; i <= stringList->count; i++) {
+ qstringList.insert(i, stringListGetAt(stringList, i));
}
- return *m_qstringlist;
+ return qstringList;
}
-
-} \ No newline at end of file
+}//end namespace \ No newline at end of file
diff --git a/src/Qt/qlistconverter.h b/src/Qt/qlistconverter.h
index 44090bd..83f73fc 100644
--- a/src/Qt/qlistconverter.h
+++ b/src/Qt/qlistconverter.h
@@ -5,8 +5,6 @@
#include <QObject>
-struct StringList;
-
class QString;
class QStringList;
@@ -16,28 +14,17 @@ class QListConverter : public QObject
{
Q_OBJECT
public:
- QListConverter(StringList *stringList, QObject *parent = 0);
- QListConverter(QStringList *stringList, QObject* parent = 0);
- virtual ~QListConverter();
+ QListConverter(QObject *parent = 0);
/**
* Converts a StringList to a QStringList
**/
- QStringList StringListToQStringList();
+ static QStringList StringListToQStringList(StringList *stringList);
/**
* Converts a QStringList to a StringList
**/
- StringList* QStringListToStringList();
-
- /**
- * This methed performs a check at the obj.If the object exists then it is dealloc.
- * We need this method,because we don't want to check "manually" if the obj exists and
- * if it exists to dealloc it with delete.
- **/
-private:
- StringList *m_stringlist;
- QStringList *m_qstringlist;
+ static StringList* QStringListToStringList(QStringList qstringList);
};
}
#endif \ No newline at end of file
diff --git a/src/Qt/qpackageproperties.cpp b/src/Qt/qpackageproperties.cpp
index f42b54d..8302122 100644
--- a/src/Qt/qpackageproperties.cpp
+++ b/src/Qt/qpackageproperties.cpp
@@ -10,19 +10,13 @@ QPackageProperties::QPackageProperties(QString slot, QStringList keywords,
QStringList flags, QStringList homepages, QObject *parent)
:QObject(parent)
{
- m_listConverter = new QListConverter(&flags, this);
- StringList *FLAGS = m_listConverter->QStringListToStringList();
- m_listConverter->checkList();
+ StringList *FLAGS = QListConverter::QStringListToStringList(flags);
- m_listConverter = new QListConverter(&homepages, this);
- StringList *HOMEPAGES = m_listConverter->QStringListToStringList();
- m_listConverter->checkList();
+ StringList *HOMEPAGES = QListConverter::QStringListToStringList(homepages);
- m_listConverter = new QListConverter(&keywords, this);
- StringList *KEYWORDS = m_listConverter->QStringListToStringList();
- m_listConverter->checkList();
+ StringList *KEYWORDS = QListConverter::QStringListToStringList(keywords);
- packagePropertiesCreate(slot.toAscii().data(), KEYWORDS, FLAGS, HOMEPAGES);
+ packagePropertiesCreate(slot.toUtf8().data(), KEYWORDS, FLAGS, HOMEPAGES);
}
@@ -34,33 +28,25 @@ QPackageProperties::~QPackageProperties()
const QString QPackageProperties::Slot()
{
- m_listConverter->checkList();
PackageProperties *p;
return packagePropertiesGetSlot(p);
}
const QStringList QPackageProperties::Flags()
{
- m_listConverter->checkList();
PackageProperties *p;
- m_listConverter = new QListConverter(packagePropertiesGetFlags(p), this);
- return m_listConverter->StringListToQStringList();
+ return QListConverter::StringListToQStringList(packagePropertiesGetFlags(p));
}
const QStringList QPackageProperties::Keywords()
{
- m_listConverter->checkList();
PackageProperties *p;
- m_listConverter = new QListConverter(packagePropertiesGetKeywords(p), this);
- return m_listConverter->StringListToQStringList();
+ return QListConverter::StringListToQStringList(packagePropertiesGetKeywords(p));
}
const QStringList QPackageProperties::Homepages()
{
- m_listConverter->checkList();
- PackageProperties *p;
- m_listConverter = new QListConverter(packagePropertiesGetHomepages(p), this);
-
- return m_listConverter->StringListToQStringList();
+ PackageProperties *p;
+ return QListConverter::StringListToQStringList(packagePropertiesGetHomepages(p));
}
}
diff --git a/src/Qt/qpackageproperties.h b/src/Qt/qpackageproperties.h
index 31db033..cfec142 100644
--- a/src/Qt/qpackageproperties.h
+++ b/src/Qt/qpackageproperties.h
@@ -28,8 +28,6 @@ public:
const QStringList Keywords();
const QStringList Flags();
const QStringList Homepages();
-private:
- QListConverter *m_listConverter;
};
}
#endif \ No newline at end of file
diff --git a/src/Qt/qportagesettings.cpp b/src/Qt/qportagesettings.cpp
index f69af6c..21dc7b2 100644
--- a/src/Qt/qportagesettings.cpp
+++ b/src/Qt/qportagesettings.cpp
@@ -5,77 +5,94 @@
namespace CppPortage{
-PortageSettings::PortageSettings(QObject *parent)
+QPortageSettings::QPortageSettings(QObject *parent)
:QObject(parent)
{
-
}
-
-PortageSettings::~PortageSettings()
+QPortageSettings::~QPortageSettings()
{
-
+ PortageSettings *ps;
+ portageSettingsFree(ps);
}
-int PortageSettings::ResetUseFlags()
+const int QPortageSettings::resetUseFlags()
{
-
+ PortageSettings *ps;
+ return portageSettingsResetUseFlags(ps);
}
-int PortageSettings::Reset()
-{
-}
-int PortageSettings::ReloadConfig()
+const int QPortageSettings::reset()
{
-
+ PortageSettings *ps;
+ return portageSettingsResetUseFlags(ps);
}
-int PortageSettings::ReloadWorld()
-{
-}
-QStringList PortageSettings::GetWorld()
+const int QPortageSettings::reloadConfig()
{
-
+ PortageSettings *ps;
+ return portageSettingsReloadConfig(ps);
}
-QStringList PortageSettings::GetArchList()
-{
-}
-QStringList PortageSettings::GetVirtuals()
+const int QPortageSettings::reloadWorld()
{
-
+ PortageSettings *ps;
+ return portageSettingsReloadWorld(ps);
}
-
-const QString PortageSettings::AcceptKeywords()
+const QStringList QPortageSettings::world()
{
-
+ PortageSettings *ps;
+ return QListConverter::StringListToQStringList(portageSettingsGetWorld(ps));
}
-const QStringList PortageSettings::SystemUseFlags()
-{
-}
-const QString PortageSettings::Arch()
+const QStringList QPortageSettings::archList()
{
+ PortageSettings *ps;
+ return QListConverter::StringListToQStringList(portageSettingsGetArchList(ps));
}
-const QString PortageSettings::Portdir()
-{
-}
-const QString PortageSettings::PortdirOverlay()
+const QStringList QPortageSettings::virtuals()
{
+ PortageSettings *ps;
+ return QListConverter::StringListToQStringList(portageSettingsGetVirtuals(ps));
+}
+const QString QPortageSettings::acceptKeywords()
+{
+ PortageSettings *ps;
+ return portageSettingsAcceptKeywords(ps);
}
-const QString PortageSettings::UserConfigDir()
+
+const QStringList QPortageSettings::systemUseFlags()
{
+ PortageSettings *ps;
+ return QListConverter::StringListToQStringList(portageSettingsSystemUseFlags(ps));
+}
+const QString QPortageSettings::arch()
+{
+ PortageSettings *ps;
+ return portageSettingsArch(ps);
}
+const QString QPortageSettings::portdir()
+{
+ PortageSettings *ps;
+ return portageSettingsPortdir(ps);
+}
-void PortageSettings::Free()
+const QString QPortageSettings::portdirOverlay()
{
+ PortageSettings *ps;
+ return portageSettingsPortdirOverlay(ps);
+}
+const QString QPortageSettings::userConfigDir()
+{
+ PortageSettings *ps;
+ return portageSettingsUserConfigDir(ps);
}
-} \ No newline at end of file
+}//end namespace
diff --git a/src/Qt/qportagesettings.h b/src/Qt/qportagesettings.h
index e72af42..652020c 100644
--- a/src/Qt/qportagesettings.h
+++ b/src/Qt/qportagesettings.h
@@ -4,38 +4,35 @@
#include <QObject>
#include "../portagesettings.h"
+#include "qlistconverter.h"
class QString;
class QStringList;
+struct PortageSettings;
+
namespace CppPortage {
-class PortageSettings : public QObject
+class QPortageSettings : public QObject
{
Q_OBJECT
public:
- PortageSettings(QObject *parent = 0);
- virtual ~PortageSettings();
-
-
-int ResetUseFlags();
-int Reset();
-int ReloadConfig();
-int ReloadWorld();
-QStringList GetWorld();
-QStringList GetArchList();
-QStringList GetVirtuals();
-
-
-const QString AcceptKeywords();
-const QStringList SystemUseFlags();
-const QString Arch();
-const QString Portdir();
-const QString PortdirOverlay();
-const QString UserConfigDir();
-
-
-void Free();
+ QPortageSettings(QObject *parent = 0);
+ virtual ~QPortageSettings();
+
+ const int resetUseFlags();
+ const int reset();
+ const int reloadConfig();
+ const int reloadWorld();
+ const QStringList world();
+ const QStringList archList();
+ const QStringList virtuals();
+ const QString acceptKeywords();
+ const QStringList systemUseFlags();
+ const QString arch();
+ const QString portdir();
+ const QString portdirOverlay();
+ const QString userConfigDir();
};
}
#endif \ No newline at end of file