コード例 #1
0
ファイル: notify.c プロジェクト: hyuni/pnmixer
/**
 * Send a volume notification. This is mainly called
 * from the alsa subsystem whenever we have volume
 * changes.
 *
 * @param level the playback volume level
 * @param muted whether the playback is muted
 */
void
do_notify_volume(gint level, gboolean muted)
{
	static NotifyNotification *notification = NULL;
	gchar *summary, *icon, *active_card_name;
	const char *active_channel;
	GError *error = NULL;

	active_card_name = (alsa_get_active_card())->name;
	active_channel = alsa_get_active_channel();

	if (notification == NULL) {
		notification = NOTIFICATION_NEW("", NULL, NULL);
		notify_notification_set_timeout(notification, noti_timeout);
		NOTIFICATION_SET_HINT_STRING(notification,
					     "x-canonical-private-synchronous", "");
	}

	if (level < 0)
		level = 0;
	if (level > 100)
		level = 100;

	if (muted)
		summary = g_strdup("Volume muted");
	else
		summary =
			g_strdup_printf("%s (%s)\nVolume: %d%%\n",
					active_card_name, active_channel, level);

	if (muted)
		icon = "audio-volume-muted";
	else if (level == 0)
		icon = "audio-volume-off";
	else if (level < 33)
		icon = "audio-volume-low";
	else if (level < 66)
		icon = "audio-volume-medium";
	else
		icon = "audio-volume-high";

	notify_notification_update(notification, summary, NULL, icon);
	NOTIFICATION_SET_HINT_INT32(notification, "value", level);

	if (!notify_notification_show(notification, &error)) {
		report_error(_("Could not send notification: %s"), error->message);
		g_error_free(error);
	}

	g_free(summary);
}
コード例 #2
0
ファイル: notify.c プロジェクト: cspk/pnmixer
/**
 * Send a text notification. 
 *
 * @param summary the notification summary
 * @param _body the notification body
 */
void do_notify_text(const gchar *summary, const gchar *body) {
  static NotifyNotification *notification = NULL;
  GError *error = NULL;

  if (notification == NULL) {
    notification = NOTIFICATION_NEW("", NULL, NULL);
    notify_notification_set_timeout(notification, noti_timeout * 2);
    NOTIFICATION_SET_HINT_STRING(notification,"x-canonical-private-synchronous","");
  }

  notify_notification_update(notification,summary,body,NULL);

  if (!notify_notification_show(notification,&error)) {
    g_warning("Could not send notification: %s",error->message);
    report_error(_("Could not send notification: %s\n"),error->message);
    g_error_free(error);
  }
}