• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

KIO::SlaveBase

KIO::SlaveBase Class Reference

#include <slavebase.h>

Inheritance diagram for KIO::SlaveBase:

Inheritance graph
[legend]

List of all members.


Detailed Description

There are two classes that specifies the protocol between application (job) and kioslave.

SlaveInterface is the class to use on the application end, SlaveBase is the one to use on the slave end.

Slave implementations should simply inherit SlaveBase

A call to foo() results in a call to slotFoo() on the other end.

Definition at line 49 of file slavebase.h.


Public Types

enum  MessageBoxType {
  QuestionYesNo = 1, WarningYesNo = 2, WarningContinueCancel = 3, WarningYesNoCancel = 4,
  Information = 5, SSLMessageBox = 6
}

Public Member Functions

 SlaveBase (const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket)
virtual ~SlaveBase ()
void exit ()
void dispatchLoop ()
void data (const QByteArray &data)
void dataReq ()
void opened ()
void error (int _errid, const QString &_text)
void connected ()
void finished ()
void needSubUrlData ()
void slaveStatus (const QString &host, bool connected)
void statEntry (const UDSEntry &_entry)
void listEntries (const UDSEntryList &_entry)
bool canResume (KIO::filesize_t offset)
void canResume ()
void totalSize (KIO::filesize_t _bytes)
void processedSize (KIO::filesize_t _bytes)
void position (KIO::filesize_t _pos)
void written (KIO::filesize_t _bytes)
void processedPercent (float percent)
void speed (unsigned long _bytes_per_second)
void redirection (const KUrl &_url)
void errorPage ()
void mimeType (const QString &_type)
void warning (const QString &msg)
void infoMessage (const QString &msg)
int messageBox (MessageBoxType type, const QString &text, const QString &caption=QString(), const QString &buttonYes=i18n("&Yes"), const QString &buttonNo=i18n("&No"))
int messageBox (const QString &text, MessageBoxType type, const QString &caption=QString(), const QString &buttonYes=i18n("&Yes"), const QString &buttonNo=i18n("&No"), const QString &dontAskAgainName=QString())
void setMetaData (const QString &key, const QString &value)
bool hasMetaData (const QString &key) const
QString metaData (const QString &key) const
MetaData allMetaData () const
KConfigGroup * config ()
KRemoteEncoding * remoteEncoding ()
virtual void setHost (const QString &host, quint16 port, const QString &user, const QString &pass)
virtual void setSubUrl (const KUrl &url)
virtual void openConnection ()
virtual void closeConnection ()
virtual void get (const KUrl &url)
virtual void open (const KUrl &url, QIODevice::OpenMode mode)
virtual void read (KIO::filesize_t size)
virtual void write (const QByteArray &data)
virtual void seek (KIO::filesize_t offset)
virtual void close ()
virtual void put (const KUrl &url, int permissions, JobFlags flags)
virtual void stat (const KUrl &url)
virtual void mimetype (const KUrl &url)
virtual void listDir (const KUrl &url)
virtual void mkdir (const KUrl &url, int permissions)
virtual void rename (const KUrl &src, const KUrl &dest, JobFlags flags)
virtual void symlink (const QString &target, const KUrl &dest, JobFlags flags)
virtual void chmod (const KUrl &url, int permissions)
virtual void chown (const KUrl &url, const QString &owner, const QString &group)
virtual void setModificationTime (const KUrl &url, const QDateTime &mtime)
virtual void copy (const KUrl &src, const KUrl &dest, int permissions, JobFlags flags)
virtual void del (const KUrl &url, bool isfile)
virtual void setLinkDest (const KUrl &url, const QString &target)
virtual void special (const QByteArray &data)
virtual void multiGet (const QByteArray &data)
virtual void slave_status ()
virtual void reparseConfiguration ()
int connectTimeout ()
int proxyConnectTimeout ()
int responseTimeout ()
int readTimeout ()
void setTimeoutSpecialCommand (int timeout, const QByteArray &data=QByteArray())
virtual void dispatch (int command, const QByteArray &data)
virtual void dispatchOpenCommand (int command, const QByteArray &data)
int readData (QByteArray &buffer)
void listEntry (const UDSEntry &_entry, bool ready)
void connectSlave (const QString &path)
void disconnectSlave ()
bool openPasswordDialog (KIO::AuthInfo &info, const QString &errorMsg=QString())
bool checkCachedAuthentication (AuthInfo &info)
bool cacheAuthentication (const AuthInfo &info)
bool requestNetwork (const QString &host=QString())
void dropNetwork (const QString &host=QString())
int waitForAnswer (int expected1, int expected2, QByteArray &data, int *pCmd=0)
void sendMetaData ()
bool wasKilled () const
void setKillFlag ()

