activated()->triggered()
[quassel.git] / gui / networkview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
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) any later version.                                   *
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 "global.h"
22 #include "networkview.h"
23
24 NetworkViewWidget::NetworkViewWidget(QWidget *parent) : QWidget(parent) {
25   ui.setupUi(this);
26
27 }
28
29 QSize NetworkViewWidget::sizeHint() const {
30   return QSize(150,100);
31
32 }
33
34 /**************************************************************************/
35
36 NetworkView::NetworkView(QString net, QWidget *parent) : network(net), QDockWidget(parent) {
37   if(!net.isEmpty()) setWindowTitle(net);
38   else setWindowTitle(tr("All Buffers"));
39   setWidget(new NetworkViewWidget(this));
40   tree = qobject_cast<NetworkViewWidget*>(widget())->tree();
41   tree->setSortingEnabled(false);
42   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(itemClicked(QTreeWidgetItem*)));
43 }
44
45 void NetworkView::buffersUpdated(BufferHash buffers) {
46   tree->clear(); items.clear();
47   if(network.isEmpty()) {
48     tree->setHeaderLabel(tr("Networks"));
49     foreach(QString net, buffers.keys()) {
50       QTreeWidgetItem *netItem = new QTreeWidgetItem(QStringList(net));
51       foreach(QString buf, buffers[net].keys()) {
52         Buffer *b = buffers[net][buf];
53         QStringList label;
54         if(buf.isEmpty()) label << tr("Status");
55         else label << buf;
56         QTreeWidgetItem *item = new QTreeWidgetItem(netItem, label);
57         items[net][buf] = item;
58         VarMap d;
59         d["Network"] = net;
60         d["Buffer"] = buf;
61         item->setData(0, Qt::UserRole, d);
62         if(!b->isActive()) {
63           item->setForeground(0, QColor("grey"));
64         }
65       }
66       VarMap d;
67       d["Network"] = net; d["Buffer"] = "";
68       netItem->setData(0, Qt::UserRole, d);
69       netItem->setFlags(netItem->flags() & ~Qt::ItemIsSelectable);
70       tree->addTopLevelItem(netItem);
71       netItem->setExpanded(true);
72     }
73     if(items[currentNetwork][currentBuffer]) items[currentNetwork][currentBuffer]->setSelected(true);
74   }
75 }
76
77 void NetworkView::itemClicked(QTreeWidgetItem *item) {
78   if(network.isEmpty()) {
79     VarMap d = item->data(0, Qt::UserRole).toMap();
80     QString net = d["Network"].toString(); QString buf = d["Buffer"].toString();
81     if(!net.isEmpty()) {
82       emit bufferSelected(net, buf);
83       currentNetwork = net; currentBuffer = buf;
84     }
85   }
86 }
87
88 void NetworkView::selectBuffer(QString net, QString buf) {
89   if(items[net][buf]) items[net][buf]->setSelected(true);
90   currentNetwork = net; currentBuffer = buf;
91 }