1
0
forked from blue/squawk
squawk/ui/squawk.cpp

131 lines
3.5 KiB
C++
Raw Normal View History

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-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),
rosterModel()
2019-03-29 14:54:34 +00:00
{
m_ui->setupUi(this);
m_ui->roster->setModel(&rosterModel);
2019-03-29 14:54:34 +00:00
2019-04-02 15:46:18 +00:00
connect(m_ui->actionAccounts, SIGNAL(triggered()), this, SLOT(onAccounts()));
connect(m_ui->comboBox, SIGNAL(activated(int)), this, SLOT(onComboboxActivated(int)));
//m_ui->mainToolBar->addWidget(m_ui->comboBox);
2019-03-29 14:54:34 +00:00
}
Squawk::~Squawk() {
}
void Squawk::onAccounts()
{
if (accounts == 0) {
2019-04-03 18:15:36 +00:00
accounts = new Accounts(rosterModel.accountsModel, this);
2019-03-29 14:54:34 +00:00
accounts->setAttribute(Qt::WA_DeleteOnClose);
connect(accounts, SIGNAL(destroyed(QObject*)), this, SLOT(onAccountsClosed(QObject*)));
2019-03-30 20:13:13 +00:00
connect(accounts, SIGNAL(newAccount(const QMap<QString, QVariant>&)), this, SIGNAL(newAccountRequest(const QMap<QString, QVariant>&)));
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
}
}
void Squawk::closeEvent(QCloseEvent* event)
{
if (accounts != 0) {
accounts->close();
}
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)
{
rosterModel.addAccount(account);
2019-03-30 20:13:13 +00:00
}
void Squawk::onComboboxActivated(int index)
{
if (index == 0) {
2019-04-03 18:15:36 +00:00
int size = rosterModel.accountsModel->rowCount(QModelIndex());
if (size > 0) {
for (int i = 0; i < size; ++i) {
Models::Account* acc = rosterModel.accountsModel->getAccount(i);
if (acc->getState() == Shared::disconnected) {
emit connectAccount(acc->getName());
}
}
} else {
m_ui->comboBox->setCurrentIndex(1);
}
} else if (index == 1) {
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);
if (acc->getState() != Shared::disconnected) {
emit disconnectAccount(acc->getName());
}
}
}
}
void Squawk::accountConnectionStateChanged(const QString& account, int state)
{
2019-04-03 18:15:36 +00:00
rosterModel.updateAccount(account, "state", state);
}
2019-04-03 21:23:51 +00:00
void Squawk::addContact(const QString& account, const QString& jid, const QString& name, const QString& group)
{
rosterModel.addContact(account, jid, name, group);
}
void Squawk::addGroup(const QString& account, const QString& name)
{
rosterModel.addGroup(account, name);
}
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-06 10:14:32 +00:00
void Squawk::changeContact(const QString& account, const QString& jid, const QString& name)
{
rosterModel.changeContact(account, jid, name);
}
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);
}
2019-04-03 21:23:51 +00:00