summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller.cxx7
m---------librtclient0
-rw-r--r--main.cxx12
-rw-r--r--tasklist.cxx13
-rw-r--r--tasklist.hxx18
-rw-r--r--worker.cxx20
-rw-r--r--worker.hxx1
7 files changed, 41 insertions, 30 deletions
diff --git a/controller.cxx b/controller.cxx
index b9bdf5e..42b1ece 100644
--- a/controller.cxx
+++ b/controller.cxx
@@ -1,6 +1,8 @@
#include <QQmlApplicationEngine>
+#include <QtQml>
#include "worker.hxx"
#include "user.hxx"
+#include "tasklist.hxx"
#include "controller.hxx"
Controller::Controller(QObject* parent) : QObject{parent}
@@ -22,6 +24,11 @@ Controller::Controller(QObject* parent) : QObject{parent}
auto user = engine->singletonInstance<User*>(User::typeId);
connect(worker, SIGNAL(logged(rt_user*)), user, SLOT(update(rt_user*)));
+ auto taskList = engine->singletonInstance<TaskList*>(TaskList::typeId);
+ engine->rootContext()->setContextProperty("taskList", taskList);
+ connect(worker, SIGNAL(foundTasks(rt_ticketlist*))
+ , taskList, SLOT(addTasks(rt_ticketlist*)));
+
thread.start();
}
diff --git a/librtclient b/librtclient
-Subproject 2e207d07a6416d7ccb32040c3f9e43c3a48aeed
+Subproject e9561a9bd14469edab70886d98e050bfe054a3e
diff --git a/main.cxx b/main.cxx
index c9e8691..ff184e7 100644
--- a/main.cxx
+++ b/main.cxx
@@ -1,6 +1,5 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
-#include <QtQml>
#include "user.hxx"
#include "tasklist.hxx"
#include "controller.hxx"
@@ -16,11 +15,16 @@ int main(int argc, char* argv[])
QJSEngine *scriptEngine) -> QObject* {
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
- return new User{};
+ return new User;
});
- TaskList taskList;
- engine.rootContext()->setContextProperty("taskList", &taskList);
+ TaskList::typeId = qmlRegisterSingletonType<User>("KelakonUser", 0, 1, "TaskList"
+ , [](QQmlEngine *engine,
+ QJSEngine *scriptEngine) -> QObject* {
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+ return new TaskList;
+ });
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Controller controller{&engine};
diff --git a/tasklist.cxx b/tasklist.cxx
index 4810c5b..863ae23 100644
--- a/tasklist.cxx
+++ b/tasklist.cxx
@@ -14,8 +14,6 @@ QVariant TaskList::data(QModelIndex const& index, int role) const
auto task = tasks[row];
switch (role) {
- case IdRole:
- return task.id();
case SubjectRole:
return task.subject();
default:
@@ -26,7 +24,6 @@ QVariant TaskList::data(QModelIndex const& index, int role) const
QHash<int, QByteArray> TaskList::roleNames() const
{
return QHash<int, QByteArray>{
- {IdRole, "id"},
{SubjectRole, "subject"}
};
}
@@ -38,3 +35,13 @@ void TaskList::addTask(Task const& task)
endInsertRows();
emit rowCountChanged();
}
+
+void TaskList::addTasks(rt_ticketlist* taskList)
+{
+ for (unsigned int i = 0; i < taskList->length; i++) {
+ auto task = taskList->tickets[i];
+ addTask(Task{task});
+ free(task);
+ }
+ free(taskList);
+}
diff --git a/tasklist.hxx b/tasklist.hxx
index a632d86..68cc3ff 100644
--- a/tasklist.hxx
+++ b/tasklist.hxx
@@ -2,19 +2,16 @@
#define TASKLIST_HXX
#include <QAbstractListModel>
+#include "rtticket.h"
class Task
{
public:
- Task(unsigned int id, QString subject)
- : m_id{id}
- , m_subject{subject}
+ Task(QString subject) : m_subject{subject}
{}
- unsigned int id() const { return m_id; }
QString const& subject() const { return m_subject; }
private:
- unsigned int m_id;
QString m_subject;
};
@@ -25,11 +22,14 @@ class TaskList : public QAbstractListModel
public:
enum TaskRoles {
- IdRole = Qt::UserRole + 1,
- SubjectRole
+ SubjectRole = Qt::UserRole + 1,
};
+
explicit TaskList(QObject* parent = nullptr)
: QAbstractListModel{parent} {}
+ ~TaskList() {}
+ inline static int typeId;
+
int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
@@ -37,11 +37,15 @@ class TaskList : public QAbstractListModel
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
signals:
+ void didAddProducts();
void rowCountChanged();
private:
QList<Task> tasks;
void addTask(Task const& task);
+
+ private slots:
+ void addTasks(rt_ticketlist* taskList);
};
#endif // TASKLIST_HXX
diff --git a/worker.cxx b/worker.cxx
index e21ef6b..c472212 100644
--- a/worker.cxx
+++ b/worker.cxx
@@ -1,6 +1,3 @@
-#ifdef DEBUG
-#include <QDebug>
-#endif // DEBUG
#include "rtclient.h"
#include "worker.hxx"
@@ -12,7 +9,7 @@ Worker::Worker()
void Worker::logIn(QString const& name, QString const& password)
{
rtclient_login(name.toLatin1().constData(), password.toLatin1().constData());
- struct rt_user *user = NULL;
+ struct rt_user* user = NULL;
rtclient_userget(&user, name.toLatin1().constData());
if (user) emit logged(user);
}
@@ -22,18 +19,9 @@ void Worker::search(QString const& owner)
QString query{"Owner='"};
query.append(owner);
query.append("'");
- rt_ticketlist *tasks = NULL;
- rtclient_search(&tasks, query.toLatin1().constData());
- if (tasks) {
-#ifdef DEBUG
- for (unsigned short i = 0; i < tasks->length; i++) {
- auto task = tasks->tickets[i];
- qDebug() << "Task: " << task;
- if (task) free(task);
- }
-#endif // DEBUG
- free(tasks);
- }
+ rt_ticketlist* taskList = NULL;
+ rtclient_search(&taskList, query.toLatin1().constData());
+ if (taskList) emit foundTasks(taskList);
}
Worker::~Worker()
diff --git a/worker.hxx b/worker.hxx
index c406db9..878c2ba 100644
--- a/worker.hxx
+++ b/worker.hxx
@@ -17,6 +17,7 @@ class Worker : public QObject
signals:
void logged(struct rt_user* user);
+ void foundTasks(struct rt_ticketlist* list);
};
#endif // WORKER_HXX