2021-06-10 00:52:28 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <mtx/responses/sync.hpp>
|
|
|
|
|
2021-06-16 01:09:45 +03:00
|
|
|
#include "CacheStructs.h"
|
|
|
|
|
2021-06-10 00:52:28 +03:00
|
|
|
class CommunitiesModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString currentTagId READ currentTagId WRITE setCurrentTagId NOTIFY
|
|
|
|
currentTagIdChanged RESET resetCurrentTagId)
|
|
|
|
Q_PROPERTY(QStringList tags READ tags NOTIFY tagsChanged)
|
2021-06-15 00:40:06 +03:00
|
|
|
Q_PROPERTY(QStringList tagsWithDefault READ tagsWithDefault NOTIFY tagsChanged)
|
2021-06-10 00:52:28 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Roles
|
|
|
|
{
|
|
|
|
AvatarUrl = Qt::UserRole,
|
|
|
|
DisplayName,
|
|
|
|
Tooltip,
|
|
|
|
ChildrenHidden,
|
2021-06-11 18:54:05 +03:00
|
|
|
Hidden,
|
2021-06-10 00:52:28 +03:00
|
|
|
Id,
|
|
|
|
};
|
|
|
|
|
|
|
|
CommunitiesModel(QObject *parent = nullptr);
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
|
|
|
{
|
|
|
|
(void)parent;
|
|
|
|
return 1 + tags_.size();
|
|
|
|
}
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void initializeSidebar();
|
|
|
|
void sync(const mtx::responses::Rooms &rooms);
|
|
|
|
void clear();
|
|
|
|
QString currentTagId() const { return currentTagId_; }
|
|
|
|
void setCurrentTagId(QString tagId);
|
|
|
|
void resetCurrentTagId()
|
|
|
|
{
|
|
|
|
currentTagId_.clear();
|
2021-06-11 15:51:29 +03:00
|
|
|
emit currentTagIdChanged(currentTagId_);
|
2021-06-10 00:52:28 +03:00
|
|
|
}
|
|
|
|
QStringList tags() const { return tags_; }
|
2021-06-15 00:40:06 +03:00
|
|
|
QStringList tagsWithDefault() const
|
|
|
|
{
|
|
|
|
QStringList tagsWD = tags_;
|
|
|
|
tagsWD.prepend("m.lowpriority");
|
|
|
|
tagsWD.prepend("m.favourite");
|
|
|
|
tagsWD.removeOne("m.server_notice");
|
|
|
|
tagsWD.removeDuplicates();
|
|
|
|
return tagsWD;
|
|
|
|
}
|
2021-06-11 18:54:05 +03:00
|
|
|
void toggleTagId(QString tagId);
|
2021-06-10 00:52:28 +03:00
|
|
|
|
|
|
|
signals:
|
2021-06-11 15:51:29 +03:00
|
|
|
void currentTagIdChanged(QString tagId);
|
2021-06-11 18:54:05 +03:00
|
|
|
void hiddenTagsChanged();
|
2021-06-10 00:52:28 +03:00
|
|
|
void tagsChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QStringList tags_;
|
|
|
|
QString currentTagId_;
|
2021-06-11 18:54:05 +03:00
|
|
|
QStringList hiddentTagIds_;
|
2021-06-16 01:09:45 +03:00
|
|
|
QStringList spaceOrder_;
|
|
|
|
std::map<QString, RoomInfo> spaces_;
|
2021-06-10 00:52:28 +03:00
|
|
|
};
|