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

List:       koffice-devel
Subject:    [PATCH] save embedded documents
From:       Dag Andersen <danders () get2net ! dk>
Date:       2002-07-17 12:38:44
[Download RAW message or body]

The atttached patch:
- checks if embedded external docs are modified and queries for save
- checks if any embedded doc has been modified so that they can be 
saved also if main doc is not modified.

Commit?
-- 
Mvh,
Dag Andersen
["save.diff" (text/x-diff)]

Index: lib/kofficecore/koDocument.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.cc,v
retrieving revision 1.239
diff -u -p -u -r1.239 koDocument.cc
--- lib/kofficecore/koDocument.cc	2002/07/15 12:41:30	1.239
+++ lib/kofficecore/koDocument.cc	2002/07/17 12:01:16
@@ -630,6 +630,24 @@ void KoDocument::paintChild( KoDocumentC
     }
 }
 
+bool KoDocument::childIsModified()
+{
+    //kdDebug()<<k_funcinfo<<" doc="<<url().url()<<endl;
+    bool res = false;
+    QPtrListIterator<KoDocumentChild> it = children();
+    for (; it.current(); ++it )
+    {
+        KoDocument *doc = it.current()->document();
+        if ( doc )
+        {
+            kdDebug()<<k_funcinfo<<" doc: "<<doc->url().url()<<" \
modified="<<doc->isModified()<<endl; +            if ( doc->isModified() || \
doc->childIsModified() ) +                res = true;//return true;
+        }
+    }
+    return res;
+}
+
 bool KoDocument::saveChildren( KoStore* /*_store*/ )
 {
     // Lets assume that we do not have children
@@ -1264,7 +1282,7 @@ void KoDocument::setModified( bool mod )
     if ( mod == isModified() )
         return;

-    kdDebug(30003) << "KoDocument::setModified( " << (mod ? "true" : "false") << ")" \
<< endl; +    kdDebug(30003) << "KoDocument::setModified( " << (mod ? "true" : \
"false") << ")" << " doc: " << url().url() << endl;  \
KParts::ReadWritePart::setModified( mod );  
     if ( mod )
@@ -1272,6 +1290,38 @@ void KoDocument::setModified( bool mod )
 
     // This influences the title
     setTitleModified();
+}
+
+int KoDocument::queryCloseExternalChildren()
+{
+    int res = KMessageBox::Ok;
+    QPtrListIterator<KoDocumentChild> it( children() );
+    for (; it.current(); ++it )
+    {
+        KoDocument *doc = it.current()->document();
+        if ( doc->queryCloseExternalChildren() == KMessageBox::Cancel )
+            return KMessageBox::Cancel;
+
+        if ( doc->isStoredExtern() && doc->isModified() )
+        {
+            QString name = doc->url().fileName();
+            res = KMessageBox::warningYesNoCancel( 0L,
+                            i18n( "<p>The document <b>'%1'</b> has been \
modified.</p><p>Do you want to save it?</p>" ).arg(name)); +
+            switch(res) {
+                case KMessageBox::Yes :
+                    doc->save(); // NOTE: External files always in native format
+                    break;
+                case KMessageBox::No :
+                    //rootDocument()->removeAutoSaveFiles();
+                    doc->setModified( false ); // Now when queryClose() is called by \
closeEvent it won't do anything. +                    break;
+                default : // case KMessageBox::Cancel :
+                    return res; // cancels the rest of the files
+            }
+        }
+    }
+    return res;
 }
 
 void KoDocument::setTitleModified()
Index: lib/kofficecore/koDocument.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.h,v
retrieving revision 1.119
diff -u -p -u -r1.119 koDocument.h
--- lib/kofficecore/koDocument.h	2002/07/01 15:48:12	1.119
+++ lib/kofficecore/koDocument.h	2002/07/17 12:01:19
@@ -30,6 +30,7 @@ using namespace std;
 #include <kurl.h>
 #include <kservice.h>
 #include <koGlobal.h>
+#include <kmessagebox.h>
 
 class QDomElement;
 class QDomDocument;
