KParts.BrowserRun

KDE 4.9 PyKDE API Reference

- KDE's Python API

# BrowserRun Class Reference

`from PyKDE4.kparts import *`

Inherits: KRun → QObject
Namespace: KParts

## Detailed Description

This class extends KRun to provide additional functionality for browsers: - "save or open" dialog boxes - "save" functionality - support for HTTP POST (including saving the result to a temp file if opening a separate application) - warning before launching executables off the web - custom error handling (i.e. treating errors as HTML pages) - generation of SSL metadata depending on the previous URL shown by the part

Author:
  David Faure <faure@kde.org>

## Enumerations
AskEmbedOrSaveFlags | { InlineDisposition, AttachmentDisposition }
AskSaveResult | { Save, Open, Cancel }
NonEmbeddableResult | { Handled, NotHandled, Delayed }
## Methods
| __init__ (self, KUrl url, KParts.OpenUrlArguments args, KParts.BrowserArguments browserArgs, KParts.ReadOnlyPart part, QWidget window, bool removeReferrer, bool trustedSource, bool hideErrorDialog=0)
KParts.OpenUrlArguments | arguments (self)
KParts.BrowserArguments | browserArguments (self)
QString | contentDisposition (self)
| handleError (self, KJob job)
KParts.BrowserRun.NonEmbeddableResult | handleNonEmbeddable (self, QString mimeType, KSharedPtr pSelectedService)
bool | hideErrorDialog (self)
| init (self)
KParts.ReadOnlyPart | part (self)
| save (self, KUrl url, QString suggestedFileName)
| scanFile (self)
bool | serverSuggestsSave (self)
| slotBrowserMimetype (self, KIO.Job job, QString type)
| slotBrowserScanFinished (self, KJob job)
| slotCopyToTempFileResult (self, KJob job)
| slotStatResult (self, KJob job)
KUrl | url (self)
## Static Methods
bool | allowExecution (QString mimeType, KUrl url)
KParts.BrowserRun.AskSaveResult | askEmbedOrSave (KUrl url, QString mimeType, QString suggestedFileName=QString(), int flags=0)
KParts.BrowserRun.AskSaveResult | askSave (KUrl url, KSharedPtr offer, QString mimeType, QString suggestedFileName=QString())
bool | isTextExecutable (QString mimeType)
KUrl | makeErrorUrl (int error, QString errorText, QString initialUrl)
| saveUrl (KUrl url, QString suggestedFileName, QWidget window, KParts.OpenUrlArguments args)
| saveUrlUsingKIO (KUrl srcUrl, KUrl destUrl, QWidget window, {QString:QString} metaData)
| simpleSave (KUrl url, QString suggestedFileName, QWidget window=0)

## Method Documentation

__init__ | ( | self, |
|  | KUrl | url,
|  | KParts.OpenUrlArguments | args,
|  | KParts.BrowserArguments | browserArgs,
|  | KParts.ReadOnlyPart | part,
|  | QWidget | window,
|  | bool | removeReferrer,
|  | bool | trustedSource,
|  | bool | hideErrorDialog=0
| ) |  |  |

Parameters:

  | url | the URL we're probing
  | args | URL args - includes reload, metaData, etc.
  | browserArgs | browser-related args - includes data for a HTTP POST, etc.
  | part | the part going to open this URL - can be 0 if not created yet
  | window | the mainwindow - passed to KIO.Job.setWindow()
  | removeReferrer | if true, the "referrer" metadata from args isn't passed on
  | trustedSource | if false, a warning will be shown before launching an executable. Always pass false for trustedSource, except for local directory views.
  | hideErrorDialog | if true, no dialog will be shown in case of errors.

KParts.OpenUrlArguments arguments | ( |  | self ) |

KParts.BrowserArguments browserArguments | ( |  | self ) |

QString contentDisposition | ( |  | self ) |

Returns:
  Suggested disposition by the server (e.g. HTTP content-disposition)

handleError | ( | self, |
|  | KJob | job
| ) |  |  |

Called when an error happens. NOTE: job could be 0L, if you passed hideErrorDialog=true. The default implementation shows a message box, but only when job != 0 .... It is strongly recommended to reimplement this method if you passed hideErrorDialog=true.

KParts.BrowserRun.NonEmbeddableResult handleNonEmbeddable | ( | self, |
|  | QString | mimeType,
|  | KSharedPtr | pSelectedService
| ) |  |  |

Helper for foundMimeType: call this if the mimetype couldn't be embedded

Parameters:

  | mimeType | the mimetype found for the URL
  | pSelectedService | Output variable: pointer to a KService.Ptr, which will be set to the service selected in the BrowserOpenOrSaveQuestion dialog, if any.

