forked from blue/squawk
Refactoring finished
This commit is contained in:
parent
2bcee521c5
commit
d14883ad91
14 changed files with 120 additions and 143 deletions
|
@ -6,8 +6,6 @@ Squawk::Squawk(QWidget *parent) :
|
|||
QMainWindow(parent),
|
||||
m_ui(new Ui::Squawk),
|
||||
accounts(0),
|
||||
accountsCache(),
|
||||
accountsIndex(),
|
||||
rosterModel()
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
@ -25,18 +23,11 @@ Squawk::~Squawk() {
|
|||
void Squawk::onAccounts()
|
||||
{
|
||||
if (accounts == 0) {
|
||||
accounts = new Accounts(this);
|
||||
accounts = new Accounts(rosterModel.accountsModel, this);
|
||||
accounts->setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(accounts, SIGNAL(destroyed(QObject*)), this, SLOT(onAccountsClosed(QObject*)));
|
||||
connect(accounts, SIGNAL(newAccount(const QMap<QString, QVariant>&)), this, SIGNAL(newAccountRequest(const QMap<QString, QVariant>&)));
|
||||
|
||||
AC::const_iterator itr = accountsCache.begin();
|
||||
AC::const_iterator end = accountsCache.end();
|
||||
|
||||
for (; itr != end; ++itr) {
|
||||
accounts->addAccount(*itr);
|
||||
}
|
||||
|
||||
accounts->show();
|
||||
} else {
|
||||
accounts->show();
|
||||
|
@ -62,39 +53,29 @@ void Squawk::onAccountsClosed(QObject* parent)
|
|||
|
||||
void Squawk::newAccount(const QMap<QString, QVariant>& account)
|
||||
{
|
||||
accountsCache.push_back(account);
|
||||
QMap<QString, QVariant>* acc = &accountsCache.back();
|
||||
accountsIndex.insert(std::make_pair(acc->value("name").toString(), acc));
|
||||
rosterModel.addAccount(account);
|
||||
if (accounts != 0) {
|
||||
accounts->addAccount(account);
|
||||
}
|
||||
}
|
||||
|
||||
void Squawk::onComboboxActivated(int index)
|
||||
{
|
||||
if (index == 0) {
|
||||
if (accountsCache.size() > 0) {
|
||||
AC::const_iterator itr = accountsCache.begin();
|
||||
AC::const_iterator end = accountsCache.end();
|
||||
|
||||
for (; itr != end; ++itr) {
|
||||
const QMap<QString, QVariant>& acc = *itr;
|
||||
if (acc.value("state").toInt() == Shared::disconnected) {
|
||||
emit connectAccount(acc.value("name").toString());
|
||||
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) {
|
||||
AC::const_iterator itr = accountsCache.begin();
|
||||
AC::const_iterator end = accountsCache.end();
|
||||
|
||||
for (; itr != end; ++itr) {
|
||||
const QMap<QString, QVariant>& acc = *itr;
|
||||
if (acc.value("state").toInt() != Shared::disconnected) {
|
||||
emit disconnectAccount(acc.value("name").toString());
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,18 +83,5 @@ void Squawk::onComboboxActivated(int index)
|
|||
|
||||
void Squawk::accountConnectionStateChanged(const QString& account, int state)
|
||||
{
|
||||
AI::iterator itr = accountsIndex.find(account);
|
||||
if (itr != accountsIndex.end()) {
|
||||
QMap<QString, QVariant>* acc = itr->second;
|
||||
acc->insert("state", state);
|
||||
|
||||
rosterModel.updateAccount(account, "state", state);
|
||||
if (accounts != 0) {
|
||||
accounts->updateAccount(account, "state", state);
|
||||
}
|
||||
} else {
|
||||
QString msg("A notification about connection state change of an unknown account ");
|
||||
msg += account + ", skipping";
|
||||
qDebug("%s", msg.toStdString().c_str());
|
||||
}
|
||||
rosterModel.updateAccount(account, "state", state);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue