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-04-03 15:09:29 +00:00
|
|
|
#ifndef MODELS_ITEM_H
|
|
|
|
#define MODELS_ITEM_H
|
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include <deque>
|
2020-04-17 23:17:47 +00:00
|
|
|
#include <set>
|
2019-04-03 15:09:29 +00:00
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/enums.h"
|
2019-04-03 15:09:29 +00:00
|
|
|
namespace Models {
|
|
|
|
|
2020-04-16 20:23:02 +00:00
|
|
|
class Reference;
|
2020-04-17 23:17:47 +00:00
|
|
|
class Contact;
|
|
|
|
class Account;
|
2020-04-16 20:23:02 +00:00
|
|
|
|
2019-04-03 18:15:36 +00:00
|
|
|
class Item : public QObject{
|
2020-04-16 20:23:02 +00:00
|
|
|
friend class Reference;
|
2019-04-03 18:15:36 +00:00
|
|
|
Q_OBJECT
|
2019-04-03 15:09:29 +00:00
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
account,
|
|
|
|
group,
|
2019-04-03 21:23:51 +00:00
|
|
|
contact,
|
2019-07-11 08:51:52 +00:00
|
|
|
room,
|
2019-04-07 14:02:41 +00:00
|
|
|
presence,
|
2019-09-01 19:46:12 +00:00
|
|
|
participant,
|
2020-04-16 20:23:02 +00:00
|
|
|
root,
|
|
|
|
reference
|
2019-04-03 15:09:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit Item(Type p_type, const QMap<QString, QVariant> &data, Item *parentItem = 0);
|
2019-09-28 14:30:16 +00:00
|
|
|
Item(const Item& other);
|
2019-04-03 15:09:29 +00:00
|
|
|
~Item();
|
|
|
|
|
2019-04-03 18:15:36 +00:00
|
|
|
signals:
|
2019-04-09 15:04:08 +00:00
|
|
|
void childChanged(Models::Item* item, int row, int col);
|
2019-04-07 14:02:41 +00:00
|
|
|
void childIsAboutToBeInserted(Item* parent, int first, int last);
|
|
|
|
void childInserted();
|
|
|
|
void childIsAboutToBeRemoved(Item* parent, int first, int last);
|
|
|
|
void childRemoved();
|
|
|
|
void childIsAboutToBeMoved(Item* source, int first, int last, Item* destination, int newIndex);
|
|
|
|
void childMoved();
|
|
|
|
|
2019-04-03 18:15:36 +00:00
|
|
|
public:
|
2019-04-07 14:02:41 +00:00
|
|
|
virtual void appendChild(Item *child);
|
|
|
|
virtual void removeChild(int index);
|
2019-09-24 09:21:29 +00:00
|
|
|
virtual QString getDisplayedName() const;
|
2019-04-03 15:09:29 +00:00
|
|
|
QString getName() const;
|
|
|
|
void setName(const QString& name);
|
|
|
|
|
2020-04-16 20:23:02 +00:00
|
|
|
virtual Item *child(int row);
|
|
|
|
virtual int childCount() const;
|
2019-04-03 15:09:29 +00:00
|
|
|
virtual int columnCount() const;
|
|
|
|
virtual QVariant data(int column) const;
|
|
|
|
int row() const;
|
|
|
|
Item *parentItem();
|
2019-04-09 15:04:08 +00:00
|
|
|
const Item *parentItemConst() const;
|
2019-04-03 15:09:29 +00:00
|
|
|
|
2019-08-28 11:40:55 +00:00
|
|
|
|
|
|
|
QString getAccountName() const;
|
|
|
|
QString getAccountJid() const;
|
|
|
|
QString getAccountResource() const;
|
2019-09-28 14:30:16 +00:00
|
|
|
Shared::ConnectionState getAccountConnectionState() const;
|
|
|
|
Shared::Availability getAccountAvailability() const;
|
2019-08-28 11:40:55 +00:00
|
|
|
|
2019-04-03 15:09:29 +00:00
|
|
|
const Type type;
|
|
|
|
|
2020-04-17 23:17:47 +00:00
|
|
|
int getContact(const QString& jid) const;
|
|
|
|
std::set<Reference*>::size_type referencesCount() const;
|
|
|
|
|
2019-04-07 14:02:41 +00:00
|
|
|
protected:
|
|
|
|
virtual void changed(int col);
|
|
|
|
virtual void _removeChild(int index);
|
2020-04-18 12:02:01 +00:00
|
|
|
virtual void _appendChild(Item *child);
|
2019-09-24 09:21:29 +00:00
|
|
|
virtual bool columnInvolvedInDisplay(int col);
|
2020-04-17 23:17:47 +00:00
|
|
|
virtual const Account* getParentAccount() const;
|
2020-04-18 12:02:01 +00:00
|
|
|
void addReference(Reference* ref);
|
|
|
|
void removeReference(Reference* ref);
|
2019-04-07 14:02:41 +00:00
|
|
|
|
2019-09-24 09:21:29 +00:00
|
|
|
protected slots:
|
|
|
|
void onChildChanged(Models::Item* item, int row, int col);
|
2020-04-18 12:02:01 +00:00
|
|
|
virtual void toOfflineState();
|
2019-09-24 09:21:29 +00:00
|
|
|
|
2019-04-03 15:09:29 +00:00
|
|
|
protected:
|
|
|
|
QString name;
|
|
|
|
std::deque<Item*> childItems;
|
|
|
|
Item* parent;
|
2020-04-17 23:17:47 +00:00
|
|
|
std::set<Reference*> references;
|
2020-04-18 12:02:01 +00:00
|
|
|
bool destroyingByParent;
|
|
|
|
bool destroyingByOriginal;
|
2019-04-03 15:09:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MODELS_ITEM_H
|