18 #define CHECK(X) do { \
21 fprintf(stderr, "%s:%i: Error calling %s!\n", __FILE__, __LINE__, S(X)); \
29 printf("e-notify-send "VERSION"\n");
36 " e-notify-send [OPTION...] <SUMMARY> [BODY] - create a notification\n"
39 " -?, --help Show help options\n"
41 "Application Options:\n"
42 " -n, --name=NAME Specifies the application name to use (default is e-notify-send).\n"
43 " -u, --urgency=LEVEL Specifies the urgency level (low, normal, critical).\n"
44 " -t, --expire-time=TIME Specifies the timeout in milliseconds at which to expire the notification.\n"
45 " -r, --replace=ID Specifies the ID of notification to replace.\n"
46 " -p, --print-id Prints the ID of notification to STDOUT.\n"
47 " -i, --icon=ICON Specifies an icon filename or stock icon to display.\n"
48 " -c, --category=TYPE Specifies the notification category.\n"
49 " -v, --version Version of the package.\n"
54 read_int_arg(long long *result, const char *name, intmax_t min, intmax_t max)
59 *result = strtoll(optarg, &endptr, 10);
60 if ((errno != 0 && *result == 0) || endptr == optarg)
62 fprintf(stderr, "Cannot parse integer value '%s' for %s\n", optarg, name);
65 else if (*result > max || *result < min)
67 fprintf(stderr, "Integer value '%s' for %s out of range\n", optarg, name);
75 send_cb(void *user_data __UNUSED__, void *method_return, DBusError *error __UNUSED__)
77 E_Notification_Return_Notify *r = method_return;
82 printf("%u\n", r->notification_id );
84 ecore_main_loop_quit();
88 main(int argc, char **argv)
97 CHECK(e_notification_init());
98 n = e_notification_new();
99 e_notification_app_name_set(n, "e-notify-send");
100 e_notification_timeout_set(n, -1);
102 /* options descriptor */
103 static struct option longopts[] = {
104 { "help", no_argument, NULL, '?' },
105 { "name", required_argument, NULL, 'n' },
106 { "urgency", required_argument, NULL, 'u' },
107 { "expire-time", required_argument, NULL, 't' },
108 { "replace", required_argument, NULL, 'r' },
109 { "print-id", no_argument, NULL, 'p' },
110 { "icon", required_argument, NULL, 'i' },
111 { "category", required_argument, NULL, 'c' },
112 { "version", no_argument, NULL, 'v' },
116 while ((ch = getopt_long(argc, argv, "p?vn:u:t:r:i:c:", longopts, NULL)) != -1)
127 e_notification_app_name_set(n, optarg);
130 if (!strcasecmp(optarg, "low"))
131 e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_LOW);
132 else if (!strcasecmp(optarg, "normal"))
133 e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_NORMAL);
134 else if (!strcasecmp(optarg, "critical"))
135 e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_CRITICAL);
137 printf("Urgency level must be: low, normal or critical\n");
140 if (!read_int_arg(&value, "-t", INT_MIN, INT_MAX))
143 e_notification_timeout_set(n, (int)value);
146 if (!read_int_arg(&value, "-r", 0, UINT_MAX))
149 e_notification_replaces_id_set(n, (unsigned int)value);
152 e_notification_app_icon_set(n, optarg);
155 e_notification_hint_category_set(n, optarg);
173 e_notification_summary_set(n, argv[0]);
174 if (argc > 1) e_notification_body_set(n, argv[1]);
179 e_notification_send(n, send_cb, NULL);
180 ecore_main_loop_begin();
183 e_notification_send(n, NULL, NULL);
185 e_notification_unref(n);
186 e_notification_shutdown();