20#include "KoTarStore.h"
27#include <tdeio/netaccess.h>
29KoTarStore::KoTarStore(
const TQString & _filename, Mode _mode,
const TQCString & appIdentification )
31 kdDebug(s_area) <<
"KoTarStore Constructor filename = " << _filename
32 <<
" mode = " << int(_mode) << endl;
34 m_pTar =
new KTar( _filename,
"application/x-gzip" );
37 kdDebug()<<
"appIdentification :"<<appIdentification<<endl;
38 if (
m_bGood && _mode == Write )
39 m_pTar->setOrigFileName( completeMagic( appIdentification ) );
42KoTarStore::KoTarStore( TQIODevice *dev, Mode mode,
const TQCString & appIdentification )
44 m_pTar =
new KTar( dev );
49 m_pTar->setOrigFileName( completeMagic( appIdentification ) );
52KoTarStore::KoTarStore( TQWidget* window,
const KURL& _url,
const TQString & _filename, Mode _mode,
const TQCString & appIdentification )
54 kdDebug(s_area) <<
"KoTarStore Constructor url= " << _url.prettyURL()
55 <<
" filename = " << _filename
56 <<
" mode = " << int(_mode) << endl;
61 if ( _mode == KoStore::Read )
63 m_fileMode = KoStoreBase::RemoteRead;
64 m_localFileName = _filename;
69 m_fileMode = KoStoreBase::RemoteWrite;
70 m_localFileName =
"/tmp/kozip";
73 m_pTar =
new KTar( m_localFileName,
"application/x-gzip" );
77 if (
m_bGood && _mode == Write )
78 m_pTar->setOrigFileName( completeMagic( appIdentification ) );
81KoTarStore::~KoTarStore()
87 if ( m_fileMode == KoStoreBase::RemoteRead )
89 TDEIO::NetAccess::removeTempFile( m_localFileName );
91 else if ( m_fileMode == KoStoreBase::RemoteWrite )
93 TDEIO::NetAccess::upload( m_localFileName,
m_url, m_window );
98TQCString KoTarStore::completeMagic(
const TQCString& appMimetype )
100 kdDebug()<<
"TQCString KoTarStore::completeMagic( const TQCString& appMimetype )********************\n";
101 TQCString res(
"KOffice " );
105 kdDebug()<<
"sssssssssssssssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n";
106 kdDebug()<<
" return :!!!!!!!!!!!!!!! :"<<res<<endl;
110bool KoTarStore::init( Mode _mode )
114 bool good = m_pTar->open( _mode == Write ? IO_WriteOnly : IO_ReadOnly );
116 if ( good && _mode == Read )
117 good = m_pTar->directory() != 0;
124bool KoTarStore::openWrite(
const TQString& )
127 m_byteArray.resize( 0 );
128 m_stream =
new TQBuffer( m_byteArray );
133bool KoTarStore::openRead(
const TQString& name )
135 const KTarEntry * entry = m_pTar->directory()->entry( name );
142 if ( entry->isDirectory() )
144 kdWarning(s_area) <<
name <<
" is a directory !" << endl;
148 KTarFile * f = (KTarFile *) entry;
149 m_byteArray.resize( 0 );
160 kdDebug(s_area) <<
"Writing file " <<
m_sName <<
" into TAR archive. size "
162 if ( !m_pTar->writeFile(
m_sName ,
"user",
"group",
m_iSize, m_byteArray.data() ) )
163 kdWarning( s_area ) <<
"Failed to write " <<
m_sName << endl;
164 m_byteArray.resize( 0 );
168bool KoTarStore::enterRelativeDirectory(
const TQString& dirName )
170 if ( m_mode == Read ) {
171 if ( !m_currentDir ) {
172 m_currentDir = m_pTar->directory();
175 const KArchiveEntry *entry = m_currentDir->entry( dirName );
176 if ( entry && entry->isDirectory() ) {
177 m_currentDir =
dynamic_cast<const KArchiveDirectory*
>( entry );
178 return m_currentDir != 0;
186bool KoTarStore::enterAbsoluteDirectory(
const TQString& path )
188 if ( path.isEmpty() )
193 if ( m_mode == Read ) {
194 m_currentDir =
dynamic_cast<const KArchiveDirectory*
>( m_pTar->directory()->entry( path ) );
195 Q_ASSERT( m_currentDir );
196 return m_currentDir != 0;
202bool KoTarStore::fileExists(
const TQString& absPath )
const
204 return m_pTar->directory()->entry( absPath ) != 0;
KURL m_url
original URL of the remote file (undefined for a local file)
virtual bool closeWrite()=0
TQStringList m_currentPath
The "current directory" (path).
bool m_bGood
Must be set by the constructor.
TQString m_sName
Current filename (between an open() and a close()).
TQIODevice::Offset m_iSize
Current size of the file named m_sName.
virtual bool init(Mode mode)
Init store - called by constructor.
TQIODevice * m_stream
The stream for the current read or write operation.
const char * name(StdAction id)