basic sending messages
This commit is contained in:
parent
d3f537856f
commit
5575cff1f5
@ -406,3 +406,12 @@ QString Core::Account::getFullJid() const
|
|||||||
return getLogin() + "@" + getServer() + "/" + getResource();
|
return getLogin() + "@" + getServer() + "/" + getResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::Account::sendMessage(const QMap<QString, QString>& data)
|
||||||
|
{
|
||||||
|
if (state == Shared::connected) {
|
||||||
|
client.sendMessage(data.value("to"), data.value("body"));
|
||||||
|
} else {
|
||||||
|
qDebug() << "An attempt to send message with not connected account " << name << ", skipping";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ public:
|
|||||||
void setResource(const QString& p_resource);
|
void setResource(const QString& p_resource);
|
||||||
void setAvailability(Shared::Availability avail);
|
void setAvailability(Shared::Availability avail);
|
||||||
QString getFullJid() const;
|
QString getFullJid() const;
|
||||||
|
void sendMessage(const QMap<QString, QString>& data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionStateChanged(int);
|
void connectionStateChanged(int);
|
||||||
|
@ -199,3 +199,14 @@ void Core::Squawk::onAccountMessage(const QMap<QString, QString>& data)
|
|||||||
Account* acc = static_cast<Account*>(sender());
|
Account* acc = static_cast<Account*>(sender());
|
||||||
emit accountMessage(acc->getName(), data);
|
emit accountMessage(acc->getName(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::Squawk::sendMessage(const QString& account, const QMap<QString, QString>& data)
|
||||||
|
{
|
||||||
|
AccountsMap::const_iterator itr = amap.find(account);
|
||||||
|
if (itr == amap.end()) {
|
||||||
|
qDebug("An attempt to send a message with non existing account, skipping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
itr->second->sendMessage(data);
|
||||||
|
}
|
||||||
|
@ -44,6 +44,7 @@ public slots:
|
|||||||
void connectAccount(const QString& account);
|
void connectAccount(const QString& account);
|
||||||
void disconnectAccount(const QString& account);
|
void disconnectAccount(const QString& account);
|
||||||
void changeState(int state);
|
void changeState(int state);
|
||||||
|
void sendMessage(const QString& account, const QMap<QString, QString>& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<Account*> Accounts;
|
typedef std::deque<Account*> Accounts;
|
||||||
|
13
global.h
13
global.h
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
namespace Shared {
|
namespace Shared {
|
||||||
|
|
||||||
@ -51,6 +52,18 @@ static const std::deque<QString> availabilityNames = {"Online", "Away", "Absent"
|
|||||||
|
|
||||||
static const std::deque<QString> subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"};
|
static const std::deque<QString> subscriptionStateThemeIcons = {"edit-none", "arrow-down-double", "arrow-up-double", "dialog-ok", "question"};
|
||||||
|
|
||||||
|
class Message {
|
||||||
|
public:
|
||||||
|
Message();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString jFrom;
|
||||||
|
QString rFrom;
|
||||||
|
QString jTo;
|
||||||
|
QString rTo;
|
||||||
|
QDateTime time;
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GLOBAL_H
|
#endif // GLOBAL_H
|
||||||
|
1
main.cpp
1
main.cpp
@ -34,6 +34,7 @@ int main(int argc, char *argv[])
|
|||||||
QObject::connect(&w, SIGNAL(connectAccount(const QString&)), squawk, SLOT(connectAccount(const QString&)));
|
QObject::connect(&w, SIGNAL(connectAccount(const QString&)), squawk, SLOT(connectAccount(const QString&)));
|
||||||
QObject::connect(&w, SIGNAL(disconnectAccount(const QString&)), squawk, SLOT(disconnectAccount(const QString&)));
|
QObject::connect(&w, SIGNAL(disconnectAccount(const QString&)), squawk, SLOT(disconnectAccount(const QString&)));
|
||||||
QObject::connect(&w, SIGNAL(changeState(int)), squawk, SLOT(changeState(int)));
|
QObject::connect(&w, SIGNAL(changeState(int)), squawk, SLOT(changeState(int)));
|
||||||
|
QObject::connect(&w, SIGNAL(sendMessage(const QString&, const QMap<QString, QString>&)), squawk, SLOT(sendMessage(const QString&, const QMap<QString, QString>&)));
|
||||||
|
|
||||||
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
|
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
|
||||||
QObject::connect(squawk, SIGNAL(accountAvailabilityChanged(const QString&, int)), &w, SLOT(accountAvailabilityChanged(const QString&, int)));
|
QObject::connect(squawk, SIGNAL(accountAvailabilityChanged(const QString&, int)), &w, SLOT(accountAvailabilityChanged(const QString&, int)));
|
||||||
|
@ -37,6 +37,13 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
|
|||||||
connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
|
connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
|
||||||
|
|
||||||
m_ui->messageEditor->installEventFilter(&ker);
|
m_ui->messageEditor->installEventFilter(&ker);
|
||||||
|
|
||||||
|
Models::Contact::Messages deque;
|
||||||
|
contact->getMessages(deque);
|
||||||
|
|
||||||
|
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
|
||||||
|
addMessage(*itr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Conversation::~Conversation()
|
Conversation::~Conversation()
|
||||||
@ -124,5 +131,8 @@ bool KeyEnterReceiver::eventFilter(QObject* obj, QEvent* event)
|
|||||||
|
|
||||||
void Conversation::onEnterPressed()
|
void Conversation::onEnterPressed()
|
||||||
{
|
{
|
||||||
qDebug() << "enter";
|
QString msg(m_ui->messageEditor->toPlainText());
|
||||||
|
m_ui->messageEditor->clear();
|
||||||
|
m_ui->dialogBox->append(contact->getAccountJid() + ": " + msg);
|
||||||
|
emit sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,9 @@ public:
|
|||||||
QString getAccount() const;
|
QString getAccount() const;
|
||||||
void addMessage(const QMap<QString, QString>& data);
|
void addMessage(const QMap<QString, QString>& data);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sendMessage(const QString& message);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setState(Shared::Availability state);
|
void setState(Shared::Availability state);
|
||||||
void setStatus(const QString& status);
|
void setStatus(const QString& status);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "contact.h"
|
#include "contact.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "account.h"
|
||||||
|
|
||||||
Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
Models::Contact::Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem):
|
||||||
Item(Item::contact, data, parentItem),
|
Item(Item::contact, data, parentItem),
|
||||||
@ -249,3 +250,30 @@ void Models::Contact::dropMessages()
|
|||||||
itr.value()->dropMessages();
|
itr.value()->dropMessages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Models::Contact::getMessages(Models::Contact::Messages& container) const
|
||||||
|
{
|
||||||
|
for (Messages::const_iterator itr = messages.begin(), end = messages.end(); itr != end; ++itr) {
|
||||||
|
const QMap<QString, QString>& msg = *itr;
|
||||||
|
container.push_back(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (QMap<QString, Presence*>::const_iterator itr = presences.begin(), end = presences.end(); itr != end; ++itr) {
|
||||||
|
itr.value()->getMessages(container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Models::Contact::getAccountJid() const
|
||||||
|
{
|
||||||
|
const Item* p = this;
|
||||||
|
do {
|
||||||
|
p = p->parentItemConst();
|
||||||
|
} while (p != 0 && p->type != Item::account);
|
||||||
|
|
||||||
|
if (p == 0) {
|
||||||
|
qDebug() << "An attempt to request account jid of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const Account* acc = static_cast<const Account*>(p);
|
||||||
|
return acc->getLogin() + "@" + acc->getServer();
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ class Contact : public Item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
typedef std::deque<QMap<QString, QString>> Messages;
|
||||||
Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
Contact(const QString& p_jid ,const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||||
~Contact();
|
~Contact();
|
||||||
|
|
||||||
@ -32,10 +33,12 @@ public:
|
|||||||
|
|
||||||
void appendChild(Models::Item * child) override;
|
void appendChild(Models::Item * child) override;
|
||||||
QString getAccountName() const;
|
QString getAccountName() const;
|
||||||
|
QString getAccountJid() const;
|
||||||
|
|
||||||
void addMessage(const QMap<QString, QString>& data);
|
void addMessage(const QMap<QString, QString>& data);
|
||||||
unsigned int getMessagesCount() const;
|
unsigned int getMessagesCount() const;
|
||||||
void dropMessages();
|
void dropMessages();
|
||||||
|
void getMessages(Messages& container) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _removeChild(int index) override;
|
void _removeChild(int index) override;
|
||||||
@ -51,7 +54,6 @@ protected:
|
|||||||
void setJid(const QString p_jid);
|
void setJid(const QString p_jid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<QMap<QString, QString>> Messages;
|
|
||||||
QString jid;
|
QString jid;
|
||||||
Shared::Availability availability;
|
Shared::Availability availability;
|
||||||
Shared::SubscriptionState state;
|
Shared::SubscriptionState state;
|
||||||
|
@ -149,3 +149,10 @@ QIcon Models::Presence::getStatusIcon() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Models::Presence::getMessages(Models::Presence::Messages& container) const
|
||||||
|
{
|
||||||
|
for (Messages::const_iterator itr = messages.begin(), end = messages.end(); itr != end; ++itr) {
|
||||||
|
const QMap<QString, QString>& msg = *itr;
|
||||||
|
container.push_back(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ class Presence : public Models::Item
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
typedef std::deque<QMap<QString, QString>> Messages;
|
||||||
explicit Presence(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
explicit Presence(const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
||||||
~Presence();
|
~Presence();
|
||||||
|
|
||||||
@ -51,9 +52,10 @@ public:
|
|||||||
unsigned int getMessagesCount() const;
|
unsigned int getMessagesCount() const;
|
||||||
void dropMessages();
|
void dropMessages();
|
||||||
void addMessage(const QMap<QString, QString>& data);
|
void addMessage(const QMap<QString, QString>& data);
|
||||||
|
|
||||||
|
void getMessages(Messages& container) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<QMap<QString, QString>> Messages;
|
|
||||||
Shared::Availability availability;
|
Shared::Availability availability;
|
||||||
QDateTime lastActivity;
|
QDateTime lastActivity;
|
||||||
QString status;
|
QString status;
|
||||||
|
@ -182,6 +182,7 @@ void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|||||||
|
|
||||||
conv->setAttribute(Qt::WA_DeleteOnClose);
|
conv->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
|
connect(conv, SIGNAL(destroyed(QObject*)), this, SLOT(onConversationClosed(QObject*)));
|
||||||
|
connect(conv, SIGNAL(sendMessage(const QString&)), this, SLOT(onConversationMessage(const QString&)));
|
||||||
|
|
||||||
conversations.insert(std::make_pair(id, conv));
|
conversations.insert(std::make_pair(id, conv));
|
||||||
rosterModel.dropMessages(account, jid);
|
rosterModel.dropMessages(account, jid);
|
||||||
@ -215,3 +216,12 @@ void Squawk::accountMessage(const QString& account, const QMap<QString, QString>
|
|||||||
rosterModel.addMessage(account, data);
|
rosterModel.addMessage(account, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Squawk::onConversationMessage(const QString& item)
|
||||||
|
{
|
||||||
|
Conversation* conv = static_cast<Conversation*>(sender());
|
||||||
|
emit sendMessage(conv->getAccount(), {
|
||||||
|
{"to", conv->getJid()},
|
||||||
|
{"body", item}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -30,6 +30,7 @@ signals:
|
|||||||
void connectAccount(const QString&);
|
void connectAccount(const QString&);
|
||||||
void disconnectAccount(const QString&);
|
void disconnectAccount(const QString&);
|
||||||
void changeState(int state);
|
void changeState(int state);
|
||||||
|
void sendMessage(const QString& account, const QMap<QString, QString>& data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void newAccount(const QMap<QString, QVariant>& account);
|
void newAccount(const QMap<QString, QVariant>& account);
|
||||||
@ -63,6 +64,7 @@ private slots:
|
|||||||
void onConversationClosed(QObject* parent = 0);
|
void onConversationClosed(QObject* parent = 0);
|
||||||
void onComboboxActivated(int index);
|
void onComboboxActivated(int index);
|
||||||
void onRosterItemDoubleClicked(const QModelIndex& item);
|
void onRosterItemDoubleClicked(const QModelIndex& item);
|
||||||
|
void onConversationMessage(const QString& item);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user