matrixion/src/timeline/CommunitiesModel.h

79 lines
2 KiB
C
Raw Normal View History

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>
#include "CacheStructs.h"
2021-06-10 00:52:28 +03:00
class CommunitiesModel : public QAbstractListModel
{
2021-09-18 01:22:33 +03:00
Q_OBJECT
Q_PROPERTY(QString currentTagId READ currentTagId WRITE setCurrentTagId NOTIFY
currentTagIdChanged RESET resetCurrentTagId)
Q_PROPERTY(QStringList tags READ tags NOTIFY tagsChanged)
Q_PROPERTY(QStringList tagsWithDefault READ tagsWithDefault NOTIFY tagsChanged)
2021-06-10 00:52:28 +03:00
public:
2021-09-18 01:22:33 +03:00
enum Roles
{
AvatarUrl = Qt::UserRole,
DisplayName,
Tooltip,
ChildrenHidden,
Hidden,
Id,
};
2021-06-10 00:52:28 +03:00
2021-09-18 01:22:33 +03:00
CommunitiesModel(QObject *parent = nullptr);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
(void)parent;
return 2 + tags_.size() + spaceOrder_.size();
2021-09-18 01:22:33 +03:00
}
QVariant data(const QModelIndex &index, int role) const override;
2021-06-10 00:52:28 +03:00
public slots:
2021-09-18 01:22:33 +03:00
void initializeSidebar();
void sync(const mtx::responses::Sync &sync_);
2021-09-18 01:22:33 +03:00
void clear();
QString currentTagId() const { return currentTagId_; }
void setCurrentTagId(QString tagId);
void resetCurrentTagId()
{
currentTagId_.clear();
emit currentTagIdChanged(currentTagId_);
}
QStringList tags() const { return tags_; }
QStringList tagsWithDefault() const
{
QStringList tagsWD = tags_;
tagsWD.prepend("m.lowpriority");
tagsWD.prepend("m.favourite");
tagsWD.removeOne("m.server_notice");
tagsWD.removeDuplicates();
return tagsWD;
}
void toggleTagId(QString tagId);
2021-06-10 00:52:28 +03:00
signals:
2021-09-18 01:22:33 +03:00
void currentTagIdChanged(QString tagId);
void hiddenTagsChanged();
void tagsChanged();
2021-06-10 00:52:28 +03:00
private:
2021-09-18 01:22:33 +03:00
QStringList tags_;
QString currentTagId_;
QStringList hiddentTagIds_;
QStringList spaceOrder_;
std::map<QString, RoomInfo> spaces_;
2021-06-10 00:52:28 +03:00
};