Protected Member Functions

virtual void virtual_hook (int id, void *data)

Protected Attributes

QByteArray mProtocol
MetaData mOutgoingMetaData
MetaData mIncomingMetaData

Friends

class SlaveBasePrivate

Member Enumeration Documentation

enum KIO::SlaveBase::MessageBoxType

Enumerator:
QuestionYesNo 
WarningYesNo 
WarningContinueCancel 
WarningYesNoCancel 
Information 
SSLMessageBox 

Definition at line 236 of file slavebase.h.


Constructor & Destructor Documentation

SlaveBase::SlaveBase ( const QByteArray &  protocol,
const QByteArray &  pool_socket,
const QByteArray &  app_socket 
)

Definition at line 153 of file slavebase.cpp.

SlaveBase::~SlaveBase (  )  [virtual]

Definition at line 232 of file slavebase.cpp.


Member Function Documentation

void SlaveBase::exit (  ) 

Definition at line 584 of file slavebase.cpp.

void SlaveBase::dispatchLoop (  ) 

Definition at line 240 of file slavebase.cpp.

void SlaveBase::data ( const QByteArray &  data  ) 

Sends data in the slave to the job (i.e.

in get).

To signal end of data, simply send an empty QByteArray().

Parameters:
data the data read by the slave

Definition at line 366 of file slavebase.cpp.

void SlaveBase::dataReq (  ) 

Asks for data from the job.

See also:
readData

Definition at line 372 of file slavebase.cpp.

void SlaveBase::opened (  ) 

open succedes

See also:
open

Definition at line 380 of file slavebase.cpp.

void SlaveBase::error ( int  _errid,
const QString &  _text 
)

Call to signal an error.

This also finishes the job, no need to call finished.

If the Error code is KIO::ERR_SLAVE_DEFINED then the _text should contain the complete translated text of of the error message. This message will be displayed in an KTextBrowser which allows rich text complete with hyper links. Email links will call the default mailer, "exec:/command arg1 arg2" will be forked and all other links will call the default browser.

See also:
KIO::Error

KTextBrowser

Parameters:
_errid the error code from KIO::Error
_text the rich text error message

Definition at line 387 of file slavebase.cpp.

void SlaveBase::connected (  ) 

Call in openConnection, if you reimplement it, when you're done.

Definition at line 402 of file slavebase.cpp.

void SlaveBase::finished (  ) 

Call to signal successful completion of any command (besides openConnection and closeConnection).

Definition at line 407 of file slavebase.cpp.

void SlaveBase::needSubUrlData (  ) 

Call to signal that data from the sub-URL is needed.

Definition at line 421 of file slavebase.cpp.

void SlaveBase::slaveStatus ( const QString &  host,
bool  connected 
)

Used to report the status of the slave.

Parameters:
host the slave is currently connected to. (Should be empty if not connected)
connected Whether an actual network connection exists.

Definition at line 434 of file slavebase.cpp.

void SlaveBase::statEntry ( const UDSEntry &  _entry  ) 

Call this from stat() to express details about an object, the UDSEntry customarily contains the atoms describing file name, size, mimetype, etc.

Parameters:
_entry The UDSEntry containing all of the object attributes.

Definition at line 627 of file slavebase.cpp.

void SlaveBase::listEntries ( const UDSEntryList &  _entry  ) 

Call this in listDir, each time you have a bunch of entries to report.

Parameters:
_entry The UDSEntry containing all of the object attributes.

Definition at line 675 of file slavebase.cpp.

bool SlaveBase::canResume ( KIO::filesize_t  offset  ) 

Call this at the beginning of put(), to give the size of the existing partial file, if there is one.

The offset argument notifies the other job (the one that gets the data) about the offset to use. In this case, the boolean returns whether we can indeed resume or not (we can't if the protocol doing the get() doesn't support setting an offset)

Definition at line 856 of file slavebase.cpp.

void SlaveBase::canResume (  ) 

