process and display progress hints (hint 'value', range 0-100) using placeholder %p

This commit is contained in:
progandy 2012-10-07 22:04:36 +02:00
parent e97c0106ca
commit fe1b2fd30e
3 changed files with 16 additions and 5 deletions

View File

@ -907,6 +907,12 @@ int init_notification(notification * n, int id)
n->msg = string_replace("%i", n->icon, n->msg); n->msg = string_replace("%i", n->icon, n->msg);
n->msg = string_replace("%I", basename(n->icon), n->msg); n->msg = string_replace("%I", basename(n->icon), n->msg);
n->msg = string_replace("%b", n->body, n->msg); n->msg = string_replace("%b", n->body, n->msg);
if (n->progress) {
char pg[20];
sprintf(pg, "[%3d%%]", n->progress-1);
n->msg = string_replace("%p", pg, n->msg);
} else
n->msg = string_replace("%p", "", n->msg);
n->msg = fix_markup(n->msg); n->msg = fix_markup(n->msg);

View File

@ -54,6 +54,7 @@ typedef struct _notification {
int dup_count; int dup_count;
ColorSet *colors; ColorSet *colors;
char *color_strings[2]; char *color_strings[2];
int progress;
} notification; } notification;
typedef struct _notification_buffer { typedef struct _notification_buffer {

View File

@ -20,7 +20,7 @@ static void _extract_basic(int type, DBusMessageIter * iter, void *target)
} }
static void static void
_extract_hint(const char *name, const char *hint_name, _extract_hint(int type, const char *name, const char *hint_name,
DBusMessageIter * hint, void *target) DBusMessageIter * hint, void *target)
{ {
@ -30,7 +30,7 @@ _extract_hint(const char *name, const char *hint_name,
dbus_message_iter_next(hint); dbus_message_iter_next(hint);
dbus_message_iter_recurse(hint, &hint_value); dbus_message_iter_recurse(hint, &hint_value);
do { do {
dbus_message_iter_get_basic(&hint_value, target); _extract_basic(type, &hint_value, target);
} while (dbus_message_iter_next(hint)); } while (dbus_message_iter_next(hint));
} }
} }
@ -296,6 +296,7 @@ void notify(DBusMessage * dmsg)
const char *fgcolor = NULL; const char *fgcolor = NULL;
const char *bgcolor = NULL; const char *bgcolor = NULL;
int urgency = 1; int urgency = 1;
int progress = 0;
notification *n = malloc(sizeof(notification)); notification *n = malloc(sizeof(notification));
dbus_uint32_t replaces_id = 0; dbus_uint32_t replaces_id = 0;
dbus_int32_t expires = -1; dbus_int32_t expires = -1;
@ -335,9 +336,11 @@ void notify(DBusMessage * dmsg)
continue; continue;
} }
dbus_message_iter_get_basic(&hint, &hint_name); dbus_message_iter_get_basic(&hint, &hint_name);
_extract_hint("urgency", hint_name, &hint, &urgency); _extract_hint(DBUS_TYPE_STRING, "urgency", hint_name, &hint, &urgency);
_extract_hint("fgcolor", hint_name, &hint, &fgcolor); _extract_hint(DBUS_TYPE_STRING, "fgcolor", hint_name, &hint, &fgcolor);
_extract_hint("bgcolor", hint_name, &hint, &bgcolor); _extract_hint(DBUS_TYPE_STRING, "bgcolor", hint_name, &hint, &bgcolor);
_extract_hint(DBUS_TYPE_INT32, "value", hint_name, &hint, &progress);
if (!progress) _extract_hint(DBUS_TYPE_UINT32, "value", hint_name, &hint, &progress);
dbus_message_iter_next(&hint); dbus_message_iter_next(&hint);
} }
dbus_message_iter_next(&hints); dbus_message_iter_next(&hints);
@ -355,6 +358,7 @@ void notify(DBusMessage * dmsg)
n->body = body != NULL ? strdup(body) : ""; n->body = body != NULL ? strdup(body) : "";
n->icon = icon != NULL ? strdup(icon) : ""; n->icon = icon != NULL ? strdup(icon) : "";
n->timeout = expires; n->timeout = expires;
n->progress = (progress < 0 || progress > 100) ? 0 : progress+1;
n->urgency = urgency; n->urgency = urgency;
n->dbus_client = strdup(dbus_message_get_sender(dmsg)); n->dbus_client = strdup(dbus_message_get_sender(dmsg));
for (i = 0; i < ColLast; i++) { for (i = 0; i < ColLast; i++) {