static void remove_contact_by_uid_cb (GObject *source_object, GAsyncResult *result, gpointer uid) { GError *error = NULL; EContact *contact = NULL; if (!e_book_client_remove_contact_by_uid_finish (E_BOOK_CLIENT (source_object), result, &error)) { report_error ("remove contact by uid finish", &error); stop_main_loop (1); return; } if (!e_book_client_get_contact_sync (E_BOOK_CLIENT (source_object), uid, &contact, NULL, &error) && g_error_matches (error, E_BOOK_CLIENT_ERROR, E_BOOK_CLIENT_ERROR_CONTACT_NOT_FOUND)) { g_clear_error (&error); stop_main_loop (0); } else { report_error ("fail with get contact on removed contact", &error); if (contact) g_object_unref (contact); stop_main_loop (1); } }
/* synchronously in idle with main-loop running */ static gboolean test_sync_in_idle (gpointer user_data) { ECalClient *cal_client = user_data; icalcomponent *icalcomp; g_return_val_if_fail (cal_client != NULL, FALSE); g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE); if (!test_sync (cal_client)) { stop_main_loop (1); return FALSE; } icalcomp = create_object (); if (!icalcomp) { stop_main_loop (1); return FALSE; } e_cal_client_send_objects (cal_client, icalcomp, NULL, async_send_result_ready, NULL); icalcomponent_free (icalcomp); return FALSE; }
static void finish_test (EBookClientView *view) { e_book_client_view_stop (view, NULL); g_object_unref (view); stop_main_loop (0); }
static void add_contact_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { GError *error = NULL; gchar *uid; if (!e_book_client_add_contact_finish (E_BOOK_CLIENT (source_object), result, &uid, &error)) { report_error ("add contact finish", &error); stop_main_loop (1); return; } printf ("Contact added as '%s'\n", uid); g_free (uid); stop_main_loop (0); }
/* asynchronous callback with a main-loop running */ static void async_refresh_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_client_refresh_finish (E_CLIENT (cal_client), result, &error)) { report_error ("refresh finish", &error); stop_main_loop (1); return; } stop_main_loop (0); }
/* asynchronous callback with a main-loop running */ static void async_attachment_uris_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; GSList *attachment_uris = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error)) { report_error ("get attachment uris finish", &error); stop_main_loop (1); return; } stop_main_loop (manage_result (attachment_uris) ? 0 : 1); }
/* asynchronous callback with a main-loop running */ static void async_send_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; GSList *users = NULL; icalcomponent *modified_icalcomp = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error)) { report_error ("send objects finish", &error); stop_main_loop (1); return; } stop_main_loop (manage_result (users, modified_icalcomp) ? 0 : 1); }
/**************************************************************** * Modify/Setup the EBook * ****************************************************************/ static void add_contact (EBookClient *client) { EContact *contact = e_contact_new (); e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson"); if (!add_contact_verify (client, contact)) stop_main_loop (1); g_object_unref (contact); }
/* synchronously in a dedicated thread with main-loop running */ static gpointer test_sync_in_thread (gpointer user_data) { if (!test_sync ()) { stop_main_loop (1); return NULL; } g_idle_add (test_sync_in_idle, NULL); return NULL; }
static void get_view_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { EBookClientView *view; GError *error = NULL; if (!e_book_client_get_view_finish (E_BOOK_CLIENT (source_object), result, &view, &error)) { report_error ("get view finish", &error); stop_main_loop (1); return; } setup_and_start_view (view); }
/* synchronously in idle with main-loop running */ static gboolean test_sync_in_idle (gpointer user_data) { ECalClient *cal_client; if (!test_sync ()) { stop_main_loop (1); return FALSE; } cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL); g_return_val_if_fail (cal_client != NULL, FALSE); e_client_open (E_CLIENT (cal_client), FALSE, NULL, async_open_ready, NULL); return FALSE; }
/* asynchronous open callback with a main-loop running */ static void async_open_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_client_open_finish (E_CLIENT (cal_client), result, &error)) { report_error ("open finish", &error); g_object_unref (cal_client); stop_main_loop (1); return; } e_client_remove (E_CLIENT (cal_client), NULL, async_remove_ready, NULL); }
/* synchronously in idle with main-loop running */ static gboolean test_sync_in_idle (gpointer user_data) { ECalClient *cal_client = user_data; g_return_val_if_fail (cal_client != NULL, FALSE); g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE); if (!test_sync (cal_client)) { stop_main_loop (1); return FALSE; } g_print ("Refresh supported: %s\n", e_client_check_refresh_supported (E_CLIENT (cal_client)) ? "yes" : "no"); e_client_refresh (E_CLIENT (cal_client), NULL, async_refresh_result_ready, NULL); return FALSE; }
/* synchronously in idle with main-loop running */ static gboolean test_sync_in_idle (gpointer user_data) { ECalClient *cal_client = user_data; const gchar *uid; g_return_val_if_fail (cal_client != NULL, FALSE); g_return_val_if_fail (E_IS_CAL_CLIENT (cal_client), FALSE); if (!test_sync (cal_client)) { stop_main_loop (1); return FALSE; } uid = g_object_get_data (G_OBJECT (cal_client), "use-uid"); e_cal_client_get_attachment_uris (cal_client, uid, NULL, NULL, async_attachment_uris_result_ready, NULL); return FALSE; }
gboolean start_new_game (gchar *game_filename, gchar *graphics_filename, gchar *splash_filename, gchar *music_filename, gchar *hints_filename) { const gchar *filters[] = { "Magnetic Scrolls data file (*.mag)", "*.mag", NULL }; if (!game_filename) game_filename = file_selector (FALSE, NULL, filters, "Open game file"); if (!game_filename) return TRUE; stop_main_loop (); if (ms_is_running ()) { ms_stop (); ms_freemem (); } stop_recording (TRUE); stop_scripting (TRUE); stop_replaying (TRUE); if (!graphics_filename) graphics_filename = change_file_extension (game_filename, "gfx"); if (!splash_filename) splash_filename = change_file_extension (game_filename, "png"); if (!music_filename) music_filename = change_file_extension (game_filename, "mp3"); if (!hints_filename) hints_filename = change_file_extension (game_filename, "hnt"); display_splash_screen (splash_filename, music_filename); text_clear (); graphics_clear (); hints_clear (); if (applicationExiting) return FALSE; if (!ms_init ((type8s *) game_filename, (type8s *) graphics_filename, (type8s *) hints_filename), NULL) { GtkWidget *error; gchar *basename; basename = g_path_get_basename (game_filename); error = gtk_message_dialog_new ( GTK_WINDOW (Gui.main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Could not start the game! The most likely cause is\n" "that '%s' is not a valid game file.", basename); gtk_dialog_run (GTK_DIALOG (error)); g_free (basename); gtk_widget_destroy (error); } else start_main_loop (); g_free (game_filename); g_free (graphics_filename); g_free (splash_filename); g_free (music_filename); g_free (hints_filename); gtk_widget_grab_focus (Gui.text_view); return TRUE; }
gboolean deliver_signal(GIOChannel * source, GIOCondition cond, gpointer d) { GError *error = NULL; /* for error handling */ union { gchar chars[sizeof(int)]; int signal; } buf; GIOStatus status; /* save the reading status */ gsize bytes_read; /* save the number of chars read */ /* * Read from the pipe as long as data is available. The reading end is * also in non-blocking mode, so if we have consumed all unix signals, * the read returns G_IO_STATUS_AGAIN. */ while ((status = g_io_channel_read_chars(source, buf.chars, sizeof(int), &bytes_read, &error)) == G_IO_STATUS_NORMAL) { g_assert(error == NULL); /* no error if reading returns normal */ /* * There might be some problem resulting in too few char's read. * Check it. */ if (bytes_read != sizeof(int)) { g_warning ("lost data in signal pipe (expected %u, received %d)\n", sizeof(int), (int)bytes_read); continue; /* discard the garbage and keep fingers crossed */ } switch (buf.signal) { case SIGWINCH: redraw_interface(); break; case SIGINT: case SIGTERM: case SIGABRT: stop_main_loop(); break; default: break; } } if (error != NULL) { g_error("reading signal pipe failed: %s\n", error->message); } if (status == G_IO_STATUS_EOF) { g_error("signal pipe has been closed\n"); } g_assert(status == G_IO_STATUS_AGAIN); return (TRUE); }
int quit(const std::vector<std::string> &args) { LocalClient::quit(); stop_main_loop(); return 1; }