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 remove = EINA_FALSE;
79 notification_h noti = NULL;
80 notification_error_e err = NOTIFICATION_ERROR_NONE;
82 Ecore_Getopt_Value values[] = {
83 ECORE_GETOPT_VALUE_STR(title),
84 ECORE_GETOPT_VALUE_STR(content),
85 ECORE_GETOPT_VALUE_STR(icon),
86 ECORE_GETOPT_VALUE_STR(image),
87 ECORE_GETOPT_VALUE_INT(imageType),
88 ECORE_GETOPT_VALUE_NONE
92 fprintf(stderr, "ERROR: Cannot init Ecore!\n");
96 if (ecore_getopt_parse(&optdesc, values, argc, argv) < 0) {
97 fprintf(stderr, "Parsing arguments failed!\n");
101 noti = notification_new(NOTIFICATION_TYPE_NOTI,
102 NOTIFICATION_GROUP_ID_NONE,
103 NOTIFICATION_PRIV_ID_NONE);
105 fprintf(stderr, "Failed to create notification: %s\n", error_to_string(err));
109 err = notification_set_pkgname(noti, "SEND_TEST_PKG");
110 if (err != NOTIFICATION_ERROR_NONE) {
111 fprintf(stderr, "Unable to set pkgname: %s\n", error_to_string(err));
115 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
116 title ? title : "Default Title",
117 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
118 if (err != NOTIFICATION_ERROR_NONE) {
119 fprintf(stderr, "Unable to set notification title: %s\n", error_to_string(err));
123 err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
124 content ? content : "Default Content",
125 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
126 if (err != NOTIFICATION_ERROR_NONE) {
127 fprintf(stderr, "Unable to set notification content: %s\n", error_to_string(err));
132 err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon);
133 if (err != NOTIFICATION_ERROR_NONE) {
134 fprintf(stderr, "Unable to set notification icon path: %s\n", error_to_string(err));
140 err = notification_set_image(noti, imageType, image);
141 if (err != NOTIFICATION_ERROR_NONE) {
142 fprintf(stderr, "Unable to set notification image path: %s\n", error_to_string(err));
147 err = notification_insert(noti, NULL);
148 if (err != NOTIFICATION_ERROR_NONE) {
149 fprintf(stderr, "Unable to insert notification: %s\n", error_to_string(err));
153 fprintf(stdout, "Sent Notification > %s : %s : %s : %s : %i\n",
154 title, content, icon, image, imageType);