File indexing completed on 2024-03-24 05:54:43
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2002 Dominik Seichter <domseichter@web.de> 0003 0004 #include "fileplugin.h" 0005 0006 #include <KIconLoader> 0007 #include <KLocalizedString> 0008 #include <kservice.h> 0009 0010 #include <QListWidget> 0011 #include <QLabel> 0012 #include <QHBoxLayout> 0013 0014 FilePlugin::FilePlugin(PluginLoader *loader, KService *service) 0015 : Plugin(loader), 0016 m_name(service->name()), 0017 m_comment(QString()), 0018 m_icon(service->icon()) 0019 { 0020 } 0021 0022 FilePlugin::FilePlugin(PluginLoader *loader) 0023 : Plugin(loader), 0024 m_name("FilePlugin") 0025 { 0026 } 0027 0028 FilePlugin::~FilePlugin() 0029 { 0030 0031 } 0032 0033 bool FilePlugin::supports(const QString &token) 0034 { 0035 QString lower = token.toLower(); 0036 0037 for (int i = 0; i < m_keys.count(); i++) 0038 // TODO: Maybe we can optimize by putting all tokens 0039 // already converted to lowercase into m_keys 0040 if (QRegExp(m_keys[i].toLower()).exactMatch(lower)) { 0041 return true; 0042 } 0043 0044 return false; 0045 } 0046 0047 const QIcon FilePlugin::icon() const 0048 { 0049 return QIcon::fromTheme(m_icon); 0050 } 0051 0052 void FilePlugin::createUI(QWidget *parent) const 0053 { 0054 QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding); 0055 0056 QVBoxLayout *l = new QVBoxLayout(parent); 0057 QHBoxLayout *hbox = new QHBoxLayout; 0058 0059 QLabel *pix = new QLabel(parent); 0060 pix->setPixmap(QIcon::fromTheme(m_icon).pixmap(KIconLoader::SizeMedium)); 0061 0062 hbox->addWidget(pix); 0063 hbox->addWidget(new QLabel("<qt><b>" + name() + "</b></qt>", parent)); 0064 hbox->addItem(spacer); 0065 0066 QLabel *comment = new QLabel(m_comment, parent); 0067 comment->setWordWrap(true); 0068 l->addLayout(hbox); 0069 l->addWidget(comment); 0070 l->addWidget(new QLabel(i18n("Supported tokens:"), parent)); 0071 0072 QListWidget *list = new QListWidget(parent); 0073 0074 const QStringList &keys = supportedTokens(); 0075 0076 for (int i = 0; i < keys.count(); i++) { 0077 list->insertItem(0, '[' + keys[i] + ']'); 0078 } 0079 0080 l->addWidget(list); 0081 l->setStretchFactor(list, 2); 0082 } 0083