1/**
2 * This file is part of the KDE project
3 * Copyright (C) 2007, 2006 Rafael Fernández López <ereslibre@kde.org>
4 * Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License version 2 as published by the Free Software Foundation.
9 *
10 * This library 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 GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef KPLUGINSELECTOR_P_H
22#define KPLUGINSELECTOR_P_H
23
24#include <QtCore/QAbstractListModel>
25#include <QtGui/QAbstractItemDelegate>
26
27#include <kconfiggroup.h>
28#include <kplugininfo.h>
29#include <kwidgetitemdelegate.h>
30#include <kcategorizedsortfilterproxymodel.h>
31
32class QLabel;
33class QCheckBox;
34class QPushButton;
35class QAbstractItemView;
36
37class KLineEdit;
38class KCategorizedView;
39class KCModuleProxy;
40class KCategoryDrawer;
41
42class PluginEntry;
43
44class KPluginSelector::Private
45 : public QObject
46{
47 Q_OBJECT
48
49public:
50 enum ExtraRoles
51 {
52 PluginEntryRole = 0x09386561,
53 ServicesCountRole = 0x1422E2AA,
54 NameRole = 0x0CBBBB00,
55 CommentRole = 0x19FC6DE2,
56 AuthorRole = 0x30861E10,
57 EmailRole = 0x02BE3775,
58 WebsiteRole = 0x13095A34,
59 VersionRole = 0x0A0CB450,
60 LicenseRole = 0x001F308A,
61 DependenciesRole = 0x04CAB650,
62 IsCheckableRole = 0x0AC2AFF8
63 };
64
65 Private(KPluginSelector *parent);
66 ~Private();
67
68 void updateDependencies(PluginEntry *pluginEntry, bool added);
69 int dependantLayoutValue(int value, int width, int totalWidth) const;
70
71public:
72 class PluginModel;
73 class ProxyModel;
74 class PluginDelegate;
75 class DependenciesWidget;
76 KPluginSelector *parent;
77 KLineEdit *lineEdit;
78 KCategorizedView *listView;
79 KCategoryDrawer *categoryDrawer;
80 PluginModel *pluginModel;
81 ProxyModel *proxyModel;
82 PluginDelegate *pluginDelegate;
83 DependenciesWidget *dependenciesWidget;
84 bool showIcons;
85};
86
87class PluginEntry
88{
89public:
90 QString category;
91 KPluginInfo pluginInfo;
92 bool checked;
93 bool manuallyAdded;
94 KConfigGroup cfgGroup;
95 KPluginSelector::PluginLoadMethod pluginLoadMethod;
96 bool isCheckable;
97
98 bool operator==(const PluginEntry &pe) const
99 {
100 return pluginInfo.entryPath() == pe.pluginInfo.entryPath();
101 }
102};
103
104Q_DECLARE_METATYPE(PluginEntry*)
105
106
107/**
108 * This widget will inform the user about changes that happened automatically
109 * due to plugin dependencies.
110 */
111class KPluginSelector::Private::DependenciesWidget
112 : public QWidget
113{
114 Q_OBJECT
115
116public:
117 DependenciesWidget(QWidget *parent = 0);
118 ~DependenciesWidget();
119
120 void addDependency(const QString &dependency, const QString &pluginCausant, bool added);
121 void userOverrideDependency(const QString &dependency);
122
123 void clearDependencies();
124
125private Q_SLOTS:
126 void showDependencyDetails();
127
128private:
129 struct FurtherInfo
130 {
131 bool added;
132 QString pluginCausant;
133 };
134
135 void updateDetails();
136
137 QLabel *details;
138 QMap<QString, struct FurtherInfo> dependencyMap;
139 int addedByDependencies;
140 int removedByDependencies;
141};
142
143
144class KPluginSelector::Private::PluginModel
145 : public QAbstractListModel
146{
147public:
148 PluginModel(KPluginSelector::Private *pluginSelector_d, QObject *parent = 0);
149 ~PluginModel();
150
151 void addPlugins(const QList<KPluginInfo> &pluginList, const QString &categoryName, const QString &categoryKey, const KConfigGroup &cfgGroup, PluginLoadMethod pluginLoadMethod = ReadConfigFile, bool manuallyAdded = false);
152 QList<KService::Ptr> pluginServices(const QModelIndex &index) const;
153
154 virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
155 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
156 virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
157 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
158
159public:
160 QList<PluginEntry> pluginEntryList;
161
162private:
163 KPluginSelector::Private *pluginSelector_d;
164};
165
166class KPluginSelector::Private::ProxyModel
167 : public KCategorizedSortFilterProxyModel
168{
169public:
170 ProxyModel(KPluginSelector::Private *pluginSelector_d, QObject *parent = 0);
171 ~ProxyModel();
172
173protected:
174 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
175 virtual bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const;
176
177private:
178 KPluginSelector::Private *pluginSelector_d;
179};
180
181
182class KPluginSelector::Private::PluginDelegate
183 : public KWidgetItemDelegate
184{
185 Q_OBJECT
186
187public:
188 PluginDelegate(KPluginSelector::Private *pluginSelector_d, QObject *parent = 0);
189 ~PluginDelegate();
190
191 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
192 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
193
194Q_SIGNALS:
195 void changed(bool hasChanged);
196 void configCommitted(const QByteArray &componentName);
197
198protected:
199 virtual QList<QWidget*> createItemWidgets() const;
200 virtual void updateItemWidgets(const QList<QWidget*> widgets,
201 const QStyleOptionViewItem &option,
202 const QPersistentModelIndex &index) const;
203
204private Q_SLOTS:
205 void slotStateChanged(bool state);
206 void emitChanged();
207 void slotAboutClicked();
208 void slotConfigureClicked();
209 void slotDefaultClicked();
210
211private:
212 QFont titleFont(const QFont &baseFont) const;
213
214 QCheckBox *checkBox;
215 QPushButton *pushButton;
216 QList<KCModuleProxy*> moduleProxyList;
217
218 KPluginSelector::Private *pluginSelector_d;
219};
220
221#endif // KPLUGINSELECTOR_P_H
222