32 #include <tqapplication.h>
34 #include <tqmetaobject.h>
36 #include <kapplication.h>
38 #include <ktempfile.h>
42 #include <kio/scheduler.h>
44 #include "kio/netaccess.h"
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 );
201 bool ret = kioNet.statInternal( url, 2 ,
true , window );
203 entry = kioNet.m_entry;
209 if ( url.isLocalFile() )
215 if (!
stat(url, entry, window))
223 KIO::UDSEntry::ConstIterator it = entry.begin();
224 const KIO::UDSEntry::ConstIterator end = entry.end();
225 for ( ; it != end; ++it )
234 if ( !path.isEmpty() )
237 new_url.setPath(path);
253 return kioNet.delInternal( url, window );
264 return kioNet.mkdirInternal( url, permissions, window );
270 return kioNet.fish_executeInternal( url, command, window );
274 KURL* finalURL, TQMap<TQString, TQString>* metaData )
277 return kioNet.synchronousRunInternal( job, window, data, finalURL, metaData );
280 TQString NetAccess::mimetype(
const KURL& url )
283 return kioNet.mimetypeInternal( url, 0 );
286 TQString NetAccess::mimetype(
const KURL& url, TQWidget* window )
289 return kioNet.mimetypeInternal( url, window );
296 if (tmpfiles->contains(name))
298 unlink(TQFile::encodeName(name));
299 tmpfiles->remove(name);
303 bool NetAccess::filecopyInternal(
const KURL& src,
const KURL& target,
int permissions,
304 bool overwrite,
bool resume, TQWidget* window,
bool move)
311 :
KIO::
file_copy( src, target, permissions, overwrite, resume );
313 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
314 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
320 bool NetAccess::dircopyInternal(
const KURL::List& src,
const KURL& target,
321 TQWidget* window,
bool move)
329 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
330 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
336 bool NetAccess::statInternal(
const KURL & url,
int details,
bool source,
344 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
345 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
350 bool NetAccess::delInternal(
const KURL & url, TQWidget* window )
355 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
356 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
361 bool NetAccess::mkdirInternal(
const KURL & url,
int permissions,
367 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
368 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
373 TQString NetAccess::mimetypeInternal(
const KURL & url, TQWidget* window )
376 m_mimetype = TQString::fromLatin1(
"unknown");
379 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
380 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
381 connect( job, TQT_SIGNAL( mimetype (
KIO::Job *,
const TQString &) ),
382 this, TQT_SLOT( slotMimetype (
KIO::Job *,
const TQString &) ) );
387 void NetAccess::slotMimetype(
KIO::Job *,
const TQString & type )
392 TQString NetAccess::fish_executeInternal(
const KURL & url,
const TQString command, TQWidget* window)
394 TQString target, remoteTempFileName, resultData;
397 tmpFile.setAutoDelete(
true );
399 if( url.protocol() ==
"fish" )
403 remoteTempFileName = tmpFile.name();
406 int pos = remoteTempFileName.findRev(
'/');
407 remoteTempFileName =
"/tmp/fishexec_" + remoteTempFileName.mid(pos + 1);
408 tempPathUrl.setPath( remoteTempFileName );
410 TQByteArray packedArgs;
411 TQDataStream stream( packedArgs, IO_WriteOnly );
413 stream << int(
'X') << tempPathUrl << command;
417 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
418 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
424 TQFile resultFile( target );
426 if (resultFile.open( IO_ReadOnly ))
428 TQTextStream ts( &resultFile );
429 ts.setEncoding( TQTextStream::Locale );
430 resultData = ts.read();
438 resultData = i18n(
"ERROR: Unknown protocol '%1'" ).arg( url.protocol() );
443 bool NetAccess::synchronousRunInternal(
Job* job, TQWidget* window, TQByteArray* data,
444 KURL* finalURL, TQMap<TQString,TQString>* metaData )
448 m_metaData = metaData;
450 for ( TQMap<TQString, TQString>::iterator it = m_metaData->begin(); it != m_metaData->end(); ++it ) {
462 connect( job, TQT_SIGNAL( result (
KIO::Job *) ),
463 this, TQT_SLOT( slotResult (
KIO::Job *) ) );
465 TQMetaObject *meta = job->metaObject();
467 static const char dataSignal[] =
"data(KIO::Job*,const " TQBYTEARRAY_OBJECT_NAME_STRING
"&)";
468 if ( meta->findSignal( dataSignal ) != -1 ) {
469 connect( job, TQT_SIGNAL(data(
KIO::Job*,
const TQByteArray&)),
470 this, TQT_SLOT(slotData(
KIO::Job*,
const TQByteArray&)) );
473 static const char redirSignal[] =
"redirection(KIO::Job*,const KURL&)";
474 if ( meta->findSignal( redirSignal ) != -1 ) {
475 connect( job, TQT_SIGNAL(redirection(
KIO::Job*,
const KURL&)),
476 this, TQT_SLOT(slotRedirection(
KIO::Job*,
const KURL&)) );
490 void qt_enter_modal( TQWidget *widget );
491 void qt_leave_modal( TQWidget *widget );
493 void NetAccess::enter_loop()
495 TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
496 dummy.setFocusPolicy( TQ_NoFocus );
497 qt_enter_modal(&dummy);
499 qt_leave_modal(&dummy);
502 void NetAccess::slotResult(
KIO::Job * job )
504 lastErrorCode = job->
error();
505 bJobOK = !job->
error();
509 lastErrorMsg =
new TQString;
512 if ( job->isA(
"KIO::StatJob") )
513 m_entry =
static_cast<KIO::StatJob *
>(job)->statResult();
521 void NetAccess::slotData(
KIO::Job*,
const TQByteArray& data )
523 if ( data.isEmpty() )
526 unsigned offset = m_data.size();
527 m_data.resize( offset + data.size() );
528 std::memcpy( m_data.data() + offset, data.data(), data.size() );
531 void NetAccess::slotRedirection(
KIO::Job*,
const KURL& url )
536 #include "netaccess.moc"
The base class for all jobs.
TQString errorString() const
void addMetaData(const TQString &key, const TQString &value)
int error() const
Returns the error code, if there has been an error.
void setWindow(TQWidget *window)
MetaData metaData() const
static bool move(const KURL &src, const KURL &target, TQWidget *window=0L)
Full-fledged equivalent of KIO::move.
static bool del(const KURL &url, TQWidget *window)
Deletes a file or a directory in a synchronous way.
static bool download(const KURL &src, TQString &target, TQWidget *window)
Downloads a file from an arbitrary URL (src) to a temporary file on the local filesystem (target).
static bool exists(const KURL &url, bool source, TQWidget *window)
Tests whether a URL exists.
static bool file_move(const KURL &src, const KURL &target, int permissions=-1, bool overwrite=false, bool resume=false, TQWidget *window=0L)
Full-fledged equivalent of KIO::file_move.
static bool synchronousRun(Job *job, TQWidget *window, TQByteArray *data=0, KURL *finalURL=0, TQMap< TQString, TQString > *metaData=0)
This function executes a job in a synchronous way.
static bool upload(const TQString &src, const KURL &target, TQWidget *window)
Uploads file src to URL target.
static bool copy(const KURL &src, const KURL &target, TQWidget *window)
Alternative to upload for copying over the network.
static void removeTempFile(const TQString &name)
Removes the specified file if and only if it was created by KIO::NetAccess as a temporary file for a ...
static KURL mostLocalURL(const KURL &url, TQWidget *window)
Tries to map a local URL for the given URL.
static bool dircopy(const KURL &src, const KURL &target, TQWidget *window)
Alternative method for copying over the network.
static bool stat(const KURL &url, KIO::UDSEntry &entry, TQWidget *window)
Tests whether a URL exists and return information on it.
static TQString fish_execute(const KURL &url, const TQString command, TQWidget *window)
Executes a remote process via the fish ioslave in a synchronous way.
static bool file_copy(const KURL &src, const KURL &dest, int permissions=-1, bool overwrite=false, bool resume=false, TQWidget *window=0L)
Full-fledged equivalent of KIO::file_copy.
static bool mkdir(const KURL &url, TQWidget *window, int permissions=-1)
Creates a directory in a synchronous way.
static void checkSlaveOnHold(bool b)
A simple job (one url and one command).
const KURL & url() const
Returns the SimpleJob's URL.
A KIO job that retrieves information about a file or directory.
void setDetails(short int details)
void setSide(bool source)
A stat() can have two meanings.
A namespace for KIO globals.
TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
KIO_EXPORT StatJob * stat(const KURL &url, bool showProgressInfo=true)
Find all details for one file or directory.
KIO_EXPORT MimetypeJob * mimetype(const KURL &url, bool showProgressInfo=true)
Find mimetype for one file or directory.
KIO_EXPORT SimpleJob * special(const KURL &url, const TQByteArray &data, bool showProgressInfo=true)
Execute any command that is specific to one slave (protocol).
KIO_EXPORT FileCopyJob * file_move(const KURL &src, const KURL &dest, int permissions=-1, bool overwrite=false, bool resume=false, bool showProgressInfo=true)
Move a single file.
KIO_EXPORT DeleteJob * del(const KURL &src, bool shred=false, bool showProgressInfo=true)
Delete a file or directory.
@ UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
KIO_EXPORT CopyJob * move(const KURL &src, const KURL &dest, bool showProgressInfo=true)
Moves a file or directory src to the given destination dest.
KIO_EXPORT SimpleJob * mkdir(const KURL &url, int permissions=-1)
Creates a single directory.