Add desktop file parser
parent
816ccacb12
commit
476581b218
|
@ -21,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")
|
||||||
|
|
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 = "";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue