Merge pull request 'Mejoras del OG Browser' (#4) from review-improvements into main

Reviewed-on: #4
main
Vadim vtroshchinskiy 2024-09-26 11:24:41 +02:00
commit 21e8f4c641
8 changed files with 175 additions and 10 deletions

View File

@ -4,6 +4,7 @@ project(Browser)
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD 17)
set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INSTALL_PREFIX "/usr")
add_subdirectory(qtermwidget)
add_subdirectory(digitalclock)

View File

@ -8,6 +8,8 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC 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${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools Network WebEngineWidgets REQUIRED)
@ -19,6 +21,7 @@ set(SOURCES
main.cpp
mainwindow.cpp
ogurlhandler.cpp
desktopparser.cpp
)
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(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)

View File

@ -1,8 +1,13 @@
#include <QApplication>
#include <QTranslator>
#include <QDebug>
#include <QCommandLineParser>
#include "mainwindow.h"
#include "ogcommandlne.h"
#include "desktopparser.h"
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;
}
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;
w.show();
return a.exec();

View File

@ -21,8 +21,12 @@
#include <QString>
#include "qtermwidget.h"
#include "KeyboardTranslator.h"
#include "digitalclock.h"
#include "ogurlhandler.h"
#include "ogwebpage.h"
#include "desktopparser.h"
#define BUFFERSIZE 2048
#define REGEXP_STRING "^\\[(\\d+)\\]"
@ -143,6 +147,29 @@ MainWindow::MainWindow(QWidget *parent)
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+output", false, true);
registerHandler("command+confirm", true, false);
@ -150,14 +177,29 @@ MainWindow::MainWindow(QWidget *parent)
registerHandler("command+output+confirm", true, true);
QStringList arguments=QCoreApplication::arguments();
m_webBar->setText(arguments.at(1));
m_web->load(QUrl(arguments.at(1)));
//QStringList arguments=QCoreApplication::arguments();
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();
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);
connect(handler, &OGBrowserUrlHandlerCommand::command, this, &MainWindow::commandQueued);
handler->setAskConfirmation(confirm);
handler->setReturnOutput(returnOutput);
handler->setBaseCommand(baseCommand);
handler->setScheme(commandName);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(commandName.toLatin1(), handler);
}

View File

@ -80,7 +80,7 @@ class MainWindow : public QMainWindow
bool isAdmin() const { return m_is_admin; }
bool isKioskMode() const { return m_kiosk_mode; }
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_kiosk_mode{false};

View File

@ -11,7 +11,20 @@ void OGBrowserUrlHandlerCommand::requestStarted(QWebEngineUrlRequestJob *job) {
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->fail(QWebEngineUrlRequestJob::NoError);

View File

@ -24,12 +24,19 @@ public:
};
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; }
bool returnOuput() const { return m_return_output; }
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:
void command(const QString &command, bool confirm, bool returnOutput);
@ -38,6 +45,8 @@ private:
bool m_ask_confirmation = false;
bool m_return_output = false;
QString m_scheme = "";
QString m_base_command = "";
};

View File

@ -29,9 +29,19 @@
<tr>
<td>Scheme</td>
<td>Test</td>
<td>Descripcion</td>
<td>Description</td>
</tr>
</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>
<td>command</td>
<td><a href="command:/bin/true">Ejecutar</a></td>
@ -67,7 +77,12 @@
<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>
</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>
</body>
</html>
</html>