static GOptionContext * gth_application_create_option_context (void) { GOptionContext *context; static gsize initialized = FALSE; context = g_option_context_new (N_("— Image browser and viewer")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_set_ignore_unknown_options (context, TRUE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); if (g_once_init_enter (&initialized)) { g_option_context_add_group (context, gtk_get_option_group (TRUE)); #ifdef HAVE_CLUTTER g_option_context_add_group (context, clutter_get_option_group_without_init ()); g_option_context_add_group (context, gtk_clutter_get_option_group ()); #endif #ifdef HAVE_GSTREAMER g_option_context_add_group (context, gst_init_get_option_group ()); #endif g_once_init_leave (&initialized, TRUE); } return context; }
int main (int argc, char *argv[]) { GOptionContext *optcontext; GOptionEntry options[] = { { NULL } }; #ifdef ENABLE_DEBUG TpDebugSender *debug_sender; #endif GError *error = NULL; gint retval; GtkSettings *gtk_settings; /* Init */ g_thread_init (NULL); #ifdef GDK_WINDOWING_X11 /* We can't call clutter_gst_init() before gtk_clutter_init(), so no choice * but to intiialise X11 threading ourself */ XInitThreads (); #endif /* Clutter needs this */ gdk_disable_multidevice (); optcontext = g_option_context_new (N_("- Empathy Audio/Video Client")); g_option_context_add_group (optcontext, gst_init_get_option_group ()); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_group (optcontext, cogl_get_option_group ()); g_option_context_add_group (optcontext, clutter_get_option_group_without_init ()); g_option_context_add_group (optcontext, gtk_clutter_get_option_group ()); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command " "line options.\n", error->message, argv[0]); g_warning ("Error in empathy-call init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); clutter_gst_init (&argc, &argv); empathy_gtk_init (); g_set_application_name (_("Empathy Audio/Video Client")); /* Make empathy and empathy-call appear as the same app in gnome-shell */ gdk_set_program_class ("Empathy"); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); gtk_settings = gtk_settings_get_default (); g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL); app = gtk_application_new (EMPATHY_CALL_DBUS_NAME, G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL); #ifdef ENABLE_DEBUG /* Set up debug sender */ debug_sender = tp_debug_sender_dup (); g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN); #endif if (g_getenv ("EMPATHY_PERSIST") != NULL) { DEBUG ("Disable timer"); use_timer = FALSE; } call_windows = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL); /* the inactivity timeout can only be set while the application is held */ g_application_hold (G_APPLICATION (app)); g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000); g_application_release (G_APPLICATION (app)); retval = g_application_run (G_APPLICATION (app), argc, argv); g_hash_table_unref (call_windows); g_object_unref (app); tp_clear_object (&call_factory); #ifdef ENABLE_DEBUG g_object_unref (debug_sender); #endif return retval; }
gint main (gint argc, gchar ** argv) { gboolean res = FALSE; gchar *command = NULL, *input_file_name = NULL; BtEditApplication *app; GOptionContext *ctx = NULL; GOptionGroup *group; GError *err = NULL; #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif /* ENABLE_NLS */ bt_setup_for_local_install (); GOptionEntry options[] = { {"version", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) parse_goption_arg, N_("Print application version"), NULL} , {"command", 'c', 0, G_OPTION_ARG_STRING, &command, N_("Command name"), "{load}"} , {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &input_file_name, N_("Input file name"), N_("<songfile>")} , {NULL} }; // init libraries ctx = g_option_context_new (NULL); //g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); group = g_option_group_new ("main", _("buzztrax-edit options"), _("Show buzztrax-edit options"), argv[0], NULL); g_option_group_add_entries (group, options); g_option_group_set_translation_domain (group, GETTEXT_PACKAGE); g_option_context_set_main_group (ctx, group); bt_init_add_option_groups (ctx); g_option_context_add_group (ctx, btic_init_get_option_group ()); g_option_context_add_group (ctx, gtk_get_option_group (TRUE)); g_option_context_add_group (ctx, clutter_get_option_group_without_init ()); g_option_context_add_group (ctx, gtk_clutter_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", safe_string (err->message)); g_error_free (err); goto Done; } GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "bt-edit", 0, "music production environment / editor ui"); // give some global context info g_set_prgname ("buzztrax-edit"); g_set_application_name ("Buzztrax"); gtk_window_set_default_icon_name ("buzztrax"); g_setenv ("PULSE_PROP_media.role", "production", TRUE); extern gboolean bt_memory_audio_src_plugin_init (GstPlugin * const plugin); gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR, "memoryaudiosrc", "Plays audio from memory", bt_memory_audio_src_plugin_init, VERSION, "LGPL", PACKAGE, PACKAGE_NAME, "http://www.buzztrax.org"); GST_INFO ("starting: thread=%p", g_thread_self ()); app = bt_edit_application_new (); // set a default command, if a file is given if (!command && BT_IS_STRING (input_file_name)) { command = g_strdup ("l"); } if (command) { // depending on the options call the correct method if (!strcmp (command, "l") || !strcmp (command, "load")) { if (!BT_IS_STRING (input_file_name)) { usage (argc, argv, ctx); // if commandline options where wrong, just start res = bt_edit_application_run (app); } else { res = bt_edit_application_load_and_run (app, input_file_name); } } else { usage (argc, argv, ctx); // if commandline options where wrong, just start res = bt_edit_application_run (app); } } else { res = bt_edit_application_run (app); } // free application GST_INFO ("app %" G_OBJECT_REF_COUNT_FMT, G_OBJECT_LOG_REF_COUNT (app)); g_object_unref (app); Done: g_free (command); g_free (input_file_name); g_option_context_free (ctx); return !res; }
static void main_prog (void *closure, int argc, char *argv[]) { AppData data; GOptionContext *option_context; GError *error = NULL; gboolean retval; memset (&data, 0, sizeof (AppData)); option_context = g_option_context_new (NULL); g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE); add_main_options (option_context, &data); ar_sound_enable (FALSE); g_option_context_add_group (option_context, gtk_get_option_group (TRUE)); #ifdef HAVE_CLUTTER g_option_context_add_group (option_context, cogl_get_option_group ()); g_option_context_add_group (option_context, clutter_get_option_group_without_init ()); g_option_context_add_group (option_context, gtk_clutter_get_option_group ()); #endif /* HAVE_CLUTTER */ retval = g_option_context_parse (option_context, &argc, &argv, &error); g_option_context_free (option_context); if (!retval) { g_printerr ("%s\n", error->message); g_error_free (error); goto cleanup; } g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot")); aisleriot_conf_init (); /* If we are asked for a specific game, check that it is valid. */ if (!data.freecell && data.variation != NULL) { char *game_module = NULL; if (data.variation[0] != '\0') { game_module = ar_filename_to_game_module (data.variation); } g_free (data.variation); data.variation = game_module; } if (!data.freecell && !data.variation) { char *pref; pref = ar_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), DEFAULT_VARIATION); data.variation = ar_filename_to_game_module (pref); g_free (pref); } g_assert (data.variation != NULL || data.freecell); ar_stock_init (); gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot"); data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell)); g_signal_connect (data.window, "destroy", G_CALLBACK (gtk_main_quit), NULL); if (data.freecell) { aisleriot_window_set_game_module (data.window, FREECELL_VARIATION, NULL); } else { aisleriot_window_set_game_module (data.window, data.variation, NULL); } gtk_window_present (GTK_WINDOW (data.window)); gtk_main (); aisleriot_conf_shutdown (); cleanup: g_free (data.variation); g_settings_sync (); ar_runtime_shutdown (); }