1 /* gmpc-awn (GMPC plugin)
2 * Copyright (C) 2007-2009 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpc.wikia.com/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <glib/gi18n-lib.h>
29 #include <gmpc/plugin.h>
30 #include <gmpc/metadata.h>
31 #include <gmpc/misc.h>
32 #include <dbus/dbus-glib.h>
33 #include <dbus/dbus-glib-bindings.h>
35 static void awn_update_cover(GmpcMetaWatcher
*gmv
, mpd_Song
*song
, MetaDataType type
, MetaDataResult ret
, MetaData
*met
);
36 static int awn_get_enabled(void)
38 return cfg_get_single_value_as_int_with_default(config
, "awn-plugin", "enable", TRUE
);
40 static void awn_set_enabled(int enabled
)
42 cfg_set_single_value_as_int(config
, "awn-plugin", "enable", enabled
);
45 /* from gseal-transition.h */
47 #define gtk_widget_get_window(x) (x)->window
50 static XID
get_main_window_xid() {
51 GtkWidget
* window
= NULL
;
53 window
= playlist3_get_window();
55 if (!window
|| playlist3_window_is_hidden()) {
59 return GDK_WINDOW_XID(gtk_widget_get_window(window
));
62 static void setAwnIcon(const char *filename
) {
64 DBusGConnection
*connection
;
68 xid
= get_main_window_xid();
75 connection
= dbus_g_bus_get(DBUS_BUS_SESSION
, &error
);
77 if (connection
!= NULL
)
79 proxy
= dbus_g_proxy_new_for_name(
81 "com.google.code.Awn",
82 "/com/google/code/Awn",
83 "com.google.code.Awn");
85 dbus_g_proxy_call(proxy
, "SetTaskIconByXid", &error
, G_TYPE_INT64
,
86 (gint64
)xid
, G_TYPE_STRING
, filename
, G_TYPE_INVALID
);
90 static void unsetAwnIcon() {
92 DBusGConnection
*connection
;
96 xid
= get_main_window_xid();
103 connection
= dbus_g_bus_get(DBUS_BUS_SESSION
, &error
);
105 if (connection
!= NULL
)
107 proxy
= dbus_g_proxy_new_for_name(
109 "com.google.code.Awn",
110 "/com/google/code/Awn",
111 "com.google.code.Awn");
113 dbus_g_proxy_call(proxy
, "UnsetTaskIconByXid", &error
,
114 G_TYPE_INT64
, (gint64
)xid
, G_TYPE_INVALID
);
117 static void setAwnProgress(int progress
) {
119 DBusGConnection
*connection
;
123 xid
= get_main_window_xid();
130 connection
= dbus_g_bus_get(DBUS_BUS_SESSION
, &error
);
132 if (connection
!= NULL
)
134 proxy
= dbus_g_proxy_new_for_name(
136 "com.google.code.Awn",
137 "/com/google/code/Awn",
138 "com.google.code.Awn");
140 dbus_g_proxy_call(proxy
, "SetProgressByXid", &error
,G_TYPE_INT64
, (gint64
)xid
,
141 G_TYPE_INT
, progress
, G_TYPE_INVALID
);
147 static void awn_plugin_destroy(void)
153 static void awn_plugin_init(void)
155 bindtextdomain(GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
156 bind_textdomain_codeset(GETTEXT_PACKAGE
, "UTF-8");
157 g_signal_connect(G_OBJECT(gmw
), "data-changed", G_CALLBACK(awn_update_cover
), NULL
);
160 static void awn_update_cover(GmpcMetaWatcher
*gmv
, mpd_Song
*song
, MetaDataType type
, MetaDataResult ret
, MetaData
*met
)
163 if(!awn_get_enabled())
166 song2
= mpd_playlist_get_current_song(connection
);
169 if(!song2
|| type
!= META_ALBUM_ART
|| !gmpc_meta_watcher_match_data(META_ALBUM_ART
, song2
, song
))
171 if(ret
== META_DATA_AVAILABLE
) {
172 if(met
->content_type
== META_DATA_CONTENT_URI
)
174 const gchar
*path
= meta_data_get_uri(met
);
182 static void awn_song_changed(MpdObj
*mi
)
185 MetaData
*met
= NULL
;
186 mpd_Song
*song
= NULL
;
188 song
= mpd_playlist_get_current_song(mi
);
189 ret
= gmpc_meta_watcher_get_meta_path(gmw
,song
, META_ALBUM_ART
,&met
);
190 awn_update_cover(gmw
, song
, META_ALBUM_ART
, ret
, met
);
196 static void awn_mpd_status_changed(MpdObj
*mi
, ChangedStatusType what
, void *data
)
198 if(!awn_get_enabled())
200 if(what
&(MPD_CST_SONGID
))
201 awn_song_changed(mi
);
202 if(what
&(MPD_CST_ELAPSED_TIME
|MPD_CST_TOTAL_TIME
))
205 int totalTime
= mpd_status_get_total_song_time(connection
);
206 int elapsedTime
= mpd_status_get_elapsed_song_time(connection
);
207 gdouble progress
= elapsedTime
/(gdouble
)MAX(totalTime
,1)*100;
208 if((int)progress
== 0)
210 setAwnProgress((int)progress
);
214 static const gchar
* awn_get_translation_domain(void) {
215 return GETTEXT_PACKAGE
;
218 int plugin_api_version
= PLUGIN_API_VERSION
;
219 /* main plugin_awn info */
220 gmpcPlugin plugin
= {
221 .name
= N_("Avant Window Navigator Plugin"),
222 .version
= { MAJOR_VERSION
, MINOR_VERSION
, MICRO_VERSION
},
223 .plugin_type
= GMPC_PLUGIN_NO_GUI
,
224 .init
= awn_plugin_init
,
225 .destroy
= awn_plugin_destroy
,
226 .mpd_status_changed
= &awn_mpd_status_changed
,
227 .get_enabled
= awn_get_enabled
,
228 .set_enabled
= awn_set_enabled
,
229 .get_translation_domain
= awn_get_translation_domain