summaryrefslogtreecommitdiffstats
path: root/client/browser
diff options
context:
space:
mode:
Diffstat (limited to 'client/browser')
-rw-r--r--client/browser/po/ca.po68
-rw-r--r--client/browser/po/en.po72
-rw-r--r--client/browser/src/mainwindow.cpp258
-rw-r--r--client/browser/src/mainwindow.h13
4 files changed, 257 insertions, 154 deletions
diff --git a/client/browser/po/ca.po b/client/browser/po/ca.po
index 8e5e0b7c..1e76b18b 100644
--- a/client/browser/po/ca.po
+++ b/client/browser/po/ca.po
@@ -7,8 +7,8 @@
msgid ""
msgstr ""
"Project-Id-Version: OpenGnsys Client Browser 1.1.0\n"
-"Report-Msgid-Bugs-To: https://opengnsys.es\n"
-"POT-Creation-Date: 2017-05-11 11:51+0000\n"
+"Report-Msgid-Bugs-To: https://opengnsys.es/\n"
+"POT-Creation-Date: 2019-09-11 15:48+0000\n"
"PO-Revision-Date: 2016-05-03 10:25+0200\n"
"Last-Translator: Ramón M. Gómez <ramongomez@us.es>\n"
"Language-Team: CATALAN <LL@li.org>\n"
@@ -17,94 +17,102 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: ../src/main.cpp:20
+#: src/main.cpp:20
#, c-format
msgid "Uso: %s -qws http://sitioweb.com/\n"
msgstr "Ús: %s -qws http://web.com/\n"
-#: ../src/mainwindow.cpp:55
+#: src/mainwindow.cpp:47
+msgid "El fichero de log no ha podido ser abierto: "
+msgstr "Log file could not be opened: "
+
+#: src/mainwindow.cpp:68
msgid "&Nueva Terminal"
msgstr "&Nova Terminal"
-#: ../src/mainwindow.cpp:60
+#: src/mainwindow.cpp:72
msgid "Salida"
msgstr "Sortida"
-#: ../src/mainwindow.cpp:97
+#: src/mainwindow.cpp:104
msgid "Proyecto OpenGnsys"
msgstr "Projecte OpenGnsys"
-#: ../src/mainwindow.cpp:145
-msgid "El fichero de log no ha podido ser abierto: "
-msgstr ""
-
-#: ../src/mainwindow.cpp:174
+#: src/mainwindow.cpp:167
msgid "Hay otro proceso en ejecución. Por favor espere."
msgstr ""
-#: ../src/mainwindow.cpp:189 ../src/mainwindow.cpp:228
+#: src/mainwindow.cpp:183 src/mainwindow.cpp:250
msgid "AVISO"
msgstr "AVIS"
-#: ../src/mainwindow.cpp:191
+#: src/mainwindow.cpp:186
msgid ""
"La siguiente acci&oacute;n puede modificar datos o tardar varios minutos. El "
"equipo no podr&aacute; ser utilizado durante su ejecuci&oacute;n."
msgstr ""
-#: ../src/mainwindow.cpp:192
+#: src/mainwindow.cpp:187
msgid "Ejecutar"
msgstr "Executar"
-#: ../src/mainwindow.cpp:193
+#: src/mainwindow.cpp:188
msgid "Cancelar"
msgstr "Cancel-lar"
-#: ../src/mainwindow.cpp:211
+#: src/mainwindow.cpp:233
#, c-format
msgid "%p% Cargando"
msgstr "%p% Carregat"
-#: ../src/mainwindow.cpp:230
+#: src/mainwindow.cpp:253
msgid "La p&aacute;gina no se puede cargar."
msgstr ""
-#: ../src/mainwindow.cpp:232
+#: src/mainwindow.cpp:255
msgid "Recargar"
msgstr "Recarregar"
-#: ../src/mainwindow.cpp:233
+#: src/mainwindow.cpp:256
msgid "Abortar"
msgstr "Avortar"
-#: ../src/mainwindow.cpp:264
-msgid "Lanzado satisfactoriamente."
+#: src/mainwindow.cpp:333 src/mainwindow.cpp:345
+msgid "Fin del proceso. Valor de retorno: "
msgstr ""
-#: ../src/mainwindow.cpp:298
-msgid "Proceso acabado correctamente. Valor de retorno: "
+#: src/mainwindow.cpp:338
+msgid "El proceso ha fallado inesperadamente. Salida: "
msgstr ""
-#: ../src/mainwindow.cpp:302
-msgid "El proceso ha fallado inesperadamente. Salida: "
+#: src/mainwindow.cpp:347
+msgid "AVISO: Pulsar el botón superior derecho para cerrar"
msgstr ""
-#: ../src/mainwindow.cpp:313
+#: src/mainwindow.cpp:353
+msgid "Código de salida: "
+msgstr ""
+
+#: src/mainwindow.cpp:364
msgid "Imposible lanzar el proceso."
msgstr ""
-#: ../src/mainwindow.cpp:316
+#: src/mainwindow.cpp:367
msgid "Error de escritura en el proceso."
msgstr ""
-#: ../src/mainwindow.cpp:319
+#: src/mainwindow.cpp:370
msgid "Error de lectura del proceso."
msgstr ""
-#: ../src/mainwindow.cpp:327
+#: src/mainwindow.cpp:378
msgid "Error desconocido."
msgstr ""
-#: ../src/mainwindow.cpp:460
+#: src/mainwindow.cpp:530 src/mainwindow.cpp:535
msgid "Lanzando el comando: "
msgstr ""
+
+#: src/mainwindow.cpp:563
+msgid "ERROR"
+msgstr "ERROR"
diff --git a/client/browser/po/en.po b/client/browser/po/en.po
index 68ab13c5..08c26b96 100644
--- a/client/browser/po/en.po
+++ b/client/browser/po/en.po
@@ -7,8 +7,8 @@
msgid ""
msgstr ""
"Project-Id-Version: OpenGnsys Client Browser 1.1.0\n"
-"Report-Msgid-Bugs-To: https://opengnsys.es\n"
-"POT-Creation-Date: 2017-05-11 11:51+0000\n"
+"Report-Msgid-Bugs-To: https://opengnsys.es/\n"
+"POT-Creation-Date: 2019-09-11 15:48+0000\n"
"PO-Revision-Date: 2016-05-03 10:16+0200\n"
"Last-Translator: Ramón M. Gómez <ramongomez@us.es>\n"
"Language-Team: ENGLISH <LL@li.org>\n"
@@ -17,36 +17,36 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-#: ../src/main.cpp:20
+#: src/main.cpp:20
#, c-format
msgid "Uso: %s -qws http://sitioweb.com/\n"
msgstr "Usage: %s -qws http://website.com/\n"
-#: ../src/mainwindow.cpp:55
+#: src/mainwindow.cpp:47
+msgid "El fichero de log no ha podido ser abierto: "
+msgstr "Log file could not be opened: "
+
+#: src/mainwindow.cpp:68
msgid "&Nueva Terminal"
msgstr "&New Terminal"
-#: ../src/mainwindow.cpp:60
+#: src/mainwindow.cpp:72
msgid "Salida"
msgstr "Output"
-#: ../src/mainwindow.cpp:97
+#: src/mainwindow.cpp:104
msgid "Proyecto OpenGnsys"
msgstr "OpenGnsys Project"
-#: ../src/mainwindow.cpp:145
-msgid "El fichero de log no ha podido ser abierto: "
-msgstr "The log file could not be opened: "
-
-#: ../src/mainwindow.cpp:174
+#: src/mainwindow.cpp:167
msgid "Hay otro proceso en ejecución. Por favor espere."
msgstr "There is another process running. Please wait."
-#: ../src/mainwindow.cpp:189 ../src/mainwindow.cpp:228
+#: src/mainwindow.cpp:183 src/mainwindow.cpp:250
msgid "AVISO"
msgstr "WARNING"
-#: ../src/mainwindow.cpp:191
+#: src/mainwindow.cpp:186
msgid ""
"La siguiente acci&oacute;n puede modificar datos o tardar varios minutos. El "
"equipo no podr&aacute; ser utilizado durante su ejecuci&oacute;n."
@@ -54,59 +54,67 @@ msgstr ""
"Following action can modify some data or take several minutes. This computer "
"may not be used during execution."
-#: ../src/mainwindow.cpp:192
+#: src/mainwindow.cpp:187
msgid "Ejecutar"
msgstr "Run"
-#: ../src/mainwindow.cpp:193
+#: src/mainwindow.cpp:188
msgid "Cancelar"
msgstr "Cancel"
-#: ../src/mainwindow.cpp:211
+#: src/mainwindow.cpp:233
#, c-format
msgid "%p% Cargando"
msgstr "%p% Loaded"
-#: ../src/mainwindow.cpp:230
+#: src/mainwindow.cpp:253
msgid "La p&aacute;gina no se puede cargar."
msgstr "Page can not be loaded."
-#: ../src/mainwindow.cpp:232
+#: src/mainwindow.cpp:255
msgid "Recargar"
msgstr "Reload"
-#: ../src/mainwindow.cpp:233
+#: src/mainwindow.cpp:256
msgid "Abortar"
msgstr "Abort"
-#: ../src/mainwindow.cpp:264
-msgid "Lanzado satisfactoriamente."
-msgstr "Successfully launched."
+#: src/mainwindow.cpp:333 src/mainwindow.cpp:345
+msgid "Fin del proceso. Valor de retorno: "
+msgstr "End of process. Return value: "
-#: ../src/mainwindow.cpp:298
-msgid "Proceso acabado correctamente. Valor de retorno: "
-msgstr "Process completed successfully. Return value: "
-
-#: ../src/mainwindow.cpp:302
+#: src/mainwindow.cpp:338
msgid "El proceso ha fallado inesperadamente. Salida: "
msgstr "The process crashed unexpectedly. Return value: "
-#: ../src/mainwindow.cpp:313
+#: src/mainwindow.cpp:347
+msgid "AVISO: Pulsar el botón superior derecho para cerrar"
+msgstr "WARNING: Press the upper right button to close"
+
+#: src/mainwindow.cpp:353
+msgid "Código de salida: "
+msgstr "Exit code: "
+
+#: src/mainwindow.cpp:364
msgid "Imposible lanzar el proceso."
msgstr "Unable to launch the process."
-#: ../src/mainwindow.cpp:316
+#: src/mainwindow.cpp:367
msgid "Error de escritura en el proceso."
msgstr "Error writing to the process."
-#: ../src/mainwindow.cpp:319
+#: src/mainwindow.cpp:370
msgid "Error de lectura del proceso."
msgstr "Error reading from the process."
-#: ../src/mainwindow.cpp:327
+#: src/mainwindow.cpp:378
msgid "Error desconocido."
msgstr "Unknown error."
-#: ../src/mainwindow.cpp:460
+#: src/mainwindow.cpp:530 src/mainwindow.cpp:535
msgid "Lanzando el comando: "
msgstr "Launching command: "
+
+#: src/mainwindow.cpp:563
+msgid "ERROR"
+msgstr "ERROR"
diff --git a/client/browser/src/mainwindow.cpp b/client/browser/src/mainwindow.cpp
index 2e799c5e..1d89a1a8 100644
--- a/client/browser/src/mainwindow.cpp
+++ b/client/browser/src/mainwindow.cpp
@@ -12,10 +12,10 @@
#include <QDateTime>
#include <QProgressBar>
#include <QTabWidget>
-#include <QWebView>
#include <QLineEdit>
#include <QNetworkReply>
#include <QSslError>
+#include <QTimer>
#include <libintl.h>
#include "qtermwidget.h"
@@ -24,7 +24,7 @@
#define BUFFERSIZE 2048
#define REGEXP_STRING "^\\[(\\d+)\\]"
-#define CURRENT_TIME() QDateTime::currentDateTime().toString("dd/MM/yy hh:mm:ss")
+#define CURRENT_TIME() QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss")
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),m_web(new QWebView()),m_output(new QTextEdit()),
@@ -33,15 +33,28 @@ MainWindow::MainWindow(QWidget *parent)
{
// Graphic
showFullScreen();
-
setWindowTitle(tr("OpenGnsys Browser"));
-
setCentralWidget(m_web);
-
readEnvironmentValues();
+ // Open the log file for append
+ if(m_env.contains("OGLOGFILE") && m_env["OGLOGFILE"]!="")
+ {
+ QFile* m_logfile=new QFile(m_env["OGLOGFILE"]);
+ if(!m_logfile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
+ {
+ delete m_logfile;
+ print(tr(gettext("El fichero de log no ha podido ser abierto: "))+m_env["OGLOGFILE"]+".");
+ }
+ else
+ {
+ m_logstream=new QTextStream(m_logfile);
+ }
+ }
+
// Output
m_output->setReadOnly(true);
+ m_output->setFontPointSize(16);
// Button Dock
QDockWidget* dock=new QDockWidget();
@@ -56,16 +69,13 @@ MainWindow::MainWindow(QWidget *parent)
button->setFocusPolicy(Qt::TabFocus);
m_tabs->setCornerWidget(button);
m_tabs->setFocusPolicy(Qt::NoFocus);
-
m_tabs->addTab(m_output,tr(gettext("Salida")));
slotCreateTerminal();
-
// Assign tabs to dock
dock->setWidget(m_tabs);
-
// Assign tabs dock to the mainwindow if admin mode is active
if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
- addDockWidget(Qt::BottomDockWidgetArea,dock);
+ addDockWidget(Qt::BottomDockWidgetArea,dock);
// Top Dock
dock=new QDockWidget();
@@ -73,16 +83,13 @@ MainWindow::MainWindow(QWidget *parent)
QWidget* dummy2=new QWidget();
dummy2->setMaximumHeight(0);
dock->setTitleBarWidget(dummy2);
-
// WebBar
m_webBar=new QLineEdit(dock);
-
// WebBar to dock
dock->setWidget(m_webBar);
-
// Assign top dock to the mainwindow if admin mode is active
if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
- addDockWidget(Qt::TopDockWidgetArea,dock);
+ addDockWidget(Qt::TopDockWidgetArea,dock);
// Status bar
QStatusBar* st=statusBar();
@@ -91,9 +98,9 @@ MainWindow::MainWindow(QWidget *parent)
m_logo=new QLabel();
QPixmap logo;
if(logo.load("/opt/opengnsys/lib/pictures/oglogo.png"))
- m_logo->setPixmap(logo);
+ m_logo->setPixmap(logo);
else
- m_logo->setText("OG");
+ m_logo->setText("OG");
m_logo->setToolTip(tr(gettext("Proyecto OpenGnsys"))+"\nhttps://opengnsys.es");
// Progress bar
m_progressBar=new QProgressBar(this);
@@ -103,8 +110,8 @@ MainWindow::MainWindow(QWidget *parent)
m_speedInfo=new QLabel(speed);
m_speedInfo->setAlignment(Qt::AlignCenter);
if(m_env.contains("DEFAULTSPEED") && m_env["DEFAULTSPEED"]!="")
- if(speed.compare(m_env["DEFAULTSPEED"])!=0)
- m_speedInfo->setStyleSheet("background-color: darkred; color: white; font-weight: bold;");
+ if(speed.compare(m_env["DEFAULTSPEED"])!=0)
+ m_speedInfo->setStyleSheet("background-color: darkred; color: white; font-weight: bold;");
// Clock
m_clock=new DigitalClock(this);
@@ -126,10 +133,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(m_process,SIGNAL(started()),this,SLOT(slotProcessStarted()));
connect(m_process,SIGNAL(finished(int,QProcess::ExitStatus)),
this,SLOT(slotProcessFinished(int,QProcess::ExitStatus)));
-
connect(m_process,SIGNAL(error(QProcess::ProcessError)),
this,SLOT(slotProcessError(QProcess::ProcessError)));
-
connect(m_process,SIGNAL(readyReadStandardOutput()),this,SLOT(slotProcessOutput()));
connect(m_process,SIGNAL(readyReadStandardError()),
this,SLOT(slotProcessErrorOutput()));
@@ -138,21 +143,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(button,SIGNAL(clicked()),this,SLOT(slotCreateTerminal()));
connect(m_webBar,SIGNAL(returnPressed()),this,SLOT(slotWebBarReturnPressed()));
- // Open the log file for append
- if(m_env.contains("OGLOGFILE") && m_env["OGLOGFILE"]!="")
- {
- QFile* m_logfile=new QFile(m_env["OGLOGFILE"]);
- if(!m_logfile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))
- {
- delete m_logfile;
- print(tr(gettext("El fichero de log no ha podido ser abierto: "))+m_env["OGLOGFILE"]+".");
- }
- else
- {
- m_logstream=new QTextStream(m_logfile);
- }
- }
-
QStringList arguments=QCoreApplication::arguments();
m_webBar->setText(arguments[1]);
m_web->load(QUrl(arguments[1]));
@@ -172,35 +162,64 @@ MainWindow::~MainWindow()
void MainWindow::slotLinkHandle(const QUrl &url)
{
// Check if it's executing another process
- if(m_process->state()!=QProcess::NotRunning)
+ if(m_process->state() != QProcess::NotRunning)
{
- print(tr(gettext("Hay otro proceso en ejecución. Por favor espere.")));
- return;
+ print(tr(gettext("Hay otro proceso en ejecución. Por favor espere.")));
+ return;
}
-
QString urlString = url.toString();
- if(urlString.startsWith(COMMAND))
+ QString urlScheme = url.scheme();
+ // Clear the output widget for a normal user
+ if(! m_env.contains("ogactiveadmin") || m_env["ogactiveadmin"] != "true")
{
- // For COMMAND link, execute
- executeCommand(urlString.remove(0,QString(COMMAND).length()));
+ m_output->clear();
}
- else if(urlString.startsWith(COMMAND_WITH_CONFIRMATION))
+ if(urlScheme == COMMAND_CONFIRM || urlScheme == COMMAND_CONFIRM_OUTPUT ||
+ urlScheme == COMMAND_OUTPUT_CONFIRM || urlScheme == COMMAND_WITH_CONFIRMATION)
{
- // For COMMAND_WITH_CONFIRMATION link, show confirmation box and execute, if accepted
+ // For all command with confirmation links, show a popup box
QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Question);
+ msgBox.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
msgBox.setWindowTitle(tr(gettext("AVISO")));
+ msgBox.setIcon(QMessageBox::Question);
msgBox.setTextFormat(Qt::RichText);
msgBox.setText(tr(gettext("La siguiente acci&oacute;n puede modificar datos o tardar varios minutos. El equipo no podr&aacute; ser utilizado durante su ejecuci&oacute;n.")));
QPushButton *execButton = msgBox.addButton(tr(gettext("Ejecutar")), QMessageBox::ActionRole);
msgBox.addButton(tr(gettext("Cancelar")), QMessageBox::RejectRole);
msgBox.setDefaultButton(execButton);
msgBox.exec();
+ // Continue if user press the execution button
if (msgBox.clickedButton() == execButton)
{
- executeCommand(urlString.remove(0,QString(COMMAND_WITH_CONFIRMATION).length()));
+ // For command with confirmation and output link, show an output window to non-admin user
+ if((urlScheme == COMMAND_CONFIRM_OUTPUT || urlScheme == COMMAND_OUTPUT_CONFIRM) &&
+ (! m_env.contains("ogactiveadmin") || m_env["ogactiveadmin"] != "true"))
+ {
+ int w=MainWindow::width(), h=MainWindow::height();
+ m_output->setWindowFlags(Qt::Window);
+ m_output->move(100, 100);
+ m_output->setFixedSize(w*0.8-100, h*0.8-100);
+ m_output->show();
+ }
+ // Execute the command
+ executeCommand(urlString.remove(0, urlScheme.length()+1));
}
}
+ else if(urlScheme == COMMAND || urlScheme == COMMAND_OUTPUT)
+ {
+ // For command with output link, show an output window to non-admin user
+ if(urlScheme == COMMAND_OUTPUT &&
+ (! m_env.contains("ogactiveadmin") || m_env["ogactiveadmin"] != "true"))
+ {
+ int w=MainWindow::width(), h=MainWindow::height();
+ m_output->setWindowFlags(Qt::Window);
+ m_output->move(100, 100);
+ m_output->setFixedSize(w*0.8-100, h*0.8-100);
+ m_output->show();
+ }
+ // Execute the command
+ executeCommand(urlString.remove(0, urlScheme.length()+1));
+ }
else
{
// For other link, load webpage
@@ -227,14 +246,14 @@ void MainWindow::slotWebLoadFinished(bool ok)
if(ok == false)
{
QMessageBox msgBox;
- msgBox.setIcon(QMessageBox::Question);
+ msgBox.setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
msgBox.setWindowTitle(tr(gettext("AVISO")));
+ msgBox.setIcon(QMessageBox::Question);
msgBox.setTextFormat(Qt::RichText);
msgBox.setText(tr(gettext("La p&aacute;gina no se puede cargar.")));
QPushButton *reloadButton = msgBox.addButton(tr(gettext("Recargar")), QMessageBox::ActionRole);
msgBox.addButton(tr(gettext("Abortar")), QMessageBox::RejectRole);
-
msgBox.exec();
if (msgBox.clickedButton() == reloadButton)
@@ -264,7 +283,6 @@ void MainWindow::slotSslErrors(QNetworkReply* reply)
void MainWindow::slotProcessStarted()
{
- m_output->insertPlainText(tr(gettext("Lanzado satisfactoriamente.")));
startProgressBar();
}
@@ -275,7 +293,11 @@ void MainWindow::slotProcessOutput()
while((m_process->readLine(buf,BUFFERSIZE) > 0))
{
QString s(buf);
- print(tr("Proc. stdout: ")+s);
+ if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
+ {
+ m_output->insertPlainText(tr("Proc. stdout: "));
+ }
+ print(s);
captureOutputForStatusBar(s);
}
}
@@ -287,39 +309,65 @@ void MainWindow::slotProcessErrorOutput()
while((m_process->readLine(buf,BUFFERSIZE) > 0))
{
QString s(buf);
- m_output->insertPlainText(tr("Proc. stderr: "));
+ if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
+ {
+ m_output->insertPlainText(tr("Proc. stderr: "));
+ }
m_output->setTextColor(QColor(Qt::darkBlue));
print(s);
m_output->setTextColor(QColor(Qt::black));
}
}
-void MainWindow::slotProcessFinished(int code,QProcess::ExitStatus status)
+void MainWindow::slotProcessFinished(int code, QProcess::ExitStatus status)
{
- if(status==QProcess::NormalExit)
+ if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
{
- print(tr(gettext("Proceso acabado correctamente. Valor de retorno: "))+QString::number(code));
+ // Admin user: show process status
+ if(status==QProcess::NormalExit)
+ {
+ if(code > 0)
+ {
+ m_output->setTextColor(QColor(Qt::darkRed));
+ }
+ print("\n"+tr(gettext("Fin del proceso. Valor de retorno: "))+QString::number(code));
+ }
+ else
+ {
+ m_output->setTextColor(QColor(Qt::darkRed));
+ print("\n"+tr(gettext("El proceso ha fallado inesperadamente. Salida: ")+code));
+ }
+ m_output->setTextColor(QColor(Qt::black));
}
else
{
- print(tr(gettext("El proceso ha fallado inesperadamente. Salida: ")+code));
+ // Non-admin user: show instruction to close the popup window
+ write(tr(gettext("Fin del proceso. Valor de retorno: "))+QString::number(code));
+ m_output->setFontUnderline(true);
+ print("\n\n"+tr(gettext("AVISO: Pulsar el botón superior derecho para cerrar"))+" [X]");
+ m_output->setFontUnderline(false);
+ }
+ // On error, show a message box
+ if(code > 0 && ! m_output->isActiveWindow())
+ {
+ showErrorMessage(gettext("Código de salida: ")+QString::number(code));
}
finishProgressBar();
}
void MainWindow::slotProcessError(QProcess::ProcessError error)
{
- m_output->setTextColor(QColor(Qt::darkRed));
+ QString errorMsg;
switch(error)
{
case QProcess::FailedToStart:
- print(tr(gettext("Imposible lanzar el proceso.")));
+ errorMsg=tr(gettext("Imposible lanzar el proceso."));
break;
case QProcess::WriteError:
- print(tr(gettext("Error de escritura en el proceso.")));
+ errorMsg=tr(gettext("Error de escritura en el proceso."));
break;
case QProcess::ReadError:
- print(tr(gettext("Error de lectura del proceso.")));
+ errorMsg=tr(gettext("Error de lectura del proceso."));
break;
// No capturo crashed porque la pillo por finished
case QProcess::Crashed:
@@ -327,11 +375,17 @@ void MainWindow::slotProcessError(QProcess::ProcessError error)
break;
case QProcess::UnknownError:
default:
- print(tr(gettext("Error desconocido.")));
+ errorMsg=tr(gettext("Error desconocido."));
break;
}
+ // Print error and show message box with timeout.
+ if(!errorMsg.isNull()) {
+ m_output->setTextColor(QColor(Qt::darkRed));
+ print(errorMsg);
+ m_output->setTextColor(QColor(Qt::black));
+ showErrorMessage(errorMsg);
+ }
finishProgressBar();
- m_output->setTextColor(QColor(Qt::black));
}
void MainWindow::slotCreateTerminal()
@@ -343,8 +397,6 @@ void MainWindow::slotCreateTerminal()
console->setTerminalFont(font);
console->setFocusPolicy(Qt::StrongFocus);
-
- //console->setColorScheme(COLOR_SCHEME_BLACK_ON_LIGHT_YELLOW);
console->setScrollBarPosition(QTermWidget::ScrollBarRight);
++m_numberTerminal;
@@ -367,7 +419,7 @@ void MainWindow::slotWebBarReturnPressed()
{
QUrl url(m_webBar->text());
if(url.isValid())
- slotLinkHandle(url);
+ slotLinkHandle(url);
}
int MainWindow::readEnvironmentValues()
@@ -403,32 +455,42 @@ int MainWindow::readEnvironmentValues()
return ret;
}
+// Write a string to the log file
+void MainWindow::write(QString s)
+{
+ if(! s.endsWith("\n"))
+ s+="\n";
+ if(m_logstream)
+ {
+ *m_logstream<<CURRENT_TIME()<<": browser: "<<s;
+ m_logstream->flush();
+ }
+}
+
+// Print and log a string
void MainWindow::print(QString s)
{
- if(!s.endsWith("\n"))
- s+="\n";
- if(m_logstream)
- {
- *m_logstream<<CURRENT_TIME()<<": "<<s;
- m_logstream->flush();
- }
- if(m_output)
- m_output->insertPlainText(s);
+ if(! s.endsWith("\n"))
+ s+="\n";
+ write(s);
+ if(m_output)
+ m_output->insertPlainText(s);
}
+// Show message in status bar
void MainWindow::captureOutputForStatusBar(QString output)
{
- // Capturar para modificar status bar
- output=output.trimmed();
-
- QRegExp regexp(REGEXP_STRING);
- if(regexp.indexIn(output) != -1)
- {
- int pass=regexp.cap(1).toInt();
- output.replace(regexp,"");
- m_progressBar->setValue(pass);
- m_progressBar->setFormat("%p%"+output);
- }
+ // Modify the status bar
+ output=output.trimmed();
+ // Get percentage (string starts with "[Number]")
+ QRegExp regexp(REGEXP_STRING);
+ if(regexp.indexIn(output) != -1)
+ {
+ int pass=regexp.cap(1).toInt();
+ output.replace(regexp,"");
+ m_progressBar->setValue(pass);
+ m_progressBar->setFormat("%p%"+output);
+ }
}
// Init status bar
@@ -445,13 +507,14 @@ void MainWindow::startProgressBar()
m_web->setEnabled(false);
}
+// Reset status bar
void MainWindow::finishProgressBar()
{
m_progressBar->reset();
m_web->setEnabled(true);
}
-
+// Execute a command
void MainWindow::executeCommand(QString &string)
{
QStringList list=string.split(" ",QString::SkipEmptyParts);
@@ -460,10 +523,17 @@ void MainWindow::executeCommand(QString &string)
// Assign the same Browser's environment to the process
m_process->setEnvironment(QProcess::systemEnvironment());
m_process->start(program,list);
- print(tr(gettext("Lanzando el comando: ")));
- m_output->setTextColor(QColor(Qt::darkGreen));
- print(program+" "+list.join(" "));
- m_output->setTextColor(QColor(Qt::black));
+ // Only show the command line to admin user
+ if(m_env.contains("ogactiveadmin") && m_env["ogactiveadmin"] == "true")
+ {
+ m_output->setTextColor(QColor(Qt::darkGreen));
+ print(tr(gettext("Lanzando el comando: "))+string);
+ m_output->setTextColor(QColor(Qt::black));
+ }
+ else
+ {
+ write(tr(gettext("Lanzando el comando: "))+string);
+ }
startProgressBar();
}
@@ -484,3 +554,15 @@ QString MainWindow::readSpeed() {
return QString("");
}
}
+
+// Show an error box with timeout
+void MainWindow::showErrorMessage(QString text)
+{
+ QMessageBox* msgBox=new QMessageBox();
+ msgBox->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);
+ msgBox->setWindowTitle(gettext("ERROR"));
+ msgBox->setIcon(QMessageBox::Warning);
+ msgBox->setText(text);
+ msgBox->show();
+ QTimer::singleShot(5000, msgBox, SLOT(close()));
+}
diff --git a/client/browser/src/mainwindow.h b/client/browser/src/mainwindow.h
index e4e02fa3..664d2f00 100644
--- a/client/browser/src/mainwindow.h
+++ b/client/browser/src/mainwindow.h
@@ -1,8 +1,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#define COMMAND "command:"
-#define COMMAND_WITH_CONFIRMATION "commandwithconfirmation:"
+#define COMMAND "command"
+#define COMMAND_CONFIRM "command+confirm"
+#define COMMAND_WITH_CONFIRMATION "commandwithconfirmation" // Backwards compatibility
+#define COMMAND_OUTPUT "command+output"
+#define COMMAND_CONFIRM_OUTPUT "command+confirm+output"
+#define COMMAND_OUTPUT_CONFIRM "command+output+confirm"
#define ENVIRONMENT "OGLOGFILE,ogactiveadmin,DEFAULTSPEED"
#include <QWidget>
@@ -41,7 +45,7 @@ class MainWindow : public QMainWindow
void slotWebLoadStarted();
void slotWebLoadFinished(bool ok);
void slotWebLoadProgress(int progress);
- void slotSslErrors(QNetworkReply* reply);
+ void slotSslErrors(QNetworkReply* reply);
// Funciones que manejan cada vez que el proceso hace algo
void slotProcessStarted();
@@ -62,12 +66,13 @@ class MainWindow : public QMainWindow
protected:
int readEnvironmentValues();
void print(QString s);
+ void write(QString s);
void captureOutputForStatusBar(QString output);
void startProgressBar();
void finishProgressBar();
void executeCommand(QString &string);
QString readSpeed();
-
+ void showErrorMessage(QString string);
protected:
QWebView *m_web;