Mercurial > pidgin
changeset 5170:13ffa9ae4282
[gaim-migrate @ 5534]
This makes the buddy ticker plugin work again, and may cause some slight
breakage in some plugins, since it slightly changes the behavior of:
event_buddy_signon
event_buddy_signoff
event_buddy_away
event_buddy_back
Then again, it's nothing compared to the massive breakage being thought up
for the very near future ;-)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 18 Apr 2003 21:49:45 +0000 |
parents | 71927464a1db |
children | 173ff9946424 |
files | plugins/ticker/gtkticker.c plugins/ticker/gtkticker.h plugins/ticker/ticker.c src/list.c src/server.c |
diffstat | 5 files changed, 449 insertions(+), 697 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/ticker/gtkticker.c Fri Apr 18 21:01:38 2003 +0000 +++ b/plugins/ticker/gtkticker.c Fri Apr 18 21:49:45 2003 +0000 @@ -30,538 +30,477 @@ static void gtk_ticker_map (GtkWidget *widget); static void gtk_ticker_realize (GtkWidget *widget); static void gtk_ticker_size_request (GtkWidget *widget, - GtkRequisition *requisition); + GtkRequisition *requisition); static void gtk_ticker_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint gtk_ticker_expose (GtkWidget *widget, - GdkEventExpose *event); + GtkAllocation *allocation); static void gtk_ticker_add_real (GtkContainer *container, - GtkWidget *widget); + GtkWidget *widget); static void gtk_ticker_remove_real (GtkContainer *container, - GtkWidget *widget); + GtkWidget *widget); static void gtk_ticker_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); + gboolean include_internals, + GtkCallback callback, + gpointer callback_data); static GtkType gtk_ticker_child_type (GtkContainer *container); static GtkContainerClass *parent_class = NULL; -GType -gtk_ticker_get_type (void) +GType gtk_ticker_get_type (void) { - static GType ticker_type = 0; + static GType ticker_type = 0; - if (!ticker_type) - { - static const GTypeInfo ticker_info = - { - sizeof(GtkTickerClass), - NULL, - NULL, - (GClassInitFunc) gtk_ticker_class_init, - NULL, - NULL, - sizeof(GtkTicker), - 0, - (GInstanceInitFunc) gtk_ticker_init - }; + if (!ticker_type) + { + static const GTypeInfo ticker_info = + { + sizeof(GtkTickerClass), + NULL, + NULL, + (GClassInitFunc) gtk_ticker_class_init, + NULL, + NULL, + sizeof(GtkTicker), + 0, + (GInstanceInitFunc) gtk_ticker_init + }; - ticker_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTicker", - &ticker_info, 0); - } + ticker_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkTicker", + &ticker_info, 0); + } - return ticker_type; + return ticker_type; +} + +static void gtk_ticker_finalize(GObject *object) { + gtk_ticker_stop_scroll(GTK_TICKER(object)); + + G_OBJECT_CLASS(parent_class)->finalize(object); } -static void -gtk_ticker_class_init (GtkTickerClass *class) +static void gtk_ticker_class_init (GtkTickerClass *class) { - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; + GObjectClass *gobject_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; - object_class = (GtkObjectClass*) class; - widget_class = (GtkWidgetClass*) class; - container_class = (GtkContainerClass*) class; + gobject_class = (GObjectClass*) class; + widget_class = (GtkWidgetClass*) class; + container_class = (GtkContainerClass*) class; + + parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - parent_class = gtk_type_class (GTK_TYPE_CONTAINER); + gobject_class->finalize = gtk_ticker_finalize; - widget_class->map = gtk_ticker_map; - widget_class->realize = gtk_ticker_realize; - widget_class->size_request = gtk_ticker_size_request; - widget_class->size_allocate = gtk_ticker_size_allocate; - widget_class->expose_event = gtk_ticker_expose; + widget_class->map = gtk_ticker_map; + widget_class->realize = gtk_ticker_realize; + widget_class->size_request = gtk_ticker_size_request; + widget_class->size_allocate = gtk_ticker_size_allocate; - container_class->add = gtk_ticker_add_real; - container_class->remove = gtk_ticker_remove_real; - container_class->forall = gtk_ticker_forall; - container_class->child_type = gtk_ticker_child_type; + container_class->add = gtk_ticker_add_real; + container_class->remove = gtk_ticker_remove_real; + container_class->forall = gtk_ticker_forall; + container_class->child_type = gtk_ticker_child_type; } -static GtkType -gtk_ticker_child_type (GtkContainer *container) +static GtkType gtk_ticker_child_type (GtkContainer *container) { - return GTK_TYPE_WIDGET; + return GTK_TYPE_WIDGET; } -static void -gtk_ticker_init (GtkTicker *ticker) +static void gtk_ticker_init (GtkTicker *ticker) { - GTK_WIDGET_UNSET_FLAGS (ticker, GTK_NO_WINDOW); + GTK_WIDGET_UNSET_FLAGS (ticker, GTK_NO_WINDOW); - ticker->interval = (guint) 200; - ticker->scootch = (guint) 2; - ticker->children = NULL; - ticker->timer = 0; - ticker->dirty = TRUE; + ticker->interval = (guint) 200; + ticker->scootch = (guint) 2; + ticker->children = NULL; + ticker->timer = 0; + ticker->dirty = TRUE; } -GtkWidget* -gtk_ticker_new (void) +GtkWidget* gtk_ticker_new (void) { return GTK_WIDGET(g_object_new(GTK_TYPE_TICKER, NULL)); } -static void -gtk_ticker_put (GtkTicker *ticker, - GtkWidget *widget) +static void gtk_ticker_put (GtkTicker *ticker, GtkWidget *widget) { - GtkTickerChild *child_info; + GtkTickerChild *child_info; - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); - g_return_if_fail (widget != NULL); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (widget != NULL); - child_info = g_new(GtkTickerChild, 1); - child_info->widget = widget; - child_info->x = 0; + child_info = g_new(GtkTickerChild, 1); + child_info->widget = widget; + child_info->x = 0; - gtk_widget_set_parent(widget, GTK_WIDGET (ticker)); + gtk_widget_set_parent(widget, GTK_WIDGET (ticker)); - ticker->children = g_list_append (ticker->children, child_info); + ticker->children = g_list_append (ticker->children, child_info); - if (GTK_WIDGET_REALIZED (ticker)) - gtk_widget_realize (widget); + if (GTK_WIDGET_REALIZED (ticker)) + gtk_widget_realize (widget); - if (GTK_WIDGET_VISIBLE (ticker) && GTK_WIDGET_VISIBLE (widget)) - { - if (GTK_WIDGET_MAPPED (ticker)) - gtk_widget_map (widget); - - gtk_widget_queue_resize (GTK_WIDGET (ticker)); - } + if (GTK_WIDGET_VISIBLE (ticker) && GTK_WIDGET_VISIBLE (widget)) + { + if (GTK_WIDGET_MAPPED (ticker)) + gtk_widget_map (widget); + + gtk_widget_queue_resize (GTK_WIDGET (ticker)); + } } -void -gtk_ticker_set_interval (GtkTicker *ticker, gint interval ) +void gtk_ticker_set_interval (GtkTicker *ticker, gint interval) { - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); - if ( interval < 0 ) - interval = 200; - ticker->interval = interval; - + if ( interval < 0 ) + interval = 200; + ticker->interval = interval; } -guint -gtk_ticker_get_interval (GtkTicker *ticker ) +guint gtk_ticker_get_interval (GtkTicker *ticker) { - g_return_val_if_fail (ticker != NULL, -1); - g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); + g_return_val_if_fail (ticker != NULL, -1); + g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); - return ticker->interval; + return ticker->interval; } -void -gtk_ticker_set_scootch (GtkTicker *ticker, gint scootch ) +void gtk_ticker_set_scootch (GtkTicker *ticker, gint scootch) { - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); - if ( scootch <= 0 ) - scootch = 2; - ticker->scootch = scootch; - ticker->dirty = TRUE; + if (scootch <= 0) + scootch = 2; + ticker->scootch = scootch; + ticker->dirty = TRUE; } -guint -gtk_ticker_get_scootch (GtkTicker *ticker ) +guint gtk_ticker_get_scootch (GtkTicker *ticker ) { - g_return_val_if_fail (ticker != NULL, -1); - g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); + g_return_val_if_fail (ticker != NULL, -1); + g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); - return ticker->scootch; + return ticker->scootch; } -void -gtk_ticker_set_spacing (GtkTicker *ticker, gint spacing ) +void gtk_ticker_set_spacing (GtkTicker *ticker, gint spacing ) { - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); - if ( spacing < 0 ) - spacing = 0; - ticker->spacing = spacing; - ticker->dirty = TRUE; - + if ( spacing < 0 ) + spacing = 0; + ticker->spacing = spacing; + ticker->dirty = TRUE; } -static int -ticker_timeout( gpointer data ) +static int ticker_timeout(gpointer data) { GtkTicker *ticker = (GtkTicker *) data; - if (GTK_WIDGET_VISIBLE (ticker)) - gtk_widget_queue_resize (GTK_WIDGET (ticker)); + if (GTK_WIDGET_VISIBLE (ticker)) + gtk_widget_queue_resize (GTK_WIDGET (ticker)); return( TRUE ); } -void -gtk_ticker_start_scroll(GtkTicker *ticker) +void gtk_ticker_start_scroll(GtkTicker *ticker) { - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); if ( ticker->timer != 0 ) return; ticker->timer = g_timeout_add(ticker->interval, ticker_timeout, ticker); } -void -gtk_ticker_stop_scroll(GtkTicker *ticker) +void gtk_ticker_stop_scroll(GtkTicker *ticker) { - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER (ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER (ticker)); if ( ticker->timer == 0 ) return; g_source_remove(ticker->timer); ticker->timer = 0; - } -guint -gtk_ticker_get_spacing (GtkTicker *ticker ) +guint gtk_ticker_get_spacing (GtkTicker *ticker ) { - g_return_val_if_fail (ticker != NULL, -1); - g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); + g_return_val_if_fail (ticker != NULL, -1); + g_return_val_if_fail (GTK_IS_TICKER (ticker), -1); - return ticker->spacing; + return ticker->spacing; } -static void -gtk_ticker_map (GtkWidget *widget) +static void gtk_ticker_map (GtkWidget *widget) { - GtkTicker *ticker; - GtkTickerChild *child; - GList *children; + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TICKER (widget)); + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER (widget)); - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - ticker = GTK_TICKER (widget); + GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); + ticker = GTK_TICKER (widget); - children = ticker->children; - while (children) - { - child = children->data; - children = children->next; + children = ticker->children; + while (children) + { + child = children->data; + children = children->next; - if (GTK_WIDGET_VISIBLE (child->widget) && - !GTK_WIDGET_MAPPED (child->widget)) - gtk_widget_map (child->widget); - } + if (GTK_WIDGET_VISIBLE (child->widget) && + !GTK_WIDGET_MAPPED (child->widget)) + gtk_widget_map (child->widget); + } - gdk_window_show (widget->window); + gdk_window_show (widget->window); } -static void -gtk_ticker_realize (GtkWidget *widget) +static void gtk_ticker_realize (GtkWidget *widget) { - GdkWindowAttr attributes; - gint attributes_mask; + GdkWindowAttr attributes; + gint attributes_mask; - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TICKER (widget)); + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER (widget)); - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = widget->allocation.x; + attributes.y = widget->allocation.y; + attributes.width = widget->allocation.width; + attributes.height = widget->allocation.height; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); + widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, attributes_mask); + gdk_window_set_user_data (widget->window, widget); - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); } -static void -gtk_ticker_size_request (GtkWidget *widget, - GtkRequisition *requisition) +static void gtk_ticker_size_request (GtkWidget *widget, GtkRequisition *requisition) { - GtkTicker *ticker; - GtkTickerChild *child; - GList *children; - GtkRequisition child_requisition; + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + GtkRequisition child_requisition; - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TICKER (widget)); - g_return_if_fail (requisition != NULL); + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER (widget)); + g_return_if_fail (requisition != NULL); - ticker = GTK_TICKER (widget); - requisition->width = 0; - requisition->height = 0; + ticker = GTK_TICKER (widget); + requisition->width = 0; + requisition->height = 0; - children = ticker->children; - while (children) - { - child = children->data; - children = children->next; + children = ticker->children; + while (children) + { + child = children->data; + children = children->next; - if (GTK_WIDGET_VISIBLE (child->widget)) - { - gtk_widget_size_request (child->widget, &child_requisition); + if (GTK_WIDGET_VISIBLE (child->widget)) + { + gtk_widget_size_request (child->widget, &child_requisition); - requisition->height = MAX (requisition->height, - child_requisition.height); - requisition->width += child_requisition.width + ticker->spacing; + requisition->height = MAX (requisition->height, + child_requisition.height); + requisition->width += child_requisition.width + ticker->spacing; + } } - } - if ( requisition->width > ticker->spacing ) - requisition->width -= ticker->spacing; + if ( requisition->width > ticker->spacing ) + requisition->width -= ticker->spacing; - requisition->height += GTK_CONTAINER (ticker)->border_width * 2; - requisition->width += GTK_CONTAINER (ticker)->border_width * 2; + requisition->height += GTK_CONTAINER (ticker)->border_width * 2; + requisition->width += GTK_CONTAINER (ticker)->border_width * 2; } -static void -gtk_ticker_compute_offsets (GtkTicker *ticker) +static void gtk_ticker_compute_offsets (GtkTicker *ticker) { - GtkTickerChild *child; - GtkRequisition child_requisition; - GList *children; - guint16 border_width; + GtkTickerChild *child; + GtkRequisition child_requisition; + GList *children; + guint16 border_width; - g_return_if_fail (ticker != NULL); - g_return_if_fail (GTK_IS_TICKER(ticker)); + g_return_if_fail (ticker != NULL); + g_return_if_fail (GTK_IS_TICKER(ticker)); - border_width = GTK_CONTAINER (ticker)->border_width; + border_width = GTK_CONTAINER (ticker)->border_width; - ticker->width = GTK_WIDGET(ticker)->allocation.width; - ticker->total = 0; - children = ticker->children; - while (children) { - child = children->data; - - child->x = 0; - if (GTK_WIDGET_VISIBLE (child->widget)) { - gtk_widget_get_child_requisition (child->widget, &child_requisition); - child->offset = ticker->total; - ticker->total += - child_requisition.width + border_width + ticker->spacing; - } - children = children->next; - } - ticker->dirty = FALSE; + ticker->width = GTK_WIDGET(ticker)->allocation.width; + ticker->total = 0; + children = ticker->children; + while (children) { + child = children->data; + + child->x = 0; + if (GTK_WIDGET_VISIBLE (child->widget)) { + gtk_widget_get_child_requisition (child->widget, &child_requisition); + child->offset = ticker->total; + ticker->total += + child_requisition.width + border_width + ticker->spacing; + } + children = children->next; + } + ticker->dirty = FALSE; } -static void -gtk_ticker_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) +static void gtk_ticker_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) { - GtkTicker *ticker; - GtkTickerChild *child; - GtkAllocation child_allocation; - GtkRequisition child_requisition; - GList *children; - guint16 border_width; + GtkTicker *ticker; + GtkTickerChild *child; + GtkAllocation child_allocation; + GtkRequisition child_requisition; + GList *children; + guint16 border_width; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_TICKER(widget)); + g_return_if_fail (allocation != NULL); + + ticker = GTK_TICKER (widget); - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TICKER(widget)); - g_return_if_fail (allocation != NULL); + if ( GTK_WIDGET(ticker)->allocation.width != ticker->width ) + ticker->dirty = TRUE; - ticker = GTK_TICKER (widget); + if ( ticker->dirty == TRUE ) { + gtk_ticker_compute_offsets( ticker ); + } - if ( GTK_WIDGET(ticker)->allocation.width != ticker->width ) - ticker->dirty = TRUE; + widget->allocation = *allocation; + if (GTK_WIDGET_REALIZED (widget)) + gdk_window_move_resize (widget->window, + allocation->x, + allocation->y, + allocation->width, + allocation->height); - if ( ticker->dirty == TRUE ) { - gtk_ticker_compute_offsets( ticker ); - } + border_width = GTK_CONTAINER (ticker)->border_width; - widget->allocation = *allocation; - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, - allocation->y, - allocation->width, - allocation->height); - - border_width = GTK_CONTAINER (ticker)->border_width; + children = ticker->children; + while (children) + { + child = children->data; + child->x -= ticker->scootch; - children = ticker->children; - while (children) - { - child = children->data; - child->x -= ticker->scootch; - - if (GTK_WIDGET_VISIBLE (child->widget)) { - gtk_widget_get_child_requisition (child->widget, &child_requisition); - child_allocation.width = child_requisition.width; - child_allocation.x = child->offset + border_width + child->x; - if ( ( child_allocation.x + child_allocation.width ) < GTK_WIDGET(ticker)->allocation.x ) { - if ( ticker->total >= GTK_WIDGET(ticker)->allocation.width ) { - child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width + ( ticker->total - ( GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width ) ); + if (GTK_WIDGET_VISIBLE (child->widget)) { + gtk_widget_get_child_requisition (child->widget, &child_requisition); + child_allocation.width = child_requisition.width; + child_allocation.x = child->offset + border_width + child->x; + if ( ( child_allocation.x + child_allocation.width ) < GTK_WIDGET(ticker)->allocation.x ) { + if ( ticker->total >= GTK_WIDGET(ticker)->allocation.width ) { + child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width + ( ticker->total - ( GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width ) ); + } + else { + child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width; + } + } + child_allocation.y = border_width; + child_allocation.height = child_requisition.height; + gtk_widget_size_allocate (child->widget, &child_allocation); } - else { - child->x += GTK_WIDGET(ticker)->allocation.x + GTK_WIDGET(ticker)->allocation.width; - } - } - child_allocation.y = border_width; - child_allocation.height = child_requisition.height; - gtk_widget_size_allocate (child->widget, &child_allocation); - } - children = children->next; - } + children = children->next; + } +} + +void gtk_ticker_add(GtkTicker *ticker, GtkWidget *widget) +{ + gtk_ticker_add_real( GTK_CONTAINER( ticker ), widget ); + ticker->dirty = TRUE; +} + +void gtk_ticker_remove(GtkTicker *ticker, GtkWidget *widget) +{ + gtk_ticker_remove_real( GTK_CONTAINER( ticker ), widget ); + ticker->dirty = TRUE; } -static gint -gtk_ticker_expose (GtkWidget *widget, GdkEventExpose *event) +static void gtk_ticker_add_real(GtkContainer *container, GtkWidget *widget) { - GtkTicker *ticker; - GtkTickerChild *child; - GdkEventExpose child_event; - GList *children; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_TICKER (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - ticker = GTK_TICKER (widget); - - child_event = *event; - - children = ticker->children; - while (children) - { - child = children->data; - children = children->next; + g_return_if_fail (container != NULL); + g_return_if_fail (GTK_IS_TICKER (container)); + g_return_if_fail (widget != NULL); - if (GTK_WIDGET_NO_WINDOW (child->widget) && - gtk_widget_intersect (child->widget, &event->area, - &child_event.area)) - gtk_widget_event (child->widget, (GdkEvent*) &child_event); - } - } - - return FALSE; -} - - -void -gtk_ticker_add(GtkTicker *ticker, GtkWidget *widget) -{ - gtk_ticker_add_real( GTK_CONTAINER( ticker ), widget ); - ticker->dirty = TRUE; -} - -void -gtk_ticker_remove(GtkTicker *ticker, GtkWidget *widget) -{ - gtk_ticker_remove_real( GTK_CONTAINER( ticker ), widget ); - ticker->dirty = TRUE; -} - -static void -gtk_ticker_add_real(GtkContainer *container, - GtkWidget *widget) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_TICKER (container)); - g_return_if_fail (widget != NULL); - - gtk_ticker_put(GTK_TICKER (container), widget); + gtk_ticker_put(GTK_TICKER (container), widget); } -static void -gtk_ticker_remove_real(GtkContainer *container, - GtkWidget *widget) +static void gtk_ticker_remove_real(GtkContainer *container, GtkWidget *widget) { - GtkTicker *ticker; - GtkTickerChild *child; - GList *children; + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_TICKER (container)); - g_return_if_fail (widget != NULL); + g_return_if_fail (container != NULL); + g_return_if_fail (GTK_IS_TICKER (container)); + g_return_if_fail (widget != NULL); - ticker = GTK_TICKER (container); + ticker = GTK_TICKER (container); - children = ticker->children; - while (children) - { - child = children->data; + children = ticker->children; + while (children) + { + child = children->data; - if (child->widget == widget) - { - gboolean was_visible = GTK_WIDGET_VISIBLE (widget); - - gtk_widget_unparent (widget); + if (child->widget == widget) + { + gboolean was_visible = GTK_WIDGET_VISIBLE (widget); + + gtk_widget_unparent (widget); - ticker->children = g_list_remove_link (ticker->children, children); - g_list_free (children); - g_free (child); + ticker->children = g_list_remove_link (ticker->children, children); + g_list_free (children); + g_free (child); - if (was_visible && GTK_WIDGET_VISIBLE (container)) - gtk_widget_queue_resize (GTK_WIDGET (container)); + if (was_visible && GTK_WIDGET_VISIBLE (container)) + gtk_widget_queue_resize (GTK_WIDGET (container)); - break; - } + break; + } - children = children->next; - } + children = children->next; + } } -static void -gtk_ticker_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) +static void gtk_ticker_forall (GtkContainer *container, + gboolean include_internals, + GtkCallback callback, + gpointer callback_data) { - GtkTicker *ticker; - GtkTickerChild *child; - GList *children; + GtkTicker *ticker; + GtkTickerChild *child; + GList *children; + + g_return_if_fail (container != NULL); + g_return_if_fail (GTK_IS_TICKER (container)); + g_return_if_fail (callback != NULL); - g_return_if_fail (container != NULL); - g_return_if_fail (GTK_IS_TICKER (container)); - g_return_if_fail (callback != NULL); - - ticker = GTK_TICKER (container); + ticker = GTK_TICKER (container); - children = ticker->children; - while (children) - { - child = children->data; - children = children->next; + children = ticker->children; + while (children) + { + child = children->data; + children = children->next; - (* callback) (child->widget, callback_data); - } + (* callback) (child->widget, callback_data); + } } +
--- a/plugins/ticker/gtkticker.h Fri Apr 18 21:01:38 2003 +0000 +++ b/plugins/ticker/gtkticker.h Fri Apr 18 21:49:45 2003 +0000 @@ -57,7 +57,7 @@ guint total; /* total width of widgets */ guint width; /* width of containing window */ gboolean dirty; - GList *children; + GList *children; }; struct _GtkTickerClass @@ -69,7 +69,7 @@ { GtkWidget *widget; gint x; /* current position */ - gint offset; /* offset in list */ + gint offset; /* offset in list */ };
--- a/plugins/ticker/ticker.c Fri Apr 18 21:01:38 2003 +0000 +++ b/plugins/ticker/ticker.c Fri Apr 18 21:49:45 2003 +0000 @@ -28,7 +28,8 @@ #include <string.h> #include <stdlib.h> #include "gaim.h" -#include "prpl.h" +#include "list.h" +#include "gtklist.h" #ifdef _WIN32 #include "win32dep.h" #endif @@ -42,348 +43,151 @@ static GModule *handle; typedef struct { - char buddy[ 128 ]; - char alias[ 388 ]; - GtkWidget *hbox; + struct buddy *buddy; GtkWidget *ebox; GtkWidget *label; - GtkWidget *pix; + GtkWidget *icon; } TickerData; -GList *tickerbuds = (GList *) NULL; -gboolean userclose = FALSE; -GtkWidget *msgw; +GList *tickerbuds = NULL; /* for win32 compatability */ G_MODULE_IMPORT GSList *connections; -G_MODULE_IMPORT GtkWidget *blist; -void BuddyTickerDestroyWindow( GtkWidget *window ); -void BuddyTickerCreateWindow( void ); -void BuddyTickerAddUser( char *name, char *alias, const char *pb); -void BuddyTickerRemoveUser( char *name ); -void BuddyTickerSetPixmap( char *name, const char *pb); -void BuddyTickerClearList( void ); -void BuddyTickerSignOff( void ); -GList * BuddyTickerFindUser( char *name ); -int BuddyTickerMessageRemove( gpointer data ); -void BuddyTickerShow(); - -void -BuddyTickerDestroyWindow( GtkWidget *window ) -{ - BuddyTickerClearList(); - gtk_ticker_stop_scroll( GTK_TICKER( ticker ) ); - gtk_widget_destroy( window ); - ticker = tickerwindow = (GtkWidget *) NULL; - userclose = TRUE; +static void buddy_ticker_destroy_window(GtkWidget *window, gpointer data) { + gtk_widget_hide(window); } -/* static char *msg = "Welcome to Gaim " VERSION ", brought to you by Rob Flynn (maintainer), Eric Warmenhoven, Mark Spencer, Jeramey Crawford, Jim Duchek, Syd Logan, and Sean Egan"; - */ - -void -BuddyTickerCreateWindow() -{ +static void buddy_ticker_create_window() { + if(tickerwindow) { + gtk_widget_show(tickerwindow); + return; + } - if ( tickerwindow != (GtkWidget *) NULL ) - return; - debug_printf("Making ticker\n"); - tickerwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_signal_connect (GTK_OBJECT(tickerwindow), "destroy", - G_CALLBACK (BuddyTickerDestroyWindow), "WM destroy"); - gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Gaim - Buddy Ticker")); + tickerwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(G_OBJECT(tickerwindow), "destroy", + G_CALLBACK (buddy_ticker_destroy_window), NULL); + gtk_window_set_title (GTK_WINDOW(tickerwindow), _("Buddy Ticker")); gtk_window_set_role (GTK_WINDOW(tickerwindow), "ticker"); - gtk_widget_realize(tickerwindow); ticker = gtk_ticker_new(); - if (!ticker) - return; - gtk_ticker_set_spacing( GTK_TICKER( ticker ), 20 ); - gtk_widget_set_size_request( ticker, 500, -1 ); - gtk_container_add( GTK_CONTAINER( tickerwindow ), ticker ); - gtk_ticker_set_interval( GTK_TICKER( ticker ), 500 ); - gtk_ticker_set_scootch( GTK_TICKER( ticker ), 10 ); - /* Damned egotists - msgw = gtk_label_new( msg ); - gtk_ticker_add( GTK_TICKER( ticker ), msgw ); - */ - gtk_ticker_start_scroll( GTK_TICKER( ticker ) ); + gtk_ticker_set_spacing(GTK_TICKER(ticker), 20); + gtk_container_add(GTK_CONTAINER(tickerwindow), ticker); + gtk_ticker_set_interval(GTK_TICKER(ticker), 500); + gtk_ticker_set_scootch(GTK_TICKER(ticker), 10); + gtk_ticker_start_scroll(GTK_TICKER(ticker)); + gtk_widget_set_size_request(ticker, 500, -1); - g_timeout_add( 60000, BuddyTickerMessageRemove, NULL); - - gtk_widget_show_all (ticker); - + gtk_widget_show_all(tickerwindow); } -gint -ButtonPressCallback( GtkWidget *widget, GdkEvent *event, gpointer callback_data ) -{ - TickerData *p = (TickerData *) callback_data; - struct gaim_buddy_list *gaimbuddylist; - GaimBlistNode *group; - GaimBlistNode *buddy; - struct buddy *b = NULL; - char *norm_name = g_strdup(normalize(p->buddy)); - - if (!(gaimbuddylist = gaim_get_blist())) - return TRUE; +static gboolean buddy_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { + struct buddy *b = user_data; - group = gaimbuddylist->root; - while (group) { - buddy = group->child; - while (buddy) { - if (!gaim_utf8_strcasecmp(normalize(((struct buddy*)buddy)->name), norm_name)) - b = (struct buddy*)buddy; - buddy = buddy->next; - } - group = group->next; - } - g_free(norm_name); - - if (b->account) - gaim_conversation_new(GAIM_CONV_IM, b->account, p->buddy); - + gaim_conversation_new(GAIM_CONV_IM, b->account, b->name); return TRUE; } -void -BuddyTickerAddUser( char *name, char *alias, const char *pb) -{ - TickerData *p; - GList *q; +static TickerData *buddy_ticker_find_buddy(struct buddy *b) { + GList *tb; + for(tb = tickerbuds; tb; tb = tb->next) { + TickerData *td = tb->data; + if(td->buddy == b) + return td; + } + return NULL; +} + +static void buddy_ticker_set_pixmap(struct buddy *b) { + TickerData *td = buddy_ticker_find_buddy(b); + GdkPixbuf *pixbuf; - if ( userclose == TRUE ) + if(!td) return; - - debug_printf("Adding %s\n", name); + + if(!td->icon) + td->icon = gtk_image_new(); - BuddyTickerCreateWindow(); + pixbuf = gaim_gtk_blist_get_status_icon(b, GAIM_STATUS_ICON_SMALL); + gtk_image_set_from_pixbuf(GTK_IMAGE(td->icon), pixbuf); + g_object_unref(G_OBJECT(pixbuf)); +} + +static void buddy_ticker_add_buddy(struct buddy *b) { + GtkWidget *hbox; + TickerData *td; + + buddy_ticker_create_window(); if (!ticker) return; - q = (GList *) BuddyTickerFindUser( name ); - if ( q != (GList *) NULL ) - return; - - p = (TickerData *) malloc( sizeof( TickerData ) ); - p->hbox = (GtkWidget *) NULL; - p->label = (GtkWidget *) NULL; - p->pix = (GtkWidget *) NULL; - strcpy( p->buddy, name ); - strcpy( p->alias, alias); - tickerbuds = g_list_append( tickerbuds, p ); - - p->hbox = gtk_hbox_new( FALSE, 0 ); - gtk_ticker_add( GTK_TICKER( ticker ), p->hbox ); - gtk_widget_show_all( p->hbox ); - - BuddyTickerSetPixmap(name, pb); - - p->ebox = gtk_event_box_new(); - - /* click detection */ - - gtk_widget_set_events (p->ebox, GDK_BUTTON_PRESS_MASK); - g_signal_connect (GTK_OBJECT (p->ebox), "button_press_event", - G_CALLBACK(ButtonPressCallback), (gpointer) p); - - gtk_box_pack_start_defaults( GTK_BOX( p->hbox ), p->ebox ); - gtk_widget_show( p->ebox ); - - if (im_options & OPT_IM_ALIAS_TAB) - p->label = gtk_label_new( alias ); - else - p->label = gtk_label_new( name ); - gtk_container_add( GTK_CONTAINER(p->ebox), p->label ); - - gtk_widget_show( p->label ); - - gtk_widget_show( tickerwindow ); -} - -void -BuddyTickerRemoveUser( char *name ) -{ - GList *p = (GList *) BuddyTickerFindUser( name ); - TickerData *data; - - if ( !p ) + if(buddy_ticker_find_buddy(b)) return; - data = (TickerData *) p->data; - - if ( userclose == TRUE ) - return; - if ( data ) { - gtk_ticker_remove( GTK_TICKER( ticker ), data->hbox ); - tickerbuds = g_list_remove( tickerbuds, data ); - free( data ); - } -} + td = g_new0(TickerData, 1); + td->buddy = b; + tickerbuds = g_list_append(tickerbuds, td); -void -BuddyTickerSetPixmap( char *name, const char *pb) -{ - GList *p; - TickerData *data; - char *file = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", pb, NULL); - - if ( userclose == TRUE ) - return; - p = (GList *) BuddyTickerFindUser( name ); - if ( p ) - data = (TickerData *) p->data; - else - return; - if ( data->pix == (GtkWidget *) NULL ) { - data->pix = gtk_image_new_from_file(file); - gtk_box_pack_start_defaults( GTK_BOX( data->hbox ), data->pix ); - } else { - gtk_widget_hide( data->pix ); - gtk_image_set_from_file(GTK_IMAGE(data->pix), file); - } - gtk_widget_show( data->pix ); -} + td->ebox = gtk_event_box_new(); + gtk_ticker_add(GTK_TICKER(ticker), td->ebox); + hbox = gtk_hbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(td->ebox), hbox); + buddy_ticker_set_pixmap(b); + gtk_box_pack_start(GTK_BOX(hbox), td->icon, FALSE, FALSE, 5); -void -BuddyTickerSetAlias( char *name, char *alias) { - GList *p; - TickerData *data; + g_signal_connect(G_OBJECT(td->ebox), "button-press-event", + G_CALLBACK(buddy_click_cb), b); - if ( userclose == TRUE ) - return; - p = (GList *) BuddyTickerFindUser( name ); - if ( p ) - data = (TickerData *) p->data; - else - return; - if (alias) { - g_snprintf(data->alias, sizeof(data->alias), alias); - - if (im_options & OPT_IM_ALIAS_TAB) - gtk_label_set_text(GTK_LABEL(data->label), alias); - } + td->label = gtk_label_new(gaim_get_buddy_alias(b)); + gtk_box_pack_start(GTK_BOX(hbox), td->label, FALSE, FALSE, 5); + + gtk_widget_show_all(td->ebox); + gtk_widget_show(tickerwindow); } -GList * -BuddyTickerFindUser( char *name ) -{ - GList *p = tickerbuds; - - while ( p ) { - TickerData *q = (TickerData *) p->data; - if ( !strcmp( name, q->buddy ) ) - return( p ); - p = p->next; - } - return (GList *) NULL; -} +static void buddy_ticker_remove_buddy(struct buddy *b) { + TickerData *td = buddy_ticker_find_buddy(b); -void -BuddyTickerSetNames() -{ - GList *p = tickerbuds; - while ( p ) { - TickerData *q = (TickerData *) p->data; - if (im_options & OPT_IM_ALIAS_TAB) - gtk_label_set_text(GTK_LABEL(q->label), q->alias); - else - gtk_label_set_text(GTK_LABEL(q->label), q->buddy); - p = p->next; - } -} + if (!td) + return; -int -BuddyTickerMessageRemove( gpointer data ) -{ - if ( userclose == TRUE ) - return FALSE; - if ( tickerwindow == NULL ) - return FALSE; - gtk_ticker_remove( GTK_TICKER( ticker ), msgw ); - return FALSE; -} - -int -BuddyTickerLogonTimeout( gpointer data ) -{ - return FALSE; + gtk_ticker_remove(GTK_TICKER(ticker), td->ebox); + tickerbuds = g_list_remove(tickerbuds, td); + g_free(td); } -int -BuddyTickerLogoutTimeout( gpointer data ) +static void buddy_ticker_show() { - char *name = (char *) data; - - if ( userclose == TRUE ) - return FALSE; - BuddyTickerRemoveUser( name ); + struct gaim_buddy_list *list = gaim_get_blist(); + GaimBlistNode *gnode, *bnode; + struct buddy *b; - return FALSE; -} - -void -BuddyTickerSignoff( void ) -{ - GList *p = tickerbuds; - TickerData *q; + if(!list) + return; - while ( p ) { - q = (TickerData *) p->data; - if ( q ) - BuddyTickerRemoveUser( q->buddy ); - p = tickerbuds; - } - userclose = FALSE; - if ( tickerwindow ) - gtk_widget_hide( tickerwindow ); -} - -void -BuddyTickerClearList( void ) -{ - GList *p = tickerbuds; - - while ( p ) - p = g_list_remove( p, p->data ); - tickerbuds = (GList *) NULL; -} - -void BuddyTickerShow() -{ - /* Someone should fix the ticker - struct group *g; - struct buddy *b; - GSList *grps, *buds; - const char *xpm; - for( grps = groups; grps; grps = grps->next ) { - g = (struct group *)grps->data; - for( buds = g->members; buds; buds = buds->next ) { - b = (struct buddy *)buds->data; - if(GAIM_BUDDY_IS_ONLINE(b)) { - xpm = NULL; - if (b->account->gc->prpl->list_icon) - xpm = b->account->gc->prpl->list_icon(b->account, b); - BuddyTickerAddUser( b->name, gaim_get_buddy_alias(b), xpm); - } + for(gnode = list->root; gnode; gnode = gnode->next) { + if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) + continue; + for(bnode = gnode->child; bnode; bnode = bnode->next) { + if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) + continue; + b = (struct buddy *)bnode; + if(GAIM_BUDDY_IS_ONLINE(b)) + buddy_ticker_add_buddy(b); } } - */ } void signon_cb(struct gaim_connection *gc, char *who) { struct buddy *b = gaim_find_buddy(gc->account, who); - const char *xpm = NULL; - - if (gc->prpl->list_icon) - xpm = gc->prpl->list_icon(b->account, b); - - BuddyTickerAddUser(who, gaim_get_buddy_alias(b), xpm); + if(buddy_ticker_find_buddy(b)) + buddy_ticker_set_pixmap(b); + else + buddy_ticker_add_buddy(b); } void signoff_cb(struct gaim_connection *gc) { - if (connections && !connections->next) { + if (!connections) { gtk_widget_destroy(tickerwindow); tickerwindow = NULL; ticker = NULL; @@ -391,16 +195,17 @@ } void buddy_signoff_cb(struct gaim_connection *gc, char *who) { - BuddyTickerRemoveUser(who); + struct buddy *b = gaim_find_buddy(gc->account, who); + + buddy_ticker_remove_buddy(b); } void away_cb(struct gaim_connection *gc, char *who) { struct buddy *b = gaim_find_buddy(gc->account, who); - const char *xpm = NULL; - - if (gc->prpl->list_icon) - xpm = gc->prpl->list_icon(b->account, b); - BuddyTickerSetPixmap(who, xpm); + if(buddy_ticker_find_buddy(b)) + buddy_ticker_set_pixmap(b); + else + buddy_ticker_add_buddy(b); } /* @@ -417,21 +222,23 @@ G_MODULE_EXPORT char *gaim_plugin_init(GModule *h) { handle = h; - + gaim_signal_connect(h, event_buddy_signon, signon_cb, NULL); gaim_signal_connect(h, event_signoff, signoff_cb, NULL); gaim_signal_connect(h, event_buddy_signoff, buddy_signoff_cb, NULL); gaim_signal_connect(h, event_buddy_away, away_cb, NULL); + gaim_signal_connect(h, event_buddy_back, away_cb, NULL); if (connections) - BuddyTickerShow(); + buddy_ticker_show(); return NULL; } G_MODULE_EXPORT void gaim_plugin_remove() { - BuddyTickerDestroyWindow(tickerwindow); + buddy_ticker_destroy_window(tickerwindow, NULL); } -struct gaim_plugin_description desc; + +struct gaim_plugin_description desc; G_MODULE_EXPORT struct gaim_plugin_description *gaim_plugin_desc() { desc.api_version = PLUGIN_API_VERSION; desc.name = g_strdup(_("Buddy Ticker"));
--- a/src/list.c Fri Apr 18 21:01:38 2003 +0000 +++ b/src/list.c Fri Apr 18 21:49:45 2003 +0000 @@ -118,6 +118,12 @@ { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; buddy->uc = status; + + if(!(status & UC_UNAVAILABLE)) + plugin_event(event_buddy_back, buddy->account->gc, buddy->name); + else + plugin_event(event_buddy_away, buddy->account->gc, buddy->name); + if (ops) ops->update(gaimbuddylist, (GaimBlistNode*)buddy); } @@ -125,10 +131,12 @@ static gboolean presence_update_timeout_cb(struct buddy *buddy) { struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; - if(buddy->present == GAIM_BUDDY_SIGNING_ON) + if(buddy->present == GAIM_BUDDY_SIGNING_ON) { buddy->present = GAIM_BUDDY_ONLINE; - else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) + plugin_event(event_buddy_signon, buddy->account->gc, buddy->name); + } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { buddy->present = GAIM_BUDDY_OFFLINE; + } buddy->timer = 0; @@ -144,9 +152,11 @@ if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { buddy->present = GAIM_BUDDY_SIGNING_ON; + plugin_event(event_buddy_signon, buddy->account->gc, buddy->name); do_timer = TRUE; } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { buddy->present = GAIM_BUDDY_SIGNING_OFF; + plugin_event(event_buddy_signoff, buddy->account->gc, buddy->name); do_timer = TRUE; }
--- a/src/server.c Fri Apr 18 21:01:38 2003 +0000 +++ b/src/server.c Fri Apr 18 21:49:45 2003 +0000 @@ -882,16 +882,14 @@ if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) { gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_AWAY_RETURN); - plugin_event(event_buddy_back, gc, b->name); system_log(log_back, gc, b, OPT_LOG_BUDDY_AWAY); } else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) { gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_AWAY); - plugin_event(event_buddy_away, gc, b->name); system_log(log_away, gc, b, OPT_LOG_BUDDY_AWAY); } gaim_blist_update_buddy_status(b, type); - + if (loggedin) { if (!GAIM_BUDDY_IS_ONLINE(b)) { @@ -914,7 +912,6 @@ } gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE); gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_SIGNON); - plugin_event(event_buddy_signon, gc, b->name); system_log(log_signon, gc, b, OPT_LOG_BUDDY_SIGNON); } } else { @@ -938,7 +935,6 @@ } gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE); gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_SIGNOFF); - plugin_event(event_buddy_signoff, gc, b->name); system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON); } }