2019-08-14 14:54:46 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
#include "squawk.h"
|
|
|
|
#include "ui_squawk.h"
|
2019-04-02 15:46:18 +00:00
|
|
|
#include <QDebug>
|
2019-04-07 20:14:15 +00:00
|
|
|
#include <QIcon>
|
2019-03-29 14:54:34 +00:00
|
|
|
|
|
|
|
Squawk::Squawk(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
|
|
|
m_ui(new Ui::Squawk),
|
2019-03-30 20:13:13 +00:00
|
|
|
accounts(0),
|
2019-04-09 15:04:08 +00:00
|
|
|
rosterModel(),
|
2019-06-12 17:18:18 +00:00
|
|
|
conversations(),
|
2019-06-18 15:08:03 +00:00
|
|
|
contextMenu(new QMenu()),
|
2019-10-22 15:13:56 +00:00
|
|
|
dbus("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()),
|
|
|
|
requestedFiles(),
|
2020-04-07 20:33:03 +00:00
|
|
|
vCards(),
|
|
|
|
requestedAccountsForPasswords(),
|
2020-04-11 20:00:15 +00:00
|
|
|
prompt(0),
|
2020-04-12 15:55:05 +00:00
|
|
|
currentConversation(0),
|
2020-04-14 16:30:33 +00:00
|
|
|
restoreSelection(),
|
|
|
|
needToRestore(false)
|
2019-03-29 14:54:34 +00:00
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
2019-03-31 21:05:09 +00:00
|
|
|
m_ui->roster->setModel(&rosterModel);
|
2019-06-12 17:18:18 +00:00
|
|
|
m_ui->roster->setContextMenuPolicy(Qt::CustomContextMenu);
|
2020-01-25 08:10:24 +00:00
|
|
|
m_ui->roster->setColumnWidth(1, 30);
|
2019-10-16 19:38:35 +00:00
|
|
|
m_ui->roster->setIconSize(QSize(20, 20));
|
|
|
|
m_ui->roster->header()->setStretchLastSection(false);
|
|
|
|
m_ui->roster->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
2019-03-29 14:54:34 +00:00
|
|
|
|
2020-04-04 16:40:32 +00:00
|
|
|
for (int i = static_cast<int>(Shared::AvailabilityLowest); i < static_cast<int>(Shared::AvailabilityHighest) + 1; ++i) {
|
2019-07-01 13:53:01 +00:00
|
|
|
Shared::Availability av = static_cast<Shared::Availability>(i);
|
2020-04-03 22:28:15 +00:00
|
|
|
m_ui->comboBox->addItem(Shared::availabilityIcon(av), Shared::Global::getName(av));
|
2019-04-07 20:14:15 +00:00
|
|
|
}
|
2020-04-03 22:28:15 +00:00
|
|
|
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
|
2019-04-07 20:14:15 +00:00
|
|
|
|
2019-11-02 20:50:25 +00:00
|
|
|
connect(m_ui->actionAccounts, &QAction::triggered, this, &Squawk::onAccounts);
|
|
|
|
connect(m_ui->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact);
|
|
|
|
connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference);
|
2020-04-15 17:27:38 +00:00
|
|
|
connect(m_ui->actionQuit, &QAction::triggered, this, &Squawk::close);
|
2019-11-02 20:50:25 +00:00
|
|
|
connect(m_ui->comboBox, qOverload<int>(&QComboBox::activated), this, &Squawk::onComboboxActivated);
|
2020-04-12 15:55:05 +00:00
|
|
|
//connect(m_ui->roster, &QTreeView::doubleClicked, this, &Squawk::onRosterItemDoubleClicked);
|
2019-11-02 20:50:25 +00:00
|
|
|
connect(m_ui->roster, &QTreeView::customContextMenuRequested, this, &Squawk::onRosterContextMenu);
|
2019-12-25 10:24:20 +00:00
|
|
|
connect(m_ui->roster, &QTreeView::collapsed, this, &Squawk::onItemCollepsed);
|
2020-04-11 20:00:15 +00:00
|
|
|
connect(m_ui->roster->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Squawk::onRosterSelectionChanged);
|
2019-06-15 15:29:15 +00:00
|
|
|
|
2019-11-02 20:50:25 +00:00
|
|
|
connect(rosterModel.accountsModel, &Models::Accounts::sizeChanged, this, &Squawk::onAccountsSizeChanged);
|
2020-04-12 15:55:05 +00:00
|
|
|
connect(contextMenu, &QMenu::aboutToHide, this, &Squawk::onContextAboutToHide);
|
2019-03-31 21:05:09 +00:00
|
|
|
//m_ui->mainToolBar->addWidget(m_ui->comboBox);
|
2019-10-23 14:49:56 +00:00
|
|
|
|
2020-03-30 21:17:10 +00:00
|
|
|
if (testAttribute(Qt::WA_TranslucentBackground)) {
|
|
|
|
m_ui->roster->viewport()->setAutoFillBackground(false);
|
|
|
|
}
|
2020-04-07 20:33:03 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("ui");
|
|
|
|
settings.beginGroup("window");
|
|
|
|
if (settings.contains("geometry")) {
|
|
|
|
restoreGeometry(settings.value("geometry").toByteArray());
|
|
|
|
}
|
|
|
|
if (settings.contains("state")) {
|
|
|
|
restoreState(settings.value("state").toByteArray());
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
2020-04-11 20:00:15 +00:00
|
|
|
|
|
|
|
if (settings.contains("splitter")) {
|
|
|
|
m_ui->splitter->restoreState(settings.value("splitter").toByteArray());
|
|
|
|
}
|
2020-04-07 20:33:03 +00:00
|
|
|
settings.endGroup();
|
2019-03-29 14:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Squawk::~Squawk() {
|
2019-06-12 17:18:18 +00:00
|
|
|
delete contextMenu;
|
2019-03-29 14:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onAccounts()
|
|
|
|
{
|
|
|
|
if (accounts == 0) {
|
2020-04-04 16:40:32 +00:00
|
|
|
accounts = new Accounts(rosterModel.accountsModel);
|
2019-03-29 14:54:34 +00:00
|
|
|
accounts->setAttribute(Qt::WA_DeleteOnClose);
|
2019-11-03 18:46:40 +00:00
|
|
|
connect(accounts, &Accounts::destroyed, this, &Squawk::onAccountsClosed);
|
|
|
|
connect(accounts, &Accounts::newAccount, this, &Squawk::newAccountRequest);
|
|
|
|
connect(accounts, &Accounts::changeAccount, this, &Squawk::modifyAccountRequest);
|
|
|
|
connect(accounts, &Accounts::connectAccount, this, &Squawk::connectAccount);
|
|
|
|
connect(accounts, &Accounts::disconnectAccount, this, &Squawk::disconnectAccount);
|
|
|
|
connect(accounts, &Accounts::removeAccount, this, &Squawk::removeAccountRequest);
|
2019-03-30 20:13:13 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
accounts->show();
|
|
|
|
} else {
|
2019-03-30 20:13:13 +00:00
|
|
|
accounts->show();
|
|
|
|
accounts->raise();
|
|
|
|
accounts->activateWindow();
|
2019-03-29 14:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 15:29:15 +00:00
|
|
|
void Squawk::onAccountsSizeChanged(unsigned int size)
|
|
|
|
{
|
|
|
|
if (size > 0) {
|
|
|
|
m_ui->actionAddContact->setEnabled(true);
|
2019-09-04 16:38:52 +00:00
|
|
|
m_ui->actionAddConference->setEnabled(true);
|
2019-06-15 15:29:15 +00:00
|
|
|
} else {
|
|
|
|
m_ui->actionAddContact->setEnabled(false);
|
2019-09-04 16:38:52 +00:00
|
|
|
m_ui->actionAddConference->setEnabled(false);
|
2019-06-15 15:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onNewContact()
|
|
|
|
{
|
|
|
|
NewContact* nc = new NewContact(rosterModel.accountsModel, this);
|
|
|
|
|
2019-11-03 18:46:40 +00:00
|
|
|
connect(nc, &NewContact::accepted, this, &Squawk::onNewContactAccepted);
|
|
|
|
connect(nc, &NewContact::rejected, nc, &NewContact::deleteLater);
|
2019-06-15 15:29:15 +00:00
|
|
|
|
|
|
|
nc->exec();
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:38:52 +00:00
|
|
|
void Squawk::onNewConference()
|
|
|
|
{
|
|
|
|
JoinConference* jc = new JoinConference(rosterModel.accountsModel, this);
|
|
|
|
|
2019-11-03 18:46:40 +00:00
|
|
|
connect(jc, &JoinConference::accepted, this, &Squawk::onJoinConferenceAccepted);
|
|
|
|
connect(jc, &JoinConference::rejected, jc, &JoinConference::deleteLater);
|
2019-09-04 16:38:52 +00:00
|
|
|
|
|
|
|
jc->exec();
|
|
|
|
}
|
|
|
|
|
2019-06-15 15:29:15 +00:00
|
|
|
void Squawk::onNewContactAccepted()
|
|
|
|
{
|
|
|
|
NewContact* nc = static_cast<NewContact*>(sender());
|
|
|
|
NewContact::Data value = nc->value();
|
|
|
|
|
|
|
|
emit addContactRequest(value.account, value.jid, value.name, value.groups);
|
|
|
|
|
|
|
|
nc->deleteLater();
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:38:52 +00:00
|
|
|
void Squawk::onJoinConferenceAccepted()
|
|
|
|
{
|
|
|
|
JoinConference* jc = static_cast<JoinConference*>(sender());
|
|
|
|
JoinConference::Data value = jc->value();
|
|
|
|
|
|
|
|
emit addRoomRequest(value.account, value.jid, value.nick, value.password, value.autoJoin);
|
|
|
|
|
|
|
|
jc->deleteLater();
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
void Squawk::closeEvent(QCloseEvent* event)
|
|
|
|
{
|
|
|
|
if (accounts != 0) {
|
|
|
|
accounts->close();
|
|
|
|
}
|
2019-10-22 15:13:56 +00:00
|
|
|
|
2019-04-09 15:04:08 +00:00
|
|
|
for (Conversations::const_iterator itr = conversations.begin(), end = conversations.end(); itr != end; ++itr) {
|
2019-10-22 15:13:56 +00:00
|
|
|
disconnect(itr->second, &Conversation::destroyed, this, &Squawk::onConversationClosed);
|
2019-04-09 15:04:08 +00:00
|
|
|
itr->second->close();
|
|
|
|
}
|
|
|
|
conversations.clear();
|
2019-03-29 14:54:34 +00:00
|
|
|
|
2019-10-22 15:13:56 +00:00
|
|
|
for (std::map<QString, VCard*>::const_iterator itr = vCards.begin(), end = vCards.end(); itr != end; ++itr) {
|
|
|
|
disconnect(itr->second, &VCard::destroyed, this, &Squawk::onVCardClosed);
|
|
|
|
itr->second->close();
|
|
|
|
}
|
|
|
|
vCards.clear();
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
QMainWindow::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Squawk::onAccountsClosed(QObject* parent)
|
|
|
|
{
|
|
|
|
accounts = 0;
|
|
|
|
}
|
2019-03-30 20:13:13 +00:00
|
|
|
|
|
|
|
void Squawk::newAccount(const QMap<QString, QVariant>& account)
|
|
|
|
{
|
2019-03-31 21:05:09 +00:00
|
|
|
rosterModel.addAccount(account);
|
2019-03-30 20:13:13 +00:00
|
|
|
}
|
2019-03-31 21:05:09 +00:00
|
|
|
|
|
|
|
void Squawk::onComboboxActivated(int index)
|
|
|
|
{
|
2020-04-03 22:28:15 +00:00
|
|
|
Shared::Availability av = Shared::Global::fromInt<Shared::Availability>(index);
|
|
|
|
if (av != Shared::Availability::offline) {
|
2019-04-03 18:15:36 +00:00
|
|
|
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
|
|
|
if (size > 0) {
|
2020-04-03 22:28:15 +00:00
|
|
|
emit changeState(av);
|
2019-04-03 18:15:36 +00:00
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
2020-04-03 22:28:15 +00:00
|
|
|
if (acc->getState() == Shared::ConnectionState::disconnected) {
|
2019-04-03 18:15:36 +00:00
|
|
|
emit connectAccount(acc->getName());
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-04-03 22:28:15 +00:00
|
|
|
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
2019-04-07 20:14:15 +00:00
|
|
|
} else {
|
2020-04-03 22:28:15 +00:00
|
|
|
emit changeState(av);
|
2019-04-03 18:15:36 +00:00
|
|
|
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
|
|
|
for (int i = 0; i != size; ++i) {
|
|
|
|
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
2020-04-03 22:28:15 +00:00
|
|
|
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
2019-04-03 18:15:36 +00:00
|
|
|
emit disconnectAccount(acc->getName());
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:46:34 +00:00
|
|
|
void Squawk::changeAccount(const QString& account, const QMap<QString, QVariant>& data)
|
2019-03-31 21:05:09 +00:00
|
|
|
{
|
2019-05-24 14:46:34 +00:00
|
|
|
for (QMap<QString, QVariant>::const_iterator itr = data.begin(), end = data.end(); itr != end; ++itr) {
|
|
|
|
QString attr = itr.key();
|
|
|
|
rosterModel.updateAccount(account, attr, *itr);
|
|
|
|
}
|
2019-04-07 20:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.addContact(account, jid, group, data);
|
2019-12-25 10:24:20 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("ui");
|
|
|
|
settings.beginGroup("roster");
|
|
|
|
settings.beginGroup(account);
|
|
|
|
if (settings.value("expanded", false).toBool()) {
|
|
|
|
QModelIndex ind = rosterModel.getAccountIndex(account);
|
|
|
|
m_ui->roster->expand(ind);
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
2019-04-03 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::addGroup(const QString& account, const QString& name)
|
|
|
|
{
|
|
|
|
rosterModel.addGroup(account, name);
|
2019-12-25 10:24:20 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("ui");
|
|
|
|
settings.beginGroup("roster");
|
|
|
|
settings.beginGroup(account);
|
|
|
|
if (settings.value("expanded", false).toBool()) {
|
|
|
|
QModelIndex ind = rosterModel.getAccountIndex(account);
|
|
|
|
m_ui->roster->expand(ind);
|
|
|
|
if (settings.value(name + "/expanded", false).toBool()) {
|
|
|
|
m_ui->roster->expand(rosterModel.getGroupIndex(account, name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
2019-04-03 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removeGroup(const QString& account, const QString& name)
|
|
|
|
{
|
2019-04-06 10:14:32 +00:00
|
|
|
rosterModel.removeGroup(account, name);
|
2019-04-03 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 20:14:15 +00:00
|
|
|
void Squawk::changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data)
|
2019-04-06 10:14:32 +00:00
|
|
|
{
|
2019-04-07 20:14:15 +00:00
|
|
|
rosterModel.changeContact(account, jid, data);
|
2019-04-06 10:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removeContact(const QString& account, const QString& jid)
|
|
|
|
{
|
|
|
|
rosterModel.removeContact(account, jid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removeContact(const QString& account, const QString& jid, const QString& group)
|
|
|
|
{
|
|
|
|
rosterModel.removeContact(account, jid, group);
|
|
|
|
}
|
2019-04-03 21:23:51 +00:00
|
|
|
|
2019-04-07 14:02:41 +00:00
|
|
|
void Squawk::addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.addPresence(account, jid, name, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removePresence(const QString& account, const QString& jid, const QString& name)
|
|
|
|
{
|
|
|
|
rosterModel.removePresence(account, jid, name);
|
|
|
|
}
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
void Squawk::stateChanged(Shared::Availability state)
|
2019-04-07 20:14:15 +00:00
|
|
|
{
|
2020-04-03 22:28:15 +00:00
|
|
|
m_ui->comboBox->setCurrentIndex(static_cast<int>(state));
|
2019-04-07 20:14:15 +00:00
|
|
|
}
|
2019-04-03 21:23:51 +00:00
|
|
|
|
2019-04-09 15:04:08 +00:00
|
|
|
void Squawk::onRosterItemDoubleClicked(const QModelIndex& item)
|
|
|
|
{
|
|
|
|
if (item.isValid()) {
|
|
|
|
Models::Item* node = static_cast<Models::Item*>(item.internalPointer());
|
2020-04-17 23:17:47 +00:00
|
|
|
if (node->type == Models::Item::reference) {
|
|
|
|
node = static_cast<Models::Reference*>(node)->dereference();
|
|
|
|
}
|
2019-04-09 15:04:08 +00:00
|
|
|
Models::Contact* contact = 0;
|
2019-08-28 11:40:55 +00:00
|
|
|
Models::Room* room = 0;
|
2019-04-12 15:22:10 +00:00
|
|
|
QString res;
|
2019-08-28 11:40:55 +00:00
|
|
|
Models::Roster::ElId* id = 0;
|
2019-04-09 15:04:08 +00:00
|
|
|
switch (node->type) {
|
|
|
|
case Models::Item::contact:
|
|
|
|
contact = static_cast<Models::Contact*>(node);
|
2019-08-28 11:40:55 +00:00
|
|
|
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
2019-04-09 15:04:08 +00:00
|
|
|
break;
|
|
|
|
case Models::Item::presence:
|
|
|
|
contact = static_cast<Models::Contact*>(node->parentItem());
|
2019-08-28 11:40:55 +00:00
|
|
|
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
2019-04-12 15:22:10 +00:00
|
|
|
res = node->getName();
|
2019-04-09 15:04:08 +00:00
|
|
|
break;
|
2019-08-28 11:40:55 +00:00
|
|
|
case Models::Item::room:
|
|
|
|
room = static_cast<Models::Room*>(node);
|
|
|
|
id = new Models::Roster::ElId(room->getAccountName(), room->getJid());
|
|
|
|
break;
|
2019-04-09 15:04:08 +00:00
|
|
|
default:
|
|
|
|
m_ui->roster->expand(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-28 11:40:55 +00:00
|
|
|
if (id != 0) {
|
|
|
|
Conversations::const_iterator itr = conversations.find(*id);
|
2019-12-20 15:41:20 +00:00
|
|
|
Models::Account* acc = rosterModel.getAccount(id->account);
|
2019-08-28 11:40:55 +00:00
|
|
|
Conversation* conv = 0;
|
|
|
|
bool created = false;
|
2019-09-12 20:54:44 +00:00
|
|
|
Models::Contact::Messages deque;
|
2019-04-09 15:04:08 +00:00
|
|
|
if (itr != conversations.end()) {
|
2019-08-28 11:40:55 +00:00
|
|
|
conv = itr->second;
|
|
|
|
} else if (contact != 0) {
|
|
|
|
created = true;
|
2019-12-20 15:41:20 +00:00
|
|
|
conv = new Chat(acc, contact);
|
2019-09-12 20:54:44 +00:00
|
|
|
contact->getMessages(deque);
|
2019-08-28 11:40:55 +00:00
|
|
|
} else if (room != 0) {
|
|
|
|
created = true;
|
2019-12-20 15:41:20 +00:00
|
|
|
conv = new Room(acc, room);
|
2019-09-12 20:54:44 +00:00
|
|
|
room->getMessages(deque);
|
2019-08-29 14:19:35 +00:00
|
|
|
|
|
|
|
if (!room->getJoined()) {
|
|
|
|
emit setRoomJoined(id->account, id->name, true);
|
|
|
|
}
|
2019-08-28 11:40:55 +00:00
|
|
|
}
|
2019-04-12 15:22:10 +00:00
|
|
|
|
2019-08-28 11:40:55 +00:00
|
|
|
if (conv != 0) {
|
|
|
|
if (created) {
|
|
|
|
conv->setAttribute(Qt::WA_DeleteOnClose);
|
2020-04-11 20:00:15 +00:00
|
|
|
subscribeConversation(conv);
|
2019-08-28 11:40:55 +00:00
|
|
|
conversations.insert(std::make_pair(*id, conv));
|
2019-09-12 20:54:44 +00:00
|
|
|
|
|
|
|
if (created) {
|
|
|
|
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
|
|
|
|
conv->addMessage(*itr);
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 15:22:10 +00:00
|
|
|
}
|
2019-04-09 15:04:08 +00:00
|
|
|
|
|
|
|
conv->show();
|
2019-08-28 11:40:55 +00:00
|
|
|
conv->raise();
|
|
|
|
conv->activateWindow();
|
2019-04-12 15:22:10 +00:00
|
|
|
|
|
|
|
if (res.size() > 0) {
|
2019-05-30 09:36:21 +00:00
|
|
|
conv->setPalResource(res);
|
2019-04-12 15:22:10 +00:00
|
|
|
}
|
2019-04-09 15:04:08 +00:00
|
|
|
}
|
2019-08-28 11:40:55 +00:00
|
|
|
|
2020-04-11 20:00:15 +00:00
|
|
|
delete id;
|
2019-04-09 15:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:08:03 +00:00
|
|
|
void Squawk::onConversationShown()
|
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
|
|
|
rosterModel.dropMessages(conv->getAccount(), conv->getJid());
|
|
|
|
}
|
|
|
|
|
2019-04-09 15:04:08 +00:00
|
|
|
void Squawk::onConversationClosed(QObject* parent)
|
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
2019-08-29 14:19:35 +00:00
|
|
|
Models::Roster::ElId id(conv->getAccount(), conv->getJid());
|
|
|
|
Conversations::const_iterator itr = conversations.find(id);
|
2020-04-11 20:00:15 +00:00
|
|
|
if (itr != conversations.end()) {
|
|
|
|
conversations.erase(itr);
|
2019-04-09 15:04:08 +00:00
|
|
|
}
|
2019-08-29 14:19:35 +00:00
|
|
|
if (conv->isMuc) {
|
|
|
|
Room* room = static_cast<Room*>(conv);
|
2019-08-31 20:50:05 +00:00
|
|
|
if (!room->autoJoined()) {
|
2019-08-29 14:19:35 +00:00
|
|
|
emit setRoomJoined(id.account, id.name, false);
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 15:04:08 +00:00
|
|
|
}
|
2019-04-09 22:01:25 +00:00
|
|
|
|
2019-09-12 20:54:44 +00:00
|
|
|
void Squawk::onConversationDownloadFile(const QString& messageId, const QString& url)
|
|
|
|
{
|
2019-09-17 15:16:09 +00:00
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.find(messageId);
|
|
|
|
bool created = false;
|
|
|
|
if (itr == requestedFiles.end()) {
|
|
|
|
itr = requestedFiles.insert(std::make_pair(messageId, std::set<Models::Roster::ElId>())).first;
|
|
|
|
created = true;
|
|
|
|
}
|
|
|
|
itr->second.insert(Models::Roster::ElId(conv->getAccount(), conv->getJid()));
|
|
|
|
if (created) {
|
|
|
|
emit downloadFileRequest(messageId, url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 13:38:01 +00:00
|
|
|
void Squawk::fileProgress(const QString& messageId, qreal value)
|
2019-09-17 15:16:09 +00:00
|
|
|
{
|
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
|
|
|
|
if (itr == requestedFiles.end()) {
|
2019-11-12 13:38:01 +00:00
|
|
|
qDebug() << "fileProgress in UI Squawk but there is nobody waiting for that id" << messageId << ", skipping";
|
2019-09-17 15:16:09 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
const std::set<Models::Roster::ElId>& convs = itr->second;
|
|
|
|
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
|
|
|
|
const Models::Roster::ElId& id = *cItr;
|
|
|
|
Conversations::const_iterator c = conversations.find(id);
|
|
|
|
if (c != conversations.end()) {
|
2019-11-12 13:38:01 +00:00
|
|
|
c->second->responseFileProgress(messageId, value);
|
2019-09-17 15:16:09 +00:00
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
currentConversation->responseFileProgress(messageId, value);
|
|
|
|
}
|
2019-09-17 15:16:09 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-12 20:54:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 13:38:01 +00:00
|
|
|
void Squawk::fileError(const QString& messageId, const QString& error)
|
2019-09-18 13:27:47 +00:00
|
|
|
{
|
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
|
|
|
|
if (itr == requestedFiles.end()) {
|
2019-11-12 13:38:01 +00:00
|
|
|
qDebug() << "fileError in UI Squawk but there is nobody waiting for that id" << messageId << ", skipping";
|
2019-09-18 13:27:47 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
const std::set<Models::Roster::ElId>& convs = itr->second;
|
|
|
|
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
|
|
|
|
const Models::Roster::ElId& id = *cItr;
|
|
|
|
Conversations::const_iterator c = conversations.find(id);
|
|
|
|
if (c != conversations.end()) {
|
2019-11-12 13:38:01 +00:00
|
|
|
c->second->fileError(messageId, error);
|
2019-09-18 13:27:47 +00:00
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
currentConversation->fileError(messageId, error);
|
|
|
|
}
|
2019-09-18 13:27:47 +00:00
|
|
|
}
|
|
|
|
requestedFiles.erase(itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-12 20:54:44 +00:00
|
|
|
void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path)
|
|
|
|
{
|
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
|
|
|
|
if (itr == requestedFiles.end()) {
|
|
|
|
qDebug() << "fileLocalPathResponse in UI Squawk but there is nobody waiting for that path, skipping";
|
|
|
|
return;
|
|
|
|
} else {
|
2019-09-18 13:27:47 +00:00
|
|
|
const std::set<Models::Roster::ElId>& convs = itr->second;
|
2019-09-12 20:54:44 +00:00
|
|
|
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
|
|
|
|
const Models::Roster::ElId& id = *cItr;
|
|
|
|
Conversations::const_iterator c = conversations.find(id);
|
|
|
|
if (c != conversations.end()) {
|
|
|
|
c->second->responseLocalFile(messageId, path);
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
currentConversation->responseLocalFile(messageId, path);
|
|
|
|
}
|
2019-09-12 20:54:44 +00:00
|
|
|
}
|
2019-09-18 13:27:47 +00:00
|
|
|
|
|
|
|
requestedFiles.erase(itr);
|
2019-09-12 20:54:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onConversationRequestLocalFile(const QString& messageId, const QString& url)
|
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.find(messageId);
|
|
|
|
bool created = false;
|
|
|
|
if (itr == requestedFiles.end()) {
|
|
|
|
itr = requestedFiles.insert(std::make_pair(messageId, std::set<Models::Roster::ElId>())).first;
|
|
|
|
created = true;
|
|
|
|
}
|
|
|
|
itr->second.insert(Models::Roster::ElId(conv->getAccount(), conv->getJid()));
|
|
|
|
if (created) {
|
|
|
|
emit fileLocalPathRequest(messageId, url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 14:58:59 +00:00
|
|
|
void Squawk::accountMessage(const QString& account, const Shared::Message& data)
|
2019-04-09 22:01:25 +00:00
|
|
|
{
|
2019-04-11 14:58:59 +00:00
|
|
|
const QString& from = data.getPenPalJid();
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Roster::ElId id({account, from});
|
|
|
|
Conversations::iterator itr = conversations.find(id);
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
currentConversation->addMessage(data);
|
|
|
|
QApplication::alert(this);
|
|
|
|
if (!isVisible() && !data.getForwarded()) {
|
|
|
|
notify(account, data);
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
2019-04-09 22:01:25 +00:00
|
|
|
if (itr != conversations.end()) {
|
2019-06-18 15:08:03 +00:00
|
|
|
Conversation* conv = itr->second;
|
|
|
|
conv->addMessage(data);
|
|
|
|
QApplication::alert(conv);
|
2020-04-11 20:00:15 +00:00
|
|
|
if (!found && conv->isMinimized()) {
|
2019-06-18 15:08:03 +00:00
|
|
|
rosterModel.addMessage(account, data);
|
2020-02-08 11:44:15 +00:00
|
|
|
}
|
|
|
|
if (!conv->isVisible() && !data.getForwarded()) {
|
|
|
|
notify(account, data);
|
2019-06-18 15:08:03 +00:00
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2019-06-18 15:08:03 +00:00
|
|
|
rosterModel.addMessage(account, data);
|
2019-04-12 15:22:10 +00:00
|
|
|
if (!data.getForwarded()) {
|
2019-06-18 15:08:03 +00:00
|
|
|
QApplication::alert(this);
|
|
|
|
notify(account, data);
|
2019-04-12 15:22:10 +00:00
|
|
|
}
|
2019-04-09 22:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 20:53:42 +00:00
|
|
|
|
2020-02-08 11:44:15 +00:00
|
|
|
void Squawk::changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Roster::ElId eid({account, jid});
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if (currentConversation != 0 && currentConversation->getId() == eid) {
|
|
|
|
currentConversation->changeMessage(id, data);
|
|
|
|
QApplication::alert(this);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Conversations::iterator itr = conversations.find(eid);
|
2020-02-08 11:44:15 +00:00
|
|
|
if (itr != conversations.end()) {
|
|
|
|
Conversation* conv = itr->second;
|
|
|
|
conv->changeMessage(id, data);
|
2020-04-11 20:00:15 +00:00
|
|
|
if (!found && conv->isMinimized()) {
|
2020-02-08 11:44:15 +00:00
|
|
|
rosterModel.changeMessage(account, jid, id, data);
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2020-02-08 11:44:15 +00:00
|
|
|
rosterModel.changeMessage(account, jid, id, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 15:08:03 +00:00
|
|
|
void Squawk::notify(const QString& account, const Shared::Message& msg)
|
|
|
|
{
|
2019-10-25 13:38:48 +00:00
|
|
|
QString name = QString(rosterModel.getContactName(account, msg.getPenPalJid()));
|
2019-12-31 18:14:12 +00:00
|
|
|
QString path = QString(rosterModel.getContactIconPath(account, msg.getPenPalJid(), msg.getPenPalResource()));
|
2019-06-18 15:08:03 +00:00
|
|
|
QVariantList args;
|
|
|
|
args << QString(QCoreApplication::applicationName());
|
|
|
|
args << QVariant(QVariant::UInt); //TODO some normal id
|
2019-10-25 13:38:48 +00:00
|
|
|
if (path.size() > 0) {
|
|
|
|
args << path;
|
|
|
|
} else {
|
2019-12-31 18:14:12 +00:00
|
|
|
args << QString("mail-message"); //TODO should here better be unknown user icon?
|
2019-10-25 13:38:48 +00:00
|
|
|
}
|
2019-08-31 20:50:05 +00:00
|
|
|
if (msg.getType() == Shared::Message::groupChat) {
|
|
|
|
args << msg.getFromResource() + " from " + name;
|
|
|
|
} else {
|
|
|
|
args << name;
|
|
|
|
}
|
2019-12-31 18:14:12 +00:00
|
|
|
|
|
|
|
QString body(msg.getBody());
|
|
|
|
QString oob(msg.getOutOfBandUrl());
|
|
|
|
if (body == oob) {
|
|
|
|
body = tr("Attached file");
|
|
|
|
}
|
|
|
|
|
|
|
|
args << body;
|
2019-06-18 15:08:03 +00:00
|
|
|
args << QStringList();
|
|
|
|
args << QVariantMap();
|
|
|
|
args << 3000;
|
|
|
|
dbus.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
|
|
|
}
|
|
|
|
|
2019-04-11 14:58:59 +00:00
|
|
|
void Squawk::onConversationMessage(const Shared::Message& msg)
|
2019-04-10 20:53:42 +00:00
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
2019-04-11 14:58:59 +00:00
|
|
|
emit sendMessage(conv->getAccount(), msg);
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Roster::ElId id = conv->getId();
|
|
|
|
|
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
if (conv == currentConversation) {
|
|
|
|
Conversations::iterator itr = conversations.find(id);
|
|
|
|
if (itr != conversations.end()) {
|
|
|
|
itr->second->addMessage(msg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentConversation->addMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 20:53:42 +00:00
|
|
|
}
|
2019-05-15 17:36:37 +00:00
|
|
|
|
2019-09-23 12:09:15 +00:00
|
|
|
void Squawk::onConversationMessage(const Shared::Message& msg, const QString& path)
|
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Roster::ElId id = conv->getId();
|
2019-11-12 13:38:01 +00:00
|
|
|
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.insert(std::make_pair(msg.getId(), std::set<Models::Roster::ElId>())).first;
|
2020-04-11 20:00:15 +00:00
|
|
|
itr->second.insert(id);
|
|
|
|
|
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
if (conv == currentConversation) {
|
|
|
|
Conversations::iterator itr = conversations.find(id);
|
|
|
|
if (itr != conversations.end()) {
|
|
|
|
itr->second->appendMessageWithUpload(msg, path);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentConversation->appendMessageWithUpload(msg, path);
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 13:38:01 +00:00
|
|
|
|
2019-09-23 12:09:15 +00:00
|
|
|
emit sendMessage(conv->getAccount(), msg, path);
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:36:37 +00:00
|
|
|
void Squawk::onConversationRequestArchive(const QString& before)
|
|
|
|
{
|
|
|
|
Conversation* conv = static_cast<Conversation*>(sender());
|
|
|
|
requestArchive(conv->getAccount(), conv->getJid(), 20, before); //TODO amount as a settings value
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list)
|
|
|
|
{
|
|
|
|
Models::Roster::ElId id(account, jid);
|
|
|
|
|
2020-04-11 20:00:15 +00:00
|
|
|
if (currentConversation != 0 && currentConversation->getId() == id) {
|
|
|
|
currentConversation->responseArchive(list);
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:36:37 +00:00
|
|
|
Conversations::const_iterator itr = conversations.find(id);
|
|
|
|
if (itr != conversations.end()) {
|
|
|
|
itr->second->responseArchive(list);
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 15:05:54 +00:00
|
|
|
|
|
|
|
void Squawk::removeAccount(const QString& account)
|
|
|
|
{
|
|
|
|
Conversations::const_iterator itr = conversations.begin();
|
|
|
|
while (itr != conversations.end()) {
|
|
|
|
if (itr->first.account == account) {
|
|
|
|
Conversations::const_iterator lItr = itr;
|
|
|
|
++itr;
|
|
|
|
Conversation* conv = lItr->second;
|
2019-11-03 18:46:40 +00:00
|
|
|
disconnect(conv, &Conversation::destroyed, this, &Squawk::onConversationClosed);
|
|
|
|
disconnect(conv, &Conversation::requestArchive, this, &Squawk::onConversationRequestArchive);
|
|
|
|
disconnect(conv, &Conversation::shown, this, &Squawk::onConversationShown);
|
2019-05-29 15:05:54 +00:00
|
|
|
conv->close();
|
|
|
|
conversations.erase(lItr);
|
|
|
|
} else {
|
|
|
|
++itr;
|
|
|
|
}
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
|
|
|
|
if (currentConversation != 0 && currentConversation->getAccount() == account) {
|
|
|
|
currentConversation->deleteLater();
|
|
|
|
currentConversation = 0;
|
|
|
|
m_ui->filler->show();
|
|
|
|
}
|
|
|
|
|
2019-05-29 15:05:54 +00:00
|
|
|
rosterModel.removeAccount(account);
|
|
|
|
}
|
2019-06-12 17:18:18 +00:00
|
|
|
|
|
|
|
void Squawk::onRosterContextMenu(const QPoint& point)
|
|
|
|
{
|
|
|
|
QModelIndex index = m_ui->roster->indexAt(point);
|
|
|
|
if (index.isValid()) {
|
|
|
|
Models::Item* item = static_cast<Models::Item*>(index.internalPointer());
|
2020-04-17 23:17:47 +00:00
|
|
|
if (item->type == Models::Item::reference) {
|
|
|
|
item = static_cast<Models::Reference*>(item)->dereference();
|
|
|
|
}
|
2019-06-12 17:18:18 +00:00
|
|
|
contextMenu->clear();
|
|
|
|
bool hasMenu = false;
|
2020-04-03 22:28:15 +00:00
|
|
|
bool active = item->getAccountConnectionState() == Shared::ConnectionState::connected;
|
2019-06-12 17:18:18 +00:00
|
|
|
switch (item->type) {
|
|
|
|
case Models::Item::account: {
|
|
|
|
Models::Account* acc = static_cast<Models::Account*>(item);
|
|
|
|
hasMenu = true;
|
|
|
|
QString name = acc->getName();
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* con = contextMenu->addAction(Shared::icon("network-disconnect"), tr("Disconnect"));
|
2019-09-28 14:30:16 +00:00
|
|
|
con->setEnabled(active);
|
2019-06-12 17:18:18 +00:00
|
|
|
connect(con, &QAction::triggered, [this, name]() {
|
|
|
|
emit disconnectAccount(name);
|
|
|
|
});
|
|
|
|
} else {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* con = contextMenu->addAction(Shared::icon("network-connect"), tr("Connect"));
|
2019-06-12 17:18:18 +00:00
|
|
|
connect(con, &QAction::triggered, [this, name]() {
|
|
|
|
emit connectAccount(name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-22 15:13:56 +00:00
|
|
|
QAction* card = contextMenu->addAction(Shared::icon("user-properties"), tr("VCard"));
|
|
|
|
card->setEnabled(active);
|
|
|
|
connect(card, &QAction::triggered, std::bind(&Squawk::onActivateVCard, this, name, acc->getBareJid(), true));
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* remove = contextMenu->addAction(Shared::icon("edit-delete"), tr("Remove"));
|
2019-09-28 14:30:16 +00:00
|
|
|
remove->setEnabled(active);
|
2019-06-12 17:18:18 +00:00
|
|
|
connect(remove, &QAction::triggered, [this, name]() {
|
|
|
|
emit removeAccount(name);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Models::Item::contact: {
|
|
|
|
Models::Contact* cnt = static_cast<Models::Contact*>(item);
|
|
|
|
hasMenu = true;
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* dialog = contextMenu->addAction(Shared::icon("mail-message"), tr("Open dialog"));
|
2019-09-28 14:30:16 +00:00
|
|
|
dialog->setEnabled(active);
|
2019-06-14 16:36:04 +00:00
|
|
|
connect(dialog, &QAction::triggered, [this, index]() {
|
2019-06-12 17:18:18 +00:00
|
|
|
onRosterItemDoubleClicked(index);
|
|
|
|
});
|
|
|
|
|
|
|
|
Shared::SubscriptionState state = cnt->getState();
|
|
|
|
switch (state) {
|
2020-04-03 22:28:15 +00:00
|
|
|
case Shared::SubscriptionState::both:
|
|
|
|
case Shared::SubscriptionState::to: {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* unsub = contextMenu->addAction(Shared::icon("news-unsubscribe"), tr("Unsubscribe"));
|
2019-09-28 14:30:16 +00:00
|
|
|
unsub->setEnabled(active);
|
2019-06-14 16:36:04 +00:00
|
|
|
connect(unsub, &QAction::triggered, [this, cnt]() {
|
2019-06-12 17:18:18 +00:00
|
|
|
emit unsubscribeContact(cnt->getAccountName(), cnt->getJid(), "");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2020-04-03 22:28:15 +00:00
|
|
|
case Shared::SubscriptionState::from:
|
|
|
|
case Shared::SubscriptionState::unknown:
|
|
|
|
case Shared::SubscriptionState::none: {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* sub = contextMenu->addAction(Shared::icon("news-subscribe"), tr("Subscribe"));
|
2019-09-28 14:30:16 +00:00
|
|
|
sub->setEnabled(active);
|
2019-06-14 16:36:04 +00:00
|
|
|
connect(sub, &QAction::triggered, [this, cnt]() {
|
2019-06-12 17:18:18 +00:00
|
|
|
emit subscribeContact(cnt->getAccountName(), cnt->getJid(), "");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-09-28 14:30:16 +00:00
|
|
|
QString accName = cnt->getAccountName();
|
|
|
|
QString cntJID = cnt->getJid();
|
2019-10-01 08:47:40 +00:00
|
|
|
QString cntName = cnt->getName();
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* rename = contextMenu->addAction(Shared::icon("edit-rename"), tr("Rename"));
|
2019-10-01 08:47:40 +00:00
|
|
|
rename->setEnabled(active);
|
|
|
|
connect(rename, &QAction::triggered, [this, cntName, accName, cntJID]() {
|
|
|
|
QInputDialog* dialog = new QInputDialog(this);
|
|
|
|
connect(dialog, &QDialog::accepted, [this, dialog, cntName, accName, cntJID]() {
|
|
|
|
QString newName = dialog->textValue();
|
|
|
|
if (newName != cntName) {
|
|
|
|
emit renameContactRequest(accName, cntJID, newName);
|
|
|
|
}
|
|
|
|
dialog->deleteLater();
|
|
|
|
});
|
|
|
|
connect(dialog, &QDialog::rejected, dialog, &QObject::deleteLater);
|
|
|
|
dialog->setInputMode(QInputDialog::TextInput);
|
2019-10-05 11:27:39 +00:00
|
|
|
dialog->setLabelText(tr("Input new name for %1\nor leave it empty for the contact \nto be displayed as %1").arg(cntJID));
|
|
|
|
dialog->setWindowTitle(tr("Renaming %1").arg(cntJID));
|
2019-10-01 08:47:40 +00:00
|
|
|
dialog->setTextValue(cntName);
|
|
|
|
dialog->exec();
|
|
|
|
});
|
2019-06-12 17:18:18 +00:00
|
|
|
|
2019-10-01 08:47:40 +00:00
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QMenu* groupsMenu = contextMenu->addMenu(Shared::icon("group"), tr("Groups"));
|
2019-09-28 14:30:16 +00:00
|
|
|
std::deque<QString> groupList = rosterModel.groupList(accName);
|
|
|
|
for (QString groupName : groupList) {
|
|
|
|
QAction* gr = groupsMenu->addAction(groupName);
|
|
|
|
gr->setCheckable(true);
|
|
|
|
gr->setChecked(rosterModel.groupHasContact(accName, groupName, cntJID));
|
|
|
|
gr->setEnabled(active);
|
|
|
|
connect(gr, &QAction::toggled, [this, accName, groupName, cntJID](bool checked) {
|
|
|
|
if (checked) {
|
|
|
|
emit addContactToGroupRequest(accName, cntJID, groupName);
|
|
|
|
} else {
|
|
|
|
emit removeContactFromGroupRequest(accName, cntJID, groupName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-10-25 13:38:48 +00:00
|
|
|
QAction* newGroup = groupsMenu->addAction(Shared::icon("group-new"), tr("New group"));
|
2019-09-28 14:30:16 +00:00
|
|
|
newGroup->setEnabled(active);
|
|
|
|
connect(newGroup, &QAction::triggered, [this, accName, cntJID]() {
|
|
|
|
QInputDialog* dialog = new QInputDialog(this);
|
|
|
|
connect(dialog, &QDialog::accepted, [this, dialog, accName, cntJID]() {
|
|
|
|
emit addContactToGroupRequest(accName, cntJID, dialog->textValue());
|
|
|
|
dialog->deleteLater();
|
|
|
|
});
|
|
|
|
connect(dialog, &QDialog::rejected, dialog, &QObject::deleteLater);
|
|
|
|
dialog->setInputMode(QInputDialog::TextInput);
|
2019-10-05 11:27:39 +00:00
|
|
|
dialog->setLabelText(tr("New group name"));
|
|
|
|
dialog->setWindowTitle(tr("Add %1 to a new group").arg(cntJID));
|
2019-09-28 14:30:16 +00:00
|
|
|
dialog->exec();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-10-22 15:13:56 +00:00
|
|
|
QAction* card = contextMenu->addAction(Shared::icon("user-properties"), tr("VCard"));
|
|
|
|
card->setEnabled(active);
|
|
|
|
connect(card, &QAction::triggered, std::bind(&Squawk::onActivateVCard, this, accName, cnt->getJid(), false));
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* remove = contextMenu->addAction(Shared::icon("edit-delete"), tr("Remove"));
|
2019-09-28 14:30:16 +00:00
|
|
|
remove->setEnabled(active);
|
2019-06-14 16:36:04 +00:00
|
|
|
connect(remove, &QAction::triggered, [this, cnt]() {
|
|
|
|
emit removeContactRequest(cnt->getAccountName(), cnt->getJid());
|
|
|
|
});
|
|
|
|
|
2019-09-03 20:28:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Models::Item::room: {
|
|
|
|
Models::Room* room = static_cast<Models::Room*>(item);
|
|
|
|
hasMenu = true;
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* dialog = contextMenu->addAction(Shared::icon("mail-message"), tr("Open conversation"));
|
2019-09-28 14:30:16 +00:00
|
|
|
dialog->setEnabled(active);
|
2019-09-03 20:28:58 +00:00
|
|
|
connect(dialog, &QAction::triggered, [this, index]() {
|
|
|
|
onRosterItemDoubleClicked(index);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Models::Roster::ElId id(room->getAccountName(), room->getJid());
|
|
|
|
if (room->getAutoJoin()) {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* unsub = contextMenu->addAction(Shared::icon("news-unsubscribe"), tr("Unsubscribe"));
|
2019-09-28 14:30:16 +00:00
|
|
|
unsub->setEnabled(active);
|
2019-09-03 20:28:58 +00:00
|
|
|
connect(unsub, &QAction::triggered, [this, id]() {
|
|
|
|
emit setRoomAutoJoin(id.account, id.name, false);
|
2020-04-11 20:00:15 +00:00
|
|
|
if (conversations.find(id) == conversations.end()
|
|
|
|
&& (currentConversation == 0 || currentConversation->getId() != id)
|
|
|
|
) { //to leave the room if it's not opened in a conversation window
|
2019-09-03 20:28:58 +00:00
|
|
|
emit setRoomJoined(id.account, id.name, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* unsub = contextMenu->addAction(Shared::icon("news-subscribe"), tr("Subscribe"));
|
2019-09-28 14:30:16 +00:00
|
|
|
unsub->setEnabled(active);
|
2019-09-03 20:28:58 +00:00
|
|
|
connect(unsub, &QAction::triggered, [this, id]() {
|
|
|
|
emit setRoomAutoJoin(id.account, id.name, true);
|
2020-04-11 20:00:15 +00:00
|
|
|
if (conversations.find(id) == conversations.end()
|
|
|
|
&& (currentConversation == 0 || currentConversation->getId() != id)
|
|
|
|
) { //to join the room if it's not already joined
|
2019-09-03 20:28:58 +00:00
|
|
|
emit setRoomJoined(id.account, id.name, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
QAction* remove = contextMenu->addAction(Shared::icon("edit-delete"), tr("Remove"));
|
2019-09-28 14:30:16 +00:00
|
|
|
remove->setEnabled(active);
|
2019-09-03 20:28:58 +00:00
|
|
|
connect(remove, &QAction::triggered, [this, id]() {
|
|
|
|
emit removeRoomRequest(id.account, id.name);
|
|
|
|
});
|
2019-06-12 17:18:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (hasMenu) {
|
|
|
|
contextMenu->popup(m_ui->roster->viewport()->mapToGlobal(point));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-11 08:51:52 +00:00
|
|
|
|
|
|
|
void Squawk::addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.addRoom(account, jid, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.changeRoom(account, jid, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removeRoom(const QString& account, const QString jid)
|
|
|
|
{
|
|
|
|
rosterModel.removeRoom(account, jid);
|
|
|
|
}
|
2019-09-02 11:17:28 +00:00
|
|
|
|
|
|
|
void Squawk::addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.addRoomParticipant(account, jid, name, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data)
|
|
|
|
{
|
|
|
|
rosterModel.changeRoomParticipant(account, jid, name, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::removeRoomParticipant(const QString& account, const QString& jid, const QString& name)
|
|
|
|
{
|
|
|
|
rosterModel.removeRoomParticipant(account, jid, name);
|
|
|
|
}
|
2019-10-22 15:13:56 +00:00
|
|
|
|
|
|
|
void Squawk::responseVCard(const QString& jid, const Shared::VCard& card)
|
|
|
|
{
|
|
|
|
std::map<QString, VCard*>::const_iterator itr = vCards.find(jid);
|
|
|
|
if (itr != vCards.end()) {
|
|
|
|
itr->second->setVCard(card);
|
2019-10-31 14:01:48 +00:00
|
|
|
itr->second->hideProgress();
|
2019-10-22 15:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onVCardClosed()
|
|
|
|
{
|
|
|
|
VCard* vCard = static_cast<VCard*>(sender());
|
|
|
|
|
|
|
|
std::map<QString, VCard*>::const_iterator itr = vCards.find(vCard->getJid());
|
|
|
|
if (itr == vCards.end()) {
|
|
|
|
qDebug() << "VCard has been closed but can not be found among other opened vCards, application is most probably going to crash";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vCards.erase(itr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onActivateVCard(const QString& account, const QString& jid, bool edition)
|
|
|
|
{
|
|
|
|
std::map<QString, VCard*>::const_iterator itr = vCards.find(jid);
|
|
|
|
VCard* card;
|
|
|
|
Models::Contact::Messages deque;
|
|
|
|
if (itr != vCards.end()) {
|
|
|
|
card = itr->second;
|
|
|
|
} else {
|
|
|
|
card = new VCard(jid, edition);
|
2019-10-23 14:49:56 +00:00
|
|
|
if (edition) {
|
|
|
|
card->setWindowTitle(tr("%1 account card").arg(account));
|
|
|
|
} else {
|
|
|
|
card->setWindowTitle(tr("%1 contact card").arg(jid));
|
|
|
|
}
|
2019-10-22 15:13:56 +00:00
|
|
|
card->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
vCards.insert(std::make_pair(jid, card));
|
|
|
|
|
|
|
|
connect(card, &VCard::destroyed, this, &Squawk::onVCardClosed);
|
2019-10-23 14:49:56 +00:00
|
|
|
connect(card, &VCard::saveVCard, std::bind( &Squawk::onVCardSave, this, std::placeholders::_1, account));
|
2019-10-22 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
card->show();
|
|
|
|
card->raise();
|
|
|
|
card->activateWindow();
|
2019-10-31 14:01:48 +00:00
|
|
|
card->showProgress(tr("Downloading vCard"));
|
2019-10-22 15:13:56 +00:00
|
|
|
|
|
|
|
emit requestVCard(account, jid);
|
|
|
|
}
|
2019-10-23 14:49:56 +00:00
|
|
|
|
|
|
|
void Squawk::onVCardSave(const Shared::VCard& card, const QString& account)
|
|
|
|
{
|
|
|
|
VCard* widget = static_cast<VCard*>(sender());
|
|
|
|
emit uploadVCard(account, card);
|
|
|
|
|
|
|
|
widget->deleteLater();
|
|
|
|
}
|
2019-12-25 10:24:20 +00:00
|
|
|
|
|
|
|
void Squawk::readSettings()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("ui");
|
|
|
|
|
|
|
|
if (settings.contains("availability")) {
|
|
|
|
int avail = settings.value("availability").toInt();
|
|
|
|
m_ui->comboBox->setCurrentIndex(avail);
|
2020-04-03 22:28:15 +00:00
|
|
|
emit stateChanged(Shared::Global::fromInt<Shared::Availability>(avail));
|
2019-12-25 10:24:20 +00:00
|
|
|
|
|
|
|
int size = settings.beginReadArray("connectedAccounts");
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
settings.setArrayIndex(i);
|
|
|
|
emit connectAccount(settings.value("name").toString()); //TODO this is actually not needed, stateChanged event already connects everything you have
|
|
|
|
} // need to fix that
|
|
|
|
settings.endArray();
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::writeSettings()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2021-07-07 13:45:08 +00:00
|
|
|
qDebug() << "settings.fileName: " << settings.fileName();
|
2019-12-25 10:24:20 +00:00
|
|
|
settings.beginGroup("ui");
|
|
|
|
settings.beginGroup("window");
|
|
|
|
settings.setValue("geometry", saveGeometry());
|
|
|
|
settings.setValue("state", saveState());
|
|
|
|
settings.endGroup();
|
|
|
|
|
2020-04-11 20:00:15 +00:00
|
|
|
settings.setValue("splitter", m_ui->splitter->saveState());
|
|
|
|
|
2019-12-25 10:24:20 +00:00
|
|
|
settings.setValue("availability", m_ui->comboBox->currentIndex());
|
|
|
|
settings.beginWriteArray("connectedAccounts");
|
|
|
|
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
|
2020-04-03 22:28:15 +00:00
|
|
|
if (acc->getState() != Shared::ConnectionState::disconnected) {
|
2019-12-25 10:24:20 +00:00
|
|
|
settings.setArrayIndex(i);
|
|
|
|
settings.setValue("name", acc->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.endArray();
|
|
|
|
|
|
|
|
settings.remove("roster");
|
|
|
|
settings.beginGroup("roster");
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
QModelIndex acc = rosterModel.index(i, 0, QModelIndex());
|
|
|
|
Models::Account* account = rosterModel.accountsModel->getAccount(i);
|
|
|
|
QString accName = account->getName();
|
|
|
|
settings.beginGroup(accName);
|
|
|
|
|
|
|
|
settings.setValue("expanded", m_ui->roster->isExpanded(acc));
|
|
|
|
std::deque<QString> groups = rosterModel.groupList(accName);
|
|
|
|
for (const QString& groupName : groups) {
|
|
|
|
settings.beginGroup(groupName);
|
|
|
|
QModelIndex gIndex = rosterModel.getGroupIndex(accName, groupName);
|
|
|
|
settings.setValue("expanded", m_ui->roster->isExpanded(gIndex));
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
|
|
|
settings.endGroup();
|
2021-07-07 13:45:08 +00:00
|
|
|
|
2019-12-25 10:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onItemCollepsed(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
Models::Item* item = static_cast<Models::Item*>(index.internalPointer());
|
|
|
|
switch (item->type) {
|
|
|
|
case Models::Item::account:
|
|
|
|
settings.setValue("ui/roster/" + item->getName() + "/expanded", false);
|
|
|
|
break;
|
|
|
|
case Models::Item::group: {
|
|
|
|
QModelIndex accInd = rosterModel.parent(index);
|
|
|
|
Models::Account* account = rosterModel.accountsModel->getAccount(accInd.row());
|
|
|
|
settings.setValue("ui/roster/" + account->getName() + "/" + item->getName() + "/expanded", false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 20:33:03 +00:00
|
|
|
|
|
|
|
void Squawk::requestPassword(const QString& account)
|
|
|
|
{
|
|
|
|
requestedAccountsForPasswords.push_back(account);
|
|
|
|
checkNextAccountForPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::checkNextAccountForPassword()
|
|
|
|
{
|
|
|
|
if (prompt == 0 && requestedAccountsForPasswords.size() > 0) {
|
|
|
|
prompt = new QInputDialog(this);
|
|
|
|
QString accName = requestedAccountsForPasswords.front();
|
|
|
|
connect(prompt, &QDialog::accepted, this, &Squawk::onPasswordPromptAccepted);
|
|
|
|
connect(prompt, &QDialog::rejected, this, &Squawk::onPasswordPromptRejected);
|
|
|
|
prompt->setInputMode(QInputDialog::TextInput);
|
|
|
|
prompt->setTextEchoMode(QLineEdit::Password);
|
|
|
|
prompt->setLabelText(tr("Input the password for account %1").arg(accName));
|
|
|
|
prompt->setWindowTitle(tr("Password for account %1").arg(accName));
|
|
|
|
prompt->setTextValue("");
|
|
|
|
prompt->exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onPasswordPromptAccepted()
|
|
|
|
{
|
|
|
|
emit responsePassword(requestedAccountsForPasswords.front(), prompt->textValue());
|
|
|
|
onPasswordPromptDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onPasswordPromptDone()
|
|
|
|
{
|
|
|
|
prompt->deleteLater();
|
|
|
|
prompt = 0;
|
|
|
|
requestedAccountsForPasswords.pop_front();
|
|
|
|
checkNextAccountForPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onPasswordPromptRejected()
|
|
|
|
{
|
|
|
|
//for now it's the same on reject and on accept, but one day I'm gonna make
|
|
|
|
//"Asking for the password again on the authentication failure" feature
|
|
|
|
//and here I'll be able to break the circle of password requests
|
|
|
|
emit responsePassword(requestedAccountsForPasswords.front(), prompt->textValue());
|
|
|
|
onPasswordPromptDone();
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
|
|
|
|
void Squawk::subscribeConversation(Conversation* conv)
|
|
|
|
{
|
|
|
|
connect(conv, &Conversation::destroyed, this, &Squawk::onConversationClosed);
|
|
|
|
connect(conv, qOverload<const Shared::Message&>(&Conversation::sendMessage), this, qOverload<const Shared::Message&>(&Squawk::onConversationMessage));
|
|
|
|
connect(conv, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage),
|
|
|
|
this, qOverload<const Shared::Message&, const QString&>(&Squawk::onConversationMessage));
|
|
|
|
connect(conv, &Conversation::requestArchive, this, &Squawk::onConversationRequestArchive);
|
|
|
|
connect(conv, &Conversation::requestLocalFile, this, &Squawk::onConversationRequestLocalFile);
|
|
|
|
connect(conv, &Conversation::downloadFile, this, &Squawk::onConversationDownloadFile);
|
|
|
|
connect(conv, &Conversation::shown, this, &Squawk::onConversationShown);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
|
2020-04-12 15:55:05 +00:00
|
|
|
{
|
|
|
|
if (restoreSelection.isValid() && restoreSelection == current) {
|
|
|
|
restoreSelection = QModelIndex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-11 20:00:15 +00:00
|
|
|
if (current.isValid()) {
|
|
|
|
Models::Item* node = static_cast<Models::Item*>(current.internalPointer());
|
2020-04-17 23:17:47 +00:00
|
|
|
if (node->type == Models::Item::reference) {
|
|
|
|
node = static_cast<Models::Reference*>(node)->dereference();
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
Models::Contact* contact = 0;
|
|
|
|
Models::Room* room = 0;
|
|
|
|
QString res;
|
|
|
|
Models::Roster::ElId* id = 0;
|
2020-04-12 15:55:05 +00:00
|
|
|
bool hasContext = true;
|
2020-04-11 20:00:15 +00:00
|
|
|
switch (node->type) {
|
|
|
|
case Models::Item::contact:
|
|
|
|
contact = static_cast<Models::Contact*>(node);
|
|
|
|
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
|
|
|
break;
|
|
|
|
case Models::Item::presence:
|
|
|
|
contact = static_cast<Models::Contact*>(node->parentItem());
|
|
|
|
id = new Models::Roster::ElId(contact->getAccountName(), contact->getJid());
|
|
|
|
res = node->getName();
|
2020-04-12 15:55:05 +00:00
|
|
|
hasContext = false;
|
2020-04-11 20:00:15 +00:00
|
|
|
break;
|
|
|
|
case Models::Item::room:
|
|
|
|
room = static_cast<Models::Room*>(node);
|
|
|
|
id = new Models::Roster::ElId(room->getAccountName(), room->getJid());
|
|
|
|
break;
|
2020-04-12 15:55:05 +00:00
|
|
|
case Models::Item::participant:
|
|
|
|
room = static_cast<Models::Room*>(node->parentItem());
|
|
|
|
id = new Models::Roster::ElId(room->getAccountName(), room->getJid());
|
|
|
|
hasContext = false;
|
|
|
|
break;
|
|
|
|
case Models::Item::group:
|
|
|
|
hasContext = false;
|
2020-04-11 20:00:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-12 15:55:05 +00:00
|
|
|
if (hasContext && QGuiApplication::mouseButtons() & Qt::RightButton) {
|
|
|
|
if (id != 0) {
|
|
|
|
delete id;
|
|
|
|
}
|
2020-04-14 16:30:33 +00:00
|
|
|
needToRestore = true;
|
2020-04-12 15:55:05 +00:00
|
|
|
restoreSelection = previous;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-11 20:00:15 +00:00
|
|
|
if (id != 0) {
|
|
|
|
if (currentConversation != 0) {
|
2020-04-12 15:55:05 +00:00
|
|
|
if (currentConversation->getId() == *id) {
|
2020-04-11 20:00:15 +00:00
|
|
|
if (contact != 0) {
|
|
|
|
currentConversation->setPalResource(res);
|
|
|
|
}
|
2020-04-12 15:55:05 +00:00
|
|
|
return;
|
2020-04-11 20:00:15 +00:00
|
|
|
} else {
|
|
|
|
currentConversation->deleteLater();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_ui->filler->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
Models::Account* acc = rosterModel.getAccount(id->account);
|
|
|
|
Models::Contact::Messages deque;
|
|
|
|
if (contact != 0) {
|
|
|
|
currentConversation = new Chat(acc, contact);
|
|
|
|
contact->getMessages(deque);
|
|
|
|
} else if (room != 0) {
|
|
|
|
currentConversation = new Room(acc, room);
|
|
|
|
room->getMessages(deque);
|
|
|
|
|
|
|
|
if (!room->getJoined()) {
|
|
|
|
emit setRoomJoined(id->account, id->name, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!testAttribute(Qt::WA_TranslucentBackground)) {
|
|
|
|
currentConversation->setFeedFrames(true, false, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribeConversation(currentConversation);
|
|
|
|
for (Models::Contact::Messages::const_iterator itr = deque.begin(), end = deque.end(); itr != end; ++itr) {
|
|
|
|
currentConversation->addMessage(*itr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res.size() > 0) {
|
|
|
|
currentConversation->setPalResource(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ui->splitter->insertWidget(1, currentConversation);
|
|
|
|
|
|
|
|
delete id;
|
|
|
|
} else {
|
|
|
|
if (currentConversation != 0) {
|
|
|
|
currentConversation->deleteLater();
|
|
|
|
currentConversation = 0;
|
|
|
|
m_ui->filler->show();
|
|
|
|
}
|
|
|
|
}
|
2020-04-12 15:55:05 +00:00
|
|
|
} else {
|
|
|
|
if (currentConversation != 0) {
|
|
|
|
currentConversation->deleteLater();
|
|
|
|
currentConversation = 0;
|
|
|
|
m_ui->filler->show();
|
|
|
|
}
|
2020-04-11 20:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-12 15:55:05 +00:00
|
|
|
|
|
|
|
void Squawk::onContextAboutToHide()
|
|
|
|
{
|
2020-04-14 16:30:33 +00:00
|
|
|
if (needToRestore) {
|
|
|
|
needToRestore = false;
|
|
|
|
m_ui->roster->selectionModel()->setCurrentIndex(restoreSelection, QItemSelectionModel::ClearAndSelect);
|
|
|
|
}
|
2020-04-12 15:55:05 +00:00
|
|
|
}
|