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

ark

jobs.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
00003  * Copyright (c) 2008 Harald Hvaal <haraldhv )@@@( stud(dot)ntnu.no>
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00016  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00017  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00018  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00019  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT
00020  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00021  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
00022  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF
00024  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 #include "jobs.h"
00027 #include "threading.h"
00028 
00029 #include <kdebug.h>
00030 #include <KLocale>
00031 #include <QDir>
00032 
00033 namespace Kerfuffle
00034 {
00035 
00036 
00037     Job::Job(ReadOnlyArchiveInterface *interface, QObject *parent)
00038         : KJob(parent),
00039         m_interface(interface)
00040     {
00041         static bool onlyOnce = false;
00042         if (!onlyOnce) {
00043             qRegisterMetaType<QPair<QString, QString> >("QPair<QString,QString>");
00044             onlyOnce = true;
00045         }
00046     }
00047 
00048     void Job::start()
00049     {
00050         ThreadExecution *thread = new ThreadExecution(this);
00051         ThreadWeaver::Weaver::instance()->enqueue( thread );
00052     }
00053 
00054     void Job::onError( const QString & message, const QString & details )
00055     {
00056         setError(1);
00057         setErrorText(message);
00058     }
00059 
00060     void Job::onEntry( const ArchiveEntry & archiveEntry )
00061     {
00062         emit newEntry( archiveEntry );
00063     }
00064 
00065     void Job::onProgress( double value )
00066     {
00067         setPercent( static_cast<unsigned long>( 100.0*value ) );
00068     }
00069 
00070     void Job::onEntryRemoved( const QString & path )
00071     {
00072         emit entryRemoved( path );
00073     }
00074 
00075     ListJob::ListJob( ReadOnlyArchiveInterface *interface, QObject *parent )
00076         : Job( interface, parent ),
00077         m_isSingleFolderArchive(true),
00078         m_isPasswordProtected(false),
00079         m_extractedFilesSize(0)
00080     {
00081         connect(this, SIGNAL(newEntry( const ArchiveEntry&)),
00082                 this, SLOT(onNewEntry( const ArchiveEntry&)));
00083     }
00084 
00085     void ListJob::doWork()
00086     {
00087         emit description( this, i18n( "Listing entries" ) );
00088         m_interface->registerObserver( this );
00089         bool result = m_interface->list();
00090         m_interface->removeObserver( this );
00091 
00092         setError(!result);
00093         emitResult();
00094     }
00095 
00096     void ListJob::onNewEntry(const ArchiveEntry& entry)
00097     {
00098         m_extractedFilesSize += entry[ Size ].toLongLong();
00099         m_isPasswordProtected |= entry [ IsPasswordProtected ].toBool();
00100         if (m_isSingleFolderArchive)
00101         {
00102             QString filename = entry[ FileName ].toString();
00103             if (m_previousEntry.isEmpty()) {
00104                 //store the root path of the filename
00105                 m_previousEntry = filename.split(QDir::separator()).first();
00106             }
00107             else {
00108                 QString newRoot = filename.split(QDir::separator()).first();
00109                 if (m_previousEntry != newRoot) {
00110                     m_isSingleFolderArchive = false;
00111                     m_subfolderName.clear();
00112                 }
00113                 else {
00114                     m_previousEntry = newRoot;
00115                     m_subfolderName = newRoot;
00116                 }
00117             }
00118         }
00119     }
00120 
00121     ExtractJob::ExtractJob( const QList<QVariant>& files, const QString& destinationDir,
00122                             Archive::CopyFlags flags, ReadOnlyArchiveInterface *interface, QObject *parent )
00123         : Job(interface,  parent ), m_files( files ), m_destinationDir( destinationDir ), m_flags(flags)
00124     {
00125     }
00126 
00127     void ExtractJob::doWork()
00128     {
00129         QString desc;
00130         if ( m_files.count() == 0 )
00131         {
00132             desc = i18n( "Extracting all files" );
00133         }
00134         else
00135         {
00136             desc = i18np( "Extracting one file", "Extracting %1 files", m_files.count() );
00137         }
00138         emit description( this, desc );
00139 
00140         m_interface->registerObserver( this );
00141 
00142         kDebug(1601) << "Starting extraction with selected files "
00143             << m_files
00144             << " Destination dir " << m_destinationDir
00145             << " Preserve paths: " << (m_flags & Archive::PreservePaths)
00146             << " Truncate common base: " << (m_flags & Archive::TruncateCommonBase)
00147                     ;
00148 
00149         setError( !m_interface->copyFiles( m_files, m_destinationDir, m_flags ) );
00150         m_interface->removeObserver( this );
00151 
00152         emitResult();
00153 
00154     }
00155 
00156     AddJob::AddJob( const QStringList& files, const CompressionOptions& options , ReadWriteArchiveInterface *interface, QObject *parent )
00157         : Job( interface, parent ), m_files( files ), m_options(options)
00158     {
00159     }
00160 
00161     void AddJob::doWork()
00162     {
00163         emit description( this, i18np( "Adding a file", "Adding %1 files", m_files.count() ) );
00164 
00165         ReadWriteArchiveInterface *m_writeInterface =
00166             qobject_cast<ReadWriteArchiveInterface*>
00167             (m_interface);
00168 
00169         Q_ASSERT(m_writeInterface);
00170         
00171         m_writeInterface->registerObserver( this );
00172         setError( !m_writeInterface->addFiles( m_files, m_options ) );
00173         m_writeInterface->removeObserver( this );
00174 
00175         emitResult();
00176 
00177     }
00178 
00179     DeleteJob::DeleteJob( const QList<QVariant>& files, ReadWriteArchiveInterface *interface, QObject *parent )
00180         : Job( interface, parent ), m_files( files )
00181     {
00182     }
00183 
00184     void DeleteJob::doWork()
00185     {
00186         emit description( this, i18np( "Deleting a file from the archive", "Deleting %1 files", m_files.count() ) );
00187 
00188         ReadWriteArchiveInterface *m_writeInterface =
00189             qobject_cast<ReadWriteArchiveInterface*>
00190             (m_interface);
00191 
00192         Q_ASSERT(m_writeInterface);
00193         
00194         m_writeInterface->registerObserver( this );
00195         setError( !m_writeInterface->deleteFiles( m_files ) );
00196         m_writeInterface->removeObserver( this );
00197 
00198         emitResult();
00199     }
00200 
00201 } // namespace Kerfuffle

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
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
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