# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KIO::NetAccess Class Reference

Net Transparency, formerly provided by kfmlib, but now done with KIO::Job. Provides a synchronous interface to io jobs. More...

`#include <netaccess.h>`

Inheritance diagram for KIO::NetAccess:

[legend]
Collaboration diagram for KIO::NetAccess:

[legend]
List of all members.

## Static Public Member Functions

bool | download (const KURL &src, QString &target)
| Downloads a file from an arbitrary URL (`src`) to a temporary file on the local filesystem (`target`).
void | removeTempFile (const QString &name)
| Removes the specified file if and only if it was created by KIO::NetAccess as a temporary file for a former download.
bool | upload (const QString &src, const KURL &target)
| Uploads file `src` to URL `target`.
bool | copy (const KURL &src, const KURL &target)
| Alternative method for copying over the network.
bool | dircopy (const KURL &src, const KURL &target)
| Alternative method for copying over the network.
bool | exists (const KURL &url)
| Tests whether a URL exists.
bool | exists (const KURL &url, bool source)
| Overloaded version of exists A stat() can have two meanings.
bool | stat (const KURL &url, KIO::UDSEntry &entry)
| Tests whether a URL exists and return information on it.
bool | del (const KURL &url)
| Deletes a file or a directory in an synchronous way.
bool | mkdir (const KURL &url, int permissions=-1)
| Creates a directory in a synchronous way.
QString | mimetype (const KURL &url)
| Determines the mimetype of a given URL.
QString | lastErrorString ()
| Returns the error string for the last job, in case it failed.

## Friends

class | I_like_this_class

## Detailed Description

Net Transparency, formerly provided by kfmlib, but now done with KIO::Job. Provides a synchronous interface to io jobs.

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. 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.

Port to kio done by David Faure, faure@kde.org

Definition at line 52 of file netaccess.h.

## Member Function Documentation

bool NetAccess::download | ( | const KURL & | src,
|  | QString & | target
| ) | `[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.

Definition at line 47 of file netaccess.cpp.

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

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 151 of file netaccess.cpp.

References QFile::encodeName(), and KStdAccel::name().

bool NetAccess::upload | ( | const QString & | src,
|  | const KURL & | target
| ) | `[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.

Definition at line 77 of file netaccess.cpp.

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

bool NetAccess::copy | ( | const KURL & | src,
|  | const KURL & | target
| ) | `[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::file_copy (not KIO::copy!). Definition at line 94 of file netaccess.cpp. References copyInternal().

bool NetAccess::dircopy | ( | const KURL & | src,
|  | const KURL & | target
| ) | `[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!. Definition at line 100 of file netaccess.cpp. References dircopyInternal().

bool NetAccess::exists | ( | const KURL & | url | ) | `[static]`

Tests whether a URL exists.

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

Definition at line 106 of file netaccess.cpp.

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

bool NetAccess::exists | ( | const KURL & | url,
|  | bool | source
| ) | `[static]`

Overloaded version of exists A stat() can have two meanings.

Either we want to read from this URL, or to check if we can write to it. First case is "source", second is "dest". It is necessary to know what the StatJob is for, to tune the kioslave's behaviour (e.g. with FTP) 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.

Definition at line 114 of file netaccess.cpp.

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

bool NetAccess::stat | ( | const KURL & | url,
|  | KIO::UDSEntry & | entry
| ) | `[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.

Definition at line 122 of file netaccess.cpp.

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

bool NetAccess::del | ( | const KURL & | url | ) | `[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.

Returns:
  `true` on success, `false` on failure.

Definition at line 131 of file netaccess.cpp.

References delInternal().

bool NetAccess::mkdir | ( | const KURL & | url,
|  | 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.

Returns:
  `true` on success, `false` on failure.

Definition at line 137 of file netaccess.cpp.

References mkdirInternal().

Referenced by KDirOperator::mkdir().

QString NetAccess::mimetype | ( | const KURL & | url | ) | `[static]`

Determines the mimetype of a given URL.

This is a convenience function for KIO::mimetype. You should call this only when really necessary. KMimeType::findByURL can determine extension a lot faster, but less reliably for remote files. Only when findByURL() returns unknown (application/octet-stream) then this one should be used.

Parameters:

  url | The URL whose mimetype we are interested in.

Returns:
  The mimetype name.

Definition at line 143 of file netaccess.cpp.

References mimetypeInternal().

QString KIO::NetAccess::lastErrorString | ( |  | ) | `[inline, static]`

| Returns the error string for the last job, in case it failed. Definition at line 220 of file netaccess.h.

The documentation for this class was generated from the following files:

- netaccess.h
- netaccess.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:25:57 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001