kparts Library API Documentation

KParts::ReadOnlyPart Class Reference

Base class for any "viewer" part. More...

#include <part.h>

Inheritance diagram for KParts::ReadOnlyPart:

KParts::Part QObject KParts::PartBase KXMLGUIClient KParts::ReadWritePart List of all members.

Public Slots

virtual bool openURL (const KURL &url)
 Only reimplement openURL if you don't want synchronous network transparency Otherwise, reimplement openFile() only .


Signals

void started (KIO::Job *)
 The part emits this when starting data.

void completed ()
 Emit this when you have completed loading data.

void completed (bool pendingAction)
 Same as the above signal except besides indicating that the data has been completely loaded it also informs the host, by setting the flag, that a pending action has been generated as a result of completing the requested task (loading the data).

void canceled (const QString &errMsg)
 Emit this if loading is canceled by the user or by an error.


Public Member Functions

 ReadOnlyPart (QObject *parent=0, const char *name=0)
 Constructor See also Part for the setXXX methods to call.

virtual ~ReadOnlyPart ()
 Destructor.

void setProgressInfoEnabled (bool show)
 Call this to turn off the progress info dialog used by the internal KIO job.

bool isProgressInfoEnabled () const
 Returns whether the part shows the progress info dialog used by internal KIO job.

void showProgressInfo (bool show)
KURL url () const
 Returns the currently in part used URL.

virtual bool closeURL ()
 Called when closing the current url (e.g.

bool openStream (const QString &mimeType, const KURL &url)
 Initiate sending data to this part.

bool writeStream (const QByteArray &data)
 Send some data to the part.

bool closeStream ()
 Terminate the sending of data to the part.


Protected Slots

void slotJobFinished (KIO::Job *job)

Protected Member Functions

virtual bool openFile ()=0
 If the part uses the standard implementation of openURL(), it must reimplement this, to open m_file.

void abortLoad ()
virtual void guiActivateEvent (GUIActivateEvent *event)
 Reimplemented from Part, so that the window caption is set to the current url (decoded) when the part is activated This is the usual behaviour in 99% of the apps Reimplement if you don't like it - test for event->activated() !


Protected Attributes

KURL m_url
 Remote (or local) url - the one displayed to the user.

QString m_file
 Local file - the only one the part implementation should deal with.

bool m_bTemp
 If true, m_file is a temporary file that needs to be deleted later.


Detailed Description

Base class for any "viewer" part.

This class takes care of network transparency for you, in the simplest way (synchronously). To use the built-in network transparency, you only need to implement openFile(), not openURL(). To prevent network transparency, or to implement it another way (e.g. asynchronously), override openURL().

KParts Application can use the signals to show feedback while the URL is being loaded.

ReadOnlyPart handles the window caption by setting it to the current URL (set in openURL(), and each time the part is activated). If you want another caption, set it in openFile() and (if the part might ever be used with a part manager) in guiActivateEvent()

Definition at line 290 of file part.h.


Constructor & Destructor Documentation

ReadOnlyPart::ReadOnlyPart QObject parent = 0,
const char *  name = 0
 

Constructor See also Part for the setXXX methods to call.

Definition at line 292 of file part.cpp.

References KStdAccel::name().

ReadOnlyPart::~ReadOnlyPart  )  [virtual]
 

Destructor.

Definition at line 298 of file part.cpp.


Member Function Documentation

void ReadOnlyPart::setProgressInfoEnabled bool  show  ) 
 

Call this to turn off the progress info dialog used by the internal KIO job.

Use this if you provide another way of displaying progress info (e.g. a statusbar), using the signals emitted by this class, and/or those emitted by the Job given by started.

Definition at line 304 of file part.cpp.

bool ReadOnlyPart::isProgressInfoEnabled  )  const
 

Returns whether the part shows the progress info dialog used by internal KIO job.

Definition at line 309 of file part.cpp.

bool ReadOnlyPart::openURL const KURL url  )  [virtual, slot]
 

Only reimplement openURL if you don't want synchronous network transparency Otherwise, reimplement openFile() only .

If you reimplement it, don't forget to set the caption, usually with emit setWindowCaption( url.prettyURL() );

Definition at line 321 of file part.cpp.

References closeURL(), completed(), QObject::connect(), QFileInfo::extension(), KIO::file_copy(), QString::isEmpty(), KURL::isLocalFile(), KURL::isMalformed(), m_bTemp, m_file, m_url, KTempFile::name(), openFile(), KURL::path(), KURL::prettyURL(), KURL::setPath(), KParts::Part::setWindowCaption(), and started().

Referenced by KParts::BrowserExtension::restoreState().

KURL KParts::ReadOnlyPart::url  )  const [inline]
 

Returns the currently in part used URL.

Returns:
The current used URL.

Definition at line 340 of file part.h.

References m_url.

