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"
23 #include <QHeaderView>
24 #include <QHBoxLayout>
25 #include <QSpacerItem>
28 #include "clientirclisthelper.h"
30 #include "iconloader.h"
32 ChannelListDlg::ChannelListDlg(QWidget *parent)
40 _sortFilter.setSourceModel(&_ircListModel);
41 _sortFilter.setFilterCaseSensitivity(Qt::CaseInsensitive);
42 _sortFilter.setFilterKeyColumn(-1);
45 ui.advancedModeLabel->setPixmap(BarIcon("edit-rename"));
47 ui.channelListView->setSelectionBehavior(QAbstractItemView::SelectRows);
48 ui.channelListView->setSelectionMode(QAbstractItemView::SingleSelection);
49 ui.channelListView->setAlternatingRowColors(true);
50 ui.channelListView->setTabKeyNavigation(false);
51 ui.channelListView->setModel(&_sortFilter);
52 ui.channelListView->setSortingEnabled(true);
53 ui.channelListView->verticalHeader()->hide();
54 ui.channelListView->horizontalHeader()->setStretchLastSection(true);
56 ui.searchChannelsButton->setAutoDefault(false);
58 setWindowIcon(Icon("format-list-unordered"));
60 connect(ui.advancedModeLabel, SIGNAL(clicked()), this, SLOT(toggleMode()));
61 connect(ui.searchChannelsButton, SIGNAL(clicked()), this, SLOT(requestSearch()));
62 connect(ui.channelNameLineEdit, SIGNAL(returnPressed()), this, SLOT(requestSearch()));
63 connect(ui.filterLineEdit, SIGNAL(textChanged(QString)), &_sortFilter, SLOT(setFilterFixedString(QString)));
64 connect(Client::ircListHelper(), SIGNAL(channelListReceived(const NetworkId &, const QStringList &, QList<IrcListHelper::ChannelDescription>)),
65 this, SLOT(receiveChannelList(NetworkId , QStringList, QList<IrcListHelper::ChannelDescription>)));
66 connect(Client::ircListHelper(), SIGNAL(finishedListReported(const NetworkId &)), this, SLOT(reportFinishedList()));
67 connect(Client::ircListHelper(), SIGNAL(errorReported(const QString &)), this, SLOT(showError(const QString &)));
68 connect(ui.channelListView, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
70 setAdvancedMode(false);
72 showFilterLine(false);
76 void ChannelListDlg::setNetwork(NetworkId netId) {
81 _ircListModel.setChannelList();
82 showFilterLine(false);
85 void ChannelListDlg::requestSearch() {
86 _listFinished = false;
89 QStringList channelFilters;
90 channelFilters << ui.channelNameLineEdit->text().trimmed();
91 Client::ircListHelper()->requestChannelList(_netId, channelFilters);
94 void ChannelListDlg::receiveChannelList(const NetworkId &netId, const QStringList &channelFilters, const QList<IrcListHelper::ChannelDescription> &channelList) {
95 Q_UNUSED(channelFilters)
99 showFilterLine(!channelList.isEmpty());
100 _ircListModel.setChannelList(channelList);
101 enableQuery(_listFinished);
104 void ChannelListDlg::showFilterLine(bool show) {
105 ui.line->setVisible(show);
106 ui.filterLabel->setVisible(show);
107 ui.filterLineEdit->setVisible(show);
110 void ChannelListDlg::enableQuery(bool enable) {
111 ui.channelNameLineEdit->setEnabled(enable);
112 ui.searchChannelsButton->setEnabled(enable);
115 void ChannelListDlg::setAdvancedMode(bool advanced) {
116 _advancedMode = advanced;
119 if(_simpleModeSpacer) {
120 ui.searchLayout->removeItem(_simpleModeSpacer);
121 delete _simpleModeSpacer;
122 _simpleModeSpacer = 0;
124 ui.advancedModeLabel->setPixmap(BarIcon("edit-clear-locationbar-rtl"));
126 if(!_simpleModeSpacer) {
127 _simpleModeSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
128 ui.searchLayout->insertSpacerItem(0, _simpleModeSpacer);
130 ui.advancedModeLabel->setPixmap(BarIcon("edit-rename"));
133 ui.channelNameLineEdit->clear();
134 ui.channelNameLineEdit->setVisible(advanced);
135 ui.searchPatternLabel->setVisible(advanced);
138 void ChannelListDlg::showErrors(bool show) {
140 ui.errorTextEdit->clear();
142 ui.errorLabel->setVisible(show);
143 ui.errorTextEdit->setVisible(show);
147 void ChannelListDlg::reportFinishedList() {
148 _listFinished = true;
151 void ChannelListDlg::showError(const QString &error) {
153 ui.errorTextEdit->moveCursor(QTextCursor::End);
154 ui.errorTextEdit->insertPlainText(error + "\n");
157 void ChannelListDlg::joinChannel(const QModelIndex &index) {
158 Client::instance()->userInput(BufferInfo::fakeStatusBuffer(_netId), QString("/JOIN %1").arg(index.sibling(index.row(), 0).data().toString()));