tmisu

Notification to stdout daemon
git clone https://git.inz.fi/tmisu/
Log | Files | Refs | README | LICENSE

commit ca06d32f9329825aa330a2b1eb5c9fa5e48407e3
parent 0d1d3538f04284b1d22a9a6aaa871d832ee9d6b6
Author: Sweets <Sweets@users.noreply.github.com>
Date:   Sun, 26 Apr 2020 14:10:25 -0700

Rewrite: formatter

Diffstat:
Mcallbacks.c | 5+++--
Aformat.c | 31+++++++++++++++++++++++++++++++
Aformat.h | 7+++++++
Mtiramisu.c | 36------------------------------------
Mtiramisu.h | 3---
5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/callbacks.c b/callbacks.c @@ -1,5 +1,6 @@ #include "tiramisu.h" #include "callbacks.h" +#include "format.h" unsigned int notification_id = 0; @@ -39,8 +40,8 @@ void method_handler(GDBusConnection *connection, const gchar *sender, gint32 timeout; g_variant_iter_next(&iterator, "i", &timeout); - output(app_name, replaces_id, app_icon, summary, body, actions, hints, - timeout); + output_notification(app_name, replaces_id, app_icon, summary, body, + actions, hints, timeout); return_value = g_variant_new("(u)", notification_id++); goto flush; diff --git a/format.c b/format.c @@ -0,0 +1,31 @@ +#include <stdio.h> + +#include "format.h" + +void output_notification(gchar *app_name, guint32 replaces_id, gchar *app_icon, + gchar *summary, gchar *body, GVariant *actions, GVariant *hints, + gint32 timeout) { + /* This function will raise warnings. I don't fucking care. */ + + /* 2048 characters should be significantly long enough*/ + char *string = (char *)calloc(2048, sizeof(char)); + + strcat(string, app_name); + +#ifdef RECEIVE_APP_ICON + sprintf(string, "%s\n%s", string, app_icon); +#endif + + /* TODO: actions */ + /* TODO: hints */ + +#ifdef RECEIVE_REPLACES_ID + sprintf(string, "%s\n%lu", string, replaces_id); +#endif + + sprintf(string, "%s\n%d\n%s\n%s", string, timeout, summary, body); + + printf("%s\n", string); + + free(string); +} diff --git a/format.h b/format.h @@ -0,0 +1,7 @@ +#pragma once + +#include <gio/gio.h> +#include <glib.h> + +void output_notification(gchar*, guint32, gchar*, gchar*, gchar*, GVariant*, + GVariant*, gint32); diff --git a/tiramisu.c b/tiramisu.c @@ -42,42 +42,6 @@ const char *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" " </interface>\n" "</node>"; -void output(gchar *app_name, guint32 replaces_id, gchar *app_icon, - gchar *summary, gchar *body, GVariant *actions, GVariant *hints, - gint32 timeout) { - - /* Build output and fucking send it */ - - char *out; - - char *format = "%s" -#ifdef RECEIVE_APP_ICON - "\n%s" -#endif - - /* TODO: actions */ - /* TODO: hints */ - -#ifdef RECEIVE_REPLACES_ID - "\n%lu" -#endif - "\n%d\n%s\n%s"; - - asprintf(&out, format, app_name, -#ifdef RECEIVE_APP_ICON - app_icon, -#endif -/* TODO: actions */ -/* TODO: hints */ -#ifdef RECEIVE_REPLACES_ID - replaces_id, -#endif - timeout, summary, body); - - printf("%s\n", out); - -} - int main(int argc, char **argv) { GMainLoop *main_loop; diff --git a/tiramisu.h b/tiramisu.h @@ -12,6 +12,3 @@ extern GDBusConnection *dbus_connection; extern GDBusNodeInfo *introspection; #define print(...) fprintf(stderr, __VA_ARGS__); - -void output(gchar*, guint32, gchar*, gchar*, gchar*, GVariant*, GVariant*, - gint32);