forked from blue/squawk
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
|
/*
|
||
|
* Squawk messenger.
|
||
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
#include "chat.h"
|
||
|
|
||
|
Chat::Chat(Models::Contact* p_contact, QWidget* parent):
|
||
|
Conversation(p_contact->getAccountJid(), p_contact->getAccountResource(), p_contact->getJid(), "", p_contact->getAccountName(), parent),
|
||
|
contact(p_contact)
|
||
|
{
|
||
|
setName(p_contact->getContactName());
|
||
|
updateState();
|
||
|
setStatus(p_contact->getStatus());
|
||
|
|
||
|
connect(contact, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onContactChanged(Models::Item*, int, int)));
|
||
|
|
||
|
line->setMyName(p_contact->getAccountName());
|
||
|
|
||
|
Models::Contact::Messages deque;
|
||
|
contact->getMessages(deque);
|
||
|
|
||
|
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
|
||
|
addMessage(*itr);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Chat::~Chat()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void Chat::onContactChanged(Models::Item* item, int row, int col)
|
||
|
{
|
||
|
if (item == contact) {
|
||
|
switch (col) {
|
||
|
case 0:
|
||
|
setName(contact->getContactName());
|
||
|
break;
|
||
|
case 3:
|
||
|
updateState();
|
||
|
break;
|
||
|
case 5:
|
||
|
setStatus(contact->getStatus());
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Chat::updateState()
|
||
|
{
|
||
|
Shared::Availability av = contact->getAvailability();
|
||
|
statusIcon->setPixmap(Shared::availabilityIcon(av, true).pixmap(40));
|
||
|
statusIcon->setToolTip(Shared::availabilityNames[av]);
|
||
|
}
|
||
|
|
||
|
void Chat::setStatus(const QString& status)
|
||
|
{
|
||
|
statusLabel->setText(status);
|
||
|
}
|