# class SlaveBase

###

Module | kio
Namespace | KIO
Class | SlaveBase
Inherits |

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.

### enums

- MessageBoxType { QuestionYesNo, WarningYesNo, WarningContinueCancel, WarningYesNoCancel, Information, SSLMessageBox }

enum details

### methods

- SlaveBase (protocol, pool_socket, app_socket)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  protocol | QByteArray |
  pool_socket | QByteArray |
  app_socket | QByteArray |

- allMetaData ( )

  returns KIO.MetaData

  Internal for ForwardingSlaveBase Contains all metadata (but no config) sent by the application to the slave.

- cacheAuthentication (info)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  info | KIO.AuthInfo |

  Explicitly store authentication information. openPasswordDialog already stores password information automatically, you only need to call this function if you want to store authentication information that is different from the information returned by openPasswordDialog.

- canResume (offset)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  offset | KIO.filesize_t |

  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)

- canResume ( )

  returns Nothing

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

- checkCachedAuthentication (info)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  info | KIO.AuthInfo |

  Checks for cached authentication based on parameters given by info.

  Use this function to check if any cached password exists for the URL given by info. If AuthInfo.realmValue and/or AuthInfo.verifyPath flag is specified, then they will also be factored in determining the presence of a cached password. Note that Auth.url is a required parameter when attempting to check for cached authorization info. Here is a simple example:

      AuthInfo info;
      info.url = KUrl("http://www.foobar.org/foo/bar");
      info.username = "somename";
      info.verifyPath = true;
      if ( !checkCachedAuthentication( info ) )
      {
      if ( !openPasswordDialog(info) )
      ....
      }

  - info See AuthInfo. Returns true if cached Authorization is found, false otherwise.

- chmod (url, permissions)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  permissions | int |

  Change permissions on url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD

- chown (url, owner, group)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  owner | QString |
  group | QString |

  Change ownership of url The slave emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHOWN

- close ( )

  returns Nothing

- closeConnection ( )

  returns Nothing

  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.

- config ( )

  returns KConfigGroup

  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.

- connectSlave (path)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  path | QString |

  internal function to connect a slave to/ disconnect from either the slave pool or the application

- connectTimeout ( )

  returns int

  Returns timeout value for connecting to remote host.

- connected ( )

  returns Nothing

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

- copy (src, dest, permissions, flags)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  src | KUrl |
  dest | KUrl |
  permissions | int |
  flags | KIO.JobFlags |

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

  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.

