[Kst] extragear/graphics/kst

George Staikos staikos at kde.org
Wed Dec 14 01:10:11 CET 2005


SVN commit 488322 by staikos:

- make argument passing to extensions work
- add a new field to give extensions a short-form name in the .desktop file
- add support for JS arguments -E js:"execute this script text"
- you can't i18n strings you plan to:
	a) store to disk and later load for comparison
	b) compare at runtime randomly


 M  +0 -1      devel-docs/RELEASE_PLAN  
 M  +23 -1     kst/extensions/js/js.cpp  
 M  +4 -1      kst/extensions/js/js.h  
 M  +1 -0      kst/extensions/js/kstextension_js.desktop  
 M  +19 -3     kst/kst.cpp  
 M  +3 -3      kst/kstdoc.cpp  
 M  +5 -0      kst/kstextension.cpp  
 M  +3 -0      kst/kstextension.desktop  
 M  +2 -0      kst/kstextension.h  
 M  +1 -2      kst/main.cpp  


--- trunk/extragear/graphics/kst/devel-docs/RELEASE_PLAN #488321:488322
@@ -4,7 +4,6 @@
 ----------------
 1) Fixes and polishing remaining:
 	- KstScript:
-		- extension argument passing
 		- Curve and images need reworking
 		- Additional plot bindings?
 		- Line and Arrow orientations fixed (1.2.1)
--- trunk/extragear/graphics/kst/kst/extensions/js/js.cpp #488321:488322
@@ -28,6 +28,7 @@
 
 #include <kst.h>
 
+#include <qdeepcopy.h>
 #include <qlayout.h>
 #include <qsplitter.h>
 
@@ -142,8 +143,29 @@
 }
 
 
+void KstJS::processArguments(const QString& args) {
+  _args.append(args);
+  QTimer::singleShot(0, this, SLOT(doArgs()));
+}
+
+
+void KstJS::doArgs() {
+  static bool executing = false;
+  if (!_jsPart || executing) {
+    QTimer::singleShot(0, this, SLOT(doArgs()));
+    return;
+  }
+  executing = true;
+  QStringList a = QDeepCopy<QStringList>(_args);
+  _args.clear();
+  for (QStringList::ConstIterator i = a.begin(); i != a.end(); ++i) {
+    _jsPart->execute(*i);
+  }
+  executing = false;
+}
+
+
 void KstJS::createBindings() {
-  // FIXME: bad
   _jsPart->addObject(app(), "kst");
   _jsPart->factory()->addType("KstJSUIBuilder");
   _jsPart->factory()->addType("KActionCollection");
--- trunk/extragear/graphics/kst/kst/extensions/js/js.h #488321:488322
@@ -41,6 +41,7 @@
     // To save state
     virtual void load(QDomElement& e);
     virtual void save(QTextStream& ts, const QString& indent = QString::null);
+    virtual void processArguments(const QString& args);
 
     KJSEmbed::KJSEmbedPart *part() const { return _jsPart; }
 
@@ -56,6 +57,7 @@
   private slots:
     void shellExited();
     void restoreUI();
+    void doArgs();
 
   private:
     void createBindings();
@@ -63,7 +65,7 @@
   protected:
     friend class LoadScript;
     QStringList _scripts;
-    KJSEmbed::KJSEmbedPart *_jsPart;
+    QGuardedPtr<KJSEmbed::KJSEmbedPart> _jsPart;
 
   private:
     JSIfaceImpl *_iface;
@@ -72,6 +74,7 @@
     QGuardedPtr<QWidget> _oldCentralWidget;
     KToggleAction *_showAction;
     QGuardedPtr<QObject> _merge;
+    QStringList _args;
 };
 
 
--- trunk/extragear/graphics/kst/kst/extensions/js/kstextension_js.desktop #488321:488322
@@ -5,6 +5,7 @@
 X-KDE-ModuleType=Plugin
 X-KDE-Library=kstextension_js
 X-Kst-Plugin-Author=The University of Toronto
+X-Kst-Extension-Name=js
 Name=JavaScript Extension
 Name[cs]=JavaScript rozšíření
 Name[da]=JavaScript udvidelse
--- trunk/extragear/graphics/kst/kst/kst.cpp #488321:488322
@@ -28,6 +28,7 @@
 
 // include files for KDE
 #include <kaccel.h>
+#include <kcmdlineargs.h>
 #include "ksdebug.h"
 #include <kfiledialog.h>
 #include <kkeydialog.h>
@@ -288,6 +289,8 @@
     _defaultFont = "helvetica";
   }
 
+  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+  QCStringList argList = args->getOptionList("E");
   ExtensionMgr *mgr = ExtensionMgr::self();
   mgr->setWindow(this);
   KService::List sl = KServiceType::offers("Kst Extension");
