1 /***************************************************************************
2 * Copyright (C) 2005/06 by The Quassel Team *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
22 #include "networkview.h"
24 NetworkViewWidget::NetworkViewWidget(QWidget *parent) : QWidget(parent) {
29 QSize NetworkViewWidget::sizeHint() const {
30 return QSize(150,100);
34 /**************************************************************************/
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*)));
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];
54 if(buf.isEmpty()) label << tr("Status");
56 QTreeWidgetItem *item = new QTreeWidgetItem(netItem, label);
57 items[net][buf] = item;
61 item->setData(0, Qt::UserRole, d);
63 item->setForeground(0, QColor("grey"));
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);
73 if(items[currentNetwork][currentBuffer]) items[currentNetwork][currentBuffer]->setSelected(true);
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();
82 emit bufferSelected(net, buf);
83 currentNetwork = net; currentBuffer = buf;
88 void NetworkView::selectBuffer(QString net, QString buf) {
89 if(items[net][buf]) items[net][buf]->setSelected(true);
90 currentNetwork = net; currentBuffer = buf;