void setNotificationHints() {
     if (notification) {
         notify_notification_clear_hints(NOTIFY_NOTIFICATION(notification));
         
         if (!hints.isEmpty()) {
             QMapIterator<QString, QVariant> iterator(hints);
         
             while (iterator.hasNext()) {
                 iterator.next();
                 
                 switch (iterator.value().type()) {
                 case QVariant::Int:
                 case QVariant::Double:
                     notify_notification_set_hint_int32(NOTIFY_NOTIFICATION(notification), QGSTRING(iterator.key()),
                                                        iterator.value().toInt());
                     break;
                 default:
                     notify_notification_set_hint_string(NOTIFY_NOTIFICATION(notification), QGSTRING(iterator.key()),
                                                         QGSTRING(iterator.value().toString()));
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
static void show_volume_notification(unsigned int volume_pct, int muted)
{
	const char *icon;

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

	if (notification) {
		GError *err = NULL;

		if (!notify_notification_update(notification, APP_NAME, NULL, icon)) {
			fprintf(stderr, "Invalid parameter passed to notify_notification_update()");
			return;
		}
		notify_notification_set_hint_int32(notification, "value",
						   (gint)volume_pct);
		notify_notification_show(notification, &err);
		if (err) {
			fprintf(stderr, "notify_notification_show() failed: %s\n", err->message);
			g_error_free(err);
			return;
		}
	}
}
Exemplo n.º 3
0
static gboolean
notify_notification_set_hint_variant (NotifyNotification *notification,
                                      const char         *type,
                                      const char         *key,
                                      const char         *value,
                                      GError            **error)
{
        static gboolean conv_error = FALSE;
        if (!strcasecmp (type, "string")) {
                notify_notification_set_hint_string (notification,
                                                     key,
                                                     value);
        } else if (!strcasecmp (type, "int")) {
                if (!g_ascii_isdigit (*value))
                        conv_error = TRUE;
                else {
                        gint h_int = (gint) g_ascii_strtoull (value, NULL, 10);
                        notify_notification_set_hint_int32 (notification,
                                                            key,
                                                            h_int);
                }
        } else if (!strcasecmp (type, "double")) {
                if (!g_ascii_isdigit (*value))
                        conv_error = TRUE;
                else {
                        gdouble h_double = g_strtod (value, NULL);
                        notify_notification_set_hint_double (notification,
                                                             key, h_double);
                }
        } else if (!strcasecmp (type, "byte")) {
                gint h_byte = (gint) g_ascii_strtoull (value, NULL, 10);

                if (h_byte < 0 || h_byte > 0xFF)
                        conv_error = TRUE;
                else {
                        notify_notification_set_hint_byte (notification,
                                                           key,
                                                           (guchar) h_byte);
                }
        } else {
                *error = g_error_new (G_OPTION_ERROR,
                                      G_OPTION_ERROR_BAD_VALUE,
                                      N_("Invalid hint type \"%s\". Valid types "
                                         "are int, double, string and byte."),
                                      type);
                return FALSE;
        }

        if (conv_error) {
                *error = g_error_new (G_OPTION_ERROR,
                                      G_OPTION_ERROR_BAD_VALUE,
                                      N_("Value \"%s\" of hint \"%s\" could not be "
                                         "parsed as type \"%s\"."), value, key,
                                      type);
                return FALSE;
        }

        return TRUE;
}
Exemplo n.º 4
0
void show_notification(const gchar *summary, const gchar *message,
			const gchar *action, gint timeout, GCallback handler)
{
	NotifyActionCallback callback;
#ifndef HAVE_APP_INDICATOR
	GdkScreen *screen;
	GdkRectangle area;
#endif /* HAVE_APP_INDICATOR */

	if (notify_is_initted() == FALSE)
		return;

	if (notify) {
		g_signal_handlers_destroy(notify);
		notify_notification_close(notify, NULL);
	}

	notify = notify_notification_new(summary, message, ACTIVE_ICON_NAME);

	notify_notification_set_timeout(notify, timeout);

#ifndef HAVE_APP_INDICATOR
	if (gtk_status_icon_get_visible(statusicon) == TRUE) {
		gtk_status_icon_get_geometry(statusicon, &screen, &area, NULL);

		notify_notification_set_hint_int32(notify,
					"x", area.x + area.width / 2);
		notify_notification_set_hint_int32(notify,
					"y", area.y + area.height / 2);
	}
#endif /* HAVE_APP_INDICATOR */

	notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL);

	callback = handler ? NOTIFY_ACTION_CALLBACK(handler) : notify_action;

	notify_notification_add_action(notify, "default", "action",
						callback, NULL, NULL);
	if (action != NULL)
		notify_notification_add_action(notify, "button", action,
							callback, NULL, NULL);

	notify_notification_show(notify, NULL);
}
Exemplo n.º 5
0
int
main(int argc, char **argv)
{
	NotifyNotification *n;
	DBusConnection *conn;

	notify_init("XY");

	conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
	loop = g_main_loop_new(NULL, FALSE);

	dbus_connection_setup_with_g_main(conn, NULL);

	n = notify_notification_new("System update available",
								"New system updates are available. It is "
								"recommended that you install the updates.",
								NULL, NULL);

	notify_notification_set_hint_int32(n, "x", 600);
	notify_notification_set_hint_int32(n, "y", 10);
	notify_notification_add_action(n, "help", "Help",
								   (NotifyActionCallback)action_cb,
								   NULL, NULL);
	notify_notification_add_action(n, "update", "Update",
								   (NotifyActionCallback)action_cb,
								   NULL, NULL);

	if (!notify_notification_show(n, NULL)) {
		fprintf(stderr, "failed to send notification\n");
		return 1;
	}

	g_main_loop_run(loop);

	return 0;
}
Exemplo n.º 6
0
    int
notify_hints_type(ErlNifEnv *env, NotifyNotification *notify, int arity, ERL_NIF_TERM key, ERL_NIF_TERM value)
{
    char a_key[256] = {0};

    union {
        ErlNifBinary b;
        int i;
        double d;
    } val;

    const ERL_NIF_TERM *byte = NULL;
    char a_byte[256] = {0};
    int len = 0;

    if (!enif_get_atom(env, key, a_key, sizeof(a_key), ERL_NIF_LATIN1))
        return -1;

    if (enif_get_int(env, value, &val.i))
        notify_notification_set_hint_int32(notify, a_key, val.i);
    else if (enif_get_double(env, value, &val.d))
        notify_notification_set_hint_double(notify, a_key, val.d);
    else if (enif_get_tuple(env, value, &len, &byte)) {
        if (len != 2 ||
                !enif_get_atom(env, byte[0], a_byte, sizeof(a_byte), ERL_NIF_LATIN1) ||
                (strcmp(a_byte, "byte") != 0) ||
                !enif_get_int(env, byte[1], &val.i))
            return -1;
        notify_notification_set_hint_byte(notify, a_key, (u_int8_t)val.i);
    }
    else if (arity == 0 || enif_inspect_iolist_as_binary(env, value, &val.b)) {
        gchar *tmpstr = NULL;

        if (arity > 0)
            tmpstr = stralloc(&val.b);

        notify_notification_set_hint_string(notify, a_key,
                (arity > 0 ? "" : tmpstr));

        strfree(tmpstr);
    }
    else
        return -1;

    return 0;
}
Exemplo n.º 7
0
void 
xvd_notify_notification(XvdInstance *Inst, 
						gchar* icon, 
						gint value)
{
	GError* error						= NULL;
	gchar*  title						= NULL;

	if ((icon != NULL) && (g_strcmp0(icon, "audio-volume-muted") == 0)) {
		// TRANSLATORS: this is the body of the ATK interface of the volume notifications. This is the case when volume is muted
		title = g_strdup ("Volume is muted");
	}
	else {
		// TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug.
		title = g_strdup_printf ("Volume is at %d%c", value, '%');
	}
	
	notify_notification_update (Inst->notification,
				title,
				NULL,
				icon);
	
	g_free (title);
	
	if (Inst->gauge_notifications) {
		notify_notification_set_hint_int32 (Inst->notification,
							"value",
							value);
		notify_notification_set_hint_string (Inst->notification,
							 "x-canonical-private-synchronous",
							 "");
	}
	
	if (!notify_notification_show (Inst->notification, &error))
	{
		g_warning ("Error while sending notification : %s\n", error->message);
		g_error_free (error);
	}
}
Exemplo n.º 8
0
static void
send_synchronous (const char *type,
		  const char *icon,
		  gint value)
{
        static NotifyNotification *n = NULL;

	if (n == NULL)
		n = notify_notification_new (" ",
					     "",
					     g_strdup (icon),
					     NULL);
	else
		notify_notification_update (n,
					    " ",
					    "",
					    g_strdup (icon));
		
	notify_notification_set_hint_int32(n, "value", value);
	notify_notification_set_hint_string(n, "x-canonical-private-synchronous", g_strdup (type));

	notify_notification_show (n, NULL);
}
Exemplo n.º 9
0
    int
notify_hints_type(ErlNifEnv *env, NotifyNotification *notify, int arity, ERL_NIF_TERM key, ERL_NIF_TERM value)
{
    char s_key[1024] = {0};

    char s_value[1024] = {0};
    int i_value = 0;
    double d_value = 0;

    const ERL_NIF_TERM *byte = NULL;
    char s_byte[256] = {0};
    int len = 0;


    if (!enif_get_string(env, key, s_key, sizeof(s_key), ERL_NIF_LATIN1))
        return -1;

    if (enif_get_int(env, value, &i_value))
        notify_notification_set_hint_int32(notify, s_key, (value == atom_undefined ? 0 : i_value));
    else if (enif_get_double(env, value, &d_value))
        notify_notification_set_hint_double(notify, s_key, (value == atom_undefined ? 0 : d_value));
    else if (enif_get_tuple(env, value, &len, &byte)) {
        if ( (len != 2) ||
                !enif_get_atom(env, byte[0], s_byte, sizeof(s_byte), ERL_NIF_LATIN1) || 
                (strcmp(s_byte, "byte") != 0) ||
                !enif_get_int(env, byte[1], &i_value))
            return -1;
        notify_notification_set_hint_byte(notify, s_key, (value == atom_undefined ? 0 : (u_int8_t)i_value));
    }
    else if ((arity == 0) || enif_get_string(env, value, s_value, sizeof(s_value), ERL_NIF_LATIN1))
        notify_notification_set_hint_string(notify, s_key, (value == atom_undefined ? "" : s_value));
    else
        return -1;

    return 0;
}