File indexing completed on 2024-05-05 16:08:28

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2005 Stephan Binner <binner@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License version 2 as published by the Free Software Foundation.
0007 
0008     This library is distributed in the hope that it will be useful,
0009     but WITHOUT ANY WARRANTY; without even the implied warranty of
0010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011     Library General Public License for more details.
0012 
0013     You should have received a copy of the GNU Library General Public License
0014     along with this library; see the file COPYING.LIB.  If not, write to
0015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016     Boston, MA 02110-1301, USA.
0017 
0018  */
0019 
0020 #include "kpreviewprops.h"
0021 #include <kio/previewjob.h>
0022 #include <kprotocolinfo.h>
0023 
0024 #include <QLayout>
0025 
0026 #include <kfilemetapreview_p.h>
0027 #include <klocalizedstring.h>
0028 
0029 class Q_DECL_HIDDEN KPreviewPropsPlugin::KPreviewPropsPluginPrivate
0030 {
0031 public:
0032     KPreviewPropsPluginPrivate()  {}
0033     ~KPreviewPropsPluginPrivate() {}
0034 };
0035 
0036 KPreviewPropsPlugin::KPreviewPropsPlugin(KPropertiesDialog *props)
0037     : KPropertiesDialogPlugin(props), d(new KPreviewPropsPluginPrivate)
0038 {
0039 
0040     if (properties->items().count() > 1) {
0041         return;
0042     }
0043 
0044     createLayout();
0045 }
0046 
0047 void KPreviewPropsPlugin::createLayout()
0048 {
0049     // let the dialog create the page frame
0050     QFrame *topframe = new QFrame();
0051     properties->addPage(topframe, i18n("P&review"));
0052     topframe->setFrameStyle(QFrame::NoFrame);
0053 
0054     QVBoxLayout *tmp = new QVBoxLayout(topframe);
0055     tmp->setContentsMargins(0, 0, 0, 0);
0056 
0057     preview = new KFileMetaPreview(topframe);
0058 
0059     tmp->addWidget(preview);
0060     connect(properties, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)));
0061 }
0062 
0063 KPreviewPropsPlugin::~KPreviewPropsPlugin()
0064 {
0065     delete d;
0066 }
0067 
0068 bool KPreviewPropsPlugin::supports(const KFileItemList &_items)
0069 {
0070     if (_items.count() != 1) {
0071         return false;
0072     }
0073     bool metaDataEnabled = KProtocolInfo::showFilePreview(_items.first().url().scheme());
0074     if (!metaDataEnabled) {
0075         return false;
0076     }
0077     const QMimeType mime = _items.first().determineMimeType();
0078     const QStringList supportedMimeTypes = KIO::PreviewJob::supportedMimeTypes();
0079     foreach (const QString &supportedMime, supportedMimeTypes) {
0080         if (mime.inherits(supportedMime)) {
0081             return true;
0082         }
0083     }
0084     return false;
0085 }
0086 
0087 void KPreviewPropsPlugin::currentPageChanged(KPageWidgetItem *current, KPageWidgetItem *)
0088 {
0089     if (current->widget() != preview->parent()) {
0090         return;
0091     }
0092 
0093     disconnect(properties, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), this, SLOT(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)));
0094     preview->showPreview(properties->item().url());
0095 }
0096 
0097 #include "moc_kpreviewprops.cpp"