1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
21 |
18 |
|
19 #include "ChromeConsole.h" |
22 #include "ChromeConsole.h" |
20 #include "../ChromeWidget.h" |
23 #include "../ChromeWidget.h" |
21 #include "qwebpage.h" |
24 #include <QWebPage> |
22 #include "qwebframe.h" |
25 #include <QWebFrame> |
23 #include "ui_console.h" |
26 #include "ui_console.h" |
|
27 #include "bedrockprovisioning.h" |
24 |
28 |
25 |
29 |
26 ChromeConsole::ChromeConsole(GVA::ChromeWidget *chromeWidget) |
30 ChromeConsole::ChromeConsole(GVA::ChromeWidget *chromeWidget) |
27 : QDialog(), |
31 : QDialog(), |
28 m_chromeWidget(chromeWidget), |
32 m_chromeWidget(chromeWidget), |
36 sizes.append(30); |
40 sizes.append(30); |
37 m_ui->splitter->setSizes(sizes); |
41 m_ui->splitter->setSizes(sizes); |
38 |
42 |
39 // Read the saved state from disk. |
43 // Read the saved state from disk. |
40 try { |
44 try { |
41 QFile file("console.dat"); |
45 QFile file(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory") + "console.dat"); |
42 if(file.open(QIODevice::ReadOnly)) { |
46 if (file.open(QIODevice::ReadOnly)) { |
43 QDataStream in(&file); |
47 QDataStream in(&file); |
44 QString str; |
48 QString str; |
45 in >> str; |
49 in >> str; |
46 m_ui->outputEdit->setPlainText(str); |
50 m_ui->outputEdit->setPlainText(str); |
47 in >> str; |
51 in >> str; |
64 QVariant ChromeConsole::evaluateExpression(const QString &expression) { |
68 QVariant ChromeConsole::evaluateExpression(const QString &expression) { |
65 m_expressionHistory.push_front(expression); |
69 m_expressionHistory.push_front(expression); |
66 m_historyIndex = 0; |
70 m_historyIndex = 0; |
67 |
71 |
68 QVariant result = m_chromeWidget->page()->mainFrame()->evaluateJavaScript(expression); |
72 QVariant result = m_chromeWidget->page()->mainFrame()->evaluateJavaScript(expression); |
69 qDebug() << result; |
|
70 return result; |
73 return result; |
71 } |
74 } |
72 |
75 |
73 void ChromeConsole::evaluate() { // slot |
76 void ChromeConsole::evaluate() { // slot |
74 QString expression = m_ui->inputEdit->toPlainText(); |
77 QString expression = m_ui->inputEdit->toPlainText(); |
75 m_ui->outputEdit->appendPlainText(">> " + expression); |
78 m_ui->outputEdit->appendPlainText(">> " + expression); |
76 QVariant result = evaluateExpression(expression); |
79 QVariant result = evaluateExpression(expression); |
77 |
80 |
78 // Figure out the best way to print the result, must be a better way to do this... |
81 // Figure out the best way to print the result, must be a better way to do this... |
79 if(result == QVariant()) { |
82 if (result == QVariant()) { |
80 m_ui->outputEdit->appendPlainText("undefined"); |
83 m_ui->outputEdit->appendPlainText("undefined"); |
81 } |
84 } |
82 else if(result.toString() != "") { |
85 else if (result.toString() != "") { |
83 m_ui->outputEdit->appendPlainText(result.toString()); |
86 m_ui->outputEdit->appendPlainText(result.toString()); |
84 } |
87 } |
85 else if(result.type() == QVariant::List) { |
88 else if (result.type() == QVariant::List) { |
86 m_ui->outputEdit->appendPlainText(result.toStringList().join(",")); |
89 m_ui->outputEdit->appendPlainText(result.toStringList().join(",")); |
87 } |
90 } |
88 else { |
91 else { |
89 // Probably a complex object, this won't be a real javascript value but it |
92 // Probably a complex object, this won't be a real javascript value but it |
90 // will be informative to the developer. |
93 // will be informative to the developer. |
110 void ChromeConsole::dump() { // slot |
113 void ChromeConsole::dump() { // slot |
111 m_chromeWidget->dump(); |
114 m_chromeWidget->dump(); |
112 } |
115 } |
113 |
116 |
114 void ChromeConsole::keyPressEvent(QKeyEvent *event) { |
117 void ChromeConsole::keyPressEvent(QKeyEvent *event) { |
115 switch(event->key()) { |
118 switch (event->key()) { |
116 case Qt::Key_Enter: |
119 case Qt::Key_Enter: |
117 case Qt::Key_Return: |
120 case Qt::Key_Return: |
118 if(event->modifiers() | Qt::ControlModifier) |
121 if (event->modifiers() | Qt::ControlModifier) |
119 evaluate(); |
122 evaluate(); |
120 break; |
123 break; |
121 case Qt::Key_Up: |
124 case Qt::Key_Up: |
122 if(event->modifiers() | Qt::ControlModifier) { |
125 if (event->modifiers() | Qt::ControlModifier) { |
123 if(m_historyIndex < m_expressionHistory.count() - 1) |
126 if (m_historyIndex < m_expressionHistory.count() - 1) |
124 m_ui->inputEdit->setPlainText(m_expressionHistory[++m_historyIndex]); |
127 m_ui->inputEdit->setPlainText(m_expressionHistory[++m_historyIndex]); |
125 } |
128 } |
126 break; |
129 break; |
127 case Qt::Key_Down: |
130 case Qt::Key_Down: |
128 if(event->modifiers() | Qt::ControlModifier) { |
131 if (event->modifiers() | Qt::ControlModifier) { |
129 if(m_historyIndex > 0) |
132 if (m_historyIndex > 0) |
130 m_ui->inputEdit->setPlainText(m_expressionHistory[--m_historyIndex]); |
133 m_ui->inputEdit->setPlainText(m_expressionHistory[--m_historyIndex]); |
131 } |
134 } |
132 break; |
135 break; |
133 } |
136 } |
134 } |
137 } |
135 |
138 |
136 void ChromeConsole::accept() { // slot |
139 void ChromeConsole::accept() { // slot |
137 try { |
140 try { |
138 // Save the state to disk. |
141 // Save the state to disk. |
139 QFile file("console.dat"); |
142 QFile file(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory") + "console.dat"); |
140 if(file.open(QIODevice::WriteOnly)) { |
143 if (file.open(QIODevice::WriteOnly)) { |
141 QDataStream out(&file); |
144 QDataStream out(&file); |
142 out << m_ui->outputEdit->toPlainText(); |
145 out << m_ui->outputEdit->toPlainText(); |
143 out << m_ui->inputEdit->toPlainText(); |
146 out << m_ui->inputEdit->toPlainText(); |
144 out << m_ui->inputEdit->textCursor().position(); |
147 out << m_ui->inputEdit->textCursor().position(); |
145 out << m_expressionHistory; |
148 out << m_expressionHistory; |