first attempt to remove accounts

This commit is contained in:
Blue 2019-05-29 18:05:54 +03:00
parent 8432a574b9
commit 234697050b
14 changed files with 190 additions and 14 deletions

View file

@ -78,9 +78,19 @@ void Models::Accounts::onAccountChanged(Item* item, int row, int col)
if (col < columnCount(QModelIndex())) {
emit dataChanged(createIndex(row, col, this), createIndex(row, col, this));
}
emit changed();
}
Models::Account * Models::Accounts::getAccount(int index)
{
return accs[index];
}
void Models::Accounts::removeAccount(int index)
{
Account* account = accs[index];
beginRemoveRows(QModelIndex(), index, index);
disconnect(account, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(onAccountChanged(Models::Item*, int, int)));
accs.erase(accs.begin() + index);
endRemoveRows();
}

View file

@ -16,6 +16,7 @@ public:
~Accounts();
void addAccount(Account* account);
void removeAccount(int index);
QVariant data ( const QModelIndex& index, int role ) const override;
int columnCount ( const QModelIndex& parent ) const override;
@ -24,6 +25,9 @@ public:
Account* getAccount(int index);
signals:
void changed();
private:
std::deque<Account*> accs;
static std::deque<QString> columns;

View file

@ -121,13 +121,13 @@ void Models::Item::_removeChild(int index)
{
Item* child = childItems[index];
QObject::connect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
QObject::connect(child, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SIGNAL(childIsAboutToBeInserted(Item*, int, int)));
QObject::connect(child, SIGNAL(childInserted()), this, SIGNAL(childInserted()));
QObject::connect(child, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)));
QObject::connect(child, SIGNAL(childRemoved()), this, SIGNAL(childRemoved()));
QObject::connect(child, SIGNAL(childIsAboutToBeMoved(Item*, int, int, Item*, int)), this, SIGNAL(childIsAboutToBeMoved(Item*, int, int, Item*, int)));
QObject::connect(child, SIGNAL(childMoved()), this, SIGNAL(childMoved()));
QObject::disconnect(child, SIGNAL(childChanged(Models::Item*, int, int)), this, SIGNAL(childChanged(Models::Item*, int, int)));
QObject::disconnect(child, SIGNAL(childIsAboutToBeInserted(Item*, int, int)), this, SIGNAL(childIsAboutToBeInserted(Item*, int, int)));
QObject::disconnect(child, SIGNAL(childInserted()), this, SIGNAL(childInserted()));
QObject::disconnect(child, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)), this, SIGNAL(childIsAboutToBeRemoved(Item*, int, int)));
QObject::disconnect(child, SIGNAL(childRemoved()), this, SIGNAL(childRemoved()));
QObject::disconnect(child, SIGNAL(childIsAboutToBeMoved(Item*, int, int, Item*, int)), this, SIGNAL(childIsAboutToBeMoved(Item*, int, int, Item*, int)));
QObject::disconnect(child, SIGNAL(childMoved()), this, SIGNAL(childMoved()));
childItems.erase(childItems.begin() + index);
child->parent = 0;

View file

@ -512,3 +512,41 @@ void Models::Roster::dropMessages(const QString& account, const QString& jid)
cBeg->second->dropMessages();
}
}
void Models::Roster::removeAccount(const QString& account)
{
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
if (itr == accounts.end()) {
qDebug() << "An attempt to remove non existing account " << account << ", skipping";
return;
}
Account* acc = itr->second;
int index = acc->row();
root->removeChild(index);
accountsModel->removeAccount(index);
std::multimap<ElId, Contact*>::const_iterator cItr = contacts.begin();
while (cItr != contacts.end()) {
if (cItr->first.account == account) {
std::multimap<ElId, Contact*>::const_iterator lItr = cItr;
++cItr;
contacts.erase(lItr);
} else {
++cItr;
}
}
std::map<ElId, Item*>::const_iterator gItr = groups.begin();
while (gItr != groups.end()) {
if (gItr->first.account == account) {
std::map<ElId, Item*>::const_iterator lItr = gItr;
++gItr;
groups.erase(lItr);
} else {
++gItr;
}
}
delete acc;
}

View file

@ -24,6 +24,7 @@ public:
void addAccount(const QMap<QString, QVariant> &data);
void updateAccount(const QString& account, const QString& field, const QVariant& value);
void removeAccount(const QString& account);
void addGroup(const QString& account, const QString& name);
void removeGroup(const QString& account, const QString& name);
void addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data);