~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/libkipi/libkipi/configwidget_p.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-09-27 21:41:30 UTC
  • mfrom: (1.2.43)
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20120927214130-i8v3ufr21nesp29i
Tags: 4:3.0.0~beta1a-1
* New upstream release

* Fix "wrongly conflicts phonon-backend-vlc" dropped (Closes: #688142)
* debian/watch include download.kde.org

* digikam 3.0.0 uses features from unreleased kdegraphics >=4.10 & ships 
a private version of the kdegraphics libs - this is not the Debian way :-(
* Unsatisfactory Conflicts: libkipi8, libkexiv2-10, libkdcraw20, libksane0
* Suspend digikam-dbg >130Mb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** ===========================================================
 
2
 * @file
 
3
 *
 
4
 * This file is a part of digiKam project
 
5
 * <a href="http://www.digikam.org">http://www.digikam.org</a>
 
6
 *
 
7
 * @date   2012-08-06
 
8
 * @brief  private implementation of plugin config widget
 
9
 *
 
10
 * @author Copyright (C) 2004-2012 by Gilles Caulier
 
11
 *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
 
12
 * @author Copyright (C) 2012 by Victor Dodon
 
13
 *         <a href="mailto:dodonvictor at gmail dot com">dodonvictor at gmail dot com</a>
 
14
 *
 
15
 * This program is free software; you can redistribute it
 
16
 * and/or modify it under the terms of the GNU General
 
17
 * Public License as published by the Free Software Foundation;
 
18
 * either version 2, or (at your option)
 
19
 * any later version.
 
20
 *
 
21
 * This program is distributed in the hope that it will be useful,
 
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
24
 * GNU General Public License for more details.
 
25
 *
 
26
 * ============================================================ */
 
27
 
 
28
#include "configwidget_p.moc"
 
29
 
 
30
// Qt include
 
31
 
 
32
#include <QList>
 
33
#include <QHeaderView>
 
34
 
 
35
// KDE includes
 
36
 
 
37
#include <ksharedconfig.h>
 
38
#include <kconfiggroup.h>
 
39
#include <kconfig.h>
 
40
#include <kaction.h>
 
41
#include <kdebug.h>
 
42
 
 
43
namespace KIPI
 
44
{
 
45
 
 
46
PluginCheckBox::PluginCheckBox(PluginLoader::Info* const info, QTreeWidget* const parent)
 
47
    : QTreeWidgetItem(parent),
 
48
      m_info(info)
 
49
{
 
50
    setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
 
51
    setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
 
52
    setDisabled(false);
 
53
 
 
54
    // Name + Icon + Selector
 
55
    setText(0, m_info->name());
 
56
    setIcon(0, m_info->icon());
 
57
    setCheckState(0, m_info->shouldLoad() ? Qt::Checked : Qt::Unchecked);
 
58
 
 
59
    // Categories
 
60
    QStringList list = m_info->pluginCategories();
 
61
    list.removeDuplicates();
 
62
    list.sort();
 
63
    setText(1, list.join(", "));
 
64
 
 
65
    // Description
 
66
    setText(2, m_info->comment());
 
67
 
 
68
    // Author
 
69
    setText(3, m_info->author().section(',', 0, 0));
 
70
}
 
71
 
 
72
PluginCheckBox::~PluginCheckBox()
 
73
{
 
74
}
 
75
 
 
76
bool PluginCheckBox::contains(const QString& txt, Qt::CaseSensitivity cs) const
 
77
{
 
78
    return (text(0).contains(txt, cs) ||
 
79
            text(1).contains(txt, cs) ||
 
80
            text(2).contains(txt, cs) ||
 
81
            text(3).contains(txt, cs));
 
82
}
 
83
 
 
84
// ---------------------------------------------------------------------
 
85
 
 
86
class PluginListView::Private
 
87
{
 
88
public:
 
89
 
 
90
    Private()
 
91
    {
 
92
    };
 
93
 
 
94
    QString                filter;
 
95
    QList<PluginCheckBox*> boxes;
 
96
};
 
97
 
 
98
PluginListView::PluginListView(QWidget* const parent)
 
99
    : QTreeWidget(parent),
 
100
      d(new Private)
 
101
{
 
102
    setRootIsDecorated(false);
 
103
    setSelectionMode(QAbstractItemView::SingleSelection);
 
104
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
105
    setAllColumnsShowFocus(true);
 
106
    setSortingEnabled(true);
 
107
    setColumnCount(4);
 
108
 
 
109
    QStringList labels;
 
110
    labels.append(i18n("Name"));
 
111
    labels.append(i18n("Categories"));
 
112
    labels.append(i18n("Description"));
 
113
    labels.append(i18n("Author"));
 
114
 
 
115
    setHeaderLabels(labels);
 
116
    header()->setResizeMode(0, QHeaderView::ResizeToContents);
 
117
    header()->setResizeMode(1, QHeaderView::ResizeToContents);
 
118
    header()->setResizeMode(2, QHeaderView::Stretch);
 
119
    header()->setResizeMode(3, QHeaderView::Interactive);
 
120
    header()->setSortIndicatorShown(true);
 
121
 
 
122
    setAutoFillBackground(false);
 
123
    viewport()->setAutoFillBackground(false);
 
124
 
 
125
    PluginLoader* const loader = PluginLoader::instance();
 
126
 
 
127
    if (loader)
 
128
    {
 
129
        foreach(PluginLoader::Info* const info, loader->pluginList())
 
130
        {
 
131
            if (info)
 
132
            {
 
133
                d->boxes.append(new PluginCheckBox(info, this));
 
134
            }
 
135
        }
 
136
    }
 
137
 
 
138
    // Sort items by plugin names.
 
139
    sortItems(0, Qt::AscendingOrder);
 
140
}
 
141
 
 
142
PluginListView::~PluginListView()
 
143
{
 
144
    delete d;
 
145
}
 
146
 
 
147
void PluginListView::slotApply()
 
148
{
 
149
    KSharedConfigPtr config = KGlobal::config();
 
150
    KConfigGroup group      = config->group(QString::fromLatin1("KIPI/EnabledPlugin"));
 
151
 
 
152
    foreach (PluginCheckBox* const item, d->boxes)
 
153
    {
 
154
        bool orig = item->m_info->shouldLoad();
 
155
        bool load = (item->checkState(0) == Qt::Checked);
 
156
 
 
157
        if (orig != load)
 
158
        {
 
159
            group.writeEntry(item->m_info->name(), load);
 
160
            item->m_info->setShouldLoad(load);
 
161
 
 
162
            // Bugfix #289779 - Plugins are not really freed / unplugged when disabled in the kipi setup dialog, always call reload()
 
163
            // to reload plugins properly when the replug() signal is send.
 
164
            item->m_info->reload();
 
165
        }
 
166
    }
 
167
}
 
168
 
 
169
void PluginListView::slotCheckAll()
 
170
{
 
171
    foreach (PluginCheckBox* const item, d->boxes)
 
172
    {
 
173
        item->setCheckState(0, Qt::Checked);
 
174
    }
 
175
}
 
176
 
 
177
void PluginListView::slotClear()
 
178
{
 
179
    foreach (PluginCheckBox* const item, d->boxes)
 
180
    {
 
181
        item->setCheckState(0, Qt::Unchecked);
 
182
    }
 
183
}
 
184
 
 
185
int PluginListView::count() const
 
186
{
 
187
    return d->boxes.count();
 
188
}
 
189
 
 
190
int PluginListView::actived() const
 
191
{
 
192
    int actived = 0;
 
193
 
 
194
    foreach (PluginCheckBox* const item, d->boxes)
 
195
    {
 
196
        if (item->checkState(0) == Qt::Checked)
 
197
            actived++;
 
198
    }
 
199
 
 
200
    return actived;
 
201
}
 
202
 
 
203
int PluginListView::visible() const
 
204
{
 
205
    int visible = 0;
 
206
 
 
207
    foreach (PluginCheckBox* const item, d->boxes)
 
208
    {
 
209
        if (!item->isHidden())
 
210
            visible++;
 
211
    }
 
212
 
 
213
    return visible;
 
214
}
 
215
 
 
216
void PluginListView::setFilter(const QString& filter, Qt::CaseSensitivity cs)
 
217
{
 
218
    d->filter  = filter;
 
219
    bool query = false;
 
220
 
 
221
    foreach (PluginCheckBox* const item, d->boxes)
 
222
    {
 
223
        if (item->contains(filter, cs))
 
224
        {
 
225
            query = true;
 
226
            item->setHidden(false);
 
227
        }
 
228
        else
 
229
        {
 
230
            item->setHidden(true);
 
231
        }
 
232
    }
 
233
 
 
234
    emit signalSearchResult(query);
 
235
}
 
236
 
 
237
QString PluginListView::filter() const
 
238
{
 
239
    return d->filter;
 
240
}
 
241
 
 
242
} // namespace KIPI