2019-09-01 22:46:12 +03: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-04-01 00:05:09 +03:00
|
|
|
#ifndef MODELS_ROSTER_H
|
|
|
|
#define MODELS_ROSTER_H
|
|
|
|
|
|
|
|
#include <qabstractitemmodel.h>
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
2019-04-03 21:15:36 +03:00
|
|
|
#include <QVector>
|
2020-02-08 14:44:15 +03:00
|
|
|
|
|
|
|
#include "global.h"
|
2019-04-03 18:09:29 +03:00
|
|
|
#include "accounts.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "account.h"
|
2019-04-05 18:12:59 +03:00
|
|
|
#include "contact.h"
|
2019-06-22 23:37:22 +03:00
|
|
|
#include "group.h"
|
2019-07-11 11:51:52 +03:00
|
|
|
#include "room.h"
|
2019-04-01 00:05:09 +03:00
|
|
|
|
|
|
|
namespace Models
|
|
|
|
{
|
|
|
|
|
|
|
|
class Roster : public QAbstractItemModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2019-04-09 18:04:08 +03:00
|
|
|
class ElId;
|
2019-04-01 00:05:09 +03:00
|
|
|
Roster(QObject* parent = 0);
|
|
|
|
~Roster();
|
|
|
|
|
|
|
|
void addAccount(const QMap<QString, QVariant> &data);
|
2019-04-03 00:58:43 +03:00
|
|
|
void updateAccount(const QString& account, const QString& field, const QVariant& value);
|
2019-05-29 18:05:54 +03:00
|
|
|
void removeAccount(const QString& account);
|
2019-04-04 00:23:51 +03:00
|
|
|
void addGroup(const QString& account, const QString& name);
|
|
|
|
void removeGroup(const QString& account, const QString& name);
|
2019-04-07 23:14:15 +03:00
|
|
|
void addContact(const QString& account, const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
|
2019-04-06 13:14:32 +03:00
|
|
|
void removeContact(const QString& account, const QString& jid, const QString& group);
|
|
|
|
void removeContact(const QString& account, const QString& jid);
|
2019-04-07 23:14:15 +03:00
|
|
|
void changeContact(const QString& account, const QString& jid, const QMap<QString, QVariant>& data);
|
2019-04-07 17:02:41 +03: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 17:58:59 +03:00
|
|
|
void addMessage(const QString& account, const Shared::Message& data);
|
2020-02-08 14:44:15 +03:00
|
|
|
void changeMessage(const QString& account, const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
|
2019-04-10 01:01:25 +03:00
|
|
|
void dropMessages(const QString& account, const QString& jid);
|
2019-07-11 11:51:52 +03: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 14:17:28 +03: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);
|
2019-06-18 18:08:03 +03:00
|
|
|
QString getContactName(const QString& account, const QString& jid);
|
2019-04-01 00:05:09 +03:00
|
|
|
|
2019-04-03 00:58:43 +03:00
|
|
|
QVariant data ( const QModelIndex& index, int role ) const override;
|
2019-04-01 00:05:09 +03:00
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
2019-04-03 00:58:43 +03: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-04-01 00:05:09 +03:00
|
|
|
|
2019-09-28 17:30:16 +03:00
|
|
|
std::deque<QString> groupList(const QString& account) const;
|
|
|
|
bool groupHasContact(const QString& account, const QString& group, const QString& contactJID) const;
|
2019-12-31 21:14:12 +03:00
|
|
|
QString getContactIconPath(const QString& account, const QString& jid, const QString& resource);
|
2019-12-20 18:41:20 +03:00
|
|
|
Account* getAccount(const QString& name);
|
2019-12-25 13:24:20 +03:00
|
|
|
QModelIndex getAccountIndex(const QString& name);
|
|
|
|
QModelIndex getGroupIndex(const QString& account, const QString& name);
|
2019-09-28 17:30:16 +03:00
|
|
|
|
2019-04-03 18:09:29 +03:00
|
|
|
Accounts* accountsModel;
|
|
|
|
|
2019-04-01 00:05:09 +03:00
|
|
|
private:
|
|
|
|
Item* root;
|
2019-04-03 00:58:43 +03:00
|
|
|
std::map<QString, Account*> accounts;
|
2019-06-22 23:37:22 +03:00
|
|
|
std::map<ElId, Group*> groups;
|
2019-04-05 18:12:59 +03:00
|
|
|
std::multimap<ElId, Contact*> contacts;
|
2019-07-11 11:51:52 +03:00
|
|
|
std::map<ElId, Room*> rooms;
|
2019-04-01 00:05:09 +03:00
|
|
|
|
2019-04-03 21:15:36 +03:00
|
|
|
private slots:
|
|
|
|
void onAccountDataChanged(const QModelIndex& tl, const QModelIndex& br, const QVector<int>& roles);
|
2019-04-09 18:04:08 +03:00
|
|
|
void onChildChanged(Models::Item* item, int row, int col);
|
2019-04-07 17:02:41 +03: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();
|
2019-04-03 21:15:36 +03:00
|
|
|
|
2019-04-09 18:04:08 +03:00
|
|
|
public:
|
2019-04-01 00:05:09 +03:00
|
|
|
class ElId {
|
|
|
|
public:
|
2019-08-28 14:40:55 +03:00
|
|
|
ElId (const QString& p_account = "", const QString& p_name = "");
|
2019-04-01 00:05:09 +03:00
|
|
|
|
|
|
|
const QString account;
|
|
|
|
const QString name;
|
|
|
|
|
|
|
|
bool operator < (const ElId& other) const;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MODELS_ROSTER_H
|