forked from blue/squawk
Better way to store expanded elements in roster, several clean ups, translations
This commit is contained in:
parent
7e9eed2075
commit
d162494ec8
18 changed files with 874 additions and 252 deletions
|
@ -52,6 +52,8 @@ void Models::Roster::addAccount(const QMap<QString, QVariant>& data)
|
|||
root->appendChild(acc);
|
||||
accounts.insert(std::make_pair(acc->getName(), acc));
|
||||
accountsModel->addAccount(acc);
|
||||
|
||||
emit addedElement({acc->getId()});
|
||||
}
|
||||
|
||||
QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
||||
|
@ -433,6 +435,9 @@ void Models::Roster::addGroup(const QString& account, const QString& name)
|
|||
Group* group = new Group({{"name", name}});
|
||||
groups.insert(std::make_pair(id, group));
|
||||
acc->appendChild(group);
|
||||
|
||||
|
||||
emit addedElement({acc->getId(), group->getId()});
|
||||
} else {
|
||||
qDebug() << "An attempt to add group " << name << " to non existing account " << account << ", skipping";
|
||||
}
|
||||
|
@ -470,6 +475,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
}
|
||||
}
|
||||
|
||||
std::list<QString> path = {acc->getId()};
|
||||
if (group == "") {
|
||||
if (acc->getContact(jid) != -1) {
|
||||
qDebug() << "An attempt to add a contact" << jid << "to the ungrouped contact set of account" << account << "for the second time, skipping";
|
||||
|
@ -486,6 +492,7 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
}
|
||||
|
||||
parent = itr->second;
|
||||
path.push_back(parent->getId());
|
||||
|
||||
if (parent->getContact(jid) != -1) {
|
||||
qDebug() << "An attempt to add a contact" << jid << "to the group" << group << "for the second time, skipping";
|
||||
|
@ -502,11 +509,14 @@ void Models::Roster::addContact(const QString& account, const QString& jid, cons
|
|||
}
|
||||
|
||||
}
|
||||
path.push_back(contact->getId());
|
||||
|
||||
if (ref == 0) {
|
||||
ref = new Reference(contact);
|
||||
}
|
||||
parent->appendChild(ref);
|
||||
|
||||
emit addedElement(path);
|
||||
}
|
||||
|
||||
void Models::Roster::removeGroup(const QString& account, const QString& name)
|
||||
|
@ -694,6 +704,7 @@ void Models::Roster::addPresence(const QString& account, const QString& jid, con
|
|||
if (itr != contacts.end()) {
|
||||
itr->second->addPresence(name, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Models::Roster::removePresence(const QString& account, const QString& jid, const QString& name)
|
||||
|
@ -809,6 +820,8 @@ void Models::Roster::addRoom(const QString& account, const QString jid, const QM
|
|||
connect(room, &Room::unreadMessagesCountChanged, this, &Roster::recalculateUnreadMessages);
|
||||
rooms.insert(std::make_pair(id, room));
|
||||
acc->appendChild(room);
|
||||
|
||||
emit addedElement({acc->getId(), room->getId()});
|
||||
}
|
||||
|
||||
void Models::Roster::changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data)
|
||||
|
@ -961,7 +974,7 @@ bool Models::Roster::markMessageAsRead(const Models::Roster::ElId& elementId, co
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getAccountIndex(const QString& name)
|
||||
QModelIndex Models::Roster::getAccountIndex(const QString& name) const
|
||||
{
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(name);
|
||||
if (itr == accounts.end()) {
|
||||
|
@ -971,7 +984,7 @@ QModelIndex Models::Roster::getAccountIndex(const QString& name)
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString& name)
|
||||
QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString& name) const
|
||||
{
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
|
@ -987,7 +1000,7 @@ QModelIndex Models::Roster::getGroupIndex(const QString& account, const QString&
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getContactIndex(const QString& account, const QString& jid, const QString& resource)
|
||||
QModelIndex Models::Roster::getContactIndex(const QString& account, const QString& jid, const QString& resource) const
|
||||
{
|
||||
std::map<QString, Account*>::const_iterator itr = accounts.find(account);
|
||||
if (itr == accounts.end()) {
|
||||
|
@ -1113,3 +1126,66 @@ void Models::Roster::recalculateUnreadMessages()
|
|||
}
|
||||
emit unreadMessagesCountChanged(count);
|
||||
}
|
||||
|
||||
std::list<QString> Models::Roster::getItemPath(const QModelIndex& index) const
|
||||
{
|
||||
std::list<QString> result;
|
||||
if (index.isValid() && index.model() == this) {
|
||||
Item* item = static_cast<Item*>(index.internalPointer());
|
||||
while (item->type != Item::root) {
|
||||
result.push_front(item->getId());
|
||||
item = item->parentItem();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QModelIndex Models::Roster::getIndexByPath(const std::list<QString>& path) const
|
||||
{
|
||||
if (path.empty())
|
||||
return QModelIndex();
|
||||
|
||||
QModelIndex current;
|
||||
for (const QString& hop : path) {
|
||||
int rows = rowCount(current);
|
||||
bool found = false;
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
QModelIndex el = index(i, 0, current);
|
||||
Item* item = static_cast<Item*>(el.internalPointer());
|
||||
if (item->getId() == hop) {
|
||||
found = true;
|
||||
current = el;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
break;
|
||||
|
||||
}
|
||||
return current; //this way I will return the last matching model index, may be it's logically incorrect
|
||||
|
||||
|
||||
// std::list<QString>::const_iterator pathItr = path.begin();
|
||||
// QString accName = *pathItr;
|
||||
// QModelIndex accIndex = getAccountIndex(accName);
|
||||
// if (path.size() == 1)
|
||||
// return accIndex;
|
||||
//
|
||||
// if (!accIndex.isValid())
|
||||
// return QModelIndex();
|
||||
//
|
||||
// ++pathItr;
|
||||
// ElId id{accName, *pathItr};
|
||||
// QModelIndex contactIndex = getContactIndex(id.account, id.name);
|
||||
// if (!contactIndex.isValid())
|
||||
// contactIndex = getGroupIndex(id.account, id.name);
|
||||
//
|
||||
// if (path.size() == 2)
|
||||
// return contactIndex;
|
||||
//
|
||||
// if (!contactIndex.isValid())
|
||||
// return QModelIndex();
|
||||
//
|
||||
// ++pathItr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue