Ejemplo n.º 1
0
Archivo: imap.c Proyecto: GCrean/hybrid
static void
process_unread_mails(hybrid_imap *imap, gint unread)
{
    if (imap->unread == unread || unread == 0) {
        if (unread == 0) {
            imap->unread = 0;
        }
        return;
    }

#ifdef USE_LIBNOTIFY
    gchar       *summary;
    GdkPixbuf   *pixbuf;
    const gchar *title = _("New Mail.");
    NotifyNotification *notification = NULL;

    summary = g_strdup_printf(_("<b>%s</b>\n<span size='xx-large' "
                              "foreground='red'><b>%d</b></span> "
                                "<span size='large'>unread mails.</span>"),
                              imap->email_addr, unread);
#ifdef LIBNOTIFY_OLD
    notification = notify_notification_new(title, summary, NULL, NULL);
#else
    notification = notify_notification_new(title, summary, NULL);
#endif
    notify_notification_set_timeout(notification, 5000);

    imap->tmp_unread = unread;
    notify_notification_clear_actions(notification);
    notify_notification_add_action(notification, "test", _("I Know"),
                                   NOTIFY_ACTION_CALLBACK(action_cb),
                                   imap, NULL);

    pixbuf = hybrid_create_proto_icon(imap->account->proto->info->name, 48);
    if (pixbuf) {
        notify_notification_set_icon_from_pixbuf(notification, pixbuf);
        g_object_unref(pixbuf);
    }

    notify_notification_show(notification, NULL);
    g_free(summary);

#endif
}
void NotificationBackendLibnotify::publish(
    const std::string& summary, const std::string& body,
    const std::string& viewParams)
{
    if(!m_initialized)
        return;

    if(m_notification) {
        notify_notification_clear_actions(m_notification);
        notify_notification_close(m_notification, NULL);
    }
#ifndef NOTIFY_CHECK_VERSION
# define NOTIFY_CHECK_VERSION(_x,_y,_z) 0
#endif
#if !NOTIFY_CHECK_VERSION(0,7,0) || defined(NOTIFY_COMPATIBILITY)
    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL, NULL);
#else
    m_notification = notify_notification_new(summary.c_str(), body.c_str(), NULL);
#endif
    //if actions are not supported, don't add actions
    //An example is Ubuntu Notify OSD. It uses an alert box
    //instead of a bubble when a notification is appended with actions.
    //the alert box won't be closed until user inputs.
    //so disable it in case of no support of actions
    if(m_acceptsActions) {
        notify_notification_add_action(m_notification, "view",
                                       _("View"), notifyAction,
                                       (gpointer)viewParams.c_str(),
                                       NULL);
        // Use "default" as ID because that is what mutter-moblin
        // recognizes: it then skips the action instead of adding it
        // in addition to its own "Dismiss" button (always added).
        notify_notification_add_action(m_notification, "default",
                                       _("Dismiss"), notifyAction,
                                       (gpointer)viewParams.c_str(),
                                       NULL);
    }
    notify_notification_show(m_notification, NULL);
}
Ejemplo n.º 3
0
void osd_setup_buttons (NotifyNotification *notification)
{
    notify_notification_clear_actions (notification);

    if (! aud_get_bool ("notify", "actions"))
        return;

    notify_notification_add_action (notification, "default", _("Show"),
     NOTIFY_ACTION_CALLBACK (show_cb), NULL, NULL);

    bool_t playing = aud_drct_get_playing ();
    bool_t paused = aud_drct_get_paused ();

    if (playing && ! paused)
        notify_notification_add_action (notification, "media-playback-pause",
         _("Pause"), NOTIFY_ACTION_CALLBACK (aud_drct_pause), NULL, NULL);
    else
        notify_notification_add_action (notification, "media-playback-start",
         _("Play"), NOTIFY_ACTION_CALLBACK (aud_drct_play), NULL, NULL);

    if (playing)
        notify_notification_add_action (notification, "media-skip-forward",
         _("Next"), NOTIFY_ACTION_CALLBACK (aud_drct_pl_next), NULL, NULL);
}
Ejemplo n.º 4
0
static void
do_notify (RBNotificationPlugin *plugin,
	   guint timeout,
	   const char *primary,
	   const char *secondary,
	   const char *image_uri,
	   gboolean playback)
{
	GError *error = NULL;
	NotifyNotification *notification;

	if (notify_is_initted () == FALSE) {
		GList *caps;

		if (notify_init ("Rhythmbox") == FALSE) {
			g_warning ("libnotify initialization failed");
			return;
		}

		/* ask the notification server if it supports actions */
		caps = notify_get_server_caps ();
		if (g_list_find_custom (caps, "actions", (GCompareFunc)g_strcmp0) != NULL) {
			rb_debug ("notification server supports actions");
			plugin->notify_supports_actions = TRUE;

			if (g_list_find_custom (caps, "action-icons", (GCompareFunc)g_strcmp0) != NULL) {
				rb_debug ("notifiction server supports icon buttons");
				plugin->notify_supports_icon_buttons = TRUE;
			}
		} else {
			rb_debug ("notification server does not support actions");
		}
		if (g_list_find_custom (caps, "persistence", (GCompareFunc)g_strcmp0) != NULL) {
			rb_debug ("notification server supports persistence");
			plugin->notify_supports_persistence = TRUE;
		} else {
			rb_debug ("notification server does not support persistence");
		}

		rb_list_deep_free (caps);
	}

	if (primary == NULL)
		primary = "";

	if (secondary == NULL)
		secondary = "";

	if (playback) {
		notification = plugin->notification;
	} else {
		notification = plugin->misc_notification;
	}

	if (notification == NULL) {
		notification = notify_notification_new (primary, secondary, RB_APP_ICON);

		g_signal_connect_object (notification,
					 "closed",
					 G_CALLBACK (notification_closed_cb),
					 plugin, 0);
		if (playback) {
			plugin->notification = notification;
		} else {
			plugin->misc_notification = notification;
		}
	} else {
		notify_notification_clear_hints (notification);
		notify_notification_update (notification, primary, secondary, RB_APP_ICON);
	}

	notify_notification_set_timeout (notification, timeout);

	if (image_uri != NULL) {
		notify_notification_clear_hints (notification);
		notify_notification_set_hint (notification,
					      "image_path",
					      g_variant_new_string (image_uri));
	}

        if (playback)
        	notify_notification_set_category (notification, "x-gnome.music");
        notify_notification_set_hint (notification, "desktop-entry",
                                      g_variant_new_string ("rhythmbox"));

	notify_notification_clear_actions (notification);
	if (playback && plugin->notify_supports_actions) {
		gboolean rtl;
		const char *play_icon;

		rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
		play_icon = rtl ? "media-playback-start-rtl" : "media-playback-start";

		if (plugin->notify_supports_icon_buttons) {
			gboolean playing = FALSE;
			rb_shell_player_get_playing (plugin->shell_player, &playing, NULL);

			notify_notification_add_action (notification,
							rtl ? "media-skip-backward-rtl" : "media-skip-backward",
							_("Previous"),
							(NotifyActionCallback) notification_previous_cb,
							plugin,
							NULL);
			notify_notification_add_action (notification,
							playing ? "media-playback-pause" : play_icon,
							playing ? _("Pause") : _("Play"),
							(NotifyActionCallback) notification_playpause_cb,
							plugin,
							NULL);
			notify_notification_set_hint (notification, "action-icons", g_variant_new_boolean (TRUE));
		}

		notify_notification_add_action (notification,
						rtl ? "media-skip-forward-rtl" : "media-skip-forward",
						_("Next"),
						(NotifyActionCallback) notification_next_cb,
						plugin,
						NULL);
	}

	if (plugin->notify_supports_persistence) {
		const char *hint;

		if (playback) {
			hint = "resident";
		} else {
			hint = "transient";
		}
		notify_notification_set_hint (notification, hint, g_variant_new_boolean (TRUE));
	}

	if (notify_notification_show (notification, &error) == FALSE) {
		g_warning ("Failed to send notification (%s): %s", primary, error->message);
		g_error_free (error);
	}
}