Skip to content

Commit

Permalink
Merge pull request #28 from korapp/dev
Browse files Browse the repository at this point in the history
Port to Plasma 6
  • Loading branch information
korapp authored Jan 2, 2024
2 parents eea79c9 + 7f11f49 commit f5c2fa0
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 194 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Simple GUI for the official [NordVPN linux client][nordvpn]. It allows to quick
## Requirements

* [NordVPN linux client][nordvpn]
* Qt >= 5.14, KDE Frameworks >= 5.73, KDE Plasma >= 5.19 (Kubuntu 20.10 and newer)
* KDE Plasma >= 6.0

## Installation

Expand Down Expand Up @@ -69,6 +69,6 @@ Say thank you with coffee ☕ if you'd like.
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/korapp)
[<img src="https://img.shields.io/badge/Revolut-white?logo=Revolut&logoColor=black" height="30"/>](https://revolut.me/korapp)

[kdestore]: https://store.kde.org/p/1689651/
[kdestore]: https://store.kde.org/p/2118492/
[releases]: https://github.com/korapp/plasma-nordvpn/releases
[nordvpn]: https://nordvpn.com/download/linux
18 changes: 10 additions & 8 deletions plasmoid/contents/ui/CompactRepresentation.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import QtQuick 2.0
import QtQuick

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.components as PlasmaComponents3
import org.kde.ksvg as KSvg

import org.kde.kirigami as Kirigami

import "../code/countries.js" as Countries

Expand All @@ -10,8 +12,8 @@ MouseArea {
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
readonly property int minSize: Math.min(width, height)

PlasmaCore.SvgItem {
svg: PlasmaCore.Svg {
KSvg.SvgItem {
svg: KSvg.Svg {
imagePath: plasmoid.icon
}
enabled: nordvpn.isConnected
Expand All @@ -21,7 +23,7 @@ MouseArea {

anchors.centerIn: parent

PlasmaCore.IconItem {
Kirigami.Icon {
visible: plasmoid.configuration.showCountryIndicator && nordvpn.isConnected
source: visible ? flags.getFlagImage(Countries.codes[nordvpn.status.Country], Qt.size(width, height)) : ''
enabled: true
Expand All @@ -41,7 +43,7 @@ MouseArea {
}
}

onClicked: {
onClicked: function (mouse) {
if (plasmoid.configuration.toggleConnectionOnMiddleButton && mouse.button === Qt.MiddleButton) {
toggleConnection()
} else {
Expand All @@ -54,6 +56,6 @@ MouseArea {
}

function toggleExpanded() {
plasmoid.expanded = !plasmoid.expanded
root.expanded = !root.expanded
}
}
6 changes: 3 additions & 3 deletions plasmoid/contents/ui/ConfigGeneral.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick
import QtQuick.Controls

import org.kde.kirigami 2.3 as Kirigami
import org.kde.kirigami as Kirigami

Kirigami.FormLayout {
id: generalPage
Expand Down
50 changes: 27 additions & 23 deletions plasmoid/contents/ui/ConnectionItem.qml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.3
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.components as PlasmaComponents
import org.kde.plasma.extras as PlasmaExtras

import org.kde.kirigami as Kirigami

import "../code/globals.js" as Globals

Expand All @@ -18,37 +19,40 @@ PlasmaExtras.ExpandableListItem {
iconEmblem: model.indicator
visible: model.visible
defaultActionButtonAction: model.isConnected ? actionDisconnect : actionConnect
contextMenu: model.pinable ? itemContextMenu : null
// plasma-frameworks 5.94 - 5.102 loads customExpandedViewContent immediately
// start with an empty component to force the expand button to appear and load the right content when expanded
customExpandedViewContent: Component { QtObject {} }
onItemExpanded: customExpandedViewContent = model.isConnected ? currentConnectionDetails : detailsComponent

PlasmaComponents.ContextMenu {
id: itemContextMenu
function prepare() {} // Implementation required by PlasmaExtras.ExpandableListItem
customExpandedViewContent: model.isConnected ? currentConnectionDetails : detailsComponent

PlasmaComponents.Menu {
id: contextMenu
PlasmaComponents.MenuItem {
text: kickerI18n("Add to Favorites")
icon: Globals.Icons.pin
enabled: model.pinable
icon.name: Globals.Icons.pin
onClicked: addFavorite(getConnection())
}
}

MouseArea {
width: parent.width
height: parent.height
acceptedButtons: Qt.RightButton
onPressed: mouse => contextMenu?.popup(mouse.x, mouse.y)
}

Component {
id: detailsComponent
RowLayout {
PlasmaCore.IconItem {
Kirigami.Icon {
source: Globals.Icons.location
enabled: false
visible: citySelector.visible
}
ComboBox {
PlasmaComponents.ComboBox {
id: citySelector
Layout.fillWidth: true
enabled: !!model && model.length > 1
visible: !!connectionItemModel.connectionObject.country
visible: !!connectionItemModel.connectionObject?.country
onActivated: connectionObject.city = currentValue
Component.onCompleted: {
onVisibleChanged: {
if (!visible) return
nordvpn.getCities(connectionItemModel.connectionObject.country)
.then(c => {
Expand All @@ -57,15 +61,15 @@ PlasmaExtras.ExpandableListItem {
});
}
}
PlasmaCore.IconItem {
Kirigami.Icon {
source: Globals.Icons.vpn
enabled: false
visible: serverGroupSelector.visible
}

ComboBox {
PlasmaComponents.ComboBox {
id: serverGroupSelector
model: connectionItemModel.connectionObject.country ? functionalGroups : allGroups
model: connectionItemModel.connectionObject?.country ? functionalGroups : allGroups
currentIndex: model.length === 1 ? 0 : -1
Layout.fillWidth: true
onActivated: connectionObject.group = currentValue
Expand Down
19 changes: 10 additions & 9 deletions plasmoid/contents/ui/DetailsText.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import QtQuick 2.0
import QtQuick

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.components as PlasmaComponents

import org.kde.kirigami as Kirigami

Column {
property alias model: repeater.model
Expand All @@ -18,14 +19,14 @@ Column {
}
height: Math.max(detailNameLabel.height, detailValueLabel.height)

PlasmaComponents3.Label {
PlasmaComponents.Label {
id: detailNameLabel

anchors {
left: parent.left
leftMargin: repeater.longestString - paintedWidth + Math.round(PlasmaCore.Units.gridUnit / 2)
leftMargin: repeater.longestString - paintedWidth + Math.round(Kirigami.Units.gridUnit / 2)
}
font.pointSize: PlasmaCore.Theme.smallestFont.pointSize
font.pointSize: Kirigami.Theme.smallFont
horizontalAlignment: Text.AlignRight
text: modelData[0] + ": "
opacity: 0.6
Expand All @@ -37,16 +38,16 @@ Column {
}
}

PlasmaComponents3.Label {
PlasmaComponents.Label {
id: detailValueLabel

anchors {
left: parent.left
right: parent.right
leftMargin: repeater.longestString + Math.round(PlasmaCore.Units.gridUnit / 2)
leftMargin: repeater.longestString + Math.round(Kirigami.Units.gridUnit / 2)
}
elide: Text.ElideRight
font.pointSize: PlasmaCore.Theme.smallestFont.pointSize
font.pointSize: Kirigami.Theme.smallFont
text: modelData[1]
textFormat: Text.PlainText
}
Expand Down
8 changes: 4 additions & 4 deletions plasmoid/contents/ui/Exec.qml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import QtQuick 2.0
import QtQuick

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasma5support as P5Support

import "../code/polyfills.js" as Polyfills

PlasmaCore.DataSource {
P5Support.DataSource {
engine: "executable"

readonly property var callbacks: ({})

onNewData: {
onNewData: function (sourceName, data) {
const { stdout } = data
if (callbacks[sourceName] !== undefined) {
if (!data["exit code"]) {
Expand Down
28 changes: 12 additions & 16 deletions plasmoid/contents/ui/FavoriteItem.qml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.3
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls

import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.components as PlasmaComponents3

import org.kde.kirigami as Kirigami

PlasmaComponents3.ToolButton {
property var contextMenu
Expand All @@ -18,13 +19,13 @@ PlasmaComponents3.ToolButton {
}

contentItem: RowLayout {
PlasmaCore.IconItem {
Kirigami.Icon {
source: resolveIcon(model.icon)
implicitWidth: PlasmaCore.Units.iconSizes.medium
implicitHeight: PlasmaCore.Units.iconSizes.medium
implicitWidth: Kirigami.Units.iconSizes.medium
implicitHeight: Kirigami.Units.iconSizes.medium
enabled: !busy

PlasmaCore.IconItem {
Kirigami.Icon {
visible: !!model.indicator
source: resolveIcon(model.indicator)
width: parent.width / 2
Expand All @@ -49,7 +50,7 @@ PlasmaComponents3.ToolButton {
}
PlasmaComponents3.Label {
text: model.subtitle || ''
font.pointSize: PlasmaCore.Theme.smallestFont.pointSize
font.pointSize: Kirigami.Theme.smallFont
}
}
}
Expand All @@ -58,11 +59,6 @@ PlasmaComponents3.ToolButton {
width: parent.width
height: parent.height
acceptedButtons: Qt.RightButton

onPressed: {
if (contextMenu) {
contextMenu.open(mouse.x, mouse.y)
}
}
onPressed: mouse => contextMenu?.popup(mouse.x, mouse.y)
}
}
Loading

0 comments on commit f5c2fa0

Please sign in to comment.