summaryrefslogtreecommitdiffstats
path: root/client/browser
diff options
context:
space:
mode:
authoradelcastillo <adelcastillo@us.es>2009-10-29 01:25:40 +0000
committeradelcastillo <adelcastillo@us.es>2009-10-29 01:25:40 +0000
commit8fd79ac1616f8e984c3abbf70eaad84dd7b2b165 (patch)
tree07ef05564da23faf54dac0ea496541faf4ef29fb /client/browser
parentae0498794ac663448d63a16de2f44a0132746753 (diff)
Ahora el browser tiene terminal y salida por pestanyas.
git-svn-id: https://opengnsys.es/svn/trunk@453 a21b9725-9963-47de-94b9-378ad31fedc9
Diffstat (limited to 'client/browser')
-rw-r--r--client/browser/CMakeLists.txt23
-rw-r--r--client/browser/mainwindow.cpp105
-rw-r--r--client/browser/mainwindow.h11
-rw-r--r--client/browser/qtermwidget/CMakeLists.txt2
-rw-r--r--client/browser/src/main.cpp17
-rw-r--r--client/browser/src/mainwindow.cpp279
-rw-r--r--client/browser/src/mainwindow.h65
7 files changed, 100 insertions, 402 deletions
diff --git a/client/browser/CMakeLists.txt b/client/browser/CMakeLists.txt
index 815123ca..0648bdbe 100644
--- a/client/browser/CMakeLists.txt
+++ b/client/browser/CMakeLists.txt
@@ -2,9 +2,22 @@ project(browser)
cmake_minimum_required(VERSION 2.6)
-find_package(Qt4 REQUIRED)
-include_directories(qtermwidget/src/ ${QT_INCLUDES} ${QT_QTWEBKIT_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
+if(QTEMBEDDED)
+ #set(QT_INCLUDES /usr/local/Trolltech/include/)
+ find_library(QT_LIBRARY NAMES QtWebKit PATHS /usr/local/Trolltech/QtEmbedded-4.5.1/lib/)
+ message("${QT_LIBRARY}")
+ message("Embedded")
+
+else(QTEMBEDDED)
+ find_package(Qt4 REQUIRED)
+ message("Normal")
+endif(QTEMBEDDED)
+
+# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in about every subdir
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+include_directories(qtermwidget/src/ ${QT_INCLUDES} ${QT_QTWEBKIT_INCLUDE_DIR})
add_subdirectory(qtermwidget)
@@ -14,4 +27,8 @@ qt4_automoc(${browser_SRCS})
add_executable(browser ${browser_SRCS})
-target_link_libraries(browser qtermwidget ${QT_LIBRARIES} ${QT_QTWEBKIT_LIBRARIES} )
+target_link_libraries(browser qtermwidget ${QT_QTWEBKIT_LIBRARIES} )
+
+foreach(QT ${QT_LIBRARIES})
+ message("${QT}")
+endforeach(QT)
diff --git a/client/browser/mainwindow.cpp b/client/browser/mainwindow.cpp
index d22bff34..5ed74e52 100644
--- a/client/browser/mainwindow.cpp
+++ b/client/browser/mainwindow.cpp
@@ -1,5 +1,4 @@
#include "mainwindow.h"
-#include "mainwindow.moc"
#include <QtWebKit>
#include <QStringList>
#include <QWebView>
@@ -11,42 +10,58 @@
#include <QMessageBox>
#include <QPushButton>
#include <QDateTime>
+#include <QProgressBar>
+#include <QTabWidget>
#include "qtermwidget.h"
+#include "mainwindow.moc"
+
#define BUFFERSIZE 2048
#define CURRENT_TIME() QDateTime::currentDateTime().toString("dd/MM/yy hh:mm:ss")
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent),web(new QWebView()),text(new QTextEdit()),
+ : QMainWindow(parent),web(new QWebView()),output(new QTextEdit()),
process(new QProcess(this)),
logfile(NULL),logstream(NULL)
{
// Graphic
+ //showFullScreen();
+
+ setWindowTitle(tr("OpenGNSys Browser"));
+
setCentralWidget(web);
- dock=new QDockWidget(this);
+ // Output
+ output->setReadOnly(true);
+
+ // Dock
+ QDockWidget* dock=new QDockWidget();
dock->setAllowedAreas(Qt::BottomDockWidgetArea);
- dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
+ QWidget* dummy=new QWidget();
+ dummy->setMaximumHeight(0);
+ dock->setTitleBarWidget(dummy);
- console = new QTermWidget();
-
- QFont font = QApplication::font();
- font.setFamily("Terminus");
- font.setPointSize(12);
-
- console->setTerminalFont(font);
-
- //console->setColorScheme(COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW);
- console->setScrollBarPosition(QTermWidget::ScrollBarRight);
-
- //showFullScreen();
+ // TabWidget
+ tabs=new QTabWidget(dock);
+
+ // Anyado output a las pestanyas
+ tabs->addTab(output,tr("Output"));
+ tabs->addTab(createTerminal(),tr("Term 1"));
- dock->setWidget(console);
+ // Las pestanyas al dock
+ dock->setWidget(tabs);
+
+ // Y el dock al mainwindow
addDockWidget(Qt::BottomDockWidgetArea,dock);
- text->setReadOnly(true);
+ // Status bar
+ QStatusBar* st=statusBar();
+ st->setSizeGripEnabled(false);
+ progressBar=new QProgressBar(this);
+ progressBar->setMinimum(0);
+ progressBar->setMaximum(100);
web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
@@ -73,11 +88,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(process,SIGNAL(readyReadStandardError()),
this,SLOT(slotProcessErrorOutput()));
- // Set tittle
- setWindowTitle(tr("OpenGNSys Browser"));
-
if(!readEnvironmentValues())
- text->insertPlainText(tr("Any environment variable/s didn't be setted\n"));
+ output->insertPlainText(tr("Any environment variable/s didn't be setted\n"));
if(env.contains("OGLOGFILE") && env["OGLOGFILE"]!="")
{
@@ -85,7 +97,7 @@ MainWindow::MainWindow(QWidget *parent)
if(!logfile->open(QIODevice::WriteOnly | QIODevice::Text |
QIODevice::Append))
{
- text->insertPlainText(tr("The log file couldn't be opened: ")+logfile->fileName());
+ output->insertPlainText(tr("The log file couldn't be opened: ")+logfile->fileName());
delete logfile;
logfile=NULL;
}
@@ -107,6 +119,13 @@ MainWindow::~MainWindow()
void MainWindow::slotLinkHandle(const QUrl &url)
{
+ // Si ya hay un proceso ejectuandose
+ if(process->state()!=QProcess::NotRunning)
+ {
+ output->insertPlainText(tr("There is a process running."));
+ return;
+ }
+
QString string = url.toString();
qDebug() << string;
// Si es un link del tipo PROTOCOL lo ejecutamos
@@ -129,11 +148,18 @@ void MainWindow::slotLinkHandle(const QUrl &url)
void MainWindow::slotWebLoadStarted()
{
+ QStatusBar* st=statusBar();
+ st->clearMessage();
+ st->addWidget(progressBar,100);
+ progressBar->show();
+ progressBar->setFormat("%p% Loading");
+
qDebug()<<"Empieza la carga de la web";
}
void MainWindow::slotWebLoadProgress(int progress)
{
+ progressBar->setValue(progress);
qDebug()<<"Progress "<<progress;
}
@@ -163,7 +189,13 @@ void MainWindow::slotWebLoadFinished(bool ok)
}
}
else
+ {
qDebug()<<"Descarga finalizada satisfactoriamente";
+
+ QStatusBar* st=statusBar();
+ st->removeWidget(progressBar);
+ st->showMessage(tr("Ready"));
+ }
}
void MainWindow::slotProcessStarted()
@@ -178,14 +210,13 @@ void MainWindow::slotProcessOutput()
char buf[BUFFERSIZE];
while((process->readLine(buf,BUFFERSIZE) > 0))
{
- text->insertPlainText(buf);
+ output->insertPlainText(buf);
/*
QString str="<b>";
str+=buf;
str+="</b>";
- text->insertHtml(str);
+ output->insertHtml(str);
*/
- output<<buf;
if(logstream)
*logstream<<CURRENT_TIME()<<": "<<buf;
}
@@ -198,8 +229,9 @@ void MainWindow::slotProcessErrorOutput()
char buf[BUFFERSIZE];
while((process->readLine(buf,BUFFERSIZE) > 0))
{
- text->insertPlainText(buf);
- errors<<buf;
+ output->insertPlainText(buf);
+ if(logstream)
+ *logstream<<CURRENT_TIME()<<": "<<buf;
}
}
@@ -208,13 +240,11 @@ void MainWindow::slotProcessFinished(int code,QProcess::ExitStatus status)
if(status==QProcess::NormalExit)
{
qDebug()<<"Finished: "<<code<<" "<<status<<endl;
- qDebug()<<"OUTPUT:"<<endl<<output<<endl<<"ERROR:"<<endl<<errors<<endl;
}
else
{
qDebug()<<"Ha petado"<<endl;
qDebug()<<"Finished: "<<code<<" "<<status<<endl;
- qDebug()<<"OUTPUT:"<<endl<<output<<endl<<"ERROR:"<<endl<<errors<<endl;
}
}
@@ -270,3 +300,18 @@ int MainWindow::readEnvironmentValues()
return ret;
}
+QTermWidget* MainWindow::createTerminal()
+{
+ QTermWidget* console = new QTermWidget();
+ QFont font = QApplication::font();
+ font.setFamily("Terminus");
+ font.setPointSize(12);
+
+ console->setTerminalFont(font);
+
+ //console->setColorScheme(COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW);
+ console->setScrollBarPosition(QTermWidget::ScrollBarRight);
+
+ return console;
+}
+
diff --git a/client/browser/mainwindow.h b/client/browser/mainwindow.h
index b51de988..535497d1 100644
--- a/client/browser/mainwindow.h
+++ b/client/browser/mainwindow.h
@@ -19,8 +19,8 @@ class QString;
class QUrl;
class QFile;
class QTextStream;
-class QDockWidget;
class QTermWidget;
+class QProgressBar;
class MainWindow : public QMainWindow
{
@@ -47,17 +47,16 @@ class MainWindow : public QMainWindow
//Functions
protected:
int readEnvironmentValues();
+ QTermWidget* createTerminal();
protected:
QWebView *web;
- QTextEdit *text;
- QDockWidget *dock;
- QTermWidget *console;
+ QTextEdit *output;
+ QProgressBar *progressBar;
+ QTabWidget *tabs;
QProcess *process;
- QStringList output;
- QStringList errors;
QMap<QString,QString> env;
QFile *logfile;
diff --git a/client/browser/qtermwidget/CMakeLists.txt b/client/browser/qtermwidget/CMakeLists.txt
index 8cb94542..c503292c 100644
--- a/client/browser/qtermwidget/CMakeLists.txt
+++ b/client/browser/qtermwidget/CMakeLists.txt
@@ -2,8 +2,6 @@ add_definitions(-DHAVE_POSIX_OPENPT)
aux_source_directory(src qtermwidget_SRCS)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
qt4_automoc(${qtermwidget_SRCS})
add_library(qtermwidget STATIC ${qtermwidget_SRCS})
diff --git a/client/browser/src/main.cpp b/client/browser/src/main.cpp
deleted file mode 100644
index d1873ce3..00000000
--- a/client/browser/src/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <QtGui/QApplication>
-#include <stdio.h>
-#include "mainwindow.h"
-
-int main(int argc, char *argv[])
-{
- if(argc<=1)
- {
- printf("Usage: %s http://siteweb.com/\n",argv[0]);
- return -1;
- }
-
- QApplication a(argc, argv);
- MainWindow w;
- w.show();
- return a.exec();
-}
diff --git a/client/browser/src/mainwindow.cpp b/client/browser/src/mainwindow.cpp
deleted file mode 100644
index 3db6778f..00000000
--- a/client/browser/src/mainwindow.cpp
+++ /dev/null
@@ -1,279 +0,0 @@
-#include "mainwindow.h"
-#include "mainwindow.moc"
-#include <QtWebKit>
-#include <QStringList>
-#include <QWebView>
-#include <QDockWidget>
-#include <QtDebug>
-#include <QWebPage>
-#include <QProcess>
-#include <QTextEdit>
-#include <QMessageBox>
-#include <QPushButton>
-#include <QDateTime>
-
-#define BUFFERSIZE 2048
-
-#define CURRENT_TIME() QDateTime::currentDateTime().toString("dd/MM/yy hh:mm:ss")
-
-MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent),web(new QWebView()),text(new QTextEdit()),
- process(new QProcess(this)),
- logfile(NULL),logstream(NULL)
-{
- // Graphic
- //layout->addWidget(web);
- //layout->addWidget(text);
- //setLayout(layout);
- setCentralWidget(web);
-
- dock=new QDockWidget(this);
- dock->setAllowedAreas(Qt::BottomDockWidgetArea);
- dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
- dock->setWidget(text);
- addDockWidget(Qt::BottomDockWidgetArea,dock);
-
-
- /*
- QTermWidget *console = new QTermWidget();
-
- QFont font = QApplication::font();
- font.setFamily("Terminus");
- font.setPointSize(12);
-
- console->setTerminalFont(font);
-
- //console->setColorScheme(COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW);
- console->setScrollBarPosition(QTermWidget::ScrollBarRight);
-
- mainWindow->setCentralWidget(console);
- mainWindow->resize(802, 610);
-
- QObject::connect(console, SIGNAL(finished()), mainWindow, SLOT(close()));
- */
- //showFullScreen();
-
- text->setReadOnly(true);
-
- web->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
-
- // Web signals
- connect(web->page(),SIGNAL(linkClicked(const QUrl&)),this,
- SLOT(slotLinkHandle(const QUrl&)));
- connect(web,SIGNAL(loadStarted()),this,SLOT(slotWebLoadStarted()));
- connect(web,SIGNAL(loadFinished(bool)),this,SLOT(slotWebLoadFinished(bool)));
- connect(web,SIGNAL(loadProgress(int)),this,SLOT(slotWebLoadProgress(int)));
-
- QStringList arguments=QCoreApplication::arguments();
- web->load(QUrl(arguments[1]));
-
-
- // Process signals
- connect(process,SIGNAL(started()),this,SLOT(slotProcessStarted()));
- connect(process,SIGNAL(finished(int,QProcess::ExitStatus)),
- this,SLOT(slotProcessFinished(int,QProcess::ExitStatus)));
-
- connect(process,SIGNAL(error(QProcess::ProcessError)),
- this,SLOT(slotProcessError(QProcess::ProcessError)));
-
- connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(slotProcessOutput()));
- connect(process,SIGNAL(readyReadStandardError()),
- this,SLOT(slotProcessErrorOutput()));
-
- // Set tittle
- setWindowTitle(tr("OpenGNSys Browser"));
-
- if(!readEnvironmentValues())
- text->insertPlainText(tr("Any environment variable/s didn't be setted\n"));
-
- if(env.contains("OGLOGFILE") && env["OGLOGFILE"]!="")
- {
- logfile=new QFile(env["OGLOGFILE"]);
- if(!logfile->open(QIODevice::WriteOnly | QIODevice::Text |
- QIODevice::Append))
- {
- text->insertPlainText(tr("The log file couldn't be opened: ")+logfile->fileName());
- delete logfile;
- logfile=NULL;
- }
- else
- logstream=new QTextStream(logfile);
- }
-}
-
-MainWindow::~MainWindow()
-{
- if(logfile)
- {
- logfile->close();
- delete logfile;
- }
- if(logstream)
- delete logstream;
-}
-
-void MainWindow::slotLinkHandle(const QUrl &url)
-{
- QString string = url.toString();
- qDebug() << string;
- // Si es un link del tipo PROTOCOL lo ejecutamos
- if(string.startsWith(PROTOCOL))
- {
- string=string.remove(0,QString(PROTOCOL).length());
- QStringList list=string.split(" ",QString::SkipEmptyParts);
- QString command=list.takeFirst();
- process->setReadChannel(QProcess::StandardOutput);
- // Le ponemos el mismo entorno que tiene el browser ahora mismo
- process->setEnvironment(QProcess::systemEnvironment());
- process->start(command,list);
- }
- else
- {
- qDebug() << "Load URL: " << url <<endl;
- web->load(url);
- }
-}
-
-void MainWindow::slotWebLoadStarted()
-{
- qDebug()<<"Empieza la carga de la web";
-}
-
-void MainWindow::slotWebLoadProgress(int progress)
-{
- qDebug()<<"Progress "<<progress;
-}
-
-void MainWindow::slotWebLoadFinished(bool ok)
-{
- // If any error ocurred, show a pop up
- // Sometimes when the url hasn't got a dot, i.e /var/www/pageweb,
- // the return value is always true so we check the bytes received too
- if(ok == false || web->page()->totalBytes() == 0)
- {
- qDebug()<<"Error accediendo a la web";
- QMessageBox msgBox;
- msgBox.setText(tr("The web page couldn't load. What do you want to do?"));
-
- QPushButton *reloadButton = msgBox.addButton(tr("Reload"), QMessageBox::ActionRole);
- msgBox.addButton(QMessageBox::Abort);
-
- msgBox.exec();
-
- if (msgBox.clickedButton() == reloadButton)
- {
- web->reload();
- }
- else
- {
- close();
- }
- }
- else
- qDebug()<<"Descarga finalizada satisfactoriamente";
-}
-
-void MainWindow::slotProcessStarted()
-{
- qDebug()<<"Proceso inicializado"<<endl;
-}
-
-void MainWindow::slotProcessOutput()
-{
- qDebug()<<"Output"<<endl;
- process->setReadChannel(QProcess::StandardOutput);
- char buf[BUFFERSIZE];
- while((process->readLine(buf,BUFFERSIZE) > 0))
- {
- text->insertPlainText(buf);
- /*
- QString str="<b>";
- str+=buf;
- str+="</b>";
- text->insertHtml(str);
- */
- output<<buf;
- if(logstream)
- *logstream<<CURRENT_TIME()<<": "<<buf;
- }
-}
-
-void MainWindow::slotProcessErrorOutput()
-{
- qDebug()<<"ErrorOutput"<<endl;
- process->setReadChannel(QProcess::StandardError);
- char buf[BUFFERSIZE];
- while((process->readLine(buf,BUFFERSIZE) > 0))
- {
- text->insertPlainText(buf);
- errors<<buf;
- }
-}
-
-void MainWindow::slotProcessFinished(int code,QProcess::ExitStatus status)
-{
- if(status==QProcess::NormalExit)
- {
- qDebug()<<"Finished: "<<code<<" "<<status<<endl;
- qDebug()<<"OUTPUT:"<<endl<<output<<endl<<"ERROR:"<<endl<<errors<<endl;
- }
- else
- {
- qDebug()<<"Ha petado"<<endl;
- qDebug()<<"Finished: "<<code<<" "<<status<<endl;
- qDebug()<<"OUTPUT:"<<endl<<output<<endl<<"ERROR:"<<endl<<errors<<endl;
- }
-}
-
-void MainWindow::slotProcessError(QProcess::ProcessError error)
-{
- switch(error)
- {
- case QProcess::FailedToStart:
- qDebug()<<"Imposible arrancar el programa"<<endl;
- break;
- // No capturo crashed porque la pillo por finished
- case QProcess::Crashed:
- case QProcess::Timedout:
- case QProcess::WriteError:
- case QProcess::ReadError:
- case QProcess::UnknownError:
- default:
- qDebug()<<"Otro error"<<endl;
- break;
- }
-}
-
-int MainWindow::readEnvironmentValues()
-{
- // The return value
- int ret=true;
-
- // Get all environment variables
- QStringList environmentlist=QProcess::systemEnvironment();
- // This is the list of the important variables
- QStringList variablelist=QString(ENVIRONMENT).split(",");
-
- // This is an auxiliar variable
- QStringList stringlist;
-
- foreach (QString str,variablelist)
- {
- // Look for the variable in the environment
- stringlist=environmentlist.filter(str+"=");
-
- if(stringlist.isEmpty())
- {
- env[str]="";
- ret=false;
- }
- else
- {
- // Get the first element and get the value part
- env[str]=(stringlist.first().split("="))[1];
- }
- }
-
- return ret;
-}
-
diff --git a/client/browser/src/mainwindow.h b/client/browser/src/mainwindow.h
deleted file mode 100644
index de712e56..00000000
--- a/client/browser/src/mainwindow.h
+++ /dev/null
@@ -1,65 +0,0 @@
-#ifndef MAINWINDOW_H
-#define MAINWINDOW_H
-
-#define PROTOCOL "command:"
-#define ENVIRONMENT "OGLOGFILE"
-//#define ENVIRONMENT "OGIP,OGSERVER,OGLOG"
-
-#include <QWidget>
-#include <QProcess>
-#include <QMap>
-#include <QMainWindow>
-
-class QWebView;
-class QTextEdit;
-class QVBoxLayout;
-class QProcess;
-class QStringList;
-class QString;
-class QUrl;
-class QFile;
-class QTextStream;
-class QDockWidget;
-
-class MainWindow : public QMainWindow
-{
- Q_OBJECT
-
- public:
- MainWindow(QWidget *parent = 0);
- ~MainWindow();
-
- public slots:
- // Funcion que maneja los links
- void slotLinkHandle(const QUrl& url);
- void slotWebLoadStarted();
- void slotWebLoadFinished(bool ok);
- void slotWebLoadProgress(int progress);
-
- // Funciones que manejan cada vez que el proceso hace algo
- void slotProcessStarted();
- void slotProcessFinished(int code,QProcess::ExitStatus status);
- void slotProcessError(QProcess::ProcessError error);
- void slotProcessOutput();
- void slotProcessErrorOutput();
-
- //Functions
- protected:
- int readEnvironmentValues();
-
-
- protected:
- QWebView *web;
- QTextEdit *text;
- QDockWidget *dock;
-
- QProcess *process;
- QStringList output;
- QStringList errors;
-
- QMap<QString,QString> env;
- QFile *logfile;
- QTextStream *logstream;
-};
-
-#endif // MAINWINDOW_H