2019-09-01 19:46:12 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-31 21:05:09 +00:00
|
|
|
#ifndef MODELS_ROSTER_H
|
|
|
|
#define MODELS_ROSTER_H
|
|
|
|
|
|
|
|
#include <qabstractitemmodel.h>
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
2022-08-17 16:25:35 +00:00
|
|
|
#include <list>
|
2019-04-03 18:15:36 +00:00
|
|
|
#include <QVector>
|
2020-02-08 11:44:15 +00:00
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/message.h"
|
|
|
|
#include "shared/global.h"
|
2021-04-18 12:49:20 +00:00
|
|
|
#include "shared/messageinfo.h"
|
2019-04-03 15:09:29 +00:00
|
|
|
#include "accounts.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "account.h"
|
2019-04-05 15:12:59 +00:00
|
|
|
#include "contact.h"
|
2019-06-22 20:37:22 +00:00
|
|
|
#include "group.h"
|
2019-07-11 08:51:52 +00:00
|
|
|
#include "room.h"
|
2020-04-17 23:17:47 +00:00
|
|
|
#include "reference.h"
|
2019-03-31 21:05:09 +00:00
|
|
|
|
|
|
|
namespace Models
|
|
|
|
{
|
|
|
|
|
|
|
|
class Roster : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-04-09 15:04:08 +00:00
|
|
|
class ElId;
|
2019-03-31 21:05:09 +00:00
|
|
|
Roster(QObject* parent = 0);
|
|
|
|
~Roster();
|
|
|
|
|
2022-04-22 15:26:18 +00:00
|
|
|
public slots:
|
2019-03-31 21:05:09 +00:00
|
|
|
void addAccount(const QMap<QString, QVariant> &data);
|
2019-04-02 21:58:43 +00:00
|
|
|
void updateAccount(const QString& account, const QString& field, const QVariant& value);
|
2019-05-29 15:05:54 +00:00
|
|
|
void removeAccount(const QString& account);
|
2019-04-03 21:23:51 +00:00
|
|
|
void addGroup(const QString& account, const QString& name);
|
|
|
|
void removeGroup(const QString& account, const QString& name);
|
2019-04-07 20:14:15 +00:00
|
|
|
void addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
|
2019-04-06 10:14:32 +00:00
|
|
|
void removeContact(const QString& account, const QString& jid, const QString& group);
|
|
|
|
void removeContact(const QString& account, const QString& jid);
|
2019-04-07 20:14:15 +00:00
|
|
|
void changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data);
|
2019-04-07 14:02:41 +00:00
|
|
|
void addPresence(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
|
|
|
void removePresence(const QString& account, const QString& jid, const QString& name);
|
2019-04-11 14:58:59 +00:00
|
|
|
void addMessage(const QString& account, const Shared::Message& data);
|
2020-02-08 11:44:15 +00:00
|
|
|
void changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
|
2019-07-11 08:51:52 +00:00
|
|
|
void addRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
|
|
|
void changeRoom(const QString& account, const QString jid, const QMap<QString, QVariant>& data);
|
|
|
|
void removeRoom(const QString& account, const QString jid);
|
2019-09-02 11:17:28 +00:00
|
|
|
void addRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
|
|
|
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
|
|
|
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
|
2022-04-22 15:26:18 +00:00
|
|
|
|
|
|
|
public:
|
2022-04-18 16:54:42 +00:00
|
|
|
QString getContactName(const QString& account, const QString& jid) const;
|
2022-04-22 15:26:18 +00:00
|
|
|
Item::Type getContactType(const Models::Roster::ElId& id) const;
|
|
|
|
const Element* getElementConst(const ElId& id) const;
|
|
|
|
Element* getElement(const ElId& id);
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2019-04-02 21:58:43 +00:00
|
|
|
QVariant data ( const QModelIndex& index, int role ) const override;
|
2019-03-31 21:05:09 +00:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
2019-04-02 21:58:43 +00:00
|
|
|
int columnCount ( const QModelIndex& parent ) const override;
|
|
|
|
int rowCount ( const QModelIndex& parent ) const override;
|
|
|
|
QModelIndex parent ( const QModelIndex& child ) const override;
|
|
|
|
QModelIndex index ( int row, int column, const QModelIndex& parent ) const override;
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2019-09-28 14:30:16 +00:00
|
|
|
std::deque<QString> groupList(const QString& account) const;
|
|
|
|
bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const;
|
2022-04-18 16:54:42 +00:00
|
|
|
QString getContactIconPath(const QString& account, const QString& jid, const QString& resource) const;
|
2019-12-20 15:41:20 +00:00
|
|
|
Account* getAccount(const QString& name);
|
2022-04-22 15:26:18 +00:00
|
|
|
const Account* getAccountConst(const QString& name) const;
|
2022-08-17 16:25:35 +00:00
|
|
|
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;
|
|
|
|
|
2022-04-24 15:52:29 +00:00
|
|
|
bool markMessageAsRead(const ElId& elementId, const QString& messageId);
|
2020-08-21 20:57:48 +00:00
|
|
|
void responseArchive(const QString& account, const QString& jid, const std::list<Shared::Message>& list, bool last);
|
2021-04-18 12:49:20 +00:00
|
|
|
|
|
|
|
void fileProgress(const std::list<Shared::MessageInfo>& msgs, qreal value, bool up);
|
|
|
|
void fileError(const std::list<Shared::MessageInfo>& msgs, const QString& err, bool up);
|
|
|
|
void fileComplete(const std::list<Shared::MessageInfo>& msgs, bool up);
|
2019-09-28 14:30:16 +00:00
|
|
|
|
2019-04-03 15:09:29 +00:00
|
|
|
Accounts* accountsModel;
|
|
|
|
|
2020-08-11 22:49:51 +00:00
|
|
|
signals:
|
|
|
|
void requestArchive(const QString& account, const QString& jid, const QString& before);
|
2021-04-18 12:49:20 +00:00
|
|
|
void fileDownloadRequest(const QString& url);
|
2022-04-23 13:58:08 +00:00
|
|
|
void unreadMessagesCountChanged(int count);
|
2021-04-27 19:29:15 +00:00
|
|
|
void unnoticedMessage(const QString& account, const Shared::Message& msg);
|
2021-04-28 20:26:19 +00:00
|
|
|
void localPathInvalid(const QString& path);
|
2022-08-17 16:25:35 +00:00
|
|
|
void addedElement(const std::list<QString>& path); //emits only on addition of Account, Contact, Room or Group. Presence and Participant are ignored
|
2020-08-11 22:49:51 +00:00
|
|
|
|
2019-04-03 18:15:36 +00:00
|
|
|
private slots:
|
|
|
|
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
2021-05-16 21:52:59 +00:00
|
|
|
void onAccountReconnected();
|
2019-04-09 15:04:08 +00:00
|
|
|
void onChildChanged(Models::Item* item, int row, int col);
|
2019-04-07 14:02:41 +00:00
|
|
|
void onChildIsAboutToBeInserted(Item* parent, int first, int last);
|
|
|
|
void onChildInserted();
|
|
|
|
void onChildIsAboutToBeRemoved(Item* parent, int first, int last);
|
|
|
|
void onChildRemoved();
|
|
|
|
void onChildIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
|
|
|
|
void onChildMoved();
|
2020-08-11 22:49:51 +00:00
|
|
|
void onElementRequestArchive(const QString& before);
|
2022-04-23 13:58:08 +00:00
|
|
|
void recalculateUnreadMessages();
|
2022-04-24 15:52:29 +00:00
|
|
|
|
2021-04-18 12:49:20 +00:00
|
|
|
private:
|
|
|
|
Item* root;
|
|
|
|
std::map<QString, Account*> accounts;
|
|
|
|
std::map<ElId, Group*> groups;
|
|
|
|
std::map<ElId, Contact*> contacts;
|
|
|
|
std::map<ElId, Room*> rooms;
|
2019-04-03 18:15:36 +00:00
|
|
|
|
2019-04-09 15:04:08 +00:00
|
|
|
public:
|
2019-03-31 21:05:09 +00:00
|
|
|
class ElId {
|
|
|
|
public:
|
2019-08-28 11:40:55 +00:00
|
|
|
ElId (const QString& p_account = "", const QString& p_name = "");
|
2019-03-31 21:05:09 +00:00
|
|
|
|
|
|
|
const QString account;
|
|
|
|
const QString name;
|
|
|
|
|
|
|
|
bool operator < (const ElId& other) const;
|
2020-04-11 20:00:15 +00:00
|
|
|
bool operator == (const ElId& other) const;
|
|
|
|
bool operator != (const ElId& other) const;
|
2019-03-31 21:05:09 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MODELS_ROSTER_H
|