diff --git a/Makefile b/Makefile index 633f118..911e3b0 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ upload-locale-fr: ## Upload fr locale to Transifex plasmoid: ## Make the .plasmoid file rm -f com.aehallh.webslice.plasmoid cd ./com.aehallh.webslice/; \ - zip -9 -r com.aehallh.webslice.plasmoid.zip contents/ metadata.desktop + zip -9 -r com.aehallh.webslice.plasmoid.zip contents/ metadata.json mv ./com.aehallh.webslice/com.aehallh.webslice.plasmoid.zip ./com.aehallh.webslice.plasmoid update: ## Update the installed package diff --git a/com.aehallh.webslice/contents/code/utils.js b/com.aehallh.webslice/contents/code/utils.js index 371b907..5bf6ba4 100644 --- a/com.aehallh.webslice/contents/code/utils.js +++ b/com.aehallh.webslice/contents/code/utils.js @@ -57,8 +57,8 @@ function navTypeString(navType) { } } -function debug(entry) { +function debug(...entry) { if (cfg_debug) { - console.log(entry) + console.log(...entry) } } diff --git a/com.aehallh.webslice/contents/ui/ConfigAdvanced.qml b/com.aehallh.webslice/contents/ui/ConfigAdvanced.qml index 01b036c..3c6e21d 100644 --- a/com.aehallh.webslice/contents/ui/ConfigAdvanced.qml +++ b/com.aehallh.webslice/contents/ui/ConfigAdvanced.qml @@ -3,9 +3,10 @@ import QtQuick.Controls 2.12 import QtQuick.Layouts 1.10 import org.kde.kquickcontrols 2.0 import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.kcmutils as KCMUtils +import org.kde.kirigami as Kirigami -Item { - +KCMUtils.SimpleKCM { property alias cfg_enableScrollTo: enableScrollTo.checked property alias cfg_scrollToX: scrollToX.text property alias cfg_scrollToY: scrollToY.text diff --git a/com.aehallh.webslice/contents/ui/ConfigExperimental.qml b/com.aehallh.webslice/contents/ui/ConfigExperimental.qml index ab429d9..78de2c7 100644 --- a/com.aehallh.webslice/contents/ui/ConfigExperimental.qml +++ b/com.aehallh.webslice/contents/ui/ConfigExperimental.qml @@ -2,8 +2,10 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.10 import org.kde.kquickcontrols 2.0 +import org.kde.kcmutils as KCMUtils +import org.kde.kirigami as Kirigami -Item { +KCMUtils.SimpleKCM { property alias cfg_keysSeqBack: keysSeqBack.keySequence property alias cfg_keysSeqForward: keysSeqForward.keySequence diff --git a/com.aehallh.webslice/contents/ui/ConfigGeneral.qml b/com.aehallh.webslice/contents/ui/ConfigGeneral.qml index 86bc791..f625991 100644 --- a/com.aehallh.webslice/contents/ui/ConfigGeneral.qml +++ b/com.aehallh.webslice/contents/ui/ConfigGeneral.qml @@ -1,10 +1,11 @@ -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.10 -import org.kde.kquickcontrols 2.0 - -Item { - +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import org.kde.kquickcontrols +import org.kde.kcmutils as KCMUtils +import org.kde.kirigami as Kirigami + +KCMUtils.SimpleKCM { property alias cfg_websliceUrl: websliceUrl.text property alias cfg_zoomFactor: zoomFactor.value property alias cfg_enableReload: enableReload.checked diff --git a/com.aehallh.webslice/contents/ui/ConfigMultipleURLs.qml b/com.aehallh.webslice/contents/ui/ConfigMultipleURLs.qml index b20721b..979aaf9 100644 --- a/com.aehallh.webslice/contents/ui/ConfigMultipleURLs.qml +++ b/com.aehallh.webslice/contents/ui/ConfigMultipleURLs.qml @@ -1,85 +1,130 @@ -import QtQuick 2.12 -import QtQuick.Controls 1.4 -import QtQuick.Layouts 1.10 +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import org.kde.plasma.components as PlasmaComponents import "../code/utils.js" as ConfigUtils +import org.kde.kcmutils as KCMUtils +import org.kde.kirigami as Kirigami -Item { +KCMUtils.SimpleKCM { id: rootItem property string cfg_urlsModel + + /* property int textfieldWidth:parent.width-(buttonAdd.width+5)*4 property double tableWidth: parent.width + */ + /* ListModel { id: urlsModel } + */ - Grid{ - columns:1 - spacing:6 - + ColumnLayout { Label { - text: i18n('List of URL accessible throught the context menu to switch to others websites.') + text: i18n('List of URLs accessible throught the context menu to switch to others websites.') } - TableView { + ListView { id: table - model: urlsModel - width: tableWidth - TableViewColumn { - role: 'url' - title: i18n('URL') - } - height:300 + width: parent.parent.width; height: 200; + model: ListModel { + id: urlsModel + } + orientation: ListView.Vertical + verticalLayoutDirection: ListView.TopToBottom + highlightFollowsCurrentItem: true + // width: tableWidth + delegate: Component { + id: urlComponent + PlasmaComponents.ItemDelegate { + id: urlText + required property string url + text: "URL: " + url + highlighted: ListView.isCurrentItem + onClicked: { + console.log("index:", index); + } + // color: ListView.isCurrentItem ? Kirigami.Theme.activeTextColor : Kirigami.Theme.textColor + + /* + MouseArea { + anchors.fill: parent + onClicked: { + urlText.forceActiveFocus() + console.log("urlText.index: ", urlText.index) + console.log("parent.index: ", parent.index) + console.log("index: ", index) + table.currentIndex = parent.index + } + } + */ + } + } + //height:300 + focus: true } - RowLayout { - TextField { - id: addedUrl - placeholderText: i18n('URL') - Layout.preferredWidth: textfieldWidth - } + TextField { + id: addedUrl + placeholderText: i18n('URL to add') + Keys.onReturnPressed: { + urlsModel.append({"url": addedUrl.text}); + cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) + } + // Layout.preferredWidth: textfieldWidth + } + RowLayout { + id: buttons Button { id:buttonAdd - iconName: 'list-add' - tooltip: i18n('Add a URL') + icon.name: 'list-add' + text: i18n('Add a URL') onClicked: { - urlsModel.append({"url":addedUrl.text}); + urlsModel.append({"url": addedUrl.text}); cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) } } Button { - iconName: 'list-remove' - tooltip: i18n('Remove the selected URL') + icon.name: 'list-remove' + text: i18n('Remove the selected URL') onClicked: { - urlsModel.remove(table.currentRow); + urlsModel.remove(table.currentIndex); cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) } } Button { - iconName: 'go-up' - tooltip: i18n('Move the selected URL up') + icon.name: 'go-up' + text: i18n('Move the selected URL up') onClicked: { - urlsModel.move(table.currentRow,table.currentRow-1, 1); - table.selection.clear(); - table.selection.select(table.currentRow-1,table.currentRow-1) - cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) + var current = table.currentIndex + + if (current > 0) { + urlsModel.move(table.currentIndex, table.currentIndex - 1, 1); + table.currentIndex = Math.max(current - 1, 0) + cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) + } } } Button { - iconName: 'go-down' - tooltip: i18n('Move the selected URL down') + icon.name: 'go-down' + text: i18n('Move the selected URL down') onClicked: { - urlsModel.move(table.currentRow, table.currentRow+1, 1); - table.selection.clear(); - table.selection.select(table.currentRow+1,table.currentRow+1) - cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) + var current = table.currentIndex + + if (current < (table.count - 1)) { + urlsModel.move(table.currentIndex, table.currentIndex + 1, 1); + table.currentIndex = Math.min(current + 1, table.count) + cfg_urlsModel = ConfigUtils.stringifyModel(urlsModel) + } } } } @@ -88,6 +133,7 @@ Item { Component.onCompleted: { var arrayURLs = ConfigUtils.getURLsObjectArray(); for (var index in arrayURLs) { + console.log("URL: ", arrayURLs[index]); urlsModel.append({"url":arrayURLs[index]}); } } diff --git a/com.aehallh.webslice/contents/ui/main.qml b/com.aehallh.webslice/contents/ui/main.qml index a141b88..6bb5fd1 100644 --- a/com.aehallh.webslice/contents/ui/main.qml +++ b/com.aehallh.webslice/contents/ui/main.qml @@ -17,21 +17,22 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ -import QtQuick 2.15 -import QtWebEngine 1.11 -import QtQuick.Layouts 1.15 -import QtQuick.Controls 2.15 -import org.kde.plasma.plasma5support 2.0 as P5Support -import org.kde.plasma.plasmoid 2.0 -import org.kde.plasma.components 2.0 as PlasmaComponents -import org.kde.plasma.core 2.0 as PlasmaCore -import QtQml 2.15 +import QtQuick +import QtWebEngine +import QtQuick.Layouts +import QtQuick.Controls +import org.kde.plasma.plasma5support as P5Support +import org.kde.plasma.plasmoid +import org.kde.plasma.components as PlasmaComponents +import org.kde.plasma.core as PlasmaCore +import QtQml +import org.kde.kirigami as Kirigami import "../code/utils.js" as ConfigUtils -Item { +PlasmoidItem { id: main property string websliceUrl: Plasmoid.configuration.websliceUrl @@ -79,11 +80,11 @@ Item { signal handleSettingsUpdated(); - Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation + preferredRepresentation: fullRepresentation - Plasmoid.fullRepresentation: webview + fullRepresentation: webview - Plasmoid.icon: webPopupIcon + // icon.name: webPopupIcon onUrlsModelChanged:{ ConfigUtils.debug("onUrlsModelChanged"); loadURLs(); } @@ -108,11 +109,13 @@ Item { //onKeysseqChanged: { main.handleSettingsUpdated(); } + /* Binding { target: plasmoid property: "hideOnWindowDeactivate" value: !showPinButton } + */ property Component webview: WebEngineView { @@ -122,7 +125,7 @@ Item { // anchors.fill: plasmoid.fullRepresentation // anchors.fill: plasmoid.rootItem; - backgroundColor: backgroundColorWhite?"white":(backgroundColorTransparent?"transparent":(backgroundColorTheme?theme.viewBackgroundColor:(backgroundColorCustom?customBackgroundColor:"black"))) + backgroundColor: backgroundColorWhite?"white":(backgroundColorTransparent?"transparent":(backgroundColorTheme?Kirigami.Theme.viewBackgroundColor:(backgroundColorCustom?customBackgroundColor:"black"))) width: webPopupWidth height: webPopupHeight @@ -161,7 +164,7 @@ Item { function onHandleSettingsUpdated() { ConfigUtils.debug("onHandleSettingsUpdated") - loadMenu(); + // loadMenu(); updateSizeHints(); } @@ -213,37 +216,33 @@ Item { /** * Handle everything around web request : display the busy indicator, and run JS */ - onLoadingChanged: { + onLoadingChanged: function(loadingInfo) { ConfigUtils.debug("onLoadingChanged") - ConfigUtils.debug(" loadRequest.status:", ConfigUtils.loadString(loadRequest.status)) - ConfigUtils.debug(" loadRequest.errorCode:", loadRequest.errorCode) - ConfigUtils.debug(" loadRequest.errorDomain:", loadRequest.errorDomain) - ConfigUtils.debug(" loadRequest.errorString:", loadRequest.errorString) - ConfigUtils.debug(" loadRequest.url:", loadRequest.url) + ConfigUtils.debug(" loadingInfo.status:", ConfigUtils.loadString(loadingInfo.status)) + ConfigUtils.debug(" loadingInfo.errorCode:", loadingInfo.errorCode) + ConfigUtils.debug(" loadingInfo.errorDomain:", loadingInfo.errorDomain) + ConfigUtils.debug(" loadingInfo.errorString:", loadingInfo.errorString) + ConfigUtils.debug(" loadingInfo.url:", loadingInfo.url) ConfigUtils.debug(" zoomFactorCfg:", zoomFactorCfg) webviewID.zoomFactor = zoomFactorCfg; - if (enableScrollTo && loadRequest.status === WebEngineView.LoadSucceededStatus) { + if (enableScrollTo && loadingInfo.status === WebEngineView.LoadSucceededStatus) { runJavaScript("window.scrollTo("+scrollToX+", "+scrollToY+");"); } - if (enableJSID && loadRequest.status === WebEngineView.LoadSucceededStatus) { + if (enableJSID && loadingInfo.status === WebEngineView.LoadSucceededStatus) { runJavaScript(jsSelector + ".scrollIntoView(true);"); } - if (scrollbarsOverflow && loadRequest.status === WebEngineView.LoadSucceededStatus) { + if (scrollbarsOverflow && loadingInfo.status === WebEngineView.LoadSucceededStatus) { runJavaScript("document.body.style.overflow='hidden';"); - }else if (scrollbarsWebkit && loadRequest.status === WebEngineView.LoadSucceededStatus){ + }else if (scrollbarsWebkit && loadingInfo.status === WebEngineView.LoadSucceededStatus){ runJavaScript("var style = document.createElement('style'); style.innerHTML = `body::-webkit-scrollbar {display: none;}`; document.head.appendChild(style);"); } - if (enableJS && loadRequest.status === WebEngineView.LoadSucceededStatus) { + if (enableJS && loadingInfo.status === WebEngineView.LoadSucceededStatus) { runJavaScript(js); } - if (loadRequest && (loadRequest.status === WebEngineView.LoadSucceededStatus || loadRequest.status === WebEngineLoadRequest.LoadFailedStatus)) { + if (loadingInfo && (loadingInfo.status === WebEngineView.LoadSucceededStatus || loadingInfo.status === WebEngineView.LoadFailedStatus)) { plasmoid.busy = false; - /* - busyIndicator.visible = false; - busyIndicator.running = false; - */ } } @@ -254,14 +253,15 @@ Item { /** * Open the middle clicked (or ctrl+clicked) link in the default browser */ - onNavigationRequested: { - ConfigUtils.debug("onNavigationRequested, request.action:", request.action, "isMainFrame:", request.isMainFrame, "navigationType:", ConfigUtils.navTypeString(request.navigationType), "url:", request.url, "isExternalLink:", isExternalLink, "zoomFactorCfg:", zoomFactorCfg) + onNavigationRequested: function(request) { + ConfigUtils.debug("onNavigationRequested, isMainFrame:", request.isMainFrame, "navigationType:", ConfigUtils.navTypeString(request.navigationType), "url:", request.url, "isExternalLink:", isExternalLink, "zoomFactorCfg:", zoomFactorCfg) webviewID.zoomFactor = zoomFactorCfg; - if(isExternalLink){ + if (isExternalLink) { isExternalLink = false; - request.action = WebEngineView.IgnoreRequest; + request.reject() + //request.action = WebEngineView.IgnoreRequest; Qt.openUrlExternally(request.url); - }else if(reloadAnimation){ + } else if (reloadAnimation) { plasmoid.busy = true; /* busyIndicator.visible = true; @@ -283,8 +283,10 @@ Item { onRenderProcessTerminated: { ConfigUtils.debug("onRenderProcessTerminated terminationStatus:", terminationStatus, "exitCode:", exitCode) + reloadFn(false) } + /* onNewViewRequested: { ConfigUtils.debug("onNewViewRequested") if (request.userInitiated) { @@ -293,11 +295,12 @@ Item { isExternalLink = false; } } + */ /** * Show context menu */ - onContextMenuRequested: { + onContextMenuRequested: function(request) { ConfigUtils.debug("onContextMenuRequested") ConfigUtils.debug(" ErrorDomain:", webviewID.ErrorDomain) ConfigUtils.debug(" Feature:", webviewID.Feature) @@ -310,16 +313,24 @@ Item { ConfigUtils.debug(" title:", webviewID.title) ConfigUtils.debug(" url:", url) ConfigUtils.debug(" request:", request) + ConfigUtils.debug(" request.x:", request.x) + ConfigUtils.debug(" request.y:", request.y) + ConfigUtils.debug(" contextualActions:", Plasmoid.contextualActions); + /* + // FIXME: We don't have any way to trigger the context menu right now. request.accepted = true - contextMenu.request = request - contextMenu.open(request.x, request.y) + Plasmoid.contextualActionsAboutToShow() + Plasmoid.showStatusNotifierContextMenu() + Plasmoid.showPlasmoidMenu(main, request.x, request.y) + contextMenu(request) + */ } /** * Get status of Ctrl key */ - P5Support.DataSource { + P5Support.DataSource { id: dataSource engine: "keystate" connectedSources: ["Ctrl"] @@ -328,28 +339,23 @@ Item { /** * Context menu */ - PlasmaComponents.ContextMenu { - property var request - id: contextMenu - - PlasmaComponents.MenuItem { + Plasmoid.contextualActions: [ + PlasmaCore.Action { text: i18n('Back') - icon: 'draw-arrow-back' + icon.name: 'draw-arrow-back' enabled: webviewID.canGoBack - onClicked: webviewID.goBack() - } - - PlasmaComponents.MenuItem { + onTriggered: webviewID.goBack() + }, + PlasmaCore.Action { text: i18n('Forward') - icon: 'draw-arrow-forward' + icon.name: 'draw-arrow-forward' enabled: webviewID.canGoForward - onClicked: webviewID.goForward() - } - - PlasmaComponents.MenuItem { + onTriggered: webviewID.goForward() + }, + PlasmaCore.Action { text: i18n('Reload') - icon: 'view-refresh' - onClicked: { + icon.name: 'view-refresh' + onTriggered: { ConfigUtils.debug("Refresh clicked") // Force reload if Ctrl pressed if (dataSource.data.Ctrl !== undefined && dataSource.data.Ctrl.Pressed) { @@ -358,63 +364,43 @@ Item { reloadFn(false); } } - } - - PlasmaComponents.MenuItem { - id: gotourls - text: i18n('Go to') - icon: 'go-jump' - visible:(urlsToShow.count>0) - enabled:(urlsToShow.count>0) - - /** - * Dynamic context menu - * Display the principal URL first, then the list - */ - PlasmaComponents.ContextMenu { - id: dynamicMenu - visualParent: gotourls.action - PlasmaComponents.MenuItem { - text: websliceUrl - icon: 'go-home' - onClicked: webviewID.url = websliceUrl - } - } - } - - PlasmaComponents.MenuItem { + }, + PlasmaCore.Action { text: i18n('Go Home') - icon: 'go-home' + icon.name: 'go-home' visible:(urlsToShow.count==0) enabled:(urlsToShow.count==0) - onClicked: webviewID.url = websliceUrl - } + onTriggered: webviewID.url = websliceUrl + }, - PlasmaComponents.MenuItem { + PlasmaCore.Action { text: i18n('Open current URL in default browser') - icon: 'document-share' - onClicked: Qt.openUrlExternally(webviewID.url) - } + icon.name: 'document-share' + onTriggered: Qt.openUrlExternally(webviewID.url) + }, - PlasmaComponents.MenuItem{ + /* + PlasmaCore.Action{ separator: true visible: (typeof contextMenu.request !== "undefined" && contextMenu.request.linkUrl && contextMenu.request.linkUrl != "") - } + }, + */ - PlasmaComponents.MenuItem { + PlasmaCore.Action { text: i18n('Open link\'s URL in default browser') - icon: 'document-share' + icon.name: 'document-share' enabled: (typeof contextMenu.request !== "undefined" && contextMenu.request.linkUrl && contextMenu.request.linkUrl != "") visible: (typeof contextMenu.request !== "undefined" && contextMenu.request.linkUrl && contextMenu.request.linkUrl != "") - onClicked: Qt.openUrlExternally(contextMenu.request.linkUrl) - } + onTriggered: Qt.openUrlExternally(contextMenu.request.linkUrl) + }, - PlasmaComponents.MenuItem { + /* + PlasmaCore.Action { text: i18n('Copy link\'s URL') - icon: 'edit-copy' + icon.name: 'edit-copy' enabled: (typeof contextMenu.request !== "undefined" && contextMenu.request.linkUrl && contextMenu.request.linkUrl != "") visible: (typeof contextMenu.request !== "undefined" && contextMenu.request.linkUrl && contextMenu.request.linkUrl != "") - onClicked: { + onTriggered: { ConfigUtils.debug("Copy link URL clicked") copyURLTextEdit.text = contextMenu.request.linkUrl copyURLTextEdit.selectAll() @@ -424,22 +410,26 @@ Item { id: copyURLTextEdit visible: false } - } + }, + */ - PlasmaComponents.MenuItem{ + /* + PlasmaCore.Action{ separator: true - } + }, + */ - PlasmaComponents.MenuItem { + PlasmaCore.Action { text: i18n('Configure') - icon: 'configure' - onClicked: Plasmoid.action("configure").trigger() + icon.name: 'configure' + onTriggered: Plasmoid.internalAction("configure").trigger() } - } + ] + /* function addEntry(stringURL) { ConfigUtils.debug("addEntry:", stringURL) - var menuItemI = menuItem.createObject(dynamicMenu, {text: stringURL, icon: 'link', "stringURL":stringURL}); + var menuItemI = menuItem.createObject(dynamicMenu, {text: stringURL, icon.name: 'link', "stringURL":stringURL}); menuItemI.clicked.connect(function() { webviewID.url = stringURL; }); } @@ -448,7 +438,9 @@ Item { PlasmaComponents.MenuItem { } } + */ + /* function loadMenu() { ConfigUtils.debug("loadMenu") for(var i=1; i 0; - loops: Animation.Infinite - } - } - } - */ - function reloadFn(force) { ConfigUtils.debug("reloadFn: ", force) if(reloadAnimation){ diff --git a/com.aehallh.webslice/metadata.desktop b/com.aehallh.webslice/metadata.desktop deleted file mode 100644 index a7bd687..0000000 --- a/com.aehallh.webslice/metadata.desktop +++ /dev/null @@ -1,17 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Name=WebSlice (New) -Comment=Add a slice of web on your desktop. -Type=Service -Icon=internet-web-browser -X-KDE-PluginInfo-Author=Liz Loss-Cutler-Hull -X-KDE-PluginInfo-Email=warp-spam_plasmoid@aehallh.com -X-KDE-PluginInfo-License=GPL3 -X-KDE-PluginInfo-Name=com.aehallh.webslice -X-KDE-PluginInfo-Version=2.5.0 -X-KDE-PluginInfo-Website=https://www.github.com/zelch/webslice-plasmoid/ -X-KDE-ServiceTypes=Plasma/Applet -X-Plasma-API=declarativeappletscript -X-Plasma-MainScript=ui/main.qml -X-KDE-PluginInfo-Category=Online Services -X-Plasma-StandAloneApp=true diff --git a/com.aehallh.webslice/metadata.json b/com.aehallh.webslice/metadata.json new file mode 100644 index 0000000..2d53424 --- /dev/null +++ b/com.aehallh.webslice/metadata.json @@ -0,0 +1,21 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "warp-spam_plasmoid@aehallh.com", + "Name": "Liz Loss-Cutler-Hull" + } + ], + "Category": "Online Services", + "Description": "Add a slice of web on your desktop.", + "Icon": "internet-web-browser", + "Id": "com.aehallh.webslice", + "License": "GPL3", + "Name": "WebSlice (New)", + "Version": "2.6.0", + "Website": "https://www.github.com/zelch/webslice-plasmoid/" + }, + "KPackageStructure": "Plasma/Applet", + "X-Plasma-API-Minimum-Version": "6.0", + "X-Plasma-StandAloneApp": true +}