File indexing completed on 2025-01-19 03:55:36
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-02-06 0007 * Description : Config panel for generic dplugins. 0008 * 0009 * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dpluginsetup.h" 0016 0017 // Qt includes 0018 0019 #include <QApplication> 0020 #include <QPushButton> 0021 #include <QGridLayout> 0022 #include <QLabel> 0023 #include <QFontMetrics> 0024 #include <QHBoxLayout> 0025 #include <QStandardPaths> 0026 #include <QStyle> 0027 0028 // KDE includes 0029 0030 #include <klocalizedstring.h> 0031 0032 // Local includes 0033 0034 #include "dpluginconfview.h" 0035 #include "dpluginaboutdlg.h" 0036 0037 namespace Digikam 0038 { 0039 0040 class Q_DECL_HIDDEN DPluginSetup::Private 0041 { 0042 public: 0043 0044 explicit Private() 0045 : pluginsNumber (nullptr), 0046 pluginsNumberActivated(nullptr), 0047 checkAllBtn (nullptr), 0048 clearBtn (nullptr), 0049 grid (nullptr), 0050 hbox (nullptr), 0051 pluginFilter (nullptr), 0052 pluginsList (nullptr) 0053 { 0054 } 0055 0056 QLabel* pluginsNumber; 0057 QLabel* pluginsNumberActivated; 0058 0059 QPushButton* checkAllBtn; 0060 QPushButton* clearBtn; 0061 0062 QGridLayout* grid; 0063 QWidget* hbox; 0064 0065 SearchTextBar* pluginFilter; 0066 DPluginConfView* pluginsList; 0067 }; 0068 0069 DPluginSetup::DPluginSetup(QWidget* const parent) 0070 : QWidget(parent), 0071 d (new Private) 0072 { 0073 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0074 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0075 0076 d->grid = new QGridLayout(this); 0077 d->pluginFilter = new SearchTextBar(this, QLatin1String("PluginsSearchBar")); 0078 d->pluginsNumber = new QLabel(this); 0079 d->pluginsNumberActivated = new QLabel(this); 0080 d->checkAllBtn = new QPushButton(i18nc("@action: search bar", "Check All"), this); 0081 d->clearBtn = new QPushButton(i18nc("@action: search bar", "Clear"), this); 0082 0083 d->grid->addWidget(d->pluginFilter, 0, 0, 1, 1); 0084 d->grid->addWidget(d->pluginsNumber, 0, 1, 1, 1); 0085 d->grid->addWidget(d->pluginsNumberActivated, 0, 2, 1, 1); 0086 d->grid->addWidget(d->checkAllBtn, 0, 4, 1, 1); 0087 d->grid->addWidget(d->clearBtn, 0, 5, 1, 1); 0088 d->grid->setColumnStretch(3, 10); 0089 d->grid->setRowStretch(1, 10); 0090 d->grid->setContentsMargins(spacing, spacing, spacing, spacing); 0091 d->grid->setSpacing(spacing); 0092 0093 // -------------------------------------------------------- 0094 0095 connect(d->checkAllBtn, SIGNAL(clicked()), 0096 this, SLOT(slotCheckAll())); 0097 0098 connect(d->clearBtn, SIGNAL(clicked()), 0099 this, SLOT(slotClearList())); 0100 0101 connect(d->pluginFilter, SIGNAL(signalSearchTextSettings(SearchTextSettings)), 0102 this, SLOT(slotSearchTextChanged(SearchTextSettings))); 0103 } 0104 0105 DPluginSetup::~DPluginSetup() 0106 { 0107 delete d; 0108 } 0109 0110 void DPluginSetup::setPluginConfView(DPluginConfView* const view) 0111 { 0112 d->pluginsList = view; 0113 d->grid->addWidget(d->pluginsList, 1, 0, 1, 6); 0114 0115 connect(d->pluginsList, SIGNAL(itemClicked(QTreeWidgetItem*,int)), 0116 this, SLOT(slotItemClicked())); 0117 0118 connect(d->pluginsList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), 0119 this, SLOT(slotAboutPlugin(QTreeWidgetItem*,int))); 0120 0121 connect(d->pluginsList, SIGNAL(signalSearchResult(int)), 0122 this, SLOT(slotSearchResult(int))); 0123 0124 updateInfo(); 0125 } 0126 0127 void DPluginSetup::applySettings() 0128 { 0129 d->pluginsList->apply(); 0130 } 0131 0132 void DPluginSetup::slotAboutPlugin(QTreeWidgetItem* item, int) 0133 { 0134 if (!item) 0135 { 0136 return; 0137 } 0138 0139 QPointer<DPluginAboutDlg> dlg = new DPluginAboutDlg(d->pluginsList->plugin(item)); 0140 dlg->exec(); 0141 delete dlg; 0142 } 0143 0144 void DPluginSetup::slotSearchTextChanged(const SearchTextSettings& settings) 0145 { 0146 d->pluginsList->setFilter(settings.text, settings.caseSensitive); 0147 } 0148 0149 void DPluginSetup::updateInfo() 0150 { 0151 bool b = (d->pluginsList->itemsWithVisiblyProperty() != 0); 0152 d->pluginsNumberActivated->setVisible(b); 0153 d->checkAllBtn->setVisible(b); 0154 d->clearBtn->setVisible(b); 0155 0156 if (d->pluginFilter->text().isEmpty()) 0157 { 0158 // List is not filtered 0159 0160 int cnt = d->pluginsList->count(); 0161 0162 if (cnt > 0) 0163 { 0164 d->pluginsNumber->setText(i18ncp("@info", "1 plugin installed", "%1 plugins installed", cnt)); 0165 } 0166 else 0167 { 0168 d->pluginsNumber->setText(i18nc("@info", "No plugin installed")); 0169 } 0170 0171 int act = d->pluginsList->actived(); 0172 0173 if (act > 0) 0174 { 0175 d->pluginsNumberActivated->setText(i18ncp("@info: %1: number of plugins activated", "(%1 activated)", "(%1 activated)", act)); 0176 } 0177 else 0178 { 0179 d->pluginsNumberActivated->setText(QString()); 0180 } 0181 } 0182 else 0183 { 0184 // List filtering is active 0185 0186 int cnt = d->pluginsList->itemsVisible(); 0187 0188 if (cnt > 0) 0189 { 0190 d->pluginsNumber->setText(i18ncp("@info", "1 plugin found", "%1 plugins found", cnt)); 0191 } 0192 else 0193 { 0194 d->pluginsNumber->setText(i18nc("@info", "No plugin found")); 0195 } 0196 0197 d->pluginsNumberActivated->setText(QString()); 0198 } 0199 } 0200 0201 void DPluginSetup::slotCheckAll() 0202 { 0203 d->pluginsList->selectAll(); 0204 updateInfo(); 0205 } 0206 0207 void DPluginSetup::slotClearList() 0208 { 0209 d->pluginsList->clearAll(); 0210 updateInfo(); 0211 } 0212 0213 void DPluginSetup::slotItemClicked() 0214 { 0215 updateInfo(); 0216 } 0217 0218 void DPluginSetup::slotSetFilter(const QString& filter, Qt::CaseSensitivity cs) 0219 { 0220 d->pluginsList->setFilter(filter, cs); 0221 updateInfo(); 0222 } 0223 0224 void DPluginSetup::slotSearchResult(int found) 0225 { 0226 d->pluginFilter->slotSearchResult(found ? true : false); 0227 } 0228 0229 } // namespace Digikam 0230 0231 #include "moc_dpluginsetup.cpp"