From 85dcb08a9ba503d5079af78431e95044416e3374 Mon Sep 17 00:00:00 2001 From: Artem Garmash Date: Sun, 10 Jan 2010 23:58:51 +0200 Subject: [PATCH] Refactor handling of active parts --- src/el-home-applet.c | 59 +++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/el-home-applet.c b/src/el-home-applet.c index 4f7858e..666dc02 100644 --- a/src/el-home-applet.c +++ b/src/el-home-applet.c @@ -65,6 +65,13 @@ #define NOTIFICATION_UI_DBUS_PATH "/org/freedesktop/Telepathy/Client/NotificationUI" #define NOTIFICATION_UI_DBUS_IFACE "com.nokia.RtcomNotificationUi" +typedef enum { + SELECTED_NONE, + SELECTED_HEADER, + SELECTED_BODY, + SELECTED_FOOTER +} WidgetActiveSelection; + struct _ELHomeAppletPrivate { RTComEl *eventlogger; @@ -80,8 +87,7 @@ struct _ELHomeAppletPrivate gchar *message; gint event_id; - gboolean active_body; - gboolean active_header; + WidgetActiveSelection active; guint unread_count; @@ -327,14 +333,18 @@ expose_event (GtkWidget *self, GdkEventExpose *event) cairo_close_path (cr); - if (priv->active_header) + switch (priv->active) { + case SELECTED_HEADER: cairo_set_source_rgba (cr, priv->active_color.red, priv->active_color.green, priv->active_color.blue, 0.8f); - else + break; + default: cairo_set_source_rgba (cr, 0.2f, 0.2f, 0.2f, 0.8f); + } + cairo_fill (cr); cairo_move_to (cr, 0, HEADER_HEIGHT); @@ -361,7 +371,8 @@ expose_event (GtkWidget *self, GdkEventExpose *event) grad = cairo_pattern_create_linear (0, HEADER_HEIGHT, 0, C_HEIGHT); - if (priv->active_body) { + switch (priv->active) { + case SELECTED_BODY: cairo_pattern_add_color_stop_rgba (grad, 0.5f, priv->active_color.red, @@ -374,13 +385,14 @@ expose_event (GtkWidget *self, GdkEventExpose *event) priv->active_color.green/2, priv->active_color.blue/2, 0.8f); - } - else { + break; + default: cairo_pattern_add_color_stop_rgba (grad, 0.5f, 0.4f, 0.4f, 0.4f, 0.8f); cairo_pattern_add_color_stop_rgba (grad, 1.0f, 0.2f, 0.2f, 0.2f, 0.8f); } + cairo_set_source (cr, grad); cairo_fill (cr); @@ -563,7 +575,6 @@ aggregator_ready_cb (OssoABookWaitable *waitable, osso_abook_contact_get_uid (priv->contact), osso_abook_contact_get_persistent_uid (priv->contact)); - if (avatar_image) { gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar), avatar_image); @@ -1021,10 +1032,10 @@ button_press_event_cb (GtkWidget *widget, if (priv->aggregator && osso_abook_waitable_is_ready (OSSO_ABOOK_WAITABLE (priv->aggregator), NULL)) - priv->active_header = TRUE; + priv->active = SELECTED_HEADER; } else - priv->active_body = TRUE; + priv->active = SELECTED_BODY; gtk_widget_queue_draw (widget); } @@ -1090,8 +1101,8 @@ button_release_event_cb (GtkWidget *widget, ELHomeAppletPrivate *priv = self->priv; g_warning (G_STRFUNC); - if (priv->active_body) { - priv->active_body = FALSE; + switch (priv->active) { + case SELECTED_BODY: stop_scroll_anim (priv); if (priv->scroll_on_click) { priv->scroll_on_click = FALSE; @@ -1105,12 +1116,11 @@ button_release_event_cb (GtkWidget *widget, open_conversation (self); #endif } - gtk_widget_queue_draw (widget); - } - if (priv->active_header) { + + break; + case SELECTED_HEADER: { GtkWidget *dialog = NULL; - priv->active_header = FALSE; if (priv->aggregator && priv->contact_id) dialog = create_contact_starter_dialog @@ -1127,7 +1137,11 @@ button_release_event_cb (GtkWidget *widget, gtk_widget_queue_draw (widget); } + break; + default:; + } + priv->active = SELECTED_NONE; return TRUE; } @@ -1138,17 +1152,18 @@ leave_notify_event_cb (GtkWidget *widget, { ELHomeAppletPrivate *priv = self->priv; - if (priv->active_body) { - priv->active_body = FALSE; - priv->active_header = FALSE; + switch (priv->active) { + case SELECTED_BODY: stop_scroll_anim (priv); gtk_widget_queue_draw (widget); - } - if (priv->active_header) { - priv->active_header = FALSE; + break; + case SELECTED_HEADER: gtk_widget_queue_draw (widget); + break; + default:; } + priv->active = SELECTED_NONE; return FALSE; } -- 1.7.9.5