kio Library API Documentation

KIO::NetAccess Class Reference

Net Transparency. Provides an easy, synchronous interface to KIO file operations. More...

#include <netaccess.h>

Inheritance diagram for KIO::NetAccess:

QObject List of all members.

Static Public Member Functions

bool download (const KURL &src, QString &target, QWidget *window)
bool download (const KURL &src, QString &target) KDE_DEPRECATED
void removeTempFile (const QString &name)
bool upload (const QString &src, const KURL &target, QWidget *window)
bool upload (const QString &src, const KURL &target) KDE_DEPRECATED
bool copy (const KURL &src, const KURL &target, QWidget *window)
bool copy (const KURL &src, const KURL &target) KDE_DEPRECATED
bool file_copy (const KURL &src, const KURL &dest, int permissions=-1, bool overwrite=false, bool resume=false, QWidget *window=0L)
bool file_move (const KURL &src, const KURL &target, int permissions=-1, bool overwrite=false, bool resume=false, QWidget *window=0L)
bool dircopy (const KURL &src, const KURL &target, QWidget *window)
bool dircopy (const KURL &src, const KURL &target) KDE_DEPRECATED
bool dircopy (const KURL::List &src, const KURL &target, QWidget *window=0L)
bool move (const KURL &src, const KURL &target, QWidget *window=0L)
bool move (const KURL::List &src, const KURL &target, QWidget *window=0L)
bool exists (const KURL &url, bool source, QWidget *window)
bool exists (const KURL &url, QWidget *window) KDE_DEPRECATED
bool exists (const KURL &url) KDE_DEPRECATED
bool exists (const KURL &url, bool source) KDE_DEPRECATED
bool stat (const KURL &url, KIO::UDSEntry &entry, QWidget *window)
bool stat (const KURL &url, KIO::UDSEntry &entry) KDE_DEPRECATED
bool del (const KURL &url, QWidget *window)
bool del (const KURL &url) KDE_DEPRECATED
bool mkdir (const KURL &url, QWidget *window, int permissions=-1)
bool mkdir (const KURL &url, int permissions=-1) KDE_DEPRECATED
QString fish_execute (const KURL &url, const QString command, QWidget *window)
QString mimetype (const KURL &url, QWidget *window)
QString mimetype (const KURL &url) KDE_DEPRECATED
QString lastErrorString ()

Friends

class I_like_this_class

Detailed Description

Net Transparency. Provides an easy, synchronous interface to KIO file operations.

NetAccess allows you to do simple file operation (load, save, copy, delete..) without working with KIO::Job directly. Whereas a KIO::Job is asynchronous, meaning that the developer has to connect slots for it, KIO::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 kio done by David Faure, faure@kde.org

Definition at line 60 of file netaccess.h.


Member Function Documentation

bool NetAccess::download const KURL src,
QString target,
QWidget 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 QString 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):

QString tmpFile; if( KIO::NetAccess::download( u, tmpFile ) ) { loadFile( tmpFile ); KIO::NetAccess::removeTempFile( tmpFile ); }

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

Parameters:
src URL Reference to the file to download.
target String 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.
window main 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 53 of file netaccess.cpp.

References QString::arg(), filecopyInternal(), QString::isEmpty(), KURL::isLocalFile(), KTempFile::name(), KURL::path(), and KURL::setPath().

bool NetAccess::download const KURL src,
QString target
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 48 of file netaccess.cpp.

void NetAccess::removeTempFile const QString name  )  [static]
 

Removes the specified file if and only if it was created by KIO::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:
name Path to temporary file to remove. May not be empty.

Definition at line 242 of file netaccess.cpp.

bool NetAccess::upload const QString src,
const KURL target,
QWidget 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:
src URL Referencing the file to upload.
target URL containing the final location of the file.
window main 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 89 of file netaccess.cpp.

References filecopyInternal(), KURL::isEmpty(), KURL::isLocalFile(), KURL::path(), and KURL::setPath().

Referenced by KIO::pasteData().

bool NetAccess::upload const QString src,
const KURL target
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 84 of file netaccess.cpp.

bool NetAccess::copy const KURL src,
const KURL target,
QWidget 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 KIO::file_copy (not KIO::copy!). It will be renamed file_copy in KDE4, so better use file_copy.

Parameters:
src URL Referencing the file to upload.
target URL containing the final location of the file.
window main 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 112 of file netaccess.cpp.

bool NetAccess::copy const KURL src,
const KURL target
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 107 of file netaccess.cpp.

bool NetAccess::file_copy const KURL src,
const KURL dest,
int  permissions = -1,
bool  overwrite = false,
bool  resume = false,
QWidget window = 0L
[static]
 

