• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • TDEIO
  • NetAccess
Static Public Member Functions | Friends | List of all members
TDEIO::NetAccess Class Reference

#include <netaccess.h>

Inherits TQObject.

Static Public Member Functions

static bool download (const KURL &src, TQString &target, TQWidget *window)
 
static bool download (const KURL &src, TQString &target) TDE_DEPRECATED
 
static void removeTempFile (const TQString &name)
 
static bool upload (const TQString &src, const KURL &target, TQWidget *window)
 
static bool upload (const TQString &src, const KURL &target) TDE_DEPRECATED
 
static bool copy (const KURL &src, const KURL &target, TQWidget *window)
 
static bool copy (const KURL &src, const KURL &target) TDE_DEPRECATED
 
static bool file_copy (const KURL &src, const KURL &dest, int permissions=-1, bool overwrite=false, bool resume=false, TQWidget *window=0L)
 
static bool file_move (const KURL &src, const KURL &target, int permissions=-1, bool overwrite=false, bool resume=false, TQWidget *window=0L)
 
static bool dircopy (const KURL &src, const KURL &target, TQWidget *window)
 
static bool dircopy (const KURL &src, const KURL &target) TDE_DEPRECATED
 
static bool dircopy (const KURL::List &src, const KURL &target, TQWidget *window=0L)
 
static bool move (const KURL &src, const KURL &target, TQWidget *window=0L)
 
static bool move (const KURL::List &src, const KURL &target, TQWidget *window=0L)
 
static KURL localURL (const KURL &url, TQWidget *window)
 
static bool exists (const KURL &url, bool source, TQWidget *window)
 
static bool exists (const KURL &url, TQWidget *window) TDE_DEPRECATED
 
static bool exists (const KURL &url) TDE_DEPRECATED
 
static bool exists (const KURL &url, bool source) TDE_DEPRECATED
 
static bool stat (const KURL &url, TDEIO::UDSEntry &entry, TQWidget *window)
 
static bool stat (const KURL &url, TDEIO::UDSEntry &entry) TDE_DEPRECATED
 
static KURL mostLocalURL (const KURL &url, TQWidget *window)
 
static bool del (const KURL &url, TQWidget *window)
 
static bool del (const KURL &url) TDE_DEPRECATED
 
static bool mkdir (const KURL &url, TQWidget *window, int permissions=-1)
 
static bool mkdir (const KURL &url, int permissions=-1) TDE_DEPRECATED
 
static TQString fish_execute (const KURL &url, const TQString command, TQWidget *window)
 
static bool synchronousRun (Job *job, TQWidget *window, TQByteArray *data=0, KURL *finalURL=0, TQMap< TQString, TQString > *metaData=0)
 
static TQString mimetype (const KURL &url, TQWidget *window)
 
static TQString mimetype (const KURL &url) TDE_DEPRECATED
 
static TQString lastErrorString ()
 
static int lastError ()
 

Friends

class I_like_this_class
 

Detailed Description

Net Transparency.

NetAccess allows you to do simple file operation (load, save, copy, delete...) without working with TDEIO::Job directly. Whereas a TDEIO::Job is asynchronous, meaning that the developer has to connect slots for it, TDEIO::NetAccess provides synchronous downloads and uploads, as well as temporary file creation and removal. The functions appear to be blocking, but the Qt event loop continues running while the operations are handled. This means that the GUI will not freeze.

This class isn't meant to be used as a class but only as a simple namespace for static functions, though an instance of the class is built for internal purposes.

Port to tdeio done by David Faure, faure.nosp@m.@kde.nosp@m..org

Provides an easy, synchronous interface to TDEIO file operations.

Definition at line 59 of file netaccess.h.

Member Function Documentation

◆ copy() [1/2]

