[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    KoStore diff for direct file extracting/adding
From:       Lucijan Busch <lucijan () gmx ! at>
Date:       2003-02-01 19:03:19
[Download RAW message or body]

hi

as discussed with david i wrote a patch which enables direct adding of files 
and directoreis into stores and direct extracting files out of stores.

as i usually don't write "fixes" in koffice/lib i attached the .diff instead 
of commiting. please give your approve to commit

thank you
 lucijan

-- 
kexi - http://luci.bux.at/projects/kexi
database management in koffice

lucijan busch
karawankenblickstraße 215
9020 klagenfurt

+43 (699) 11 50 67 32

irc:	lucijan @ irc.freenode.net (#kexi, #koffice, #kde-devel)
icq:	#43746208
["addextract.diff" (text/x-diff)]

? addextract.diff
Index: koStore.cc
===================================================================
RCS file: /home/kde/koffice/lib/store/koStore.cc,v
retrieving revision 1.36
diff -r1.36 koStore.cc
34a35
> #include <qdir.h>
371a373,473
> 
> bool KoStore::addLocalFile( const QString &fileName, const QString &destName )
> {
>   QFileInfo fi( fileName );
>   uint size = fi.size();
>   QFile file( fileName );
>   if ( !file.open( IO_ReadOnly ))
>   {
>     return false;
>   }
> 
>   if ( !open ( destName ) )
>   {
>     return false;
>   }
> 
>   QByteArray data ( 8 * 1024 );
> 
>   uint total = 0;
>   for ( int block = 0; ( block = file.readBlock ( data.data(), data.size() ) ) > 0; total += block )
>   {
>     write( data );
>   }
>   Q_ASSERT( total == size );
> 
>   close();
>   file.close();
> 
>   return true;
> }
> 
> bool KoStore::extractFile ( const QString &srcName, const QString &fileName )
> {
>   if ( !open ( srcName ) )
>     return false;
> 
>   uint dsize = size();
> 
>   if( dsize == -1 )
>   {
>     close();
>     return false;
>   }
> 
>   QFile file( fileName );
> 
>   if( !file.open ( IO_WriteOnly ) )
>   {
>     close();
>     return false;
>   }
> 
>   QByteArray data ( 8 * 1024 );
>   uint total = 0;
>   for( int block = 0; ( block = read ( data.data(), data.size() ) ) > 0; total += block )
>   {
>     file.writeBlock ( data.data(), data.size() );
>   }
> 
>   Q_ASSERT( total == dsize );
> 
>   file.close();
>   close();
> 
>   return true;
> }
> 
> QStringList KoStore::addLocalDirectory( const QString &dirPath, const QString &destName )
> {
>   QString dot = ".";
>   QString dotdot = "..";
>   QStringList content;
> 
>   QDir dir(dirPath);
>   if ( !dir.exists() )
>     return 0;
> 
>   QStringList files = dir.entryList();
>   for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it )
>   {
>      if ( *it != dot && *it != dotdot )
>      {
>         QString currentFile = dirPath + "/" + *it;
>         QString dest = destName.isEmpty() ? *it : (destName + "/" + *it);
> 
>         QFileInfo fi ( currentFile );
>         if ( fi.isFile() )
>         {
>           addLocalFile ( currentFile, dest );
>           content.append(dest);
>         }
>         else if ( fi.isDir() )
>         {
>           content += addLocalDirectory ( currentFile, dest );
>         }
>      }
>   }
> 
>   return content;
> }
> 
Index: koStore.h
===================================================================
RCS file: /home/kde/koffice/lib/store/koStore.h,v
retrieving revision 1.37
diff -r1.37 koStore.h
171a172,194
>   /**
>    * Imports a local file into a store
>    * @param fileName file on hard disk
>    * @param destName file in the store
>    */
>   bool addLocalFile( const QString &fileName, const QString &destName );
> 
>   /**
>    * Imports a local directory
>    * @param dirPath path to the directory on a disk
>    * @param dest path in the store where the direcotry should get saved
>    * @returns the directory index
>    */
>   QStringList addLocalDirectory( const QString &dirPath, const QString &dest );
> 
> 
>   /**
>    * Extracts a file out of the store
>    * @param srcName file in the store
>    * @param fileName file on a disk
>    */
>   bool extractFile( const QString &srcName, const QString &fileName );
> 

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic