diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-06-28 21:12:07 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-06-28 21:12:07 +0100 |
commit | 0e616c323a678732dbd593d0d430507e099fda9f (patch) | |
tree | a0ff25cb5b4f98d0c4ea2eb8a25a89248909f647 | |
parent | 33395ee8bff3e3d4b42bc40823eb9efe88f1611d (diff) | |
download | ayatana-indicator-sound-0e616c323a678732dbd593d0d430507e099fda9f.tar.gz ayatana-indicator-sound-0e616c323a678732dbd593d0d430507e099fda9f.tar.bz2 ayatana-indicator-sound-0e616c323a678732dbd593d0d430507e099fda9f.zip |
moving in the right direction
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/play-button.c | 82 | ||||
-rw-r--r-- | src/play-button.h | 2 | ||||
-rw-r--r-- | src/sound-service.c | 4 | ||||
-rw-r--r-- | src/transport-widget.c | 123 |
5 files changed, 102 insertions, 111 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b33107d..21212d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ libsoundmenu_la_SOURCES = \ transport-widget.h \ metadata-widget.c \ metadata-widget.h \ + play-button.c \ + play-button.h \ indicator-sound.c \ dbus-shared-names.h \ sound-service-client.h diff --git a/src/play-button.c b/src/play-button.c index ab441ea..774b1e6 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -21,10 +21,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "config.h" #endif -#include <glib/gi18n.h> +#include <math.h> #include "play-button.h" -#include "common-defs.h" -#include <gtk/gtk.h> typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -43,6 +41,7 @@ static void play_button_dispose (GObject *object); static void play_button_finalize (GObject *object); static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event); +static void draw (GtkWidget* button, cairo_t *cr); G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); @@ -50,22 +49,32 @@ G_DEFINE_TYPE (PlayButton, play_button, GTK_TYPE_DRAWING_AREA); static void play_button_class_init (PlayButtonClass *klass) { - g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); - GtkWidgetClass* widget_class; + + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass* widget_class = GTK_WIDGET_CLASS (klass); - widget_class = GTK_WIDGET_CLASS (klass); + g_type_class_add_private (klass, sizeof (PlayButtonPrivate)); widget_class->expose_event = play_button_expose; gobject_class->dispose = play_button_dispose; gobject_class->finalize = play_button_finalize; - } static void play_button_init (PlayButton *self) { g_debug("PlayButton::play_button_init"); + GtkAllocation alloc; + + alloc.width = 100; + alloc.height = 100; + alloc.x = 0; + alloc.y = 0; + + gtk_widget_set_allocation(GTK_WIDGET(self), + &alloc); + //g_free(alloc); } static void @@ -83,11 +92,66 @@ play_button_finalize (GObject *object) static gboolean play_button_expose (GtkWidget *button, GdkEventExpose *event) { -return FALSE; + cairo_t *cr; + cr = gdk_cairo_create (button->window); + cairo_rectangle (cr, + event->area.x, event->area.y, + event->area.width, event->area.height); + + cairo_clip(cr); + draw (button, cr); + cairo_destroy (cr); + return FALSE; } +static void +draw (GtkWidget* button, cairo_t *cr) +{ + double x, y; + double radius; + int i; + + x = button->allocation.x + button->allocation.width / 2; + y = button->allocation.y + button->allocation.height / 2; + radius = MIN (button->allocation.width / 2, + button->allocation.height / 2) - 5; + + /* button back */ + cairo_arc (cr, x, y, radius, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_stroke (cr); + + /* button ticks */ + for (i = 0; i < 12; i++) + { + int inset; + + cairo_save (cr); /* stack-pen-size */ + + if (i % 3 == 0) + { + inset = 0.2 * radius; + } + else + { + inset = 0.1 * radius; + cairo_set_line_width (cr, 0.5 * + cairo_get_line_width (cr)); + } + + cairo_move_to (cr, + x + (radius - inset) * cos (i * M_PI / 6), + y + (radius - inset) * sin (i * M_PI / 6)); + cairo_line_to (cr, + x + radius * cos (i * M_PI / 6), + y + radius * sin (i * M_PI / 6)); + cairo_stroke (cr); + cairo_restore (cr); /* stack-pen-size */ + } +} - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/play-button.h b/src/play-button.h index a1e18f7..4f7cdd0 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -19,6 +19,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef __PLAY_BUTTON_H__ #define __PLAY_BUTTON_H__ +#include <gtk/gtk.h> + G_BEGIN_DECLS #define PLAY_BUTTON_TYPE (play_button_get_type ()) diff --git a/src/sound-service.c b/src/sound-service.c index bcdac07..ea04e4b 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -45,8 +45,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index a86e37b..07e7402 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -25,8 +25,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "transport-widget.h" #include "common-defs.h" #include <gtk/gtk.h> +#include "play-button.h" -// TODO: think about leakage: ted ! static DbusmenuMenuitem* twin_item; @@ -34,20 +34,10 @@ typedef struct _TransportWidgetPrivate TransportWidgetPrivate; struct _TransportWidgetPrivate { - //GtkWidget* hbox; - //GtkWidget* play_button; + GtkWidget* hbox; + GtkWidget* play_button; }; -enum { - PLAY, - PAUSE, - NEXT, - PREVIOUS, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - #define TRANSPORT_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRANSPORT_WIDGET_TYPE, TransportWidgetPrivate)) /* Gobject boiler plate */ @@ -60,21 +50,14 @@ static void transport_widget_finalize (GObject *object); static gboolean transport_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); static gboolean transport_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); -static void transport_widget_play_clicked (GtkWidget* button, - TransportWidget* self); - + GdkEventButton *event); static void transport_widget_property_update(DbusmenuMenuitem* item, - gchar * property, - GValue * value, - gpointer userdata); -// utility methods -static gchar* transport_widget_toggle_play_label(gint state); + gchar * property, + GValue * value, + gpointer userdata); G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM); - - static void transport_widget_class_init (TransportWidgetClass *klass) { @@ -84,45 +67,12 @@ transport_widget_class_init (TransportWidgetClass *klass) menu_item_class->hide_on_activate = FALSE; widget_class->button_press_event = transport_widget_button_press_event; - widget_class->button_release_event = transport_widget_button_release_event; - + widget_class->button_release_event = transport_widget_button_release_event; g_type_class_add_private (klass, sizeof (TransportWidgetPrivate)); gobject_class->dispose = transport_widget_dispose; gobject_class->finalize = transport_widget_finalize; - signals[PLAY] = g_signal_new ("play", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PAUSE] = g_signal_new ("pause", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - - signals[NEXT] = g_signal_new ("next", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[PREVIOUS] = g_signal_new ("previous", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } static void @@ -131,19 +81,17 @@ transport_widget_init (TransportWidget *self) g_debug("TransportWidget::transport_widget_init"); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(self); - GtkWidget *hbox; + GtkWidget* hbox; hbox = gtk_hbox_new(TRUE, 2); - gchar* symbol = transport_widget_toggle_play_label(dbusmenu_menuitem_property_get_int(twin_item, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE)); - priv->play_button = gtk_button_new_with_label(symbol); - //g_free(symbol); - gtk_box_pack_start (GTK_BOX (hbox), priv->play_button, FALSE, TRUE, 0); priv->hbox = hbox; + + priv->play_button = play_button_new(); + + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->play_button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self); - - g_signal_connect(priv->play_button, "clicked", G_CALLBACK(transport_widget_play_clicked), self); gtk_container_add (GTK_CONTAINER (self), priv->hbox); @@ -172,28 +120,17 @@ transport_widget_button_press_event (GtkWidget *menuitem, return FALSE; } - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - - gtk_widget_event (priv->hbox, (GdkEvent*)event); - gboolean state = g_ascii_strcasecmp(gtk_button_get_label(GTK_BUTTON(priv->play_button)), ">") == 0; + //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label((gint)state)); - GValue value = {0}; - g_value_init(&value, G_TYPE_BOOLEAN); - g_debug("TransportWidget::menu_press_event - going to send value %i", state); - - g_value_set_boolean(&value, state); - dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); + //GValue value = {0}; + //g_value_init(&value, G_TYPE_BOOLEAN); + //g_debug("TransportWidget::menu_press_event - going to send value %i", state); + //g_value_set_boolean(&value, state); + //dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); return TRUE; } -static void -transport_widget_play_clicked(GtkWidget* button, - TransportWidget* self) -{ - g_debug("Transport_widget_play_clicked"); -} static gboolean transport_widget_button_release_event (GtkWidget *menuitem, @@ -203,9 +140,6 @@ transport_widget_button_release_event (GtkWidget *menuitem, if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){ return FALSE; } - - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - gtk_widget_event (priv->hbox, (GdkEvent*)event); return TRUE; } @@ -219,23 +153,12 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { g_debug("transport_widget_update_state - with property %s", property); - int update_value = g_value_get_int(value); - g_debug("transport_widget_update_state - with value %i", update_value); + //int update_value = g_value_get_int(value); + //g_debug("transport_widget_update_state - with value %i", update_value); - TransportWidget* bar = (TransportWidget*)userdata; - TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); + //TransportWidget* bar = (TransportWidget*)userdata; + //TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar); - gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label(update_value)); -} - -// will be needed for image swapping -static gchar* transport_widget_toggle_play_label(int play_state) -{ - gchar* label = ">"; - if(play_state == 1){ - label = "||"; - } - return label; } /** |