KIO
kpreviewprops.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005 Stephan Binner <binner@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 00018 */ 00019 00020 #include "kpreviewprops.h" 00021 #include <kio/previewjob.h> 00022 00023 #include <QtGui/QLayout> 00024 00025 #include <kfilemetapreview.h> 00026 #include <kglobalsettings.h> 00027 #include <klocale.h> 00028 00029 class KPreviewPropsPlugin::KPreviewPropsPluginPrivate 00030 { 00031 public: 00032 KPreviewPropsPluginPrivate() {} 00033 ~KPreviewPropsPluginPrivate() {} 00034 }; 00035 00036 KPreviewPropsPlugin::KPreviewPropsPlugin(KPropertiesDialog* props) 00037 : KPropertiesDialogPlugin(props),d(new KPreviewPropsPluginPrivate) 00038 { 00039 00040 if (properties->items().count()>1) 00041 return; 00042 00043 createLayout(); 00044 } 00045 00046 void KPreviewPropsPlugin::createLayout() 00047 { 00048 // let the dialog create the page frame 00049 QFrame* topframe = new QFrame(); 00050 properties->addPage(topframe, i18n("P&review")); 00051 topframe->setFrameStyle(QFrame::NoFrame); 00052 00053 QVBoxLayout* tmp = new QVBoxLayout(topframe); 00054 tmp->setMargin(0); 00055 00056 preview = new KFileMetaPreview(topframe); 00057 00058 tmp->addWidget(preview) ; 00059 connect( properties, SIGNAL( currentPageChanged( KPageWidgetItem *, KPageWidgetItem * ) ), SLOT( currentPageChanged( KPageWidgetItem *, KPageWidgetItem * ) ) ); 00060 } 00061 00062 KPreviewPropsPlugin::~KPreviewPropsPlugin() 00063 { 00064 delete d; 00065 } 00066 00067 bool KPreviewPropsPlugin::supports( const KFileItemList &_items ) 00068 { 00069 if ( _items.count() != 1 ) 00070 return false; 00071 bool metaDataEnabled = KGlobalSettings::showFilePreview(_items.first().url()); 00072 if (!metaDataEnabled) 00073 return false; 00074 const KMimeType::Ptr mime = _items.first().mimeTypePtr(); 00075 const QStringList supportedMimeTypes = KIO::PreviewJob::supportedMimeTypes(); 00076 foreach(const QString& supportedMime, supportedMimeTypes) { 00077 if (mime->is(supportedMime)) 00078 return true; 00079 } 00080 return false; 00081 } 00082 00083 void KPreviewPropsPlugin::currentPageChanged( KPageWidgetItem *current, KPageWidgetItem * ) 00084 { 00085 if ( current->widget() != preview->parent() ) 00086 return; 00087 00088 disconnect( properties, SIGNAL( currentPageChanged( KPageWidgetItem *, KPageWidgetItem * ) ), this, SLOT( currentPageChanged( KPageWidgetItem *, KPageWidgetItem * ) ) ); 00089 preview->showPreview(properties->item().url()); 00090 } 00091 00092 #include "kpreviewprops.moc"
KDE 4.6 API Reference