Merge pull request 'Mejoras del OG Browser' (#4) from review-improvements into main
Reviewed-on: #4main
commit
21e8f4c641
|
@ -4,6 +4,7 @@ project(Browser)
|
||||||
|
|
||||||
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD 17)
|
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD 17)
|
||||||
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD_REQUIRED ON)
|
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_INSTALL_PREFIX "/usr")
|
||||||
|
|
||||||
add_subdirectory(qtermwidget)
|
add_subdirectory(qtermwidget)
|
||||||
add_subdirectory(digitalclock)
|
add_subdirectory(digitalclock)
|
||||||
|
|
|
@ -8,6 +8,8 @@ set(CMAKE_AUTOUIC ON)
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
set(KB_LAYOUT_DIR "/usr/lib/qtermwidget/kb" CACHE INTERNAL "")
|
||||||
|
|
||||||
|
|
||||||
find_package(QT NAMES Qt6 COMPONENTS Widgets LinguistTools Network WebEngineWidgets REQUIRED)
|
find_package(QT NAMES Qt6 COMPONENTS Widgets LinguistTools Network WebEngineWidgets REQUIRED)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools Network WebEngineWidgets REQUIRED)
|
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools Network WebEngineWidgets REQUIRED)
|
||||||
|
@ -19,6 +21,7 @@ set(SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
ogurlhandler.cpp
|
ogurlhandler.cpp
|
||||||
|
desktopparser.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB TRANSLATIONS "${PROJECT_SOURCE_DIR}/i18n/*.ts")
|
file(GLOB TRANSLATIONS "${PROJECT_SOURCE_DIR}/i18n/*.ts")
|
||||||
|
@ -45,3 +48,32 @@ target_link_directories(OGBrowser PRIVATE ${qtermwidget_LIB_DIRS} ${DigitalClock
|
||||||
install(TARGETS OGBrowser DESTINATION bin )
|
install(TARGETS OGBrowser DESTINATION bin )
|
||||||
install(FILES ${qm_files} DESTINATION "translations")
|
install(FILES ${qm_files} DESTINATION "translations")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# CPack settings must be set before including CPack
|
||||||
|
set(CPACK_PACKAGE_NAME "OGBrowser")
|
||||||
|
set(CPACK_PACKAGE_VENDOR "OpenGnsys")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenGnsys Browser")
|
||||||
|
set(CMAKE_PROJECT_HOMEPAGE_URL "https://opengnsys.es/web/")
|
||||||
|
set(CPACK_PACKAGE_VERSION "2.0")
|
||||||
|
|
||||||
|
set(CPACK_SET_DESTDIR true)
|
||||||
|
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")
|
||||||
|
|
||||||
|
# Debian package support
|
||||||
|
set(CPACK_PACKAGE_CONTACT "Vadim Troshchinskiy <vadim@qindel.com>")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Vadim Troshchinskiy <vadim@qindel.com>")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "ON")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY ">=")
|
||||||
|
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_SECTION "web")
|
||||||
|
|
||||||
|
# RedHat package support. Dependencies are automatically detected
|
||||||
|
set(CPACK_RPM_PACKAGE_GROUP "Applications/Internet")
|
||||||
|
set(CPACK_RPM_PACKAGE_RELEASE "1")
|
||||||
|
set(CPACK_RPM_PACKAGE_LICENSE "GPL-3.0")
|
||||||
|
|
||||||
|
# This goes last
|
||||||
|
include(CPack)
|
||||||
|
|
||||||
|
|
||||||
|
|
51
src/main.cpp
51
src/main.cpp
|
@ -1,8 +1,13 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "ogcommandlne.h"
|
||||||
|
#include "desktopparser.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -30,6 +35,52 @@ int main(int argc, char *argv[])
|
||||||
qWarning() << "Failed to load translations. Tried looking in:" << translationDirs;
|
qWarning() << "Failed to load translations. Tried looking in:" << translationDirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto &desktopParser = DesktopParser::getInstance();
|
||||||
|
desktopParser.loadSchemes();
|
||||||
|
|
||||||
|
|
||||||
|
QCommandLineParser parser;
|
||||||
|
QCommandLineOption openInNewTabOption("openInNewTab", "Create a new tab when opening a new page");
|
||||||
|
parser.addOption(openInNewTabOption);
|
||||||
|
|
||||||
|
QCommandLineOption replacePageOption("replacePage", "When trying to open a new page/tab, replace the current page instead");
|
||||||
|
parser.addOption(replacePageOption);
|
||||||
|
|
||||||
|
QCommandLineOption ignoreNewPageOption("ignoreNewPage", "Ignore attempts to open documents in a new page/tab");
|
||||||
|
parser.addOption(ignoreNewPageOption);
|
||||||
|
|
||||||
|
QCommandLineOption disableWebSecurityOption("disable-web-security", "Disable web security and allow custom URL schemes");
|
||||||
|
parser.addOption(disableWebSecurityOption);
|
||||||
|
|
||||||
|
QCommandLineOption helpOption = parser.addHelpOption();
|
||||||
|
|
||||||
|
OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
parser.process(a);
|
||||||
|
|
||||||
|
if (parser.isSet(helpOption)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(openInNewTabOption)) {
|
||||||
|
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::NewTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(replacePageOption)) {
|
||||||
|
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::ReplacePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parser.isSet(ignoreNewPageOption)) {
|
||||||
|
options.setNewTabBehavior(OGCommandLineOptions::NewTabBehavior::Ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList positional = parser.positionalArguments();
|
||||||
|
if ( positional.length() > 0) {
|
||||||
|
options.setUrl( positional[0 ] );
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
|
@ -21,8 +21,12 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "qtermwidget.h"
|
#include "qtermwidget.h"
|
||||||
|
#include "KeyboardTranslator.h"
|
||||||
|
|
||||||
#include "digitalclock.h"
|
#include "digitalclock.h"
|
||||||
#include "ogurlhandler.h"
|
#include "ogurlhandler.h"
|
||||||
|
#include "ogwebpage.h"
|
||||||
|
#include "desktopparser.h"
|
||||||
|
|
||||||
#define BUFFERSIZE 2048
|
#define BUFFERSIZE 2048
|
||||||
#define REGEXP_STRING "^\\[(\\d+)\\]"
|
#define REGEXP_STRING "^\\[(\\d+)\\]"
|
||||||
|
@ -143,6 +147,29 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
registerScheme("command+output+confirm");
|
registerScheme("command+output+confirm");
|
||||||
|
|
||||||
|
|
||||||
|
auto &desktopParser = DesktopParser::getInstance();
|
||||||
|
QMap<QString, QString> schemes = desktopParser.getSchemes();
|
||||||
|
|
||||||
|
for(const QString scheme : schemes.keys()) {
|
||||||
|
if ( scheme == "http" || scheme == "https")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
registerScheme(scheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// Register all handlers after the schemes
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
for(const QString scheme : schemes.keys()) {
|
||||||
|
if ( scheme == "http" || scheme == "https")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
registerHandler(scheme, false, false, schemes[scheme]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerHandler("command", false, false);
|
registerHandler("command", false, false);
|
||||||
registerHandler("command+output", false, true);
|
registerHandler("command+output", false, true);
|
||||||
registerHandler("command+confirm", true, false);
|
registerHandler("command+confirm", true, false);
|
||||||
|
@ -150,14 +177,29 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
registerHandler("command+output+confirm", true, true);
|
registerHandler("command+output+confirm", true, true);
|
||||||
|
|
||||||
|
|
||||||
QStringList arguments=QCoreApplication::arguments();
|
//QStringList arguments=QCoreApplication::arguments();
|
||||||
m_webBar->setText(arguments.at(1));
|
|
||||||
m_web->load(QUrl(arguments.at(1)));
|
m_web->setPage( new OGWebPage(this));
|
||||||
|
|
||||||
|
OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
|
||||||
|
QUrl url = QUrl(options.getUrl());
|
||||||
|
|
||||||
|
m_webBar->setText(url.toString());
|
||||||
|
|
||||||
|
qInfo() << "Page set to" << url;
|
||||||
|
m_web->load(url);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// auto ktm = Konsole::KeyboardTranslatorManager::instance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
showMaximized();
|
showMaximized();
|
||||||
showFullScreen();
|
showFullScreen();
|
||||||
}
|
}
|
||||||
|
@ -190,11 +232,13 @@ void MainWindow::registerScheme(const QString &name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::registerHandler(const QString &commandName, bool confirm, bool returnOutput) {
|
void MainWindow::registerHandler(const QString &commandName, bool confirm, bool returnOutput, const QString baseCommand) {
|
||||||
OGBrowserUrlHandlerCommand *handler = new OGBrowserUrlHandlerCommand(this);
|
OGBrowserUrlHandlerCommand *handler = new OGBrowserUrlHandlerCommand(this);
|
||||||
connect(handler, &OGBrowserUrlHandlerCommand::command, this, &MainWindow::commandQueued);
|
connect(handler, &OGBrowserUrlHandlerCommand::command, this, &MainWindow::commandQueued);
|
||||||
handler->setAskConfirmation(confirm);
|
handler->setAskConfirmation(confirm);
|
||||||
handler->setReturnOutput(returnOutput);
|
handler->setReturnOutput(returnOutput);
|
||||||
|
handler->setBaseCommand(baseCommand);
|
||||||
|
handler->setScheme(commandName);
|
||||||
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(commandName.toLatin1(), handler);
|
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(commandName.toLatin1(), handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class MainWindow : public QMainWindow
|
||||||
bool isAdmin() const { return m_is_admin; }
|
bool isAdmin() const { return m_is_admin; }
|
||||||
bool isKioskMode() const { return m_kiosk_mode; }
|
bool isKioskMode() const { return m_kiosk_mode; }
|
||||||
void registerScheme(const QString &name);
|
void registerScheme(const QString &name);
|
||||||
void registerHandler(const QString &name, bool confirm, bool output);
|
void registerHandler(const QString &name, bool confirm, bool output, const QString baseCommand = "");
|
||||||
|
|
||||||
bool m_is_admin{false};
|
bool m_is_admin{false};
|
||||||
bool m_kiosk_mode{false};
|
bool m_kiosk_mode{false};
|
||||||
|
|
|
@ -11,7 +11,20 @@ void OGBrowserUrlHandlerCommand::requestStarted(QWebEngineUrlRequestJob *job) {
|
||||||
qInfo() << "Command request: " << job->requestUrl();
|
qInfo() << "Command request: " << job->requestUrl();
|
||||||
|
|
||||||
|
|
||||||
emit command(job->requestUrl().path(), askConfirmation(), returnOuput());
|
QString cmd;
|
||||||
|
if ( !baseCommand().isEmpty() ) {
|
||||||
|
cmd = baseCommand();
|
||||||
|
|
||||||
|
//QString url = getScheme() + ":/" +
|
||||||
|
cmd = cmd.replace("%u", job->requestUrl().toString()); // single URL
|
||||||
|
cmd = cmd.replace("%U", job->requestUrl().toString()); // URL list
|
||||||
|
} else {
|
||||||
|
cmd = job->requestUrl().path();
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Resulting command: " << cmd;
|
||||||
|
emit command(cmd, askConfirmation(), returnOuput());
|
||||||
|
|
||||||
//job->redirect(QUrl());
|
//job->redirect(QUrl());
|
||||||
job->fail(QWebEngineUrlRequestJob::NoError);
|
job->fail(QWebEngineUrlRequestJob::NoError);
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,19 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void requestStarted(QWebEngineUrlRequestJob *job);
|
virtual void requestStarted(QWebEngineUrlRequestJob *job);
|
||||||
bool askConfirmation() const { return m_ask_confirmation; }
|
|
||||||
bool returnOuput() const { return m_return_output; }
|
|
||||||
|
|
||||||
|
bool askConfirmation() const { return m_ask_confirmation; }
|
||||||
void setAskConfirmation(const bool ask) { m_ask_confirmation = ask; }
|
void setAskConfirmation(const bool ask) { m_ask_confirmation = ask; }
|
||||||
|
|
||||||
|
bool returnOuput() const { return m_return_output; }
|
||||||
void setReturnOutput(const bool retOutput) { m_return_output = retOutput; }
|
void setReturnOutput(const bool retOutput) { m_return_output = retOutput; }
|
||||||
|
|
||||||
|
QString baseCommand() const { return m_base_command; }
|
||||||
|
void setBaseCommand(const QString &cmd) { m_base_command = cmd; }
|
||||||
|
|
||||||
|
void setScheme(const QString &scheme) { m_scheme = scheme; }
|
||||||
|
const QString getScheme() const { return m_scheme; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void command(const QString &command, bool confirm, bool returnOutput);
|
void command(const QString &command, bool confirm, bool returnOutput);
|
||||||
|
|
||||||
|
@ -38,6 +45,8 @@ private:
|
||||||
|
|
||||||
bool m_ask_confirmation = false;
|
bool m_ask_confirmation = false;
|
||||||
bool m_return_output = false;
|
bool m_return_output = false;
|
||||||
|
QString m_scheme = "";
|
||||||
|
QString m_base_command = "";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,19 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>Scheme</td>
|
<td>Scheme</td>
|
||||||
<td>Test</td>
|
<td>Test</td>
|
||||||
<td>Descripcion</td>
|
<td>Description</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td>HTTP</td>
|
||||||
|
<td><a href="https://google.com">Google en ventana actual</a></td>
|
||||||
|
<td>Abrir en pestaña nueva</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>HTTP</td>
|
||||||
|
<td><a href="https://google.com" target="_blank">Google en ventana nueva</a></td>
|
||||||
|
<td>Abrir en pestaña nueva</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>command</td>
|
<td>command</td>
|
||||||
<td><a href="command:/bin/true">Ejecutar</a></td>
|
<td><a href="command:/bin/true">Ejecutar</a></td>
|
||||||
|
@ -67,6 +77,11 @@
|
||||||
<td><a href="command+confirm+output:/bin/ping -c 5 127.0.0.1">Ejecutar</a></td>
|
<td><a href="command+confirm+output:/bin/ping -c 5 127.0.0.1">Ejecutar</a></td>
|
||||||
<td>Ejecutar comando con confirmacion, salida y largo tiempo (5s)</td>
|
<td>Ejecutar comando con confirmacion, salida y largo tiempo (5s)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>UDSS</td>
|
||||||
|
<td><a href="udss://pcvirtual.cv.uma.es/ylo9l0zv7odzl4ww4nazrisz65vvebipfdlrou14/e99zib94jxrd1ybmj6xaj1cg6pnp9iqm">UDS</a></td>
|
||||||
|
<td>Abrir URL udss://</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue