@@ -14,89 +14,89 @@ static int oldLoopStatus = -1;
1414static int oldShuffleStatus = -1 ;
1515
1616static int onStart () {
17- oldLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , 0 );
18- oldShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
19- mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
17+ oldLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , 0 );
18+ oldShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
19+ mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
2020
2121#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 32 )
22- mprisThread = g_thread_create (startServer , (void * )& mprisData , TRUE, NULL );
22+ mprisThread = g_thread_create (startServer , (void * )& mprisData , TRUE, NULL );
2323#else
24- mprisThread = g_thread_new ("mpris-listener" , startServer , (void * )& mprisData );
24+ mprisThread = g_thread_new ("mpris-listener" , startServer , (void * )& mprisData );
2525#endif
26- return 0 ;
26+ return 0 ;
2727}
2828
2929static int onStop () {
30- stopServer ();
30+ stopServer ();
3131
3232#if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 32 )
33- g_thread_join (mprisThread );
33+ g_thread_join (mprisThread );
3434#else
35- g_thread_unref (mprisThread );
35+ g_thread_unref (mprisThread );
3636#endif
3737
38- if (mprisData .artworkData .artwork ) {
39- free (mprisData .artworkData .path );
40- free (mprisData .artworkData .default_path );
41- mprisData .artworkData .path = NULL ;
42- mprisData .artworkData .default_path = NULL ;
43- }
38+ if (mprisData .artworkData .artwork ) {
39+ free (mprisData .artworkData .path );
40+ free (mprisData .artworkData .default_path );
41+ mprisData .artworkData .path = NULL ;
42+ mprisData .artworkData .default_path = NULL ;
43+ }
4444
45- return 0 ;
45+ return 0 ;
4646}
4747
4848static int onDisconnect () {
49- if (mprisData .artworkData .artwork ) {
50- mprisData .artworkData .artwork -> cancel_queries_with_source_id (mprisData .artworkData .source_id );
51- }
49+ if (mprisData .artworkData .artwork ) {
50+ mprisData .artworkData .artwork -> cancel_queries_with_source_id (mprisData .artworkData .source_id );
51+ }
5252 return 0 ;
5353}
5454
5555static int onConnect () {
56- mprisData .prevOrRestart = NULL ;
57-
58- ddb_artwork_plugin_t * artworkPlugin = (ddb_artwork_plugin_t * )mprisData .deadbeef -> plug_get_for_id ("artwork2" );
59-
60- if (artworkPlugin != NULL ) {
61- debug ("artwork plugin detected... album art support enabled\n" );
62- if (artworkPlugin ) {
63- mprisData .artworkData .artwork = artworkPlugin ;
64- mprisData .artworkData .source_id = artworkPlugin -> allocate_source_id ();
65- mprisData .artworkData .path = NULL ;
66- mprisData .artworkData .default_path = malloc (PATH_MAX );
67- if (mprisData .artworkData .default_path ) {
68- strcpy (mprisData .artworkData .default_path ,"file://" );
69- size_t offset = strlen ("file://" );
70- artworkPlugin -> default_image_path (mprisData .artworkData .default_path + offset , PATH_MAX - offset );
71- }
72- }
73- } else {
74- debug ("artwork plugin not detected... album art support disabled\n" );
75- }
76-
77- DB_plugin_t * hotkeysPlugin = mprisData .deadbeef -> plug_get_for_id ( "hotkeys" );
78-
79- if (hotkeysPlugin != NULL ) {
80- debug ( "hotkeys plugin detected...\n" );
81-
82- DB_plugin_action_t * dbaction ;
83-
84- for ( dbaction = hotkeysPlugin -> get_actions ( NULL ); dbaction ; dbaction = dbaction -> next ) {
85- if ( strcmp ( dbaction -> name , "prev_or_restart" ) == 0 ) {
86- debug ( "prev_or_restart command detected... previous or restart support enabled\n" );
87- mprisData . prevOrRestart = dbaction ;
88- break ;
89- }
90- }
91-
92- if ( mprisData . prevOrRestart == NULL ) {
93- debug ( "prev_or_restart command not detected... previous or restart support disabled\n" );
94- }
95- } else {
96- debug ("hotkeys plugin not detected... previous or restart support disabled\n" );
97- }
98-
99- return 0 ;
56+ mprisData .prevOrRestart = NULL ;
57+
58+ ddb_artwork_plugin_t * artworkPlugin = (ddb_artwork_plugin_t * )mprisData .deadbeef -> plug_get_for_id ("artwork2" );
59+
60+ if (artworkPlugin != NULL ) {
61+ debug ("artwork plugin detected... album art support enabled\n" );
62+ if (artworkPlugin ) {
63+ mprisData .artworkData .artwork = artworkPlugin ;
64+ mprisData .artworkData .source_id = artworkPlugin -> allocate_source_id ();
65+ mprisData .artworkData .path = NULL ;
66+ mprisData .artworkData .default_path = malloc (PATH_MAX );
67+ if (mprisData .artworkData .default_path ) {
68+ strcpy (mprisData .artworkData .default_path ,"file://" );
69+ size_t offset = strlen ("file://" );
70+ artworkPlugin -> default_image_path (mprisData .artworkData .default_path + offset , PATH_MAX - offset );
71+ }
72+ }
73+ } else {
74+ debug ("artwork plugin not detected... album art support disabled\n" );
75+ }
76+
77+ DB_plugin_t * * plugins = mprisData .deadbeef -> plug_get_list ( );
78+ for ( int i = 0 ; plugins [ i ]; i ++ ) {
79+ if (plugins [ i ] -> get_actions != NULL ) {
80+ for ( DB_plugin_action_t * dbaction = plugins [ i ] -> get_actions ( NULL ); dbaction ; dbaction = dbaction -> next ) {
81+ if ( strcmp ( dbaction -> name , "prev_or_restart" ) == 0 ) {
82+ debug ( "prev_or_restart command detected... previous or restart support enabled\n" ) ;
83+ mprisData . prevOrRestart = dbaction ;
84+ break ;
85+ }
86+ }
87+
88+ if ( mprisData . prevOrRestart != NULL ) {
89+ break ;
90+ }
91+ }
92+ }
93+
94+
95+ if ( mprisData . prevOrRestart == NULL ) {
96+ debug ("prev_or_restart command not detected... previous or restart support disabled\n" );
97+ }
98+
99+ return 0 ;
100100}
101101
102102//***********************
@@ -109,117 +109,117 @@ static int onConnect() {
109109//* - Shuffle status *
110110//***********************
111111static int handleEvent (uint32_t id , uintptr_t ctx , uint32_t p1 , uint32_t p2 ) {
112- DB_functions_t * deadbeef = mprisData .deadbeef ;
113-
114- switch (id ) {
115- case DB_EV_SEEKED :
116- debug ("DB_EV_SEEKED event received\n" );
117- emitSeeked (((ddb_event_playpos_t * ) ctx )-> playpos );
118- break ;
119- case DB_EV_TRACKINFOCHANGED :
120- debug ("DB_EV_TRACKINFOCHANGED event received\n" );
121- emitMetadataChanged (-1 , & mprisData );
122- emitCanGoChanged (& mprisData );
123- emitSeeked (deadbeef -> streamer_get_playpos ());
124- break ;
125- case DB_EV_SELCHANGED :
126- case DB_EV_PLAYLISTSWITCHED :
127- emitCanGoChanged (& mprisData );
128- break ;
129- case DB_EV_SONGSTARTED :
130- debug ("DB_EV_SONGSTARTED event received\n" );
131- emitMetadataChanged (-1 , & mprisData );
132- emitPlaybackStatusChanged (OUTPUT_STATE_PLAYING , & mprisData );
133- break ;
134- case DB_EV_PAUSED :
135- debug ("DB_EV_PAUSED event received\n" );
136- emitPlaybackStatusChanged (p1 ? OUTPUT_STATE_PAUSED : OUTPUT_STATE_PLAYING , & mprisData );
137- break ;
138- case DB_EV_STOP :
139- debug ("DB_EV_STOP event received\n" );
140- emitPlaybackStatusChanged (OUTPUT_STATE_STOPPED , & mprisData );
141- break ;
142- case DB_EV_VOLUMECHANGED :
143- debug ("DB_EV_VOLUMECHANGED event received\n" );
144- emitVolumeChanged (deadbeef -> volume_get_db ());
145- break ;
146- case DB_EV_CONFIGCHANGED :
147- debug ("DB_EV_CONFIGCHANGED event received\n" );
148- if (oldShuffleStatus != -1 ) {
149- int newLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , PLAYBACK_MODE_LOOP_ALL );
150- int newShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
151-
152- if (newLoopStatus != oldLoopStatus ) {
153- debug ("LoopStatus changed %d\n" , newLoopStatus );
154- emitLoopStatusChanged (oldLoopStatus = newLoopStatus );
155- } if (newShuffleStatus != oldShuffleStatus ) {
156- debug ("ShuffleStatus changed %d\n" , newShuffleStatus );
157- emitShuffleStatusChanged (oldShuffleStatus = newShuffleStatus );
158- }
159-
160- mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
161- }
112+ DB_functions_t * deadbeef = mprisData .deadbeef ;
113+
114+ switch (id ) {
115+ case DB_EV_SEEKED :
116+ debug ("DB_EV_SEEKED event received\n" );
117+ emitSeeked (((ddb_event_playpos_t * ) ctx )-> playpos );
118+ break ;
119+ case DB_EV_TRACKINFOCHANGED :
120+ debug ("DB_EV_TRACKINFOCHANGED event received\n" );
121+ emitMetadataChanged (-1 , & mprisData );
122+ emitCanGoChanged (& mprisData );
123+ emitSeeked (deadbeef -> streamer_get_playpos ());
124+ break ;
125+ case DB_EV_SELCHANGED :
126+ case DB_EV_PLAYLISTSWITCHED :
127+ emitCanGoChanged (& mprisData );
128+ break ;
129+ case DB_EV_SONGSTARTED :
130+ debug ("DB_EV_SONGSTARTED event received\n" );
131+ emitMetadataChanged (-1 , & mprisData );
132+ emitPlaybackStatusChanged (OUTPUT_STATE_PLAYING , & mprisData );
133+ break ;
134+ case DB_EV_PAUSED :
135+ debug ("DB_EV_PAUSED event received\n" );
136+ emitPlaybackStatusChanged (p1 ? OUTPUT_STATE_PAUSED : OUTPUT_STATE_PLAYING , & mprisData );
137+ break ;
138+ case DB_EV_STOP :
139+ debug ("DB_EV_STOP event received\n" );
140+ emitPlaybackStatusChanged (OUTPUT_STATE_STOPPED , & mprisData );
141+ break ;
142+ case DB_EV_VOLUMECHANGED :
143+ debug ("DB_EV_VOLUMECHANGED event received\n" );
144+ emitVolumeChanged (deadbeef -> volume_get_db ());
145+ break ;
146+ case DB_EV_CONFIGCHANGED :
147+ debug ("DB_EV_CONFIGCHANGED event received\n" );
148+ if (oldShuffleStatus != -1 ) {
149+ int newLoopStatus = mprisData .deadbeef -> conf_get_int ("playback.loop" , PLAYBACK_MODE_LOOP_ALL );
150+ int newShuffleStatus = mprisData .deadbeef -> conf_get_int ("playback.order" , PLAYBACK_ORDER_LINEAR );
151+
152+ if (newLoopStatus != oldLoopStatus ) {
153+ debug ("LoopStatus changed %d\n" , newLoopStatus );
154+ emitLoopStatusChanged (oldLoopStatus = newLoopStatus );
155+ } if (newShuffleStatus != oldShuffleStatus ) {
156+ debug ("ShuffleStatus changed %d\n" , newShuffleStatus );
157+ emitShuffleStatusChanged (oldShuffleStatus = newShuffleStatus );
158+ }
159+
160+ mprisData .previousAction = mprisData .deadbeef -> conf_get_int (SETTING_PREVIOUS_ACTION , PREVIOUS_ACTION_PREV_OR_RESTART );
161+ }
162162 if (deadbeef -> conf_get_int ("mpris.trace" , 0 )) {
163163 plugin .plugin .flags |= DDB_PLUGIN_FLAG_LOGGING ;
164164 }
165165 else {
166166 plugin .plugin .flags &= ~DDB_PLUGIN_FLAG_LOGGING ;
167167 }
168- break ;
169- default :
170- break ;
171- }
168+ break ;
169+ default :
170+ break ;
171+ }
172172
173- return 0 ;
173+ return 0 ;
174174}
175175
176176#define STR (x ) #x
177177#define XSTR (x ) STR(x)
178178
179179static const char settings_dlg [] =
180- "property \"\\\"Previous\\\" action behavior\" select[2] " SETTING_PREVIOUS_ACTION " " XSTR (PREVIOUS_ACTION_PREV_OR_RESTART ) " \"Previous\" \"Previous or restart current track\";"
180+ "property \"\\\"Previous\\\" action behavior\" select[2] " SETTING_PREVIOUS_ACTION " " XSTR (PREVIOUS_ACTION_PREV_OR_RESTART ) " \"Previous\" \"Previous or restart current track\";"
181181 "property \"Enable logging\" checkbox mpris.trace 0;\n"
182182 "property \"Disable shuffle and repeat\" checkbox mpris.disable_shuffle_repeat 0;\n"
183183;
184184
185185
186186DB_misc_t plugin = {
187- .plugin .api_vmajor = 1 ,
188- .plugin .api_vminor = DDB_API_LEVEL ,
189- .plugin .type = DB_PLUGIN_MISC ,
190- .plugin .version_major = PLUGIN_VERSION_MAJOR ,
191- .plugin .version_minor = PLUGIN_VERSION_MINOR ,
192- .plugin .id = "mpris" ,
193- .plugin .name = "MPRISv2 plugin" ,
194- .plugin .descr = "Communicate with other applications using D-Bus." ,
195- .plugin .copyright =
196- "Copyright (C) 2014 Peter Lamby <[email protected] >\n" 197- "\n"
198- "This program is free software; you can redistribute it and/or\n"
199- "modify it under the terms of the GNU General Public License\n"
200- "as published by the Free Software Foundation; either version 2\n"
201- "of the License, or (at your option) any later version.\n"
202- "\n"
203- "This program is distributed in the hope that it will be useful,\n"
204- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
205- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
206- "GNU General Public License for more details.\n"
207- "\n"
208- "You should have received a copy of the GNU General Public License\n"
209- "along with this program; if not, write to the Free Software\n"
210- "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
211- ,
212- .plugin .website = "https://github.com/DeaDBeeF-Player/deadbeef-mpris2-plugin" ,
213- .plugin .start = onStart ,
214- .plugin .stop = onStop ,
215- .plugin .connect = onConnect ,
216- .plugin .disconnect = onDisconnect ,
217- .plugin .configdialog = settings_dlg ,
218- .plugin .message = handleEvent ,
187+ .plugin .api_vmajor = 1 ,
188+ .plugin .api_vminor = DDB_API_LEVEL ,
189+ .plugin .type = DB_PLUGIN_MISC ,
190+ .plugin .version_major = PLUGIN_VERSION_MAJOR ,
191+ .plugin .version_minor = PLUGIN_VERSION_MINOR ,
192+ .plugin .id = "mpris" ,
193+ .plugin .name = "MPRISv2 plugin" ,
194+ .plugin .descr = "Communicate with other applications using D-Bus." ,
195+ .plugin .copyright =
196+ "Copyright (C) 2014 Peter Lamby <[email protected] >\n" 197+ "\n"
198+ "This program is free software; you can redistribute it and/or\n"
199+ "modify it under the terms of the GNU General Public License\n"
200+ "as published by the Free Software Foundation; either version 2\n"
201+ "of the License, or (at your option) any later version.\n"
202+ "\n"
203+ "This program is distributed in the hope that it will be useful,\n"
204+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
205+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
206+ "GNU General Public License for more details.\n"
207+ "\n"
208+ "You should have received a copy of the GNU General Public License\n"
209+ "along with this program; if not, write to the Free Software\n"
210+ "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
211+ ,
212+ .plugin .website = "https://github.com/DeaDBeeF-Player/deadbeef-mpris2-plugin" ,
213+ .plugin .start = onStart ,
214+ .plugin .stop = onStop ,
215+ .plugin .connect = onConnect ,
216+ .plugin .disconnect = onDisconnect ,
217+ .plugin .configdialog = settings_dlg ,
218+ .plugin .message = handleEvent ,
219219};
220220
221221DB_plugin_t * mpris_load (DB_functions_t * ddb ) {
222- deadbeef = mprisData .deadbeef = ddb ;
222+ deadbeef = mprisData .deadbeef = ddb ;
223223
224- return DB_PLUGIN (& plugin );
224+ return DB_PLUGIN (& plugin );
225225}
0 commit comments