1 /***************************************************************************
2 * Copyright (C) 2005-09 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 "nickviewfilter.h"
23 #include "buffersettings.h"
24 #include "iconloader.h"
25 #include "networkmodel.h"
27 /******************************************************************************************
29 ******************************************************************************************/
30 NickViewFilter::NickViewFilter(const BufferId &bufferId, NetworkModel *parent)
31 : QSortFilterProxyModel(parent),
33 _userOnlineIcon(SmallIcon("im-user")),
34 _userAwayIcon(SmallIcon("im-user-away")),
35 _categoryOpIcon(SmallIcon("irc-operator")),
36 _categoryVoiceIcon(SmallIcon("irc-voice")),
37 _opIconLimit(UserCategoryItem::categoryFromModes("o")),
38 _voiceIconLimit(UserCategoryItem::categoryFromModes("v"))
40 setSourceModel(parent);
41 setDynamicSortFilter(true);
42 setSortCaseSensitivity(Qt::CaseInsensitive);
43 setSortRole(TreeModel::SortRole);
45 BufferSettings bufferSettings;
46 _showUserStateIcons = bufferSettings.showUserStateIcons();
47 bufferSettings.notify("ShowUserStateIcons", this, SLOT(showUserStateIconsChanged()));
50 bool NickViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
51 // root node, networkindexes, the bufferindex of the buffer this filter is active for and it's childs are accepted
52 if(!source_parent.isValid())
55 QModelIndex source_child = source_parent.child(source_row, 0);
56 return (sourceModel()->data(source_child, NetworkModel::BufferIdRole).value<BufferId>() == _bufferId);
59 QVariant NickViewFilter::data(const QModelIndex &index, int role) const {
61 case Qt::DecorationRole:
64 return QSortFilterProxyModel::data(index, role);
68 QVariant NickViewFilter::icon(const QModelIndex &index) const {
69 if(!_showUserStateIcons)
72 if(index.column() != 0)
75 QModelIndex source_index = mapToSource(index);
76 NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt();
78 case NetworkModel::UserCategoryItemType:
80 int categoryId = sourceModel()->data(source_index, TreeModel::SortRole).toInt();
81 if(categoryId <= _opIconLimit)
82 return _categoryOpIcon;
83 if(categoryId <= _voiceIconLimit)
84 return _categoryVoiceIcon;
85 return _userOnlineIcon;
87 case NetworkModel::IrcUserItemType:
88 if(sourceModel()->data(source_index, NetworkModel::ItemActiveRole).toBool())
89 return _userOnlineIcon;
98 void NickViewFilter::showUserStateIconsChanged() {
99 BufferSettings bufferSettings;
100 _showUserStateIcons = bufferSettings.showUserStateIcons();