Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] DBus add NotificationListDisplayed #1348

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ static const char *introspection_xml =
" <method name=\"NotificationClearHistory\"/>"
" <method name=\"NotificationCloseLast\" />"
" <method name=\"NotificationCloseAll\" />"
" <method name=\"NotificationListDisplayed\">"
" <arg direction=\"out\" name=\"notifications\" type=\"aa{sv}\"/>"
" </method>"
" <method name=\"NotificationListHistory\">"
" <arg direction=\"out\" name=\"notifications\" type=\"aa{sv}\"/>"
" </method>"
Expand Down Expand Up @@ -187,6 +190,7 @@ DBUS_METHOD(dunst_NotificationAction);
DBUS_METHOD(dunst_NotificationClearHistory);
DBUS_METHOD(dunst_NotificationCloseAll);
DBUS_METHOD(dunst_NotificationCloseLast);
DBUS_METHOD(dunst_NotificationListDisplayed);
DBUS_METHOD(dunst_NotificationListHistory);
DBUS_METHOD(dunst_NotificationPopHistory);
DBUS_METHOD(dunst_NotificationRemoveFromHistory);
Expand All @@ -200,6 +204,7 @@ static struct dbus_method methods_dunst[] = {
{"NotificationClearHistory", dbus_cb_dunst_NotificationClearHistory},
{"NotificationCloseAll", dbus_cb_dunst_NotificationCloseAll},
{"NotificationCloseLast", dbus_cb_dunst_NotificationCloseLast},
{"NotificationListDisplayed", dbus_cb_dunst_NotificationListDisplayed},
{"NotificationListHistory", dbus_cb_dunst_NotificationListHistory},
{"NotificationPopHistory", dbus_cb_dunst_NotificationPopHistory},
{"NotificationRemoveFromHistory", dbus_cb_dunst_NotificationRemoveFromHistory},
Expand Down Expand Up @@ -332,20 +337,16 @@ static void dbus_cb_dunst_NotificationShow(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL);
}

static void dbus_cb_dunst_NotificationListHistory(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
static void dbus_answer_queue_entries(GDBusConnection *connection,
GDBusMethodInvocation *invocation,
int list_length,
GList *notification_list)
{
LOG_D("CMD: Listing all notifications from history");

GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE("aa{sv}"));

GList *notification_list = queues_get_history();

// reverse chronological list
for(int i = queues_length_history(); i > 0; i--) {
for(int i = list_length; i > 0; i--) {
struct notification *n;
n = g_list_nth_data(notification_list, i-1);

Expand Down Expand Up @@ -384,6 +385,24 @@ static void dbus_cb_dunst_NotificationListHistory(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL);
}

static void dbus_cb_dunst_NotificationListDisplayed(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
LOG_D("CMD: Listing all currently displayed notifications");
dbus_answer_queue_entries(connection, invocation, queues_length_displayed(), queues_get_displayed());
}

static void dbus_cb_dunst_NotificationListHistory(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
GDBusMethodInvocation *invocation)
{
LOG_D("CMD: Listing all notifications from history");
dbus_answer_queue_entries(connection, invocation, queues_length_history(), queues_get_history());
}

static void dbus_cb_dunst_NotificationPopHistory(GDBusConnection *connection,
const gchar *sender,
GVariant *parameters,
Expand Down