Commit a9477f2d authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Removing traces of jobtracker in ArchiveModel. Making the jobtracker UI more...

Removing traces of jobtracker in ArchiveModel. Making the jobtracker UI more consistent. Fixing a bug where "Loading job" text didn't appear. Making the progress bar do the inactive animation when progress reports have not been sent.

svn path=/trunk/KDE/kdeutils/ark/; revision=873025
parent 298c496f
......@@ -84,13 +84,14 @@ namespace Kerfuffle
void ListJob::doWork()
{
emit description( this, i18n( "Listing entries" ) );
emit description( this, i18n( "Loading archive..." ) );
m_interface->registerObserver( this );
bool result = m_interface->list();
m_interface->removeObserver( this );
setError(!result);
emitResult();
kDebug( 1601 ) << "Finished";
}
void ListJob::onNewEntry(const ArchiveEntry& entry)
......
......@@ -164,8 +164,7 @@ int ArchiveNode::row()
ArchiveModel::ArchiveModel( QObject *parent )
: QAbstractItemModel( parent ), m_archive( 0 ),
m_rootNode( new ArchiveDirNode( 0, ArchiveEntry() ) ),
m_jobTracker(0)
m_rootNode( new ArchiveDirNode( 0, ArchiveEntry() ) )
{
}
......@@ -668,16 +667,18 @@ void ArchiveModel::insertNode( ArchiveNode *node )
endInsertRows();
}
void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
KJob* ArchiveModel::setArchive( Kerfuffle::Archive *archive )
{
delete m_archive;
m_archive = archive;
m_rootNode->clear();
Kerfuffle::ListJob *job = NULL;
if ( m_archive )
{
Kerfuffle::ListJob *job = m_archive->list(); // TODO: call "open" or "create"?
job = m_archive->list(); // TODO: call "open" or "create"?
connect( job, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
......@@ -685,18 +686,13 @@ void ArchiveModel::setArchive( Kerfuffle::Archive *archive )
connect( job, SIGNAL( result( KJob * ) ),
this, SIGNAL( loadingFinished(KJob *) ) );
if ( m_jobTracker )
{
m_jobTracker->registerJob( job );
}
emit loadingStarted();
// TODO: make sure if it's ok to not have calls to beginRemoveColumns here
m_showColumns.clear();
job->start();
}
reset();
return job;
}
ExtractJob* ArchiveModel::extractFile( const QVariant& fileName, const QString & destinationDir, Archive::CopyFlags flags ) const
......@@ -722,7 +718,6 @@ AddJob* ArchiveModel::addFiles( const QStringList & filenames, const Compression
if ( !m_archive->isReadOnly())
{
AddJob *job = m_archive->addFiles(filenames, options);
m_jobTracker->registerJob( job );
connect( job, SIGNAL( newEntry( const ArchiveEntry& ) ),
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
connect(job, SIGNAL(userQuery(Query*)),
......@@ -740,7 +735,6 @@ DeleteJob* ArchiveModel::deleteFiles( const QList<QVariant> & files )
if ( !m_archive->isReadOnly() )
{
DeleteJob *job = m_archive->deleteFiles( files );
m_jobTracker->registerJob( job );
connect( job, SIGNAL( entryRemoved( const QString & ) ),
this, SLOT( slotEntryRemoved( const QString & ) ) );
......
......@@ -56,7 +56,7 @@ class ArchiveModel: public QAbstractItemModel
virtual bool dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
void setArchive( Kerfuffle::Archive *archive );
KJob* setArchive( Kerfuffle::Archive *archive );
Kerfuffle::Archive *archive() const { return m_archive; }
ArchiveEntry entryForIndex( const QModelIndex &index );
......@@ -68,8 +68,6 @@ class ArchiveModel: public QAbstractItemModel
AddJob* addFiles( const QStringList & paths, const CompressionOptions& options = CompressionOptions() );
DeleteJob* deleteFiles( const QList<QVariant> & files );
void setJobTracker( KJobTrackerInterface *tracker ) { m_jobTracker = tracker; }
signals:
void loadingStarted();
void loadingFinished(KJob *);
......
......@@ -22,6 +22,7 @@
#include <KIconLoader>
#include <QTimer>
#include <KDebug>
JobTrackerWidget::JobTrackerWidget( QWidget *parent )
: QFrame( parent )
......@@ -33,7 +34,7 @@ JobTracker::JobTracker( QWidget *parent )
: KAbstractWidgetJobTracker( parent ), m_currentJob( 0 )
{
m_ui = new JobTrackerWidget( parent );
m_ui->hide();
resetUi();
}
void JobTracker::description( KJob *job, const QString &title, const QPair< QString, QString > &f1, const QPair< QString, QString > &f2 )
......@@ -42,6 +43,7 @@ void JobTracker::description( KJob *job, const QString &title, const QPair< QStr
Q_UNUSED( f1 );
Q_UNUSED( f2 );
m_ui->descriptionLabel->setText( QString( "<b>%1</b>" ).arg( title ) );
m_ui->descriptionLabel->show();
}
void JobTracker::infoMessage( KJob *job, const QString &plain, const QString &rich )
......@@ -71,24 +73,31 @@ void JobTracker::registerJob( KJob *job )
void JobTracker::percent (KJob *job, unsigned long percent )
{
Q_UNUSED(job );
m_ui->progressBar->setMaximum(100);
m_ui->progressBar->setMinimum(0);
m_ui->progressBar->setValue(percent);
}
void JobTracker::unregisterJob( KJob *job )
{
m_ui->hide();
kDebug( 1601 );
resetUi();
m_currentJob = 0;
KJobTrackerInterface::unregisterJob( job );
}
void JobTracker::timeOut()
void JobTracker::resetUi()
{
m_ui->hide();
m_ui->descriptionLabel->hide();
m_ui->informationLabel->hide();
m_ui->progressBar->setMaximum(0);
m_ui->progressBar->setMinimum(0);
}
void JobTracker::finished( KJob *job )
{
QTimer::singleShot( 1500, this, SLOT( timeOut() ) );
QTimer::singleShot( 1500, this, SLOT( resetUi() ) );
m_ui->informationLabel->setText( i18n( "Operation finished." ) );
m_ui->informationLabel->show();
m_ui->progressBar->hide();
......
......@@ -53,7 +53,7 @@ class JobTracker: public KAbstractWidgetJobTracker
virtual void percent (KJob *job, unsigned long percent );
private slots:
void timeOut();
void resetUi();
private:
JobTrackerWidget *m_ui;
......
......@@ -47,7 +47,7 @@
<item>
<widget class="QLabel" name="informationLabel" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -66,7 +66,7 @@
<item>
<widget class="QProgressBar" name="progressBar" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......
......@@ -62,7 +62,8 @@ 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 ) ), m_previewDir( 0 ), m_busy( false )
: KParts::ReadWritePart( parent ), m_model( new ArchiveModel( this ) ), m_previewDir( 0 ), m_busy( false ),
m_jobTracker(NULL)
{
Q_UNUSED( args );
setComponentData( Factory::componentData() );
......@@ -94,7 +95,6 @@ Part::Part( QWidget *parentWidget, QObject *parent, const QStringList& args )
new DndExtractAdaptor(this);
QDBusConnection::sessionBus().registerObject("/DndExtract", this);
QTimer::singleShot( 0, this, SLOT( createJobTracker() ) );
}
Part::~Part()
......@@ -103,12 +103,14 @@ Part::~Part()
m_previewDir = 0;
}
void Part::createJobTracker()
void Part::registerJob(KJob* job)
{
m_jobTracker = new JobTracker;
m_model->setJobTracker( m_jobTracker );
if (!m_jobTracker) {
m_jobTracker = new JobTracker();
m_statusBarExtension->addStatusBarItem( m_jobTracker->widget(0), 0, true );
m_jobTracker->widget(0)->hide();
m_jobTracker->widget(job)->show();
}
m_jobTracker->registerJob(job);
}
void Part::extractSelectedFilesTo(QString localPath)
......@@ -121,7 +123,7 @@ void Part::extractSelectedFilesTo(QString localPath)
kDebug( 1601 ) << "selected files are " << files;
ExtractJob *job = m_model->extractFiles( files, localPath, Archive::PreservePaths | Archive::TruncateCommonBase );
m_jobTracker->registerJob( job );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotExtractionDone( KJob * ) ) );
......@@ -246,7 +248,7 @@ void Part::slotQuickExtractFiles(QAction *triggeredAction)
QList<QVariant> files = selectedFiles();
ExtractJob *job = m_model->extractFiles( files, finalDestinationDirectory, Archive::PreservePaths );
m_jobTracker->registerJob( job );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotExtractionDone( KJob * ) ) );
......@@ -284,7 +286,10 @@ bool Part::openFile()
#endif
Kerfuffle::Archive *archive = Kerfuffle::factory( localFilePath() );
m_model->setArchive( archive );
KJob *job = m_model->setArchive( archive );
registerJob(job);
job->start();
m_infoPanel->setIndex( QModelIndex() );
if (!archive) {
......@@ -359,7 +364,7 @@ void Part::slotPreview( const QModelIndex & index )
m_previewDir = new KTempDir();
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name(), Archive::CopyFlags() );
m_jobTracker->registerJob( job );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotPreviewExtracted( KJob* ) ) );
job->start();
......@@ -480,7 +485,7 @@ void Part::slotExtractFiles()
flags |= Kerfuffle::Archive::PreservePaths;
ExtractJob *job = m_model->extractFiles( files, destinationDirectory, flags );
m_jobTracker->registerJob( job );
registerJob( job );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotExtractionDone( KJob * ) ) );
......@@ -583,6 +588,7 @@ void Part::slotAddFiles(const QStringList& filesToAdd, const QString& path)
AddJob *job = m_model->addFiles( filesToAdd, options);
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotAddFilesDone( KJob* ) ) );
registerJob(job);
job->start();
}
}
......@@ -622,5 +628,6 @@ void Part::slotDeleteFiles()
DeleteJob *job = m_model->deleteFiles( selectedFiles() );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotDeleteFilesDone( KJob* ) ) );
registerJob(job);
job->start();
}
......@@ -75,7 +75,6 @@ class Part: public KParts::ReadWritePart, public Interface
void updateActions();
void selectionChanged();
void adjustColumns( const QModelIndex & topleft, const QModelIndex& bottomRight );
void createJobTracker();
signals:
void busy();
......@@ -89,6 +88,9 @@ class Part: public KParts::ReadWritePart, public Interface
bool isPreviewable( const QModelIndex & index );
QList<QVariant> selectedFiles();
QList<QVariant> selectedFilesWithChildren();
void registerJob(KJob *job);
QString lastExtractionFolder;
ArchiveModel *m_model;
......
......@@ -126,7 +126,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
return false;
}
progress( 0.0 );
//progress( 0.0 );
for ( int index = 0; index < zip_get_num_files( m_archive ); ++index )
{
......
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