Call this at the beginning of get(), if the "resume" metadata was set and resuming is implemented by this protocol.

Definition at line 444 of file slavebase.cpp.

void SlaveBase::totalSize ( KIO::filesize_t  _bytes  ) 

Call this in get and copy, to give the total size of the file Call in listDir too, when you know the total number of items.

Definition at line 449 of file slavebase.cpp.

void SlaveBase::processedSize ( KIO::filesize_t  _bytes  ) 

Call this during get and copy, once in a while, to give some info about the current state.

Don't emit it in listDir, listEntries speaks for itself.

Definition at line 463 of file slavebase.cpp.

void SlaveBase::position ( KIO::filesize_t  _pos  ) 

Definition at line 503 of file slavebase.cpp.

void SlaveBase::written ( KIO::filesize_t  _bytes  ) 

Definition at line 497 of file slavebase.cpp.

void SlaveBase::processedPercent ( float  percent  ) 

Only use this if you can't know in advance the size of the copied data.

For example, if you're doing variable bitrate compression of the source.

STUB ! Currently unimplemented. Here now for binary compatibility.

Call this during get and copy, once in a while, to give some info about the current state. Don't emit it in listDir, listEntries speaks for itself.

Definition at line 509 of file slavebase.cpp.

void SlaveBase::speed ( unsigned long  _bytes_per_second  ) 

Call this in get and copy, to give the current transfer speed, but only if it can't be calculated out of the size you passed to processedSize (in most cases you don't want to call it).

Definition at line 515 of file slavebase.cpp.

void SlaveBase::redirection ( const KUrl &  _url  ) 

Call this to signal a redirection The job will take care of going to that url.

Definition at line 521 of file slavebase.cpp.

void SlaveBase::errorPage (  ) 

Tell that we will only get an error page here.

This means: the data you'll get isn't the data you requested, but an error page (usually HTML) that describes an error.

Definition at line 527 of file slavebase.cpp.

void SlaveBase::mimeType ( const QString &  _type  ) 

Call this in mimetype() and in get(), when you know the mimetype.

See mimetype about other ways to implement it.

Definition at line 544 of file slavebase.cpp.

void SlaveBase::warning ( const QString &  msg  ) 

Call to signal a warning, to be displayed in a dialog box.

Definition at line 594 of file slavebase.cpp.

void SlaveBase::infoMessage ( const QString &  msg  ) 

Call to signal a message, to be displayed if the application wants to, for instance in a status bar.

Usual examples are "connecting to host xyz", etc.

Definition at line 600 of file slavebase.cpp.

int SlaveBase::messageBox ( MessageBoxType  type,
const QString &  text,
const QString &  caption = QString(),
const QString &  buttonYes = i18n("&Yes"),
const QString &  buttonNo = i18n("&No") 
)

Call this to show a message box from the slave.

Parameters:
type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
text Message string. May contain newlines.
caption Message box title.
buttonYes The text for the first button. The default is i18n("&Yes").
buttonNo The text for the second button. The default is i18n("&No"). Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. and for Information, none is used.
Returns:
a button code, as defined in KMessageBox, or 0 on communication error.

Definition at line 832 of file slavebase.cpp.

int SlaveBase::messageBox ( const QString &  text,
MessageBoxType  type,
const QString &  caption = QString(),
const QString &  buttonYes = i18n("&Yes"),
const QString &  buttonNo = i18n("&No"),
const QString &  dontAskAgainName = QString() 
)

Call this to show a message box from the slave.

Parameters:
text Message string. May contain newlines.
type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
caption Message box title.
buttonYes The text for the first button. The default is i18n("&Yes").
buttonNo The text for the second button. The default is i18n("&No"). Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. and for Information, none is used.
dontAskAgain A checkbox is added with which further confirmation can be turned off. If the checkbox was ticked *dontAskAgain will be set to true, otherwise false.
Returns:
a button code, as defined in KMessageBox, or 0 on communication error.

Definition at line 838 of file slavebase.cpp.

void SlaveBase::setMetaData ( const QString &  key,
const QString &  value 
)

Sets meta-data to be send to the application before the first data() or finished() signal.

Definition at line 313 of file slavebase.cpp.

bool SlaveBase::hasMetaData ( const QString &  key  )  const

Queries for the existence of a certain config/meta-data entry send by the application to the slave.

