Add/Update translations
[gmpc-dynamic-playlist.git] / src / icon.c
blob3755d1dc68b55a30c3fa5cf293e17e6395309b22
1 /* gmpc-dynamic-playlist (GMPC plugin)
2 * Copyright (C) 2009 Andre Klitzing <andre@incubo.de>
3 * Homepage: http://www.incubo.de
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.
20 #include "icon.h"
21 #include "search.h"
22 #include "plugin.h"
23 #include <glib/gi18n-lib.h>
24 #include <gmpc/status_icon.h>
25 #include "defaults.h"
27 static GtkWidget* m_box = NULL;
28 static GtkWidget* m_image = NULL;
30 gboolean icon_clicked(G_GNUC_UNUSED GtkWidget* l_widget, GdkEventButton* l_event, G_GNUC_UNUSED gpointer l_data)
32 if(l_event->button == 1) // left mouse button
33 set_search_active(!get_search_active());
34 else if(l_event->button == 2) // middle mouse button
35 search_easy();
36 else if(l_event->button == 3) // right mouse button
37 g_debug("todo: open popup menu");
38 else
39 return FALSE;
41 return TRUE;
44 static void refresh_icon_state()
46 g_assert(m_image != NULL);
47 gtk_widget_set_sensitive(m_image, get_search_active());
50 gboolean icon_integration(G_GNUC_UNUSED gpointer l_data)
52 g_assert(m_box == NULL);
53 g_assert(m_image == NULL);
55 m_box = gtk_event_box_new();
56 m_image = gtk_image_new_from_stock(GTK_STOCK_INDEX, GTK_ICON_SIZE_MENU);
57 gtk_container_add(GTK_CONTAINER(m_box), m_image);
58 gtk_widget_set_tooltip_text(m_box, _("Dynamic Playlist"));
59 g_signal_connect(G_OBJECT(m_box), "button-release-event", G_CALLBACK(icon_clicked), NULL);
61 refresh_icon_state();
62 gtk_widget_show_all(m_box);
63 main_window_add_status_icon(m_box);
65 return TRUE;
68 gboolean is_icon_added()
70 return m_box != NULL;
73 gboolean is_grayed_out()
75 g_assert(m_image != NULL);
76 return gtk_widget_get_sensitive(m_image);
79 void add_icon()
81 icon_integration(NULL);
84 void remove_icon()
86 g_assert(m_box != NULL);
87 g_assert(m_image != NULL);
89 gtk_widget_destroy(m_box);
90 m_box = NULL;
91 m_image = NULL;
94 void reload_icon()
96 if(dyn_get_enabled())
98 if(is_icon_added())
99 refresh_icon_state();
100 else
101 add_icon();
103 else if(is_icon_added())
104 remove_icon();
107 void init_icon()
109 icon_integration(NULL);
112 /* vim:set ts=4 sw=4: */