[Kst] branches/work/kst/viewupdates/kst/src/libkstapp
George Staikos
staikos at kde.org
Sun May 28 19:11:26 CEST 2006
SVN commit 545969 by staikos:
Make it use events so it doesn't crash and add support for executing KstScript
M +68 -21 ksteventmonitorentry.cpp
M +30 -24 ksteventmonitorentry.h
--- branches/work/kst/viewupdates/kst/src/libkstapp/ksteventmonitorentry.cpp #545968:545969
@@ -16,10 +16,14 @@
* *
***************************************************************************/
+#include <config.h>
+
// include files for Qt
#include <qstylesheet.h>
+#include <qthread.h>
// include files for KDE
+#include <dcopref.h>
#include <klocale.h>
// application specific includes
@@ -30,6 +34,9 @@
#include "ksteventmonitorentry.h"
#include "ksteventmonitor_i.h"
+#include <assert.h>
+#include <unistd.h>
+
extern "C" int yyparse();
extern "C" void *ParsedEquation;
extern "C" struct yy_buffer_state *yy_scan_string(const char*);
@@ -150,7 +157,7 @@
EventMonitorEntry::~EventMonitorEntry() {
- logImmediately();
+ logImmediately(false);
delete _pExpression;
_pExpression = 0L;
@@ -180,14 +187,8 @@
KstVectorPtr yv = *_yVector;
int ns = 1;
- if (_vectorsUsed.count() > 0) {
- for (KstVectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) {
- if (i.data()->length() > ns) {
- ns = i.data()->length();
- }
- }
- } else {
- ns = 1;
+ for (KstVectorMap::ConstIterator i = _vectorsUsed.begin(); i != _vectorsUsed.end(); ++i) {
+ ns = kMax(ns, i.data()->length());
}
double *rawValuesX = 0L;
@@ -264,7 +265,17 @@
}
-void EventMonitorEntry::logImmediately() {
+namespace {
+ const int EventMonitorEventType = int(QEvent::User) + 2931;
+ class EventMonitorEvent : public QEvent {
+ public:
+ EventMonitorEvent(const QString& msg) : QEvent(QEvent::Type(EventMonitorEventType)), logMessage(msg) {}
+ QString logMessage;
+ };
+}
+
+
+void EventMonitorEntry::logImmediately(bool sendEvent) {
const int arraySize = _indexArray.size();
if (arraySize > 0) {
@@ -299,23 +310,46 @@
logMessage = i18n("Event Monitor: %1: %2").arg(_description).arg(rangeString);
}
- if (_logKstDebug) {
- KstDebug::self()->log(logMessage, _level);
- }
+ _indexArray.clear();
- if (_logEMail && !_eMailRecipients.isEmpty()) {
- // FIXME: wrong thread - can crash (QStrings unguarded, at best)
- EMailThread* thread = new EMailThread(_eMailRecipients, i18n("Kst Event Monitoring Notification"), logMessage);
- thread->send();
+ if (sendEvent) { // update thread
+ QApplication::postEvent(this, new EventMonitorEvent(logMessage));
+ } else { // GUI thread
+ doLog(logMessage);
}
+ }
+}
- if (_logELOG) {
- // FIXME: wrong thread - can crash
- KstApp::inst()->EventELOGSubmitEntry(logMessage);
+
+bool EventMonitorEntry::event(QEvent *e) {
+ if (e->type() == EventMonitorEventType) {
+ writeLock();
+ doLog(static_cast<EventMonitorEvent*>(e)->logMessage);
+ writeUnlock();
+ return true;
}
+ return false;
+}
- _indexArray.clear();
+
+void EventMonitorEntry::doLog(const QString& logMessage) const {
+ if (_logKstDebug) {
+ KstDebug::self()->log(logMessage, _level);
}
+
+ if (_logEMail && !_eMailRecipients.isEmpty()) {
+ EMailThread* thread = new EMailThread(_eMailRecipients, i18n("Kst Event Monitoring Notification"), logMessage);
+ thread->send();
+ }
+
+ if (_logELOG) {
+ KstApp::inst()->EventELOGSubmitEntry(logMessage);
+ }
+
+ if (!_script.isEmpty()) {
+ DCOPRef ref(QString("kst-%1").arg(getpid()).latin1(), "KstScript");
+ ref.call("evaluate", _script);
+ }
}
@@ -337,6 +371,19 @@
}
+const QString& EventMonitorEntry::scriptCode() const {
+ return _script;
+}
+
+
+void EventMonitorEntry::setScriptCode(const QString& script) {
+ if (_script != script) {
+ setDirty();
+ _script = script;
+ }
+}
+
+
void EventMonitorEntry::setDescription(const QString& str) {
if (_description != str) {
setDirty();
--- branches/work/kst/viewupdates/kst/src/libkstapp/ksteventmonitorentry.h #545968:545969
@@ -33,12 +33,12 @@
public:
EventMonitorEntry(const QString &in_tag);
EventMonitorEntry(const QDomElement &e);
- virtual ~EventMonitorEntry();
+ ~EventMonitorEntry();
- virtual UpdateType update(int updateCounter = -1);
- virtual void save(QTextStream &ts, const QString& indent = QString::null);
- virtual QString propertyString() const;
- virtual void _showDialog();
+ UpdateType update(int updateCounter = -1);
+ void save(QTextStream &ts, const QString& indent = QString::null);
+ QString propertyString() const;
+ void _showDialog();
bool needToEvaluate();
bool isValid() const { return _isValid; }
@@ -52,21 +52,21 @@
bool logEMail() const { return _logEMail; }
bool logELOG() const { return _logELOG; }
const QString& eMailRecipients() const { return _eMailRecipients; }
+ const QString& scriptCode() const;
+ void setScriptCode(const QString& script);
void setEvent(const QString& str);
void setDescription(const QString& str);
void setLevel(KstDebug::LogLevel level);
void setExpression(Equation::Node* pExpression);
- void setLogKstDebug(bool bLogKstDebug);
- void setLogEMail(bool bLogEMail);
- void setLogELOG(bool bLogELOG);
+ void setLogKstDebug(bool logKstDebug);
+ void setLogEMail(bool logEMail);
+ void setLogELOG(bool logELOG);
void setEMailRecipients(const QString& str);
- void logImmediately();
-
bool reparse();
- virtual KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap);
+ KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap);
void replaceDependency(KstDataObjectPtr oldObject, KstDataObjectPtr newObject);
@@ -75,29 +75,35 @@
bool uses(KstObjectPtr p) const;
+ protected:
+ bool event(QEvent *e);
+
private slots:
- void slotUpdate();
+ void slotUpdate();
+ void doLog(const QString& logMessage) const;
private:
+ void logImmediately(bool sendEvent = true);
void commonConstructor(const QString &in_tag);
static const QString OUTXVECTOR;
static const QString OUTYVECTOR;
- KstVectorMap _vectorsUsed;
- QValueList<int> _indexArray;
- QString _event;
- QString _description;
- QString _eMailRecipients;
- KstDebug::LogLevel _level;
- Equation::Node* _pExpression;
+ KstVectorMap _vectorsUsed;
+ QValueList<int> _indexArray;
+ QString _event;
+ QString _description;
+ QString _eMailRecipients;
+ KstDebug::LogLevel _level;
+ Equation::Node* _pExpression;
KstVectorMap::Iterator _xVector;
KstVectorMap::Iterator _yVector;
- bool _logKstDebug;
- bool _logEMail;
- bool _logELOG;
- bool _isValid;
- int _numDone;
+ bool _logKstDebug;
+ bool _logEMail;
+ bool _logELOG;
+ bool _isValid;
+ int _numDone;
+ QString _script;
};
typedef KstSharedPtr<EventMonitorEntry> EventMonitorEntryPtr;
More information about the Kst
mailing list