kparts Library API Documentation

KParts::ReadWritePart Class Reference

Base class for an "editor" part. More...

#include <part.h>

Inheritance diagram for KParts::ReadWritePart:

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

Public Slots

virtual void setModified ()
virtual bool save ()
bool waitSaveComplete ()

Signals

void sigQueryClose (bool *handled, bool *abortClosing)

Public Methods

 ReadWritePart (QObject *parent=0, const char *name=0)
virtual ~ReadWritePart ()
bool isReadWrite () const
virtual void setReadWrite (bool readwrite=true)
bool isModified () const
bool queryClose ()
virtual bool closeURL ()
bool closeURL (bool promptToSave)
virtual bool saveAs (const KURL &url)
virtual void setModified (bool modified)

Protected Slots

void slotUploadFinished (KIO::Job *job)

Protected Methods

virtual bool saveFile ()=0
virtual bool saveToURL ()

Detailed Description

Base class for an "editor" part.

This class handles network transparency for you. Anything that can open a URL, allow modifications, and save (to the same URL or a different one).

A read-write part can be set to read-only mode, using setReadWrite().

Part writers : Any part inheriting ReadWritePart should check isReadWrite before allowing any action that modifies the part. The part probably wants to reimplement setReadWrite, disable those actions. Don't forget to call the parent setReadWrite.

Definition at line 535 of file part.h.


Constructor & Destructor Documentation

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

Constructor See parent constructor for instructions.

Definition at line 445 of file part.cpp.

ReadWritePart::~ReadWritePart   [virtual]
 

Destructor Applications using a ReadWritePart should make sure, before destroying it, to call closeURL().

In KMainWindow::queryClose(), for instance, they should allow closing only if the return value of closeURL() was true. This allows to cancel.

Definition at line 451 of file part.cpp.


Member Function Documentation

bool KParts::ReadWritePart::isReadWrite   const [inline]
 

Returns:
true if the part is in read-write mode

Definition at line 557 of file part.h.

Referenced by closeURL(), and queryClose().

void ReadWritePart::setReadWrite bool    readwrite = true [virtual]
 

Changes the behavior of this part to readonly or readwrite.

Parameters:
readwrite  set to true to enable readwrite mode

Definition at line 459 of file part.cpp.

Referenced by KParts::GenericFactory< T >::createPartObject().

bool KParts::ReadWritePart::isModified   const [inline]
 

Returns:
true if the document has been modified.

Definition at line 568 of file part.h.

Referenced by closeURL(), and queryClose().

bool ReadWritePart::queryClose  
 

If the document has been modified, ask the user to save changes.

This method is meant to be called from KMainWindow::queryClose(). It will also be called from closeURL().

Returns:
true if closeURL() can be called without the user losing important data, false if the user chooses to cancel.
Since:
3.2

Definition at line 481 of file part.cpp.

References KURL::fileName(), KFileDialog::getSaveURL(), KURL::isEmpty(), QString::isEmpty(), isModified(), isReadWrite(), KParts::ReadOnlyPart::m_url, save(), saveAs(), sigQueryClose(), KParts::ReadOnlyPart::url(), waitSaveComplete(), KMessageBox::warningYesNoCancel(), and KParts::Part::widget().

Referenced by closeURL().

bool ReadWritePart::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.

If isModified(), queryClose() will be called.

Returns:
false on cancel

Reimplemented from KParts::ReadOnlyPart.

Definition at line 523 of file part.cpp.

References isModified(), isReadWrite(), and queryClose().

Referenced by closeURL().

bool ReadWritePart::closeURL bool    promptToSave
 

Call this method instead of the above if you need control if the save prompt is shown.

For example, if you call queryClose() from KMainWindow::queryClose(), you would not want to prompt again when closing the url.

Equivalent to promptToSave ? closeURL() : ReadOnlyPart::closeURL()

Since:
3.2

Definition at line 535 of file part.cpp.

References closeURL().

bool ReadWritePart::saveAs const KURL   url [virtual]
 

Save the file to a new location.

Calls save(), no need to reimplement

Definition at line 548 of file part.cpp.

References QFile::encodeName(), QString::isEmpty(), KURL::isLocalFile(), KURL::isValid(), KParts::ReadOnlyPart::m_bTemp, KParts::ReadOnlyPart::m_file, KParts::ReadOnlyPart::m_url, KTempFile::name(), KURL::path(), KURL::prettyURL(), save(), KParts::Part::setWindowCaption(), and KURL::url().

Referenced by queryClose().

void ReadWritePart::setModified bool    modified [virtual]
 

Sets the modified flag of the part.

Definition at line 465 of file part.cpp.

void KParts::ReadWritePart::sigQueryClose bool *    handled,
bool *    abortClosing
[signal]
 

Since:
3.2, remove in KDE 4, when queryClose is made virtual.

set handled to true, if you don't want the default handling set abortClosing to true, if you handled the request, but for any reason don't want to allow closing the document

Referenced by queryClose().

void ReadWritePart::setModified   [virtual, slot]
 

Call setModified() whenever the contents get modified.

This is a slot for convenience, so that you can connect it to a signal, like textChanged().

Definition at line 476 of file part.cpp.

Referenced by saveToURL().

bool ReadWritePart::save   [virtual, slot]
 

Save the file in the location from which it was opened.

You can connect this to the "save" action. Calls saveFile() and saveToURL(), no need to reimplement.

Definition at line 540 of file part.cpp.

References saveFile(), and saveToURL().

Referenced by queryClose(), and saveAs().

bool ReadWritePart::waitSaveComplete   [slot]
 

Waits for any pending upload job to finish and returns whether the last save() action was successful.

Definition at line 659 of file part.cpp.

References QWidget::setFocusPolicy().

Referenced by queryClose().

virtual bool KParts::ReadWritePart::saveFile   [protected, pure virtual]
 

Save to a local file.

You need to implement it, to save to m_file. The framework takes care of re-uploading afterwards.

Returns:
true on success, false on failure. On failure the function should inform the user about the problem with an appropriate message box. Standard error messages can be constructed using KIO::buildErrorString() in combination with the error codes defined in kio/global.h

Referenced by save().

bool ReadWritePart::saveToURL   [protected, virtual]
 

Save the file.

Uploads the file, if m_url is remote. This will emit started(), and either completed() or canceled(), in case you want to provide feedback.

Returns:
true on success, false on failure.

Definition at line 592 of file part.cpp.

References KParts::ReadOnlyPart::completed(), QObject::connect(), QFile::encodeName(), KIO::file_move(), KURL::isLocalFile(), KParts::ReadOnlyPart::m_bTemp, KParts::ReadOnlyPart::m_file, KParts::ReadOnlyPart::m_url, KTempFile::name(), setModified(), KTempFile::unlink(), and KParts::Part::widget().

Referenced by save().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kparts Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun May 16 22:04:11 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003