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, TQ_SIGNAL( result (
TDEIO::Job *) ),
326 bool NetAccess::dircopyInternal(
const KURL::List& src,
const KURL& target,
327 TQWidget* window,
bool move)
335 connect( job, TQ_SIGNAL( result (
TDEIO::Job *) ),
342 bool NetAccess::statInternal(
const KURL & url,
int details,
bool source,
350 connect( job, TQ_SIGNAL( result (
TDEIO::Job *) ),
356 KURL NetAccess::localURLInternal(
const KURL & url, TQWidget* window )
362 this, TQ_SLOT( slotLocalURL(
TDEIO::Job*,
const KURL&,
bool) ));
367 bool NetAccess::delInternal(
const KURL & url, TQWidget* window )
372 connect( job, TQ_SIGNAL( result (
TDEIO::Job *) ),
378 bool NetAccess::mkdirInternal(
const KURL & url,
int permissions,
384 connect( job, TQ_SIGNAL( result (
TDEIO::Job *) ),
390 TQString NetAccess::mimetypeInternal(
const KURL & url, TQWidget* window )
393 m_mimetype = TQString::fromLatin1(
"unknown");
396 connect( job, TQ_SIGNAL( result (
TDEIO::Job *) ),
398 connect( job, TQ_SIGNAL( mimetype (
TDEIO::Job *,
const TQString &) ),
399 this, TQ_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, TQ_SIGNAL( result (
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, TQ_SIGNAL( result (
TDEIO::Job *) ),
488 TQMetaObject *meta = job->metaObject();
490 static const char dataSignal[] =
"data(TDEIO::Job*,const " "TQByteArray" "&)";
491 if ( meta->findSignal( dataSignal ) != -1 ) {
492 connect( job, TQ_SIGNAL(data(
TDEIO::Job*,
const TQByteArray&)),
493 this, TQ_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, TQ_SIGNAL(redirection(
TDEIO::Job*,
const KURL&)),
499 this, TQ_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( TQWidget::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"
The base class for all jobs.
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)
TQString errorString() const
MetaData metaData() const
A TDEIO job that finds a local URL.
static bool move(const KURL &src, const KURL &target, TQWidget *window=0L)
Full-fledged equivalent of TDEIO::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 stat(const KURL &url, TDEIO::UDSEntry &entry, TQWidget *window)
Tests whether a URL exists and return information on it.
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 TDEIO::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 TDEIO::NetAccess as a temporary file for ...
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 TQString fish_execute(const KURL &url, const TQString command, TQWidget *window)
Executes a remote process via the fish ioslave in a synchronous way.
static KURL localURL(const KURL &url, TQWidget *window)
Returns the output of the localURL TDEIO job.
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 TDEIO::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 TDEIO job that retrieves information about a file or directory.
void setSide(bool source)
A stat() can have two meanings.
void setDetails(short int details)
A namespace for TDEIO globals.
TDEIO_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.
TDEIO_EXPORT CopyJob * move(const KURL &src, const KURL &dest, bool showProgressInfo=true)
Moves a file or directory src to the given destination dest.
TDEIO_EXPORT DeleteJob * del(const KURL &src, bool shred=false, bool showProgressInfo=true)
Delete a file or directory.
TDEIO_EXPORT SimpleJob * special(const KURL &url, const TQByteArray &data, bool showProgressInfo=true)
Execute any command that is specific to one slave (protocol).
TDEIO_EXPORT LocalURLJob * localURL(const KURL &remoteUrl)
Retrieve local URL if available.
TDEIO_EXPORT MimetypeJob * mimetype(const KURL &url, bool showProgressInfo=true)
Find mimetype for one file or directory.
TDEIO_EXPORT SimpleJob * mkdir(const KURL &url, int permissions=-1)
Creates a single directory.
@ UDS_LOCAL_PATH
A local file path if the ioslave display files sitting on the local filesystem (but in another hierar...
TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
TDEIO_EXPORT StatJob * stat(const KURL &url, bool showProgressInfo=true)
Find all details for one file or directory.