nick changes and day changes can now be hidden too
[quassel.git] / src / uisupport / bufferview.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 "bufferview.h"
22
23 #include "buffermodel.h"
24 #include "bufferviewfilter.h"
25 #include "buffersettings.h"
26 #include "buffersyncer.h"
27 #include "client.h"
28 #include "iconloader.h"
29 #include "mappedselectionmodel.h"
30 #include "network.h"
31 #include "networkmodel.h"
32
33 #include "uisettings.h"
34
35 #include <QAction>
36 #include <QFlags>
37 #include <QHeaderView>
38 #include <QInputDialog>
39 #include <QLineEdit>
40 #include <QMenu>
41 #include <QMessageBox>
42 #include <QSet>
43
44 /*****************************************
45 * The TreeView showing the Buffers
46 *****************************************/
47 // Please be carefull when reimplementing methods which are used to inform the view about changes to the data
48 // to be on the safe side: call QTreeView's method aswell
49 BufferView::BufferView(QWidget *parent)
50   : QTreeView(parent),
51     showChannelList(tr("Show Channel List"), this),
52     _connectNetAction(tr("Connect"), this),
53     _disconnectNetAction(tr("Disconnect"), this),
54     _joinChannelAction(tr("Join Channel"), this),
55
56     _joinBufferAction(tr("Join"), this),
57     _partBufferAction(tr("Part"), this),
58     _hideBufferTemporarilyAction(tr("Hide buffers"), this),
59     _hideBufferPermanentlyAction(tr("Hide buffers permanently"), this),
60     _removeBufferAction(tr("Delete buffer"), this),
61     _ignoreListAction(tr("Ignore list"), this),
62
63     _hideJoinAction(tr("Joins"), this),
64     _hidePartAction(tr("Parts"), this),
65     _hideQuitAction(tr("Quits"), this),
66     _hideNickAction(tr("Nick Changes"), this),
67     _hideModeAction(tr("Mode"), this),
68     _hideDayChangeAction(tr("Day Change"), this)
69 {
70   _hideJoinAction.setCheckable(true);
71   _hidePartAction.setCheckable(true);
72   _hideQuitAction.setCheckable(true);
73   _hideNickAction.setCheckable(true);
74   _hideModeAction.setCheckable(true);
75   _hideDayChangeAction.setCheckable(true);
76   _ignoreListAction.setEnabled(false);
77
78   showChannelList.setIcon(SmallIcon("format-list-unordered"));
79
80   connect(this, SIGNAL(collapsed(const QModelIndex &)), this, SLOT(on_collapse(const QModelIndex &)));
81   connect(this, SIGNAL(expanded(const QModelIndex &)), this, SLOT(on_expand(const QModelIndex &)));
82
83   setSelectionMode(QAbstractItemView::ExtendedSelection);
84 }
85
86 void BufferView::init() {
87   setIndentation(10);
88   header()->setContextMenuPolicy(Qt::ActionsContextMenu);
89   hideColumn(1);
90   hideColumn(2);
91   expandAll();
92
93   setAnimated(true);
94
95 #ifndef QT_NO_DRAGANDDROP
96   setDragEnabled(true);
97   setAcceptDrops(true);
98   setDropIndicatorShown(true);
99 #endif
100
101   setSortingEnabled(true);
102   sortByColumn(0, Qt::AscendingOrder);
103
104   // activated() fails on X11 and Qtopia at least
105 #if defined Q_WS_QWS or defined Q_WS_X11
106   connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(joinChannel(QModelIndex)));
107 #else
108   // afaik this is better on Mac and Windows
109   connect(this, SIGNAL(activated(QModelIndex)), SLOT(joinChannel(QModelIndex)));
110 #endif
111 }
112
113 void BufferView::setModel(QAbstractItemModel *model) {
114   delete selectionModel();
115
116   QTreeView::setModel(model);
117   init();
118   // remove old Actions
119   QList<QAction *> oldactions = header()->actions();
120   foreach(QAction *action, oldactions) {
121     header()->removeAction(action);
122     action->deleteLater();
123   }
124
125   if(!model)
126     return;
127
128   QString sectionName;
129   QAction *showSection;
130   for(int i = 1; i < model->columnCount(); i++) {
131     sectionName = (model->headerData(i, Qt::Horizontal, Qt::DisplayRole)).toString();
132     showSection = new QAction(sectionName, header());
133     showSection->setCheckable(true);
134     showSection->setChecked(!isColumnHidden(i));
135     showSection->setProperty("column", i);
136     connect(showSection, SIGNAL(toggled(bool)), this, SLOT(toggleHeader(bool)));
137     header()->addAction(showSection);
138   }
139
140 }
141
142 void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *config) {
143   BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
144   if(filter) {
145     filter->setConfig(config);
146     setConfig(config);
147     return;
148   }
149
150   if(model()) {
151     disconnect(this, 0, model(), 0);
152     disconnect(model(), 0, this, 0);
153   }
154
155   if(!model_) {
156     setModel(model_);
157   } else {
158     BufferViewFilter *filter = new BufferViewFilter(model_, config);
159     setModel(filter);
160     connect(filter, SIGNAL(configChanged()), this, SLOT(on_configChanged()));
161   }
162   setConfig(config);
163 }
164
165 void BufferView::setSelectionModel(QItemSelectionModel *selectionModel) {
166   if(QTreeView::selectionModel())
167     disconnect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
168                model(), SIGNAL(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
169
170   QTreeView::setSelectionModel(selectionModel);
171   BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
172   if(filter) {
173     connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
174             filter, SLOT(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
175   }
176 }
177
178 void BufferView::setConfig(BufferViewConfig *config) {
179   if(_config == config)
180     return;
181
182   if(_config) {
183     disconnect(_config, 0, this, 0);
184   }
185
186   _config = config;
187   if(config) {
188     connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(setRootIndexForNetworkId(const NetworkId &)));
189     setRootIndexForNetworkId(config->networkId());
190   } else {
191     setRootIndex(QModelIndex());
192   }
193 }
194
195 void BufferView::setRootIndexForNetworkId(const NetworkId &networkId) {
196   if(!networkId.isValid() || !model()) {
197     setRootIndex(QModelIndex());
198   } else {
199     int networkCount = model()->rowCount();
200     QModelIndex child;
201     for(int i = 0; i < networkCount; i++) {
202       child = model()->index(i, 0);
203       if(networkId == model()->data(child, NetworkModel::NetworkIdRole).value<NetworkId>())
204         setRootIndex(child);
205     }
206   }
207 }
208
209 void BufferView::joinChannel(const QModelIndex &index) {
210   BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value<int>();
211
212   if(bufferType != BufferInfo::ChannelBuffer)
213     return;
214
215   BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
216
217   Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
218 }
219
220 void BufferView::keyPressEvent(QKeyEvent *event) {
221   if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
222     event->accept();
223     removeSelectedBuffers();
224   }
225   QTreeView::keyPressEvent(event);
226 }
227
228 void BufferView::removeSelectedBuffers(bool permanently) {
229   if(!config())
230     return;
231
232   BufferId bufferId;
233   QSet<BufferId> removedRows;
234   foreach(QModelIndex index, selectionModel()->selectedIndexes()) {
235     if(index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
236       continue;
237
238     bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
239     if(removedRows.contains(bufferId))
240       continue;
241
242     removedRows << bufferId;
243
244     if(permanently)
245       config()->requestRemoveBufferPermanently(bufferId);
246     else
247       config()->requestRemoveBuffer(bufferId);
248   }
249 }
250
251 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
252   QTreeView::rowsInserted(parent, start, end);
253
254   // ensure that newly inserted network nodes are expanded per default
255   if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
256     return;
257
258   if(model()->rowCount(parent) == 1 && parent.data(NetworkModel::ItemActiveRole) == true) {
259     // without updating the parent the expand will have no effect... Qt Bug?
260     update(parent);
261     expand(parent);
262   }
263 }
264
265 void BufferView::on_configChanged() {
266   Q_ASSERT(model());
267
268   // expand all active networks... collapse inactive ones... unless manually changed
269   QModelIndex networkIdx;
270   NetworkId networkId;
271   for(int row = 0; row < model()->rowCount(); row++) {
272     networkIdx = model()->index(row, 0);
273     if(model()->rowCount(networkIdx) ==  0)
274       continue;
275
276     networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
277     if(!networkId.isValid())
278       continue;
279
280     update(networkIdx);
281
282     bool expandNetwork = false;
283     if(_expandedState.contains(networkId))
284       expandNetwork = _expandedState[networkId];
285     else
286       expandNetwork = model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool();
287
288     if(expandNetwork)
289       expand(networkIdx);
290     else
291       collapse(networkIdx);
292   }
293
294   // update selection to current one
295   MappedSelectionModel *mappedSelectionModel = qobject_cast<MappedSelectionModel *>(selectionModel());
296   if(!config() || !mappedSelectionModel)
297     return;
298
299   mappedSelectionModel->mappedSetCurrentIndex(Client::bufferModel()->standardSelectionModel()->currentIndex(), QItemSelectionModel::Current);
300   mappedSelectionModel->mappedSelect(Client::bufferModel()->standardSelectionModel()->selection(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
301 }
302
303 void BufferView::on_collapse(const QModelIndex &index) {
304   storeExpandedState(index.data(NetworkModel::NetworkIdRole).value<NetworkId>(), false);
305 }
306
307 void BufferView::on_expand(const QModelIndex &index) {
308   storeExpandedState(index.data(NetworkModel::NetworkIdRole).value<NetworkId>(), true);
309 }
310
311 void BufferView::storeExpandedState(NetworkId networkId, bool expanded) {
312   _expandedState[networkId] = expanded;
313 }
314
315 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
316   QTreeView::dataChanged(topLeft, bottomRight);
317
318   // determine how many items have been changed and if any of them is a networkitem
319   // which just swichted from active to inactive or vice versa
320   if(topLeft.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
321     return;
322
323   for(int i = topLeft.row(); i <= bottomRight.row(); i++) {
324     QModelIndex networkIdx = topLeft.sibling(i, 0);
325     if(model()->rowCount(networkIdx) == 0)
326       continue;
327
328     bool isActive = networkIdx.data(NetworkModel::ItemActiveRole).toBool();
329 #ifdef SPUTDEV
330     if(isExpanded(networkIdx) != isActive) setExpanded(networkIdx, true);
331 #else
332     if(isExpanded(networkIdx) != isActive) setExpanded(networkIdx, isActive);
333 #endif
334   }
335 }
336
337 void BufferView::toggleHeader(bool checked) {
338   QAction *action = qobject_cast<QAction *>(sender());
339   header()->setSectionHidden((action->property("column")).toInt(), !checked);
340 }
341
342 bool BufferView::checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState) {
343   if(!index.isValid())
344     return false;
345
346   ItemActiveStates isActive = index.data(NetworkModel::ItemActiveRole).toBool()
347     ? ActiveState
348     : InactiveState;
349
350   if(!(isActive & requiredActiveState))
351     return false;
352
353   return true;
354 }
355
356 void BufferView::addItemToMenu(QAction &action, QMenu &menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
357   if(checkRequirements(index, requiredActiveState)) {
358     menu.addAction(&action);
359     action.setVisible(true);
360   } else {
361     action.setVisible(false);
362   }
363 }
364
365 void BufferView::addItemToMenu(QAction &action, QMenu &menu, bool condition) {
366   if(condition) {
367     menu.addAction(&action);
368     action.setVisible(true);
369   } else {
370     action.setVisible(false);
371   }
372 }
373
374
375 void BufferView::addItemToMenu(QMenu &subMenu, QMenu &menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
376   if(checkRequirements(index, requiredActiveState)) {
377     menu.addMenu(&subMenu);
378     subMenu.setVisible(true);
379   } else {
380     subMenu.setVisible(false);
381   }
382 }
383
384 void BufferView::addSeparatorToMenu(QMenu &menu, const QModelIndex &index, ItemActiveStates requiredActiveState) {
385   if(checkRequirements(index, requiredActiveState)) {
386     menu.addSeparator();
387   }
388 }
389
390 QMenu *BufferView::createHideEventsSubMenu(QMenu &menu, BufferId bufferId) {
391   int filter = BufferSettings(bufferId).messageFilter();
392   _hideJoinAction.setChecked(filter & Message::Join);
393   _hidePartAction.setChecked(filter & Message::Part);
394   _hideQuitAction.setChecked(filter & Message::Quit);
395   _hideNickAction.setChecked(filter & Message::Nick);
396   _hideModeAction.setChecked(filter & Message::Mode);
397   _hideDayChangeAction.setChecked(filter & Message::DayChange);
398
399   QMenu *hideEventsMenu = menu.addMenu(tr("Hide Events"));
400   hideEventsMenu->addAction(&_hideJoinAction);
401   hideEventsMenu->addAction(&_hidePartAction);
402   hideEventsMenu->addAction(&_hideQuitAction);
403   hideEventsMenu->addAction(&_hideNickAction);
404   hideEventsMenu->addAction(&_hideModeAction);
405   hideEventsMenu->addAction(&_hideDayChangeAction);
406   return hideEventsMenu;
407 }
408
409 void BufferView::contextMenuEvent(QContextMenuEvent *event) {
410   QModelIndex index = indexAt(event->pos());
411   if(!index.isValid())
412     index = rootIndex();
413   if(!index.isValid())
414     return;
415
416   const Network *network = Client::network(index.data(NetworkModel::NetworkIdRole).value<NetworkId>());
417   Q_CHECK_PTR(network);
418
419   QPixmap connectionStateIcon;
420   if(network) {
421     if(network->connectionState() == Network::Initialized) {
422       connectionStateIcon = SmallIcon("network-connect");
423     } else if(network->connectionState() == Network::Disconnected) {
424       connectionStateIcon = SmallIcon("network-disconnect");
425     } else {
426       connectionStateIcon = SmallIcon("network-wired");  // FIXME network-connecting
427     }
428   }
429
430   QMenu contextMenu(this);
431   NetworkModel::itemType itemType = static_cast<NetworkModel::itemType>(index.data(NetworkModel::ItemTypeRole).toInt());
432
433   switch(itemType) {
434   case NetworkModel::NetworkItemType:
435     showChannelList.setData(index.data(NetworkModel::NetworkIdRole));
436     _disconnectNetAction.setIcon(connectionStateIcon);
437     _connectNetAction.setIcon(connectionStateIcon);
438     addItemToMenu(showChannelList, contextMenu, index, ActiveState);
439     addItemToMenu(_disconnectNetAction, contextMenu, network->connectionState() != Network::Disconnected);
440     addItemToMenu(_connectNetAction, contextMenu, network->connectionState() == Network::Disconnected);
441     addSeparatorToMenu(contextMenu, index, ActiveState);
442     addItemToMenu(_joinChannelAction, contextMenu, index, ActiveState);
443     break;
444   case NetworkModel::BufferItemType:
445     {
446       BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
447       switch(bufferInfo.type()) {
448       case BufferInfo::ChannelBuffer:
449         addItemToMenu(_joinBufferAction, contextMenu, index, InactiveState);
450         addItemToMenu(_partBufferAction, contextMenu, index, ActiveState);
451         addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
452         addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
453         addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState);
454         createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
455         addItemToMenu(_ignoreListAction, contextMenu);
456         break;
457       case BufferInfo::QueryBuffer:
458         addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
459         addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
460         addItemToMenu(_removeBufferAction, contextMenu);
461         createHideEventsSubMenu(contextMenu, bufferInfo.bufferId());
462         break;
463       default:
464         addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config());
465         addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config());
466         break;
467       }
468     }
469     break;
470   default:
471     return;
472   }
473
474   if(contextMenu.actions().isEmpty())
475     return;
476   QAction *result = contextMenu.exec(QCursor::pos());
477
478   // Handle Result
479   if(network && result == &_connectNetAction) {
480     network->requestConnect();
481     return;
482   }
483
484   if(network && result == &_disconnectNetAction) {
485     network->requestDisconnect();
486     return;
487   }
488
489   if(result == &_joinChannelAction) {
490     // FIXME no QInputDialog in Qtopia
491 #ifndef Q_WS_QWS
492     bool ok;
493     QString channelName = QInputDialog::getText(this, tr("Join Channel"), tr("Input channel name:"), QLineEdit::Normal, QString(), &ok);
494     if(ok && !channelName.isEmpty()) {
495       Client::instance()->userInput(BufferInfo::fakeStatusBuffer(index.data(NetworkModel::NetworkIdRole).value<NetworkId>()), QString("/J %1").arg(channelName));
496     }
497 #endif
498     return;
499   }
500
501   if(result == &_joinBufferAction) {
502     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
503     Client::instance()->userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
504     return;
505   }
506
507   if(result == &_partBufferAction) {
508     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
509     Client::instance()->userInput(bufferInfo, QString("/PART"));
510     return;
511   }
512
513   if(result == &_hideBufferTemporarilyAction) {
514     removeSelectedBuffers();
515     return;
516   }
517
518   if(result == &_hideBufferPermanentlyAction) {
519     removeSelectedBuffers(true);
520     return;
521   }
522
523   if(result == &_removeBufferAction) {
524     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
525     int res = QMessageBox::question(this, tr("Remove buffer permanently?"),
526                                     tr("Do you want to delete the buffer \"%1\" permanently? This will delete all related data, including all backlog "
527                                        "data, from the core's database!").arg(bufferInfo.bufferName()),
528                                         QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
529     if(res == QMessageBox::Yes) {
530       Client::removeBuffer(bufferInfo.bufferId());
531     }
532     return;
533   }
534
535   if(result == & _hideJoinAction) {
536     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
537     BufferSettings(bufferId).filterMessage(Message::Join, _hideJoinAction.isChecked());
538     return;
539   }
540   if(result == &_hidePartAction) {
541     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
542     BufferSettings(bufferId).filterMessage(Message::Part, _hidePartAction.isChecked());
543     return;
544   }
545   if(result == &_hideQuitAction) {
546     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
547     BufferSettings(bufferId).filterMessage(Message::Quit, _hideQuitAction.isChecked());
548     return;
549   }
550   if(result == &_hideNickAction) {
551     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
552     BufferSettings(bufferId).filterMessage(Message::Nick, _hideNickAction.isChecked());
553     return;
554   }
555   if(result == &_hideModeAction) {
556     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
557     BufferSettings(bufferId).filterMessage(Message::Mode, _hideModeAction.isChecked());
558     return;
559   }
560   if(result == &_hideDayChangeAction) {
561     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
562     BufferSettings(bufferId).filterMessage(Message::DayChange, _hideDayChangeAction.isChecked());
563     return;
564   }
565 }
566
567 void BufferView::wheelEvent(QWheelEvent* event) {
568   if(UiSettings().value("MouseWheelChangesBuffers", QVariant(true)).toBool() == (bool)(event->modifiers() & Qt::AltModifier))
569     return QTreeView::wheelEvent(event);
570
571   int rowDelta = ( event->delta() > 0 ) ? -1 : 1;
572   QModelIndex currentIndex = selectionModel()->currentIndex();
573   QModelIndex resultingIndex;
574   if( model()->hasIndex(  currentIndex.row() + rowDelta, currentIndex.column(), currentIndex.parent() ) )
575     {
576       resultingIndex = currentIndex.sibling( currentIndex.row() + rowDelta, currentIndex.column() );
577     }
578     else //if we scroll into a the parent node...
579       {
580         QModelIndex parent = currentIndex.parent();
581         QModelIndex aunt = parent.sibling( parent.row() + rowDelta, parent.column() );
582         if( rowDelta == -1 )
583           resultingIndex = aunt.child( model()->rowCount( aunt ) - 1, 0 );
584         else
585           resultingIndex = aunt.child( 0, 0 );
586         if( !resultingIndex.isValid() )
587           return;
588       }
589   selectionModel()->setCurrentIndex( resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
590   selectionModel()->select( resultingIndex, QItemSelectionModel::ClearAndSelect );
591
592 }
593
594
595 QSize BufferView::sizeHint() const {
596   return QTreeView::sizeHint();
597
598   if(!model())
599     return QTreeView::sizeHint();
600
601   if(model()->rowCount() == 0)
602     return QSize(120, 50);
603
604   int columnSize = 0;
605   for(int i = 0; i < model()->columnCount(); i++) {
606     if(!isColumnHidden(i))
607       columnSize += sizeHintForColumn(i);
608   }
609   return QSize(columnSize, 50);
610 }
611
612 // ==============================
613 //  BufferView Dock
614 // ==============================
615 BufferViewDock::BufferViewDock(BufferViewConfig *config, QWidget *parent)
616   : QDockWidget(config->bufferViewName(), parent)
617 {
618   setObjectName("BufferViewDock-" + QString::number(config->bufferViewId()));
619   toggleViewAction()->setData(config->bufferViewId());
620   setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
621   connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(bufferViewRenamed(const QString &)));
622 }
623
624 BufferViewDock::BufferViewDock(QWidget *parent)
625   : QDockWidget(tr("All Buffers"), parent)
626 {
627   setObjectName("BufferViewDock--1");
628   toggleViewAction()->setData((int)-1);
629   setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
630 }
631
632 void BufferViewDock::bufferViewRenamed(const QString &newName) {
633   setWindowTitle(newName);
634   toggleViewAction()->setText(newName);
635 }