Permalink
Browse files

add readFile writeFile callProcess(process, callback)

  • Loading branch information...
1 parent 335c3ea commit 76329afdd4454679cc84585aacfe2a0d25901e09 xunxin committed Aug 12, 2009
Showing with 73 additions and 0 deletions.
  1. +18 −0 mainwindow.cpp
  2. +55 −0 mainwindow.h
View
@@ -42,6 +42,13 @@ MainWindow::MainWindow(const QString& url): currentZoom(100) {
readSettings();
setupUI();
+ m_callProc = new QProcess();
+
+ connect(m_view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
+ this, SLOT(populateJavaScriptWindowObject()));
+
+ connect(m_callProc, SIGNAL(finished(int, QProcess::ExitStatus)),
+ this, SLOT(processFinished(int, QProcess::ExitStatus)));
QUrl qurl;
qurl.setEncodedUrl(url.toUtf8(), QUrl::StrictMode);
@@ -379,6 +386,13 @@ void MainWindow::createSettingsMenu() {
enableJS->setCheckable(true);
enableJS->setChecked(m_enableJavascript);
}
+
+ {
+ QAction *enableParseJS = prefMenu->addAction(tr("Enable &Parse Javascript"), this, SLOT(toggleEnableParseJavascript(bool)));
+ enableParseJS->setCheckable(true);
+ enableParseJS->setChecked(m_enableParseJavascript);
+ }
+
{
QAction *enableImages = prefMenu->addAction(tr("Enable &Images"), this, SLOT(toggleEnableImages(bool)));
enableImages->setCheckable(true);
@@ -414,6 +428,7 @@ void MainWindow::writeSettings() {
m_settings->setValue("pos", pos());
m_settings->setValue("enableJavascript", QVariant(m_enableJavascript));
+ m_settings->setValue("enableParseJavascript", QVariant(m_enableParseJavascript));
m_settings->setValue("enablePlugins", QVariant(m_enablePlugins));
m_settings->setValue("enableImages", QVariant(m_enableImages));
m_settings->setValue("enableJava", QVariant(m_enableJava));
@@ -438,6 +453,9 @@ void MainWindow::readSettings() {
move(m_settings->value("pos", QPoint(200, 200)).toPoint());
m_enableJavascript = m_settings->value("enableJavascript").toBool();
+ m_enableParseJavascript = m_settings->value("enableParseJavascript").toBool();
+ QWebVDom::setEnabledParseJavascript(m_enableParseJavascript);
+
m_enablePlugins = m_settings->value("enablePlugins").toBool();
m_enableImages = m_settings->value("enableImages").toBool();
m_enableJava = m_settings->value("enableJava").toBool();
View
@@ -35,6 +35,51 @@ class MainWindow : public QMainWindow
void setJSFiles(QStringList& jsFiles);
+public slots:
+ void populateJavaScriptWindowObject() {
+ m_view->page()->mainFrame()->addToJavaScriptWindowObject("vdom_external_call", this);
+ }
+
+ QString readFile(const QString& filePath) {
+ qDebug() << "read file: " << filePath;
+ QFile file(filePath);
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return "";
+
+ QTextStream in(&file);
+ QString content = in.readAll();
+
+ qDebug() << "read file: " << content;
+ file.close();
+
+ return content;
+ }
+
+ bool writeFile(const QString& filePath, const QString& content) {
+ qDebug() << "write file: " << filePath;
+ QFile file(filePath);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ return false;
+ }
+
+ QTextStream out(&file);
+ out<<content;
+ file.close();
+
+ return true;
+ }
+
+ void processFinished(int exitCode, QProcess::ExitStatus) {
+ qDebug() << "processFinished: " << m_processCallback << exitCode;
+ m_view->page()->mainFrame()->evaluateJavaScript(m_processCallback + "(" + QString::number(exitCode) + ");");
+ }
+
+ bool callProcess(const QString& process, const QString& callback) {
+ m_processCallback = callback;
+ m_callProc->start(process);
+ return true;
+ }
+
protected:
virtual void closeEvent(QCloseEvent * event);
@@ -146,6 +191,11 @@ protected slots:
m_view->page()->settings()->setAttribute(QWebSettings::JavascriptEnabled, enabled);
}
+ void toggleEnableParseJavascript(bool enabled) {
+ m_enableParseJavascript = enabled;
+ QWebVDom::setEnabledParseJavascript(enabled);
+ }
+
void toggleEnableJava(bool enabled) {
m_enableJava = enabled;
m_view->page()->settings()->setAttribute(QWebSettings::JavaEnabled, enabled);
@@ -221,6 +271,8 @@ protected slots:
QSettings* m_settings;
bool m_enableJavascript;
+ bool m_enableParseJavascript;
+
bool m_enablePlugins;
bool m_enableImages;
bool m_enableJava;
@@ -247,6 +299,9 @@ protected slots:
QSplitter* m_mainSplitter;
QStringList m_injectedJSFiles;
+
+ QString m_processCallback;
+ QProcess* m_callProc;
};
#endif

0 comments on commit 76329af

Please sign in to comment.