[pulseaudio-discuss] [PATCH 6/8] desktop-notifications: Improved the notification reply struct and change the actions to a hashmap.
Ștefan Săftescu
stefan.saftescu at gmail.com
Thu Jul 12 09:10:27 PDT 2012
---
src/modules/notifications/notification.c | 26 ++++++++++++++++++++------
src/modules/notifications/notification.h | 23 ++++++++++++++++++-----
2 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/src/modules/notifications/notification.c b/src/modules/notifications/notification.c
index cb6bca1..f3757d7 100644
--- a/src/modules/notifications/notification.c
+++ b/src/modules/notifications/notification.c
@@ -25,26 +25,40 @@
#include <pulse/xmalloc.h>
+#include <pulsecore/hashmap.h>
+
#include "notification.h"
#include "notification-backend.h"
pa_ui_notification* pa_ui_notification_new(pa_ui_notification_reply_cb_t reply_cb, void *userdata) {
- pa_ui_notification *n = pa_xnew(pa_ui_notification, 1);
+ pa_ui_notification *n = pa_xnew0(pa_ui_notification, 1);
- n->replaces_id = 0;
n->summary = "";
n->body = "";
- n->actions = NULL;
- n->num_actions = 0; /* TODO: actions */
n->expire_timeout = -1;
-
+ n->actions = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
n->handle_reply = reply_cb;
n->userdata = userdata;
-
return n;
}
void pa_ui_notification_free(pa_ui_notification *n) {
+ pa_hashmap_free(n->actions, NULL, NULL);
pa_xfree(n);
}
+
+pa_ui_notification_reply* pa_ui_notification_reply_new(pa_ui_notification_reply_type_t type, pa_ui_notification *source, char *action_key) {
+ pa_ui_notification_reply *reply = pa_xnew0(pa_ui_notification_reply, 1);
+
+ reply->type = type;
+ reply->source = source;
+ reply->action_key = action_key;
+
+ return reply;
+}
+
+void pa_ui_notification_reply_free(pa_ui_notification_reply *reply) {
+ pa_ui_notification_free(reply->source);
+ pa_xfree(reply);
+}
diff --git a/src/modules/notifications/notification.h b/src/modules/notifications/notification.h
index 03623a6..1944311 100644
--- a/src/modules/notifications/notification.h
+++ b/src/modules/notifications/notification.h
@@ -20,7 +20,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
-#include <stdint.h>
+#include <pulsecore/hashmap.h>
typedef struct pa_ui_notification pa_ui_notification;
typedef struct pa_ui_notification_reply pa_ui_notification_reply;
@@ -28,22 +28,35 @@ typedef struct pa_ui_notification_reply pa_ui_notification_reply;
typedef void(*pa_ui_notification_reply_cb_t)(pa_ui_notification_reply *reply);
struct pa_ui_notification {
- uint32_t replaces_id;
+ unsigned replaces_id;
char *summary;
char *body;
- char **actions;
- size_t num_actions;
- int32_t expire_timeout;
+ pa_hashmap *actions;
+ int expire_timeout;
pa_ui_notification_reply_cb_t handle_reply;
void* userdata;
};
+typedef enum pa_ui_notification_reply_type {
+ PA_UI_NOTIFCATION_REPLY_ERROR,
+ PA_UI_NOTIFCATION_REPLY_CANCELLED,
+ PA_UI_NOTIFCATION_REPLY_DISMISSED,
+ PA_UI_NOTIFCATION_REPLY_EXPIRED,
+ PA_UI_NOTIFCATION_REPLY_ACTION_INVOKED,
+ PA_UI_NOTIFCATION_REPLY_MAX
+} pa_ui_notification_reply_type_t;
+
struct pa_ui_notification_reply {
+ pa_ui_notification_reply_type_t type;
pa_ui_notification *source;
+ char *action_key;
};
pa_ui_notification* pa_ui_notification_new(pa_ui_notification_reply_cb_t reply_cb, void *userdata);
void pa_ui_notification_free(pa_ui_notification *notification);
+pa_ui_notification_reply* pa_ui_notification_reply_new(pa_ui_notification_reply_type_t type, pa_ui_notification *source, char *action_key);
+void pa_ui_notification_reply_free(pa_ui_notification_reply *reply);
+
#endif
--
1.7.10.4
More information about the pulseaudio-discuss
mailing list