@@ -299,6 +302,19 @@
     }
     mgr->loadExtension(service);
   }
+  for (KService::List::ConstIterator it = sl.begin(); it != sl.end(); ++it) {
+    KService::Ptr service = *it;
+    QString name = service->property("Name").toString();
+    KstExtension *e = mgr->extension(name);
+    if (e) {
+      QString ename = service->property("X-Kst-Extension-Name").toString();
+      for (QCStringList::ConstIterator i = argList.begin(); i != argList.end(); ++i) {
+        if (QString::fromLatin1(*i).startsWith(ename + ":")) {
+          e->processArguments((*i).mid(ename.length() + 1));
+        }
+      }
+    }
+  }
   QApplication::restoreOverrideCursor();
 }
 
@@ -1060,7 +1076,7 @@
 
 void KstApp::saveProperties(KConfig *config) {
   QString name = doc->absFilePath();
-  if (!name.isEmpty() && doc->title() != i18n("Untitled")) {
+  if (!name.isEmpty() && doc->title() != "Untitled") {
     config->writePathEntry("Document", name);
     config->writeEntry("NamedDocument", true);
   } else {
@@ -1088,7 +1104,7 @@
   } else {
     doc->openDocument(name);
     QFile::remove(name);
-    doc->setTitle(i18n("Untitled"));
+    doc->setTitle("Untitled");
   }
 }
 
@@ -1160,7 +1176,7 @@
 
 
 void KstApp::slotFileSave() {
-  if (doc->title() == i18n("Untitled")) {
+  if (doc->title() == "Untitled") {
     slotFileSaveAs();
   } else {
     slotUpdateStatusMsg(i18n("Saving file..."));
--- trunk/extragear/graphics/kst/kst/kstdoc.cpp #488321:488322
@@ -73,7 +73,7 @@
   _updating = false;
   _stopping = false;
   _nextEventPaint = false;
-  _title = i18n("Untitled");
+  _title = "Untitled";
 }
 
 KstDoc::~KstDoc() {
@@ -117,7 +117,7 @@
       int want_save = KMessageBox::warningYesNoCancel( win, i18n("The current plot definition has been modified. Do you want to save it?"), i18n("Question"));
       switch (want_save) {
         case KMessageBox::Yes:
-          if (_title == i18n("Untitled")) {
+          if (_title == "Untitled") {
             if (!win->slotFileSaveAs()) {
               return false;
             }
@@ -163,7 +163,7 @@
     deleteContents();
     _modified = false;
     _absFilePath = QDir::homeDirPath();
-    _title = i18n("Untitled");
+    _title = "Untitled";
     KstApp::inst()->newWindow(i18n("default name of first window", "W1"));
     createScalars();
     emit updateDialogs();
--- trunk/extragear/graphics/kst/kst/kstextension.cpp #488321:488322
@@ -49,5 +49,10 @@
   return static_cast<KstApp*>(parent());
 }
 
+
+void KstExtension::processArguments(const QString& args) {
+  Q_UNUSED(args)
+}
+
 #include "kstextension.moc"
 // vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstextension.desktop #488321:488322
@@ -7,3 +7,6 @@
 [PropertyDef::X-Kst-Enabled]
 Type=bool
 
+[PropertyDef::X-Kst-Extension-Name]
+Type=QString
+
--- trunk/extragear/graphics/kst/kst/kstextension.h #488321:488322
@@ -31,6 +31,8 @@
     KstExtension(QObject *parent, const char *name, const QStringList&);
     virtual ~KstExtension();
 
+    virtual void processArguments(const QString& args);
+
     // To save state
     virtual void load(const QDomElement& e);
     virtual void save(QTextStream& ts, const QString& indent = QString::null);
--- trunk/extragear/graphics/kst/kst/main.cpp #488321:488322
@@ -51,6 +51,7 @@
   { "y <Y>",  I18N_NOOP("Field for Y axis (multiple allowed)"), 0 },
   { "z <Z>",  I18N_NOOP("Field for a Z image (multiple allowed)"), 0 },
   { "ye <equation>",  I18N_NOOP("Equation for Y axis (multiple allowed)"), 0 },
+  { "E <text>",  I18N_NOOP("Pass argument to extension.  text is of format extensionname:argumentlist"), 0 },
   { "e <E>",  I18N_NOOP("Field for Y errors (multiple allowed)"), 0 },
   { "x <X>",  I18N_NOOP("Field or range for X axis"),        "INDEX"},
   { "xe <X>", I18N_NOOP("X vector for equations x0:x1:n"),   "INDEX"},
@@ -789,11 +790,9 @@
     }
 
     if (print_and_exit) {
-      args->clear();
       delete kst;
       return 0;
     } else {
-      args->clear();
       kst->updateDialogs();
       
       if (showQuickStart) {


More information about the Kst mailing list