[Kst] branches/work/kst/1.6/kst/src/extensions/js

Andrew Walker arwalker at sumusltd.com
Fri Nov 23 21:03:53 CET 2007


SVN commit 740643 by arwalker:

elog functionality complete

 M  +18 -8     bind_elog.cpp  
 M  +46 -9     elogthreadsubmit.cpp  
 M  +3 -3      elogthreadsubmit.h  
 M  +8 -0      js.cpp  
 M  +2 -0      js.h  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_elog.cpp #740642:740643
@@ -27,9 +27,19 @@
   if (globalObject) {
     globalObject->put(exec, "ELOG", o);
   }
+
+  _port = 80;
+  _suppressEmailNotification = false;
+  _encodedHTML = false;
+  _includeCapture = false;
+  _includeConfiguration = false;
+  _includeDebugInfo = false;
+  _captureWidth = 640;
+  _captureHeight = 480;
 }
 
 
+
 KstBindELOG::KstBindELOG(int id)
 : KstBinding("ELOG Method", id) {
 }
@@ -84,10 +94,10 @@
   { "encodedHTML", &KstBindELOG::setEncodedHTML , &KstBindELOG::encodedHTML },
   { "text", &KstBindELOG::setText , &KstBindELOG::text },
   { "includeCapture", &KstBindELOG::setIncludeCapture , &KstBindELOG::includeCapture },
+  { "includeConfiguration", &KstBindELOG::setIncludeConfiguration , &KstBindELOG::includeConfiguration },
+  { "includeDebugInfo", &KstBindELOG::setIncludeDebugInfo , &KstBindELOG::includeDebugInfo },
   { "captureWidth", &KstBindELOG::setCaptureWidth , &KstBindELOG::captureWidth },
   { "captureHeight", &KstBindELOG::setCaptureHeight , &KstBindELOG::captureHeight },
-  { "includeConfiguration", &KstBindELOG::setIncludeConfiguration , &KstBindELOG::includeConfiguration },
-  { "includeDebugInfo", &KstBindELOG::setIncludeDebugInfo , &KstBindELOG::includeDebugInfo },
   { 0L, 0L, 0L }
 };
 
@@ -175,7 +185,6 @@
 
 KJS::Value KstBindELOG::submit(KJS::ExecState *exec, const KJS::List& args) {
   ElogThreadSubmit* pThread;
-  QByteArray byteArrayCapture;
 
   if (args.size() != 0) {
     KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Requires no arguments.");
@@ -191,10 +200,9 @@
 
   pThread = new ElogThreadSubmit(_hostname,
                                  _port,
-                                 false,
-                                 false,
-                                 false,
-                                 &byteArrayCapture,
+                                 _includeCapture,
+                                 _includeConfiguration,
+                                 _includeDebugInfo,
                                  _text,
                                  _username,
                                  _password,
@@ -203,7 +211,9 @@
                                  _attributes,
                                  _attachments,
                                  _encodedHTML,
-                                 _suppressEmailNotification);
+                                 _suppressEmailNotification,
+                                 _captureWidth,
+                                 _captureHeight);
   pThread->doTransmit();
 
   return KJS::Boolean(true);
--- branches/work/kst/1.6/kst/src/extensions/js/elogthreadsubmit.cpp #740642:740643
@@ -24,6 +24,15 @@
 #include <kmdcodec.h>
 
 #include "elogthreadsubmit.h"
+
+#define private public
+#define protected public
+#include <kjsembed/kjsembedpart.h>
+#undef protected
+#undef private
+
+#include "js.h"
+
 #include <kst.h>
 #include <kstevents.h>
 
@@ -33,7 +42,6 @@
                                   bool bIncludeCapture,
                                   bool bIncludeConfiguration,
                                   bool bIncludeDebugInfo,
-                                  QByteArray* pByteArrayCapture,
                                   const QString& strMessage,
                                   const QString& strUserName,
                                   const QString& strUserPassword,
@@ -42,9 +50,10 @@
                                   const QMap<QString, QString>& attributes,
                                   const QStringList& attachments,
                                   bool bSubmitAsHTML,
-                                  bool bSuppressEmail)
+                                  bool bSuppressEmail,
+                                  int iCaptureWidth,
+                                  int iCaptureHeight)
 : _textStreamResult(_byteArrayResult, IO_ReadWrite), _dataStreamAll(_byteArrayAll, IO_ReadWrite) {
-  _byteArrayCapture.duplicate( *pByteArrayCapture );
   _bIncludeCapture        = bIncludeCapture;
   _bIncludeConfiguration  = bIncludeConfiguration;
   _bIncludeDebugInfo      = bIncludeDebugInfo;
@@ -59,6 +68,8 @@
   _attachments            = attachments;
   _bSubmitAsHTML          = bSubmitAsHTML;
   _bSuppressEmail         = bSuppressEmail;
+  _iCaptureWidth          = iCaptureWidth;
+  _iCaptureHeight         = iCaptureHeight;
   _strType                = i18n("script entry");
 }
 
