Skip to content

Commit

Permalink
Rewrite Kaidan [part 2]
Browse files Browse the repository at this point in the history
  • Loading branch information
LNJ committed Jul 1, 2017
1 parent 528ffc9 commit b1e942c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
15 changes: 14 additions & 1 deletion src/Kaidan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QSettings>
#include <QString>
#include <QStandardPaths>
#include <QTimer>
// Boost
#include <boost/bind.hpp>
// gloox
Expand Down Expand Up @@ -111,7 +112,11 @@ void Kaidan::mainConnect()
// Roster
rosterManager = new RosterManager(rosterModel, client);

client->connect();
client->connect(false);

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateClient()));
timer->start(100);

// client = new Swift::Client(jid.toStdString(), password.toStdString(), netFactories, storages);
//
Expand Down Expand Up @@ -173,6 +178,14 @@ bool Kaidan::onTLSConnect(const gloox::CertInfo &info)
return true;
}

void Kaidan::updateClient()
{
qDebug() << "updating client";
// parse new incoming network packages
client->recv(10);
qDebug() << "finished updating";
}

bool Kaidan::newLoginNeeded()
{
return (jid == "") || (password == "");
Expand Down
17 changes: 9 additions & 8 deletions src/Kaidan.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ class Kaidan : public QObject, public gloox::ConnectionListener
Kaidan(QObject *parent = 0);
~Kaidan();

Q_INVOKABLE void mainDisconnect();
Q_INVOKABLE void mainConnect();
Q_INVOKABLE void mainDisconnect();
Q_INVOKABLE bool newLoginNeeded();
Q_INVOKABLE void sendMessage(QString jid, QString message);
Q_INVOKABLE void addContact(QString jid, QString nick);
Q_INVOKABLE void removeContact(QString jid);
Q_INVOKABLE QString getResourcePath(QString);
Q_INVOKABLE QString getVersionString();

bool getConnectionState() const;
QString getJid();
Expand All @@ -70,17 +75,10 @@ class Kaidan : public QObject, public gloox::ConnectionListener
void setPassword(QString);
QString getChatPartner();
void setChatPartner(QString);

RosterModel* getRosterModel();
MessageModel* getMessageModel();
VCardController* getVCardController();

Q_INVOKABLE void sendMessage(QString jid, QString message);
Q_INVOKABLE void addContact(QString jid, QString nick);
Q_INVOKABLE void removeContact(QString jid);
Q_INVOKABLE QString getResourcePath(QString);
Q_INVOKABLE QString getVersionString();

virtual void onConnect();
virtual void onDisconnect(gloox::ConnectionError error);
virtual bool onTLSConnect(const gloox::CertInfo &info);
Expand All @@ -96,6 +94,9 @@ class Kaidan : public QObject, public gloox::ConnectionListener
void passwordChanged();
void chatPartnerChanged();

private slots:
void updateClient();

private:
gloox::Client *client;

Expand Down
7 changes: 3 additions & 4 deletions src/MessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void MessageHandler::handleMessage(const gloox::Message &message, gloox::Message

const QString msgId = QString::fromStdString(message.id());

messageModel->addMessage(&author, &author_resource, &recipient,
&recipient_resource, &timestamp, &body, &msgId, false);
messageModel->addMessage(&author, &recipient, &timestamp, &body, &msgId,
false, &author_resource, &recipient_resource);

// send a new notification | TODO: Resolve nickname from JID
Notifications::sendMessageNotification(message.from().full(), body.toStdString());
Expand Down Expand Up @@ -95,8 +95,7 @@ void MessageHandler::sendMessage(QString *fromJid, QString *toJid, QString *body
const QString timestamp = QDateTime::currentDateTime().toString(Qt::ISODate);
const QString id = QString::fromStdString(message.id());

messageModel->addMessage(fromJid, nullptr, toJid, nullptr, &timestamp, body,
&id, true);
messageModel->addMessage(fromJid, toJid, &timestamp, body, &id, true);

// XEP-0184: Message Delivery Receipts
// request a delivery receipt from the other client
Expand Down
8 changes: 4 additions & 4 deletions src/MessageModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void MessageModel::setMessageAsDelivered(const QString msgId)
submitAll();
}

void MessageModel::addMessage(const QString *author, const QString *author_resource,
const QString *recipient, const QString *recipient_resource,
const QString *timestamp, const QString *message, const QString *msgId,
bool sentByMe)
void MessageModel::addMessage(const QString *author, const QString *recipient,
const QString *timestamp, const QString *message,
const QString *msgId, bool sentByMe,
const QString *author_resource, const QString *recipient_resource)
{
//
// add the new message
Expand Down
9 changes: 5 additions & 4 deletions src/MessageModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class MessageModel : public QSqlTableModel
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;

void applyRecipientFilter(QString *recipient_, QString *author_);
void addMessage(const QString *author, const QString *author_resource,
const QString *recipient, const QString *recipient_resource,
const QString *timestamp, const QString *message,
const QString *msgId, bool sentByMe);
void addMessage(const QString *author, const QString *recipient,
const QString *timestamp, const QString *message,
const QString *msgId, bool sentByMe,
const QString *author_resource = new QString(),
const QString *recipient_resource = new QString());
void setMessageAsSent(const QString msgId);
void setMessageAsDelivered(const QString msgId);

Expand Down

0 comments on commit b1e942c

Please sign in to comment.