@@ -55,7 +56,7 @@ class KoDocument : public KParts::ReadWr
 {
     Q_OBJECT
     Q_PROPERTY( QCString dcopObjectId READ dcopObjectId)
-    
+
 public:
 
     /**
@@ -460,7 +461,7 @@ public:
      * so that their dcop interface provides more functionality than the basic \
                KoDocumentIface
      */
     virtual DCOPObject * dcopObject();
-    
+
     /**
      * return the ID of the dcop interface for this document.
      **/
@@ -479,9 +480,13 @@ public:
     virtual bool isStoredExtern();
 
     KoPageLayout pageLayout() const { return m_pageLayout; }
-    
+
     void removeAutoSaveFiles();
+
+    virtual bool childIsModified();
     
+    virtual int queryCloseExternalChildren();
+
 signals:
     /**
      * This signal is emitted, if a direct or indirect child document changes
Index: lib/kofficecore/koMainWindow.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koMainWindow.cc,v
retrieving revision 1.266
diff -u -p -u -r1.266 koMainWindow.cc
--- lib/kofficecore/koMainWindow.cc	2002/06/17 15:54:56	1.266
+++ lib/kofficecore/koMainWindow.cc	2002/07/17 12:01:22
@@ -669,47 +669,54 @@ void KoMainWindow::resizeEvent( QResizeE
 
 bool KoMainWindow::queryClose()
 {
-  if ( rootDocument() == 0 )
-    return true;
-  //kdDebug(30003) << "KoMainWindow::queryClose() viewcount=" << \
                rootDocument()->viewCount()
-  //               << " shellcount=" << rootDocument()->shellCount() << endl;
-  if ( !d->m_forQuit && rootDocument()->shellCount() > 1 )
-    // there are more open, and we are closing just one, so no problem for closing
-    return true;
+    if ( rootDocument() == 0 )
+        return true;
+    //kdDebug(30003) << "KoMainWindow::queryClose() viewcount=" << \
rootDocument()->viewCount() +    //               << " shellcount=" << \
rootDocument()->shellCount() << endl; +    if ( !d->m_forQuit && \
rootDocument()->shellCount() > 1 ) +        // there are more open, and we are \
closing just one, so no problem for closing +        return true;
+
+    // see DTOR for a descr. of the test
+    if ( d->m_rootDoc->isEmbedded() )
+        return true;
+
+    // external documents first
+    if ( d->m_rootDoc->queryCloseExternalChildren() == KMessageBox::Cancel )
+        return false;
 
-  // see DTOR for a descr. for the 2nd test
-  if ( d->m_rootDoc->isModified() &&
-       !d->m_rootDoc->isEmbedded())
-  {
-      QString name;
-      if ( rootDocument()->documentInfo() )
-      {
-         name = rootDocument()->documentInfo()->title();
-      }
-      if ( name.isEmpty() )
-          name = rootDocument()->url().fileName();
-
-      if ( name.isEmpty() )
-          name = i18n( "Untitled" );
-
-      int res = KMessageBox::warningYesNoCancel( 0L,
-                    i18n( "<p>The document <b>'%1'</b> has been modified.</p><p>Do \
                you want to save it?</p>" ).arg(name));
-
-      switch(res) {
-          case KMessageBox::Yes : {
-              bool isNative = ( d->m_rootDoc->outputMimeType() == \
                d->m_rootDoc->nativeFormatMimeType() );
-              if (! saveDocument( !isNative ) )
-                  return false;
-          }
-          case KMessageBox::No :
-              rootDocument()->removeAutoSaveFiles();
-              rootDocument()->setModified( false ); // Now when queryClose() is \
                called by closeEvent it won't do anything.
-              break;
-          default : // case KMessageBox::Cancel :
-              return false;
-      }
-  }
-  return true;
+    // main doc + embedded docs in store
+    if ( d->m_rootDoc->isModified() || d->m_rootDoc->childIsModified() )
+    {
+        QString name;
+        if ( rootDocument()->documentInfo() )
+        {
+            name = rootDocument()->documentInfo()->title();
+        }
+        if ( name.isEmpty() )
+            name = rootDocument()->url().fileName();
+
+        if ( name.isEmpty() )
+            name = i18n( "Untitled" );
+
+        int res = KMessageBox::warningYesNoCancel( 0L,
+                        i18n( "<p>The document <b>'%1'</b> has been \
modified.</p><p>Do you want to save it?</p>" ).arg(name)); +
+        switch(res) {
+            case KMessageBox::Yes : {
+                bool isNative = ( d->m_rootDoc->outputMimeType() == \
d->m_rootDoc->nativeFormatMimeType() ); +                if (! saveDocument( \
!isNative ) ) +                    return false;
+            }
+            case KMessageBox::No :
+                rootDocument()->removeAutoSaveFiles();
+                rootDocument()->setModified( false ); // Now when queryClose() is \
called by closeEvent it won't do anything. +                break;
+            default : // case KMessageBox::Cancel :
+                return false;
+        }
+    }
+    return true;
 }
 
 void KoMainWindow::slotFileNew()


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

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

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