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 00022 #include <qlayout.h> 00023 00024 #include <kfilemetapreview.h> 00025 #include <kglobalsettings.h> 00026 #include <klocale.h> 00027 00028 class KPreviewPropsPlugin::KPreviewPropsPluginPrivate 00029 { 00030 public: 00031 KPreviewPropsPluginPrivate() {} 00032 ~KPreviewPropsPluginPrivate() {} 00033 }; 00034 00035 KPreviewPropsPlugin::KPreviewPropsPlugin(KPropertiesDialog* props) 00036 : KPropsDlgPlugin(props) 00037 { 00038 d = new KPreviewPropsPluginPrivate; 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 = properties->addPage(i18n("P&review")); 00050 topframe->setFrameStyle(QFrame::NoFrame); 00051 00052 QVBoxLayout* tmp = new QVBoxLayout(topframe, 0, 0); 00053 00054 preview = new KFileMetaPreview(topframe); 00055 00056 tmp->addWidget(preview) ; 00057 connect( properties, SIGNAL( aboutToShowPage( QWidget * ) ), SLOT( aboutToShowPage( QWidget* ) ) ); 00058 } 00059 00060 KPreviewPropsPlugin::~KPreviewPropsPlugin() 00061 { 00062 delete d; 00063 } 00064 00065 bool KPreviewPropsPlugin::supports( KFileItemList _items ) 00066 { 00067 if ( _items.count() != 1) 00068 return false; 00069 if( !KGlobalSettings::showFilePreview(_items.first()->url())) 00070 return false; 00071 KMimeType::Ptr mt = KMimeType::findByURL( _items.first()->url() ); 00072 if ( mt->inherits("inode/directory") || mt->name() == "application/octet-stream" ) 00073 return false; 00074 00075 //TODO Copy everything of KFileMetaPreview::previewProviderFor() ? 00076 00077 return true; 00078 } 00079 00080 void KPreviewPropsPlugin::aboutToShowPage( QWidget* widget ) 00081 { 00082 if ( widget != preview->parent() ) 00083 return; 00084 00085 disconnect( properties, SIGNAL( aboutToShowPage( QWidget * ) ), this, SLOT( aboutToShowPage( QWidget* ) ) ); 00086 preview->showPreview(properties->item()->url()); 00087 } 00088 00089 #include "kpreviewprops.moc"