Extending components
If the KXMLTreePart component is meant to be used by
Konqueror to display a certain type of file when clicking on it in the
file manager, better integration with Konqueror can be provided by
creating a BrowserExtension for the part.
This allows, for example, the component to save and restore its state when the user navigates using the back and forward actions in Konqueror, or for session management purposes. It also allows the component to request that a URL be opened by Konqueror. For example, this is used when clicking on a link in the HTML component.
To provide a browser extension for a better integration of a read-only
part into Konqueror, the component usually needs to define a class that
inherits from KParts::BrowserExtension. An instance of that
class must be created by the part's constructor, with the part itself as
the parent object. Konqueror will detect it and use it automatically.
The BrowserExtension-derived class
The BrowserExtension-derived class should re-implement
xOffset() and yOffset() if the component's
widget has scrollbars, as in the case of it inheriting
QScrollView. Reimplementing saveState and
restoreState allows the component to store additional
information in memory, such as when navigating in Konqueror using the back
and forward actions.
The browser extension's signals (which are public, unlike usual
signals) also allow a component, among other things, to open a URL
(openURLRequest), to open a window
(createNewWindow), to show a standard popupmenu for a set of
files (popupMenu), and to change the URL shown in the
location bar (setLocationBarURL).
A read-write part must inherit KParts::ReadWritePart and
implement saveFile(). It must also implement the read-only
status in setReadWrite(bool rw), usually disabling some
actions when rw is false and enabling them when
rw is true. Any action that modifies the data must be
prevented when the part is in read-only mode.
When the user modifies the data in the part, it must call
setModified(). This usually updates the caption bar to show
modified, and enables the confirmation when closing without
saving.
Make sure to specify that the part is read-write in the
.desktop file, using
ServiceTypes=KParts/ReadWritePart, and adapt the factory if
using KDE 2 code (see Factory code to create the part) so that
setReadWrite is called right after creating the
component.
This is how to provide read-write functionality in a KParts component. Note that Konqueror can't use the read-write functionality: it is a design decision that Konqueror only uses read-only components. A separate application is needed to take advantage of the read-write functionality of the component.

