[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KParts::ReadWritePart
From:       Matthias Kretz <kretz () kde ! org>
Date:       2002-01-25 14:29:02
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 24 January 2002 18:10, David Faure wrote:
> I thought about doing it that way, but it's incomplete. In case of errors
> you want to set it to false too.
> (in the isMalformed case of saveAs, and in case of an error in
> slotUploadFinished - ah you took care of that one already).
> Ok, then just one m_bClosing=false to add in saveAs, and this should be ok.

patch attached, may I apply?

> Here again, anyone reimplementing saveAs etc. is in trouble... although
> there aren't many reasons to reimplement those.

Yes, then he has to reimplement closeURL, save, saveFile, saveAs, saveToURL 
and create his own m_bClosing flag.

- -- 
C'ya
        Matthias
________________________________________________________
Matthias Kretz (Germany)
http://Vir.homeip.net/
MatthiasKretz@gmx.net, kretz@kde.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8UWu2yg4WnCj6OIoRAvV2AKCMPnmAM7Uq5wquy7TZugFqyTJpSACeLu3D
X48oQ6F40/dSXEWwOTu1HGI=
=IgQA
-----END PGP SIGNATURE-----

["part.cpp.patch" (text/x-diff)]

Index: part.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/part.cpp,v
retrieving revision 1.105
diff -u -3 -p -r1.105 part.cpp
--- part.cpp	2002/01/21 00:08:13	1.105
+++ part.cpp	2002/01/25 14:25:05
@@ -445,11 +445,16 @@ bool ReadWritePart::closeURL()
       if (m_url.isEmpty())
       {
           KURL url = KFileDialog::getSaveURL();
-          if (url.isEmpty()) return false;
-          return saveAs( url ) && ReadOnlyPart::closeURL();
+          if (url.isEmpty())
+          {
+            m_bClosing = false;
+            return false;
+          }
+          return saveAs( url );
       }
-      return save() && ReadOnlyPart::closeURL();
+      return save();
     case KMessageBox::No :
+      setModified( false ); // the user isn't interested in the changes, forget them
       return true;
     default : // case KMessageBox::Cancel :
       return false;
@@ -461,7 +466,10 @@ bool ReadWritePart::closeURL()
 
 bool ReadWritePart::save()
 {
-  return saveFile() && saveToURL();
+  if( saveFile() )
+    return saveToURL();
+  m_bClosing = false;
+  return false;
 }
 
 bool ReadWritePart::saveAs( const KURL & kurl )
@@ -469,6 +477,7 @@ bool ReadWritePart::saveAs( const KURL &
   if (kurl.isMalformed())
   {
       kdError(1000) << "saveAs: Malformed URL" << kurl.url() << endl;
+      m_bClosing = false;
       return false;
   }
   m_url = kurl; // Store where to upload in saveToURL
@@ -503,6 +512,9 @@ bool ReadWritePart::saveToURL()
   {
     setModified( false );
     emit completed();
+    // if m_url is a local file there won't be a temp file -> nothing to remove
+    assert( !m_bTemp );
+    m_bClosing = false; // no temp file to cleaned up
     return true; // Nothing to do
   }
   else
@@ -520,10 +532,16 @@ void ReadWritePart::slotUploadFinished( 
   else
   {
     setModified( false );
-    if ( m_bClosing )
-      ReadOnlyPart::closeURL();
+    if ( m_bClosing && m_bTemp ) // We're finished with this document -> remove temp file
+    {
+      unlink( QFile::encodeName(m_file) );
+      m_bTemp = false;
+    }
     emit completed();
   }
+  m_bClosing = false; // temp file was cleaned up
 }
 
 #include "part.moc"
+
+// vim:sw=2:ts=8:et


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic