Changeset 2477

Show
Ignore:
Timestamp:
01/23/06 01:10:55
Author:
chipx86
Message:

Make a best attempt at clearing away notifications that require actions or that exist until clicked when the calling application exits. This doesn't always work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libnotify/ChangeLog

    r2469 r2477  
     1Mon Jan 23 01:10:23 PST 2006  Christian Hammond <chipx86@chipx86.com> 
     2 
     3    * libnotify/internal.h: 
     4    * libnotify/notification.c: 
     5    * libnotify/notify.c: 
     6    * tests/test-replace-widget.c: 
     7      - Make a best attempt at clearing away notifications that require 
     8        actions or that exist until clicked when the calling application 
     9        exits. This doesn't always work. 
     10 
    111Sun Jan 22 23:46:27 PST 2006  Christian Hammond <chipx86@chipx86.com> 
    212 
  • trunk/libnotify/libnotify/internal.h

    r2457 r2477  
    3737#define NOTIFY_DBUS_CORE_OBJECT    "/org/freedesktop/Notifications" 
    3838 
    39 DBusGConnection *get_dbus_g_conn(void); 
    40 DBusGProxy *get_g_proxy(void); 
     39DBusGConnection *_notify_get_dbus_g_conn(void); 
     40DBusGProxy *_notify_get_g_proxy(void); 
     41 
     42void _notify_cache_add_notification(NotifyNotification *n); 
     43void _notify_cache_remove_notification(NotifyNotification *n); 
     44gint _notify_notification_get_timeout(const NotifyNotification *n); 
     45gboolean _notify_notification_has_nondefault_actions( 
     46    const NotifyNotification *n); 
    4147 
    4248#endif /* _LIBNOTIFY_INTERNAL_H_ */ 
  • trunk/libnotify/libnotify/notification.c

    r2469 r2477  
    7373    gint widget_old_y; 
    7474 
     75    gboolean has_nondefault_actions; 
    7576    gboolean updates_pending; 
    7677    gboolean signals_registered; 
     
    142143    NotifyNotification *obj = NOTIFY_NOTIFICATION(object); 
    143144    NotifyNotificationPrivate *priv = obj->priv; 
    144     DBusGProxy *proxy = get_g_proxy(); 
     145    DBusGProxy *proxy = _notify_get_g_proxy(); 
     146 
     147    _notify_cache_remove_notification(obj); 
    145148 
    146149    g_free(priv->summary); 
     
    283286    } 
    284287 
     288    _notify_cache_add_notification(obj); 
     289 
    285290    return obj; 
    286291} 
     
    381386 
    382387    priv = notification->priv; 
    383     proxy = get_g_proxy(); 
     388    proxy = _notify_get_g_proxy(); 
    384389 
    385390    if (!priv->signals_registered) 
     
    438443} 
    439444 
     445gint 
     446_notify_notification_get_timeout(const NotifyNotification *notification) 
     447{ 
     448    g_return_val_if_fail(notification != NULL, -1); 
     449    g_return_val_if_fail(NOTIFY_IS_NOTIFICATION(notification), -1); 
     450 
     451    return notification->priv->timeout; 
     452} 
     453 
    440454void 
    441455notify_notification_set_category(NotifyNotification *notification, 
     
    693707 
    694708    notification->priv->actions = NULL; 
     709    notification->priv->has_nondefault_actions = FALSE; 
    695710} 
    696711 
     
    720735    pair->user_data = user_data; 
    721736    g_hash_table_insert(priv->action_map, g_strdup(action), pair); 
     737 
     738    if (notification->priv->has_nondefault_actions && 
     739        g_ascii_strcasecmp(action, "default")) 
     740    { 
     741        notification->priv->has_nondefault_actions = TRUE; 
     742    } 
     743} 
     744 
     745gboolean 
     746_notify_notification_has_nondefault_actions(const NotifyNotification *n) 
     747{ 
     748    g_return_val_if_fail(n != NULL, FALSE); 
     749    g_return_val_if_fail(NOTIFY_IS_NOTIFICATION(n), FALSE); 
     750 
     751    return n->priv->has_nondefault_actions; 
    722752} 
    723753 
     
    735765    priv = notification->priv; 
    736766 
    737     dbus_g_proxy_call(get_g_proxy(), "CloseNotification", &tmp_error, 
     767    dbus_g_proxy_call(_notify_get_g_proxy(), "CloseNotification", &tmp_error, 
    738768                      G_TYPE_UINT, priv->id, G_TYPE_INVALID, 
    739769                      G_TYPE_INVALID); 
  • trunk/libnotify/libnotify/notify.c

    r2457 r2477  
    3232static DBusGProxy *_proxy = NULL; 
    3333static DBusGConnection *_dbus_gconn = NULL; 
     34static GList *_active_notifications = NULL; 
    3435 
    3536#ifdef __GNUC__ 
     
    8182                            G_TYPE_INVALID); 
    8283 
    83 #ifdef HAVE_ATEXIT 
    84     atexit(notify_uninit); 
    85 #endif /* HAVE_ATEXIT */ 
     84    g_atexit(notify_uninit); 
    8685 
    8786    _initted = TRUE; 
     
    9998notify_uninit(void) 
    10099{ 
     100    GList *l; 
     101 
    101102    if (_app_name != NULL) 
    102103    { 
     
    105106    } 
    106107 
    107     /* 
    108      * TODO: Keep track of all notifications and destroy them here? 
    109      *       Definitely all notifications that don't expire. 
    110      */ 
     108    for (l = _active_notifications; l != NULL; l = l->next) 
     109    { 
     110        NotifyNotification *n = NOTIFY_NOTIFICATION(l->data); 
     111 
     112        if (_notify_notification_get_timeout(n) == 0 || 
     113            _notify_notification_has_nondefault_actions(n)) 
     114        { 
     115            notify_notification_close(n, NULL); 
     116        } 
     117    } 
    111118} 
    112119 
     
    118125 
    119126DBusGConnection * 
    120 get_dbus_g_conn(void) 
     127_notify_get_dbus_g_conn(void) 
    121128{ 
    122129    return _dbus_gconn; 
     
    124131 
    125132DBusGProxy * 
    126 get_g_proxy(void) 
     133_notify_get_g_proxy(void) 
    127134{ 
    128135    return _proxy; 
     
    135142    char **caps = NULL, **cap; 
    136143    GList *result = NULL; 
    137     DBusGProxy *proxy = get_g_proxy(); 
     144    DBusGProxy *proxy = _notify_get_g_proxy(); 
    138145 
    139146    g_return_val_if_fail(proxy != NULL, NULL); 
     
    163170{ 
    164171    GError *error = NULL; 
    165     DBusGProxy *proxy = get_g_proxy(); 
     172    DBusGProxy *proxy = _notify_get_g_proxy(); 
    166173    char *name, *vendor, *version, *spec_version; 
    167174 
     
    194201    return TRUE; 
    195202} 
     203 
     204void 
     205_notify_cache_add_notification(NotifyNotification *n) 
     206{ 
     207    _active_notifications = g_list_prepend(_active_notifications, n); 
     208} 
     209 
     210void 
     211_notify_cache_remove_notification(NotifyNotification *n) 
     212{ 
     213    _active_notifications = g_list_remove(_active_notifications, n); 
     214} 
  • trunk/libnotify/tests/test-replace-widget.c

    r2391 r2477  
    4242 
    4343    window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 
     44    g_signal_connect(G_OBJECT(window), "delete_event", 
     45                     G_CALLBACK(gtk_main_quit), NULL); 
     46 
    4447    button = gtk_button_new_with_label("click here to change notification"); 
    4548    gtk_container_add(GTK_CONTAINER(window), button);