Definition at line 332 of file slavebase.cpp.

QString SlaveBase::metaData ( const QString &  key  )  const

Queries for config/meta-data send by the application to the slave.

Definition at line 318 of file slavebase.cpp.

MetaData SlaveBase::allMetaData (  )  const

Definition at line 327 of file slavebase.cpp.

KConfigGroup * SlaveBase::config (  ) 

Returns a configuration object to query config/meta-data information from.

The application provides the slave with all configuration information relevant for the current protocol and host.

Definition at line 341 of file slavebase.cpp.

KRemoteEncoding * SlaveBase::remoteEncoding (  ) 

Returns an object that can translate remote filenames into proper Unicode forms.

This encoding can be set by the user.

Definition at line 357 of file slavebase.cpp.

void SlaveBase::setHost ( const QString &  host,
quint16  port,
const QString &  user,
const QString &  pass 
) [virtual]

Set the host.

Parameters:
host 
port 
user 
pass Called directly by createSlave, this is why there is no equivalent in SlaveInterface, unlike the other methods.
This method is called whenever a change in host, port or user occurs.

Definition at line 723 of file slavebase.cpp.

void SlaveBase::setSubUrl ( const KUrl &  url  )  [virtual]

Prepare slave for streaming operation.

Definition at line 771 of file slavebase.cpp.

void SlaveBase::openConnection ( void   )  [virtual]

Opens the connection (forced) When this function gets called the slave is operating in connection-oriented mode.

When a connection gets lost while the slave operates in connection oriented mode, the slave should report ERR_CONNECTION_BROKEN instead of reconnecting. The user is expected to disconnect the slave in the error handler.

Definition at line 727 of file slavebase.cpp.

void SlaveBase::closeConnection ( void   )  [virtual]

Closes the connection (forced) Called when the application disconnects the slave to close any open network connections.

When the slave was operating in connection-oriented mode, it should reset itself to connectionless (default) mode.

Definition at line 729 of file slavebase.cpp.

void SlaveBase::get ( const KUrl &  url  )  [virtual]

get, aka read.

Parameters:
url the full url for this request. Host, port and user of the URL can be assumed to be the same as in the last setHost() call. The slave emits the data through data

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 739 of file slavebase.cpp.

void SlaveBase::open ( const KUrl &  url,
QIODevice::OpenMode  mode 
) [virtual]

open.

Parameters:
url the full url for this request. Host, port and user of the URL can be assumed to be the same as in the last setHost() call.
mode see QIODevice::OpenMode

Definition at line 741 of file slavebase.cpp.

void SlaveBase::read ( KIO::filesize_t  size  )  [virtual]

Definition at line 743 of file slavebase.cpp.

void SlaveBase::write ( const QByteArray &  data  )  [virtual]

Definition at line 745 of file slavebase.cpp.

void SlaveBase::seek ( KIO::filesize_t  offset  )  [virtual]

Definition at line 747 of file slavebase.cpp.

void SlaveBase::close (  )  [virtual]

Definition at line 749 of file slavebase.cpp.

void SlaveBase::put ( const KUrl &  url,
int  permissions,
JobFlags  flags 
) [virtual]

put, i.e.

write data into a file.

Parameters:
url where to write the file
permissions may be -1. In this case no special permission mode is set.
flags,: We support Overwrite here. Hopefully, we're going to support Resume in the future, too. If the file indeed already exists, the slave should NOT apply the permissions change to it. The support for resuming using .part files is done by calling canResume().
IMPORTANT: Use the "modified" metadata in order to set the modification time of the file.

See also:
canResume()

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 733 of file slavebase.cpp.

void SlaveBase::stat ( const KUrl &  url  )  [virtual]

Finds all details for one file or directory.

The information returned is the same as what listDir returns, but only for one file or directory.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 731 of file slavebase.cpp.

void SlaveBase::mimetype ( const KUrl &  url  )  [virtual]

Finds mimetype for one file or directory.

This method should either emit 'mimeType' or it should send a block of data big enough to be able to determine the mimetype.

If the slave doesn't reimplement it, a get will be issued, i.e. the whole file will be downloaded before determining the mimetype on it - this is obviously not a good thing in most cases.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 751 of file slavebase.cpp.

void SlaveBase::listDir ( const KUrl &  url  )  [virtual]

Lists the contents of url.

