Skip to content

Commit

Permalink
Update to KF6
Browse files Browse the repository at this point in the history
KF5 will no longer be supported. To install on Plasma 5, use the commit
prior to this.

* KF6 API: https://develop.kde.org/docs/plasma/widget/porting_kf6
* Move the players from the fullRepresentation to the main item. This
  allows starting playback before the fullRepresentation is initialised,
  e.g. automatically at startup before the plasmoid is ever manually
  activated.
  • Loading branch information
m-pilia committed Mar 10, 2024
1 parent ccbe62f commit 243d642
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 173 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

set(QT_MIN_VERSION "5.3.0")
set(KF5_MIN_VERSION "5.0.0")
project(AmbientNoise)

find_package(ECM 0.0.11 REQUIRED NO_MODULE)
find_package(ECM 6.0.0 REQUIRED NO_MODULE)

set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})

include(KDEInstallDirs)
include(KDEInstallDirs6)
include(KDECMakeSettings)
include(KDECompilerSettings)

find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Quick)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma)
find_package(Qt6 6.5.0 CONFIG REQUIRED Quick Multimedia)
find_package(KF6 6.0.0 REQUIRED)
find_package(Plasma REQUIRED)

add_subdirectory(icons)
add_subdirectory(translations)
Expand Down
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ambient noise applet for Plasma 5
# Ambient noise applet for Plasma 6
[![Checks](https://github.com/m-pilia/plasma-applet-ambientnoise/workflows/Checks/badge.svg)](https://github.com/m-pilia/plasma-applet-ambientnoise/actions/workflows/checks.yml)


Expand All @@ -24,21 +24,22 @@ The applet can be installed locally with
```bash
git clone https://github.com/m-pilia/plasma-applet-ambientnoise
cd plasma-applet-ambientnoise/
kpackagetool5 -t Plasma/Applet --install plasmoid
kpackagetool6 -t Plasma/Applet --install plasmoid
```
or globally with
```bash
git clone https://github.com/m-pilia/plasma-applet-ambientnoise
cd plasma-applet-ambientnoise/
cmake . -DCMAKE_INSTALL_PREFIX=`kf5-config --prefix`
make
sudo make install
mkdir build
cmake . -B build
cmake --build build
sudo cmake --install build
```

To see the plasmoid, you may need to restart plasmashell
```bash
kquitapp5 plasmashell
kstart5 plasmashell
kquitapp6 plasmashell
kstart plasmashell
```

# Contribute
Expand Down Expand Up @@ -71,12 +72,7 @@ In case something seems not to be working, launch the plasmoid in debug mode
from a console, with `plasmoidviewer -a org.kde.plasma.ambientnoise` or
`plasmawindowed org.kde.plasma.ambientnoise`, and look for relevant log
messages. Especially when it comes to audio playback, most of the troubles come
from bad configuration of the multimedia back-end, or missing plugins.

If no audio is played, or the audio plays but the volume controls do not work,
or if you see messages like `Error: "The autoaudiosink element is missing."` or
`Warning: "No volume control found"`, try installing
[gst-plugins-good](https://gstreamer.freedesktop.org/modules/gst-plugins-good.html).
from bad configuration of the multimedia back-end.

# License
The project is licensed under GPL 3. See [LICENSE](./LICENSE)
Expand Down
6 changes: 3 additions & 3 deletions icons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
install( DIRECTORY breeze DESTINATION ${ICON_INSTALL_DIR})
install( DIRECTORY breeze-dark DESTINATION ${ICON_INSTALL_DIR})
install( DIRECTORY hicolor DESTINATION ${ICON_INSTALL_DIR})
install(DIRECTORY breeze DESTINATION ${KDE_INSTALL_ICONDIR})
install(DIRECTORY breeze-dark DESTINATION ${KDE_INSTALL_ICONDIR})
install(DIRECTORY hicolor DESTINATION ${KDE_INSTALL_ICONDIR})
4 changes: 2 additions & 2 deletions plasmoid/contents/config/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* along with Ambient Noise. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.2
import org.kde.plasma.configuration 2.0
import QtQuick
import org.kde.plasma.configuration

ConfigModel {
ConfigCategory {
Expand Down
27 changes: 10 additions & 17 deletions plasmoid/contents/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ function toImageName(filename) {
*/
function dataDirectory() {
var dir = plasmoid.configuration.noiseDataDirectory;
return dir.trim().replace(/\/*$/, "") + "/";
return "file://" + dir.trim().replace(/\/*$/, "") + "/";
}

/*!
* Compute the volume of an audio stream, given its volume.
* Multiply it by the global volume, and apply nonlinear scaling.
*/
function computeVolume(componentVolume) {
var volume = componentVolume * plasmoid.configuration.globalVolume;
volume /= main.maxVolume * main.maxVolume;
return QtMultimedia.convertVolume(volume,
QtMultimedia.LogarithmicVolumeScale,
QtMultimedia.LinearVolumeScale);
const volume = (componentVolume * plasmoid.configuration.globalVolume) / (main.maxVolume ** 2);
return (volume > 0.99) ? 1.0 : -Math.log(1.0 - volume) / Math.log(100.0);
}

/*!
Expand Down Expand Up @@ -133,15 +130,11 @@ function saveComponents() {
* Restore noise components from settings.
*/
function restoreComponents() {
deserialiseDataModel(plasmoid.configuration.noiseComponents, noiseComponentsModel);
}

/*!
* Set the playpause action in the context menu.
*/
function setPlayPauseAction() {
var text = main.playing ? i18n("Pause") : i18n("Play");
var icon = "media-playback-" + (main.playing ? "pause" : "start");
plasmoid.removeAction("playpause");
plasmoid.setAction("playpause", text, icon);
try {
deserialiseDataModel(plasmoid.configuration.noiseComponents, noiseComponentsModel);
}
catch (e) {
console.log(e);
plasmoid.configuration.noiseComponents = "[]";
}
}
65 changes: 37 additions & 28 deletions plasmoid/contents/ui/AddNoisePopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
* along with Ambient Noise. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
import QtQuick.Window 2.0
import Qt.labs.folderlistmodel 1.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.plasmoid 2.0
import Qt.labs.folderlistmodel
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window

import org.kde.kirigami as Kirigami
import org.kde.plasma.components as PlasmaComponents
import org.kde.plasma.extras as PlasmaExtras
import org.kde.plasma.plasmoid

import "../js/scripts.js" as Js

ScrollView {
ListView {
header: PlasmaComponents.ToolButton {
iconName: "draw-arrow-back"
icon.name: "draw-arrow-back"
Layout.alignment: Qt.AlignVCenter
onClicked: {
stack.pop();
Expand All @@ -42,28 +46,15 @@ ScrollView {
showDirs: false
}

delegate: PlasmaComponents.ListItem {
separatorVisible: true

RowLayout {

Image {
source: Js.toImageName(fileName)
fillMode: Image.PreserveAspectFit
Layout.preferredHeight: units.iconSizes.medium
Layout.preferredWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignVCenter
}

PlasmaComponents.Label {
id: fileText
text: Js.toPrettyName(fileName)
Layout.alignment: Qt.AlignVCenter
}
}
delegate: PlasmaExtras.ListItem {
width: row_layout.width
height: row_layout.height
separatorVisible: false

MouseArea {
anchors.fill: parent
width: childrenRect.width
height: childrenRect.height
acceptedButtons: Qt.LeftButton

onClicked: {
noiseComponentsModel.append({
Expand All @@ -76,6 +67,24 @@ ScrollView {
}
stack.pop();
}

RowLayout {
id: row_layout

Image {
source: Js.toImageName(fileName)
fillMode: Image.PreserveAspectFit
Layout.preferredHeight: Kirigami.Units.iconSizes.medium
Layout.preferredWidth: Kirigami.Units.iconSizes.medium
Layout.alignment: Qt.AlignVCenter
}

PlasmaComponents.Label {
id: fileText
text: Js.toPrettyName(fileName)
Layout.alignment: Qt.AlignVCenter
}
}
}
}
}
Expand Down
48 changes: 17 additions & 31 deletions plasmoid/contents/ui/NoiseListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,33 @@
* along with Ambient Noise. If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 1.4
import QtMultimedia 5.7
import org.kde.plasma.components 2.0 as PlasmaComponents
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import org.kde.kirigami as Kirigami
import org.kde.plasma.components as PlasmaComponents
import org.kde.plasma.extras as PlasmaExtras

import "../js/scripts.js" as Js

PlasmaComponents.ListItem {
PlasmaExtras.ListItem {
id: root
width: .95 * noiseComponents.width
height: units.gridUnit * 4
separatorVisible: true
height: Kirigami.Units.gridUnit * 4
separatorVisible: false

property alias noiseName: name.text
property alias audioSource: player.source
property alias imageSource: componentIcon.source
property alias volume: slider.value
property bool muted: false
property bool playing: false

onPlayingChanged: {
if (playing) {
player.play();
} else {
player.pause();
}
}

Component.onCompleted: Js.saveComponents()

RowLayout {
id: componentLine
width: root.width
spacing: units.smallSpacing
spacing: Kirigami.Units.smallSpacing

// Image for the noise component
Image {
Expand All @@ -73,13 +66,13 @@ PlasmaComponents.ListItem {
RowLayout {
id: controlsRow
width: leftColumn.width
spacing: units.smallSpacing
spacing: Kirigami.Units.smallSpacing
Layout.alignment: Qt.AlignCenter

// Delete component
PlasmaComponents.ToolButton {
id: deleteButton
iconName: "edit-delete"
icon.name: "edit-delete"
Layout.alignment: Qt.AlignVCenter
onClicked: {
noiseComponentsModel.remove(index);
Expand All @@ -90,7 +83,7 @@ PlasmaComponents.ListItem {
// Mute component
PlasmaComponents.ToolButton {
id: muteButton
iconName: Js.volumeIcon(slider.value, muted)
icon.name: Js.volumeIcon(slider.value, muted)
Layout.alignment: Qt.AlignVCenter
onClicked: {
muted = !muted;
Expand All @@ -104,8 +97,8 @@ PlasmaComponents.ListItem {
id: slider
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
maximumValue: main.maxVolume
minimumValue: main.minVolume
from: main.minVolume
to: main.maxVolume
stepSize: main.volumeStep
enabled: !muted
opacity: muted ? 0.5 : 1.0
Expand All @@ -125,11 +118,4 @@ PlasmaComponents.ListItem {
}
}
}

Audio {
id: player
loops: Audio.Infinite
volume: Js.computeVolume(slider.value * slider.enabled)
autoPlay: root.playing
}
}
Loading

0 comments on commit 243d642

Please sign in to comment.