Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Creating KParts components, Part 1: Build KParts components

David Faure (faure@kde.org), Maintainer of Konqueror, MandrakeSoft
David Faure is a French KDE Developer working for MandrakeSoft and the maintainer of Konqueror, the file manager and Web browser. He also works on the KDE libraries (component technology and network transparency) and on KOffice (framework and KWord). His experience with KParts stems directly from his involvement in the design and development of KParts, particularly before the KDE 2.0 release. You can contact him at faure@kde.org.

Summary:  This tutorial shows you how to build and deploy a KParts component, how to provide extra functionality through the component's actions, and how to improve integration into Konqueror with the Browser Extension.

View more content in this series

Date:  21 May 2002
Level:  Introductory PDF:  A4 and Letter (92 KB | 19 pages)Get Adobe® Reader®

Activity:  7289 views
Comments:  

Extending components

The Browser Extension

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


Developing a read-write part

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.

6 of 8 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=132914
TutorialTitle=Creating KParts components, Part 1: Build KParts components
publish-date=05212002
author1-email=faure@kde.org
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.