Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <libnotify/notify.h>
- void quit (NotifyNotification *notification, const char *action, gpointer user_data)
- {
- notify_notification_close(notification,NULL);
- notify_uninit();
- exit(0);
- }
- void callbackfunc (NotifyNotification *notification, const char *action, gpointer user_data)
- {
- notify_notification_clear_actions (notification);
- int pause = g_strcmp0(action,"play");
- notify_notification_add_action (notification, pause ? "play" : "pause", pause ? "Play" : "Pause",NOTIFY_ACTION_CALLBACK(callbackfunc),NULL,NULL);
- notify_notification_add_action (notification,"quit","Quit",NOTIFY_ACTION_CALLBACK(quit),"play",NULL);
- if(!notify_notification_show(notification,NULL))
- printf("Error when showing the notification\n");
- return;
- }
- int main(int argc, char* argv[])
- {
- if(argc!=2 || (g_strcmp0(argv[1],"-pixbuf") && g_strcmp0(argv[1],"-path")))
- {
- printf("Usage : %s -pixbuf for pixbuf-sharing test, %s -path for path-sharing test\n",argv[0],argv[0]);
- exit(1);
- }
- if (!notify_init("Test"))
- printf("Initialization failure");
- NotifyNotification * notif = notify_notification_new("Test","To check performance",NULL);
- if(!g_strcmp0(argv[1],"-pixbuf"))
- {
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("/usr/share/icons/gnome/256x256/status/trophy-gold.png",NULL);
- notify_notification_set_image_from_pixbuf(notif, pixbuf);
- }
- else
- notify_notification_set_hint_string (notif,"image_path", "/usr/share/icons/gnome/256x256/status/trophy-gold.png");
- notify_notification_set_hint (notif, "resident", g_variant_new_boolean (TRUE));
- notify_notification_add_action (notif,"play","Play",NOTIFY_ACTION_CALLBACK(callbackfunc),"play",NULL);
- notify_notification_add_action (notif,"quit","Quit",NOTIFY_ACTION_CALLBACK(quit),"play",NULL);
- GError *error = NULL;
- if(!notify_notification_show(notif,&error))
- printf("Error when showing the notification\n");
- notify_notification_close(notif,NULL);
- if (error) {printf("Error: %s\n", error->message);}
- if(!notify_notification_show(notif,&error))
- printf("Error when showing the notification\n");
- GMainLoop * gml = g_main_loop_new(NULL,TRUE);
- g_main_loop_run(gml);
- notify_uninit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement