int main (int argc, char** argv) { if (!notify_init ("append-hint-example")) return 1; /* call this so we can savely use has_cap(CAP_SOMETHING) later */ init_caps (); /* show what's supported */ print_caps (); /* try the append-hint */ if (has_cap (CAP_APPEND)) { push_notification ("Cole Raby", "Hey Bro Coly!", "notification-message-im"); push_notification ("Cole Raby", "What's up dude?", "notification-message-im"); push_notification ("Cole Raby", "Did you watch the air-race in Oshkosh last week?", "notification-message-im"); push_notification ("Cole Raby", "Phil owned the place like no one before him!", "notification-message-im"); push_notification ("Cole Raby", "Did really everything in the race work according to regulations?", "notification-message-im"); push_notification ("Cole Raby", "Somehow I think to remember Burt Williams did cut corners and was not punished for this.", "notification-message-im"); push_notification ("Cole Raby", "Hopefully the referees will watch the videos of the race.", "notification-message-im"); push_notification ("Cole Raby", "Burt could get fined with US$ 50000 for that rule-violation :)", "notification-message-im"); } else { g_print ("The daemon does not support the x-canonical-append hint!"); } notify_uninit (); return 0; }
static gboolean applet_check_icon (softupd_applet *applet) { char image_file[1024]; char msg[1024]; // Check if there are dead bones to collect check_dead_bones(applet); if (applet->icon_status == 0) { sprintf(&image_file[0], "%s/%s", APPLET_ICON_PATH, APPLET_ICON_OFF); gtk_widget_set_tooltip_text (GTK_WIDGET (applet->applet), _("Your system is up to date.")); } else { sprintf(&image_file[0], "%s/%s", APPLET_ICON_PATH, APPLET_ICON_ON); if (applet->pending >= 0) { sprintf(&msg[0], _("You have %u updates. Click to proceed."), applet->pending); } else { sprintf(&msg[0], _("Could not get count of pending updates.")); } gtk_widget_set_tooltip_text (GTK_WIDGET (applet->applet), &msg[0]); // Notification: only if icon status is ON and flip is ON if (applet->flip_icon == 1) { if (applet->pending >= 0) { sprintf(&msg[0], _("You have %u updates."), applet->pending); } else { sprintf(&msg[0], _("Could not get count of pending updates.")); } push_notification(_("Software updates available"), &msg[0], NULL); } } if (applet->flip_icon == 1) { gtk_image_set_from_file(GTK_IMAGE(applet->image), &image_file[0]); applet->flip_icon = 0; } return TRUE; }
gboolean applet_main (MyPanelApplet *applet_widget, const gchar *iid, gpointer data) { streamer_applet *applet; char *zErrMsg; int res, i; char ui[24576]; if (strcmp (iid, APPLET_ID) != 0) return FALSE; // i18n setlocale (LC_ALL, ""); bindtextdomain (PACKAGE_NAME, LOCALEDIR); bind_textdomain_codeset(PACKAGE_NAME, "utf-8"); textdomain (PACKAGE_NAME); // Init applet = g_malloc0(sizeof(streamer_applet)); applet->applet = applet_widget; memset(&applet->xml_listen_url[0], '\0', 1024); memset(&applet->xml_bitrate[0], '\0', 1024); memset(&applet->xml_server_name[0], '\0', 1024); memset(&applet->xml_genre[0], '\0', 1024); memset(&applet->url[0], '\0', 1024); memset(&applet->ui_fav[0], '\0', 10240); memset(&applet->ui_recent[0], '\0', 10240); applet->timestamp = time(NULL); applet->xml_curr_entries = 0; applet->icecast_total_entries = 0; applet->status = 0; for (i=0; i<10; i++) { memset(&applet->hash_fav[i].hash[0], '\0', 64); memset(&applet->hash_recent[i].hash[0], '\0', 64); } applet->settings.show_notifications = 0; applet->settings.duration_notifications = 5; #ifdef HAVE_GNOME_2 applet->bonobo_counter = 0; #endif // Check home dir, copy skel database char applet_home_dir[1024], skel_file[1024], local_file[1024]; struct stat stat_buf; struct passwd *pw = getpwuid(getuid()); sprintf(&applet_home_dir[0], "%s/%s", pw->pw_dir, APPLET_HOME_DIR); int stat_res = stat(&applet_home_dir[0], &stat_buf); int errsv = errno; if ((stat_res == 0) && (!S_ISDIR(stat_buf.st_mode))){ push_notification(_("Streamer Applet Error"), _("Cannot access configuration directory. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } else if (stat_res == -1) { if (errsv == ENOENT) { int mkdir_res = mkdir(&applet_home_dir[0], 0755); if (mkdir_res == 1) { push_notification(_("Streamer Applet Error"), _("Cannot create configuration directory. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } } else { push_notification(_("Streamer Applet Error"), _("Cannot verify configuration directory. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } } sprintf(&skel_file[0], "%s/%s", APPLET_SKEL_PATH, APPLET_SQLITE_DB_FILENAME); sprintf(&local_file[0], "%s/%s/%s", pw->pw_dir, APPLET_HOME_DIR, APPLET_SQLITE_DB_FILENAME); stat_res = stat(&local_file[0], &stat_buf); errsv = errno; if ((stat_res == 0) && (!S_ISREG(stat_buf.st_mode))){ push_notification(_("Streamer Applet Error"), _("Database file is not a regular file. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); } else if (stat_res == -1) { if (errsv == ENOENT) { if (!cp(&local_file[0], &skel_file[0])) { push_notification(_("Streamer Applet Error"), _("Cannot copy database file to configuration directory. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } } else { push_notification(_("Streamer Applet Error"), _("Cannot verify database file. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } } // Test DB connection, upgrade DB if necessary if (!sqlite_connect(applet)) { push_notification(_("Streamer Applet Error"), _("Unable to connect to DB. Exiting."), NULL, DEFAULT_NOTIFICATION_DURATION); return FALSE; } zErrMsg = 0; res = sqlite3_exec(applet->sqlite, "SELECT version FROM version", cb_sql_version, (void*) applet, &zErrMsg); if (res != SQLITE_OK) { push_notification(_("Streamer Applet Error"), zErrMsg, NULL, DEFAULT_NOTIFICATION_DURATION); sqlite3_free(zErrMsg); return FALSE; } if (applet->db_version == 1) { // Upgrade DB to version 2 sqlite_insert(applet, "CREATE TABLE custom_stations (server_name VARCHAR(255), listen_url VARCHAR(255), bitrate VARCHAR(255), genre VARCHAR(255))"); sqlite_insert(applet, "ALTER TABLE stations RENAME TO icecast_stations"); sqlite_insert(applet, "UPDATE version SET version=2"); } else if (applet->db_version == 2) { // Upgrade DB to version 3 sqlite_insert(applet, "CREATE TABLE rbrowser_stations (server_name VARCHAR(255), listen_url VARCHAR(255), bitrate VARCHAR(255), genre VARCHAR(255))"); sqlite_insert(applet, "UPDATE version SET version=3"); } sqlite3_close(applet->sqlite); // Init GStreamer gstreamer_init(applet); // Get an image char image_file[1024]; sprintf(&image_file[0], "%s/%s", APPLET_ICON_PATH, APPLET_ICON_PAUSE); applet->image = gtk_image_new_from_file (&image_file[0]); // Put the image into a container (it needs to receive actions) applet->event_box = gtk_event_box_new(); gtk_container_add (GTK_CONTAINER (applet->event_box), applet->image); // Put the container into the applet gtk_container_add (GTK_CONTAINER (applet->applet), applet->event_box); // Define menu action group #ifdef HAVE_MATE applet->action_group = gtk_action_group_new ("Streamer_Applet_Actions"); gtk_action_group_set_translation_domain(applet->action_group, PACKAGE_NAME); gtk_action_group_add_actions (applet->action_group, applet_menu_actions_mate, G_N_ELEMENTS (applet_menu_actions_mate), applet); #endif // Get last 10 entried from Recent & Fav, then fetch last URL if (!sqlite_connect(applet)) return FALSE; zErrMsg = 0; memset(&applet->ui_recent[0], '\0', 1); res = sqlite3_exec(applet->sqlite, "SELECT server_name, listen_url FROM recent GROUP BY listen_url ORDER BY unix_timestamp DESC LIMIT 10", cb_sql_recent_10, (void*) applet, &zErrMsg); if (res != SQLITE_OK) { push_notification(_("Streamer Applet Error"), zErrMsg, NULL, DEFAULT_NOTIFICATION_DURATION); sqlite3_free(zErrMsg); return FALSE; } memset(&applet->ui_fav[0], '\0', 1); res = sqlite3_exec(applet->sqlite, "SELECT server_name, listen_url FROM favourites LIMIT 10", cb_sql_fav_10, (void*) applet, &zErrMsg); if (res != SQLITE_OK) { push_notification(_("Streamer Applet Error"), zErrMsg, NULL, DEFAULT_NOTIFICATION_DURATION); sqlite3_free(zErrMsg); return FALSE; } res = sqlite3_exec(applet->sqlite, "SELECT * FROM recent ORDER BY unix_timestamp DESC LIMIT 1", cb_sql_recent, (void*) applet, &zErrMsg); if (res != SQLITE_OK) { push_notification(_("Streamer Applet Error"), zErrMsg, NULL, DEFAULT_NOTIFICATION_DURATION); sqlite3_free(zErrMsg); return FALSE; } sqlite3_free(zErrMsg); sqlite3_close(applet->sqlite); // Build menu sprintf(&ui[0], "%s %s %s %s %s", ui1, &applet->ui_recent[0], ui2, &applet->ui_fav[0], ui3); #ifdef HAVE_MATE mate_panel_applet_setup_menu(applet->applet, &ui[0], applet->action_group); #elif HAVE_GNOME_2 BonoboUIVerb bnb1 = BONOBO_UI_UNSAFE_VERB ("All", G_CALLBACK (menu_cb_all)); applet->applet_menu_actions_gnome[applet->bonobo_counter] = bnb1; applet->bonobo_counter++; BonoboUIVerb bnb1a = BONOBO_UI_UNSAFE_VERB ("Settings", G_CALLBACK (menu_cb_settings)); applet->applet_menu_actions_gnome[applet->bonobo_counter] = bnb1a; applet->bonobo_counter++; BonoboUIVerb bnb2 = BONOBO_UI_UNSAFE_VERB ("About", G_CALLBACK (menu_cb_about)); applet->applet_menu_actions_gnome[applet->bonobo_counter] = bnb2; applet->bonobo_counter++; BonoboUIVerb bnb3 = BONOBO_UI_VERB_END; applet->applet_menu_actions_gnome[applet->bonobo_counter] = bnb3; applet->bonobo_counter++; panel_applet_setup_menu(applet->applet, &ui[0], applet->applet_menu_actions_gnome, applet); #endif // Merge menu //GError **error; //char ui[10240]; //sprintf(&ui[0], "<menu action='SubMenu1'>\n<menuitem action='All'/>\n<menuitem action='All'/></menu>"); //guint merge_id = gtk_ui_manager_add_ui_from_string (applet->applet->priv->ui_manager, &ui[0], -1, error); // Settings: Prepare DConf - GNOME2 only #ifdef HAVE_GNOME_2 if (!panel_applet_gconf_get_bool(PANEL_APPLET(applet->applet), "have_settings", NULL)) { panel_applet_gconf_set_bool(PANEL_APPLET(applet->applet), "have_settings", TRUE, NULL); panel_applet_gconf_set_int(PANEL_APPLET(applet->applet), APPLET_KEY_OPTION_1, 0, NULL); panel_applet_gconf_set_int(PANEL_APPLET(applet->applet), APPLET_KEY_OPTION_2, 5, NULL); } #endif // Load settings #ifdef HAVE_MATE applet->gsettings = g_settings_new_with_path(APPLET_GSETTINGS_SCHEMA, APPLET_GSETTINGS_PATH); applet->settings.show_notifications = g_settings_get_int(applet->gsettings, APPLET_KEY_OPTION_1); applet->settings.duration_notifications = g_settings_get_int(applet->gsettings, APPLET_KEY_OPTION_2); #elif HAVE_GNOME_2 applet->settings.show_notifications = panel_applet_gconf_get_int(PANEL_APPLET(applet->applet), APPLET_KEY_OPTION_1, NULL); applet->settings.duration_notifications = panel_applet_gconf_get_int(PANEL_APPLET(applet->applet), APPLET_KEY_OPTION_2, NULL); #endif // Signals g_signal_connect(G_OBJECT(applet->event_box), "button_press_event", G_CALLBACK (on_left_click), (gpointer)applet); g_signal_connect(G_OBJECT(applet->applet), "change_background", G_CALLBACK (applet_back_change), (gpointer)applet); g_signal_connect(G_OBJECT(applet->applet), "destroy", G_CALLBACK(applet_destroy), (gpointer)applet); // Tooltip gtk_widget_set_tooltip_text (GTK_WIDGET (applet->applet), _("No stream selected. Right-click to load one.")); // Show applet gtk_widget_show_all (GTK_WIDGET (applet->applet)); // Run applet->loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (applet->loop); return TRUE; }
Error MessageQueue::push_notification(Object *p_object, int p_notification) { return push_notification(p_object->get_instance_ID(),p_notification); }