[Kst] extragear/graphics/kst/src/libkstapp

George Staikos staikos at kde.org
Sun May 14 00:12:08 CEST 2006


SVN commit 540546 by staikos:

fix saving Kst files with KIO


 M  +2 -2      kst.cpp  
 M  +37 -18    kstdoc.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst.cpp #540545:540546
@@ -1021,12 +1021,12 @@
   bool rc = false;
 
   if (QFile::exists(in_filename) && QFileInfo(in_filename).isRelative()) {
-    url.setPath(in_filename);
+    url.setPath(QFileInfo(in_filename).absFilePath());
   } else {
     url = KURL::fromPathOrURL(in_filename);
   }
 
-  slotUpdateStatusMsg(i18n("Opening file..."));
+  slotUpdateStatusMsg(i18n("Opening %1...").arg(url.prettyURL()));
 
   if (doc->openDocument(url, o_file, o_n, o_f, o_s, o_ave)) {
     setCaption(doc->title());
--- trunk/extragear/graphics/kst/src/libkstapp/kstdoc.cpp #540545:540546
@@ -41,6 +41,8 @@
 #include <kmdimainfrm.h>
 #include <kprogress.h>
 #include <ksavefile.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
 
 // application specific includes
 #include "kst2dplot.h"
@@ -729,35 +731,52 @@
 
 
 bool KstDoc::saveDocument(const QString& filename, bool saveAbsoluteVectorPositions, bool prompt) {
-  backupFile(filename);
-  QFile f(filename);
-
-  if (prompt && f.exists() && filename != absFilePath()) {
-    if (KMessageBox::warningYesNo(KstApp::inst(), i18n("%1: A file of this name already exists.").arg(filename),
-                                  i18n("Warning"),i18n("&Overwrite"),
-                                  i18n("&Cancel")) == KMessageBox::No) {
-      return false;
-    }
+  KURL url;
+  if (QFile::exists(filename) && QFileInfo(filename).isRelative()) {
+    url.setPath(QFileInfo(filename).absFilePath());
+  } else {
+    url = KURL::fromPathOrURL(filename);
   }
 
-  if (!f.open(IO_WriteOnly|IO_Truncate)) {
-    if (prompt) {
-      KMessageBox::sorry(KstApp::inst(), i18n("%1: Could not open file for saving. The plot description has not been saved. Try a different filename or directory.").arg(filename));
-    }
-    return false;
+  if (QFile::exists(filename)) {
+    // Only backup local files
+    backupFile(filename);
   }
+  KTempFile tf(locateLocal("tmp", "kst"), "txt");
 
-  // FIXME: KIO enable
-  QTextStream ts(&f);
+  QTextStream ts(tf.file());
   ts.setEncoding(QTextStream::UnicodeUTF8);
   ts.precision(14);
 
-  _lastFilePath = KURL(filename).path();
+  _lastFilePath = url.prettyURL();
 
   saveDocument(ts, saveAbsoluteVectorPositions);
 
-  f.close();
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+  tf.sync();
+#else
+  tf.close();
+#endif
 
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+  if (KIO::NetAccess::exists(url, false, KstApp::inst())) {
+#else
+  if (KIO::NetAccess::exists(url)) {
+#endif
+    if (prompt) {
+      int rc = KMessageBox::warningYesNo(KstApp::inst(), i18n("File %1 exists.  Overwrite?").arg(url.prettyURL()), i18n("Kst"));
+      if (rc == KMessageBox::No) {
+        return false;
+      }
+    }
+  }
+
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,2,0)
+  KIO::NetAccess::file_copy(KURL(tf.name()), url, -1, true, false, KstApp::inst());
+#else
+  KIO::NetAccess::upload(tf.name(), url);
+#endif
+
   _modified = false;
   return true;
 }


More information about the Kst mailing list