summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-02-02 11:51:44 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-02-02 11:51:44 +0800
commit8107effd171ffb5285e4e6d79ff9a2b7e4669c79 (patch)
tree72248cb1266c355a6ed3f0b05615a7a93e6c41d7
parentc6708f0223f284aaa15768861a8b018d9e0acdae (diff)
Conform to updated librtclient
commit 12cde42c929b63a1ef1b2ad7f3482336419980b2
-rw-r--r--client.cxx127
-rw-r--r--qrtclient.hxx32
-rw-r--r--qrtclient/ticket.hxx17
-rw-r--r--qrtclient/tickethistory.hxx23
-rw-r--r--qrtclient/user.hxx4
-rw-r--r--ticket.cxx30
-rw-r--r--tickethistory.cxx30
-rw-r--r--user.cxx113
8 files changed, 148 insertions, 228 deletions
diff --git a/client.cxx b/client.cxx
index 5bf4801..c931191 100644
--- a/client.cxx
+++ b/client.cxx
@@ -1,21 +1,36 @@
#include <QStringBuilder>
#include <rtclient.h>
+#include <rtclient/user.h>
#include <rtclient/ticket.h>
#include <rtclient/search.h>
#include "qrtclient.hxx"
namespace RTClient {
- Client::Client(char const* url, char const* certificate)
- {
- rtclient_init(url, certificate);
- }
+static Client* client;
+static char *nCopy, *pwCopy;
- void Client::logIn(QString const& name, QString const& password)
- {
- rtclient_login(name.toLatin1().constData(), password.toLatin1().constData());
- emit loggedIn(name);
- }
+Client::Client(char const* url, char const* cookies, char const* certificate)
+{
+ client = this;
+ rtclient_init(url, cookies, certificate);
+}
+
+void Client::logIn(QString const& name, QString const& password)
+{
+ auto nData = name.toLatin1().constData();
+ nCopy = (char*)malloc(strlen(nData) + 1);
+ strcpy(nCopy, nData);
+ auto pwData = password.toLatin1().constData();
+ pwCopy = (char*)malloc(strlen(pwData) + 1);
+ strcpy(pwCopy, pwData);
+ rtclient_login(nCopy, pwCopy, [](rtclient_response* response) {
+ rtclient_free_response(response);
+ client->emitLoggedIn(QString{nCopy});
+ free(nCopy);
+ free(pwCopy);
+ });
+}
void Client::userNew(QString const& name,
QString const& password,
@@ -68,19 +83,22 @@ void Client::userNew(QString const& name,
privileged);
}
- void Client::userShow(unsigned int id)
- {
- rtclient_user* user = nullptr;
- rtclient_user_showid(&user, id);
- emit userShown(user);
- }
+void Client::userShow(unsigned int id)
+{
+ rtclient_user_showid(id, [](struct rtclient_user* user) {
+ client->emitUserShown(User{user});
+ rtclient_user_free(user);
+ });
+}
- void Client::userShow(QString const& name)
- {
- rtclient_user* user = nullptr;
- rtclient_user_showname(&user, name.toLatin1().constData());
- emit userShown(user);
- }
+void Client::userShow(QString const& name)
+{
+ rtclient_user_showname(name.toLatin1().constData(),
+ [](struct rtclient_user* user) {
+ client->emitUserShown(User{user});
+ rtclient_user_free(user);
+ });
+}
void Client::ticketNew(QString const& queue,
QString const& requestor,
@@ -113,24 +131,53 @@ void Client::ticketNew(QString const& queue,
text.toLatin1().constData());
}
- void Client::searchTicket(QString const& owner)
- {
- QString query{"Owner='" % owner % "'"};
- rtclient_search_ticket_list* list = nullptr;
- rtclient_search_ticket(&list, query.toLatin1().constData());
- emit searchedTicket(list);
- }
-
- void Client::ticketHistory(int id, bool longFormat)
- {
- rtclient_ticket_history_list* historyList = nullptr;
- rtclient_ticket_history(&historyList, id, longFormat);
- emit gotTicketHistory(historyList);
- }
-
- Client::~Client()
- {
- rtclient_cleanup();
- }
+void Client::searchTicket(QString const& owner)
+{
+ QString query{"Owner='" % owner % "'"};
+ rtclient_search_ticket(query.toLatin1().constData(),
+ [](struct rtclient_ticket** list) {
+ client->emitSearchedTicket(TicketList{list});
+ size_t i = 0;
+ while (list[i]) {
+ free(list[i]->subject);
+ free(list[i++]);
+ }
+ });
+}
+
+void Client::ticketHistoryList(int id, bool longFormat)
+{
+ rtclient_ticket_history_list(id, longFormat,
+ [](struct rtclient_ticket_history** list) {
+ client->emitGotTicketHistoryList(TicketHistoryList{list});
+ size_t i = 0;
+// while (list[i]) rtclient_ticket_history_free(list[i++]);
+ });
+}
+
+void Client::emitLoggedIn(QString const& name)
+{
+ emit loggedIn(name);
+}
+
+void Client::emitUserShown(User const& user)
+{
+ emit userShown(user);
+}
+
+void Client::emitSearchedTicket(TicketList const& list)
+{
+ emit searchedTicket(list);
+}
+
+void Client::emitGotTicketHistoryList(TicketHistoryList const& list)
+{
+ emit gotTicketHistoryList(list);
+}
+
+Client::~Client()
+{
+ rtclient_cleanup();
+}
}
diff --git a/qrtclient.hxx b/qrtclient.hxx
index 51ddcad..8ee76b3 100644
--- a/qrtclient.hxx
+++ b/qrtclient.hxx
@@ -2,11 +2,9 @@
#define QRTCLIENT_HXX
#include <QObject>
-#include <rtclient/user.h>
-
-struct rtclient_user;
-struct rtclient_search_ticket_list;
-struct rtclient_ticket_history_list;
+#include "qrtclient/user.hxx"
+#include "qrtclient/ticket.hxx"
+#include "qrtclient/tickethistory.hxx"
namespace RTClient {
@@ -14,6 +12,10 @@ class Client : public QObject
{
Q_OBJECT
+ public:
+ Client(char const* url, char const* cookies,
+ char const* certificate = nullptr);
+ ~Client();
public slots:
void logIn(QString const& name, QString const& password);
@@ -61,17 +63,19 @@ class Client : public QObject
QString const& text = nullptr);
void searchTicket(QString const& owner);
void ticketHistoryList(int id, bool longFormat = false);
- public:
- Client(char const* url, char const* certificate = nullptr);
- ~Client();
+ signals:
+ void loggedIn(QString const& name);
+ void userShown(User const& user);
+ void searchedTicket(TicketList const& list);
+ void gotTicketHistoryList(TicketHistoryList const& list);
- signals:
- void loggedIn(QString const& name);
- void userShown(rtclient_user* user);
- void searchedTicket(rtclient_search_ticket_list* list);
- void gotTicketHistory(rtclient_ticket_history_list* list);
- };
+ protected:
+ void emitLoggedIn(QString const&);
+ void emitUserShown(User const&);
+ void emitSearchedTicket(TicketList const&);
+ void emitGotTicketHistoryList(TicketHistoryList const&);
+};
}
diff --git a/qrtclient/ticket.hxx b/qrtclient/ticket.hxx
index 080a296..6e3d0eb 100644
--- a/qrtclient/ticket.hxx
+++ b/qrtclient/ticket.hxx
@@ -3,9 +3,6 @@
#include <QAbstractListModel>
#include <rtclient/ticket.h>
-#include <rtclient/search.h>
-
-struct rtclient_search_ticket_list;
namespace RTClient {
@@ -34,8 +31,12 @@ class TicketList : public QAbstractListModel
SubjectRole
};
- explicit TicketList(QObject* parent = nullptr)
- : QAbstractListModel{parent} {}
+ TicketList(QObject* parent = nullptr)
+ : QAbstractListModel{parent} {}
+ TicketList(struct rtclient_ticket** list,
+ QObject* parent = nullptr);
+ TicketList(TicketList const& list) { tickets = list.tickets; }
+ ~TicketList() {}
int rowCount(QModelIndex const& parent
= QModelIndex()) const Q_DECL_OVERRIDE;
@@ -46,14 +47,12 @@ class TicketList : public QAbstractListModel
protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
- signals:
- void updated();
- void rowCountChanged();
-
private:
QList<Ticket> tickets;
};
}
+Q_DECLARE_METATYPE(RTClient::TicketList)
+
#endif
diff --git a/qrtclient/tickethistory.hxx b/qrtclient/tickethistory.hxx
index effe9f1..bfc77ac 100644
--- a/qrtclient/tickethistory.hxx
+++ b/qrtclient/tickethistory.hxx
@@ -5,8 +5,6 @@
#include <QDateTime>
#include <rtclient/ticket.h>
-struct rtclient_ticket_history_list;
-
namespace RTClient {
class TicketHistory
@@ -63,7 +61,6 @@ class TicketHistory
class TicketHistoryList : public QAbstractListModel
{
Q_OBJECT
- Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
public:
enum TicketHistoryRoles {
@@ -82,8 +79,15 @@ class TicketHistoryList : public QAbstractListModel
AttachmentsRole*/
};
- explicit TicketHistoryList(QObject* parent = nullptr)
- : QAbstractListModel{parent} {}
+ TicketHistoryList(QObject* parent = nullptr)
+ : QAbstractListModel{parent} {}
+ TicketHistoryList(struct rtclient_ticket_history** list,
+ QObject* parent = nullptr);
+ TicketHistoryList(TicketHistoryList const& list)
+ {
+ histories = list.histories;
+ }
+ ~TicketHistoryList() {}
int rowCount(QModelIndex const& parent
= QModelIndex()) const Q_DECL_OVERRIDE;
@@ -91,20 +95,15 @@ class TicketHistoryList : public QAbstractListModel
int role = Qt::DisplayRole
) const Q_DECL_OVERRIDE;
- public slots:
- void update(rtclient_ticket_history_list* list);
-
protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
- signals:
- void rowCountChanged();
- void updated();
-
private:
QList<TicketHistory> histories;
};
}
+Q_DECLARE_METATYPE(RTClient::TicketHistoryList)
+
#endif
diff --git a/qrtclient/user.hxx b/qrtclient/user.hxx
index d258820..d76b8e4 100644
--- a/qrtclient/user.hxx
+++ b/qrtclient/user.hxx
@@ -4,8 +4,6 @@
#include <QObject>
#include <rtclient/user.h>
-struct rtclient_user;
-
namespace RTClient {
class User : public QObject
@@ -121,8 +119,6 @@ class User : public QObject
void setTimeZone(rtclient_user_timezone timezone);
void setPrivileged(bool privileged);
void setDisabled(bool disabled);
- public slots:
- void update(rtclient_user* user);
signals:
void idChanged();
diff --git a/ticket.cxx b/ticket.cxx
index e42207b..05b57ad 100644
--- a/ticket.cxx
+++ b/ticket.cxx
@@ -3,6 +3,18 @@
namespace RTClient {
+TicketList::TicketList(struct rtclient_ticket** list,
+ QObject* parent)
+ : QAbstractListModel{parent}
+{
+ size_t i = 0;
+ while (list[i]) {
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ tickets << Ticket{list[i++]};
+ endInsertRows();
+ }
+}
+
int TicketList::rowCount(QModelIndex const& parent) const
{
Q_UNUSED(parent)
@@ -33,22 +45,4 @@ QHash<int, QByteArray> TicketList::roleNames() const
};
}
- void TicketList::addTicket(Ticket const& ticket)
- {
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- tickets << ticket;
- endInsertRows();
- emit rowCountChanged();
- }
-
- void TicketList::update(rtclient_search_ticket_list* list)
- {
- if (list) {
- for (size_t i = 0; i < list->length; i++)
- addTicket(Ticket{list->tickets[i]});
- rtclient_search_ticket_free(list);
- emit updated();
- }
- }
-
}
diff --git a/tickethistory.cxx b/tickethistory.cxx
index d163882..ae0e2d7 100644
--- a/tickethistory.cxx
+++ b/tickethistory.cxx
@@ -3,6 +3,18 @@
namespace RTClient {
+TicketHistoryList::TicketHistoryList(struct rtclient_ticket_history** list,
+ QObject* parent)
+ : QAbstractListModel{parent}
+{
+ size_t i = 0;
+ while (list[i]) {
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ histories << TicketHistory{list[i++]};
+ endInsertRows();
+ }
+}
+
int TicketHistoryList::rowCount(QModelIndex const& parent) const
{
Q_UNUSED(parent)
@@ -66,22 +78,4 @@ QHash<int, QByteArray> TicketHistoryList::roleNames() const
};
}
- void TicketHistoryList::addTicketHistory(TicketHistory const& history)
- {
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- histories << history;
- endInsertRows();
- }
-
- void TicketHistoryList::update(rtclient_ticket_history_list* list)
- {
- if (list) {
- for (size_t i = 0; i < list->length; i++)
- addTicketHistory
- (TicketHistory{list->histories[i]});
- rtclient_ticket_history_list_free(list);
- emit updated();
- }
- }
-
}
diff --git a/user.cxx b/user.cxx
index 59229da..8bc593c 100644
--- a/user.cxx
+++ b/user.cxx
@@ -1,5 +1,3 @@
-#include <cstddef>
-#include <rtclient.h>
#include "qrtclient/user.hxx"
namespace RTClient {
@@ -201,117 +199,6 @@ void User::setDisabled(bool disabled)
if (m_disabled != disabled) {
m_disabled = disabled;
emit disabledChanged();
- void User::update(rtclient_user* user)
- {
- if (user) {
- if (user->id) {
- m_id = user->id;
- emit idChanged();
- }
- if (user->email_address) {
- m_emailAddress = user->email_address;
- emit emailAddressChanged();
- }
- if (user->real_name) {
- m_realName = user->real_name;
- emit realNameChanged();
- }
- if (user->nick_name) {
- m_nickName = user->nick_name;
- emit nickNameChanged();
- }
- if (user->organization) {
- m_organization = user->organization;
- emit organizationChanged();
- }
- if (user->address1) {
- m_address1 = user->address1;
- emit address1Changed();
- }
- if (user->address2) {
- m_address2 = user->address2;
- emit address2Changed();
- }
- if (user->city) {
- m_city = user->city;
- emit cityChanged();
- }
- if (user->state) {
- m_state = user->state;
- emit stateChanged();
- }
- if (user->zip) {
- m_zip = user->zip;
- emit zipChanged();
- }
- if (user->country) {
- m_country = user->country;
- emit countryChanged();
- }
- if (user->home_phone) {
- m_homePhone = user->home_phone;
- emit homePhoneChanged();
- }
- if (user->work_phone) {
- m_workPhone = user->work_phone;
- emit workPhoneChanged();
- }
- if (user->mobile_phone) {
- m_mobilePhone = user->mobile_phone;
- emit mobilePhoneChanged();
- }
- if (user->pager_phone) {
- m_pagerPhone = user->pager_phone;
- emit pagerPhoneChanged();
- }
- if (user->gecos) {
- m_gecos = user->gecos;
- emit gecosChanged();
- }
- if (user->timezone) {
- m_timezone = user->timezone;
- emit timezoneChanged();
- }
- if (user->lang) {
- m_lang = user->lang;
- emit langChanged();
- }
- if (user->privileged) {
- m_privileged = user->privileged;
- emit privilegedChanged();
- }
- if (!user->disabled) {
- m_disabled = user->disabled;
- emit disabledChanged();
- }
- rtclient_user_free(user);
- } else {
- m_id = 0;
- m_name = "";
- m_password = "";
- m_emailAddress = "";
- m_realName = "";
- m_nickName = "";
- m_organization = "";
- m_address1 = "";
- m_address2 = "";
- m_city = "";
- m_state = "";
- m_zip = "";
- m_country = "";
- m_homePhone = "";
- m_workPhone = "";
- m_mobilePhone = "";
- m_pagerPhone = "";
- m_contactInfo = "";
- m_comments = "";
- m_signature = "";
- m_gecos = "";
- m_lang = RTCLIENT_USER_LANG_NONE;
- m_timezone = RTCLIENT_USER_TIMEZONE_NONE;
- m_privileged = false;
- m_disabled = true;
- }
}
}