allow rule matching against category

fix issue #135
This commit is contained in:
Sascha Kruse 2014-03-08 15:03:38 +01:00
parent d082f51cbb
commit 1ccb6185ac
8 changed files with 31 additions and 8 deletions

View File

@ -87,11 +87,11 @@ keyboard_shortcut context_ks = {.str = "none",
rule_t default_rules[] = { rule_t default_rules[] = {
/* name can be any unique string. It is used to identify the rule in dunstrc to override it there */ /* name can be any unique string. It is used to identify the rule in dunstrc to override it there */
/* name, appname, summary, body, icon, msg_urgency, timeout, urgency, fg, bg, format, script */ /* name, appname, summary, body, icon, category, msg_urgency, timeout, urgency, fg, bg, format, script */
{ "empty", NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, NULL, NULL}, { "empty", NULL, NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, NULL, NULL},
/* { "rule1", "notify-send", NULL, NULL, NULL, -1, -1, -1, NULL, NULL, "%s %b", NULL }, */ /* { "rule1", "notify-send", NULL, NULL, NULL, NULL, -1, -1, -1, NULL, NULL, "%s %b", NULL }, */
/* { "rule2", "Pidgin", "*says*, NULL, NULL, -1, -1, CRITICAL, NULL, NULL, NULL, NULL }, */ /* { "rule2", "Pidgin", "*says*, NULL, NULL, NULL, -1, -1, CRITICAL, NULL, NULL, NULL, NULL }, */
/* { "rule3", "Pidgin", "*signed on*", NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ /* { "rule3", "Pidgin", "*signed on*", NULL, NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */
/* { "rule4", "Pidgin", "*signed off*", NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */ /* { "rule4", "Pidgin", "*signed off*", NULL, NULL, NULL, -1, -1, LOW, NULL, NULL, NULL, NULL }, */
/* { "rule5", NULL, "*foobar*", NULL, NULL, -1, -1, -1, NULL, "#00FF00", NULL, NULL }, */ /* { "rule5", NULL, "*foobar*", NULL, NULL, NULL, -1, -1, -1, NULL, "#00FF00", NULL, NULL }, */
}; };

13
dbus.c
View File

@ -131,6 +131,7 @@ static void onNotify(GDBusConnection * connection,
gint progress = -1; gint progress = -1;
gchar *fgcolor = NULL; gchar *fgcolor = NULL;
gchar *bgcolor = NULL; gchar *bgcolor = NULL;
gchar *category = NULL;
actions->actions = NULL; actions->actions = NULL;
actions->count = 0; actions->count = 0;
@ -212,6 +213,17 @@ static void onNotify(GDBusConnection * connection,
g_variant_dup_string g_variant_dup_string
(dict_value, NULL); (dict_value, NULL);
dict_value =
g_variant_lookup_value(content,
"category",
G_VARIANT_TYPE_STRING);
if (dict_value) {
category =
g_variant_dup_string(
dict_value, NULL);
}
dict_value = dict_value =
g_variant_lookup_value(content, g_variant_lookup_value(content,
"value", "value",
@ -263,6 +275,7 @@ static void onNotify(GDBusConnection * connection,
n->timeout = timeout; n->timeout = timeout;
n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1; n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1;
n->urgency = urgency; n->urgency = urgency;
n->category = category;
n->dbus_client = strdup(sender); n->dbus_client = strdup(sender);
if (actions->count > 0) { if (actions->count > 0) {
n->actions = actions; n->actions = actions;

View File

@ -305,6 +305,7 @@ int main(int argc, char *argv[])
n->timeout = 10; n->timeout = 10;
n->urgency = LOW; n->urgency = LOW;
n->icon = NULL; n->icon = NULL;
n->category = NULL;
n->msg = NULL; n->msg = NULL;
n->dbus_client = NULL; n->dbus_client = NULL;
n->color_strings[0] = NULL; n->color_strings[0] = NULL;

View File

@ -189,7 +189,7 @@
# Every section that isn't one of the above is interpreted as a rules to # Every section that isn't one of the above is interpreted as a rules to
# override settings for certain messages. # override settings for certain messages.
# Messages can be matched by "appname", "summary", "body", "icon", # Messages can be matched by "appname", "summary", "body", "icon", "category",
# "msg_urgency" and you can override the "timeout", "urgency", "foreground", # "msg_urgency" and you can override the "timeout", "urgency", "foreground",
# "background", "new_icon" and "format". # "background", "new_icon" and "format".
# Shell-like globbing will get expanded. # Shell-like globbing will get expanded.

View File

@ -32,6 +32,7 @@ void notification_print(notification * n)
printf("\tsummary: '%s'\n", n->summary); printf("\tsummary: '%s'\n", n->summary);
printf("\tbody: '%s'\n", n->body); printf("\tbody: '%s'\n", n->body);
printf("\ticon: '%s'\n", n->icon); printf("\ticon: '%s'\n", n->icon);
printf("\tcategory: %s\n", n->category);
printf("\turgency: %d\n", n->urgency); printf("\turgency: %d\n", n->urgency);
printf("\tformatted: '%s'\n", n->msg); printf("\tformatted: '%s'\n", n->msg);
printf("\tfg: %s\n", n->color_strings[ColFG]); printf("\tfg: %s\n", n->color_strings[ColFG]);
@ -391,6 +392,10 @@ int notification_init(notification * n, int id)
n->icon = settings.icons[n->urgency]; n->icon = settings.icons[n->urgency];
} }
if (n->category == NULL) {
n->category = "";
}
n->timestamp = time(NULL); n->timestamp = time(NULL);
n->redisplayed = false; n->redisplayed = false;

View File

@ -19,6 +19,7 @@ typedef struct _notification {
char *body; char *body;
char *icon; char *icon;
char *msg; /* formatted message */ char *msg; /* formatted message */
char *category;
char *text_to_render; char *text_to_render;
const char *format; const char *format;
char *dbus_client; char *dbus_client;

View File

@ -50,6 +50,7 @@ void rule_init(rule_t * r)
r->summary = NULL; r->summary = NULL;
r->body = NULL; r->body = NULL;
r->icon = NULL; r->icon = NULL;
r->category = NULL;
r->msg_urgency = -1; r->msg_urgency = -1;
r->timeout = -1; r->timeout = -1;
r->urgency = -1; r->urgency = -1;
@ -69,6 +70,7 @@ bool rule_matches_notification(rule_t * r, notification * n)
&& (!r->summary || !fnmatch(r->summary, n->summary, 0)) && (!r->summary || !fnmatch(r->summary, n->summary, 0))
&& (!r->body || !fnmatch(r->body, n->body, 0)) && (!r->body || !fnmatch(r->body, n->body, 0))
&& (!r->icon || !fnmatch(r->icon, n->icon, 0)) && (!r->icon || !fnmatch(r->icon, n->icon, 0))
&& (!r->category || !fnmatch(r->category, n->category, 0))
&& (r->msg_urgency == -1 || r->msg_urgency == n->urgency)); && (r->msg_urgency == -1 || r->msg_urgency == n->urgency));
} }
/* vim: set ts=8 sw=8 tw=0: */ /* vim: set ts=8 sw=8 tw=0: */

View File

@ -13,6 +13,7 @@ typedef struct _rule_t {
char *summary; char *summary;
char *body; char *body;
char *icon; char *icon;
char *category;
int msg_urgency; int msg_urgency;
/* actions */ /* actions */