Commit d8d680bf authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* Added a widget to track the progress of jobs.

 * Extraction of the selected files now works

svn path=/branches/work/libarchive-based-ark/ark/; revision=690424
parent 7f059978
......@@ -11,10 +11,12 @@ set(arkpart_PART_SRCS
arkviewer.cpp
archivemodel.cpp
extractiondialog.cpp
jobtracker.cpp
)
kde4_add_ui_files(arkpart_PART_SRCS extractiondialog.ui )
kde4_add_ui_files(arkpart_PART_SRCS infopanel.ui )
kde4_add_ui_files(arkpart_PART_SRCS jobtracker.ui )
kde4_add_kcfg_files(arkpart_PART_SRCS settings.kcfgc)
......
......@@ -377,6 +377,11 @@ void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
connect( job, SIGNAL( result( KJob * ) ),
this, SIGNAL( loadingFinished() ) );
if ( m_jobTracker )
{
m_jobTracker->registerJob( job );
}
emit loadingStarted();
job->start();
}
......@@ -385,8 +390,13 @@ void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths )
{
Q_ASSERT( m_archive );
QList<QVariant> files;
files << fileName;
return extractFiles( files, destinationDir, preservePaths );
}
ExtractJob* ArchiveModel::extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths )
{
Q_ASSERT( m_archive );
return m_archive->copyFiles( files, destinationDir, preservePaths );
}
......@@ -22,6 +22,7 @@
#define ARCHIVEMODEL_H
#include <QAbstractItemModel>
#include <kjobtrackerinterface.h>
#include "kerfuffle/archive.h"
class ArchiveNode;
......@@ -53,6 +54,9 @@ class ArchiveModel: public QAbstractItemModel
int childCount( const QModelIndex &index );
ExtractJob* extractFile( const QVariant& fileName, const QString & destinationDir, bool preservePaths = false );
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths = false );
void setJobTracker( KJobTrackerInterface *tracker ) { m_jobTracker = tracker; }
signals:
void loadingStarted();
......@@ -69,6 +73,7 @@ class ArchiveModel: public QAbstractItemModel
Kerfuffle::Archive *m_archive;
ArchiveDirNode *m_rootNode;
KJobTrackerInterface *m_jobTracker;
};
#endif // ARCHIVEMODEL_H
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 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 "jobtracker.h"
#include <KIconLoader>
#include <QTimer>
JobTrackerWidget::JobTrackerWidget( QWidget *parent )
: QFrame( parent )
{
setupUi( this );
iconLabel->setPixmap( DesktopIcon( "ark" ) );
iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
setMaximumHeight( K3Icon::SizeHuge );
}
JobTracker::JobTracker( QWidget *parent )
: KJobTrackerInterface( parent )
{
m_ui = new JobTrackerWidget( parent );
m_ui->hide();
}
void JobTracker::description( KJob *job, const QString &title, const QPair< QString, QString > &f1, const QPair< QString, QString > &f2 )
{
Q_UNUSED( job );
Q_UNUSED( f1 );
Q_UNUSED( f2 );
m_ui->descriptionLabel->setText( QString( "<b>%1</b>" ).arg( title ) );
}
void JobTracker::infoMessage( KJob *job, const QString &plain, const QString &rich )
{
Q_UNUSED( job );
Q_UNUSED( rich );
m_ui->informationLabel->setText( plain );
}
void JobTracker::warning( KJob *job, const QString &plain, const QString &rich )
{
Q_UNUSED( job );
Q_UNUSED( rich );
m_ui->informationLabel->setText( plain );
}
void JobTracker::registerJob( KJob *job )
{
KJobTrackerInterface::registerJob( job );
m_ui->show();
}
void JobTracker::unregisterJob( KJob *job )
{
m_ui->hide();
KJobTrackerInterface::unregisterJob( job );
}
void JobTracker::timeOut()
{
m_ui->hide();
}
void JobTracker::finished( KJob *job )
{
QTimer::singleShot( 1500, this, SLOT( timeOut() ) );
m_ui->informationLabel->setText( i18n( "Done!" ) );
KJobTrackerInterface::unregisterJob( job );
}
/*
* ark -- archiver for the KDE project
*
* Copyright (C) 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.
*
*/
#ifndef JOBTRACKER_H
#define JOBTRACKER_H
#include <QFrame>
#include <kjobtrackerinterface.h>
#include "ui_jobtracker.h"
class JobTrackerWidget: public QFrame, public Ui::JobTrackerWidget
{
Q_OBJECT
public:
JobTrackerWidget( QWidget *parent = 0 );
};
class JobTracker: public KJobTrackerInterface
{
Q_OBJECT
public:
JobTracker( QWidget *parent = 0 );
QWidget *widget() const { return m_ui; }
virtual void registerJob( KJob *job );
virtual void unregisterJob( KJob *job );
protected slots:
virtual void finished( KJob *job );
virtual void description( KJob *job, const QString &title, const QPair< QString, QString > &f1, const QPair< QString, QString > &f2 );
virtual void infoMessage( KJob *job, const QString &plain, const QString &rich );
virtual void warning( KJob *job, const QString &plain, const QString &rich );
private slots:
void timeOut();
private:
JobTrackerWidget *m_ui;
};
#endif // JOBTRACKER_H
<ui version="4.0" >
<class>JobTrackerWidget</class>
<widget class="QWidget" name="JobTrackerWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>516</width>
<height>50</height>
</rect>
</property>
<property name="windowTitle" >
<string>Job Tracker</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="iconLabel" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string/>
</property>
<property name="pixmap" >
<pixmap>../../../../../../home/kde-devel/ark-trunk/pics/ox32-action-ark_extract.png</pixmap>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="descriptionLabel" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&lt;b>Job Description&lt;/b></string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="informationLabel" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Some Information about the job</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="progressBar" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum" >
<number>0</number>
</property>
<property name="value" >
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -25,6 +25,7 @@
#include "extractiondialog.h"
#include "kerfuffle/jobs.h"
#include "settings.h"
#include "jobtracker.h"
#include <KParts/GenericFactory>
#include <KApplication>
......@@ -35,11 +36,13 @@
#include <KTempDir>
#include <KDebug>
#include <KMessageBox>
#include <KVBox>
#include <QTreeView>
#include <QCursor>
#include <QAction>
#include <QSplitter>
#include <QVBoxLayout>
typedef KParts::GenericFactory<Part> Factory;
K_EXPORT_COMPONENT_FACTORY( libarkpart, Factory );
......@@ -51,12 +54,18 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
setComponentData( Factory::componentData() );
setXMLFile( "ark_part.rc" );
QSplitter *mainWidget = new QSplitter( Qt::Horizontal, parentWidget );
KVBox *mainWidget = new KVBox( parentWidget );
setWidget( mainWidget );
m_view = new QTreeView( parentWidget );
m_infoPanel = new InfoPanel( m_model, parentWidget );
mainWidget->addWidget( m_view );
mainWidget->addWidget( m_infoPanel );
m_jobTracker = new JobTracker( mainWidget );
QSplitter *splitter = new QSplitter( Qt::Horizontal, mainWidget );
m_view = new QTreeView( mainWidget );
m_infoPanel = new InfoPanel( m_model, mainWidget );
splitter->addWidget( m_view );
splitter->addWidget( m_infoPanel );
setupView();
setupActions();
......@@ -67,6 +76,8 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
this, SLOT( slotLoadingFinished() ) );
connect( m_model, SIGNAL( error( const QString&, const QString& ) ),
this, SLOT( slotError( const QString&, const QString& ) ) );
m_model->setJobTracker( m_jobTracker );
}
Part::~Part()
......@@ -180,6 +191,7 @@ void Part::slotPreview( const QModelIndex & index )
{
m_previewDir = new KTempDir();
ExtractJob *job = m_model->extractFile( entry[ OriginalFileName ], m_previewDir->name(), false );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotPreviewExtracted( KJob* ) ) );
job->start();
......@@ -237,7 +249,34 @@ void Part::slotExtractFiles()
kDebug( 1601 ) << k_funcinfo << "Destination Url : " << dialog.destinationDirectory() << endl;
ArkSettings::setOpenDestinationFolderAfterExtraction( dialog.openDestinationAfterExtraction() );
ArkSettings::setLastExtractionFolder( dialog.destinationDirectory().path() );
QList<QVariant> files = selectedFiles();
ExtractJob *job = m_model->extractFiles( files, dialog.destinationDirectory().path(), false );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( done( KJob* ) ),
this, SLOT( slotExtractionDone( KJob * ) ) );
job->start();
}
}
QList<QVariant> Part::selectedFiles()
{
QList<QVariant> files;
foreach( const QModelIndex & index, m_view->selectionModel()->selectedRows() )
{
const ArchiveEntry& entry = m_model->entryForIndex( index );
files << entry[ OriginalFileName ];
}
return files;
}
void Part::slotExtractionDone( KJob* )
{
kDebug( 1601 ) << k_funcinfo << endl;
}
void Part::slotAddFiles()
......
......@@ -27,6 +27,7 @@
class ArchiveModel;
class InfoPanel;
class JobTracker;
class QTreeView;
class QAction;
......@@ -57,6 +58,7 @@ class Part: public KParts::ReadWritePart, public Interface
void slotPreviewExtracted( KJob* );
void slotError( const QString& errorMessage, const QString& details );
void slotExtractFiles();
void slotExtractionDone( KJob* );
void slotAddFiles();
void updateActions();
void selectionChanged();
......@@ -65,6 +67,7 @@ class Part: public KParts::ReadWritePart, public Interface
void setupView();
void setupActions();
bool isPreviewable( const QModelIndex & index );
QList<QVariant> selectedFiles();
ArchiveModel *m_model;
QTreeView *m_view;
......@@ -73,6 +76,7 @@ class Part: public KParts::ReadWritePart, public Interface
QAction *m_addFilesAction;
InfoPanel *m_infoPanel;
KTempDir *m_previewDir;
JobTracker *m_jobTracker;
};
#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