The slave should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist, if we don't have enough permissions, or if it is a file It should also emit totalFiles as soon as it knows how many files it will list.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 737 of file slavebase.cpp.

void SlaveBase::mkdir ( const KUrl &  url,
int  permissions 
) [virtual]

Create a directory.

Parameters:
url path to the directory to create
permissions the permissions to set after creating the directory (-1 if no permissions to be set) The slave emits ERR_COULD_NOT_MKDIR if failure.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 763 of file slavebase.cpp.

void SlaveBase::rename ( const KUrl &  src,
const KUrl &  dest,
JobFlags  flags 
) [virtual]

Rename oldname into newname.

If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for copy + del instead.

Parameters:
src where to move the file from
dest where to move the file to
flags,: We support Overwrite here

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 753 of file slavebase.cpp.

void SlaveBase::symlink ( const QString &  target,
const KUrl &  dest,
JobFlags  flags 
) [virtual]

Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.

Parameters:
target The string that will become the "target" of the link (can be relative)
dest The symlink to create.
flags,: We support Overwrite here

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 755 of file slavebase.cpp.

void SlaveBase::chmod ( const KUrl &  url,
int  permissions 
) [virtual]

Change permissions on url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 765 of file slavebase.cpp.

void SlaveBase::chown ( const KUrl &  url,
const QString &  owner,
const QString &  group 
) [virtual]

Change ownership of url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHOWN.

Definition at line 769 of file slavebase.cpp.

void SlaveBase::setModificationTime ( const KUrl &  url,
const QDateTime &  mtime 
) [virtual]

Sets the modification time for For instance this is what CopyJob uses to set mtime on dirs at the end of a copy.

It could also be used to set the mtime on any file, in theory. The usual implementation on unix is to call utime(path, &myutimbuf). The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_SETTIME

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 767 of file slavebase.cpp.

void SlaveBase::copy ( const KUrl &  src,
const KUrl &  dest,
int  permissions,
JobFlags  flags 
) [virtual]

Copy src into dest.

If the slave returns an error ERR_UNSUPPORTED_ACTION, the job will ask for get + put instead.

Parameters:
src where to copy the file from (decoded)
dest where to copy the file to (decoded)
permissions may be -1. In this case no special permission mode is set.
flags,: We support Overwrite here
Don't forget to set the modification time of dest to be the modification time of src.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 757 of file slavebase.cpp.

void SlaveBase::del ( const KUrl &  url,
bool  isfile 
) [virtual]

Delete a file or directory.

Parameters:
url file/directory to delete
isfile if true, a file should be deleted. if false, a directory should be deleted.

Reimplemented in KIO::ForwardingSlaveBase.

Definition at line 759 of file slavebase.cpp.

void SlaveBase::setLinkDest ( const KUrl &  url,
const QString &  target 
) [virtual]

Change the destination of a symlink.

Parameters:
url the url of the symlink to modify
target the new destination (target) of the symlink

Definition at line 761 of file slavebase.cpp.

void SlaveBase::special ( const QByteArray &  data  )  [virtual]

Used for any command that is specific to this slave (protocol) Examples are : HTTP POST, mount and unmount (kio_file).

Parameters:
data packed data; the meaning is completely dependent on the slave, but usually starts with an int for the command number. Document your slave's commands, at least in its header file.

Definition at line 735 of file slavebase.cpp.

void SlaveBase::multiGet ( const QByteArray &  data  )  [virtual]

Used for multiple get.

Currently only used foir HTTP pielining support.

Parameters:
data packed data; Contains number of URLs to fetch, and for each URL the URL itself and its associated MetaData.

Definition at line 773 of file slavebase.cpp.

void SlaveBase::slave_status (  )  [virtual]

Called to get the status of the slave.

Slave should respond by calling slaveStatus(...)

Definition at line 777 of file slavebase.cpp.

void SlaveBase::reparseConfiguration (  )  [virtual]

Called by the scheduler to tell the slave that the configuration changed (i.e.

proxy settings) .

Definition at line 780 of file slavebase.cpp.

int SlaveBase::connectTimeout (  ) 

Returns:
timeout value for connecting to remote host.

Definition at line 1194 of file slavebase.cpp.

int SlaveBase::proxyConnectTimeout (  ) 

Returns:
timeout value for connecting to proxy in secs.

Definition at line