Referenced by KParts::ReadWritePart::queryClose(), and KParts::BrowserExtension::saveState().

bool ReadOnlyPart::closeURL  )  [virtual]
 

Called when closing the current url (e.g.

document), for instance when switching to another url (note that openURL() calls it automatically in this case). If the current URL is not fully loaded yet, aborts loading. Deletes the temporary file used when the url is remote.

Returns:
always true, but the return value exists for reimplementations

Reimplemented in KParts::ReadWritePart.

Definition at line 370 of file part.cpp.

References QFile::encodeName(), m_bTemp, and m_file.

Referenced by openStream(), and openURL().

bool ReadOnlyPart::openStream const QString mimeType,
const KURL url
 

Initiate sending data to this part.

This is an alternative to openURL, which allows the user of the part to load the data itself, and send it progressively to the part.

Parameters:
url the URL representing this data. Although not directly used, every ReadOnlyPart has a URL (see url()), so this simply sets it.
mimeType the type of data that is going to be sent to this part.
Returns:
true if the part supports progressive loading and accepts data, false otherwise.

Definition at line 411 of file part.cpp.

References closeURL(), and m_url.

bool ReadOnlyPart::writeStream const QByteArray data  ) 
 

Send some data to the part.

openStream must have been called previously, and must have returned true.

Returns:
true if the data was accepted by the part. If false is returned, the application should stop sending data, and doesn't have to call closeStream.

Definition at line 419 of file part.cpp.

bool ReadOnlyPart::closeStream  ) 
 

Terminate the sending of data to the part.

With some data types (text, html...) closeStream might never actually be called, in the case of continous streams, for instance plain text or HTML data.

Definition at line 424 of file part.cpp.

void KParts::ReadOnlyPart::started KIO::Job  )  [signal]
 

The part emits this when starting data.

If using a KIO::Job, it sets the job in the signal, so that progress information can be shown. Otherwise, job is 0.

Referenced by openURL().

void KParts::ReadOnlyPart::completed  )  [signal]
 

Emit this when you have completed loading data.

Hosting apps will want to know when the process of loading the data is finished, so that they can access the data when everything is loaded.

Referenced by openURL(), and KParts::ReadWritePart::saveToURL().

void KParts::ReadOnlyPart::completed bool  pendingAction  )  [signal]
 

Same as the above signal except besides indicating that the data has been completely loaded it also informs the host, by setting the flag, that a pending action has been generated as a result of completing the requested task (loading the data).

An example of this is meta-refresh tags on HTML pages which result in the page either being refreshed or the viewer being redirected to another page. By emitting this signal after appropriately setting the flag, the part can tell the host of the pending scheduled action inorder to give it a chance to accept or cancel that action.

pendingAction if true, a pending action exists (ex: a scheduled refresh)

void KParts::ReadOnlyPart::canceled const QString errMsg  )  [signal]
 

Emit this if loading is canceled by the user or by an error.

Parameters:
errMsg the error message, empty if the user canceled the loading voluntarily.

virtual bool KParts::ReadOnlyPart::openFile  )  [protected, pure virtual]
 

If the part uses the standard implementation of openURL(), it must reimplement this, to open m_file.

Otherwise simply define it to { return false; }

Referenced by openURL().

void ReadOnlyPart::guiActivateEvent GUIActivateEvent event  )  [protected, virtual]
 

Reimplemented from Part, so that the window caption is set to the current url (decoded) when the part is activated This is the usual behaviour in 99% of the apps Reimplement if you don't like it - test for event->activated() !

Technical note : this is done with GUIActivateEvent and not with PartActivateEvent because it's handled by the mainwindow (which gets the even after the PartActivateEvent events have been sent)

Reimplemented from KParts::Part.

Definition at line 399 of file part.cpp.

References KNotifyClient::event(), KURL::isEmpty(), m_url, KURL::prettyURL(), and KParts::Part::setWindowCaption().


Member Data Documentation

KURL KParts::ReadOnlyPart::m_url [protected]
 

Remote (or local) url - the one displayed to the user.

Definition at line 469 of file part.h.

Referenced by guiActivateEvent(), openStream(), openURL(), KParts::ReadWritePart::queryClose(), KParts::ReadWritePart::saveAs(), KParts::ReadWritePart::saveToURL(), and url().

QString KParts::ReadOnlyPart::m_file [protected]
 

Local file - the only one the part implementation should deal with.

Definition at line 473 of file part.h.

Referenced by closeURL(), openURL(), KParts::ReadWritePart::saveAs(), and KParts::ReadWritePart::saveToURL().

bool KParts::ReadOnlyPart::m_bTemp [protected]
 

If true, m_file is a temporary file that needs to be deleted later.

Definition at line 477 of file part.h.

Referenced by closeURL(), openURL(), KParts::ReadWritePart::saveAs(), and KParts::ReadWritePart::saveToURL().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:15:45 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001