bool NetAccess::copy ( const KURL &  src,
const KURL &  target 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 112 of file netaccess.cpp.

◆ copy() [2/2]

bool NetAccess::copy ( const KURL &  src,
const KURL &  target,
TQWidget *  window 
)
static

Alternative to upload for copying over the network.

Overwrite is false, so this will fail if target exists.

This one takes two URLs and is a direct equivalent of TDEIO::file_copy (not TDEIO::copy!). It will be renamed file_copy in KDE4, so better use file_copy.

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure

Definition at line 117 of file netaccess.cpp.

◆ del() [1/2]

bool NetAccess::del ( const KURL &  url)
static
Deprecated:
.

Use the function above instead. Passing NULL as the additional argument will give the same behaviour, but you should try to identify a suitable parent widget if at all possible.

Definition at line 251 of file netaccess.cpp.

◆ del() [2/2]

bool NetAccess::del ( const KURL &  url,
TQWidget *  window 
)
static

Deletes a file or a directory in a synchronous way.

This is a convenience function for TDEIO::del (it saves creating a slot and testing for the job result).

Parameters
urlThe file or directory to delete.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true on success, false on failure.

Definition at line 256 of file netaccess.cpp.

◆ dircopy() [1/3]

bool NetAccess::dircopy ( const KURL &  src,
const KURL &  target 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 139 of file netaccess.cpp.

◆ dircopy() [2/3]

bool NetAccess::dircopy ( const KURL &  src,
const KURL &  target,
TQWidget *  window 
)
static

Alternative method for copying over the network.

Overwrite is false, so this will fail if target exists.

This one takes two URLs and is a direct equivalent of TDEIO::copy!. This means that it can copy files and directories alike (it should have been named copy()).

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure

Definition at line 144 of file netaccess.cpp.

◆ dircopy() [3/3]

bool NetAccess::dircopy ( const KURL::List &  src,
const KURL &  target,
TQWidget *  window = 0L 
)
static

Overloaded method, which takes a list of source URLs.

Definition at line 151 of file netaccess.cpp.

◆ download() [1/2]

bool NetAccess::download ( const KURL &  src,
TQString &  target 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 52 of file netaccess.cpp.

◆ download() [2/2]

bool NetAccess::download ( const KURL &  src,
TQString &  target,
TQWidget *  window 
)
static

Downloads a file from an arbitrary URL (src) to a temporary file on the local filesystem (target).

If the argument for target is an empty string, download will generate a unique temporary filename in /tmp. Since target is a reference to TQString you can access this filename easily. Download will return true if the download was successful, otherwise false.

Special case: If the URL is of kind file:, then no downloading is processed but the full filename is returned in target. That means you have to take care about the target argument. (This is very easy to do, please see the example below.)

Download is synchronous. That means you can use it like this, (assuming u is a string which represents a URL and your application has a loadFile() function):

TQString tmpFile;
if( TDEIO::NetAccess::download( u, tmpFile, window ) )
{
loadFile( tmpFile );
TDEIO::NetAccess::removeTempFile( tmpFile );
} else {
KMessageBox::error(this, TDEIO::NetAccess::lastErrorString() );
}
TDEIO::NetAccess::download
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).
Definition: netaccess.cpp:57
TDEIO::NetAccess::removeTempFile
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 ...
Definition: netaccess.cpp:298
TDEIO::NetAccess::lastErrorString
static TQString lastErrorString()
Returns the error string for the last job, in case it failed.
Definition: netaccess.h:482

Of course, your user interface will still process exposure/repaint events during the download.

If the download fails, lastError() and lastErrorString() will be set.

Parameters
srcURL Reference to the file to download.
targetString containing the final local location of the file. If you insert an empty string, it will return a location in a temporary spot. Note: you are responsible for the removal of this file when you are finished reading it using removeTempFile.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure. Use lastErrorString() to get the reason it failed.
See also
lastErrorString()
Since
3.2

Definition at line 57 of file netaccess.cpp.

◆ exists() [1/4]

bool NetAccess::exists ( const KURL &  url)
static
Deprecated:
.

Use the function above instead.

Definition at line 170 of file netaccess.cpp.

◆ exists() [2/4]

bool NetAccess::exists ( const KURL &  url,
bool  source 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 180 of file netaccess.cpp.

◆ exists() [3/4]

bool NetAccess::exists ( const KURL &  url,
bool  source,
TQWidget *  window 
)
static

Tests whether a URL exists.

Parameters
urlthe URL we are testing
sourceif true, we want to read from that URL. If false, we want to write to it. IMPORTANT: see documentation for TDEIO::stat for more details about this.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if the URL exists and we can do the operation specified by source, false otherwise
Since
3.2

Definition at line 185 of file netaccess.cpp.

◆ exists() [4/4]

bool NetAccess::exists ( const KURL &  url,
TQWidget *  window 
)
static
Deprecated:
.

Use the function above instead.

Since
3.2

Definition at line 175 of file netaccess.cpp.

◆ file_copy()

bool NetAccess::file_copy ( const KURL &  src,
const KURL &  dest,
int  permissions = -1,
bool  overwrite = false,
bool  resume = false,
TQWidget *  window = 0L 
)
static

Full-fledged equivalent of TDEIO::file_copy.

Definition at line 122 of file netaccess.cpp.

◆ file_move()

bool NetAccess::file_move ( const KURL &  src,
const KURL &  target,
int  permissions = -1,
bool  overwrite = false,
bool  resume = false,
TQWidget *  window = 0L 
)
static

Full-fledged equivalent of TDEIO::file_move.

Moves or renames one file.

Since
3.2

Definition at line 131 of file netaccess.cpp.

◆ fish_execute()

TQString NetAccess::fish_execute ( const KURL &  url,
const TQString  command,
TQWidget *  window 
)
static

Executes a remote process via the fish ioslave in a synchronous way.

Parameters
urlThe remote machine where the command should be executed. e.g. fish://someuser@somehost:sshport/ some special cases exist. fish://someuser@localhost/ will use su instead of ssh to connect and execute the command. fish://someuser@localhost:port/ will use ssh to connect and execute the command.
commandThe command to be executed.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
The resulting output of the command that is executed.

Definition at line 273 of file netaccess.cpp.

◆ lastError()

static int TDEIO::NetAccess::lastError ( )
inlinestatic

Returns the error code for the last job, in case it failed.

Returns
the last error code
Since
3.3

Definition at line 489 of file netaccess.h.

◆ lastErrorString()

static TQString TDEIO::NetAccess::lastErrorString ( )
inlinestatic

Returns the error string for the last job, in case it failed.

Note that this is already translated.

Returns
the last error string, or TQString::null

Definition at line 482 of file netaccess.h.

◆ localURL()

KURL NetAccess::localURL ( const KURL &  url,
TQWidget *  window 
)
static

Returns the output of the localURL TDEIO job.

Parameters
urlthe URL we are testing
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
the local URL for the given URL
Since
R14

Definition at line 193 of file netaccess.cpp.

◆ mimetype()

TQString NetAccess::mimetype ( const KURL &  url)
static
Deprecated:
.

Use the function above instead. Passing NULL as the additional argument will give the same behaviour, but you should try to identify a suitable parent widget if at all possible.

Definition at line 286 of file netaccess.cpp.

◆ mkdir() [1/2]

bool NetAccess::mkdir ( const KURL &  url,
int  permissions = -1 
)
static
Deprecated:
.

Use the function above instead. Passing NULL as the additional argument will give the same behaviour, but you should try to identify a suitable parent widget if at all possible.

Definition at line 262 of file netaccess.cpp.

◆ mkdir() [2/2]

bool NetAccess::mkdir ( const KURL &  url,
TQWidget *  window,
int  permissions = -1 
)
static

Creates a directory in a synchronous way.

This is a convenience function for TDEIO::mkdir (it saves creating a slot and testing for the job result).

Parameters
urlThe directory to create.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
permissionsdirectory permissions.
Returns
true on success, false on failure.

Definition at line 267 of file netaccess.cpp.

◆ mostLocalURL()

KURL NetAccess::mostLocalURL ( const KURL &  url,
TQWidget *  window 
)
static

Tries to map a local URL for the given URL.

This is a convenience function for TDEIO::stat + parsing the resulting UDSEntry.

Parameters
urlThe URL we are testing.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
a local URL corresponding to the same ressource than the original URL, or the original URL if no local URL can be mapped
Since
3.5

Definition at line 213 of file netaccess.cpp.

◆ move() [1/2]

bool NetAccess::move ( const KURL &  src,
const KURL &  target,
TQWidget *  window = 0L 
)
static

Full-fledged equivalent of TDEIO::move.

Moves or renames one file or directory.

Since
3.2

Definition at line 157 of file netaccess.cpp.

◆ move() [2/2]

bool NetAccess::move ( const KURL::List &  src,
const KURL &  target,
TQWidget *  window = 0L 
)
static

Full-fledged equivalent of TDEIO::move.

Moves or renames a list of files or directories.

Since
3.2

Definition at line 164 of file netaccess.cpp.

◆ removeTempFile()

void NetAccess::removeTempFile ( const TQString &  name)
static

Removes the specified file if and only if it was created by TDEIO::NetAccess as a temporary file for a former download.

Note: This means that if you created your temporary with KTempFile, use KTempFile::unlink() or KTempFile::setAutoDelete() to have it removed.

Parameters
namePath to temporary file to remove. May not be empty.

Definition at line 298 of file netaccess.cpp.

◆ stat() [1/2]

bool NetAccess::stat ( const KURL &  url,
TDEIO::UDSEntry &  entry 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 199 of file netaccess.cpp.

◆ stat() [2/2]

bool NetAccess::stat ( const KURL &  url,
TDEIO::UDSEntry &  entry,
TQWidget *  window 
)
static

Tests whether a URL exists and return information on it.

This is a convenience function for TDEIO::stat (it saves creating a slot and testing for the job result).

Parameters
urlThe URL we are testing.
entryThe result of the stat. Iterate over the list of atoms to get hold of name, type, size, etc., or use KFileItem.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure

Definition at line 204 of file netaccess.cpp.

◆ synchronousRun()

bool NetAccess::synchronousRun ( Job *  job,
TQWidget *  window,
TQByteArray *  data = 0,
KURL *  finalURL = 0,
TQMap< TQString, TQString > *  metaData = 0 
)
static

This function executes a job in a synchronous way.

If a job fetches some data, pass a TQByteArray pointer as data parameter to this function and after the function returns it will contain all the data fetched by this job.

TDEIO::Job *job = TDEIO::get( url, false, false ); TQMap<TQString, TQString> metaData; metaData.insert( "PropagateHttpHeader", "true" ); if ( NetAccess::synchronousRun( job, 0, &data, &url, &metaData ) ) { TQString responseHeaders = metaData[ "HTTP-Headers" ]; kdDebug()<<"Response header = "<< responseHeaders << endl; }

Parameters
jobjob which the function will run. Note that after this function finishes running, job is deleted and you can't access it anymore!
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
dataif passed and relevant to this job then it will contain the data that was fetched by the job
finalURLif passed will contain the final url of this job (it might differ from the one it was created with if there was a redirection)
metaDatayou can pass a pointer to the map with meta data you wish to set on the job. After the job finishes this map will hold all the meta data from the job.
Returns
true on success, false on failure.
Since
3.4

Definition at line 279 of file netaccess.cpp.

◆ upload() [1/2]

bool NetAccess::upload ( const TQString &  src,
const KURL &  target 
)
static
Deprecated:
.

Use the function above instead.

Definition at line 89 of file netaccess.cpp.

◆ upload() [2/2]

bool NetAccess::upload ( const TQString &  src,
const KURL &  target,
TQWidget *  window 
)
static

Uploads file src to URL target.

Both must be specified, unlike download. Note that this is assumed to be used for saving a file over the network, so overwriting is set to true. This is not the case with copy.

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure
Since
3.2

Definition at line 94 of file netaccess.cpp.


The documentation for this class was generated from the following files:
  • netaccess.h
  • netaccess.cpp

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.1
This website is maintained by Timothy Pearson.