2 #include <Ecore_Getopt.h>
3 #include <notification.h>
4 #include <notification_internal.h>
7 const char *error_to_string(notification_error_e error)
9 if (error == NOTIFICATION_ERROR_INVALID_PARAMETER)
10 return "NOTIFICATION_ERROR_INVALID_PARAMETER";
11 if (error == NOTIFICATION_ERROR_OUT_OF_MEMORY)
12 return "NOTIFICATION_ERROR_OUT_OF_MEMORY";
13 if (error == NOTIFICATION_ERROR_FROM_DB)
14 return "NOTIFICATION_ERROR_FROM_DB";
15 if (error == NOTIFICATION_ERROR_ALREADY_EXIST_ID)
16 return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
17 if (error == NOTIFICATION_ERROR_FROM_DBUS)
18 return "NOTIFICATION_ERROR_FROM_DBUS";
19 if (error == NOTIFICATION_ERROR_NOT_EXIST_ID)
20 return "NOTIFICATION_ERROR_NOT_EXIST_ID";
21 if (error == NOTIFICATION_ERROR_IO_ERROR)
22 return "NOTIFICATION_ERROR_IO_ERROR";
23 if (error == NOTIFICATION_ERROR_SERVICE_NOT_READY)
24 return "NOTIFICATION_ERROR_SERVICE_NOT_READY";
25 if (error == NOTIFICATION_ERROR_NONE)
26 return "NOTIFICATION_ERROR_NONE";
28 return "UNHANDLED ERROR";
31 static Eina_Bool remove_all(const Ecore_Getopt *parser,
32 const Ecore_Getopt_Desc *desc,
35 Ecore_Getopt_Value *storage)
37 notification_error_e err = NOTIFICATION_ERROR_NONE;
39 err = notification_delete_all_by_type("SEND_TEST_PKG", NOTIFICATION_TYPE_NOTI);
40 if (err != NOTIFICATION_ERROR_NONE) {
41 fprintf(stderr, "Unable to remove notifications: %s\n", error_to_string(err));
47 // will never reach here
51 static const Ecore_Getopt optdesc = {
52 "send notification test utility",
55 "(C) 2013 Intel Corp",
57 "Test utility for sending notifications",
60 ECORE_GETOPT_STORE_STR('t', "title", "Title"),
61 ECORE_GETOPT_STORE_STR('c', "content", "Content"),
62 ECORE_GETOPT_STORE_STR('i', "icon", "Path to icon"),
63 ECORE_GETOPT_STORE_STR('m', "image", "Path to image"),
64 ECORE_GETOPT_STORE_INT('y', "imagetype", "Image type enum value"),
65 ECORE_GETOPT_CALLBACK_NOARGS('r', "removeall", "Remove all notifications", remove_all, NULL),
66 ECORE_GETOPT_HELP('h', "help"),
72 main(int argc, char **argv)
79 Eina_Bool quit = EINA_FALSE;
80 Eina_Bool remove = EINA_FALSE;
81 notification_h noti = NULL;
82 notification_error_e err = NOTIFICATION_ERROR_NONE;
84 Ecore_Getopt_Value values[] = {
85 ECORE_GETOPT_VALUE_STR(title),
86 ECORE_GETOPT_VALUE_STR(content),
87 ECORE_GETOPT_VALUE_STR(icon),
88 ECORE_GETOPT_VALUE_STR(image),
89 ECORE_GETOPT_VALUE_INT(imageType),
90 ECORE_GETOPT_VALUE_NONE,
91 ECORE_GETOPT_VALUE_BOOL(quit)
95 fprintf(stderr, "ERROR: Cannot init Ecore!\n");
99 if (ecore_getopt_parse(&optdesc, values, argc, argv) < 0) {
100 fprintf(stderr, "Parsing arguments failed!\n");
107 noti = notification_new(NOTIFICATION_TYPE_NOTI,
108 NOTIFICATION_GROUP_ID_NONE,
109 NOTIFICATION_PRIV_ID_NONE);
111 fprintf(stderr, "Failed to create notification: %s\n", error_to_string(err));
115 err = notification_set_pkgname(noti, "SEND_TEST_PKG");
116 if (err != NOTIFICATION_ERROR_NONE) {
117 fprintf(stderr, "Unable to set pkgname: %s\n", error_to_string(err));
121 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
122 title ? title : "Default Title",
123 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
124 if (err != NOTIFICATION_ERROR_NONE) {
125 fprintf(stderr, "Unable to set notification title: %s\n", error_to_string(err));
129 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
130 content ? content : "Default Content",
131 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
132 if (err != NOTIFICATION_ERROR_NONE) {
133 fprintf(stderr, "Unable to set notification content: %s\n", error_to_string(err));
138 err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon);
139 if (err != NOTIFICATION_ERROR_NONE) {
140 fprintf(stderr, "Unable to set notification icon path: %s\n", error_to_string(err));
146 err = notification_set_image(noti, imageType, image);
147 if (err != NOTIFICATION_ERROR_NONE) {
148 fprintf(stderr, "Unable to set notification image path: %s\n", error_to_string(err));
153 err = notification_insert(noti, NULL);
154 if (err != NOTIFICATION_ERROR_NONE) {
155 fprintf(stderr, "Unable to insert notification: %s\n", error_to_string(err));
159 fprintf(stdout, "Sent Notification > %s : %s : %s : %s : %i\n",
160 title, content, icon, image, imageType);