[PATCH] KParts::ReadWritePart::saveAs - again ;-)

Andras Mantia amantia at kde.org
Tue Mar 9 17:39:59 GMT 2004

Hash: SHA1


 The save() and saveAs() methods are supposed to return a boolean value, an 
although it's not clearly documented, it should be true on success and false 
on failure. This works fine in case of local files, but as soon as you save a 
non-local file, it will always return true, as the saving is asynchronous. 
This wouldn't be a big problem itself (although makes the function to behave 
differently in case of non-local files), as there is a completed () and 
canceled (const QString &errMsg) signal that one can use to check the result 
of the save. The real problem comes here: it's not usable, as in case of 
local files on failure there is no such signal emitted,  unless the KPart 
emits it in the reimplemented saveFile() method. But why should it emit, if 
in all other cases it's emitted in the KParts::ReadWritePart. 
 I propose one of the following patches:

- --- part.cpp    2004-03-02 14:24:33.000000000 +0200
+++ part.cpp.new        2004-03-09 19:33:39.000000000 +0200
@@ -539,6 +539,8 @@
   d->m_saveOk = false;
   if( saveFile() )
     return saveToURL();
+  else
+    emit canceled("");
   return false;

- - fixes the above problem for all parts

Possible problems:
- - if the KPart already emitted the canceled() signal, the receiver will get 
one more. Note that the same problem is present also on success, as 
saveToURL() uncoditionally emits completed() for local files. Requires more 
code on the caller side (e.g disconnect from the signals after receiving the 
first one).
- - there is no error message sent. Maybe a general i18n("Saving failed.") may 
be added there.

- --- part.h      2003-09-30 19:25:30.000000000 +0300
+++ part.h.new  2004-03-09 19:37:02.000000000 +0200
@@ -657,8 +657,9 @@
    * @return 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()
+   * problem with an appropriate message box and should emit the
+   * canceled() signal with the error message as argument.
+   * Standard error  messages can be constructed using 
    * in combination with the error codes defined in kio/global.h
   virtual bool saveFile() = 0;

- - cannot break any code

- - doesn't fix any existing code (I must fix everywhere as I see)
- - we must trust the developers to read the documentation ;-)


- -- 
Quanta Plus developer - http://quanta.sourceforge.net
K Desktop Environment - http://www.kde.org
Version: GnuPG v1.2.2 (GNU/Linux)


More information about the kde-core-devel mailing list