Load Qt's default translations if available, fixes BR #400
[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   // normaly initSeters don't need an emit. this one is to track changes in the settingspage
119   emit bufferListSet();
120 }
121
122 void BufferViewConfig::initSetBufferList(const QList<BufferId> &buffers) {
123   _buffers.clear();
124
125   foreach(BufferId bufferId, buffers) {
126     _buffers << bufferId;
127   }
128
129   // normaly initSeters don't need an emit. this one is to track changes in the settingspage
130   emit bufferListSet();
131 }
132
133 QVariantList BufferViewConfig::initRemovedBuffers() const {
134   QVariantList removedBuffers;
135
136   foreach(BufferId bufferId, _removedBuffers) {
137     removedBuffers << qVariantFromValue(bufferId);
138   }
139
140   return removedBuffers;
141 }
142
143 void BufferViewConfig::initSetRemovedBuffers(const QVariantList &buffers) {
144   _removedBuffers.clear();
145
146   foreach(QVariant buffer, buffers) {
147     _removedBuffers << buffer.value<BufferId>();
148   }
149 }
150
151 QVariantList BufferViewConfig::initTemporarilyRemovedBuffers() const {
152   QVariantList temporarilyRemovedBuffers;
153
154   foreach(BufferId bufferId, _temporarilyRemovedBuffers) {
155     temporarilyRemovedBuffers << qVariantFromValue(bufferId);
156   }
157
158   return temporarilyRemovedBuffers;
159 }
160
161 void BufferViewConfig::initSetTemporarilyRemovedBuffers(const QVariantList &buffers) {
162   _temporarilyRemovedBuffers.clear();
163
164   foreach(QVariant buffer, buffers) {
165     _temporarilyRemovedBuffers << buffer.value<BufferId>();
166   }
167 }
168
169 void BufferViewConfig::addBuffer(const BufferId &bufferId, int pos) {
170   if(_buffers.contains(bufferId))
171     return;
172
173   if(pos < 0)
174     pos = 0;
175   if(pos > _buffers.count())
176     pos = _buffers.count();
177
178   if(_removedBuffers.contains(bufferId))
179     _removedBuffers.remove(bufferId);
180   
181   if(_temporarilyRemovedBuffers.contains(bufferId))
182     _temporarilyRemovedBuffers.remove(bufferId);
183   
184   _buffers.insert(pos, bufferId);
185   emit bufferAdded(bufferId, pos);
186 }
187
188 void BufferViewConfig::moveBuffer(const BufferId &bufferId, int pos) {
189   if(!_buffers.contains(bufferId))
190     return;
191
192   if(pos < 0)
193     pos = 0;
194   if(pos >= _buffers.count())
195     pos = _buffers.count() - 1;
196
197   _buffers.move(_buffers.indexOf(bufferId), pos);
198   emit bufferMoved(bufferId, pos);
199 }
200
201 void BufferViewConfig::removeBuffer(const BufferId &bufferId) {
202   if(_buffers.contains(bufferId))
203     _buffers.removeAt(_buffers.indexOf(bufferId));
204   
205   if(_removedBuffers.contains(bufferId))
206     _removedBuffers.remove(bufferId);
207
208   _temporarilyRemovedBuffers << bufferId;
209
210   emit bufferRemoved(bufferId);
211 }
212
213 void BufferViewConfig::removeBufferPermanently(const BufferId &bufferId) {
214   if(_buffers.contains(bufferId))
215     _buffers.removeAt(_buffers.indexOf(bufferId));
216
217   if(_temporarilyRemovedBuffers.contains(bufferId))
218     _temporarilyRemovedBuffers.remove(bufferId);
219   
220   _removedBuffers << bufferId;
221
222   emit bufferPermanentlyRemoved(bufferId);
223 }