@@ -114,30 +125,56 @@
   // add the attachments...
   //
   if( _bIncludeCapture ) {
+    KstELOGCaptureStruct captureStruct;
+    QByteArray byteArrayCapture;
+    QDataStream dataStreamCapture( byteArrayCapture, IO_ReadWrite );
+    QCustomEvent eventCapture( KstELOGCaptureEvent );
+
+    captureStruct.pBuffer = &dataStreamCapture;
+    captureStruct.iWidth = _iCaptureWidth;
+    captureStruct.iHeight = _iCaptureHeight;
+
+    eventCapture.setData( &captureStruct );
+    QApplication::sendEvent( (QObject*)KstJS::inst()->app(), (QEvent*)&eventCapture );
     iAttachment++;
-    addAttachment( _dataStreamAll, boundary, _byteArrayCapture, iAttachment, "Capture.png" );
+    addAttachment( _dataStreamAll, boundary, byteArrayCapture, iAttachment, "Capture.png" );
   }
+
   if( _bIncludeConfiguration ) {
     QByteArray byteArrayConfigure;
     QTextStream textStreamConfigure( byteArrayConfigure, IO_ReadWrite );
-    QCustomEvent eventConfigure(KstELOGConfigureEvent);
+    QCustomEvent eventConfigure( KstELOGConfigureEvent );
 
     eventConfigure.setData( &textStreamConfigure );
-//    QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventConfigure );
+    QApplication::sendEvent( (QObject*)KstJS::inst()->app(), (QEvent*)&eventConfigure );
     iAttachment++;
     addAttachment( _dataStreamAll, boundary, byteArrayConfigure, iAttachment, "Configure.kst" );
   }
+
   if( _bIncludeDebugInfo ) {
     QByteArray byteArrayDebugInfo;
     QTextStream textStreamDebugInfo( byteArrayDebugInfo, IO_ReadWrite );
-    QCustomEvent eventDebugInfo(KstELOGDebugInfoEvent);
+    QCustomEvent eventDebugInfo( KstELOGDebugInfoEvent );
 
     eventDebugInfo.setData( &textStreamDebugInfo );
-//    QApplication::sendEvent( (QObject*)_elog->app(), (QEvent*)&eventDebugInfo );
+    QApplication::sendEvent( (QObject*)KstJS::inst()->app(), (QEvent*)&eventDebugInfo );
     iAttachment++;
     addAttachment( _dataStreamAll, boundary, byteArrayDebugInfo, iAttachment, "DebugInfo.txt" );
   }
 
