summary refs log tree commit diff
path: root/include/CommunitiesList.h
blob: 32a64bf250c72c5c0a18391cebdea80d1d15c96d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once

#include <QScrollArea>
#include <QSharedPointer>
#include <QVBoxLayout>

#include "CommunitiesListItem.h"
#include "ui/Theme.h"

class CommunitiesList : public QWidget
{
        Q_OBJECT

public:
        CommunitiesList(QWidget *parent = nullptr);

        void clear() { communities_.clear(); }

        void addCommunity(const std::string &id);
        void removeCommunity(const QString &id) { communities_.erase(id); };
        std::vector<QString> roomList(const QString &id) const;

signals:
        void communityChanged(const QString &id);
        void avatarRetrieved(const QString &id, const QPixmap &img);
        void groupProfileRetrieved(const QString &group_id, const mtx::responses::GroupProfile &);
        void groupRoomsRetrieved(const QString &group_id, const std::vector<QString> &res);

public slots:
        void updateCommunityAvatar(const QString &id, const QPixmap &img);
        void highlightSelectedCommunity(const QString &id);
        void setCommunities(const mtx::responses::JoinedGroups &groups);

private:
        void fetchCommunityAvatar(const QString &id, const QString &avatarUrl);
        void addGlobalItem() { addCommunity("world"); }

        //! Check whether or not a community id is currently managed.
        bool communityExists(const QString &id) const
        {
                return communities_.find(id) != communities_.end();
        }

        QVBoxLayout *topLayout_;
        QVBoxLayout *contentsLayout_;
        QWidget *scrollAreaContents_;
        QScrollArea *scrollArea_;

        std::map<QString, QSharedPointer<CommunitiesListItem>> communities_;
};