Advertisement
Guest User

notifytester.c

a guest
Apr 29th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <libnotify/notify.h>
  3.  
  4. void quit (NotifyNotification *notification, const char *action, gpointer user_data)
  5. {
  6.     notify_notification_close(notification,NULL);
  7.     notify_uninit();
  8.     exit(0);
  9. }
  10.  
  11. void callbackfunc (NotifyNotification *notification, const char *action, gpointer user_data)
  12. {
  13.     notify_notification_clear_actions (notification);
  14.     int pause = g_strcmp0(action,"play");
  15.     notify_notification_add_action (notification, pause ? "play" : "pause", pause ? "Play" : "Pause",NOTIFY_ACTION_CALLBACK(callbackfunc),NULL,NULL);
  16.         notify_notification_add_action (notification,"quit","Quit",NOTIFY_ACTION_CALLBACK(quit),"play",NULL);
  17.     if(!notify_notification_show(notification,NULL))
  18.         printf("Error when showing the notification\n");
  19.     return;
  20. }
  21.  
  22.  
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26.     if(argc!=2 || (g_strcmp0(argv[1],"-pixbuf") && g_strcmp0(argv[1],"-path")))
  27.     {
  28.         printf("Usage : %s -pixbuf for pixbuf-sharing test, %s -path for path-sharing test\n",argv[0],argv[0]);
  29.         exit(1);
  30.     }
  31.  
  32.     if (!notify_init("Test"))
  33.         printf("Initialization failure");
  34.     NotifyNotification * notif = notify_notification_new("Test","To check performance",NULL);
  35.  
  36.     if(!g_strcmp0(argv[1],"-pixbuf"))
  37.     {
  38.         GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file("/usr/share/icons/gnome/256x256/status/trophy-gold.png",NULL);
  39.         notify_notification_set_image_from_pixbuf(notif, pixbuf);
  40.     }
  41.     else
  42.         notify_notification_set_hint_string (notif,"image_path", "/usr/share/icons/gnome/256x256/status/trophy-gold.png"); 
  43.  
  44.     notify_notification_set_hint (notif, "resident", g_variant_new_boolean (TRUE));
  45.         notify_notification_add_action (notif,"play","Play",NOTIFY_ACTION_CALLBACK(callbackfunc),"play",NULL);
  46.         notify_notification_add_action (notif,"quit","Quit",NOTIFY_ACTION_CALLBACK(quit),"play",NULL);
  47.  
  48.    
  49.     GError *error = NULL;
  50.     if(!notify_notification_show(notif,&error))
  51.         printf("Error when showing the notification\n");
  52.     notify_notification_close(notif,NULL);
  53.     if (error) {printf("Error: %s\n", error->message);}
  54.     if(!notify_notification_show(notif,&error))
  55.         printf("Error when showing the notification\n");
  56.     GMainLoop * gml = g_main_loop_new(NULL,TRUE);
  57.     g_main_loop_run(gml);
  58.     notify_uninit();
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement