[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Mon Jul 16 21:00:32 CEST 2007


SVN commit 688749 by treat:

* Open files from command line* Open files from command line* Open files from command line* Open files from command line* Open files from command line* Open files from command line* Open files from command line* Open files from command line


 M  +7 -11     document.cpp  
 M  +1 -0      document.h  
 M  +5 -0      kstapplication.cpp  
 M  +7 -2      mainwindow.cpp  
 M  +1 -0      mainwindow.h  


--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #688748:688749
@@ -24,7 +24,6 @@
 
 #include <QDebug>
 #include <QFile>
-#include <QMessageBox>
 #include <QXmlStreamReader>
 
 namespace Kst {
@@ -57,15 +56,14 @@
   // - only setChanged(false) if save was successful
   setChanged(false);
 
-  QString fn = !to.isEmpty() ? to : _fileName;
-  QFile f(fn);
+  QString file = !to.isEmpty() ? to : _fileName;
+  QFile f(file);
   if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
-    QMessageBox::critical(_win, QObject::tr("Kst: Critical"),
-                          QObject::tr("File '%1' could not be opened for writing.").arg(fn));
+    _lastError = QObject::tr("File '%1' could not be opened for writing.").arg(file);
     return false;
   }
 
-  _fileName = fn;
+  _fileName = file;
 
   QXmlStreamWriter xml;
   xml.setDevice(&f);
@@ -127,8 +125,7 @@
   _isOpen = false;
   QFile f(file);
   if (!f.open(QIODevice::ReadOnly)) {
-    QMessageBox::critical(_win, QObject::tr("Kst: Critical"),
-                          QObject::tr("File '%1' could not be opened for reading.").arg(file));
+    _lastError = QObject::tr("File '%1' could not be opened for reading.").arg(file);
     return false;
   }
 
@@ -241,8 +238,7 @@
 #undef malformed
 
   if (xml.hasError()) {
-    QMessageBox::critical(_win, QObject::tr("Kst: Critical"),
-                          QObject::tr("File '%1' is malformed and encountered an error when opening.").arg(file));
+    _lastError = QObject::tr("File '%1' is malformed and encountered an error when reading.").arg(file);
     return false;
   }
 
@@ -251,7 +247,7 @@
 
 
 QString Document::lastError() const {
-  return QString::null;
+  return _lastError;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/document.h #688748:688749
@@ -44,6 +44,7 @@
     bool _dirty;
     bool _isOpen;
     QString _fileName;
+    QString _lastError;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkstapp/kstapplication.cpp #688748:688749
@@ -19,6 +19,11 @@
   _mainWindow = new Kst::MainWindow;
   connect(this, SIGNAL(aboutToQuit()), _mainWindow, SLOT(aboutToQuit()));
 
+  //FIXME need a real getopt here...
+  QStringList args = QCoreApplication::arguments();
+  if (!args.at(1).isEmpty())
+    _mainWindow->openFile(args.at(1));
+
   _mainWindow->show();
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #688748:688749
@@ -167,11 +167,16 @@
     return;
   }
 
+  openFile(fn);
+}
+
+
+void MainWindow::openFile(const QString &file) {
   delete _doc;
   _doc = new Document(this);
-  bool ok = _doc->open(fn);
+  bool ok = _doc->open(file);
   if (!ok) {
-    QMessageBox::critical(this, tr("Kst"), tr("Error opening document '%1':\n%2").arg(fn, _doc->lastError()));
+    QMessageBox::critical(this, tr("Kst"), tr("Error opening document '%1':\n%2").arg(file, _doc->lastError()));
     delete _doc;
     _doc = new Document(this);
   }
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #688748:688749
@@ -51,6 +51,7 @@
     void save();
     void saveAs();
     void open();
+    void openFile(const QString &file);
     void print();
 
   private Q_SLOTS:


More information about the Kst mailing list