32 #include <tqapplication.h>
34 #include <tqmetaobject.h>
36 #include <tdeapplication.h>
37 #include <tdelocale.h>
38 #include <tdetempfile.h>
41 #include <tdeio/job.h>
42 #include <tdeio/scheduler.h>
44 #include "tdeio/netaccess.h"
46 using namespace TDEIO;
48 TQString * NetAccess::lastErrorMsg;
49 int NetAccess::lastErrorCode = 0;
50 TQStringList* NetAccess::tmpfiles;
59 if (u.isLocalFile()) {
62 bool accessible = checkAccess(target, R_OK);
66 lastErrorMsg =
new TQString;
67 *lastErrorMsg = i18n(
"File '%1' is not readable").arg(target);
68 lastErrorCode = ERR_COULD_NOT_READ;
76 target = tmpFile.name();
78 tmpfiles =
new TQStringList;
79 tmpfiles->append(target);
84 dest.setPath( target );
85 return kioNet.filecopyInternal( u, dest, -1,
true ,
86 false, window,
false );
102 if (target.isLocalFile() && target.path() == src)
108 return kioNet.filecopyInternal( s, target, -1,
true ,
109 false, window,
false );
123 bool overwrite,
bool resume, TQWidget* window )
126 return kioNet.filecopyInternal( src, target, permissions, overwrite, resume,
132 bool overwrite,
bool resume, TQWidget* window )
135 return kioNet.filecopyInternal( src, target, permissions, overwrite, resume,
147 srcList.append( src );
154 return kioNet.dircopyInternal( srcList, target, window,
false );
160 srcList.append( src );
164 bool NetAccess::move(
const KURL::List& srcList,
const KURL& target, TQWidget* window )
167 return kioNet.dircopyInternal( srcList, target, window,
true );
187 if ( url.isLocalFile() )
188 return TQFile::exists( url.path() );
190 return kioNet.statInternal( url, 0 , source, window );
196 return kioNet.localURLInternal( url, window );
207 bool ret = kioNet.statInternal( url, 2 ,
true , window );
209 entry = kioNet.m_entry;
215 if ( url.isLocalFile() )
221 if (!
stat(url, entry, window))
229 TDEIO::UDSEntry::ConstIterator it = entry.begin();
230 const TDEIO::UDSEntry::ConstIterator end = entry.end();
231 for ( ; it != end; ++it )
240 if ( !path.isEmpty() )
243 new_url.setPath(path);
259 return kioNet.delInternal( url, window );
270 return kioNet.mkdirInternal( url, permissions, window );
276 return kioNet.fish_executeInternal( url, command, window );
280 KURL* finalURL, TQMap<TQString, TQString>* metaData )
283 return kioNet.synchronousRunInternal( job, window, data, finalURL, metaData );
286 TQString NetAccess::mimetype(
const KURL& url )
289 return kioNet.mimetypeInternal( url, 0 );
292 TQString NetAccess::mimetype(
const KURL& url, TQWidget* window )
295 return kioNet.mimetypeInternal( url, window );
302 if (tmpfiles->contains(name))
304 unlink(TQFile::encodeName(name));
305 tmpfiles->remove(name);
309 bool NetAccess::filecopyInternal(
const KURL& src,
const KURL& target,
int permissions,
310 bool overwrite,
bool resume, TQWidget* window,
bool move)
317 : TDEIO::
file_copy( src, target, permissions, overwrite, resume );
319 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
320 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
326 bool NetAccess::dircopyInternal(
const KURL::List& src,
const KURL& target,
327 TQWidget* window,
bool move)
333 : TDEIO::
copy( src, target );
335 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
336 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
342 bool NetAccess::statInternal(
const KURL & url,
int details,
bool source,
350 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
351 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
356 KURL NetAccess::localURLInternal(
const KURL & url, TQWidget* window )
362 this, TQT_SLOT( slotLocalURL(
TDEIO::Job*,
const KURL&,
bool) ));
367 bool NetAccess::delInternal(
const KURL & url, TQWidget* window )
372 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
373 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
378 bool NetAccess::mkdirInternal(
const KURL & url,
int permissions,
384 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
385 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
390 TQString NetAccess::mimetypeInternal(
const KURL & url, TQWidget* window )
393 m_mimetype = TQString::fromLatin1(
"unknown");
396 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
397 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
398 connect( job, TQT_SIGNAL( mimetype (
TDEIO::Job *,
const TQString &) ),
399 this, TQT_SLOT( slotMimetype (
TDEIO::Job *,
const TQString &) ) );
404 void NetAccess::slotMimetype(
TDEIO::Job *,
const TQString & type )
409 void NetAccess::slotLocalURL(
TDEIO::Job*,
const KURL & url,
bool)
415 TQString NetAccess::fish_executeInternal(
const KURL & url,
const TQString command, TQWidget* window)
417 TQString target, remoteTempFileName, resultData;
420 tmpFile.setAutoDelete(
true );
422 if( url.protocol() ==
"fish" )
426 remoteTempFileName = tmpFile.name();
429 int pos = remoteTempFileName.findRev(
'/');
430 remoteTempFileName =
"/tmp/fishexec_" + remoteTempFileName.mid(pos + 1);
431 tempPathUrl.setPath( remoteTempFileName );
433 TQByteArray packedArgs;
434 TQDataStream stream( packedArgs, IO_WriteOnly );
436 stream << int(
'X') << tempPathUrl << command;
440 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
441 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
447 TQFile resultFile( target );
449 if (resultFile.open( IO_ReadOnly ))
451 TQTextStream ts( &resultFile );
452 ts.setEncoding( TQTextStream::Locale );
453 resultData = ts.read();
461 resultData = i18n(
"ERROR: Unknown protocol '%1'" ).arg( url.protocol() );
466 bool NetAccess::synchronousRunInternal(
Job* job, TQWidget* window, TQByteArray* data,
467 KURL* finalURL, TQMap<TQString,TQString>* metaData )
471 m_metaData = metaData;
473 for ( TQMap<TQString, TQString>::iterator it = m_metaData->begin(); it != m_metaData->end(); ++it ) {
485 connect( job, TQT_SIGNAL( result (
TDEIO::Job *) ),
486 this, TQT_SLOT( slotResult (
TDEIO::Job *) ) );
488 TQMetaObject *meta = job->metaObject();
490 static const char dataSignal[] =
"data(TDEIO::Job*,const " TQBYTEARRAY_OBJECT_NAME_STRING
"&)";
491 if ( meta->findSignal( dataSignal ) != -1 ) {
492 connect( job, TQT_SIGNAL(data(
TDEIO::Job*,
const TQByteArray&)),
493 this, TQT_SLOT(slotData(
TDEIO::Job*,
const TQByteArray&)) );
496 static const char redirSignal[] =
"redirection(TDEIO::Job*,const KURL&)";
497 if ( meta->findSignal( redirSignal ) != -1 ) {
498 connect( job, TQT_SIGNAL(redirection(
TDEIO::Job*,
const KURL&)),
499 this, TQT_SLOT(slotRedirection(
TDEIO::Job*,
const KURL&)) );
513 void tqt_enter_modal( TQWidget *widget );
514 void tqt_leave_modal( TQWidget *widget );
516 void NetAccess::enter_loop()
518 TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
519 dummy.setFocusPolicy( TQ_NoFocus );
520 tqt_enter_modal(&dummy);
522 tqt_leave_modal(&dummy);
525 void NetAccess::slotResult(
TDEIO::Job * job )
527 lastErrorCode = job->
error();
528 bJobOK = !job->
error();
530 if ( !lastErrorMsg ) {
531 lastErrorMsg =
new TQString;
535 if ( job->isA(
"TDEIO::StatJob") ) {
546 void NetAccess::slotData(
TDEIO::Job*,
const TQByteArray& data )
548 if ( data.isEmpty() ) {
552 unsigned offset = m_data.size();
553 m_data.resize( offset + data.size() );
554 std::memcpy( m_data.data() + offset, data.data(), data.size() );
557 void NetAccess::slotRedirection(
TDEIO::Job*,
const KURL& url )
562 #include "netaccess.moc"