Full-fledged equivalent of KIO::file_copy.

Definition at line 117 of file netaccess.cpp.

References filecopyInternal().

bool NetAccess::file_move const KURL src,
const KURL target,
int  permissions = -1,
bool  overwrite = false,
bool  resume = false,
QWidget window = 0L
[static]
 

Full-fledged equivalent of KIO::file_move.

Moves or renames *one file*.

Since:
3.2

Definition at line 126 of file netaccess.cpp.

References filecopyInternal().

bool NetAccess::dircopy const KURL src,
const KURL target,
QWidget 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 KIO::copy!. This means that it can copy files and directories alike (it should have been named copy()).

Parameters:
src URL Referencing the file to upload.
target URL containing the final location of the file.
window main 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 139 of file netaccess.cpp.

References QValueList< KURL >::append().

bool NetAccess::dircopy const KURL src,
const KURL target
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 134 of file netaccess.cpp.

bool NetAccess::dircopy const KURL::List src,
const KURL target,
QWidget window = 0L
[static]
 

Overloaded method, which takes a list of source urls.

Definition at line 146 of file netaccess.cpp.

References dircopyInternal().

bool NetAccess::move const KURL src,
const KURL target,
QWidget window = 0L
[static]
 

Full-fledged equivalent of KIO::move.

Moves or renames one file or directory.

Since:
3.2

Definition at line 152 of file netaccess.cpp.

References QValueList< KURL >::append().

bool NetAccess::move const KURL::List src,
const KURL target,
QWidget window = 0L
[static]
 

Full-fledged equivalent of KIO::move.

Moves or renames a list of files or directories.

Since:
3.2

Definition at line 159 of file netaccess.cpp.

References dircopyInternal().

bool NetAccess::exists const KURL url,
bool  source,
QWidget window
[static]
 

Tests whether a URL exists.

Parameters:
url the url we are testing
source if true, we want to read from that URL. If false, we want to write to it. IMPORTANT: see documentation for KIO::stat for more details about this.
window main 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

Definition at line 180 of file netaccess.cpp.

References QFile::exists(), KURL::isLocalFile(), KURL::path(), and statInternal().

Referenced by KDirOperator::mkdir().

bool NetAccess::exists const KURL url,
QWidget window
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 170 of file netaccess.cpp.

bool NetAccess::exists const KURL url  )  [static]
 

Deprecated:
. Use the function above instead.

Definition at line 165 of file netaccess.cpp.

bool NetAccess::exists const KURL url,
bool  source
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 175 of file netaccess.cpp.

bool NetAccess::stat const KURL url,
KIO::UDSEntry entry,
QWidget window
[static]
 

Tests whether a URL exists and return information on it.

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

Parameters:
url The URL we are testing.
entry The result of the stat. Iterate over the list of atoms to get hold of name, type, size, etc., or use KFileItem.
window main 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 193 of file netaccess.cpp.

References m_entry, statInternal(), and KIO::UDSEntry.

Referenced by KPropertiesDialog::KPropertiesDialog().

bool NetAccess::stat const KURL url,
KIO::UDSEntry entry
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 188 of file netaccess.cpp.

References KIO::UDSEntry.

bool NetAccess::del const KURL url,
QWidget window
[static]
 

Deletes a file or a directory in an synchronous way.

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

Parameters:
url The file or directory to delete.
window main 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 207 of file netaccess.cpp.

References delInternal().

bool NetAccess::del const KURL url  )  [static]
 

Deprecated:
. Use the function above instead.

Definition at line 202 of file netaccess.cpp.

bool NetAccess::mkdir const KURL url,
QWidget window,
int  permissions = -1
[static]
 

Creates a directory in a synchronous way.

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

Parameters:
url The directory to create.
window main 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 218 of file netaccess.cpp.

References mkdirInternal().

Referenced by KDirOperator::mkdir().

bool NetAccess::mkdir const KURL url,
int  permissions = -1
[static]
 

Deprecated:
. Use the function above instead.

Definition at line 213 of file netaccess.cpp.

QString NetAccess::fish_execute const KURL url,
const QString  command,
QWidget window
[static]
 

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

Parameters:
url The 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.
command The command to be executed.
window main 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 224 of file netaccess.cpp.

References fish_executeInternal().

QString NetAccess::mimetype const KURL url  )  [static]
 

Deprecated:
. Use the function above instead.

Definition at line 230 of file netaccess.cpp.

References mimetypeInternal().

QString KIO::NetAccess::lastErrorString  )  [inline, static]
 

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

Returns:
the last error string, or QString::null

Definition at line 392 of file netaccess.h.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kio Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 5 07:16:59 2004 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003