int main(int argc, char **argv) { KCmdLineArgs::init(argc,argv, "netaccesstest", 0, ki18n("netaccesstest"), 0); KApplication app; KUrl srcURL( "ftp://ftp.kde.org/pub/kde/README" ); #ifdef Q_WS_WIN KUrl tmpURL( "file://" + QDir::tempPath() + "/netaccesstest_README" ); #else KUrl tmpURL( "file:/tmp/netaccesstest_README" ); #endif for ( uint i = 0; i < 4 ; ++i ) { kDebug() << "file_copy"; KIO::Job* job = KIO::file_copy(srcURL, tmpURL, -1, KIO::Overwrite); if ( !KIO::NetAccess::synchronousRun(job, 0) ) kError() << "file_copy failed: " << KIO::NetAccess::lastErrorString() << endl; else { QFile f( tmpURL.path() ); if (!f.open(QIODevice::ReadOnly)) kFatal() << "Cannot open: " << f.fileName() << ". The error was: " << f.errorString(); else { f.close(); } } } return 0; }
int main(int argc, char **argv) { KApplication app( argc, argv, "netaccesstest", true /* it _has_ a GUI ! */); KURL srcURL( "ftp://ftp.kde.org/pub/kde/README" ); KURL tmpURL( "file:/tmp/netaccesstest_README" ); for ( uint i = 0; i < 4 ; ++i ) { kdDebug() << "file_copy" << endl; if ( !KIO::NetAccess::file_copy(srcURL, tmpURL, -1, true, false, 0) ) kdError() << "file_copy failed: " << KIO::NetAccess::lastErrorString() << endl; else { QFile f( tmpURL.path() ); if (!f.open(IO_ReadOnly)) kdFatal() << "Cannot open: " << f.name() << ". The error was: " << f.errorString() << endl; else { f.close(); } } } return 0; }
void KugarPart::slotPreferredTemplate( const QString &tpl ) { KURL url( tpl ); QString localtpl; bool isTemp = false; if ( !url.isValid() ) { /* kdDebug() << "mailformed url" << endl;*/ if ( tpl.find( '/' ) >= 0 ) { if ( tpl.startsWith( "." ) ) { KURL tmpURL( m_docURL ); tmpURL.setFileName( "" ); tmpURL.addPath( tpl ); if ( KIO::NetAccess::download( tmpURL, localtpl ) ) isTemp = true; else KMessageBox::sorry( 0, i18n( "Unable to download template file: %1" ).arg( url.prettyURL() ) ); } else localtpl = tpl; } else { QString former_localtpl = localtpl; localtpl = kapp -> dirs() -> findResource( "data", "kugar/templates/" + tpl ); if ( localtpl.isEmpty() ) { KURL tmpURL( m_docURL ); tmpURL.setFileName( "" ); tmpURL.addPath( tpl ); if ( KIO::NetAccess::download( tmpURL, localtpl ) ) isTemp = true; else KMessageBox::sorry( 0, i18n( "Unable to download template file: %1" ).arg( url.prettyURL() ) ); } } } else { if ( KIO::NetAccess::download( url, localtpl ) ) isTemp = true; else KMessageBox::sorry( 0, i18n( "Unable to download template file: %1" ).arg( url.prettyURL() ) ); } /* kdDebug() << "localtpl: " << localtpl.latin1() << endl;*/ if ( !localtpl.isEmpty() ) { QFile f( localtpl ); if ( f.open( IO_ReadOnly ) ) { /* kdDebug() << "localtpl opened" << endl;*/ // Try to find out whether it is a mime multi part file char buf[ 5 ]; if ( f.readBlock( buf, 4 ) == 4 ) { bool isRawXML = ( strncasecmp( buf, "<?xm", 4 ) == 0 ); f.close(); if ( isRawXML ) { /* kdDebug() << "RawXML" << endl;*/ f.open( IO_ReadOnly ); if ( !m_reportEngine -> setReportTemplate( &f ) ) KMessageBox::sorry( 0, i18n( "Invalid template file: %1" ).arg( localtpl ) ); else { m_templateOk = true; /* kdDebug() << "Setting m_templateOk" << endl;*/ } f.close(); } else { KoStore *tmpStore = KoStore::createStore( localtpl, KoStore::Read ); if ( tmpStore->open( "maindoc.xml" ) ) { if ( !m_reportEngine -> setReportTemplate( tmpStore->device() ) ) KMessageBox::sorry( 0, i18n( "%1 is not a valid Kugar Designer template file." ).arg( localtpl ) ); else m_templateOk = true; tmpStore->close(); } else KMessageBox::sorry( 0, i18n( "%1 is not a valid Kugar Designer template file." ).arg( localtpl ) ); delete tmpStore; } } else { f.close(); KMessageBox::sorry( 0, i18n( "Couldn't read the beginning of the template file: %1" ).arg( localtpl ) ); } } else KMessageBox::sorry( 0, i18n( "Unable to open template file: %1" ).arg( localtpl ) ); if ( isTemp ) KIO::NetAccess::removeTempFile( localtpl ); } }