+  for ( QStringList::iterator itList = _attachments.begin(); itList != _attachments.end(); ++itList ) {
+    QByteArray byteArrayAttachment;
+    QFile file(*itList);
+
+    if (file.open( IO_ReadOnly )) {
+      byteArrayAttachment = file.readAll();
+      iAttachment++;
+      addAttachment( _dataStreamAll, boundary, byteArrayAttachment, iAttachment, *itList );
+    } else {
+      doError( i18n("%1: unable to open attachment '%2'").arg(_strType).arg(*itList), KstDebug::Warning );
+    }
+  }
+
   _job = KIO::http_post(destination, _byteArrayAll, false);
   if (_job) {
     _job->addMetaData("content-type", QString("multipart/form-data; boundary=%1").arg(boundary));
@@ -266,7 +303,7 @@
                                 const QString& name ) {
   if (byteArray.count() > 0) {
     QString strStart = QString("Content-Disposition: form-data; name=\"attfile%1\"; filename=\"%2\"\r\n\r\n").arg(iFileNumber).arg(name);
-    QString strEnd   = QString("%1\r\n").arg(boundary);
+    QString strEnd = QString("%1\r\n").arg(boundary);
 
     stream.writeRawBytes(strStart.ascii(), strStart.length());
     stream.writeRawBytes(byteArray.data(), byteArray.count());
--- branches/work/kst/1.6/kst/src/extensions/js/elogthreadsubmit.h #740642:740643
@@ -32,7 +32,6 @@
                      bool bIncludeCapture,
                      bool bIncludeConfiguration,
                      bool bIncludeDebugInfo,
-                     QByteArray* pByteArrayCapture,
                      const QString& strMessage,
                      const QString& strUserName,
                      const QString& strUserPassword,
@@ -41,7 +40,9 @@
                      const QMap<QString, QString>& attributes,
                      const QStringList& attachments,
                      bool bSubmitAsHTML,
-                     bool bSuppressEmail);
+                     bool bSuppressEmail,
+                     int iCaptureWidth,
+                     int iCaptureHeight);
 
     virtual ~ElogThreadSubmit();
     virtual void doTransmit( );
@@ -68,7 +69,6 @@
 
     QByteArray              _byteArrayAll;
     QDataStream             _dataStreamAll;
-    QByteArray              _byteArrayCapture;
     QString                 _strHostname;
     QString                 _strType;
     QString                 _strMessage;
--- branches/work/kst/1.6/kst/src/extensions/js/js.cpp #740642:740643
@@ -77,6 +77,7 @@
 
 K_EXPORT_COMPONENT_FACTORY(kstextension_js, KGenericFactory<KstJS>)
 
+static KstJS *inst = 0L;
 
 class Function : public KJS::ObjectImp {
   public:
@@ -115,6 +116,7 @@
   KJSEmbed::JSSecurityPolicy::setDefaultPolicy(KJSEmbed::JSSecurityPolicy::CapabilityAll);
   _jsPart = new KJSEmbed::KJSEmbedPart(0L, "javascript", this, "kjsembedpart");
   createBindings();
+  ::inst = this;
 
 #ifdef KST_HAVE_READLINE
   _showAction = new KToggleAction(i18n("Show &JavaScript Console"), 0, 0, 0, 0, actionCollection(), "js_console_show");
@@ -141,6 +143,7 @@
   _konsolePart = 0L;
   delete _iface;
   _iface = 0L;
+  ::inst = 0L;
   destroyRegistry();
   KstApp *app = dynamic_cast<KstApp*>(this->app());
   if (app && app->guiFactory()) {
@@ -149,6 +152,11 @@
 }
 
 
+KstJS* KstJS::inst() {
+  return ::inst;
+}
+
+
 void KstJS::processArguments(const QString& args) {
   _args.append(args);
   QTimer::singleShot(0, this, SLOT(doArgs()));
--- branches/work/kst/1.6/kst/src/extensions/js/js.h #740642:740643
@@ -38,6 +38,8 @@
     KstJS(QObject *parent, const char *name, const QStringList&);
     virtual ~KstJS();
 
+    static KstJS* inst();
+
     // To save state
     virtual void load(QDomElement& e);
     virtual void save(QTextStream& ts, const QString& indent = QString::null);


More information about the Kst mailing list