Introducing the all-new all-fancy bufferviews.
[quassel.git] / src / common / bufferviewconfig.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 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  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "bufferviewconfig.h"
22
23 #include "bufferinfo.h"
24
25 BufferViewConfig::BufferViewConfig(int bufferViewId, QObject *parent)
26   : SyncableObject(parent),
27     _bufferViewId(bufferViewId),
28     _addNewBuffersAutomatically(true),
29     _sortAlphabetically(true),
30     _hideInactiveBuffers(false),
31     _allowedBufferTypes(BufferInfo::StatusBuffer | BufferInfo::ChannelBuffer | BufferInfo::QueryBuffer | BufferInfo::GroupBuffer),
32     _minimumActivity(0)
33 {
34   setObjectName(QString::number(bufferViewId));
35 }
36
37 BufferViewConfig::BufferViewConfig(int bufferViewId, const QVariantMap &properties, QObject *parent)
38   : SyncableObject(parent),
39     _bufferViewId(bufferViewId)
40 {
41   fromVariantMap(properties);
42   setObjectName(QString::number(bufferViewId));
43 }
44
45 void BufferViewConfig::setBufferViewName(const QString &bufferViewName) {
46   if(_bufferViewName == bufferViewName)
47     return;
48
49   _bufferViewName = bufferViewName;
50   emit bufferViewNameSet(bufferViewName);
51 }
52
53 void BufferViewConfig::setNetworkId(const NetworkId &networkId) {
54   if(_networkId == networkId)
55     return;
56
57   _networkId = networkId;
58   emit networkIdSet(networkId);
59 }
60
61 void BufferViewConfig::setAddNewBuffersAutomatically(bool addNewBuffersAutomatically) {
62   if(_addNewBuffersAutomatically == addNewBuffersAutomatically)
63     return;
64
65   _addNewBuffersAutomatically = addNewBuffersAutomatically;
66   emit addNewBuffersAutomaticallySet(addNewBuffersAutomatically);
67 }
68
69 void BufferViewConfig::setSortAlphabetically(bool sortAlphabetically) {
70   if(_sortAlphabetically == sortAlphabetically)
71     return;
72
73   _sortAlphabetically = sortAlphabetically;
74   emit sortAlphabeticallySet(sortAlphabetically);
75 }
76
77 void BufferViewConfig::setAllowedBufferTypes(int bufferTypes) {
78   if(_allowedBufferTypes == bufferTypes)
79     return;
80
81   _allowedBufferTypes = bufferTypes;
82   emit allowedBufferTypesSet(bufferTypes);
83 }
84
85 void BufferViewConfig::setMinimumActivity(int activity) {
86   if(_minimumActivity == activity)
87     return;
88
89   _minimumActivity = activity;
90   emit minimumActivitySet(activity);
91 }
92
93 void BufferViewConfig::setHideInactiveBuffers(bool hideInactiveBuffers) {
94   if(_hideInactiveBuffers == hideInactiveBuffers)
95     return;
96
97   _hideInactiveBuffers = hideInactiveBuffers;
98   emit hideInactiveBuffersSet(hideInactiveBuffers);
99 }
100
101 QVariantList BufferViewConfig::initBufferList() const {
102   QVariantList buffers;
103
104   foreach(BufferId bufferId, _buffers) {
105     buffers << qVariantFromValue(bufferId);
106   }
107
108   return buffers;
109 }
110
111 void BufferViewConfig::initSetBufferList(const QVariantList &buffers) {
112   _buffers.clear();
113
114   foreach(QVariant buffer, buffers) {
115     _buffers << buffer.value<BufferId>();
116   }
117
118   emit bufferListSet();
119 }
120
121 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
122   _buffers.clear();
123
124   foreach(BufferId bufferId, buffers) {
125     _buffers << bufferId;
126   }
127
128   emit bufferListSet();
129 }
130
131 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
132   qDebug() << "addBuffer" << bufferId;
133   if(_buffers.contains(bufferId))
134     return;
135   
136   _buffers.insert(pos, bufferId);
137   emit bufferAdded(bufferId, pos);
138 }
139
140 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
141   qDebug() << "moveeBuffer" << bufferId;
142   if(!_buffers.contains(bufferId))
143     return;
144
145   qDebug() << "lala" << bufferId << pos;
146   _buffers.move(_buffers.indexOf(bufferId), pos);
147   emit bufferMoved(bufferId, pos);
148 }
149
150 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
151   qDebug() << "removeBuffer" << bufferId;
152   if(!_buffers.contains(bufferId))
153     return;
154   
155   _buffers.removeAt(_buffers.indexOf(bufferId));
156   emit bufferRemoved(bufferId);
157 }