Merge lp:~hakermania/synapse-project/synapse-project into lp:synapse-project

Proposed by Alex Solanos on 2016-08-22
Status: Needs review
Proposed branch: lp:~hakermania/synapse-project/synapse-project
Merge into: lp:synapse-project
Diff against target: 236 lines (+210/-0)
3 files modified
src/plugins/Makefile.am (+1/-0)
src/plugins/audacious-plugin.vala (+208/-0)
src/ui/synapse-main.vala (+1/-0)
To merge this branch: bzr merge lp:~hakermania/synapse-project/synapse-project
Reviewer Review Type Date Requested Status
Synapse core team 2016-08-22 Pending
Review via email: mp+303526@code.launchpad.net

Description of the change

Just added an audacious plugin (MPRIS2 compatibility).

The plugin will be useful for any other MPRIS2-compatible player.

To post a comment you must log in.

Unmerged revisions

652. By Alex Solanos <email address hidden> on 2016-08-22

Add audacious plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugins/Makefile.am'
2--- src/plugins/Makefile.am 2016-04-01 05:58:51 +0000
3+++ src/plugins/Makefile.am 2016-08-22 08:58:23 +0000
4@@ -54,6 +54,7 @@
5 xnoise-media-player-plugin.vala \
6 system-management.vala \
7 zeal-plugin.vala \
8+ audacious-plugin.vala \
9 $(NULL)
10
11 if HAVE_ZEITGEIST
12
13=== added file 'src/plugins/audacious-plugin.vala'
14--- src/plugins/audacious-plugin.vala 1970-01-01 00:00:00 +0000
15+++ src/plugins/audacious-plugin.vala 2016-08-22 08:58:23 +0000
16@@ -0,0 +1,208 @@
17+/*
18+ * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
19+ *
20+ * This program is free software; you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License as published by
22+ * the Free Software Foundation; either version 2 of the License, or
23+ * (at your option) any later version.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU General Public License
31+ * along with this program; if not, write to the Free Software
32+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33+ *
34+ * Authored by Solanos Alex <solanosalex@gmail.com>
35+ *
36+ */
37+
38+namespace Synapse
39+{
40+ [DBus (name = "org.mpris.MediaPlayer2.Player")]
41+ interface AudaciousPlayerEngine : Object {
42+ public const string UNIQUE_NAME = "org.mpris.MediaPlayer2.audacious";
43+ public const string OBJECT_PATH = "/org/mpris/MediaPlayer2";
44+
45+ public abstract void play () throws IOError;
46+ public abstract void pause () throws IOError;
47+ public abstract void next () throws IOError;
48+ public abstract void previous () throws IOError;
49+ }
50+
51+ public class AudaciousActions : Object, Activatable, ItemProvider
52+ {
53+ public bool enabled { get; set; default = true; }
54+
55+ public void activate ()
56+ {
57+
58+ }
59+
60+ public void deactivate ()
61+ {
62+
63+ }
64+
65+ static void register_plugin ()
66+ {
67+ PluginRegistry.get_default ().register_plugin (
68+ typeof (AudaciousActions),
69+ "Audacious",
70+ _("Control Audacious"),
71+ "audacious",
72+ register_plugin,
73+ Environment.find_program_in_path ("audacious") != null,
74+ _("Audacious is not installed")
75+ );
76+ }
77+
78+ static construct
79+ {
80+ register_plugin ();
81+ }
82+
83+ private abstract class AudaciousControlMatch : ActionMatch
84+ {
85+ public virtual bool action_available ()
86+ {
87+ return DBusService.get_default ().name_has_owner (
88+ AudaciousPlayerEngine.UNIQUE_NAME);
89+ }
90+ }
91+
92+ /* MATCHES of Type.ACTION */
93+ private class Play : AudaciousControlMatch
94+ {
95+ public Play ()
96+ {
97+ Object (title: _("Play"),
98+ description: _("Start playback in Audacious"),
99+ icon_name: "media-playback-start", has_thumbnail: false);
100+ }
101+
102+ public override void do_action ()
103+ {
104+ try {
105+ AudaciousPlayerEngine player = Bus.get_proxy_sync (BusType.SESSION,
106+ AudaciousPlayerEngine.UNIQUE_NAME,
107+ AudaciousPlayerEngine.OBJECT_PATH);
108+
109+ player.play ();
110+ } catch (IOError e) {
111+ stderr.printf ("Audacious is not available.\n%s", e.message);
112+ }
113+ }
114+
115+ public override bool action_available ()
116+ {
117+ return true;
118+ }
119+ }
120+ private class Pause : AudaciousControlMatch
121+ {
122+ public Pause ()
123+ {
124+ Object (title: _("Pause"),
125+ description: _("Pause playback in Audacious"),
126+ icon_name: "media-playback-pause", has_thumbnail: false);
127+ }
128+ public override void do_action ()
129+ {
130+ try {
131+ AudaciousPlayerEngine player = Bus.get_proxy_sync (BusType.SESSION,
132+ AudaciousPlayerEngine.UNIQUE_NAME,
133+ AudaciousPlayerEngine.OBJECT_PATH);
134+ player.pause ();
135+ } catch (IOError e) {
136+ stderr.printf ("Audacious is not available.\n%s", e.message);
137+ }
138+ }
139+ }
140+ private class Next : AudaciousControlMatch
141+ {
142+ public Next ()
143+ {
144+ Object (title: _("Next"),
145+ description: _("Plays the next song in Audacious's playlist"),
146+ icon_name: "media-skip-forward", has_thumbnail: false);
147+ }
148+
149+ public override void do_action ()
150+ {
151+ try {
152+ AudaciousPlayerEngine player = Bus.get_proxy_sync (BusType.SESSION,
153+ AudaciousPlayerEngine.UNIQUE_NAME,
154+ AudaciousPlayerEngine.OBJECT_PATH);
155+
156+ player.next ();
157+ } catch (IOError e) {
158+ stderr.printf ("Audacious is not available.\n%s", e.message);
159+ }
160+ }
161+ }
162+ private class Previous : AudaciousControlMatch
163+ {
164+ public Previous ()
165+ {
166+ Object (title: _("Previous"),
167+ description: _("Plays the previous song in Audacious's playlist"),
168+ icon_name: "media-skip-backward", has_thumbnail: false);
169+ }
170+
171+ public override void do_action ()
172+ {
173+ try {
174+ AudaciousPlayerEngine player = Bus.get_proxy_sync (BusType.SESSION,
175+ AudaciousPlayerEngine.UNIQUE_NAME,
176+ AudaciousPlayerEngine.OBJECT_PATH);
177+ player.previous ();
178+ } catch (IOError e) {
179+ stderr.printf ("Audacious is not available.\n%s", e.message);
180+ }
181+ }
182+ }
183+
184+ private Gee.List<AudaciousControlMatch> matches;
185+
186+ construct
187+ {
188+ matches = new Gee.ArrayList<AudaciousControlMatch> ();
189+
190+ matches.add (new Play ());
191+ matches.add (new Pause ());
192+ matches.add (new Previous ());
193+ matches.add (new Next ());
194+ }
195+
196+ public async ResultSet? search (Query q) throws SearchError
197+ {
198+ // we only search for actions
199+ if (!(QueryFlags.ACTIONS in q.query_type)) return null;
200+
201+ var result = new ResultSet ();
202+
203+ var matchers = Query.get_matchers_for_query (q.query_string, 0,
204+ RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS);
205+
206+ foreach (var action in matches)
207+ {
208+ if (!action.action_available ()) continue;
209+ foreach (var matcher in matchers)
210+ {
211+ if (matcher.key.match (action.title))
212+ {
213+ result.add (action, matcher.value - MatchScore.INCREMENT_SMALL);
214+ break;
215+ }
216+ }
217+ }
218+
219+ q.check_cancellable ();
220+
221+ return result;
222+ }
223+ }
224+}
225
226=== modified file 'src/ui/synapse-main.vala'
227--- src/ui/synapse-main.vala 2016-04-01 05:58:51 +0000
228+++ src/ui/synapse-main.vala 2016-08-22 08:58:23 +0000
229@@ -165,6 +165,7 @@
230 typeof (CommandPlugin),
231 typeof (RhythmboxActions),
232 typeof (BansheeActions),
233+ typeof (AudaciousActions),
234 typeof (DirectoryPlugin),
235 typeof (LaunchpadPlugin),
236 typeof (CalculatorPlugin),