ginebra2/emulator/ChromeConsole.cpp
changeset 5 0f2326c2a325
parent 0 1450b09d0cfd
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     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;
    74     QString expression = m_ui->inputEdit->toPlainText();
    78     QString expression = m_ui->inputEdit->toPlainText();
    75     m_ui->outputEdit->appendPlainText(">> " + expression);
    79     m_ui->outputEdit->appendPlainText(">> " + expression);
    76     QVariant result = evaluateExpression(expression);
    80     QVariant result = evaluateExpression(expression);
    77 
    81 
    78     // Figure out the best way to print the result, must be a better way to do this...
    82     // Figure out the best way to print the result, must be a better way to do this...
    79     if(result == QVariant()) {
    83     if (result == QVariant()) {
    80         m_ui->outputEdit->appendPlainText("undefined");
    84         m_ui->outputEdit->appendPlainText("undefined");
    81     }
    85     }
    82     else if(result.toString() != "") {
    86     else if (result.toString() != "") {
    83         m_ui->outputEdit->appendPlainText(result.toString());
    87         m_ui->outputEdit->appendPlainText(result.toString());
    84     }
    88     }
    85     else if(result.type() == QVariant::List) {
    89     else if (result.type() == QVariant::List) {
    86         m_ui->outputEdit->appendPlainText(result.toStringList().join(","));
    90         m_ui->outputEdit->appendPlainText(result.toStringList().join(","));
    87     }
    91     }
    88     else {
    92     else {
    89         // Probably a complex object, this won't be a real javascript value but it
    93         // Probably a complex object, this won't be a real javascript value but it
    90         // will be informative to the developer.
    94         // will be informative to the developer.
   110 void ChromeConsole::dump() {  // slot
   114 void ChromeConsole::dump() {  // slot
   111     m_chromeWidget->dump();
   115     m_chromeWidget->dump();
   112 }
   116 }
   113 
   117 
   114 void ChromeConsole::keyPressEvent(QKeyEvent *event) {
   118 void ChromeConsole::keyPressEvent(QKeyEvent *event) {
   115     switch(event->key()) {
   119     switch (event->key()) {
   116         case Qt::Key_Enter:
   120         case Qt::Key_Enter:
   117         case Qt::Key_Return:
   121         case Qt::Key_Return:
   118           if(event->modifiers() | Qt::ControlModifier)
   122           if (event->modifiers() | Qt::ControlModifier)
   119               evaluate();
   123               evaluate();
   120           break;
   124           break;
   121         case Qt::Key_Up:
   125         case Qt::Key_Up:
   122           if(event->modifiers() | Qt::ControlModifier) {
   126           if (event->modifiers() | Qt::ControlModifier) {
   123               if(m_historyIndex < m_expressionHistory.count() - 1)
   127               if (m_historyIndex < m_expressionHistory.count() - 1)
   124                   m_ui->inputEdit->setPlainText(m_expressionHistory[++m_historyIndex]);
   128                   m_ui->inputEdit->setPlainText(m_expressionHistory[++m_historyIndex]);
   125           }
   129           }
   126           break;
   130           break;
   127         case Qt::Key_Down:
   131         case Qt::Key_Down:
   128           if(event->modifiers() | Qt::ControlModifier) {
   132           if (event->modifiers() | Qt::ControlModifier) {
   129               if(m_historyIndex > 0)
   133               if (m_historyIndex > 0)
   130                   m_ui->inputEdit->setPlainText(m_expressionHistory[--m_historyIndex]);
   134                   m_ui->inputEdit->setPlainText(m_expressionHistory[--m_historyIndex]);
   131           }
   135           }
   132           break;
   136           break;
   133     }
   137     }
   134 }
   138 }
   135 
   139 
   136 void ChromeConsole::accept() {  // slot
   140 void ChromeConsole::accept() {  // slot
   137     try {
   141     try {
   138         // Save the state to disk.
   142         // Save the state to disk.
   139         QFile file("console.dat");
   143         QFile file(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory") + "console.dat");
   140         if(file.open(QIODevice::WriteOnly)) {
   144         if (file.open(QIODevice::WriteOnly)) {
   141             QDataStream out(&file);
   145             QDataStream out(&file);
   142             out << m_ui->outputEdit->toPlainText();
   146             out << m_ui->outputEdit->toPlainText();
   143             out << m_ui->inputEdit->toPlainText();
   147             out << m_ui->inputEdit->toPlainText();
   144             out << m_ui->inputEdit->textCursor().position();
   148             out << m_ui->inputEdit->textCursor().position();
   145             out << m_expressionHistory;
   149             out << m_expressionHistory;