Skip to content

Commit

Permalink
refactor: copy InhibitionHint from battery applet
Browse files Browse the repository at this point in the history
  • Loading branch information
romangg committed Feb 26, 2024
1 parent d10f040 commit 657eaa6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 35 deletions.
37 changes: 37 additions & 0 deletions plasma-integration/plasmoid/package/contents/ui/InhibitionHint.qml
@@ -0,0 +1,37 @@
/*
SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-License-Identifier: LGPL-2.0-or-later
*/

import QtQuick 2.15
import QtQuick.Layouts 1.15

import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kirigami 2.20 as Kirigami

// everything like in battery applet, but slightly bigger
RowLayout {
property alias iconSource: iconItem.source
property alias text: label.text

spacing: Kirigami.Units.smallSpacing * 2

Kirigami.Icon {
id: iconItem
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
visible: valid
}

PlasmaComponents3.Label {
id: label
Layout.fillWidth: true
Layout.maximumWidth: Math.min(Kirigami.Units.gridUnit * 20, implicitWidth)
font: Kirigami.Theme.smallFont
textFormat: Text.PlainText
wrapMode: Text.WordWrap
elide: Text.ElideRight
maximumLineCount: 4
}
}
Expand Up @@ -79,43 +79,29 @@ ColumnLayout {
wrapMode: Text.WordWrap
}

RowLayout {
InhibitionHint {
Layout.fillWidth: true
Layout.leftMargin: presentationModeSwitch.indicator.width + presentationModeSwitch.spacing
spacing: Kirigami.Units.smallSpacing

PlasmaCore.IconItem {
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
source: pmSource.inhibitions[0] ? pmSource.inhibitions[0].Icon || "" : ""
visible: valid
}

PlasmaComponents3.Label {
Layout.fillWidth: true
Layout.maximumWidth: Math.min(Kirigami.Units.gridUnit * 20, implicitWidth)
font.pointSize: theme.smallestFont.pointSize
wrapMode: Text.WordWrap
elide: Text.ElideRight
textFormat: Text.PlainText
text: {
var inhibitions = pmSource.inhibitions;
if (inhibitions.length > 1) {
return i18ncp("Some Application and n others enforce presentation mode",
"%2 and %1 other application are enforcing presentation mode.",
"%2 and %1 other applications are enforcing presentation mode.",
inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1
} else if (inhibitions.length === 1) {
if (!inhibitions[0].Reason) {
return i18nc("Some Application enforce presentation mode",
"%1 is enforcing presentation mode.", inhibitions[0].Name)
} else {
return i18nc("Some Application enforce presentation mode: Reason provided by the app",
"%1 is enforcing presentation mode: %2", inhibitions[0].Name, inhibitions[0].Reason)
}
iconSource: pmSource.inhibitions.length > 0 ? pmSource.inhibitions[0].Icon || "" : ""
text: {
const inhibitions = pmSource.inhibitions;
const inhibition = inhibitions[0];
if (inhibitions.length > 1) {
return i18ncp("Some Application and n others enforce presentation mode",
"%2 and %1 other application are enforcing presentation mode.",
"%2 and %1 other applications are enforcing presentation mode.",
inhibitions.length - 1, inhibition.Name) // plural only works on %1
} else if (inhibitions.length === 1) {
if (!inhibition.Reason) {
return i18nc("Some Application enforce presentation mode",
"%1 is enforcing presentation mode.", inhibition.Name)
} else {
return "";
return i18nc("Some Application enforce presentation mode: Reason provided by the app",
"%1 is enforcing presentation mode: %2", inhibition.Name, inhibition.Reason)
}
} else {
return "";
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions plasma-integration/po/plasma_applet_org.kwinft.kdisplay.pot
Expand Up @@ -69,21 +69,21 @@ msgid ""
"This will prevent your display and computer from turning off automatically."
msgstr ""

#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:105
#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:92
#, kde-format
msgctxt "Some Application and n others enforce presentation mode"
msgid "%2 and %1 other application are enforcing presentation mode."
msgid_plural "%2 and %1 other applications are enforcing presentation mode."
msgstr[0] ""
msgstr[1] ""

#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:111
#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:98
#, kde-format
msgctxt "Some Application enforce presentation mode"
msgid "%1 is enforcing presentation mode."
msgstr ""

#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:114
#: plasma-integration/plasmoid/package/contents/ui/PresentationModeItem.qml:101
#, kde-format
msgctxt ""
"Some Application enforce presentation mode: Reason provided by the app"
Expand Down

0 comments on commit 657eaa6

Please sign in to comment.