How to handle this properly: if pSelectedService is non-zero, then the dialog will show additional "open with" buttons. In your code, you should write:

    if (selectedService) {
    KRun.setPreferredService(selectedService->desktopEntryName());
    // and let this code path fall back to KRun.foundMimeType(mimeType);
    } else {
    KRun.displayOpenWithDialog(url(), m_window, false, suggestedFileName());
    setFinished(true);
    }

Since:
  4.5

bool hideErrorDialog | ( |  | self ) |

init | ( |  | self ) |

Reimplemented from KRun

KParts.ReadOnlyPart part | ( |  | self ) |

save | ( | self, |
|  | KUrl | url,
|  | QString | suggestedFileName
| ) |  |  |

scanFile | ( |  | self ) |

Reimplemented from KRun

bool serverSuggestsSave | ( |  | self ) |

Returns:
  Wheter the returned disposition suggests saving or opening inline

slotBrowserMimetype | ( | self, |
|  | KIO.Job | job,
|  | QString | type
| ) |  |  |

slotBrowserScanFinished | ( | self, |
|  | KJob | job
| ) |  |  |

slotCopyToTempFileResult | ( | self, |
|  | KJob | job
| ) |  |  |

slotStatResult | ( | self, |
|  | KJob | job
| ) |  |  |

KUrl url | ( |  | self ) |

## Static Method Documentation

bool allowExecution | ( | QString | mimeType,
|  | KUrl | url
| ) |  |  |

KParts.BrowserRun.AskSaveResult askEmbedOrSave | ( | KUrl | url,
|  | QString | mimeType,
|  | QString | suggestedFileName=QString(),
|  | int | flags=0
| ) |  |  |

Similar to askSave but for the case where the current application is able to embed the url itself (instead of passing it to another app).

Parameters:

  | url | the URL in question
  | mimeType | the mimetype of the URL
  | suggestedFileName | optional filename suggested by the server
  | flags | set to AttachmentDisposition if suggested by the server

Returns:
  Save, Open or Cancel.

Deprecated:
  use BrowserOpenOrSaveQuestion

      BrowserOpenOrSaveQuestion dlg(parent, url, mimeType, suggestedFileName);
      const BrowserOpenOrSaveQuestion.Result res = dlg.askEmbedOrSave(flags);
      // Important: returns Embed now, not Open!

KParts.BrowserRun.AskSaveResult askSave | ( | KUrl | url,
|  | KSharedPtr | offer,
|  | QString | mimeType,
|  | QString | suggestedFileName=QString()
| ) |  |  |

Ask the user whether to save or open a url in another application.

Parameters:

  | url | the URL in question
  | offer | the application that will be used to open the URL
  | mimeType | the mimetype of the URL
  | suggestedFileName | optional file name suggested by the server

Returns:
  Save, Open or Cancel.

Deprecated:
  use BrowserOpenOrSaveQuestion

      BrowserOpenOrSaveQuestion dlg(parent, url, mimeType, suggestedFileName);
      const BrowserOpenOrSaveQuestion.Result res = dlg.askOpenOrSave();

bool isTextExecutable | ( | QString | mimeType
| ) |  |  |

KUrl makeErrorUrl | ( | int | error,
|  | QString | errorText,
|  | QString | initialUrl
| ) |  |  |

KDE webbrowsing kparts support error urls to display errors in-line in the browser component. This helper method creates the error URL from its parameters.

Parameters:

  | error | the KIO error code (or KIO.ERR_SLAVE_DEFINED if not from KIO)
  | errorText | the text of the error message
  | initialUrl | the URL that we were trying to open (as a string, so that this can support invalid URLs as well)

Since:
  4.6

saveUrl | ( | KUrl | url,
|  | QString | suggestedFileName,
|  | QWidget | window,
|  | KParts.OpenUrlArguments | args
| ) |  |  |

If kget integration is enabled, passes the url to kget. Otherwise, asks the user for a destination url, and calls saveUrlUsingKIO.

Since:
  4.4

saveUrlUsingKIO | ( | KUrl | srcUrl,
|  | KUrl | destUrl,
|  | QWidget | window,
|  | {QString:QString} | metaData
| ) |  |  |

Starts the KIO file copy job to download srcUrl into destUrl.

Since:
  4.4

simpleSave | ( | KUrl | url,
|  | QString | suggestedFileName,
|  | QWidget | window=0
| ) |  |  |

## Enumeration Documentation

AskEmbedOrSaveFlags

Enumerator:

  InlineDisposition = 0 |
  AttachmentDisposition = 1 |

AskSaveResult

Enumerator:

  Save |
  Open |
  Cancel |

NonEmbeddableResult

NotHandled means that foundMimeType should call KRun.foundMimeType, i.e. launch an external app.

Enumerator:

  Handled |
  NotHandled |
  Delayed |