Fix build, missing file in cmake
parent
476581b218
commit
6b6f1ba861
|
@ -22,6 +22,7 @@ set(SOURCES
|
|||
mainwindow.cpp
|
||||
ogurlhandler.cpp
|
||||
desktopparser.cpp
|
||||
ogwebpage.cpp
|
||||
)
|
||||
|
||||
file(GLOB TRANSLATIONS "${PROJECT_SOURCE_DIR}/i18n/*.ts")
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#include "desktopparser.h"
|
||||
#include <QDebug>
|
||||
#include <QtGlobal>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
|
||||
DesktopParser::DesktopParser() {
|
||||
_applicationPaths += qgetenv("HOME") + "./local/share/applications";
|
||||
|
||||
}
|
||||
|
||||
void DesktopParser::loadSchemes() {
|
||||
|
||||
qDebug() << "Loading URL schemes";
|
||||
_schemes.clear();
|
||||
|
||||
for(const auto& appdir : _applicationPaths) {
|
||||
qDebug() << "Looking in" << appdir;
|
||||
|
||||
QDir dir(appdir);
|
||||
for(const QFileInfo &fi : dir.entryInfoList(QDir::Files)) {
|
||||
//qDebug() << "File: " << fi;
|
||||
|
||||
QFile file(fi.absoluteFilePath());
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QTextStream fs(&file);
|
||||
|
||||
QString commandString;
|
||||
QString mimeTypesString;
|
||||
|
||||
while(!fs.atEnd()) {
|
||||
QString line = fs.readLine();
|
||||
QStringList parts = line.split("=");
|
||||
|
||||
if (!parts.length() > 1) continue;
|
||||
|
||||
if ( parts[0] == "Exec") {
|
||||
commandString=parts[1];
|
||||
}
|
||||
|
||||
if (parts[0] == "MimeType" ) {
|
||||
mimeTypesString=parts[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!commandString.isEmpty() && !mimeTypesString.isEmpty()) {
|
||||
//qDebug() << "Found MIME handler: " << mimeTypesString << "; " << commandString;
|
||||
|
||||
QStringList handlers = mimeTypesString.split(";");
|
||||
|
||||
for(const QString &handler : handlers) {
|
||||
QStringList parts = handler.split("/");
|
||||
if (parts.length() > 1 && parts[0] == "x-scheme-handler") {
|
||||
qInfo() << "Found URL scheme handler: " << parts[1] << " => " << commandString;
|
||||
_schemes[parts[1]] = commandString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Failed to open" << fi.absoluteFilePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
class DesktopParser {
|
||||
public:
|
||||
|
||||
static DesktopParser &getInstance() {
|
||||
static DesktopParser instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void loadSchemes();
|
||||
|
||||
QString getScheme(const QString &scheme) {
|
||||
QString s = scheme.toLower().trimmed();
|
||||
|
||||
if (_schemes.contains(s)) {
|
||||
return _schemes[s];
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString>& getSchemes() { return _schemes; }
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
DesktopParser();
|
||||
|
||||
QStringList _applicationPaths{"/usr/share/applications"};
|
||||
QMap<QString, QString> _schemes{};
|
||||
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QCommandLineParser>
|
||||
|
||||
class OGCommandLineOptions {
|
||||
public:
|
||||
|
||||
enum NewTabBehavior {
|
||||
/**
|
||||
* Ignore attempt to open new tab
|
||||
*/
|
||||
Ignore,
|
||||
|
||||
/**
|
||||
* Replace current page, ignore "new tab" directive.
|
||||
*/
|
||||
ReplacePage,
|
||||
|
||||
/**
|
||||
* Open a new tab.
|
||||
*/
|
||||
NewTab
|
||||
};
|
||||
|
||||
static OGCommandLineOptions &getInstance() {
|
||||
static OGCommandLineOptions instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
QString getUrl() const { return _url; }
|
||||
void setUrl(const QString& url) { _url = url; }
|
||||
|
||||
NewTabBehavior getNewTabBehavior() const { return _newTabBehavior; }
|
||||
void setNewTabBehavior(NewTabBehavior nt) { _newTabBehavior = nt; }
|
||||
|
||||
private:
|
||||
OGCommandLineOptions() {
|
||||
|
||||
}
|
||||
|
||||
QString _url;
|
||||
NewTabBehavior _newTabBehavior{ReplacePage};
|
||||
};
|
|
@ -0,0 +1,42 @@
|
|||
#include "ogwebpage.h"
|
||||
|
||||
|
||||
#include <QWebEnginePage>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ogcommandlne.h"
|
||||
#include "mainwindow.h"
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
bool OGWebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) {
|
||||
|
||||
qInfo() << "Link clicked: URL = " << url << "; type = " << type << "; isMainFrame = " << isMainFrame;
|
||||
|
||||
if ( type == QWebEnginePage::NavigationType::NavigationTypeLinkClicked) {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QWebEnginePage *OGWebPage::createWindow(QWebEnginePage::WebWindowType type) {
|
||||
qInfo() << "Create new window: " << type;
|
||||
|
||||
OGCommandLineOptions &options = OGCommandLineOptions::getInstance();
|
||||
|
||||
switch(options.getNewTabBehavior()) {
|
||||
case OGCommandLineOptions::NewTabBehavior::NewTab:
|
||||
qWarning() << "Unimplemented";
|
||||
return this;
|
||||
case OGCommandLineOptions::NewTabBehavior::ReplacePage:
|
||||
qInfo() << "Replacing page";
|
||||
return this;
|
||||
case OGCommandLineOptions::NewTabBehavior::Ignore:
|
||||
qInfo() << "Ignoring attempt to open new tab";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
qCritical() << "Unknown new tab behavior, this should be unreachable";
|
||||
return this;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
#include <QWebEnginePage>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ogcommandlne.h"
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class OGWebPage : public QWebEnginePage {
|
||||
public:
|
||||
|
||||
OGWebPage(QObject *parent) : QWebEnginePage(parent) {
|
||||
qDebug() << "OGWebPage constructed!";
|
||||
}
|
||||
|
||||
virtual bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame);
|
||||
virtual QWebEnginePage *createWindow(QWebEnginePage::WebWindowType type);
|
||||
|
||||
void setMainWindow(MainWindow *mw) { m_mainWindow = mw; }
|
||||
|
||||
private:
|
||||
MainWindow *m_mainWindow;
|
||||
};
|
Loading…
Reference in New Issue