1 /* gmpc-favorites.c generated by valac 0.12.0, the Vala compiler
2 * generated from gmpc-favorites.vala, do not modify */
3
4 /* Gnome Music Player Client (GMPC)
5 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
6 * Project homepage: http://gmpclient.org/
7
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 /****************************************************************************************
23 * "Public" api.
24 ****************************************************************************************/
25
26 #include <glib.h>
27 #include <glib-object.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <config.h>
31 #include <gtk/gtk.h>
32 #include <gtktransition.h>
33 #include "gmpc-extras.h"
34 #include <libmpd/libmpd.h>
35 #include <glib/gi18n-lib.h>
36 #include <libmpd/libmpdclient.h>
37 #include <misc.h>
38 #include <libmpd/libmpd-internal.h>
39 #include <plugin.h>
40 #include <main.h>
41 #include <gdk-pixbuf/gdk-pixdata.h>
42 #include <gdk/gdk.h>
43
44 #define _mpd_data_free0(var) ((var == NULL) ? NULL : (var = (mpd_data_free (var), NULL)))
45 #define _mpd_freeSong0(var) ((var == NULL) ? NULL : (var = (mpd_freeSong (var), NULL)))
46 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
47 typedef struct _Block37Data Block37Data;
48 #define _g_free0(var) (var = (g_free (var), NULL))
49 #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
50
51 struct _GmpcFavoritesListPrivate {
52 MpdData* list;
53 gboolean _disable;
54 };
55
56 struct _GmpcFavoritesButtonPrivate {
57 mpd_Song* song;
58 GtkImage* image;
59 gboolean fstate;
60 GdkPixbuf* pb;
61 };
62
63 struct _Block37Data {
64 int _ref_count_;
65 GmpcFavoritesButton * self;
66 gchar* pp;
67 };
68
69
70 GmpcFavoritesList* favorites = NULL;
71 static gpointer gmpc_favorites_list_parent_class = NULL;
72 static gpointer gmpc_favorites_button_parent_class = NULL;
73
74 #define some_unique_name_fav VERSION
75 #define use_transition_fav TRUE
76 #define LOG_DOMAIN_FAV "Gmpc.Favorites"
77 #define GMPC_FAVORITES_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMPC_FAVORITES_TYPE_LIST, GmpcFavoritesListPrivate))
78 enum {
79 GMPC_FAVORITES_LIST_DUMMY_PROPERTY,
80 GMPC_FAVORITES_LIST_DISABLE
81 };
82 static void gmpc_favorites_list_con_changed (GmpcFavoritesList* self, GmpcConnection* conn, MpdObj* server, gint connect);
83 static void gmpc_favorites_list_status_changed (GmpcFavoritesList* self, GmpcConnection* conn, MpdObj* server, ChangedStatusType what);
84 static GObject * gmpc_favorites_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
85 static void _gmpc_favorites_list_con_changed_gmpc_connection_connection_changed (GmpcConnection* _sender, MpdObj* mi, gint connect, gpointer self);
86 static void _gmpc_favorites_list_status_changed_gmpc_connection_status_changed (GmpcConnection* _sender, MpdObj* mi, ChangedStatusType what, gpointer self);
87 static void gmpc_favorites_list_finalize (GObject* obj);
88 static void _vala_gmpc_favorites_list_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
89 static void _vala_gmpc_favorites_list_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
90 #define GMPC_FAVORITES_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GMPC_FAVORITES_TYPE_BUTTON, GmpcFavoritesButtonPrivate))
91 enum {
92 GMPC_FAVORITES_BUTTON_DUMMY_PROPERTY
93 };
94 static gboolean gmpc_favorites_button_button_press_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventButton* event);
95 static Block37Data* block37_data_ref (Block37Data* _data37_);
96 static void block37_data_unref (Block37Data* _data37_);
97 static void _lambda38_ (GtkMenuItem* source, Block37Data* _data37_);
98 static void __lambda38__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
99 static gboolean gmpc_favorites_button_enter_notify_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventCrossing* motion);
100 static gboolean gmpc_favorites_button_leave_notify_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventCrossing* motion);
101 static void gmpc_favorites_button_update (GmpcFavoritesButton* self, GmpcFavoritesList* list);
102 static GObject * gmpc_favorites_button_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
103 static void _lambda39_ (GParamSpec* source, GmpcFavoritesButton* self);
104 static void __lambda39__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
105 static void _gmpc_favorites_button_update_gmpc_favorites_list_updated (GmpcFavoritesList* _sender, gpointer self);
106 static gboolean _gmpc_favorites_button_button_press_event_callback_gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
107 static gboolean _gmpc_favorites_button_enter_notify_event_callback_gtk_widget_enter_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self);
108 static gboolean _gmpc_favorites_button_leave_notify_event_callback_gtk_widget_leave_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self);
109 static void gmpc_favorites_button_finalize (GObject* obj);
110
111
112 /**
113 * If disconnected from mpd, clear the list.
114 * On connect fill
115 */
gmpc_favorites_list_con_changed(GmpcFavoritesList * self,GmpcConnection * conn,MpdObj * server,gint connect)116 static void gmpc_favorites_list_con_changed (GmpcFavoritesList* self, GmpcConnection* conn, MpdObj* server, gint connect) {
117 g_return_if_fail (self != NULL);
118 g_return_if_fail (conn != NULL);
119 g_return_if_fail (server != NULL);
120 if (connect == 1) {
121 const gchar* _tmp0_ = NULL;
122 MpdData* _tmp1_ = NULL;
123 g_log (LOG_DOMAIN_FAV, G_LOG_LEVEL_DEBUG, "gmpc-favorites.vala:57: Update list");
124 _tmp0_ = _ ("Favorites");
125 _tmp1_ = mpd_database_get_playlist_content (server, _tmp0_);
126 _mpd_data_free0 (self->priv->list);
127 self->priv->list = _tmp1_;
128 gmpc_favorites_list_set_disable (self, FALSE);
129 g_signal_emit_by_name (self, "updated");
130 } else {
131 _mpd_data_free0 (self->priv->list);
132 self->priv->list = NULL;
133 }
134 }
135
136
137 /**
138 * If playlist changed update the list
139 */
gmpc_favorites_list_status_changed(GmpcFavoritesList * self,GmpcConnection * conn,MpdObj * server,ChangedStatusType what)140 static void gmpc_favorites_list_status_changed (GmpcFavoritesList* self, GmpcConnection* conn, MpdObj* server, ChangedStatusType what) {
141 gboolean _tmp0_ = FALSE;
142 g_return_if_fail (self != NULL);
143 g_return_if_fail (conn != NULL);
144 g_return_if_fail (server != NULL);
145 if (!self->priv->_disable) {
146 _tmp0_ = (what & MPD_CST_STORED_PLAYLIST) == MPD_CST_STORED_PLAYLIST;
147 } else {
148 _tmp0_ = FALSE;
149 }
150 if (_tmp0_) {
151 const gchar* _tmp1_ = NULL;
152 MpdData* _tmp2_ = NULL;
153 g_log (LOG_DOMAIN_FAV, G_LOG_LEVEL_DEBUG, "gmpc-favorites.vala:75: Update list");
154 _tmp1_ = _ ("Favorites");
155 _tmp2_ = mpd_database_get_playlist_content (server, _tmp1_);
156 _mpd_data_free0 (self->priv->list);
157 self->priv->list = _tmp2_;
158 g_signal_emit_by_name (self, "updated");
159 }
160 }
161
162
163 /**
164 * Check if the song (specified by path) is favored
165 */
gmpc_favorites_list_is_favorite(GmpcFavoritesList * self,const gchar * path)166 gboolean gmpc_favorites_list_is_favorite (GmpcFavoritesList* self, const gchar* path) {
167 gboolean result = FALSE;
168 MpdData* _tmp0_ = NULL;
169 MpdData* iter;
170 g_return_val_if_fail (self != NULL, FALSE);
171 g_return_val_if_fail (path != NULL, FALSE);
172 _tmp0_ = mpd_data_get_first (self->priv->list);
173 iter = _tmp0_;
174 while (TRUE) {
175 if (!(iter != NULL)) {
176 break;
177 }
178 if (iter->type == MPD_DATA_TYPE_SONG) {
179 if (g_strcmp0 (iter->song->file, path) == 0) {
180 result = TRUE;
181 return result;
182 }
183 }
184 iter = mpd_data_get_next_real (iter, FALSE);
185 }
186 result = FALSE;
187 return result;
188 }
189
190
191 /**
192 * Favor, or unfavor a song
193 */
gmpc_favorites_list_set_favorite(GmpcFavoritesList * self,const gchar * path,gboolean favorite)194 void gmpc_favorites_list_set_favorite (GmpcFavoritesList* self, const gchar* path, gboolean favorite) {
195 gboolean _tmp0_;
196 gboolean current;
197 gboolean _tmp1_ = FALSE;
198 g_return_if_fail (self != NULL);
199 g_return_if_fail (path != NULL);
200 _tmp0_ = gmpc_favorites_list_is_favorite (self, path);
201 current = _tmp0_;
202 if (!self->priv->_disable) {
203 _tmp1_ = current != favorite;
204 } else {
205 _tmp1_ = FALSE;
206 }
207 if (_tmp1_) {
208 if (favorite) {
209 const gchar* _tmp2_ = NULL;
210 _tmp2_ = _ ("Favorites");
211 mpd_database_playlist_list_add (connection, _tmp2_, path);
212 } else {
213 MpdData* _tmp3_ = NULL;
214 MpdData* iter;
215 _tmp3_ = mpd_data_get_first (self->priv->list);
216 iter = _tmp3_;
217 while (TRUE) {
218 if (!(iter != NULL)) {
219 break;
220 }
221 if (iter->type == MPD_DATA_TYPE_SONG) {
222 if (g_strcmp0 (iter->song->file, path) == 0) {
223 const gchar* _tmp4_ = NULL;
224 _tmp4_ = _ ("Favorites");
225 mpd_database_playlist_list_delete (connection, _tmp4_, iter->song->pos);
226 return;
227 }
228 }
229 iter = mpd_data_get_next_real (iter, FALSE);
230 }
231 }
232 }
233 }
234
235
gmpc_favorites_list_construct(GType object_type)236 GmpcFavoritesList* gmpc_favorites_list_construct (GType object_type) {
237 GmpcFavoritesList * self = NULL;
238 self = (GmpcFavoritesList*) g_object_new (object_type, NULL);
239 return self;
240 }
241
242
gmpc_favorites_list_new(void)243 GmpcFavoritesList* gmpc_favorites_list_new (void) {
244 return gmpc_favorites_list_construct (GMPC_FAVORITES_TYPE_LIST);
245 }
246
247
gmpc_favorites_list_get_disable(GmpcFavoritesList * self)248 gboolean gmpc_favorites_list_get_disable (GmpcFavoritesList* self) {
249 gboolean result;
250 g_return_val_if_fail (self != NULL, FALSE);
251 result = self->priv->_disable;
252 return result;
253 }
254
255
gmpc_favorites_list_set_disable(GmpcFavoritesList * self,gboolean value)256 void gmpc_favorites_list_set_disable (GmpcFavoritesList* self, gboolean value) {
257 g_return_if_fail (self != NULL);
258 self->priv->_disable = value;
259 g_object_notify ((GObject *) self, "disable");
260 }
261
262
_gmpc_favorites_list_con_changed_gmpc_connection_connection_changed(GmpcConnection * _sender,MpdObj * mi,gint connect,gpointer self)263 static void _gmpc_favorites_list_con_changed_gmpc_connection_connection_changed (GmpcConnection* _sender, MpdObj* mi, gint connect, gpointer self) {
264 gmpc_favorites_list_con_changed (self, _sender, mi, connect);
265 }
266
267
_gmpc_favorites_list_status_changed_gmpc_connection_status_changed(GmpcConnection * _sender,MpdObj * mi,ChangedStatusType what,gpointer self)268 static void _gmpc_favorites_list_status_changed_gmpc_connection_status_changed (GmpcConnection* _sender, MpdObj* mi, ChangedStatusType what, gpointer self) {
269 gmpc_favorites_list_status_changed (self, _sender, mi, what);
270 }
271
272
mpd_get_connected(MpdObj * self)273 static gboolean mpd_get_connected (MpdObj* self) {
274 gboolean result;
275 gboolean _tmp0_;
276 g_return_val_if_fail (self != NULL, FALSE);
277 _tmp0_ = mpd_check_connected (self);
278 result = _tmp0_;
279 return result;
280 }
281
282
gmpc_favorites_list_constructor(GType type,guint n_construct_properties,GObjectConstructParam * construct_properties)283 static GObject * gmpc_favorites_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
284 GObject * obj;
285 GObjectClass * parent_class;
286 GmpcFavoritesList * self;
287 gboolean _tmp0_;
288 parent_class = G_OBJECT_CLASS (gmpc_favorites_list_parent_class);
289 obj = parent_class->constructor (type, n_construct_properties, construct_properties);
290 self = GMPC_FAVORITES_LIST (obj);
291 g_signal_connect_object (gmpcconn, "connection-changed", (GCallback) _gmpc_favorites_list_con_changed_gmpc_connection_connection_changed, self, 0);
292 g_signal_connect_object (gmpcconn, "status-changed", (GCallback) _gmpc_favorites_list_status_changed_gmpc_connection_status_changed, self, 0);
293 g_log (LOG_DOMAIN_FAV, G_LOG_LEVEL_DEBUG, "gmpc-favorites.vala:42: Favorites object created");
294 _tmp0_ = mpd_get_connected (connection);
295 if (_tmp0_) {
296 gmpc_favorites_list_con_changed (self, gmpcconn, connection, 1);
297 }
298 return obj;
299 }
300
301
gmpc_favorites_list_class_init(GmpcFavoritesListClass * klass)302 static void gmpc_favorites_list_class_init (GmpcFavoritesListClass * klass) {
303 gmpc_favorites_list_parent_class = g_type_class_peek_parent (klass);
304 g_type_class_add_private (klass, sizeof (GmpcFavoritesListPrivate));
305 G_OBJECT_CLASS (klass)->get_property = _vala_gmpc_favorites_list_get_property;
306 G_OBJECT_CLASS (klass)->set_property = _vala_gmpc_favorites_list_set_property;
307 G_OBJECT_CLASS (klass)->constructor = gmpc_favorites_list_constructor;
308 G_OBJECT_CLASS (klass)->finalize = gmpc_favorites_list_finalize;
309 g_object_class_install_property (G_OBJECT_CLASS (klass), GMPC_FAVORITES_LIST_DISABLE, g_param_spec_boolean ("disable", "disable", "disable", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
310 /**
311 * Signal for the widget using the list to see if it needs to recheck status
312 */
313 g_signal_new ("updated", GMPC_FAVORITES_TYPE_LIST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
314 }
315
316
gmpc_favorites_list_instance_init(GmpcFavoritesList * self)317 static void gmpc_favorites_list_instance_init (GmpcFavoritesList * self) {
318 self->priv = GMPC_FAVORITES_LIST_GET_PRIVATE (self);
319 self->priv->list = NULL;
320 self->priv->_disable = FALSE;
321 }
322
323
gmpc_favorites_list_finalize(GObject * obj)324 static void gmpc_favorites_list_finalize (GObject* obj) {
325 GmpcFavoritesList * self;
326 self = GMPC_FAVORITES_LIST (obj);
327 _mpd_data_free0 (self->priv->list);
328 G_OBJECT_CLASS (gmpc_favorites_list_parent_class)->finalize (obj);
329 }
330
331
332 /**
333 * This class is created, and stays active until the last GmpcFavoritesButton gets removed
334 */
gmpc_favorites_list_get_type(void)335 GType gmpc_favorites_list_get_type (void) {
336 static volatile gsize gmpc_favorites_list_type_id__volatile = 0;
337 if (g_once_init_enter (&gmpc_favorites_list_type_id__volatile)) {
338 static const GTypeInfo g_define_type_info = { sizeof (GmpcFavoritesListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gmpc_favorites_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GmpcFavoritesList), 0, (GInstanceInitFunc) gmpc_favorites_list_instance_init, NULL };
339 GType gmpc_favorites_list_type_id;
340 gmpc_favorites_list_type_id = g_type_register_static (G_TYPE_OBJECT, "GmpcFavoritesList", &g_define_type_info, 0);
341 g_once_init_leave (&gmpc_favorites_list_type_id__volatile, gmpc_favorites_list_type_id);
342 }
343 return gmpc_favorites_list_type_id__volatile;
344 }
345
346
_vala_gmpc_favorites_list_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)347 static void _vala_gmpc_favorites_list_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
348 GmpcFavoritesList * self;
349 self = GMPC_FAVORITES_LIST (object);
350 switch (property_id) {
351 case GMPC_FAVORITES_LIST_DISABLE:
352 g_value_set_boolean (value, gmpc_favorites_list_get_disable (self));
353 break;
354 default:
355 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
356 break;
357 }
358 }
359
360
_vala_gmpc_favorites_list_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)361 static void _vala_gmpc_favorites_list_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
362 GmpcFavoritesList * self;
363 self = GMPC_FAVORITES_LIST (object);
364 switch (property_id) {
365 case GMPC_FAVORITES_LIST_DISABLE:
366 gmpc_favorites_list_set_disable (self, g_value_get_boolean (value));
367 break;
368 default:
369 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
370 break;
371 }
372 }
373
374
block37_data_ref(Block37Data * _data37_)375 static Block37Data* block37_data_ref (Block37Data* _data37_) {
376 g_atomic_int_inc (&_data37_->_ref_count_);
377 return _data37_;
378 }
379
380
block37_data_unref(Block37Data * _data37_)381 static void block37_data_unref (Block37Data* _data37_) {
382 if (g_atomic_int_dec_and_test (&_data37_->_ref_count_)) {
383 _g_object_unref0 (_data37_->self);
384 _g_free0 (_data37_->pp);
385 g_slice_free (Block37Data, _data37_);
386 }
387 }
388
389
_lambda38_(GtkMenuItem * source,Block37Data * _data37_)390 static void _lambda38_ (GtkMenuItem* source, Block37Data* _data37_) {
391 GmpcFavoritesButton * self;
392 self = _data37_->self;
393 g_return_if_fail (source != NULL);
394 mpd_database_playlist_list_add (connection, _data37_->pp, self->priv->song->file);
395 }
396
397
__lambda38__gtk_menu_item_activate(GtkMenuItem * _sender,gpointer self)398 static void __lambda38__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
399 _lambda38_ (_sender, self);
400 }
401
402
gmpc_favorites_button_button_press_event_callback(GmpcFavoritesButton * self,GtkWidget * button,GdkEventButton * event)403 static gboolean gmpc_favorites_button_button_press_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventButton* event) {
404 gboolean result = FALSE;
405 gboolean _tmp0_ = FALSE;
406 g_return_val_if_fail (self != NULL, FALSE);
407 g_return_val_if_fail (button != NULL, FALSE);
408 if ((*event).button == 1) {
409 _tmp0_ = self->priv->song != NULL;
410 } else {
411 _tmp0_ = FALSE;
412 }
413 if (_tmp0_) {
414 gmpc_favorites_list_set_favorite (favorites, self->priv->song->file, !self->priv->fstate);
415 self->priv->fstate = !self->priv->fstate;
416 } else {
417 gboolean _tmp1_ = FALSE;
418 if ((*event).button == 3) {
419 _tmp1_ = self->priv->song != NULL;
420 } else {
421 _tmp1_ = FALSE;
422 }
423 if (_tmp1_) {
424 GtkMenu* _tmp2_ = NULL;
425 GtkMenu* menu;
426 gint items;
427 MpdData* _tmp3_ = NULL;
428 MpdData* item;
429 _tmp2_ = (GtkMenu*) gtk_menu_new ();
430 menu = g_object_ref_sink (_tmp2_);
431 items = 0;
432 _tmp3_ = mpd_database_playlist_list (connection);
433 item = _tmp3_;
434 while (TRUE) {
435 Block37Data* _data37_;
436 gchar* _tmp4_;
437 GtkImageMenuItem* _tmp5_ = NULL;
438 GtkImageMenuItem* entry;
439 const gchar* _tmp6_ = NULL;
440 _data37_ = g_slice_new0 (Block37Data);
441 _data37_->_ref_count_ = 1;
442 _data37_->self = g_object_ref (self);
443 if (!(item != NULL)) {
444 block37_data_unref (_data37_);
445 _data37_ = NULL;
446 break;
447 }
448 _tmp4_ = g_strdup ((gchar*) item->playlist->path);
449 _data37_->pp = _tmp4_;
450 _tmp5_ = (GtkImageMenuItem*) gtk_image_menu_item_new_with_label (_data37_->pp);
451 entry = g_object_ref_sink (_tmp5_);
452 _tmp6_ = _ ("Favorites");
453 if (g_strcmp0 (_data37_->pp, _tmp6_) == 0) {
454 GtkImage* _tmp7_ = NULL;
455 GtkImage* _tmp8_;
456 _tmp7_ = (GtkImage*) gtk_image_new_from_icon_name ("emblem-favorite", GTK_ICON_SIZE_MENU);
457 _tmp8_ = g_object_ref_sink (_tmp7_);
458 gtk_image_menu_item_set_image (entry, (GtkWidget*) _tmp8_);
459 _g_object_unref0 (_tmp8_);
460 } else {
461 GtkImage* _tmp9_ = NULL;
462 GtkImage* _tmp10_;
463 _tmp9_ = (GtkImage*) gtk_image_new_from_icon_name ("media-playlist", GTK_ICON_SIZE_MENU);
464 _tmp10_ = g_object_ref_sink (_tmp9_);
465 gtk_image_menu_item_set_image (entry, (GtkWidget*) _tmp10_);
466 _g_object_unref0 (_tmp10_);
467 }
468 g_signal_connect_data ((GtkMenuItem*) entry, "activate", (GCallback) __lambda38__gtk_menu_item_activate, block37_data_ref (_data37_), (GClosureNotify) block37_data_unref, 0);
469 gtk_menu_shell_append ((GtkMenuShell*) menu, (GtkWidget*) ((GtkMenuItem*) entry));
470 item = mpd_data_get_next (item);
471 items++;
472 _g_object_unref0 (entry);
473 block37_data_unref (_data37_);
474 _data37_ = NULL;
475 }
476 if (items > 0) {
477 gtk_widget_show_all ((GtkWidget*) menu);
478 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, (*event).button, (*event).time);
479 } else {
480 gtk_object_destroy ((GtkObject*) menu);
481 }
482 result = TRUE;
483 _mpd_data_free0 (item);
484 _g_object_unref0 (menu);
485 return result;
486 }
487 }
488 result = FALSE;
489 return result;
490 }
491
492
gmpc_favorites_button_enter_notify_event_callback(GmpcFavoritesButton * self,GtkWidget * button,GdkEventCrossing * motion)493 static gboolean gmpc_favorites_button_enter_notify_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventCrossing* motion) {
494 gboolean result = FALSE;
495 GdkPixbuf* _tmp0_ = NULL;
496 GdkPixbuf* pb2;
497 g_return_val_if_fail (self != NULL, FALSE);
498 g_return_val_if_fail (button != NULL, FALSE);
499 _tmp0_ = gdk_pixbuf_copy (self->priv->pb);
500 pb2 = _tmp0_;
501 if (self->priv->fstate) {
502 colorshift_pixbuf (pb2, self->priv->pb, 10);
503 } else {
504 colorshift_pixbuf (pb2, self->priv->pb, -50);
505 }
506 gtk_image_set_from_pixbuf (self->priv->image, pb2);
507 result = FALSE;
508 _g_object_unref0 (pb2);
509 return result;
510 }
511
512
gmpc_favorites_button_leave_notify_event_callback(GmpcFavoritesButton * self,GtkWidget * button,GdkEventCrossing * motion)513 static gboolean gmpc_favorites_button_leave_notify_event_callback (GmpcFavoritesButton* self, GtkWidget* button, GdkEventCrossing* motion) {
514 gboolean result = FALSE;
515 g_return_val_if_fail (self != NULL, FALSE);
516 g_return_val_if_fail (button != NULL, FALSE);
517 gmpc_favorites_button_update (self, favorites);
518 result = FALSE;
519 return result;
520 }
521
522
gmpc_favorites_button_update(GmpcFavoritesButton * self,GmpcFavoritesList * list)523 static void gmpc_favorites_button_update (GmpcFavoritesButton* self, GmpcFavoritesList* list) {
524 GdkPixbuf* _tmp1_ = NULL;
525 GdkPixbuf* pb2;
526 g_return_if_fail (self != NULL);
527 g_return_if_fail (list != NULL);
528 if (self->priv->song != NULL) {
529 gboolean _tmp0_;
530 _tmp0_ = gmpc_favorites_list_is_favorite (favorites, self->priv->song->file);
531 self->priv->fstate = _tmp0_;
532 } else {
533 gtk_widget_hide ((GtkWidget*) self);
534 return;
535 }
536 _tmp1_ = gdk_pixbuf_copy (self->priv->pb);
537 pb2 = _tmp1_;
538 if (self->priv->fstate) {
539 colorshift_pixbuf (pb2, self->priv->pb, 30);
540 } else {
541 colorshift_pixbuf (pb2, self->priv->pb, -80);
542 }
543 gtk_image_set_from_pixbuf (self->priv->image, pb2);
544 gtk_widget_show ((GtkWidget*) self->priv->image);
545 gtk_widget_show ((GtkWidget*) self);
546 _g_object_unref0 (pb2);
547 }
548
549
550 /**********************************************************************
551 * Public api
552 *********************************************************************/
_mpd_songDup0(gpointer self)553 static gpointer _mpd_songDup0 (gpointer self) {
554 return self ? mpd_songDup (self) : NULL;
555 }
556
557
gmpc_favorites_button_set_song(GmpcFavoritesButton * self,const mpd_Song * song)558 void gmpc_favorites_button_set_song (GmpcFavoritesButton* self, const mpd_Song* song) {
559 gboolean _tmp0_ = FALSE;
560 gboolean _tmp1_ = FALSE;
561 gboolean _tmp2_ = FALSE;
562 mpd_Song* _tmp3_;
563 g_return_if_fail (self != NULL);
564 if (self->priv->song == NULL) {
565 _tmp0_ = song == NULL;
566 } else {
567 _tmp0_ = FALSE;
568 }
569 if (_tmp0_) {
570 return;
571 }
572 if (self->priv->song != NULL) {
573 _tmp2_ = song != NULL;
574 } else {
575 _tmp2_ = FALSE;
576 }
577 if (_tmp2_) {
578 _tmp1_ = g_strcmp0 (self->priv->song->file, song->file) == 0;
579 } else {
580 _tmp1_ = FALSE;
581 }
582 if (_tmp1_) {
583 return;
584 }
585 _tmp3_ = _mpd_songDup0 (song);
586 _mpd_freeSong0 (self->priv->song);
587 self->priv->song = _tmp3_;
588 gmpc_favorites_button_update (self, favorites);
589 }
590
591
gmpc_favorites_button_construct(GType object_type)592 GmpcFavoritesButton* gmpc_favorites_button_construct (GType object_type) {
593 GmpcFavoritesButton * self = NULL;
594 self = (GmpcFavoritesButton*) g_object_new (object_type, NULL);
595 return self;
596 }
597
598
gmpc_favorites_button_new(void)599 GmpcFavoritesButton* gmpc_favorites_button_new (void) {
600 return gmpc_favorites_button_construct (GMPC_FAVORITES_TYPE_BUTTON);
601 }
602
603
_g_object_ref0(gpointer self)604 static gpointer _g_object_ref0 (gpointer self) {
605 return self ? g_object_ref (self) : NULL;
606 }
607
608
_lambda39_(GParamSpec * source,GmpcFavoritesButton * self)609 static void _lambda39_ (GParamSpec* source, GmpcFavoritesButton* self) {
610 gboolean _tmp0_;
611 g_return_if_fail (source != NULL);
612 _tmp0_ = gmpc_favorites_list_get_disable (favorites);
613 if (_tmp0_) {
614 gtk_widget_set_sensitive ((GtkWidget*) self, FALSE);
615 } else {
616 gtk_widget_set_sensitive ((GtkWidget*) self, TRUE);
617 }
618 }
619
620
__lambda39__g_object_notify(GObject * _sender,GParamSpec * pspec,gpointer self)621 static void __lambda39__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
622 _lambda39_ (pspec, self);
623 }
624
625
_gmpc_favorites_button_update_gmpc_favorites_list_updated(GmpcFavoritesList * _sender,gpointer self)626 static void _gmpc_favorites_button_update_gmpc_favorites_list_updated (GmpcFavoritesList* _sender, gpointer self) {
627 gmpc_favorites_button_update (self, _sender);
628 }
629
630
_gmpc_favorites_button_button_press_event_callback_gtk_widget_button_press_event(GtkWidget * _sender,GdkEventButton * event,gpointer self)631 static gboolean _gmpc_favorites_button_button_press_event_callback_gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
632 gboolean result;
633 result = gmpc_favorites_button_button_press_event_callback (self, _sender, event);
634 return result;
635 }
636
637
_gmpc_favorites_button_enter_notify_event_callback_gtk_widget_enter_notify_event(GtkWidget * _sender,GdkEventCrossing * event,gpointer self)638 static gboolean _gmpc_favorites_button_enter_notify_event_callback_gtk_widget_enter_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self) {
639 gboolean result;
640 result = gmpc_favorites_button_enter_notify_event_callback (self, _sender, event);
641 return result;
642 }
643
644
_gmpc_favorites_button_leave_notify_event_callback_gtk_widget_leave_notify_event(GtkWidget * _sender,GdkEventCrossing * event,gpointer self)645 static gboolean _gmpc_favorites_button_leave_notify_event_callback_gtk_widget_leave_notify_event (GtkWidget* _sender, GdkEventCrossing* event, gpointer self) {
646 gboolean result;
647 result = gmpc_favorites_button_leave_notify_event_callback (self, _sender, event);
648 return result;
649 }
650
651
gmpc_favorites_button_constructor(GType type,guint n_construct_properties,GObjectConstructParam * construct_properties)652 static GObject * gmpc_favorites_button_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
653 GObject * obj;
654 GObjectClass * parent_class;
655 GmpcFavoritesButton * self;
656 GtkIconTheme* _tmp0_ = NULL;
657 GtkIconTheme* _tmp1_;
658 GtkIconTheme* it;
659 GdkPixbuf* _tmp2_ = NULL;
660 GdkPixbuf* _tmp3_;
661 GtkImage* _tmp5_ = NULL;
662 GError * _inner_error_ = NULL;
663 parent_class = G_OBJECT_CLASS (gmpc_favorites_button_parent_class);
664 obj = parent_class->constructor (type, n_construct_properties, construct_properties);
665 self = GMPC_FAVORITES_BUTTON (obj);
666 gtk_widget_set_no_show_all ((GtkWidget*) self, TRUE);
667 gtk_event_box_set_visible_window ((GtkEventBox*) self, FALSE);
668 _tmp0_ = gtk_icon_theme_get_default ();
669 _tmp1_ = _g_object_ref0 (_tmp0_);
670 it = _tmp1_;
671 _tmp2_ = gtk_icon_theme_load_icon (it, "emblem-favorite", 24, 0, &_inner_error_);
672 _tmp3_ = _tmp2_;
673 if (_inner_error_ != NULL) {
674 goto __catch26_g_error;
675 }
676 _g_object_unref0 (self->priv->pb);
677 self->priv->pb = _tmp3_;
678 goto __finally26;
679 __catch26_g_error:
680 {
681 GError * e;
682 e = _inner_error_;
683 _inner_error_ = NULL;
684 g_error ("gmpc-favorites.vala:165: error: %s\n", e->message);
685 _g_error_free0 (e);
686 }
687 __finally26:
688 if (_inner_error_ != NULL) {
689 _g_object_unref0 (it);
690 g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
691 g_clear_error (&_inner_error_);
692 }
693 if (favorites == NULL) {
694 GmpcFavoritesList* _tmp4_ = NULL;
695 _tmp4_ = gmpc_favorites_list_new ();
696 _g_object_unref0 (favorites);
697 favorites = _tmp4_;
698 g_object_add_weak_pointer ((GObject*) favorites, &favorites);
699 } else {
700 g_object_ref ((GObject*) favorites);
701 }
702 g_signal_connect_object ((GObject*) favorites, "notify::disable", (GCallback) __lambda39__g_object_notify, self, 0);
703 g_signal_connect_object (favorites, "updated", (GCallback) _gmpc_favorites_button_update_gmpc_favorites_list_updated, self, 0);
704 _tmp5_ = (GtkImage*) gtk_image_new ();
705 _g_object_unref0 (self->priv->image);
706 self->priv->image = g_object_ref_sink (_tmp5_);
707 gmpc_favorites_button_update (self, favorites);
708 gtk_container_add ((GtkContainer*) self, (GtkWidget*) self->priv->image);
709 g_signal_connect_object ((GtkWidget*) self, "button-press-event", (GCallback) _gmpc_favorites_button_button_press_event_callback_gtk_widget_button_press_event, self, 0);
710 g_signal_connect_object ((GtkWidget*) self, "enter-notify-event", (GCallback) _gmpc_favorites_button_enter_notify_event_callback_gtk_widget_enter_notify_event, self, 0);
711 g_signal_connect_object ((GtkWidget*) self, "leave-notify-event", (GCallback) _gmpc_favorites_button_leave_notify_event_callback_gtk_widget_leave_notify_event, self, 0);
712 _g_object_unref0 (it);
713 return obj;
714 }
715
716
gmpc_favorites_button_class_init(GmpcFavoritesButtonClass * klass)717 static void gmpc_favorites_button_class_init (GmpcFavoritesButtonClass * klass) {
718 gmpc_favorites_button_parent_class = g_type_class_peek_parent (klass);
719 g_type_class_add_private (klass, sizeof (GmpcFavoritesButtonPrivate));
720 G_OBJECT_CLASS (klass)->constructor = gmpc_favorites_button_constructor;
721 G_OBJECT_CLASS (klass)->finalize = gmpc_favorites_button_finalize;
722 }
723
724
gmpc_favorites_button_instance_init(GmpcFavoritesButton * self)725 static void gmpc_favorites_button_instance_init (GmpcFavoritesButton * self) {
726 self->priv = GMPC_FAVORITES_BUTTON_GET_PRIVATE (self);
727 self->priv->fstate = FALSE;
728 self->priv->pb = NULL;
729 }
730
731
gmpc_favorites_button_finalize(GObject * obj)732 static void gmpc_favorites_button_finalize (GObject* obj) {
733 GmpcFavoritesButton * self;
734 self = GMPC_FAVORITES_BUTTON (obj);
735 if (favorites != NULL) {
736 g_object_unref ((GObject*) favorites);
737 }
738 _mpd_freeSong0 (self->priv->song);
739 _g_object_unref0 (self->priv->image);
740 _g_object_unref0 (self->priv->pb);
741 G_OBJECT_CLASS (gmpc_favorites_button_parent_class)->finalize (obj);
742 }
743
744
745 /**
746 * The actual favorite button
747 */
gmpc_favorites_button_get_type(void)748 GType gmpc_favorites_button_get_type (void) {
749 static volatile gsize gmpc_favorites_button_type_id__volatile = 0;
750 if (g_once_init_enter (&gmpc_favorites_button_type_id__volatile)) {
751 static const GTypeInfo g_define_type_info = { sizeof (GmpcFavoritesButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gmpc_favorites_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GmpcFavoritesButton), 0, (GInstanceInitFunc) gmpc_favorites_button_instance_init, NULL };
752 GType gmpc_favorites_button_type_id;
753 gmpc_favorites_button_type_id = g_type_register_static (GTK_TYPE_EVENT_BOX, "GmpcFavoritesButton", &g_define_type_info, 0);
754 g_once_init_leave (&gmpc_favorites_button_type_id__volatile, gmpc_favorites_button_type_id);
755 }
756 return gmpc_favorites_button_type_id__volatile;
757 }
758
759
760
761