File: abstractroomordering.h

package info (click to toggle)
quaternion 0.0.97.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: cpp: 8,380; xml: 172; sh: 5; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 3,251 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/******************************************************************************
 * SPDX-FileCopyrightText: 2018-2019 QMatrixClient Project
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#pragma once

#include <Quotient/room.h>
#include <QtCore/QVariantList>

struct RoomGroup
{
    QVariant key;
    QVector<Quotient::Room*> rooms;

    bool operator==(const RoomGroup& other) const
    {
        return key == other.key;
    }
    bool operator!=(const RoomGroup& other) const
    {
        return !(*this == other);
    }
    bool operator==(const QVariant& otherCaption) const
    {
        return key == otherCaption;
    }
    bool operator!=(const QVariant& otherCaption) const
    {
        return !(*this == otherCaption);
    }
    friend bool operator==(const QVariant& otherCaption,
                           const RoomGroup& group)
    {
        return group == otherCaption;
    }
    friend bool operator!=(const QVariant& otherCaption,
                           const RoomGroup& group)
    {
        return !(group == otherCaption);
    }

    static inline const auto SystemPrefix = QStringLiteral("im.quotient.");
    static inline const auto LegacyPrefix = QStringLiteral("org.qmatrixclient.");
};
using RoomGroups = QVector<RoomGroup>;

class RoomListModel;

class AbstractRoomOrdering : public QObject
{
        Q_OBJECT
    public:
        using Room = Quotient::Room;
        using Connection = Quotient::Connection;
        using groups_t = QVariantList;

        explicit AbstractRoomOrdering(RoomListModel* m);

    public: // Overridables
        /// Returns human-readable name of the room ordering
        virtual QString orderingName() const = 0;
        /// Returns human-readable room group caption
        virtual QVariant groupLabel(const RoomGroup& g) const = 0;
        /// Orders a group against a key of another group
        virtual bool groupLessThan(const QVariant& g1key,
                                   const QVariant& g2key) const = 0;
        /// Orders two rooms within one group
        virtual bool roomLessThan(const QVariant& group,
                                  const Room* r1, const Room* r2) const = 0;

        /// Returns the full list of room groups
        virtual groups_t roomGroups(const Room* room) const = 0;
        /// Connects order updates to signals from a new Matrix connection
        virtual void connectSignals(Connection* connection) = 0;
        /// Connects order updates to signals from a new Matrix room
        virtual void connectSignals(Room* room) = 0;

    public:
        using groupLessThan_closure_t = std::function<bool(const QVariant&, const QVariant&)>;
        /// Returns a closure that invokes this->groupLessThan()
        groupLessThan_closure_t groupLessThanFactory() const;

        using roomLessThan_closure_t =
                std::function<bool(const Room*, const Room*)>;
        /// Returns a closure that invokes this->roomLessThan in a given group
        roomLessThan_closure_t roomLessThanFactory(const QVariant& group) const;

    protected slots:
        /// A facade for derived classes to trigger RoomListModel::updateGroups
        virtual void updateGroups(Room* room);

    protected:
        RoomListModel* model() const;
};