1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
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) version 3. *
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 ***************************************************************************/
21 #include "channellistdlg.h"
24 #include "clientirclisthelper.h"
26 #include <QHeaderView>
28 ChannelListDlg::ChannelListDlg(QWidget *parent)
34 _sortFilter.setSourceModel(&_ircListModel);
35 _sortFilter.setFilterCaseSensitivity(Qt::CaseInsensitive);
36 _sortFilter.setFilterKeyColumn(-1);
39 ui.channelListView->setSelectionBehavior(QAbstractItemView::SelectRows);
40 ui.channelListView->setSelectionMode(QAbstractItemView::SingleSelection);
41 ui.channelListView->setAlternatingRowColors(true);
42 ui.channelListView->setTabKeyNavigation(false);
43 ui.channelListView->setModel(&_sortFilter);
44 ui.channelListView->setSortingEnabled(true);
45 ui.channelListView->verticalHeader()->hide();
46 ui.channelListView->horizontalHeader()->setStretchLastSection(true);
48 ui.searchChannelsButton->setAutoDefault(false);
50 connect(ui.searchChannelsButton, SIGNAL(clicked()), this, SLOT(requestSearch()));
51 connect(ui.channelNameLineEdit, SIGNAL(returnPressed()), this, SLOT(requestSearch()));
52 connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), &_sortFilter, SLOT(setFilterFixedString(QString)));
53 connect(Client::ircListHelper(), SIGNAL(channelListReceived(const NetworkId &, const QStringList &, QList<IrcListHelper::ChannelDescription>)),
54 this, SLOT(receiveChannelList(NetworkId , QStringList, QList<IrcListHelper::ChannelDescription>)));
55 connect(Client::ircListHelper(), SIGNAL(finishedListReported(const NetworkId &)), this, SLOT(reportFinishedList()));
56 connect(ui.channelListView, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
59 showFilterLine(false);
63 void ChannelListDlg::setNetwork(NetworkId netId) {
68 _ircListModel.setChannelList();
69 showFilterLine(false);
72 void ChannelListDlg::requestSearch() {
73 _listFinished = false;
75 QStringList channelFilters;
76 channelFilters << ui.channelNameLineEdit->text().trimmed();
77 Client::ircListHelper()->requestChannelList(_netId, channelFilters);
80 void ChannelListDlg::receiveChannelList(const NetworkId &netId, const QStringList &channelFilters, const QList<IrcListHelper::ChannelDescription> &channelList) {
82 Q_UNUSED(channelFilters)
84 showFilterLine(!channelList.isEmpty());
85 _ircListModel.setChannelList(channelList);
86 enableQuery(_listFinished);
89 void ChannelListDlg::showFilterLine(bool show) {
90 ui.line->setVisible(show);
91 ui.filterLabel->setVisible(show);
92 ui.filterLineEdit->setVisible(show);
95 void ChannelListDlg::enableQuery(bool enable) {
96 ui.channelNameLineEdit->setEnabled(enable);
97 ui.searchChannelsButton->setEnabled(enable);
100 void ChannelListDlg::reportFinishedList() {
101 _listFinished = true;
105 void ChannelListDlg::joinChannel(const QModelIndex &index) {
106 Client::instance()->userInput(BufferInfo::fakeStatusBuffer(_netId), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));