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
|
@ -75,6 +75,11 @@ void Models::Element::update(const QString& field, const QVariant& value)
|
|||
}
|
||||
}
|
||||
|
||||
QString Models::Element::getId() const
|
||||
{
|
||||
return jid;
|
||||
}
|
||||
|
||||
QString Models::Element::getAvatarPath() const
|
||||
{
|
||||
return avatarPath;
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
QString getAvatarPath() const;
|
||||
|
||||
virtual void update(const QString& field, const QVariant& value);
|
||||
virtual QString getId() const override;
|
||||
|
||||
void addMessage(const Shared::Message& data);
|
||||
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
||||
|
|
|
@ -181,6 +181,11 @@ QString Models::Item::getName() const
|
|||
return name;
|
||||
}
|
||||
|
||||
QString Models::Item::getId() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
QVariant Models::Item::data(int column) const
|
||||
{
|
||||
if (column != 0) {
|
||||
|
|
|
@ -65,6 +65,7 @@ class Item : public QObject{
|
|||
virtual void appendChild(Item *child);
|
||||
virtual void removeChild(int index);
|
||||
virtual QString getDisplayedName() const;
|
||||
virtual QString getId() const;
|
||||
QString getName() const;
|
||||
void setName(const QString& name);
|
||||
|
||||
|
|
|
@ -75,6 +75,11 @@ QString Models::Reference::getDisplayedName() const
|
|||
return original->getDisplayedName();
|
||||
}
|
||||
|
||||
QString Models::Reference::getId() const
|
||||
{
|
||||
return original->getId();
|
||||
}
|
||||
|
||||
Models::Item * Models::Reference::dereference()
|
||||
{
|
||||
return original;
|
||||
|
|
|
@ -38,6 +38,8 @@ public:
|
|||
QString getDisplayedName() const override;
|
||||
void appendChild(Models::Item * child) override;
|
||||
void removeChild(int index) override;
|
||||
QString getId() const override;
|
||||
|
||||
Item* dereference();
|
||||
const Item* dereferenceConst() const;
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ private:
|
|||
private:
|
||||
bool autoJoin;
|
||||
bool joined;
|
||||
QString jid;
|
||||
QString nick;
|
||||
QString subject;
|
||||
std::map<QString, Participant*> participants;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <qabstractitemmodel.h>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <QVector>
|
||||
|
||||
#include "shared/message.h"
|
||||
|
@ -86,9 +87,12 @@ public:
|
|||
QString getContactIconPath(const QString& account, const QString& jid, const QString& resource) const;
|
||||
Account* getAccount(const QString& name);
|
||||
const Account* getAccountConst(const QString& name) const;
|
||||
QModelIndex getAccountIndex(const QString& name);
|
||||
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
||||
QModelIndex getContactIndex(const QString& account, const QString& jid, const QString& resource = "");
|
||||
QModelIndex getAccountIndex(const QString& name) const;
|
||||
QModelIndex getGroupIndex(const QString& account, const QString& name) const;
|
||||
QModelIndex getContactIndex(const QString& account, const QString& jid, const QString& resource = "") const;
|
||||
QModelIndex getIndexByPath(const std::list<QString>& path) const;
|
||||
std::list<QString> getItemPath(const QModelIndex& index) const;
|
||||
|
||||
bool markMessageAsRead(const ElId& elementId, const QString& messageId);
|
||||
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
||||
|
||||
|
@ -104,6 +108,7 @@ signals:
|
|||
void unreadMessagesCountChanged(int count);
|
||||
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
||||
void localPathInvalid(const QString& path);
|
||||
void addedElement(const std::list<QString>& path); //emits only on addition of Account, Contact, Room or Group. Presence and Participant are ignored
|
||||
|
||||
private slots:
|
||||
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
||||
|
|
|
@ -60,7 +60,8 @@ Squawk::Squawk(Models::Roster& p_rosterModel, QWidget *parent) :
|
|||
connect(m_ui->comboBox, qOverload<int>(&QComboBox::activated), this, &Squawk::onComboboxActivated);
|
||||
//connect(m_ui->roster, &QTreeView::doubleClicked, this, &Squawk::onRosterItemDoubleClicked);
|
||||
connect(m_ui->roster, &QTreeView::customContextMenuRequested, this, &Squawk::onRosterContextMenu);
|
||||
connect(m_ui->roster, &QTreeView::collapsed, this, &Squawk::onItemCollepsed);
|
||||
connect(m_ui->roster, &QTreeView::collapsed, this, &Squawk::itemCollapsed);
|
||||
connect(m_ui->roster, &QTreeView::expanded, this, &Squawk::itemExpanded);
|
||||
connect(m_ui->roster->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Squawk::onRosterSelectionChanged);
|
||||
|
||||
connect(rosterModel.accountsModel, &Models::Accounts::changed, this, &Squawk::onAccountsChanged);
|
||||
|
@ -491,49 +492,7 @@ void Squawk::writeSettings()
|
|||
settings.endGroup();
|
||||
|
||||
settings.setValue("splitter", m_ui->splitter->saveState());
|
||||
settings.remove("roster");
|
||||
settings.beginGroup("roster");
|
||||
int size = rosterModel.accountsModel->rowCount(QModelIndex());
|
||||
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();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Squawk::onRosterSelectionChanged(const QModelIndex& current, const QModelIndex& previous)
|
||||
|
|
|
@ -83,6 +83,8 @@ signals:
|
|||
void openConversation(const Models::Roster::ElId& id, const QString& resource = "");
|
||||
|
||||
void modifyAccountRequest(const QString&, const QMap<QString, QVariant>&);
|
||||
void itemExpanded (const QModelIndex& index);
|
||||
void itemCollapsed (const QModelIndex& index);
|
||||
|
||||
public:
|
||||
Models::Roster::ElId currentConversationId() const;
|
||||
|
@ -127,7 +129,6 @@ private slots:
|
|||
void onComboboxActivated(int index);
|
||||
void onRosterItemDoubleClicked(const QModelIndex& item);
|
||||
void onRosterContextMenu(const QPoint& point);
|
||||
void onItemCollepsed(const QModelIndex& index);
|
||||
void onRosterSelectionChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
void onContextAboutToHide();
|
||||
void onAboutSquawkCalled();
|
||||
|
|
|
@ -100,7 +100,7 @@ void PageGeneral::onTrayChecked(int state)
|
|||
emit variableModified("tray", enabled);
|
||||
m_ui->hideTrayInput->setEnabled(enabled);
|
||||
if (!enabled) {
|
||||
m_ui->hideTrayInput->setEnabled(false);
|
||||
m_ui->hideTrayInput->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue