2 #include <Ecore_Getopt.h>
3 #include <notification.h>
6 const char *error_to_string(notification_error_e error)
8 if (error == NOTIFICATION_ERROR_INVALID_DATA)
9 return "NOTIFICATION_ERROR_INVALID_DATA";
10 if (error == NOTIFICATION_ERROR_NO_MEMORY)
11 return "NOTIFICATION_ERROR_NO_MEMORY";
12 if (error == NOTIFICATION_ERROR_FROM_DB)
13 return "NOTIFICATION_ERROR_FROM_DB";
14 if (error == NOTIFICATION_ERROR_ALREADY_EXIST_ID)
15 return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
16 if (error == NOTIFICATION_ERROR_FROM_DBUS)
17 return "NOTIFICATION_ERROR_FROM_DBUS";
18 if (error == NOTIFICATION_ERROR_NOT_EXIST_ID)
19 return "NOTIFICATION_ERROR_NOT_EXIST_ID";
20 if (error == NOTIFICATION_ERROR_IO)
21 return "NOTIFICATION_ERROR_IO";
22 if (error == NOTIFICATION_ERROR_SERVICE_NOT_READY)
23 return "NOTIFICATION_ERROR_SERVICE_NOT_READY";
24 if (error == NOTIFICATION_ERROR_NONE)
25 return "NOTIFICATION_ERROR_NONE";
27 return "UNHANDLED ERROR";
30 static Eina_Bool remove_all(const Ecore_Getopt *parser,
31 const Ecore_Getopt_Desc *desc,
34 Ecore_Getopt_Value *storage)
36 notification_error_e err = NOTIFICATION_ERROR_NONE;
38 err = notification_delete_all_by_type("SEND_TEST_PKG", NOTIFICATION_TYPE_NOTI);
39 if (err != NOTIFICATION_ERROR_NONE) {
40 fprintf(stderr, "Unable to remove notifications: %s\n", error_to_string(err));
46 // will never reach here
50 static const Ecore_Getopt optdesc = {
51 "send notification test utility",
54 "(C) 2013 Intel Corp",
56 "Test utility for sending notifications",
59 ECORE_GETOPT_STORE_STR('t', "title", "Title"),
60 ECORE_GETOPT_STORE_STR('c', "content", "Content"),
61 ECORE_GETOPT_STORE_STR('i', "icon", "Path to icon"),
62 ECORE_GETOPT_STORE_STR('m', "image", "Path to image"),
63 ECORE_GETOPT_STORE_INT('y', "imagetype", "Image type enum value"),
64 ECORE_GETOPT_CALLBACK_NOARGS('r', "removeall", "Remove all notifications", remove_all, NULL),
65 ECORE_GETOPT_HELP('h', "help"),
71 main(int argc, char **argv)
78 Eina_Bool quit = EINA_FALSE;
79 Eina_Bool remove = EINA_FALSE;
80 notification_h noti = NULL;
81 notification_error_e err = NOTIFICATION_ERROR_NONE;
83 Ecore_Getopt_Value values[] = {
84 ECORE_GETOPT_VALUE_STR(title),
85 ECORE_GETOPT_VALUE_STR(content),
86 ECORE_GETOPT_VALUE_STR(icon),
87 ECORE_GETOPT_VALUE_STR(image),
88 ECORE_GETOPT_VALUE_INT(imageType),
89 ECORE_GETOPT_VALUE_NONE,
90 ECORE_GETOPT_VALUE_BOOL(quit)
94 fprintf(stderr, "ERROR: Cannot init Ecore!\n");
98 if (ecore_getopt_parse(&optdesc, values, argc, argv) < 0) {
99 fprintf(stderr, "Parsing arguments failed!\n");
106 noti = notification_new(NOTIFICATION_TYPE_NOTI,
107 NOTIFICATION_GROUP_ID_NONE,
108 NOTIFICATION_PRIV_ID_NONE);
110 fprintf(stderr, "Failed to create notification: %s\n", error_to_string(err));
114 err = notification_set_pkgname(noti, "SEND_TEST_PKG");
115 if (err != NOTIFICATION_ERROR_NONE) {
116 fprintf(stderr, "Unable to set pkgname: %s\n", error_to_string(err));
120 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
121 title ? title : "Default Title",
122 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
123 if (err != NOTIFICATION_ERROR_NONE) {
124 fprintf(stderr, "Unable to set notification title: %s\n", error_to_string(err));
128 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
129 content ? content : "Default Content",
130 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
131 if (err != NOTIFICATION_ERROR_NONE) {
132 fprintf(stderr, "Unable to set notification content: %s\n", error_to_string(err));
137 err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon);
138 if (err != NOTIFICATION_ERROR_NONE) {
139 fprintf(stderr, "Unable to set notification icon path: %s\n", error_to_string(err));
145 err = notification_set_image(noti, imageType, image);
146 if (err != NOTIFICATION_ERROR_NONE) {
147 fprintf(stderr, "Unable to set notification image path: %s\n", error_to_string(err));
152 err = notification_insert(noti, NULL);
153 if (err != NOTIFICATION_ERROR_NONE) {
154 fprintf(stderr, "Unable to insert notification: %s\n", error_to_string(err));
158 fprintf(stdout, "Sent Notification > %s : %s : %s : %s : %i\n",
159 title, content, icon, image, imageType);