common: Simplify SyncableObject macros and usage
[quassel.git] / src / common / bufferviewconfig.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "syncableobject.h"
24
25 #include "bufferinfo.h"
26 #include "types.h"
27
28 class BufferViewConfig : public SyncableObject
29 {
30     Q_OBJECT
31     SYNCABLE_OBJECT
32
33     Q_PROPERTY(QString bufferViewName READ bufferViewName WRITE setBufferViewName)
34     Q_PROPERTY(NetworkId networkId READ networkId WRITE setNetworkId)
35     Q_PROPERTY(bool addNewBuffersAutomatically READ addNewBuffersAutomatically WRITE setAddNewBuffersAutomatically)
36     Q_PROPERTY(bool sortAlphabetically READ sortAlphabetically WRITE setSortAlphabetically)
37     Q_PROPERTY(bool hideInactiveBuffers READ hideInactiveBuffers WRITE setHideInactiveBuffers)
38     Q_PROPERTY(bool hideInactiveNetworks READ hideInactiveNetworks WRITE setHideInactiveNetworks)
39     Q_PROPERTY(bool disableDecoration READ disableDecoration WRITE setDisableDecoration)
40     Q_PROPERTY(int allowedBufferTypes READ allowedBufferTypes WRITE setAllowedBufferTypes)
41     Q_PROPERTY(int minimumActivity READ minimumActivity WRITE setMinimumActivity)
42     Q_PROPERTY(bool showSearch READ showSearch WRITE setShowSearch)
43
44 public :
45     BufferViewConfig(int bufferViewId, QObject *parent = 0);
46     BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent = 0);
47
48 public slots:
49     inline int bufferViewId() const { return _bufferViewId; }
50
51     inline const QString &bufferViewName() const { return _bufferViewName; }
52     void setBufferViewName(const QString &bufferViewName);
53
54     inline const NetworkId &networkId() const { return _networkId; }
55     void setNetworkId(const NetworkId &networkId);
56
57     inline bool addNewBuffersAutomatically() const { return _addNewBuffersAutomatically; }
58     void setAddNewBuffersAutomatically(bool addNewBuffersAutomatically);
59
60     inline bool sortAlphabetically() const { return _sortAlphabetically; }
61     void setSortAlphabetically(bool sortAlphabetically);
62
63     inline bool disableDecoration() const { return _disableDecoration; }
64     void setDisableDecoration(bool disableDecoration);
65
66     inline int allowedBufferTypes() const { return _allowedBufferTypes; }
67     void setAllowedBufferTypes(int bufferTypes);
68
69     inline int minimumActivity() const { return _minimumActivity; }
70     void setMinimumActivity(int activity);
71
72     inline bool hideInactiveBuffers() const { return _hideInactiveBuffers; }
73     void setHideInactiveBuffers(bool hideInactiveBuffers);
74
75     inline bool hideInactiveNetworks() const { return _hideInactiveNetworks; }
76     void setHideInactiveNetworks(bool hideInactiveNetworks);
77
78     inline bool showSearch() const { return _showSearch; }
79     void setShowSearch(bool showSearch);
80
81     virtual inline void requestSetBufferViewName(const QString &bufferViewName) { REQUEST(ARG(bufferViewName)) }
82
83     const QList<BufferId> &bufferList() const { return _buffers; }
84     const QSet<BufferId> &removedBuffers() const { return _removedBuffers; }
85     const QSet<BufferId> &temporarilyRemovedBuffers() const { return _temporarilyRemovedBuffers; }
86
87     QVariantList initBufferList() const;
88     void initSetBufferList(const QVariantList &buffers);
89     void initSetBufferList(const QList<BufferId> &buffers);
90
91     QVariantList initRemovedBuffers() const;
92     void initSetRemovedBuffers(const QVariantList &buffers);
93
94     QVariantList initTemporarilyRemovedBuffers() const;
95     void initSetTemporarilyRemovedBuffers(const QVariantList &buffers);
96
97     void addBuffer(const BufferId &bufferId, int pos);
98     virtual inline void requestAddBuffer(const BufferId &bufferId, int pos) { REQUEST(ARG(bufferId), ARG(pos)) }
99     void moveBuffer(const BufferId &bufferId, int pos);
100     virtual inline void requestMoveBuffer(const BufferId &bufferId, int pos) { REQUEST(ARG(bufferId), ARG(pos)) }
101     void removeBuffer(const BufferId &bufferId);
102     virtual inline void requestRemoveBuffer(const BufferId &bufferId) { REQUEST(ARG(bufferId)) }
103     void removeBufferPermanently(const BufferId &bufferId);
104     virtual inline void requestRemoveBufferPermanently(const BufferId &bufferId) { REQUEST(ARG(bufferId)) }
105
106 signals:
107     void bufferViewNameSet(const QString &bufferViewName); // invalidate
108     void configChanged();
109     void networkIdSet(const NetworkId &networkId);
110 //   void addNewBuffersAutomaticallySet(bool addNewBuffersAutomatically); // invalidate
111 //   void sortAlphabeticallySet(bool sortAlphabetically); // invalidate
112 //   //  void disableDecorationSet(bool disableDecoration); // invalidate
113 //   void allowedBufferTypesSet(int allowedBufferTypes); // invalidate
114 //   void minimumActivitySet(int activity); // invalidate
115 //   void hideInactiveBuffersSet(bool hideInactiveBuffers); // invalidate
116     void bufferListSet(); // invalidate
117
118     void bufferAdded(const BufferId &bufferId, int pos);
119 //   void addBufferRequested(const BufferId &bufferId, int pos);
120     void bufferMoved(const BufferId &bufferId, int pos);
121 //   void moveBufferRequested(const BufferId &bufferId, int pos);
122     void bufferRemoved(const BufferId &bufferId);
123     void bufferPermanentlyRemoved(const BufferId &bufferId);
124 //   void removeBufferRequested(const BufferId &bufferId);
125 //   void removeBufferPermanentlyRequested(const BufferId &bufferId);
126
127 //   void setBufferViewNameRequested(const QString &bufferViewName);
128
129 private:
130     int _bufferViewId = 0;                   ///< ID of the associated BufferView
131     QString _bufferViewName = {};            ///< Display name of the associated BufferView
132     NetworkId _networkId = {};               ///< Network ID this buffer belongs to
133
134     bool _addNewBuffersAutomatically = true; ///< Automatically add new buffers when created
135     bool _sortAlphabetically = true;         ///< Sort buffers alphabetically
136     bool _hideInactiveBuffers = false;       ///< Hide buffers without activity
137     bool _hideInactiveNetworks = false;      ///< Hide networks without activity
138     bool _disableDecoration = false;         ///< Disable buffer decoration (not fully implemented)
139     /// Buffer types allowed within this view
140     int _allowedBufferTypes = (BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer
141                                | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer);
142     int _minimumActivity = 0;                ///< Minimum activity for a buffer to show
143     bool _showSearch = false;                ///< Persistently show the buffer search UI
144
145     QList<BufferId> _buffers;
146     QSet<BufferId> _removedBuffers;
147     QSet<BufferId> _temporarilyRemovedBuffers;
148 };