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

ark

bkplugin.cpp

Go to the documentation of this file.
00001 /*
00002  * ark -- archiver for the KDE project
00003  *
00004  * Copyright (C) 2007 Henrique Pinto <henrique.pinto@kdemail.net>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 #include "bkplugin.h"
00022 #include "kerfuffle/archivefactory.h"
00023 
00024 #include <QFile>
00025 #include <KDebug>
00026 
00027 BKInterface::BKInterface( const QString & filename, QObject *parent )
00028     : ReadWriteArchiveInterface( filename, parent )
00029 {
00030 }
00031 
00032 BKInterface::~BKInterface()
00033 {
00034     bk_destroy_vol_info( &m_volInfo );
00035 }
00036 
00037 bool BKInterface::list()
00038 {
00039     int rc;
00040 
00041     rc = bk_init_vol_info( &m_volInfo, true );
00042     if ( rc <= 0 ) return false;
00043 
00044     rc = bk_open_image( &m_volInfo, filename().toAscii().constData() );
00045     if ( rc <= 0 ) return false;
00046 
00047     rc = bk_read_vol_info( &m_volInfo );
00048     if ( rc <= 0 ) return false;
00049 
00050     if(m_volInfo.filenameTypes & FNTYPE_ROCKRIDGE)
00051         rc = bk_read_dir_tree( &m_volInfo, FNTYPE_ROCKRIDGE, true, 0 );
00052     else if(m_volInfo.filenameTypes & FNTYPE_JOLIET)
00053         rc = bk_read_dir_tree( &m_volInfo, FNTYPE_JOLIET, false, 0 );
00054     else
00055         rc = bk_read_dir_tree( &m_volInfo, FNTYPE_9660, false, 0 );
00056     if(rc <= 0) return false;
00057 
00058     return browse( BK_BASE_PTR( &( m_volInfo.dirTree ) ) );
00059 }
00060 
00061 bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, Archive::CopyFlags flags )
00062 {
00063     //TODO: this var should be used!
00064     const bool preservePaths = flags & Archive::PreservePaths;
00065 
00066     foreach( const QVariant& file, files )
00067     {
00068         int rc;
00069 
00070         kDebug( 1601 ) << "Trying to extract " << file.toByteArray() ;
00071         rc = bk_extract( &m_volInfo, file.toByteArray(), QFile::encodeName( destinationDirectory ), true, 0 );
00072         if ( rc <= 0 )
00073         {
00074             error( QString( "Could not extract '%1'" ).arg( file.toString() ) );
00075             return false;
00076         }
00077     }
00078     return true;
00079 }
00080 
00081 bool BKInterface::browse( BkFileBase* base, const QString& prefix )
00082 {
00083     QString name( base->name );
00084     QString fullpath = prefix.isEmpty()? name : prefix + '/' + name;
00085     if ( !name.isEmpty() )
00086     {
00087         ArchiveEntry e;
00088         e[ FileName ] = fullpath;
00089         e[ InternalID ] = '/'+fullpath;
00090 
00091         if ( IS_SYMLINK( base->posixFileMode ) )
00092         {
00093             e[ Link ] = QByteArray( BK_SYMLINK_PTR( base )->target );
00094         }
00095         if ( IS_REG_FILE( base->posixFileMode ) )
00096         {
00097             e[ Size ] = ( qulonglong ) BK_FILE_PTR( base )->size;
00098         }
00099         if ( IS_DIR( base->posixFileMode ) )
00100         {
00101             e[ IsDirectory ] = true;
00102         }
00103 
00104         entry( e );
00105     }
00106 
00107     if ( IS_DIR( base->posixFileMode ) )
00108     {
00109         BkFileBase *child = BK_DIR_PTR( base )->children;
00110         while ( child )
00111         {
00112             if ( !browse( child, fullpath ) )
00113             {
00114                 return false;
00115             }
00116             child = child->next;
00117         }
00118     }
00119 
00120     return true;
00121 }
00122 
00123 bool BKInterface::addFiles( const QString& path, const QStringList & files )
00124 {
00125     Q_UNUSED(files  );
00126   return false;
00127 }
00128 
00129 bool BKInterface::deleteFiles( const QList<QVariant> & files )
00130 {
00131     Q_UNUSED(files  );
00132   return false;
00133 }
00134 
00135 KERFUFFLE_PLUGIN_FACTORY( BKInterface )
00136 

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