Use enum for urgency

This commit is contained in:
Benedikt Heine 2017-11-16 16:16:43 +01:00
parent 62e50289f0
commit d91053c85e
5 changed files with 36 additions and 27 deletions

View File

@ -38,7 +38,7 @@ void notification_print(notification *n)
printf("\traw_icon set: %s\n", (n->raw_icon ? "true" : "false"));
printf("\tcategory: %s\n", n->category);
printf("\ttimeout: %ld\n", n->timeout/1000);
printf("\turgency: %d\n", n->urgency);
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency));
printf("\ttransient: %d\n", n->transient);
printf("\tformatted: '%s'\n", n->msg);
printf("\tfg: %s\n", n->color_strings[ColFG]);
@ -80,21 +80,7 @@ void notification_run_script(notification *n)
char *body = n->body ? n->body : "";
char *icon = n->icon ? n->icon : "";
char *urgency;
switch (n->urgency) {
case LOW:
urgency = "LOW";
break;
case NORM:
urgency = "NORMAL";
break;
case CRIT:
urgency = "CRITICAL";
break;
default:
urgency = "NORMAL";
break;
}
const char *urgency = notification_urgency_to_string(n->urgency);
int pid1 = fork();
@ -121,6 +107,25 @@ void notification_run_script(notification *n)
}
}
/*
* Helper function to convert an urgency to a string
*/
const char *notification_urgency_to_string(enum urgency urgency)
{
switch (urgency) {
case NONE:
return "NONE";
case LOW:
return "LOW";
case NORM:
return "NORMAL";
case CRIT:
return "CRITICAL";
default:
return "UNDEF";
}
}
/*
* Helper function to compare to given
* notifications.

View File

@ -7,12 +7,15 @@
#include "settings.h"
#define LOW 0
#define NORM 1
#define CRIT 2
#define DUNST_NOTIF_MAX_CHARS 5000
enum urgency {
NONE = -1,
LOW = 0,
NORM = 1,
CRIT = 2,
};
typedef struct _raw_image {
int width;
int height;
@ -43,7 +46,7 @@ typedef struct _notification {
gint64 start;
gint64 timestamp;
gint64 timeout;
int urgency;
enum urgency urgency;
enum markup_mode markup;
bool redisplayed; /* has been displayed before? */
int id;
@ -74,5 +77,6 @@ void notification_replace_single_field(char **haystack, char **needle, const cha
void notification_update_text_to_render(notification *n);
void notification_do_action(notification *n);
const char *notification_urgency_to_string(enum urgency urgency);
#endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -14,7 +14,7 @@ void rule_apply(rule_t *r, notification *n)
{
if (r->timeout != -1)
n->timeout = r->timeout;
if (r->urgency != -1)
if (r->urgency != NONE)
n->urgency = r->urgency;
if (r->history_ignore != -1)
n->history_ignore = r->history_ignore;
@ -62,9 +62,9 @@ void rule_init(rule_t *r)
r->body = NULL;
r->icon = NULL;
r->category = NULL;
r->msg_urgency = -1;
r->msg_urgency = NONE;
r->timeout = -1;
r->urgency = -1;
r->urgency = NONE;
r->markup = MARKUP_NULL;
r->new_icon = NULL;
r->history_ignore = false;
@ -86,6 +86,6 @@ bool rule_matches_notification(rule_t *r, notification *n)
&& (!r->icon || !fnmatch(r->icon, n->icon, 0))
&& (!r->category || !fnmatch(r->category, n->category, 0))
&& (r->match_transient == -1 || (r->match_transient == n->transient))
&& (r->msg_urgency == -1 || r->msg_urgency == n->urgency));
&& (r->msg_urgency == NONE || r->msg_urgency == n->urgency));
}
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -20,7 +20,7 @@ typedef struct _rule_t {
/* actions */
gint64 timeout;
int urgency;
enum urgency urgency;
enum markup_mode markup;
int history_ignore;
int match_transient;

View File

@ -47,7 +47,7 @@ static enum markup_mode parse_markup_mode(const char *mode)
}
}
static int ini_get_urgency(const char *section, const char *key, const int def)
static enum urgency ini_get_urgency(const char *section, const char *key, const int def)
{
int ret = def;
char *urg = ini_get_string(section, key, "");