beautifull messageList, messages now being sent to full jid
This commit is contained in:
parent
e48444636a
commit
6e9e100188
@ -33,6 +33,7 @@ void Core::Squawk::stop()
|
||||
settings.setValue("server", acc->getServer());
|
||||
settings.setValue("login", acc->getLogin());
|
||||
settings.setValue("password", acc->getPassword());
|
||||
settings.setValue("resource", acc->getResource());
|
||||
}
|
||||
settings.endArray();
|
||||
settings.endGroup();
|
||||
@ -51,7 +52,13 @@ void Core::Squawk::start()
|
||||
int size = settings.beginReadArray("accounts");
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
addAccount(settings.value("login").toString(), settings.value("server").toString(), settings.value("password").toString(), settings.value("name").toString());
|
||||
addAccount(
|
||||
settings.value("login").toString(),
|
||||
settings.value("server").toString(),
|
||||
settings.value("password").toString(),
|
||||
settings.value("name").toString(),
|
||||
settings.value("resource").toString()
|
||||
);
|
||||
}
|
||||
settings.endArray();
|
||||
settings.endGroup();
|
||||
@ -63,13 +70,15 @@ void Core::Squawk::newAccountRequest(const QMap<QString, QVariant>& map)
|
||||
QString login = map.value("login").toString();
|
||||
QString server = map.value("server").toString();
|
||||
QString password = map.value("password").toString();
|
||||
QString resource = map.value("resource").toString();
|
||||
|
||||
addAccount(login, server, password, name);
|
||||
addAccount(login, server, password, name, resource);
|
||||
}
|
||||
|
||||
void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name)
|
||||
void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource)
|
||||
{
|
||||
Account* acc = new Account(login, server, password, name);
|
||||
acc->setResource(resource);
|
||||
accounts.push_back(acc);
|
||||
amap.insert(std::make_pair(name, acc));
|
||||
|
||||
@ -93,6 +102,7 @@ void Core::Squawk::addAccount(const QString& login, const QString& server, const
|
||||
{"server", server},
|
||||
{"name", name},
|
||||
{"password", password},
|
||||
{"resource", resource},
|
||||
{"state", Shared::disconnected},
|
||||
{"offline", Shared::offline}
|
||||
};
|
||||
|
@ -55,7 +55,7 @@ private:
|
||||
Shared::Availability state;
|
||||
|
||||
private:
|
||||
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name);
|
||||
void addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource);
|
||||
|
||||
private slots:
|
||||
void onAccountConnectionStateChanged(int state);
|
||||
|
49
global.cpp
49
global.cpp
@ -8,7 +8,8 @@ Shared::Message::Message(Shared::Message::Type p_type):
|
||||
id(),
|
||||
body(),
|
||||
time(),
|
||||
type(p_type)
|
||||
type(p_type),
|
||||
outgoing(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -20,7 +21,8 @@ Shared::Message::Message():
|
||||
id(),
|
||||
body(),
|
||||
time(),
|
||||
type(Message::normal)
|
||||
type(Message::normal),
|
||||
outgoing(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -116,10 +118,49 @@ QString Shared::Message::getToResource() const
|
||||
|
||||
QString Shared::Message::getPenPalJid() const
|
||||
{
|
||||
return jFrom;
|
||||
if (outgoing) {
|
||||
return jTo;
|
||||
} else {
|
||||
return jFrom;
|
||||
}
|
||||
}
|
||||
|
||||
QString Shared::Message::getPenPalResource() const
|
||||
{
|
||||
return rFrom;
|
||||
if (outgoing) {
|
||||
return rTo;
|
||||
} else {
|
||||
return rFrom;
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::Message::setFromJid(const QString& from)
|
||||
{
|
||||
jFrom = from;
|
||||
}
|
||||
|
||||
void Shared::Message::setFromResource(const QString& from)
|
||||
{
|
||||
rFrom = from;
|
||||
}
|
||||
|
||||
void Shared::Message::setToJid(const QString& to)
|
||||
{
|
||||
jTo = to;
|
||||
}
|
||||
|
||||
void Shared::Message::setToResource(const QString& to)
|
||||
{
|
||||
rTo = to;
|
||||
}
|
||||
|
||||
bool Shared::Message::getOutgoing() const
|
||||
{
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
void Shared::Message::setOutgoing(bool og)
|
||||
{
|
||||
outgoing = og;
|
||||
}
|
||||
|
||||
|
7
global.h
7
global.h
@ -65,10 +65,15 @@ public:
|
||||
Message();
|
||||
|
||||
void setFrom(const QString& from);
|
||||
void setFromResource(const QString& from);
|
||||
void setFromJid(const QString& from);
|
||||
void setTo(const QString& to);
|
||||
void setToResource(const QString& to);
|
||||
void setToJid(const QString& to);
|
||||
void setTime(const QDateTime& p_time);
|
||||
void setId(const QString& p_id);
|
||||
void setBody(const QString& p_body);
|
||||
void setOutgoing(bool og);
|
||||
|
||||
QString getFrom() const;
|
||||
QString getFromJid() const;
|
||||
@ -79,6 +84,7 @@ public:
|
||||
QDateTime getTime() const;
|
||||
QString getId() const;
|
||||
QString getBody() const;
|
||||
bool getOutgoing() const;
|
||||
|
||||
QString getPenPalJid() const;
|
||||
QString getPenPalResource() const;
|
||||
@ -92,6 +98,7 @@ private:
|
||||
QString body;
|
||||
QDateTime time;
|
||||
Type type;
|
||||
bool outgoing;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -18,6 +18,7 @@ QMap<QString, QVariant> Account::value() const
|
||||
map["password"] = m_ui->password->text();
|
||||
map["server"] = m_ui->server->text();
|
||||
map["name"] = m_ui->name->text();
|
||||
map["resource"] = m_ui->resource->text();
|
||||
|
||||
return map;
|
||||
}
|
||||
|
@ -102,6 +102,23 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Resource</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLineEdit" name="resource">
|
||||
<property name="toolTip">
|
||||
<string>A resource name like "Home" or "Work"</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>QXmpp</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -36,6 +36,7 @@ Conversation::Conversation(Models::Contact* p_contact, QWidget* parent):
|
||||
|
||||
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
|
||||
connect(&ker, SIGNAL(enterPressed()), this, SLOT(onEnterPressed()));
|
||||
connect(m_ui->sendButton, SIGNAL(clicked(bool)), this, SLOT(onEnterPressed()));
|
||||
|
||||
m_ui->messageEditor->installEventFilter(&ker);
|
||||
|
||||
@ -138,9 +139,11 @@ void Conversation::onEnterPressed()
|
||||
const QString& aJid = contact->getAccountJid();
|
||||
m_ui->messageEditor->clear();
|
||||
Shared::Message msg(Shared::Message::chat);
|
||||
msg.setFrom(aJid);
|
||||
msg.setFromJid(aJid);
|
||||
msg.setFromResource(contact->getAccountResource());
|
||||
msg.setTo(contact->getJid());
|
||||
msg.setBody(body);
|
||||
msg.setOutgoing(true);
|
||||
line->message(msg);
|
||||
emit sendMessage(msg);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ MessageLine::MessageLine(QWidget* parent):
|
||||
{
|
||||
setLayout(layout);
|
||||
setBackgroundRole(QPalette::Base);
|
||||
layout->addStretch();
|
||||
}
|
||||
|
||||
MessageLine::~MessageLine()
|
||||
@ -38,16 +39,31 @@ void MessageLine::message(const Shared::Message& msg)
|
||||
QHBoxLayout* hBox = new QHBoxLayout();
|
||||
QWidget* message = new QWidget();
|
||||
message->setLayout(vBox);
|
||||
//message->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
message->setBackgroundRole(QPalette::AlternateBase);
|
||||
message->setAutoFillBackground(true);;
|
||||
|
||||
QLabel* body = new QLabel(msg.getBody());
|
||||
QLabel* sender = new QLabel(msg.getFrom());
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
sender->setFont(f);
|
||||
|
||||
body->setWordWrap(true);
|
||||
|
||||
vBox->addWidget(body);
|
||||
vBox->addWidget(sender);
|
||||
vBox->addWidget(body);
|
||||
|
||||
hBox->addStretch();
|
||||
hBox->addWidget(message);
|
||||
if (msg.getOutgoing()) {
|
||||
body->setAlignment(Qt::AlignRight);
|
||||
sender->setAlignment(Qt::AlignRight);
|
||||
hBox->addStretch();
|
||||
hBox->addWidget(message);
|
||||
} else {
|
||||
hBox->addWidget(message);
|
||||
hBox->addStretch();
|
||||
}
|
||||
|
||||
layout->addItem(hBox);
|
||||
layout->addLayout(hBox);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ Models::Account::Account(const QMap<QString, QVariant>& data, Models::Item* pare
|
||||
login(data.value("login").toString()),
|
||||
password(data.value("password").toString()),
|
||||
server(data.value("server").toString()),
|
||||
resource(data.value("resource").toString()),
|
||||
state(Shared::disconnected),
|
||||
availability(Shared::offline)
|
||||
{
|
||||
@ -135,6 +136,8 @@ QVariant Models::Account::data(int column) const
|
||||
return password;
|
||||
case 5:
|
||||
return Shared::availabilityNames[availability];
|
||||
case 6:
|
||||
return resource;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -142,7 +145,7 @@ QVariant Models::Account::data(int column) const
|
||||
|
||||
int Models::Account::columnCount() const
|
||||
{
|
||||
return 6;
|
||||
return 7;
|
||||
}
|
||||
|
||||
void Models::Account::update(const QString& field, const QVariant& value)
|
||||
@ -159,5 +162,21 @@ void Models::Account::update(const QString& field, const QVariant& value)
|
||||
setState(value.toUInt());
|
||||
} else if (field == "availability") {
|
||||
setAvailability(value.toUInt());
|
||||
} else if (field == "resource") {
|
||||
setResource(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
QString Models::Account::getResource() const
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
|
||||
void Models::Account::setResource(const QString& p_resource)
|
||||
{
|
||||
if (resource != p_resource) {
|
||||
resource = p_resource;
|
||||
changed(6);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ namespace Models {
|
||||
void setPassword(const QString& p_password);
|
||||
QString getPassword() const;
|
||||
|
||||
void setResource(const QString& p_resource);
|
||||
QString getResource() const;
|
||||
|
||||
void setAvailability(Shared::Availability p_avail);
|
||||
void setAvailability(unsigned int p_avail);
|
||||
Shared::Availability getAvailability() const;
|
||||
@ -40,6 +43,7 @@ namespace Models {
|
||||
QString login;
|
||||
QString password;
|
||||
QString server;
|
||||
QString resource;
|
||||
Shared::ConnectionState state;
|
||||
Shared::Availability availability;
|
||||
};
|
||||
|
@ -206,16 +206,12 @@ QIcon Models::Contact::getStatusIcon() const
|
||||
|
||||
QString Models::Contact::getAccountName() const
|
||||
{
|
||||
const Item* p = this;
|
||||
do {
|
||||
p = p->parentItemConst();
|
||||
} while (p != 0 && p->type != Item::account);
|
||||
|
||||
if (p == 0) {
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account name of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return p->getName();
|
||||
return acc->getName();
|
||||
}
|
||||
|
||||
void Models::Contact::addMessage(const Shared::Message& data)
|
||||
@ -264,16 +260,31 @@ void Models::Contact::getMessages(Models::Contact::Messages& container) const
|
||||
}
|
||||
|
||||
QString Models::Contact::getAccountJid() const
|
||||
{
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account jid of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return acc->getLogin() + "@" + acc->getServer();
|
||||
}
|
||||
|
||||
QString Models::Contact::getAccountResource() const
|
||||
{
|
||||
const Account* acc = getParentAccount();
|
||||
if (acc == 0) {
|
||||
qDebug() << "An attempt to request account resource of the contact " << jid << " but the parent account wasn't found, returning empty string";
|
||||
return "";
|
||||
}
|
||||
return acc->getResource();
|
||||
}
|
||||
|
||||
const Models::Account * Models::Contact::getParentAccount() 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();
|
||||
return static_cast<const Account*>(p);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace Models {
|
||||
|
||||
class Account;
|
||||
class Contact : public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -34,6 +35,7 @@ public:
|
||||
void appendChild(Models::Item * child) override;
|
||||
QString getAccountName() const;
|
||||
QString getAccountJid() const;
|
||||
QString getAccountResource() const;
|
||||
|
||||
void addMessage(const Shared::Message& data);
|
||||
unsigned int getMessagesCount() const;
|
||||
@ -42,6 +44,7 @@ public:
|
||||
|
||||
protected:
|
||||
void _removeChild(int index) override;
|
||||
const Account* getParentAccount() const;
|
||||
|
||||
protected slots:
|
||||
void refresh();
|
||||
|
Loading…
Reference in New Issue
Block a user