- data (data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

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

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

  data - the data read by the slave

- dataReq ( )

  returns Nothing

  Asks for data from the job.

  See also readData

- del (url, isfile)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  isfile | bool |

  Delete a file or directory.

  url - file/directory to delete

  isfile - if true, a file should be deleted. if false, a directory should be deleted.

- disconnectSlave ( )

  returns Nothing

- dispatch (command, data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  command | int |
  data | QByteArray |

  Internal

- dispatchLoop ( )

  returns Nothing

  Internal

- dispatchOpenCommand (command, data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  command | int |
  data | QByteArray |

  Internal

- dropNetwork (host)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  host | QString | QString()

  Used by the slave to withdraw a connection requested by requestNetwork. This function cancels the last call to requestNetwork. If a client uses more than one internet connection, it must use dropNetwork(host) to stop each request.

  If KNetMgr is not running, then this is a no-op.

  host - the host passed to requestNetwork

  A slave should call this function every time it disconnect from a host.

- error (_errid, _text)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _errid | int |
  _text | QString |

  Call to signal an error. This also finishes the job, so you must not call finished() after calling this.

  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

  See also KTextBrowser

  _errid - the error code from KIO.Error

  _text - the rich text error message

- errorPage ( )

  returns Nothing

  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.

- exit ( )

  returns Nothing

  Internal Terminate the slave by calling the destructor and then .exit()

- finished ( )

  returns Nothing

  Call to signal successful completion of any command besides openConnection and closeConnection. Do not call this after calling error().

- get (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  get, aka read.

  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

- hasMetaData (key)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  key | QString |

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

- infoMessage (msg)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  msg | QString |

  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.

- listDir (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  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.

- listEntries (_entry)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _entry | KIO.UDSEntryList |

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

  _entry - The UDSEntry containing all of the object attributes.

- listEntry (_entry, ready)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _entry | KIO.UDSEntry |
  ready | bool |

  internal function to be called by the slave. It collects entries and emits them via listEntries when enough of them are there or a certain time frame exceeded (to make sure the app gets some items in time but not too many items one by one as this will cause a drastic performance penalty)

  _entry - The UDSEntry containing all of the object attributes.

  ready - set to true after emitting all items. _entry is not used in this case

- messageBox (type, text, caption, buttonYes, buttonNo)

  returns int

  Argument | Type | Default
  --- | --- | ---
  type | KIO::SlaveBase.MessageBoxType |
  text | QString |
  caption | QString | QString()
  buttonYes | QString | i18n("&Yes")
  buttonNo | QString | i18n("&No")

  Call this to show a message box from the slave

  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.

- messageBox (text, type, caption, buttonYes, buttonNo, dontAskAgainName)

  returns int

  Argument | Type | Default
  --- | --- | ---
  text | QString |
  type | KIO::SlaveBase.MessageBoxType |
  caption | QString | QString()
  buttonYes | QString | i18n("&Yes")
  buttonNo | QString | i18n("&No")
  dontAskAgainName | QString | QString()

  Call this to show a message box from the slave

  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 @p*dontAskAgain will be set to true, otherwise false. Returns a button code, as defined in KMessageBox, or 0 on communication error.

- metaData (key)

  returns QString

  Argument | Type | Default
  --- | --- | ---
  key | QString |

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

- mimeType (_type)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _type | QString |

  Call this in mimetype() and in get(), when you know the mimetype. See mimetype about other ways to implement it.

- mimetype (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  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.

- mkdir (url, permissions)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  permissions | int |

  Create a directory

  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.

- multiGet (data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

  Used for multiple get. Currently only used foir HTTP pielining support.

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

- needSubUrlData ( )

  returns Nothing

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

- open (url, mode)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  mode | QIODevice.OpenMode |

  open.

  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

- openConnection ( )

  returns Nothing

  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.

- openPasswordDialog (info, errorMsg)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  info | KIO.AuthInfo |
  errorMsg | QString | QString()

  Prompt the user for Authorization info (login & password).

  Use this function to request authorization information from the end user. You can also pass an error message which explains why a previous authorization attempt failed. Here is a very simple example:

      KIO.AuthInfo authInfo;
      if ( openPasswordDialog( authInfo ) )
      {
      kDebug() << QLatin1String("User: ")
      << authInfo.username << endl;
      kDebug() << QLatin1String("Password: ")
      << QLatin1String("Not displayed here!") << endl;
      }

  You can also preset some values like the username, caption or comment as follows:

      KIO.AuthInfo authInfo;
      authInfo.caption= "Acme Password Dialog";
      authInfo.username= "Wile E. Coyote";
      QString errorMsg = "You entered an incorrect password.";
      if ( openPasswordDialog( authInfo, errorMsg ) )
      {
      kDebug() << QLatin1String("User: ")
      << authInfo.username << endl;
      kDebug() << QLatin1String("Password: ")
      << QLatin1String("Not displayed here!") << endl;
      }

  You should consider using checkCachedAuthentication() to see if the password is available in kpasswdserver before calling this function.

  A call to this function can fail and return false, if the UIServer could not be started for whatever reason.

  See also checkCachedAuthentication

  info - See AuthInfo.

  errorMsg - Error message to show Returns true if user clicks on "OK", false otherwsie.

- opened ( )

  returns Nothing

  open succedes

  See also open

- position (_pos)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _pos | KIO.filesize_t |

- processedPercent (percent)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  percent | float |

  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.

- processedSize (_bytes)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _bytes | KIO.filesize_t |

  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.

- proxyConnectTimeout ( )

  returns int

  Returns timeout value for connecting to proxy in secs.

- put (url, permissions, flags)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  permissions | int |
  flags | KIO.JobFlags |

  put, i.e. write data into a file.

  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()

- read (size)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  size | KIO.filesize_t |

- readData (buffer)

  returns int

  Argument | Type | Default
  --- | --- | ---
  buffer | QByteArray |

  Read data send by the job, after a dataReq

  buffer - buffer where data is stored Returns 0 on end of data, > 0 bytes read < 0 error

- readTimeout ( )

  returns int

  Returns timeout value for read from subsequent data from remote host in secs.

- redirection (_url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _url | KUrl |

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

- remoteEncoding ( )

  returns KRemoteEncoding

  Returns an object that can translate remote filenames into proper Unicode forms. This encoding can be set by the user.

- rename (src, dest, flags)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  src | KUrl |
  dest | KUrl |
  flags | KIO.JobFlags |

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

  src - where to move the file from

  dest - where to move the file to

  flags: - We support Overwrite here

- reparseConfiguration ( )

  returns Nothing

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

- requestNetwork (host)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  host | QString | QString()

  Used by the slave to check if it can connect to a given host. This should be called where the slave is ready to do a .connect() on a socket. For each call to requestNetwork must exist a matching call to dropNetwork, or the system will stay online until KNetMgr gets closed (or the SlaveBase gets destructed)!

  If KNetMgr is not running, then this is a no-op and returns true

  host - tells the netmgr the host the slave wants to connect to. As this could also be a proxy, we can't just take the host currenctly connected to (but that's the default value)

  Returns true in theorie, the host is reachable false the system is offline and the host is in a remote network.

- responseTimeout ( )

  returns int

  Returns timeout value for read from first data from remote host in seconds.

- seek (offset)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  offset | KIO.filesize_t |

- sendMetaData ( )

  returns Nothing

  Internal function to transmit meta data to the application.

- setHost (host, port, user, pass)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  host | QString |
  port | quint16 |
  user | QString |
  pass | QString |

  Set the host

  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.

- setKillFlag ( )

  returns Nothing

  Internally used. Internal

- setLinkDest (url, target)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  target | QString |

  Change the destination of a symlink

  url - the url of the symlink to modify

  target - the new destination (target) of the symlink

- setMetaData (key, value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  key | QString |
  value | QString |

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

- setModificationTime (url, mtime)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  mtime | QDateTime |

  Sets the modification time for url 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

- setSubUrl (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  Prepare slave for streaming operation

- setTimeoutSpecialCommand (timeout, data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  timeout | int |
  data | QByteArray | QByteArray()

  This function sets a timeout of timeout seconds and calls special(data) when the timeout occurs as if it was called by the application.

  A timeout can only occur when the slave is waiting for a command from the application.

  Specifying a negative timeout cancels a pending timeout.

  Only one timeout at a time is supported, setting a timeout cancels any pending timeout.

- slaveStatus (host, connected)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  host | QString |
  connected | bool |

  Used to report the status of the slave.

  host - the slave is currently connected to. (Should be empty if not connected)

  connected - Whether an actual network connection exists.

- slave_status ( )

  returns Nothing

  Called to get the status of the slave. Slave should respond by calling slaveStatus(...)

- special (data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

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

  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.

- speed (_bytes_per_second)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _bytes_per_second | unsigned long |

  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)

- stat (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  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.

- statEntry (_entry)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _entry | KIO.UDSEntry |

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

  _entry - The UDSEntry containing all of the object attributes.

- symlink (target, dest, flags)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  target | QString |
  dest | KUrl |
  flags | KIO.JobFlags |

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

  target - The string that will become the "target" of the link (can be relative)

  dest - The symlink to create.

  flags: - We support Overwrite here

- totalSize (_bytes)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _bytes | KIO.filesize_t |

  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.

- virtual_hook (id, data)

  returns Nothing
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  id | int |
  data | void |

- waitForAnswer (expected1, expected2, data)

  returns int, int (pCmd)

  Argument | Type | Default
  --- | --- | ---
  expected1 | int |
  expected2 | int |
  data | QByteArray |

  Wait for an answer to our request, until we get expected1 or expected2 Returns the result from readData, as well as the cmd in *pCmd if set, and the data in data

- warning (msg)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  msg | QString |

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

- wasKilled ( )

  returns bool

  If your ioslave was killed by a signal, wasKilled() returns true. Check it regularly in lengthy functions (e.g. in get();) and return as fast as possible from this function if wasKilled() returns true. This will ensure that your slave destructor will be called correctly.

- write (data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

- written (_bytes)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  _bytes | KIO.filesize_t |

### enums - detail

- MessageBoxType { QuestionYesNo, WarningYesNo, WarningContinueCancel, WarningYesNoCancel, Information, SSLMessageBox }

  | QuestionYesNo | - 1 | - |
  | WarningYesNo | - 2 | - |
  | WarningContinueCancel | - 3 | - |
  | WarningYesNoCancel | - 4 | - |
  | Information | - 5 | - |
  | SSLMessageBox | - 6 | - |