Commit 679dc99e authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* Preview now works

svn path=/branches/work/libarchive-based-ark/ark/; revision=689742
parent 80c77068
......@@ -8,6 +8,7 @@ ADD_DEFINITIONS(-D_LARGEFILE64_SOURCE)
set(arkpart_PART_SRCS
part.cpp
infopanel.cpp
arkviewer.cpp
archivemodel.cpp
)
......
......@@ -359,8 +359,21 @@ void ArchiveModel::setArchive( Arch *archive )
this, SIGNAL( loadingFinished() ) );
connect( m_archive, SIGNAL( error( const QString&, const QString& ) ),
this, SIGNAL( error( const QString&, const QString& ) ) );
connect( m_archive, SIGNAL( sigExtract( bool ) ),
this, SIGNAL( extractionFinished( bool ) ) );
emit loadingStarted();
m_archive->open();
}
reset();
}
void ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir )
{
if ( !m_archive )
{
emit extractionFinished( false );
return;
}
m_archive->extractFile( fileName, destinationDir );
}
void extractFile( const QVariant& fileName, const QString & destinationDir );
......@@ -48,9 +48,12 @@ class ArchiveModel: public QAbstractItemModel
ArchiveEntry entryForIndex( const QModelIndex &index );
void extractFile( const QVariant& fileName, const QString & destinationDir );
signals:
void loadingStarted();
void loadingFinished();
void extractionFinished( bool success );
void error( const QString& error, const QString& details );
private slots:
......
/*
* ark: A program for modifying archives via a GUI.
*
* Copyright (C) 2004, Henrique Pinto <henrique.pinto@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "arkviewer.h"
#include <KLocale>
#include <KParts/ComponentFactory>
#include <KMimeType>
#include <KDebug>
#include <KUrl>
#include <KGlobal>
#include <KIconLoader>
#include <KVBox>
#include <QHBoxLayout>
#include <QFrame>
#include <QLabel>
ArkViewer::ArkViewer( QWidget * parent )
: KDialog( parent), m_part( 0 )
{
setButtons( Close );
m_widget = new KVBox( this );
m_widget->layout()->setSpacing( 10 );
connect( this, SIGNAL( finished() ), this, SLOT( slotFinished() ) );
setMainWidget( m_widget );
}
ArkViewer::~ArkViewer()
{
}
void ArkViewer::slotFinished()
{
delete m_part;
m_part = 0;
delayedDestruct();
}
bool ArkViewer::view( const QString& filename )
{
KUrl u( filename );
KMimeType::Ptr mimetype = KMimeType::findByUrl( u, 0, true );
setCaption( u.fileName() );
// TODO: Load the size from the config file
QSize size = QSize();
if (size.width() < 200)
size = QSize(560, 400);
setInitialSize( size );
QFrame *header = new QFrame( m_widget );
QHBoxLayout *headerLayout = new QHBoxLayout( header );
QLabel *iconLabel = new QLabel( header );
headerLayout->addWidget(iconLabel);
iconLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon(mimetype->iconName(), K3Icon::Desktop ) );
iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
KVBox *headerRight = new KVBox( header );
headerLayout->addWidget(headerRight);
new QLabel( QString( "<qt><b>%1</b></qt>" )
.arg( KUrl( filename ).fileName() ), headerRight
);
new QLabel( mimetype->comment(), headerRight );
header->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
m_part = KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>( mimetype->name(), QString(), m_widget, this );
if ( m_part )
{
m_part->openUrl( filename );
exec();
return true;
}
else
{
return false;
}
}
#include "arkviewer.moc"
#ifndef ARKVIEWER_H
#define ARKVIEWER_H
/*
* ark: A program for modifying archives via a GUI.
*
* Copyright (C) 2004-2007, Henrique Pinto <henrique.pinto@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <KDialog>
#include <KParts/ReadOnlyPart>
class ArkViewer : public KDialog
{
Q_OBJECT
public:
explicit ArkViewer( QWidget* parent = 0 );
~ArkViewer();
bool view( const QString& filename );
protected slots:
void slotFinished();
private:
KParts::ReadOnlyPart *m_part;
QWidget *m_widget;
};
#endif // ARKVIEWER_H
......@@ -21,6 +21,7 @@
#include "part.h"
#include "archivemodel.h"
#include "infopanel.h"
#include "arkviewer.h"
#include <KParts/GenericFactory>
#include <KApplication>
......@@ -28,6 +29,7 @@
#include <KDebug>
#include <KActionCollection>
#include <KIcon>
#include <KTempDir>
#include <KDebug>
#include <KMessageBox>
......@@ -40,7 +42,7 @@ typedef KParts::GenericFactory<Part> Factory;
K_EXPORT_COMPONENT_FACTORY( libarkpart, Factory );
Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) ), m_previewDir( 0 )
{
Q_UNUSED( args );
setComponentData( Factory::componentData() );
......@@ -136,6 +138,32 @@ void Part::slotLoadingFinished()
void Part::slotPreview()
{
Q_ASSERT( m_previewDir == 0 );
const ArchiveEntry& entry = m_model->entryForIndex( m_view->selectionModel()->currentIndex() );
if ( !entry.isEmpty() )
{
m_previewDir = new KTempDir();
connect( m_model, SIGNAL( extractionFinished( bool ) ),
this, SLOT( slotPreviewExtracted( bool ) ) );
m_model->extractFile( entry[ FileName ], m_previewDir->name() );
}
}
void Part::slotPreviewExtracted( bool success )
{
disconnect( m_model, SIGNAL( extractionFinished( bool ) ),
this, SLOT( slotPreviewExtracted( bool ) ) );
if ( success )
{
ArkViewer viewer( widget() );
const ArchiveEntry& entry = m_model->entryForIndex( m_view->selectionModel()->currentIndex() );
if ( !viewer.view( m_previewDir->name() + '/' + entry[ FileName ].toString() ) )
{
KMessageBox::sorry( widget(), i18n( "The internal viewer cannot preview this file." ) );
}
}
delete m_previewDir;
m_previewDir = 0;
}
void Part::slotError( const QString& errorMessage, const QString& details )
......
......@@ -29,6 +29,7 @@ class InfoPanel;
class QTreeView;
class QAction;
class KAboutData;
class KTempDir;
class Part: public KParts::ReadWritePart, public Interface
{
......@@ -48,6 +49,7 @@ class Part: public KParts::ReadWritePart, public Interface
void slotLoadingStarted();
void slotLoadingFinished();
void slotPreview();
void slotPreviewExtracted( bool success );
void slotError( const QString& errorMessage, const QString& details );
void updateActions();
void selectionChanged();
......@@ -60,7 +62,7 @@ class Part: public KParts::ReadWritePart, public Interface
QTreeView *m_view;
QAction *m_previewAction;
InfoPanel *m_infoPanel;
KTempDir *m_previewDir;
};
#endif // PART_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment