1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02: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:
Anmol Gautam 2018-07-18 18:48:28 +05:30
parent c322fdb068
commit bf684cb7ff
11 changed files with 75 additions and 14 deletions

View File

@ -20,7 +20,9 @@
#include "navigationbar.h"
#include "statusbar.h"
#include "pluginproxy.h"
#include "qml/api/fileutils/qmlfileutils.h"
#include <QQuickWindow>
#include <QQmlContext>
QmlBrowserAction::QmlBrowserAction(QObject *parent)
: QObject(parent)
@ -212,8 +214,14 @@ void QmlBrowserActionButton::setIcon(const QString &icon)
m_iconUrl = icon;
if (QIcon::hasThemeIcon(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 {
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));
}
}

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "qmlaction.h"
#include "qztools.h"
#include "qml/api/fileutils/qmlfileutils.h"
QmlAction::QmlAction(QAction *action, QObject *parent)
: QObject(parent)
@ -37,8 +38,12 @@ void QmlAction::setProperties(const QVariantMap &map)
QIcon icon;
if (QIcon::hasThemeIcon(iconPath)) {
icon = QIcon::fromTheme(iconPath);
} else if (iconPath.startsWith(QSL(":"))) {
// Icon is loaded from falkon resource
icon = QIcon(iconPath);
} else {
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
QmlFileUtils fileUtils(m_pluginPath);
icon = QIcon(fileUtils.resolve(iconPath));
}
m_action->setIcon(icon);
} else if (key == QSL("shortcut")) {
@ -57,3 +62,8 @@ void QmlAction::update(const QVariantMap &map)
{
setProperties(map);
}
void QmlAction::setPluginPath(const QString &path)
{
m_pluginPath = path;
}

View File

@ -31,6 +31,7 @@ public:
explicit QmlAction(QAction *action, QObject *parent = nullptr);
void setProperties(const QVariantMap &map);
Q_INVOKABLE void update(const QVariantMap &map);
void setPluginPath(const QString &path);
Q_SIGNALS:
/**
@ -40,4 +41,5 @@ Q_SIGNALS:
private:
QAction *m_action;
QString m_pluginPath;
};

View File

@ -17,6 +17,7 @@
* ============================================================ */
#include "qmlmenu.h"
#include "qztools.h"
#include "qml/api/fileutils/qmlfileutils.h"
#include <QQmlEngine>
QmlMenu::QmlMenu(QMenu *menu, QObject *parent)
@ -43,6 +44,7 @@ QmlAction *QmlMenu::addAction(const QVariantMap &map)
QAction *action = new QAction();
QmlAction *qmlAction = new QmlAction(action, this);
qmlAction->setPluginPath(m_pluginPath);
qmlAction->setProperties(map);
m_menu->addAction(action);
@ -68,8 +70,12 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
QIcon icon;
if (QIcon::hasThemeIcon(iconPath)) {
icon = QIcon::fromTheme(iconPath);
} else if (iconPath.startsWith(QSL(":"))) {
// Icon is loaded from falkon resource
icon = QIcon(iconPath);
} else {
icon = QIcon(QzTools::getPathFromUrl(QUrl::fromEncoded(iconPath.toUtf8())));
QmlFileUtils fileUtils(m_pluginPath);
icon = QIcon(fileUtils.resolve(iconPath));
}
newMenu->setIcon(icon);
continue;
@ -78,6 +84,7 @@ QmlMenu *QmlMenu::addMenu(const QVariantMap &map)
}
m_menu->addMenu(newMenu);
QmlMenu *newQmlMenu = new QmlMenu(newMenu, this);
newQmlMenu->setPluginPath(m_pluginPath);
return newQmlMenu;
}
@ -92,3 +99,8 @@ void QmlMenu::addSeparator()
m_menu->addSeparator();
}
void QmlMenu::setPluginPath(const QString &path)
{
m_pluginPath = path;
}

View File

@ -31,6 +31,7 @@ public:
Q_INVOKABLE QmlAction *addAction(const QVariantMap &map);
Q_INVOKABLE QmlMenu *addMenu(const QVariantMap &map);
Q_INVOKABLE void addSeparator();
void setPluginPath(const QString &path);
Q_SIGNALS:
/**
@ -40,4 +41,5 @@ Q_SIGNALS:
private:
QMenu *m_menu;
QString m_pluginPath;
};

View File

@ -19,6 +19,7 @@
#include "mainapplication.h"
#include "desktopnotificationsfactory.h"
#include "qztools.h"
#include "qml/api/fileutils/qmlfileutils.h"
QmlNotifications::QmlNotifications(QObject *parent)
: QObject(parent)
@ -38,9 +39,21 @@ QmlNotifications::QmlNotifications(QObject *parent)
void QmlNotifications::create(const QVariantMap &map)
{
const QString iconUrl = map.value(QSL("icon")).toString();
const QString iconPath = QzTools::getPathFromUrl(QUrl(iconUrl));
const QPixmap icon(iconPath);
QPixmap icon;
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 message = map.value(QSL("message")).toString();
mApp->desktopNotifications()->showNotification(icon, heading, message);
}
void QmlNotifications::setPluginPath(const QString &path)
{
m_pluginPath = path;
}

View File

@ -28,4 +28,7 @@ class QmlNotifications : public QObject
public:
explicit QmlNotifications(QObject *parent = nullptr);
Q_INVOKABLE void create(const QVariantMap &map);
void setPluginPath(const QString &path);
private:
QString m_pluginPath;
};

View File

@ -19,8 +19,10 @@
#include "mainapplication.h"
#include "qztools.h"
#include "sidebar.h"
#include "qml/api/fileutils/qmlfileutils.h"
#include <QAction>
#include <QQuickWindow>
#include <QQmlContext>
QmlSideBar::QmlSideBar(QObject *parent)
: QObject(parent)
@ -133,8 +135,13 @@ QAction *QmlSideBarHelper::createMenuAction()
action->setShortcut(QKeySequence(m_shortcut));
if (QIcon::hasThemeIcon(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 {
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);
return action;

View File

@ -34,6 +34,7 @@
#include <QQuickWindow>
#include <QDialog>
#include <QVBoxLayout>
#include <QQmlContext>
QmlPluginInterface::QmlPluginInterface()
: m_settingsWindow(nullptr)
@ -94,8 +95,8 @@ void QmlPluginInterface::populateWebViewMenu(QMenu *menu, WebView *webview, cons
}
QmlMenu *qmlMenu = new QmlMenu(menu);
qmlMenu->setPluginPath(m_engine->rootContext()->contextProperty("__path__").toString());
QmlWebHitTestResult *qmlWebHitTestResult = new QmlWebHitTestResult(webHitTestResult);
QJSValueList args;
args.append(m_engine->newQObject(qmlMenu));
args.append(m_engine->newQObject(qmlWebHitTestResult));

View File

@ -122,7 +122,10 @@ void QmlPlugins::registerQmlTypes()
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
QString filePath = engine->rootContext()->contextProperty("__path__").toString();
auto *object = new QmlNotifications();
object->setPluginPath(filePath);
return object;
});

View File

@ -21,7 +21,7 @@ Falkon.PluginInterface {
identity: 'helloqml-id'
title: 'Testing QML Title'
toolTip: 'Testing QML Tooltip'
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
icon: ':/icons/preferences/extensions.svg'
location: Falkon.BrowserAction.NavigationToolBar | Falkon.BrowserAction.StatusBar
popup: Window {
property var borderMargin: 1
@ -41,7 +41,7 @@ Falkon.PluginInterface {
color: 'white'
Image {
id: image
source: Qt.resolvedUrl('qrc:/icons/other/startpage.svg')
source: 'qrc:/icons/other/startpage.svg'
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
@ -61,11 +61,11 @@ Falkon.PluginInterface {
Falkon.SideBar {
name: 'helloqml-sidebar'
title: 'Testing QML SideBar'
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
icon: ':/icons/preferences/extensions.svg'
checkable: true
Window {
Image {
source: Qt.resolvedUrl('qrc:/icons/other/startpage.svg')
source: 'qrc:/icons/other/startpage.svg'
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.right: parent.right
@ -84,7 +84,7 @@ Falkon.PluginInterface {
var text = 'My first qml plugin action'
var action = menu.addAction({
text: text,
icon: Qt.resolvedUrl('qrc:/icons/preferences/extensions.svg')
icon: ':/icons/preferences/extensions.svg'
})
if (webHitTestResult.isImage()) {
@ -105,7 +105,7 @@ Falkon.PluginInterface {
Falkon.Notifications.create({
heading: 'Hello QML',
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
Image {
id: image
source: Qt.resolvedUrl('qrc:/icons/other/about.svg')
source: 'qrc:/icons/other/about.svg'
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right