File indexing completed on 2022-11-29 20:25:13

0001 /***************************************************************************
0002                           fileplugin.cpp  -  description
0003                              -------------------
0004     begin                : Mon Jul 1 2002
0005     copyright            : (C) 2002 by Dominik Seichter
0006     email                : domseichter@web.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "fileplugin.h"
0019 
0020 #include <KIconLoader>
0021 #include <KLocalizedString>
0022 #include <kservice.h>
0023 
0024 #include <QListWidget>
0025 #include <QLabel>
0026 #include <QHBoxLayout>
0027 
0028 FilePlugin::FilePlugin(PluginLoader *loader, KService *service)
0029     : Plugin(loader),
0030       m_name(service->name()),
0031       m_comment(QString()),
0032       m_icon(service->icon())
0033 {
0034 }
0035 
0036 FilePlugin::FilePlugin(PluginLoader *loader)
0037     : Plugin(loader),
0038       m_name("FilePlugin")
0039 {
0040 }
0041 
0042 FilePlugin::~FilePlugin()
0043 {
0044 
0045 }
0046 
0047 bool FilePlugin::supports(const QString &token)
0048 {
0049     QString lower = token.toLower();
0050 
0051     for (int i = 0; i < m_keys.count(); i++)
0052         // TODO: Maybe we can optimize by putting all tokens
0053         //       already converted to lowercase into m_keys
0054         if (QRegExp(m_keys[i].toLower()).exactMatch(lower)) {
0055             return true;
0056         }
0057 
0058     return false;
0059 }
0060 
0061 const QPixmap FilePlugin::icon() const
0062 {
0063     return KIconLoader::global()->loadIcon(m_icon, KIconLoader::NoGroup, KIconLoader::SizeSmall);
0064 }
0065 
0066 void FilePlugin::createUI(QWidget *parent) const
0067 {
0068     QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
0069 
0070     QVBoxLayout *l    = new QVBoxLayout(parent);
0071     QHBoxLayout *hbox = new QHBoxLayout;
0072 
0073     QLabel *pix = new QLabel(parent);
0074     pix->setPixmap(KIconLoader::global()->loadIcon(m_icon, KIconLoader::Desktop));
0075 
0076     hbox->addWidget(pix);
0077     hbox->addWidget(new QLabel("<qt><b>" + name() + "</b></qt>", parent));
0078     hbox->addItem(spacer);
0079 
0080     QLabel *comment = new QLabel(m_comment, parent);
0081     comment->setWordWrap(true);
0082     l->addLayout(hbox);
0083     l->addWidget(comment);
0084     l->addWidget(new QLabel(i18n("Supported tokens:"), parent));
0085 
0086     QListWidget *list = new QListWidget(parent);
0087 
0088     const QStringList &keys = supportedTokens();
0089 
0090     for (int i = 0; i < keys.count(); i++) {
0091         list->insertItem(0, '[' + keys[i] + ']');
0092     }
0093 
0094     l->addWidget(list);
0095     l->setStretchFactor(list, 2);
0096 }
0097