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

Proposed by Alex Solanos
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 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>

Add audacious plugin

Preview Diff

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