Changeset View
Standalone View
applets/mediacontroller/contents/ui/main.qml
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 28 | Item { | |||
---|---|---|---|---|---|
61 | readonly property bool canPause: canControl && mpris2Source.currentData.CanPause | 61 | readonly property bool canPause: canControl && mpris2Source.currentData.CanPause | ||
62 | 62 | | |||
63 | Plasmoid.switchWidth: units.gridUnit * 14 | 63 | Plasmoid.switchWidth: units.gridUnit * 14 | ||
64 | Plasmoid.switchHeight: units.gridUnit * 10 | 64 | Plasmoid.switchHeight: units.gridUnit * 10 | ||
65 | Plasmoid.icon: albumArt ? albumArt : "media-playback-start" | 65 | Plasmoid.icon: albumArt ? albumArt : "media-playback-start" | ||
66 | Plasmoid.toolTipMainText: i18n("No media playing") | 66 | Plasmoid.toolTipMainText: i18n("No media playing") | ||
67 | Plasmoid.toolTipSubText: "" | 67 | Plasmoid.toolTipSubText: "" | ||
68 | Plasmoid.toolTipTextFormat: Text.PlainText | 68 | Plasmoid.toolTipTextFormat: Text.PlainText | ||
69 | Plasmoid.status: PlasmaCore.Types.ActiveStatus | 69 | Plasmoid.status: PlasmaCore.Types.PassiveStatus | ||
70 | 70 | | |||
71 | Plasmoid.onContextualActionsAboutToShow: { | 71 | Plasmoid.onContextualActionsAboutToShow: { | ||
72 | plasmoid.clearActions() | 72 | plasmoid.clearActions() | ||
73 | 73 | | |||
74 | if (root.noPlayer) { | 74 | if (root.noPlayer) { | ||
75 | return | 75 | return | ||
76 | } | 76 | } | ||
77 | 77 | | |||
78 | if (mpris2Source.currentData.CanRaise) { | 78 | if (mpris2Source.currentData.CanRaise) { | ||
79 | var icon = mpris2Source.currentData["Desktop Icon Name"] || "" | 79 | var icon = mpris2Source.currentData["Desktop Icon Name"] || "" | ||
80 | plasmoid.setAction("open", i18nc("Open player window or bring it to the front if already open", "Open"), icon) | 80 | plasmoid.setAction("open", i18nc("Open player window or bring it to the front if already open", "Open"), icon) | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | if (canControl) { | 83 | if (canControl) { | ||
84 | plasmoid.setAction("previous", i18nc("Play previous track", "Previous Track"), | 84 | plasmoid.setAction("previous", i18nc("Play previous track", "Previous Track"), | ||
85 | Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-forward" : "media-skip-backward"); | 85 | Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-forward" : "media-skip-backward"); | ||
86 | plasmoid.action("previous").enabled = Qt.binding(function() { | 86 | plasmoid.action("previous").enabled = Qt.binding(function() { | ||
87 | return root.canGoPrevious | 87 | return root.canGoPrevious | ||
88 | }) | 88 | }) | ||
89 | 89 | | |||
90 | if (root.state == "playing") { | 90 | if (root.state == "playing") { | ||
91 | plasmoid.setAction("playPause", i18nc("Pause playback", "Pause"), "media-playback-pause") | 91 | if (canPause) { | ||
broulik: Shouldn't that be a binding? If the player cannot pause, the entry would just not show up… | |||||
Not sure myself (but the doubled canPause looks strange on second read). In the context menu of the taskmanager all media actions are kept and only disabled if not possible, with play/pause action though being same and switching label for canPause. So no menu entry for Play if playing and !canPause? Instead of disabled menu entry? kossebau: Not sure myself (but the doubled canPause looks strange on second read).
In the context menu… | |||||
92 | plasmoid.action("playPause").enabled = Qt.binding(function() { | 92 | plasmoid.setAction("pause", i18nc("Pause playback", "Pause"), "media-playback-pause") | ||
93 | plasmoid.action("pause").enabled = Qt.binding(function() { | ||||
93 | return root.canPause; | 94 | return root.canPause; | ||
94 | }); | 95 | }); | ||
96 | } | ||||
95 | } else { | 97 | } else { | ||
96 | plasmoid.setAction("playPause", i18nc("Start playback", "Play"), "media-playback-start") | 98 | plasmoid.setAction("play", i18nc("Start playback", "Play"), "media-playback-start") | ||
97 | plasmoid.action("playPause").enabled = Qt.binding(function() { | 99 | plasmoid.action("play").enabled = Qt.binding(function() { | ||
98 | return root.canPlay; | 100 | return root.canPlay; | ||
99 | }); | 101 | }); | ||
100 | } | 102 | } | ||
101 | 103 | | |||
102 | plasmoid.setAction("next", i18nc("Play next track", "Next Track"), | 104 | plasmoid.setAction("next", i18nc("Play next track", "Next Track"), | ||
103 | Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-backward" : "media-skip-forward") | 105 | Qt.application.layoutDirection === Qt.RightToLeft ? "media-skip-backward" : "media-skip-forward") | ||
104 | plasmoid.action("next").enabled = Qt.binding(function() { | 106 | plasmoid.action("next").enabled = Qt.binding(function() { | ||
105 | return root.canGoNext | 107 | return root.canGoNext | ||
106 | }) | 108 | }) | ||
107 | 109 | | |||
108 | plasmoid.setAction("stop", i18nc("Stop playback", "Stop"), "media-playback-stop") | 110 | plasmoid.setAction("stop", i18nc("Stop playback", "Stop"), "media-playback-stop") | ||
111 | plasmoid.action("stop").enabled = Qt.binding(function() { | ||||
112 | return root.state === "playing" || root.state === "paused"; | ||||
113 | }) | ||||
109 | } | 114 | } | ||
110 | 115 | | |||
111 | if (mpris2Source.currentData.CanQuit) { | 116 | if (mpris2Source.currentData.CanQuit) { | ||
112 | plasmoid.setActionSeparator("quitseparator"); | 117 | plasmoid.setActionSeparator("quitseparator"); | ||
113 | plasmoid.setAction("quit", i18nc("Quit player", "Quit"), "application-exit") | 118 | plasmoid.setAction("quit", i18nc("Quit player", "Quit"), "application-exit") | ||
114 | } | 119 | } | ||
115 | } | 120 | } | ||
116 | 121 | | |||
Show All 17 Lines | 138 | } else { | |||
134 | plasmoid.status = PlasmaCore.Types.PassiveStatus | 139 | plasmoid.status = PlasmaCore.Types.PassiveStatus | ||
135 | } | 140 | } | ||
136 | } | 141 | } | ||
137 | } | 142 | } | ||
138 | 143 | | |||
139 | Plasmoid.fullRepresentation: ExpandedRepresentation {} | 144 | Plasmoid.fullRepresentation: ExpandedRepresentation {} | ||
140 | 145 | | |||
141 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | 146 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | ||
142 | source: root.state === "playing" ? "media-playback-start" : "media-playback-pause" | 147 | source: root.state === "playing" ? "media-playback-start" : | ||
148 | root.state === "paused" ? "media-playback-pause" : | ||||
149 | "media-playback-stop" | ||||
broulik: Not a huge fan of that stopped icon in the panel | |||||
The icon will not be visible in the system tray, as it's only used when neither playing or paused, and then the status is passive, so hidden in system tray. Showing the stopped icon on the compact version of the applet in general makes sense for me, to really show it's in a different state. kossebau: The icon will not be visible in the system tray, as it's only used when neither playing or… | |||||
143 | active: compactMouse.containsMouse | 150 | active: compactMouse.containsMouse | ||
144 | 151 | | |||
145 | MouseArea { | 152 | MouseArea { | ||
146 | id: compactMouse | 153 | id: compactMouse | ||
147 | anchors.fill: parent | 154 | anchors.fill: parent | ||
148 | hoverEnabled: true | 155 | hoverEnabled: true | ||
149 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.BackButton | Qt.ForwardButton | 156 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.BackButton | Qt.ForwardButton | ||
150 | onClicked: { | 157 | onClicked: { | ||
151 | switch (mouse.button) { | 158 | switch (mouse.button) { | ||
152 | case Qt.MiddleButton: | 159 | case Qt.MiddleButton: | ||
153 | root.action_playPause() | 160 | root.togglePlaying() | ||
154 | break | 161 | break | ||
155 | case Qt.BackButton: | 162 | case Qt.BackButton: | ||
156 | root.action_previous() | 163 | root.action_previous() | ||
157 | break | 164 | break | ||
158 | case Qt.ForwardButton: | 165 | case Qt.ForwardButton: | ||
159 | root.action_next() | 166 | root.action_next() | ||
160 | break | 167 | break | ||
161 | default: | 168 | default: | ||
Show All 21 Lines | 186 | onSourceRemoved: { | |||
183 | } | 190 | } | ||
184 | } | 191 | } | ||
185 | } | 192 | } | ||
186 | 193 | | |||
187 | Component.onCompleted: { | 194 | Component.onCompleted: { | ||
188 | mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts(); | 195 | mpris2Source.serviceForSource("@multiplex").enableGlobalShortcuts(); | ||
189 | } | 196 | } | ||
190 | 197 | | |||
198 | function togglePlaying() { | ||||
199 | if (root.state === "playing") { | ||||
Please don't mix manual toggling and playPause, just do it manually then, otherwise the code becomes a bit convoluted broulik: Please don't mix manual toggling and playPause, just do it manually then, otherwise the code… | |||||
200 | if (root.canPause) { | ||||
201 | root.action_pause(); | ||||
202 | } | ||||
203 | } else { | ||||
204 | if (root.canPlay) { | ||||
205 | root.action_play(); | ||||
206 | } | ||||
207 | } | ||||
208 | } | ||||
209 | | ||||
191 | function action_open() { | 210 | function action_open() { | ||
192 | serviceOp(mpris2Source.current, "Raise"); | 211 | serviceOp(mpris2Source.current, "Raise"); | ||
193 | } | 212 | } | ||
194 | function action_quit() { | 213 | function action_quit() { | ||
195 | serviceOp(mpris2Source.current, "Quit"); | 214 | serviceOp(mpris2Source.current, "Quit"); | ||
196 | } | 215 | } | ||
197 | 216 | | |||
198 | function action_play() { | 217 | function action_play() { | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |
Shouldn't that be a binding? If the player cannot pause, the entry would just not show up rather than become disabled, ie. keep the action as "playPause" maybe?