Commit 54a56681 authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* "Delete" now somehow works, the files are deleted, but the GUI is not updated yet

svn path=/branches/work/libarchive-based-ark/ark/; revision=694059
parent 3bc49400
......@@ -39,6 +39,7 @@ namespace Kerfuffle
{
class ListJob;
class ExtractJob;
class DeleteJob;
class AddJob;
enum EntryMetaDataType { FileName = 0, OriginalFileName = 1, Permissions = 2, Owner = 3,
......@@ -55,11 +56,11 @@ namespace Kerfuffle
virtual QString fileName() = 0;
virtual bool isReadOnly() = 0;
virtual KJob* open() = 0;
virtual KJob* create() = 0;
virtual ListJob* list() = 0;
virtual KJob* deleteFiles( const QList<QVariant> & files ) = 0;
virtual AddJob* addFiles( const QStringList & files ) = 0;
virtual KJob* open() = 0;
virtual KJob* create() = 0;
virtual ListJob* list() = 0;
virtual DeleteJob* deleteFiles( const QList<QVariant> & files ) = 0;
virtual AddJob* addFiles( const QStringList & files ) = 0;
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, bool preservePaths = false ) = 0;
};
......
......@@ -73,9 +73,13 @@ namespace Kerfuffle
return new ListJob( m_iface, this );
}
KJob* ArchiveBase::deleteFiles( const QList<QVariant> & files )
DeleteJob* ArchiveBase::deleteFiles( const QList<QVariant> & files )
{
return 0;
if ( m_iface->isReadOnly() )
{
return 0;
}
return new DeleteJob( files, static_cast<ReadWriteArchiveInterface*>( m_iface ), this );
}
AddJob* ArchiveBase::addFiles( const QStringList & files )
......
......@@ -53,7 +53,7 @@ namespace Kerfuffle
virtual KJob* open();
virtual KJob* create();
virtual ListJob* list();
virtual KJob* deleteFiles( const QList<QVariant> & files );
virtual DeleteJob* deleteFiles( const QList<QVariant> & files );
virtual AddJob* addFiles( const QStringList & files );
virtual ExtractJob* copyFiles( const QList<QVariant> & files, const QString & destinationDir, bool preservePaths = false );
......
......@@ -53,6 +53,14 @@ namespace Kerfuffle
}
}
void ReadOnlyArchiveInterface::entryRemoved( const QString & path )
{
foreach( ArchiveObserver *observer, m_observers )
{
observer->onEntryRemoved( path );
}
}
void ReadOnlyArchiveInterface::progress( double p )
{
foreach( ArchiveObserver *observer, m_observers )
......
......@@ -58,6 +58,7 @@ namespace Kerfuffle
void error( const QString & message, const QString & details = QString() );
void entry( const ArchiveEntry & archiveEntry );
void progress( double );
void entryRemoved( const QString& path );
private:
QList<ArchiveObserver*> m_observers;
......
......@@ -29,9 +29,17 @@
namespace Kerfuffle
{
InternalJob::InternalJob( QObject *parent )
: ThreadWeaver::Job( parent ), m_success( false )
{
}
InternalJob::~InternalJob()
{
}
InternalListingJob::InternalListingJob( ReadOnlyArchiveInterface *archive, QObject *parent )
: ThreadWeaver::Job( parent ), m_helper( 0 ), m_archive( archive ), m_success( false )
: InternalJob( parent ), m_helper( 0 ), m_archive( archive )
{
}
......@@ -50,12 +58,12 @@ namespace Kerfuffle
this, SIGNAL( progress( double ) ) );
connect( m_helper, SIGNAL( error( const QString&, const QString& ) ),
this, SIGNAL( error( const QString&, const QString& ) ) );
m_success = m_helper->getTheListing();
setSuccess( m_helper->getTheListing() );
}
InternalExtractJob::InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths, QObject *parent )
: ThreadWeaver::Job( parent ), m_archive( archive ), m_files( files ), m_destinationDirectory( destinationDirectory ),
m_helper( 0 ), m_success( false ), m_preservePaths( preservePaths )
: InternalJob( parent ), m_archive( archive ), m_files( files ), m_destinationDirectory( destinationDirectory ),
m_helper( 0 ), m_preservePaths( preservePaths )
{
}
......@@ -74,12 +82,12 @@ namespace Kerfuffle
connect( m_helper, SIGNAL( error( const QString&, const QString& ) ),
this, SIGNAL( error( const QString&, const QString& ) ) );
m_archive->registerObserver( m_helper );
m_success = m_archive->copyFiles( m_files, m_destinationDirectory, m_preservePaths );
setSuccess( m_archive->copyFiles( m_files, m_destinationDirectory, m_preservePaths ) );
m_archive->removeObserver( m_helper );
}
InternalAddJob::InternalAddJob( ReadWriteArchiveInterface *archive, const QStringList & files, QObject *parent )
: ThreadWeaver::Job( parent ), m_files( files ), m_archive( archive ), m_helper( 0 ), m_success( false )
: InternalJob( parent ), m_files( files ), m_archive( archive ), m_helper( 0 )
{
}
......@@ -101,7 +109,35 @@ namespace Kerfuffle
this, SIGNAL( error( const QString&, const QString& ) ) );
m_archive->registerObserver( m_helper );
m_success = m_archive->addFiles( m_files );
setSuccess( m_archive->addFiles( m_files ) );
m_archive->removeObserver( m_helper );
}
InternalDeleteJob::InternalDeleteJob( ReadWriteArchiveInterface *archive, const QList<QVariant> & entries, QObject *parent )
: InternalJob( parent ), m_entries( entries ), m_archive( archive ), m_helper( 0 )
{
}
InternalDeleteJob::~InternalDeleteJob()
{
delete m_helper;
m_helper = 0;
}
void InternalDeleteJob::run()
{
m_helper = new ArchiveJobHelper( m_archive );
// TODO: Connect the signals
connect( m_helper, SIGNAL( entryRemoved( const QString& ) ),
this, SIGNAL( entryRemoved( const QString& ) ) );
connect( m_helper, SIGNAL( progress( double ) ),
this, SIGNAL( progress( double ) ) );
connect( m_helper, SIGNAL( error( const QString&, const QString& ) ),
this, SIGNAL( error( const QString&, const QString& ) ) );
m_archive->registerObserver( m_helper );
setSuccess( m_archive->deleteFiles( m_entries ) );
m_archive->removeObserver( m_helper );
}
......@@ -137,12 +173,12 @@ namespace Kerfuffle
emit progress( d );
}
void ArchiveJobHelper::entryslot( const ArchiveEntry & e )
void ArchiveJobHelper::onEntryRemoved( const QString & path )
{
kDebug( 1601 ) << k_funcinfo << "Entry: " << e[ FileName ] << ", Owner = " << e[ Owner ] << endl;
emit entryRemoved( path );
}
} // namespace Kerfuffle
#include "internaljobs.moc"
......@@ -38,14 +38,29 @@ namespace Kerfuffle
{
class ArchiveJobHelper;
class InternalListingJob: public ThreadWeaver::Job
class InternalJob: public ThreadWeaver::Job
{
Q_OBJECT
public:
InternalJob( QObject *parent = 0 );
~InternalJob();
bool success() const { return m_success; }
protected:
void setSuccess( bool success ) { m_success = success; }
private:
bool m_success;
};
class InternalListingJob: public InternalJob
{
Q_OBJECT
public:
InternalListingJob( ReadOnlyArchiveInterface *archive, QObject *parent = 0 );
~InternalListingJob();
bool success() const { return m_success; }
protected:
void run();
......@@ -58,18 +73,15 @@ namespace Kerfuffle
QList<ArchiveEntry> m_entries;
ArchiveJobHelper *m_helper;
ReadOnlyArchiveInterface *m_archive;
bool m_success;
};
class InternalExtractJob: public ThreadWeaver::Job
class InternalExtractJob: public InternalJob
{
Q_OBJECT
public:
InternalExtractJob( ReadOnlyArchiveInterface *archive, const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths = false, QObject *parent = 0 );
~InternalExtractJob();
bool success() const { return m_success; }
protected:
void run();
......@@ -82,19 +94,16 @@ namespace Kerfuffle
QList<QVariant> m_files;
QString m_destinationDirectory;
ArchiveJobHelper *m_helper;
bool m_success;
bool m_preservePaths;
};
class InternalAddJob: public ThreadWeaver::Job
class InternalAddJob: public InternalJob
{
Q_OBJECT
public:
InternalAddJob( ReadWriteArchiveInterface *archive, const QStringList & files, QObject *parent = 0 );
~InternalAddJob();
bool success() const { return m_success; }
protected:
void run();
......@@ -107,7 +116,26 @@ namespace Kerfuffle
QStringList m_files;
ReadWriteArchiveInterface *m_archive;
ArchiveJobHelper *m_helper;
bool m_success;
};
class InternalDeleteJob: public InternalJob
{
Q_OBJECT
public:
InternalDeleteJob( ReadWriteArchiveInterface *archive, const QList<QVariant> & entries, QObject *parent = 0 );
~InternalDeleteJob();
protected:
void run();
signals:
void entryRemoved( const QString& path );
private:
QList<QVariant> m_entries;
ReadWriteArchiveInterface *m_archive;
ArchiveJobHelper *m_helper;
};
class ArchiveJobHelper: public QObject, public ArchiveObserver
......@@ -121,15 +149,14 @@ namespace Kerfuffle
void onError( const QString & message, const QString & details = QString() );
void onEntry( const ArchiveEntry & archiveEntry );
void onEntryRemoved( const QString & path );
void onProgress( double );
signals:
void entry( const ArchiveEntry & );
void progress( double );
void error( const QString & message, const QString & details );
private slots:
void entryslot( const ArchiveEntry & );
void entryRemoved( const QString & path );
private:
ReadOnlyArchiveInterface *m_archive;
......
......@@ -113,13 +113,16 @@ namespace Kerfuffle
void AddJob::start()
{
emit description( this, i18np( "Adding one file to the archive", "Adding %1 files to the archive", m_files.count() ) );
InternalAddJob *job = new InternalAddJob( m_archive, m_files, this );
connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
this, SLOT( done( ThreadWeaver::Job* ) ) );
connect( job, SIGNAL( progress( double ) ),
this, SLOT( progress( double ) ) );
connect( job, SIGNAL( entry( const ArchiveEntry& ) ),
this, SIGNAL( newEntry( const ArchiveEntry & ) ) );
ThreadWeaver::Weaver::instance()->enqueue( job );
}
......@@ -141,7 +144,15 @@ namespace Kerfuffle
void DeleteJob::start()
{
emit description( this, i18np( "Deleting one file from the archive", "Deleting %n files from the archive", m_files.count() ) );
done( 0 );
InternalDeleteJob *job = new InternalDeleteJob( m_archive, m_files, this );
connect( job, SIGNAL( done( ThreadWeaver::Job* ) ),
this, SLOT( done( ThreadWeaver::Job* ) ) );
connect( job, SIGNAL( progress( double ) ),
this, SLOT( progress( double ) ) );
ThreadWeaver::Weaver::instance()->enqueue( job );
}
void DeleteJob::done( ThreadWeaver::Job *job )
......
......@@ -36,6 +36,7 @@ namespace Kerfuffle
virtual void onError( const QString & message, const QString & details ) = 0;
virtual void onEntry( const ArchiveEntry & archiveEntry ) = 0;
virtual void onProgress( double ) = 0;
virtual void onEntryRemoved( const QString & path ) = 0;
};
} // namespace Kerfuffle
......
......@@ -328,6 +328,11 @@ QModelIndex ArchiveModel::indexForNode( ArchiveNode *node )
return QModelIndex();
}
void ArchiveModel::slotEntryRemoved( const QString & path )
{
// TODO: Do something
}
void ArchiveModel::slotNewEntry( const ArchiveEntry& entry )
{
/// 1. Find Parent Node
......@@ -408,3 +413,17 @@ AddJob* ArchiveModel::addFiles( const QStringList & paths )
this, SLOT( slotNewEntry( const ArchiveEntry& ) ) );
return job;
}
DeleteJob* ArchiveModel::deleteFiles( const QList<QVariant> & files )
{
Q_ASSERT( m_archive );
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 & ) ) );
return job;
}
return 0;
}
......@@ -57,6 +57,7 @@ class ArchiveModel: public QAbstractItemModel
ExtractJob* extractFiles( const QList<QVariant>& files, const QString & destinationDir, bool preservePaths = false );
AddJob* addFiles( const QStringList & paths );
DeleteJob* deleteFiles( const QList<QVariant> & files );
void setJobTracker( KJobTrackerInterface *tracker ) { m_jobTracker = tracker; }
......@@ -68,6 +69,7 @@ class ArchiveModel: public QAbstractItemModel
private slots:
void slotNewEntry( const ArchiveEntry& entry );
void slotEntryRemoved( const QString & path );
private:
ArchiveDirNode* parentFor( const ArchiveEntry& entry );
......
......@@ -330,4 +330,8 @@ void Part::slotAddFiles()
void Part::slotDeleteFiles()
{
kDebug( 1601 ) << k_funcinfo << endl;
DeleteJob *job = m_model->deleteFiles( selectedFiles() );
connect( job, SIGNAL( result( KJob* ) ),
this, SLOT( slotDeleteFilesDone( KJob* ) ) );
job->start();
}
......@@ -73,7 +73,6 @@ class LibZipInterface: public ReadWriteArchiveInterface
*/
entry( e );
kDebug( 1601 ) << k_funcinfo << "Entry for index " << index << " emmited." << endl;
}
bool list()
......@@ -206,6 +205,7 @@ class LibZipInterface: public ReadWriteArchiveInterface
}
zip_delete( m_archive, index );
// TODO: emit some signal to inform the model of the deleted entry
entryRemoved( file.toString() );
}
return true;
}
......
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