mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Restricted icons to plugin directory
The icons will be searched in the following order: - Theme icons - Falkon resource - Files present in the plugin directory
This commit is contained in:
parent
c322fdb068
commit
bf684cb7ff
|
@ -20,7 +20,9 @@
|
||||||
#include "navigationbar.h"
|
#include "navigationbar.h"
|
||||||
#include "statusbar.h"
|
#include "statusbar.h"
|
||||||
#include "pluginproxy.h"
|
#include "pluginproxy.h"
|
||||||
|
#include "qml/api/fileutils/qmlfileutils.h"
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
QmlBrowserAction::QmlBrowserAction(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -212,8 +214,14 @@ void QmlBrowserActionButton::setIcon(const QString &icon)
|
||||||
m_iconUrl = icon;
|
m_iconUrl = icon;
|
||||||
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
||||||
AbstractButtonInterface::setIcon(QIcon::fromTheme(m_iconUrl));
|
AbstractButtonInterface::setIcon(QIcon::fromTheme(m_iconUrl));
|
||||||
|
} else if (m_iconUrl.startsWith(QSL(":"))) {
|
||||||
|
// Icon is loaded from falkon resource
|
||||||
|
AbstractButtonInterface::setIcon(QIcon(m_iconUrl));
|
||||||
} else {
|
} else {
|
||||||
AbstractButtonInterface::setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl))));
|
const QString pluginPath = m_popup->creationContext()->contextProperty("__path__").toString();
|
||||||
|
QmlFileUtils fileUtils(pluginPath);
|
||||||
|
m_iconUrl = fileUtils.resolve(icon);
|
||||||
|
AbstractButtonInterface::setIcon(QIcon(m_iconUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlaction.h"
|
#include "qmlaction.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
|
#include "qml/api/fileutils/qmlfileutils.h"
|
||||||
|
|
||||||
QmlAction::QmlAction(QAction *action, QObject *parent)
|
QmlAction::QmlAction(QAction *action, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -37,8 +38,12 @@ void QmlAction::setProperties(const QVariantMap &map)
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
if (QIcon::hasThemeIcon(iconPath)) {
|
if (QIcon::hasThemeIcon(iconPath)) {
|
||||||
icon = QIcon::fromTheme(iconPath);
|
icon = QIcon::fromTheme(iconPath);
|
||||||
|
} else if (iconPath.startsWith(QSL(":"))) {
|
||||||
|
// Icon is loaded from falkon resource
|
||||||
|
icon = QIcon(iconPath);
|
||||||
} else {
|
} else {
|
||||||
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
|
QmlFileUtils fileUtils(m_pluginPath);
|
||||||
|
icon = QIcon(fileUtils.resolve(iconPath));
|
||||||
}
|
}
|
||||||
m_action->setIcon(icon);
|
m_action->setIcon(icon);
|
||||||
} else if (key == QSL("shortcut")) {
|
} else if (key == QSL("shortcut")) {
|
||||||
|
@ -57,3 +62,8 @@ void QmlAction::update(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
setProperties(map);
|
setProperties(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlAction::setPluginPath(const QString &path)
|
||||||
|
{
|
||||||
|
m_pluginPath = path;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
explicit QmlAction(QAction *action, QObject *parent = nullptr);
|
explicit QmlAction(QAction *action, QObject *parent = nullptr);
|
||||||
void setProperties(const QVariantMap &map);
|
void setProperties(const QVariantMap &map);
|
||||||
Q_INVOKABLE void update(const QVariantMap &map);
|
Q_INVOKABLE void update(const QVariantMap &map);
|
||||||
|
void setPluginPath(const QString &path);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
|
@ -40,4 +41,5 @@ Q_SIGNALS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAction *m_action;
|
QAction *m_action;
|
||||||
|
QString m_pluginPath;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "qmlmenu.h"
|
#include "qmlmenu.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
|
#include "qml/api/fileutils/qmlfileutils.h"
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
|
||||||
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
|
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
|
||||||
|
@ -43,6 +44,7 @@ QmlAction *QmlMenu::addAction(const QVariantMap &map)
|
||||||
|
|
||||||
QAction *action = new QAction();
|
QAction *action = new QAction();
|
||||||
QmlAction *qmlAction = new QmlAction(action, this);
|
QmlAction *qmlAction = new QmlAction(action, this);
|
||||||
|
qmlAction->setPluginPath(m_pluginPath);
|
||||||
qmlAction->setProperties(map);
|
qmlAction->setProperties(map);
|
||||||
m_menu->addAction(action);
|
m_menu->addAction(action);
|
||||||
|
|
||||||
|
@ -68,8 +70,12 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
if (QIcon::hasThemeIcon(iconPath)) {
|
if (QIcon::hasThemeIcon(iconPath)) {
|
||||||
icon = QIcon::fromTheme(iconPath);
|
icon = QIcon::fromTheme(iconPath);
|
||||||
|
} else if (iconPath.startsWith(QSL(":"))) {
|
||||||
|
// Icon is loaded from falkon resource
|
||||||
|
icon = QIcon(iconPath);
|
||||||
} else {
|
} else {
|
||||||
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
|
QmlFileUtils fileUtils(m_pluginPath);
|
||||||
|
icon = QIcon(fileUtils.resolve(iconPath));
|
||||||
}
|
}
|
||||||
newMenu->setIcon(icon);
|
newMenu->setIcon(icon);
|
||||||
continue;
|
continue;
|
||||||
|
@ -78,6 +84,7 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
|
||||||
}
|
}
|
||||||
m_menu->addMenu(newMenu);
|
m_menu->addMenu(newMenu);
|
||||||
QmlMenu *newQmlMenu = new QmlMenu(newMenu, this);
|
QmlMenu *newQmlMenu = new QmlMenu(newMenu, this);
|
||||||
|
newQmlMenu->setPluginPath(m_pluginPath);
|
||||||
return newQmlMenu;
|
return newQmlMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,3 +99,8 @@ void QmlMenu::addSeparator()
|
||||||
|
|
||||||
m_menu->addSeparator();
|
m_menu->addSeparator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlMenu::setPluginPath(const QString &path)
|
||||||
|
{
|
||||||
|
m_pluginPath = path;
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
Q_INVOKABLE QmlAction *addAction(const QVariantMap &map);
|
Q_INVOKABLE QmlAction *addAction(const QVariantMap &map);
|
||||||
Q_INVOKABLE QmlMenu *addMenu(const QVariantMap &map);
|
Q_INVOKABLE QmlMenu *addMenu(const QVariantMap &map);
|
||||||
Q_INVOKABLE void addSeparator();
|
Q_INVOKABLE void addSeparator();
|
||||||
|
void setPluginPath(const QString &path);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
/**
|
/**
|
||||||
|
@ -40,4 +41,5 @@ Q_SIGNALS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMenu *m_menu;
|
QMenu *m_menu;
|
||||||
|
QString m_pluginPath;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "desktopnotificationsfactory.h"
|
#include "desktopnotificationsfactory.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
|
#include "qml/api/fileutils/qmlfileutils.h"
|
||||||
|
|
||||||
QmlNotifications::QmlNotifications(QObject *parent)
|
QmlNotifications::QmlNotifications(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -38,9 +39,21 @@ QmlNotifications::QmlNotifications(QObject *parent)
|
||||||
void QmlNotifications::create(const QVariantMap &map)
|
void QmlNotifications::create(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
const QString iconUrl = map.value(QSL("icon")).toString();
|
const QString iconUrl = map.value(QSL("icon")).toString();
|
||||||
const QString iconPath = QzTools::getPathFromUrl(QUrl(iconUrl));
|
QPixmap icon;
|
||||||
const QPixmap icon(iconPath);
|
if (iconUrl.startsWith(QSL(":"))) {
|
||||||
|
// Icon is loaded from falkon resource
|
||||||
|
icon = QPixmap(iconUrl);
|
||||||
|
} else {
|
||||||
|
QmlFileUtils fileUtils(m_pluginPath);
|
||||||
|
const QString iconPath = fileUtils.resolve(iconUrl);
|
||||||
|
icon = QPixmap(iconPath);
|
||||||
|
}
|
||||||
const QString heading = map.value(QSL("heading")).toString();
|
const QString heading = map.value(QSL("heading")).toString();
|
||||||
const QString message = map.value(QSL("message")).toString();
|
const QString message = map.value(QSL("message")).toString();
|
||||||
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
mApp->desktopNotifications()->showNotification(icon, heading, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QmlNotifications::setPluginPath(const QString &path)
|
||||||
|
{
|
||||||
|
m_pluginPath = path;
|
||||||
|
}
|
||||||
|
|
|
@ -28,4 +28,7 @@ class QmlNotifications : public QObject
|
||||||
public:
|
public:
|
||||||
explicit QmlNotifications(QObject *parent = nullptr);
|
explicit QmlNotifications(QObject *parent = nullptr);
|
||||||
Q_INVOKABLE void create(const QVariantMap &map);
|
Q_INVOKABLE void create(const QVariantMap &map);
|
||||||
|
void setPluginPath(const QString &path);
|
||||||
|
private:
|
||||||
|
QString m_pluginPath;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,8 +19,10 @@
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "qztools.h"
|
#include "qztools.h"
|
||||||
#include "sidebar.h"
|
#include "sidebar.h"
|
||||||
|
#include "qml/api/fileutils/qmlfileutils.h"
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
QmlSideBar::QmlSideBar(QObject *parent)
|
QmlSideBar::QmlSideBar(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
@ -133,8 +135,13 @@ QAction *QmlSideBarHelper::createMenuAction()
|
||||||
action->setShortcut(QKeySequence(m_shortcut));
|
action->setShortcut(QKeySequence(m_shortcut));
|
||||||
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
if (QIcon::hasThemeIcon(m_iconUrl)) {
|
||||||
action->setIcon(QIcon::fromTheme(m_iconUrl));
|
action->setIcon(QIcon::fromTheme(m_iconUrl));
|
||||||
|
} else if (m_iconUrl.startsWith(QSL(":"))) {
|
||||||
|
// Icon is loaded from falkon resource
|
||||||
|
action->setIcon(QIcon(m_iconUrl));
|
||||||
} else {
|
} else {
|
||||||
action->setIcon(QIcon(QzTools::getPathFromUrl(QUrl(m_iconUrl))));
|
const QString pluginPath = m_item->creationContext()->contextProperty("__path__").toString();
|
||||||
|
QmlFileUtils fileUtils(pluginPath);
|
||||||
|
action->setIcon(QIcon(fileUtils.resolve(m_iconUrl)));
|
||||||
}
|
}
|
||||||
action->setCheckable(m_checkable);
|
action->setCheckable(m_checkable);
|
||||||
return action;
|
return action;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
QmlPluginInterface::QmlPluginInterface()
|
QmlPluginInterface::QmlPluginInterface()
|
||||||
: m_settingsWindow(nullptr)
|
: m_settingsWindow(nullptr)
|
||||||
|
@ -94,8 +95,8 @@ void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlMenu *qmlMenu = new QmlMenu(menu);
|
QmlMenu *qmlMenu = new QmlMenu(menu);
|
||||||
|
qmlMenu->setPluginPath(m_engine->rootContext()->contextProperty("__path__").toString());
|
||||||
QmlWebHitTestResult *qmlWebHitTestResult = new QmlWebHitTestResult(webHitTestResult);
|
QmlWebHitTestResult *qmlWebHitTestResult = new QmlWebHitTestResult(webHitTestResult);
|
||||||
|
|
||||||
QJSValueList args;
|
QJSValueList args;
|
||||||
args.append(m_engine->newQObject(qmlMenu));
|
args.append(m_engine->newQObject(qmlMenu));
|
||||||
args.append(m_engine->newQObject(qmlWebHitTestResult));
|
args.append(m_engine->newQObject(qmlWebHitTestResult));
|
||||||
|
|
|
@ -122,7 +122,10 @@ void QmlPlugins::registerQmlTypes()
|
||||||
Q_UNUSED(engine)
|
Q_UNUSED(engine)
|
||||||
Q_UNUSED(scriptEngine)
|
Q_UNUSED(scriptEngine)
|
||||||
|
|
||||||
|
QString filePath = engine->rootContext()->contextProperty("__path__").toString();
|
||||||
|
|
||||||
auto *object = new QmlNotifications();
|
auto *object = new QmlNotifications();
|
||||||
|
object->setPluginPath(filePath);
|
||||||
return object;
|
return object;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ Falkon.PluginInterface {
|
||||||
identity: 'helloqml-id'
|
identity: 'helloqml-id'
|
||||||
title: 'Testing QML Title'
|
title: 'Testing QML Title'
|
||||||
toolTip: 'Testing QML Tooltip'
|
toolTip: 'Testing QML Tooltip'
|
||||||
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
|
icon: ':/icons/preferences/extensions.svg'
|
||||||
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
|
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
|
||||||
popup: Window {
|
popup: Window {
|
||||||
property var borderMargin: 1
|
property var borderMargin: 1
|
||||||
|
@ -41,7 +41,7 @@ Falkon.PluginInterface {
|
||||||
color: 'white'
|
color: 'white'
|
||||||
Image {
|
Image {
|
||||||
id: image
|
id: image
|
||||||
source: Qt.resolvedUrl('qrc:/icons/other/startpage.svg')
|
source: 'qrc:/icons/other/startpage.svg'
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
@ -61,11 +61,11 @@ Falkon.PluginInterface {
|
||||||
Falkon.SideBar {
|
Falkon.SideBar {
|
||||||
name: 'helloqml-sidebar'
|
name: 'helloqml-sidebar'
|
||||||
title: 'Testing QML SideBar'
|
title: 'Testing QML SideBar'
|
||||||
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
|
icon: ':/icons/preferences/extensions.svg'
|
||||||
checkable: true
|
checkable: true
|
||||||
Window {
|
Window {
|
||||||
Image {
|
Image {
|
||||||
source: Qt.resolvedUrl('qrc:/icons/other/startpage.svg')
|
source: 'qrc:/icons/other/startpage.svg'
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
@ -84,7 +84,7 @@ Falkon.PluginInterface {
|
||||||
var text = 'My first qml plugin action'
|
var text = 'My first qml plugin action'
|
||||||
var action = menu.addAction({
|
var action = menu.addAction({
|
||||||
text: text,
|
text: text,
|
||||||
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
|
icon: ':/icons/preferences/extensions.svg'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (webHitTestResult.isImage()) {
|
if (webHitTestResult.isImage()) {
|
||||||
|
@ -105,7 +105,7 @@ Falkon.PluginInterface {
|
||||||
Falkon.Notifications.create({
|
Falkon.Notifications.create({
|
||||||
heading: 'Hello QML',
|
heading: 'Hello QML',
|
||||||
message: 'First qml plugin action works :-)',
|
message: 'First qml plugin action works :-)',
|
||||||
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
|
icon: ':/icons/preferences/extensions.svg'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ Falkon.PluginInterface {
|
||||||
height: 200
|
height: 200
|
||||||
Image {
|
Image {
|
||||||
id: image
|
id: image
|
||||||
source: Qt.resolvedUrl('qrc:/icons/other/about.svg')
|
source: 'qrc:/icons/other/about.svg'
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
Loading…
Reference in New Issue
Block a user