• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

ark

arkviewer.cpp

Go to the documentation of this file.
00001 /*
00002  * ark: A program for modifying archives via a GUI.
00003  *
00004  * Copyright (C) 2004, Henrique Pinto <henrique.pinto@kdemail.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 
00022 #include "arkviewer.h"
00023 
00024 #include <KLocale>
00025 #include <KParts/ComponentFactory>
00026 #include <KMimeType>
00027 #include <KDebug>
00028 #include <KUrl>
00029 #include <KGlobal>
00030 #include <KIconLoader>
00031 #include <KVBox>
00032 
00033 #include <QHBoxLayout>
00034 #include <QFrame>
00035 #include <QLabel>
00036 
00037 ArkViewer::ArkViewer( QWidget * parent )
00038     : KDialog( parent), m_part( 0 )
00039 {
00040     setButtons( Close );
00041     m_widget = new KVBox( this );
00042     m_widget->layout()->setSpacing( 10 );
00043 
00044     connect( this, SIGNAL( finished() ), this, SLOT( slotFinished() ) );
00045 
00046     setMainWidget( m_widget );
00047 }
00048 
00049 ArkViewer::~ArkViewer()
00050 {
00051 }
00052 
00053 void ArkViewer::slotFinished()
00054 {
00055     delete m_part;
00056     m_part = 0;
00057     delayedDestruct();
00058 }
00059 
00060 bool ArkViewer::view( const QString& filename )
00061 {
00062     KUrl u( filename );
00063 
00064     KMimeType::Ptr mimetype = KMimeType::findByUrl( u, 0, true );
00065 
00066     setCaption( u.fileName() );
00067     // TODO: Load the size from the config file
00068     QSize size = QSize();
00069     if (size.width() < 200)
00070         size = QSize(560, 400);
00071     setInitialSize( size );
00072 
00073     QFrame *header = new QFrame( m_widget );
00074     QHBoxLayout *headerLayout = new QHBoxLayout( header );
00075 
00076     QLabel *iconLabel = new QLabel( header );
00077         headerLayout->addWidget(iconLabel);
00078     iconLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon(mimetype->iconName(), KIconLoader::Desktop ) );
00079     iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
00080 
00081     KVBox *headerRight = new KVBox( header );
00082         headerLayout->addWidget(headerRight);
00083     new QLabel( QString( "<qt><b>%1</b></qt>" )
00084                          .arg( KUrl( filename ).fileName() ), headerRight
00085               );
00086     new QLabel( mimetype->comment(), headerRight );
00087 
00088     header->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
00089 
00090     m_part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype->name(), QString(), m_widget, this );
00091 
00092     if ( m_part )
00093     {
00094         m_part->openUrl( filename );
00095         exec();
00096         return true;
00097     }
00098     else
00099     {
00100         return false;
00101     }
00102 }
00103 
00104 #include "arkviewer.moc"

ark

Skip menu "ark"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal