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

George Staikos staikos at kde.org
Tue Apr 11 02:48:54 CEST 2006


SVN commit 528444 by staikos:

Make Kst files KIO enabled.  Data references must be URLs else it will try local
files.
FEATURE: 123200


 M  +10 -6     kst.cpp  
 M  +50 -9     kstdoc.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst.cpp #528443:528444
@@ -1020,7 +1020,12 @@
   KURL url;
   bool rc = false;
 
-  url.setPath(in_filename);
+  if (QFile::exists(in_filename) && QFileInfo(in_filename).isRelative()) {
+    url.setPath(in_filename);
+  } else {
+    url = KURL::fromPathOrURL(in_filename);
+  }
+
   slotUpdateStatusMsg(i18n("Opening file..."));
 
   if (doc->openDocument(url, o_file, o_n, o_f, o_s, o_ave)) {
@@ -1162,14 +1167,13 @@
   slotUpdateStatusMsg(i18n("Opening file..."));
 
   if (doc->saveModified(false)) {
-    QString fileToOpen = KFileDialog::getOpenFileName("::<kstfiledir>",
-        i18n("*.kst|Kst Plot File (*.kst)\n*|All Files"), this, i18n("Open File"));
-    if (!fileToOpen.isEmpty()) {
+    KURL url = KFileDialog::getOpenURL("::<kstfiledir>", i18n("*.kst|Kst Plot File (*.kst)\n*|All Files"), this, i18n("Open File"));
+    if (!url.isEmpty()) {
       doc->deleteContents();
       doc->setModified(false);
-      if (doc->openDocument(fileToOpen)) {
+      if (doc->openDocument(url)) {
         setCaption(doc->title());
-        addRecentFile(fileToOpen);
+        addRecentFile(url);
       }
     }
   }
--- trunk/extragear/graphics/kst/src/libkstapp/kstdoc.cpp #528443:528444
@@ -36,6 +36,7 @@
 #include "ksdebug.h"
 #include <kdeversion.h>
 #include <kfiledialog.h>
+#include <kio/netaccess.h>
 #include <kmessagebox.h>
 #include <kmdimainfrm.h>
 #include <kprogress.h>
@@ -176,11 +177,36 @@
 bool KstDoc::openDocument(const KURL& url, const QString& o_file,
                           int o_n, int o_f, int o_s, bool o_ave) {
   static bool opening = false;
+  bool cleanupFile = false;
 
   if (opening) {
     return false;
   }
 
+  QString tmpFile;
+  if (url.isLocalFile() || url.protocol().isEmpty()) {
+    tmpFile = url.path();
+  } else {
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+    if (!KIO::NetAccess::exists(url, true, KstApp::inst())) {
+#else
+    if (!KIO::NetAccess::exists(url, true)) {
+#endif
+      KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.prettyURL()));
+      return false;
+    }
+
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+    if (!KIO::NetAccess::download(url, tmpFile, KstApp::inst())) {
+#else
+    if (!KIO::NetAccess::download(url, tmpFile)) {
+#endif
+      KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.prettyURL()));
+      return false;
+    }
+    cleanupFile = true;
+  }
+
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
   opening = true;
 
@@ -188,9 +214,9 @@
   KstApp::inst()->setPaused(true);
   _updating = true; // block update thread from sending events until we're done
 
-  QFile f(url.path());
+  QFile f(tmpFile);
   if (!f.exists()) {
-    KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.path()));
+    KMessageBox::sorry(KstApp::inst(), i18n("%1: There is no file with that name to open.").arg(url.prettyURL()));
     opening = false;
     _updating = false;
     KstApp::inst()->setPaused(false);
@@ -199,29 +225,35 @@
   }
 
   _title = url.fileName(false);
-  _absFilePath = url.path();
-  _lastFilePath = url.path();
+  _absFilePath = url.url();
+  _lastFilePath = url.url();
   if (_title.isEmpty()) {
     _title = _absFilePath;
   }
   QDomDocument doc(_title);
 
   if (!f.open(IO_ReadOnly)) {
-    KMessageBox::sorry(KstApp::inst(), i18n("%1: File exists, but kst could not open it.").arg(url.path()));
+    KMessageBox::sorry(KstApp::inst(), i18n("%1: File exists, but kst could not open it.").arg(url.prettyURL()));
     opening = false;
     _updating = false;
     KstApp::inst()->setPaused(false);
     QApplication::restoreOverrideCursor();
+    if (cleanupFile) {
+      KIO::NetAccess::removeTempFile(tmpFile);
+    }
     return false;
   }
 
   if (!doc.setContent(&f)) {
-    KMessageBox::sorry(KstApp::inst(), i18n("%1: Not a valid kst plot specification file.").arg(url.path()));
+    KMessageBox::sorry(KstApp::inst(), i18n("%1: Not a valid kst plot specification file.").arg(url.prettyURL()));
     f.close();
     opening = false;
     _updating = false;
     KstApp::inst()->setPaused(false);
     QApplication::restoreOverrideCursor();
+    if (cleanupFile) {
+      KIO::NetAccess::removeTempFile(tmpFile);
+    }
     return false;
   }
 
@@ -238,24 +270,30 @@
   QString readingDocument = i18n("Reading Kst file");
 
   if (docElem.tagName() != "kstdoc") {
-    QString err = i18n("Error opening file %1.  Does not appear to be a Kst file.").arg(url.path());
+    QString err = i18n("Error opening file %1.  Does not appear to be a Kst file.").arg(url.prettyURL());
     KstDebug::self()->log(err, KstDebug::Error);
     KMessageBox::sorry(KstApp::inst(), err);
     opening = false;
     _updating = false;
     KstApp::inst()->setPaused(false);
     QApplication::restoreOverrideCursor();
+    if (cleanupFile) {
+      KIO::NetAccess::removeTempFile(tmpFile);
+    }
     return false;
   }
 
   if (docElem.attribute("version") != "1.2" && !docElem.attribute("version").isEmpty()) {
-    QString err = i18n("Error opening file %2.  Version %1 is too new.  Update Kst or fix the Kst file.").arg(docElem.attribute("version")).arg(url.path());
+    QString err = i18n("Error opening file %2.  Version %1 is too new.  Update Kst or fix the Kst file.").arg(docElem.attribute("version")).arg(url.prettyURL());
     KstDebug::self()->log(err, KstDebug::Error);
     KMessageBox::sorry(KstApp::inst(), err);
     opening = false;
     _updating = false;
     KstApp::inst()->setPaused(false);
     QApplication::restoreOverrideCursor();
+    if (cleanupFile) {
+      KIO::NetAccess::removeTempFile(tmpFile);
+    }
     return false;
   }
 
@@ -420,7 +458,7 @@
           app->closeWindow(toDelete);
         }
       } else {
-        KstDebug::self()->log(i18n("Unsupported element '%1' in file %2.").arg(e.tagName()).arg(url.path()), KstDebug::Warning);
+        KstDebug::self()->log(i18n("Unsupported element '%1' in file %2.").arg(e.tagName()).arg(url.prettyURL()), KstDebug::Warning);
       }
     }
     handled++;
@@ -543,6 +581,9 @@
   KstApp::inst()->setPaused(false);
   QApplication::restoreOverrideCursor();
   
+  if (cleanupFile) {
+    KIO::NetAccess::removeTempFile(tmpFile);
+  }
   return true;
 }
 


More information about the Kst mailing list