KoStore* KoStore::createStore( QIODevice *device, Mode mode, const QCString & appIdentification, Backend backend ) { if ( backend == Auto ) { if ( mode == KoStore::Write ) backend = DefaultFormat; else { if ( device->open( IO_ReadOnly ) ) { backend = determineBackend( device ); device->close(); } } } switch ( backend ) { case Tar: return new KoTarStore( device, mode, appIdentification ); case Directory: kdError(s_area) << "Can't create a Directory store for a memory buffer!" << endl; // fallback case Zip: return new KoZipStore( device, mode, appIdentification ); default: kdWarning(s_area) << "Unsupported backend requested for KoStore : " << backend << endl; return 0L; } }
KoStore* KoStore::createStore( const QString& fileName, Mode mode, const QCString & appIdentification, Backend backend ) { if ( backend == Auto ) { if ( mode == KoStore::Write ) backend = DefaultFormat; else { QFileInfo inf( fileName ); if ( inf.isDir() ) backend = Directory; else { QFile file( fileName ); if ( file.open( IO_ReadOnly ) ) backend = determineBackend( &file ); else backend = DefaultFormat; // will create a "bad" store (bad()==true) } } } switch ( backend ) { case Tar: return new KoTarStore( fileName, mode, appIdentification ); case Zip: return new KoZipStore( fileName, mode, appIdentification ); case Directory: return new KoDirectoryStore( fileName /* should be a dir name.... */, mode ); default: kdWarning(s_area) << "Unsupported backend requested for KoStore : " << backend << endl; return 0L; } }
KoStore* KoStore::createStore(QWidget* window, const KUrl& url, Mode mode, const QByteArray & appIdentification, Backend backend) { const bool automatic = (backend == Auto); if (url.isLocalFile()) return createStore(url.toLocalFile(), mode, appIdentification, backend); QString tmpFile; if (mode == KoStore::Write) { if (automatic) backend = DefaultFormat; } else { const bool downloaded = KIO::NetAccess::download(url, tmpFile, window); if (!downloaded) { kError(30002) << "Could not download file!" << endl; backend = DefaultFormat; // will create a "bad" store (bad()==true) } else if (automatic) { QFile file(tmpFile); if (file.open(QIODevice::ReadOnly)) { backend = determineBackend(&file); file.close(); } } } switch (backend) { case Tar: return new KoTarStore(window, url, tmpFile, mode, appIdentification); case Zip: #ifdef QCA2 if (automatic && mode == Read) { // When automatically detecting, this might as well be an encrypted file. We'll need to check anyway, so we'll just use the encrypted store. return new KoEncryptedStore(window, url, tmpFile, Read, appIdentification); } #endif return new KoZipStore(window, url, tmpFile, mode, appIdentification); #ifdef QCA2 case Encrypted: return new KoEncryptedStore(window, url, tmpFile, mode, appIdentification); #endif default: kWarning(30002) << "Unsupported backend requested for KoStore (KUrl) : " << backend; KMessageBox::sorry(window, i18n("The directory mode is not supported for remote locations."), i18n("KOffice Storage")); return 0; } }
KoStore* KoStore::createStore( QWidget* window, const KURL& url, Mode mode, const QCString & appIdentification, Backend backend ) { if ( url.isLocalFile() ) return createStore(url.path(), mode, appIdentification, backend ); QString tmpFile; if ( mode == KoStore::Write ) { if ( backend == Auto ) backend = DefaultFormat; } else { const bool downloaded = KIO::NetAccess::download( url, tmpFile, window ); if (!downloaded) { kdError(s_area) << "Could not download file!" << endl; backend = DefaultFormat; // will create a "bad" store (bad()==true) } else if ( backend == Auto ) { QFile file( tmpFile ); if ( file.open( IO_ReadOnly ) ) { backend = determineBackend( &file ); file.close(); } } } switch ( backend ) { case Tar: return new KoTarStore( window, url, tmpFile, mode, appIdentification ); case Zip: return new KoZipStore( window, url, tmpFile, mode, appIdentification ); default: kdWarning(s_area) << "Unsupported backend requested for KoStore (KURL) : " << backend << endl; KMessageBox::sorry( window, i18n("The directory mode is not supported for remote locations."), i18n("KOffice Storage")); return 0L; } }
KoStore* KoStore::createStore(const QString& fileName, Mode mode, const QByteArray & appIdentification, Backend backend) { bool automatic = false; if (backend == Auto) { automatic = true; if (mode == KoStore::Write) backend = DefaultFormat; else { QFileInfo inf(fileName); if (inf.isDir()) backend = Directory; else { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) backend = determineBackend(&file); else backend = DefaultFormat; // will create a "bad" store (bad()==true) } } } switch (backend) { case Tar: return new KoTarStore(fileName, mode, appIdentification); case Zip: #ifdef QCA2 if (automatic && mode == Read) { // When automatically detecting, this might as well be an encrypted file. We'll need to check anyway, so we'll just use the encrypted store. return new KoEncryptedStore(fileName, Read, appIdentification); } #endif return new KoZipStore(fileName, mode, appIdentification); case Directory: return new KoDirectoryStore(fileName /* should be a dir name.... */, mode); #ifdef QCA2 case Encrypted: return new KoEncryptedStore(fileName, mode, appIdentification); #endif default: kWarning(30002) << "Unsupported backend requested for KoStore : " << backend; return 0; } }
KoStore* KoStore::createStore(QIODevice *device, Mode mode, const QByteArray & appIdentification, Backend backend) { bool automatic = false; if (backend == Auto) { automatic = true; if (mode == KoStore::Write) backend = DefaultFormat; else { if (device->open(QIODevice::ReadOnly)) { backend = determineBackend(device); device->close(); } } } switch (backend) { case Tar: return new KoTarStore(device, mode, appIdentification); case Directory: kError(30002) << "Can't create a Directory store for a memory buffer!" << endl; // fallback case Zip: #ifdef QCA2 if (automatic && mode == Read) { // When automatically detecting, this might as well be an encrypted file. We'll need to check anyway, so we'll just use the encrypted store. return new KoEncryptedStore(device, Read, appIdentification); } #endif return new KoZipStore(device, mode, appIdentification); #ifdef QCA2 case Encrypted: return new KoEncryptedStore(device, mode, appIdentification); #endif default: kWarning(30002) << "Unsupported backend requested for KoStore : " << backend; return 0; } }