int main (int argc, char **argv) { MyApp *app; GOptionContext *context; GError *error = NULL; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); context = g_option_context_new (N_("- Manage your mobile phone")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_error ("Couldn't parse options: %s", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (version != FALSE) { g_print (_("gnome-phone-manager version %s\n"), VERSION); return 0; } if (bdaddr_ident != NULL) { phonemgr_utils_tell_driver (bdaddr_ident); return 0; } if (bdaddr_config != NULL) { phonemgr_utils_write_gnokii_config (bdaddr_config); return 0; } gconf_init (argc, argv, NULL); app = g_new0 (MyApp, 1); /* Setup the D-Bus object */ app->object = g_object_new (phonemgr_object_get_type (), NULL); app->client = gconf_client_get_default (); gconf_client_add_dir (app->client, CONFBASE, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); /* Setup the listener */ app->listener = phonemgr_listener_new (debug); initialise_connection (app); ui_init (app); construct_menu (app); tray_icon_init (app); reconnect_phone (app); gtk_main (); tray_icon_hide (app); ui_hide (app); free_connection (app); g_object_unref (app->listener); g_object_unref (app->client); g_object_unref (app->object); g_free (app); return 0; }
int main(int argc, char *argv[]) { struct stat buf = { 0 }; struct mntent *mnt = NULL; FILE *fp = NULL; gchar *uri; gint fileindex = 1; GError *error = NULL; GOptionContext *context; gint i; gdouble volume = 100.0; gchar *accelerator_keys; gchar **parse; #ifdef GTK3_ENABLED GtkSettings *gtk_settings; #endif int stat_result; #ifndef OS_WIN32 struct sigaction sa; #endif gboolean playiter = FALSE; #ifdef GIO_ENABLED GFile *file; #endif #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif playlist = 0; embed_window = 0; control_id = 0; window_x = 0; window_y = 0; last_window_width = 0; last_window_height = 0; showcontrols = 1; showsubtitles = TRUE; autostart = 1; videopresent = 0; disable_context_menu = FALSE; dontplaynext = FALSE; idledata = (IdleData *) g_new0(IdleData, 1); idledata->videopresent = FALSE; idledata->length = 0.0; idledata->device = NULL; idledata->cachepercent = -1.0; selection = NULL; path = NULL; js_state = STATE_UNDEFINED; control_instance = TRUE; playlistname = NULL; rpconsole = NULL; subtitle = NULL; tv_device = NULL; tv_driver = NULL; tv_width = 0; tv_height = 0; tv_fps = 0; ok_to_play = TRUE; alang = NULL; slang = NULL; metadata_codepage = NULL; playlistname = NULL; window_width = -1; window_height = -1; stored_window_width = -1; stored_window_height = -1; cache_size = 0; forcecache = FALSE; use_volume_option = FALSE; vertical_layout = FALSE; playlist_visible = FALSE; disable_fullscreen = FALSE; disable_framedrop = FALSE; softvol = FALSE; remember_softvol = FALSE; volume_softvol = -1; volume_gain = 0; subtitlefont = NULL; subtitle_codepage = NULL; subtitle_color = NULL; subtitle_outline = FALSE; subtitle_shadow = FALSE; subtitle_fuzziness = 0; disable_embeddedfonts = FALSE; quit_on_complete = FALSE; verbose = 0; reallyverbose = 0; embedding_disabled = FALSE; disable_pause_on_click = FALSE; disable_animation = FALSE; auto_hide_timeout = 3; mouse_over_controls = FALSE; use_mediakeys = TRUE; use_defaultpl = FALSE; mplayer_bin = NULL; mplayer_dvd_device = NULL; single_instance = FALSE; disable_deinterlace = TRUE; details_visible = FALSE; replace_and_play = FALSE; bring_to_front = FALSE; keep_on_top = FALSE; resize_on_new_media = FALSE; use_pausing_keep_force = FALSE; show_notification = TRUE; show_status_icon = TRUE; lang_group = NULL; audio_group = NULL; gpod_mount_point = NULL; load_tracks_from_gpod = FALSE; disable_cover_art_fetch = FALSE; fullscreen = 0; vo = NULL; data = NULL; max_data = NULL; details_table = NULL; large_buttons = FALSE; button_size = GTK_ICON_SIZE_BUTTON; lastguistate = -1; non_fs_height = 0; non_fs_width = 0; use_hw_audio = FALSE; start_second = 0; play_length = 0; save_loc = TRUE; use_xscrnsaver = FALSE; screensaver_disabled = FALSE; update_control_flag = FALSE; gchar *filename; skip_fixed_allocation_on_show = FALSE; skip_fixed_allocation_on_hide = FALSE; pref_volume = -1; use_mplayer2 = FALSE; enable_global_menu = FALSE; #ifndef OS_WIN32 sa.sa_handler = hup_handler; sigemptyset(&sa.sa_mask); #ifdef SA_RESTART sa.sa_flags = SA_RESTART; /* Restart functions if interrupted by handler */ #endif #ifdef SIGINT if (sigaction(SIGINT, &sa, NULL) == -1) printf("SIGINT signal handler not installed\n"); #endif #ifdef SIGHUP if (sigaction(SIGHUP, &sa, NULL) == -1) printf("SIGHUP signal handler not installed\n"); #endif #ifdef SIGTERM if (sigaction(SIGTERM, &sa, NULL) == -1) printf("SIGTERM signal handler not installed\n"); #endif #endif // call g_type_init or otherwise we can crash gtk_init(&argc, &argv); if (!g_thread_supported()) g_thread_init(NULL); uri = g_strdup_printf("%s/gnome-mplayer/cover_art", g_get_user_config_dir()); if (!g_file_test(uri, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents(uri, 0775); } g_free(uri); uri = g_strdup_printf("%s/gnome-mplayer/plugin", g_get_user_config_dir()); if (!g_file_test(uri, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents(uri, 0775); } g_free(uri); uri = NULL; default_playlist = g_strdup_printf("file://%s/gnome-mplayer/default.pls", g_get_user_config_dir()); safe_to_save_default_playlist = TRUE; gm_store = gm_pref_store_new("gnome-mplayer"); gmp_store = gm_pref_store_new("gecko-mediaplayer"); vo = gm_pref_store_get_string(gm_store, VO); audio_device.alsa_mixer = gm_pref_store_get_string(gm_store, ALSA_MIXER); use_hardware_codecs = gm_pref_store_get_boolean(gm_store, USE_HARDWARE_CODECS); use_crystalhd_codecs = gm_pref_store_get_boolean(gm_store, USE_CRYSTALHD_CODECS); osdlevel = gm_pref_store_get_int(gm_store, OSDLEVEL); pplevel = gm_pref_store_get_int(gm_store, PPLEVEL); #ifndef HAVE_ASOUNDLIB volume = gm_pref_store_get_int(gm_store, VOLUME); #endif audio_channels = gm_pref_store_get_int(gm_store, AUDIO_CHANNELS); use_hw_audio = gm_pref_store_get_boolean(gm_store, USE_HW_AUDIO); fullscreen = gm_pref_store_get_boolean(gm_store, FULLSCREEN); softvol = gm_pref_store_get_boolean(gm_store, SOFTVOL); remember_softvol = gm_pref_store_get_boolean(gm_store, REMEMBER_SOFTVOL); volume_softvol = gm_pref_store_get_float(gm_store, VOLUME_SOFTVOL); volume_gain = gm_pref_store_get_int(gm_store, VOLUME_GAIN); forcecache = gm_pref_store_get_boolean(gm_store, FORCECACHE); vertical_layout = gm_pref_store_get_boolean(gm_store, VERTICAL); playlist_visible = gm_pref_store_get_boolean(gm_store, SHOWPLAYLIST); details_visible = gm_pref_store_get_boolean(gm_store, SHOWDETAILS); show_notification = gm_pref_store_get_boolean(gm_store, SHOW_NOTIFICATION); show_status_icon = gm_pref_store_get_boolean(gm_store, SHOW_STATUS_ICON); showcontrols = gm_pref_store_get_boolean_with_default(gm_store, SHOW_CONTROLS, showcontrols); restore_controls = showcontrols; disable_deinterlace = gm_pref_store_get_boolean(gm_store, DISABLEDEINTERLACE); disable_framedrop = gm_pref_store_get_boolean(gm_store, DISABLEFRAMEDROP); disable_fullscreen = gm_pref_store_get_boolean(gm_store, DISABLEFULLSCREEN); disable_context_menu = gm_pref_store_get_boolean(gm_store, DISABLECONTEXTMENU); disable_ass = gm_pref_store_get_boolean(gm_store, DISABLEASS); disable_embeddedfonts = gm_pref_store_get_boolean(gm_store, DISABLEEMBEDDEDFONTS); disable_pause_on_click = gm_pref_store_get_boolean(gm_store, DISABLEPAUSEONCLICK); disable_animation = gm_pref_store_get_boolean(gm_store, DISABLEANIMATION); auto_hide_timeout = gm_pref_store_get_int_with_default(gm_store, AUTOHIDETIMEOUT, auto_hide_timeout); disable_cover_art_fetch = gm_pref_store_get_boolean(gm_store, DISABLE_COVER_ART_FETCH); use_mediakeys = gm_pref_store_get_boolean_with_default(gm_store, USE_MEDIAKEYS, use_mediakeys); use_defaultpl = gm_pref_store_get_boolean_with_default(gm_store, USE_DEFAULTPL, use_defaultpl); metadata_codepage = gm_pref_store_get_string(gm_store, METADATACODEPAGE); alang = gm_pref_store_get_string(gm_store, AUDIO_LANG); slang = gm_pref_store_get_string(gm_store, SUBTITLE_LANG); subtitlefont = gm_pref_store_get_string(gm_store, SUBTITLEFONT); subtitle_scale = gm_pref_store_get_float(gm_store, SUBTITLESCALE); if (subtitle_scale < 0.25) { subtitle_scale = 1.0; } subtitle_codepage = gm_pref_store_get_string(gm_store, SUBTITLECODEPAGE); subtitle_color = gm_pref_store_get_string(gm_store, SUBTITLECOLOR); subtitle_outline = gm_pref_store_get_boolean(gm_store, SUBTITLEOUTLINE); subtitle_shadow = gm_pref_store_get_boolean(gm_store, SUBTITLESHADOW); subtitle_margin = gm_pref_store_get_int(gm_store, SUBTITLE_MARGIN); subtitle_fuzziness = gm_pref_store_get_int(gm_store, SUBTITLE_FUZZINESS); showsubtitles = gm_pref_store_get_boolean_with_default(gm_store, SHOW_SUBTITLES, TRUE); qt_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_QT); real_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_REAL); wmp_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_WMP); dvx_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_DVX); midi_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_MIDI); embedding_disabled = gm_pref_store_get_boolean(gmp_store, DISABLE_EMBEDDING); disable_embedded_scaling = gm_pref_store_get_boolean(gmp_store, DISABLE_EMBEDDED_SCALING); if (embed_window == 0) { single_instance = gm_pref_store_get_boolean(gm_store, SINGLE_INSTANCE); if (single_instance) { replace_and_play = gm_pref_store_get_boolean(gm_store, REPLACE_AND_PLAY); bring_to_front = gm_pref_store_get_boolean(gm_store, BRING_TO_FRONT); } } enable_global_menu = gm_pref_store_get_boolean(gm_store, ENABLE_GLOBAL_MENU); if (!enable_global_menu) { enable_global_menu = (g_getenv("UBUNTU_MENUPROXY") == NULL ? FALSE : TRUE); } enable_nautilus_plugin = gm_pref_store_get_boolean_with_default(gm_store, ENABLE_NAUTILUS_PLUGIN, TRUE); mplayer_bin = gm_pref_store_get_string(gm_store, MPLAYER_BIN); if (mplayer_bin != NULL && !g_file_test(mplayer_bin, G_FILE_TEST_EXISTS)) { g_free(mplayer_bin); mplayer_bin = NULL; } mplayer_dvd_device = gm_pref_store_get_string(gm_store, MPLAYER_DVD_DEVICE); extraopts = gm_pref_store_get_string(gm_store, EXTRAOPTS); use_xscrnsaver = gm_pref_store_get_boolean_with_default(gm_store, USE_XSCRNSAVER, use_xscrnsaver); accelerator_keys = gm_pref_store_get_string(gm_store, ACCELERATOR_KEYS); accel_keys = g_strv_new(KEY_COUNT); accel_keys_description = g_strv_new(KEY_COUNT); if (accelerator_keys != NULL) { parse = g_strsplit(accelerator_keys, " ", KEY_COUNT); for (i = 0; i < g_strv_length(parse); i++) { accel_keys[i] = g_strdup(parse[i]); } g_free(accelerator_keys); g_strfreev(parse); } assign_default_keys(); accel_keys_description[FILE_OPEN_LOCATION] = g_strdup(_("Open Location")); accel_keys_description[EDIT_SCREENSHOT] = g_strdup(_("Take Screenshot")); accel_keys_description[EDIT_PREFERENCES] = g_strdup(_("Preferences")); accel_keys_description[VIEW_PLAYLIST] = g_strdup(_("Playlist")); accel_keys_description[VIEW_INFO] = g_strdup(_("Media Info")); accel_keys_description[VIEW_DETAILS] = g_strdup(_("Details")); accel_keys_description[VIEW_METER] = g_strdup(_("Audio Meter")); accel_keys_description[VIEW_FULLSCREEN] = g_strdup(_("Full Screen")); accel_keys_description[VIEW_ASPECT] = g_strdup(_("Aspect")); accel_keys_description[VIEW_SUBTITLES] = g_strdup(_("Subtitles")); accel_keys_description[VIEW_DECREASE_SIZE] = g_strdup(_("Decrease Subtitle Size")); accel_keys_description[VIEW_INCREASE_SIZE] = g_strdup(_("Increase Subtitle Size")); accel_keys_description[VIEW_ANGLE] = g_strdup(_("Switch Angle")); accel_keys_description[VIEW_CONTROLS] = g_strdup(_("Controls")); remember_loc = gm_pref_store_get_boolean(gm_store, REMEMBER_LOC); loc_window_x = gm_pref_store_get_int(gm_store, WINDOW_X); loc_window_y = gm_pref_store_get_int(gm_store, WINDOW_Y); loc_window_height = gm_pref_store_get_int(gm_store, WINDOW_HEIGHT); loc_window_width = gm_pref_store_get_int(gm_store, WINDOW_WIDTH); loc_panel_position = gm_pref_store_get_int(gm_store, PANEL_POSITION); keep_on_top = gm_pref_store_get_boolean(gm_store, KEEP_ON_TOP); resize_on_new_media = gm_pref_store_get_boolean(gm_store, RESIZE_ON_NEW_MEDIA); mouse_wheel_changes_volume = gm_pref_store_get_boolean_with_default(gm_store, MOUSE_WHEEL_CHANGES_VOLUME, FALSE); audio_device_name = gm_pref_store_get_string(gm_store, AUDIO_DEVICE_NAME); audio_device.description = g_strdup(audio_device_name); context = g_option_context_new(_("[FILES...] - GNOME Media player based on MPlayer")); #ifdef GTK2_12_ENABLED g_option_context_set_translation_domain(context, "UTF-8"); g_option_context_set_translate_func(context, (GTranslateFunc) gettext, NULL, NULL); #endif g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); g_option_context_parse(context, &argc, &argv, &error); g_option_context_free(context); if (new_instance) single_instance = FALSE; if (verbose == 0) verbose = gm_pref_store_get_int(gm_store, VERBOSE); if (reallyverbose) verbose = 2; if (verbose) { printf(_("GNOME MPlayer v%s\n"), VERSION); printf(_("gmtk v%s\n"), gmtk_version()); } if (cache_size == 0) cache_size = gm_pref_store_get_int(gm_store, CACHE_SIZE); if (cache_size == 0) cache_size = 2000; plugin_audio_cache_size = gm_pref_store_get_int(gm_store, PLUGIN_AUDIO_CACHE_SIZE); if (plugin_audio_cache_size == 0) plugin_audio_cache_size = 2000; plugin_video_cache_size = gm_pref_store_get_int(gm_store, PLUGIN_VIDEO_CACHE_SIZE); if (plugin_video_cache_size == 0) plugin_video_cache_size = 2000; if (control_id != 0) cache_size = plugin_video_cache_size; gm_pref_store_free(gm_store); gm_pref_store_free(gmp_store); if (verbose && embed_window) { printf("embedded in window id 0x%x\n", embed_window); } if (verbose && single_instance) { printf("Running in single instance mode\n"); } #ifdef GIO_ENABLED if (verbose) { printf("Running with GIO support\n"); } #endif #ifdef ENABLE_PANSCAN if (verbose) { printf("Running with panscan enabled (mplayer svn r29565 or higher required)\n"); } #endif if (verbose) { printf("Using audio device: %s\n", audio_device_name); } if (softvol) { if (verbose) printf("Using MPlayer Software Volume control\n"); if (remember_softvol && volume_softvol != -1) { if (verbose) printf("Using last volume of %f%%\n", volume_softvol * 100.0); volume = (gdouble) volume_softvol *100.0; } else { volume = 100.0; } } if (large_buttons) button_size = GTK_ICON_SIZE_DIALOG; if (playlist_visible && control_id != 0) playlist_visible = FALSE; if (error != NULL) { printf("%s\n", error->message); printf(_("Run 'gnome-mplayer --help' to see a full list of available command line options.\n")); return 1; } // if (verbose) // printf("Threading support enabled = %i\n",g_thread_supported()); if (rpconsole == NULL) rpconsole = g_strdup("NONE"); // setup playliststore playliststore = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_FLOAT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_FLOAT, G_TYPE_FLOAT, G_TYPE_BOOLEAN); // only use dark theme if not embedded, otherwise use the default theme #ifdef GTK3_ENABLED if (embed_window <= 0) { gtk_settings = gtk_settings_get_default(); g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL); } #endif create_window(embed_window); autopause = FALSE; #ifdef GIO_ENABLED idledata->caching = g_mutex_new(); idledata->caching_complete = g_cond_new(); #endif retrieve_metadata_pool = g_thread_pool_new(retrieve_metadata, NULL, 10, TRUE, NULL); if (argv[fileindex] != NULL) { #ifdef GIO_ENABLED file = g_file_new_for_commandline_arg(argv[fileindex]); stat_result = -1; if (file != NULL) { GError *error = NULL; GFileInfo *file_info = g_file_query_info(file, G_FILE_ATTRIBUTE_UNIX_MODE, 0, NULL, &error); if (file_info != NULL) { buf.st_mode = g_file_info_get_attribute_uint32(file_info, G_FILE_ATTRIBUTE_UNIX_MODE); stat_result = 0; g_object_unref(file_info); } if (error != NULL) { if (verbose) printf("failed to get mode: %s\n", error->message); g_error_free(error); } g_object_unref(file); } #else stat_result = g_stat(argv[fileindex], &buf); #endif if (verbose) { printf("opening %s\n", argv[fileindex]); printf("stat_result = %i\n", stat_result); printf("is block %i\n", S_ISBLK(buf.st_mode)); printf("is character %i\n", S_ISCHR(buf.st_mode)); printf("is reg %i\n", S_ISREG(buf.st_mode)); printf("is dir %i\n", S_ISDIR(buf.st_mode)); printf("playlist %i\n", playlist); printf("embedded in window id 0x%x\n", embed_window); } if (stat_result == 0 && S_ISBLK(buf.st_mode)) { // might have a block device, so could be a DVD #ifdef HAVE_SYS_MOUNT_H fp = setmntent("/etc/mtab", "r"); do { mnt = getmntent(fp); if (mnt) printf("%s is at %s\n", mnt->mnt_fsname, mnt->mnt_dir); if (argv[fileindex] != NULL && mnt && mnt->mnt_fsname != NULL) { if (strcmp(argv[fileindex], mnt->mnt_fsname) == 0) break; } } while (mnt); endmntent(fp); #endif if (mnt && mnt->mnt_dir) { printf("%s is mounted on %s\n", argv[fileindex], mnt->mnt_dir); uri = g_strdup_printf("%s/VIDEO_TS", mnt->mnt_dir); stat(uri, &buf); g_free(uri); if (S_ISDIR(buf.st_mode)) { add_item_to_playlist("dvdnav://", 0); gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD); //play_iter(&iter, 0); playiter = TRUE; } else { uri = g_strdup_printf("file://%s", mnt->mnt_dir); create_folder_progress_window(); add_folder_to_playlist_callback(uri, NULL); g_free(uri); destroy_folder_progress_window(); if (random_order) { gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); randomize_playlist(playliststore); } if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter)) { // play_iter(&iter, 0); playiter = TRUE; } } } else { parse_cdda("cdda://"); if (random_order) { gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); randomize_playlist(playliststore); } //play_file("cdda://", playlist); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter)) { // play_iter(&iter, 0); playiter = TRUE; } } } else if (stat_result == 0 && S_ISDIR(buf.st_mode)) { uri = g_strdup_printf("%s/VIDEO_TS", argv[fileindex]); stat_result = g_stat(uri, &buf); g_free(uri); if (stat_result == 0 && S_ISDIR(buf.st_mode)) { add_item_to_playlist("dvdnav://", 0); gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); gmtk_media_player_set_media_type(GMTK_MEDIA_PLAYER(media), TYPE_DVD); //play_iter(&iter, 0); playiter = TRUE; } else { create_folder_progress_window(); uri = NULL; #ifdef GIO_ENABLED file = g_file_new_for_commandline_arg(argv[fileindex]); if (file != NULL) { uri = g_file_get_uri(file); g_object_unref(file); } #else uri = g_filename_to_uri(argv[fileindex], NULL, NULL); #endif add_folder_to_playlist_callback(uri, NULL); g_free(uri); destroy_folder_progress_window(); if (random_order) { gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); randomize_playlist(playliststore); } if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter)) { //play_iter(&iter, 0); playiter = TRUE; } } } else { // local file // detect if playlist here, so even if not specified it can be picked up i = fileindex; while (argv[i] != NULL) { if (verbose > 1) printf("Argument %i is %s\n", i, argv[i]); #ifdef GIO_ENABLED if (!device_name(argv[i])) { file = g_file_new_for_commandline_arg(argv[i]); if (file != NULL) { uri = g_file_get_uri(file); g_object_unref(file); } else { uri = g_strdup(argv[i]); } } else { uri = g_strdup(argv[i]); } #else uri = g_filename_to_uri(argv[i], NULL, NULL); #endif if (uri != NULL) { if (playlist == 0) playlist = detect_playlist(uri); if (!playlist) { add_item_to_playlist(uri, playlist); } else { if (!parse_playlist(uri)) { add_item_to_playlist(uri, playlist); } } g_free(uri); } i++; } if (random_order) { gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter); randomize_playlist(playliststore); } if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(playliststore), &iter)) { // play_iter(&iter, 0); playiter = TRUE; } } } #ifdef HAVE_GPOD if (load_tracks_from_gpod) { gpod_mount_point = find_gpod_mount_point(); printf("mount point is %s\n", gpod_mount_point); if (gpod_mount_point != NULL) { gpod_load_tracks(gpod_mount_point); } else { printf("Unable to find gpod mount point\n"); } } #endif gm_audio_update_device(&audio_device); gm_audio_get_volume(&audio_device); gm_audio_set_server_volume_update_callback(&audio_device, set_volume); set_media_player_attributes(media); if (!softvol) { if (pref_volume != -1) { audio_device.volume = (gdouble) pref_volume / 100.0; } if (verbose) printf("The volume on '%s' is %f\n", audio_device.description, audio_device.volume); volume = audio_device.volume * 100; } else { audio_device.volume = volume / 100.0; } #ifdef GTK2_12_ENABLED gtk_scale_button_set_value(GTK_SCALE_BUTTON(vol_slider), audio_device.volume); #else gtk_range_set_value(GTK_RANGE(vol_slider), audio_device.volume); #endif use_volume_option = detect_volume_option(); dbus_hookup(embed_window, control_id); show_window(embed_window); if (playiter) play_iter(&iter, 0); if (argv[fileindex] == NULL && embed_window == 0) { // When running as apple.com external player, don't load the default playlist if (control_id == 0) { use_remember_loc = remember_loc; gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem_view_playlist), playlist_visible); } else { remember_loc = FALSE; use_remember_loc = FALSE; // prevents saving of a playlist with one item on it use_defaultpl = FALSE; // don't save the loc when launched with a single file save_loc = FALSE; } } else { // prevents saving of a playlist with one item on it use_defaultpl = FALSE; // don't save the loc when launched with a single file save_loc = FALSE; } if (single_instance && embed_window == 0) { if (control_id == 0) { use_remember_loc = remember_loc; gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem_view_playlist), playlist_visible); } } if (embed_window == 0) { if (remember_loc) { gtk_window_move(GTK_WINDOW(window), loc_window_x, loc_window_y); g_idle_add(set_pane_position, NULL); } } safe_to_save_default_playlist = FALSE; if (use_defaultpl) { create_folder_progress_window(); parse_playlist(default_playlist); destroy_folder_progress_window(); } safe_to_save_default_playlist = TRUE; gtk_main(); return 0; }
int main (int argc, char *argv[]) { GOptionContext *context; GError *error = NULL; #ifdef G_OS_WIN32 if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) { /* stdout is fine, presumably redirected to a file or pipe */ } else { typedef BOOL (* WINAPI AttachConsole_t) (DWORD); AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole"); if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) { freopen ("CONOUT$", "w", stdout); dup2 (fileno (stdout), 1); freopen ("CONOUT$", "w", stderr); dup2 (fileno (stderr), 2); } } #endif #if (!GLIB_CHECK_VERSION(2,31,0)) /* Remove this once we bump dependencies to glib >= 2.31.0 */ /* Init glib threads asap */ if (!g_thread_supported ()) g_thread_init (NULL); #endif #ifdef ENABLE_NLS /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (N_("GNOME Document Viewer")); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); #ifdef WITH_SMCLIENT g_option_context_add_group (context, egg_sm_client_get_option_group ()); #endif g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Cannot parse arguments: %s\n", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (preview_mode) { gboolean retval; retval = launch_previewer (); return retval ? 0 : 1; } if (!ev_init ()) return 1; ev_stock_icons_init (); #if defined(WITH_SMCLIENT) && defined(GDK_WINDOWING_X11) egg_set_desktop_file (GNOMEDATADIR "/applications/evince.desktop"); #else /* Manually set name and icon */ g_set_application_name (_("Document Viewer")); gtk_window_set_default_icon_name ("evince"); #endif /* WITH_SMCLIENT && GDK_WINDOWING_X11 */ ev_application_load_session (EV_APP); load_files (file_arguments); /* Change directory so we don't prevent unmounting in case the initial cwd * is on an external device (see bug #575436) */ g_chdir (g_get_home_dir ()); gtk_main (); ev_shutdown (); ev_stock_icons_shutdown (); return 0; }
static int cc_application_command_line (GApplication *application, GApplicationCommandLine *command_line) { CcApplication *self = CC_APPLICATION (application); int argc; char **argv; int retval = 0; GOptionContext *context; GError *error = NULL; GVariantBuilder *flags_builder; verbose = FALSE; show_overview = FALSE; show_help = FALSE; start_panels = NULL; flags_builder = g_variant_builder_new (G_VARIANT_TYPE_VARDICT); argv = g_application_command_line_get_arguments (command_line, &argc); context = g_option_context_new (N_("- Settings")); g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); cc_panel_loader_add_option_groups (context, flags_builder); g_option_context_set_help_enabled (context, FALSE); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); g_option_context_free (context); return 1; } if (show_help || show_help_all || show_help_gtk) { gchar *help; GOptionGroup *group; if (show_help || show_help_all) group = NULL; else group = gtk_get_option_group (FALSE); help = g_option_context_get_help (context, FALSE, group); g_print ("%s", help); g_free (help); g_option_context_free (context); return 0; } if (list_panels) { GList *panels, *l; panels = cc_panel_loader_get_panels (); g_print ("%s\n", _("Available panels:")); for (l = panels; l != NULL; l = l->next) g_print ("\t%s\n", (char *) l->data); g_list_free (panels); return 0; } #ifdef HAVE_CHEESE cheese_gtk_init (&argc, &argv); #endif /* HAVE_CHEESE */ cc_shell_log_set_debug (verbose); cc_window_show (self->priv->window); if (search_str) { cc_window_set_search_item (self->priv->window, search_str); } else if (show_overview) { cc_window_set_overview_page (self->priv->window); } else if (start_panels != NULL && start_panels[0] != NULL) { const char *start_id; GError *err = NULL; GVariant *parameters; GVariantBuilder *builder; int i; start_id = start_panels[0]; if (start_panels[1]) g_debug ("Extra argument: %s", start_panels[1]); else g_debug ("No extra argument"); builder = g_variant_builder_new (G_VARIANT_TYPE ("av")); g_variant_builder_add (builder, "v", g_variant_builder_end (flags_builder)); for (i = 1; start_panels[i] != NULL; i++) g_variant_builder_add (builder, "v", g_variant_new_string (start_panels[i])); parameters = g_variant_builder_end (builder); if (!cc_shell_set_active_panel_from_id (CC_SHELL (self->priv->window), start_id, parameters, &err)) { g_warning ("Could not load setting panel \"%s\": %s", start_id, (err) ? err->message : "Unknown error"); retval = 1; if (err) { g_error_free (err); err = NULL; } } } if (start_panels != NULL) { g_strfreev (start_panels); start_panels = NULL; } show_overview = FALSE; g_option_context_free (context); g_strfreev (argv); return retval; }
/** * main * @argc: number of arguments * @argv: arguments * * Description: * main * * Returns: * exit code **/ int main (int argc, char *argv[]) { GtkWidget *errordialog; GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe; GtkUIManager *ui_manager; GOptionContext *context; struct timeval tv; gint i; gchar *config; gboolean retval; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); games_scores_startup (); gettimeofday (&tv, NULL); srand (tv.tv_usec); context = g_option_context_new (NULL); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); retval = g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (!retval) { g_print ("%s", error->message); g_error_free (error); exit (1); } g_set_application_name (_("Robots")); highscores = games_scores_new ("gnobots2", scorecats, G_N_ELEMENTS (scorecats), NULL, NULL, 0 /* default category */, GAMES_SCORES_STYLE_PLAIN_DESCENDING); settings = g_settings_new ("org.gnome.gnobots2"); gtk_window_set_default_icon_name ("gnobots2"); app = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (app), _("Robots")); g_signal_connect (GTK_WINDOW (app), "configure-event", G_CALLBACK (window_configure_event_cb), NULL); g_signal_connect (GTK_WINDOW (app), "window-state-event", G_CALLBACK (window_state_event_cb), NULL); gtk_window_set_default_size (GTK_WINDOW (app), g_settings_get_int (settings, "window-width"), g_settings_get_int (settings, "window-height")); if (g_settings_get_boolean (settings, "window-is-fullscreen")) gtk_window_fullscreen (GTK_WINDOW (app)); if (g_settings_get_boolean (settings, "window-is-maximized")) gtk_window_maximize (GTK_WINDOW (app)); g_signal_connect (G_OBJECT (app), "delete_event", G_CALLBACK (quit_game), NULL); statusbar = gnobots_statusbar_new (); ui_manager = gtk_ui_manager_new (); games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar); create_game_menus (ui_manager); gtk_window_add_accel_group (GTK_WINDOW (app), gtk_ui_manager_get_accel_group (ui_manager)); menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar"); gtk_style_context_add_class (gtk_widget_get_style_context (toolbar), GTK_STYLE_CLASS_PRIMARY_TOOLBAR); make_cursors (); game_area = gtk_drawing_area_new (); gtk_widget_add_events (game_area, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); g_signal_connect (G_OBJECT (game_area), "button-press-event", G_CALLBACK (mouse_cb), NULL); g_signal_connect (G_OBJECT (game_area), "motion-notify-event", G_CALLBACK (move_cb), NULL); g_signal_connect (G_OBJECT (game_area), "configure-event", G_CALLBACK (resize_cb), NULL); g_signal_connect (G_OBJECT (game_area), "draw", G_CALLBACK (draw_cb), NULL); gridframe = games_grid_frame_new (GAME_WIDTH, GAME_HEIGHT); gtk_container_add (GTK_CONTAINER (gridframe), game_area); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (app), vbox); gtk_widget_set_size_request (GTK_WIDGET (game_area), MINIMUM_TILE_WIDTH * GAME_WIDTH, MINIMUM_TILE_HEIGHT * GAME_HEIGHT); /* Set the window position if it was set by the session manager */ if (session_xpos >= 0 && session_ypos >= 0) { gtk_window_move (GTK_WINDOW (app), session_xpos, session_ypos); } gtk_widget_show_all (app); if (!load_game_configs ()) { /* Oops, no configs, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _("No game data could be found."), _ ("The program Robots was unable to find any valid game configuration files. Please check that the program is installed correctly.")); gtk_window_set_resizable (GTK_WINDOW (errordialog), FALSE); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } load_properties (); if (!load_game_graphics ()) { /* Oops, no graphics, we probably haven't been installed properly. */ errordialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "<b>%s</b>\n\n%s", _ ("Some graphics files are missing or corrupt."), _ ("The program Robots was unable to load all the necessary graphics files. Please check that the program is installed correctly.")); gtk_dialog_run (GTK_DIALOG (errordialog)); exit (1); } connect_toolbar_toggle (toolbar); init_sound (); init_game (); if (cmdline_scenario) { set_game_graphics (cmdline_scenario); } if (cmdline_config) { for (i = 0; i < num_game_configs (); ++i) { config = game_config_name (i); if (!strcmp (cmdline_config, config)) { properties_set_config (i); g_free (config); break; } g_free (config); } } gtk_main (); g_settings_sync(); return 0; }
gboolean flatpak_builtin_build (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(FlatpakDeploy) runtime_deploy = NULL; g_autoptr(GVariant) runtime_deploy_data = NULL; g_autoptr(FlatpakDeploy) extensionof_deploy = NULL; g_autoptr(GFile) var = NULL; g_autoptr(GFile) var_tmp = NULL; g_autoptr(GFile) var_lib = NULL; g_autoptr(GFile) usr = NULL; g_autoptr(GFile) res_deploy = NULL; g_autoptr(GFile) res_files = NULL; g_autoptr(GFile) app_files = NULL; gboolean app_files_ro = FALSE; g_autoptr(GFile) runtime_files = NULL; g_autoptr(GFile) metadata = NULL; g_autofree char *metadata_contents = NULL; g_autofree char *runtime = NULL; g_autofree char *runtime_ref = NULL; g_autofree char *extensionof_ref = NULL; g_autofree char *extensionof_tag = NULL; g_autofree char *extension_point = NULL; g_autofree char *extension_tmpfs_point = NULL; g_autoptr(GKeyFile) metakey = NULL; g_autoptr(GKeyFile) runtime_metakey = NULL; g_autoptr(FlatpakBwrap) bwrap = NULL; g_auto(GStrv) minimal_envp = NULL; gsize metadata_size; const char *directory = NULL; const char *command = "/bin/sh"; g_autofree char *id = NULL; int i; int rest_argv_start, rest_argc; g_autoptr(FlatpakContext) arg_context = NULL; g_autoptr(FlatpakContext) app_context = NULL; gboolean custom_usr; g_auto(GStrv) runtime_ref_parts = NULL; FlatpakRunFlags run_flags; const char *group = NULL; const char *runtime_key = NULL; const char *dest = NULL; gboolean is_app = FALSE; gboolean is_extension = FALSE; gboolean is_app_extension = FALSE; g_autofree char *app_info_path = NULL; g_autofree char *app_extensions = NULL; g_autofree char *runtime_extensions = NULL; g_autofree char *instance_id_host_dir = NULL; char pid_str[64]; g_autofree char *pid_path = NULL; g_autoptr(GFile) app_id_dir = NULL; context = g_option_context_new (_("DIRECTORY [COMMAND [ARGUMENT…]] - Build in directory")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); rest_argc = 0; for (i = 1; i < argc; i++) { /* The non-option is the directory, take it out of the arguments */ if (argv[i][0] != '-') { rest_argv_start = i; rest_argc = argc - i; argc = i; break; } } arg_context = flatpak_context_new (); g_option_context_add_group (context, flatpak_context_get_options (arg_context)); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (rest_argc == 0) return usage_error (context, _("DIRECTORY must be specified"), error); directory = argv[rest_argv_start]; if (rest_argc >= 2) command = argv[rest_argv_start + 1]; res_deploy = g_file_new_for_commandline_arg (directory); metadata = g_file_get_child (res_deploy, opt_metadata ? opt_metadata : "metadata"); if (!g_file_query_exists (res_deploy, NULL) || !g_file_query_exists (metadata, NULL)) return flatpak_fail (error, _("Build directory %s not initialized, use flatpak build-init"), directory); if (!g_file_load_contents (metadata, cancellable, &metadata_contents, &metadata_size, NULL, error)) return FALSE; metakey = g_key_file_new (); if (!g_key_file_load_from_data (metakey, metadata_contents, metadata_size, 0, error)) return FALSE; if (g_key_file_has_group (metakey, FLATPAK_METADATA_GROUP_APPLICATION)) { group = FLATPAK_METADATA_GROUP_APPLICATION; is_app = TRUE; } else if (g_key_file_has_group (metakey, FLATPAK_METADATA_GROUP_RUNTIME)) { group = FLATPAK_METADATA_GROUP_RUNTIME; } else return flatpak_fail (error, _("metadata invalid, not application or runtime")); extensionof_ref = g_key_file_get_string (metakey, FLATPAK_METADATA_GROUP_EXTENSION_OF, FLATPAK_METADATA_KEY_REF, NULL); if (extensionof_ref != NULL) { is_extension = TRUE; if (g_str_has_prefix (extensionof_ref, "app/")) is_app_extension = TRUE; } extensionof_tag = g_key_file_get_string (metakey, FLATPAK_METADATA_GROUP_EXTENSION_OF, FLATPAK_METADATA_KEY_TAG, NULL); id = g_key_file_get_string (metakey, group, FLATPAK_METADATA_KEY_NAME, error); if (id == NULL) return FALSE; if (opt_runtime) runtime_key = FLATPAK_METADATA_KEY_RUNTIME; else runtime_key = FLATPAK_METADATA_KEY_SDK; runtime = g_key_file_get_string (metakey, group, runtime_key, error); if (runtime == NULL) return FALSE; runtime_ref = g_build_filename ("runtime", runtime, NULL); runtime_ref_parts = flatpak_decompose_ref (runtime_ref, error); if (runtime_ref_parts == NULL) return FALSE; custom_usr = FALSE; usr = g_file_get_child (res_deploy, opt_sdk_dir ? opt_sdk_dir : "usr"); if (g_file_query_exists (usr, cancellable)) { custom_usr = TRUE; runtime_files = g_object_ref (usr); } else { runtime_deploy = flatpak_find_deploy_for_ref (runtime_ref, NULL, cancellable, error); if (runtime_deploy == NULL) return FALSE; runtime_deploy_data = flatpak_deploy_get_deploy_data (runtime_deploy, FLATPAK_DEPLOY_VERSION_ANY, cancellable, error); if (runtime_deploy_data == NULL) return FALSE; runtime_metakey = flatpak_deploy_get_metadata (runtime_deploy); runtime_files = flatpak_deploy_get_files (runtime_deploy); } var = g_file_get_child (res_deploy, "var"); var_tmp = g_file_get_child (var, "tmp"); if (!flatpak_mkdir_p (var_tmp, cancellable, error)) return FALSE; var_lib = g_file_get_child (var, "lib"); if (!flatpak_mkdir_p (var_lib, cancellable, error)) return FALSE; res_files = g_file_get_child (res_deploy, "files"); if (is_app) { app_files = g_object_ref (res_files); if (opt_with_appdir) app_id_dir = flatpak_ensure_data_dir (id, cancellable, NULL); } else if (is_extension) { g_autoptr(GKeyFile) x_metakey = NULL; g_autofree char *x_group = NULL; g_autofree char *x_dir = NULL; g_autofree char *x_subdir_suffix = NULL; char *x_subdir = NULL; g_autofree char *bare_extension_point = NULL; extensionof_deploy = flatpak_find_deploy_for_ref (extensionof_ref, NULL, cancellable, error); if (extensionof_deploy == NULL) return FALSE; x_metakey = flatpak_deploy_get_metadata (extensionof_deploy); /* Since we have tagged extensions, it is possible that an extension could * be listed more than once in the "parent" flatpak. In that case, we should * try and disambiguate using the following rules: * * 1. Use the 'tag=' key in the ExtensionOfSection and if not found: * 2. Use the only extension point available if there is only one. * 3. If there are no matching groups, return NULL. * 4. In all other cases, error out. */ if (!find_matching_extension_group_in_metakey (x_metakey, id, extensionof_tag, &x_group, error)) return FALSE; if (x_group == NULL) { /* Failed, look for subdirectories=true parent */ char *last_dot = strrchr (id, '.'); if (last_dot != NULL) { char *parent_id = g_strndup (id, last_dot - id); if (!find_matching_extension_group_in_metakey (x_metakey, parent_id, extensionof_tag, &x_group, error)) return FALSE; if (x_group != NULL && g_key_file_get_boolean (x_metakey, x_group, FLATPAK_METADATA_KEY_SUBDIRECTORIES, NULL)) x_subdir = last_dot + 1; } if (x_subdir == NULL) return flatpak_fail (error, _("No extension point matching %s in %s"), id, extensionof_ref); } x_dir = g_key_file_get_string (x_metakey, x_group, FLATPAK_METADATA_KEY_DIRECTORY, error); if (x_dir == NULL) return FALSE; x_subdir_suffix = g_key_file_get_string (x_metakey, x_group, FLATPAK_METADATA_KEY_SUBDIRECTORY_SUFFIX, NULL); if (is_app_extension) { app_files = flatpak_deploy_get_files (extensionof_deploy); app_files_ro = TRUE; if (x_subdir != NULL) extension_tmpfs_point = g_build_filename ("/app", x_dir, NULL); bare_extension_point = g_build_filename ("/app", x_dir, x_subdir, NULL); } else { if (x_subdir != NULL) extension_tmpfs_point = g_build_filename ("/usr", x_dir, NULL); bare_extension_point = g_build_filename ("/usr", x_dir, x_subdir, NULL); } extension_point = g_build_filename (bare_extension_point, x_subdir_suffix, NULL); } app_context = flatpak_app_compute_permissions (metakey, runtime_metakey, error); if (app_context == NULL) return FALSE; flatpak_context_allow_host_fs (app_context); flatpak_context_merge (app_context, arg_context); minimal_envp = flatpak_run_get_minimal_env (TRUE, FALSE); bwrap = flatpak_bwrap_new (minimal_envp); flatpak_bwrap_add_args (bwrap, flatpak_get_bwrap (), NULL); run_flags = FLATPAK_RUN_FLAG_DEVEL | FLATPAK_RUN_FLAG_MULTIARCH | FLATPAK_RUN_FLAG_NO_SESSION_HELPER | FLATPAK_RUN_FLAG_SET_PERSONALITY | FLATPAK_RUN_FLAG_NO_A11Y_BUS_PROXY; if (opt_die_with_parent) run_flags |= FLATPAK_RUN_FLAG_DIE_WITH_PARENT; if (custom_usr) run_flags |= FLATPAK_RUN_FLAG_WRITABLE_ETC; run_flags |= flatpak_context_get_run_flags (app_context); /* Unless manually specified, we disable dbus proxy */ if (!flatpak_context_get_needs_session_bus_proxy (arg_context)) run_flags |= FLATPAK_RUN_FLAG_NO_SESSION_BUS_PROXY; if (!flatpak_context_get_needs_system_bus_proxy (arg_context)) run_flags |= FLATPAK_RUN_FLAG_NO_SYSTEM_BUS_PROXY; if (opt_log_session_bus) run_flags |= FLATPAK_RUN_FLAG_LOG_SESSION_BUS; if (opt_log_system_bus) run_flags |= FLATPAK_RUN_FLAG_LOG_SYSTEM_BUS; /* Never set up an a11y bus for builds */ run_flags |= FLATPAK_RUN_FLAG_NO_A11Y_BUS_PROXY; if (!flatpak_run_setup_base_argv (bwrap, runtime_files, app_id_dir, runtime_ref_parts[2], run_flags, error)) return FALSE; flatpak_bwrap_add_args (bwrap, (custom_usr && !opt_readonly) ? "--bind" : "--ro-bind", flatpak_file_get_path_cached (runtime_files), "/usr", NULL); if (!custom_usr) flatpak_bwrap_add_args (bwrap, "--lock-file", "/usr/.ref", NULL); if (app_files) flatpak_bwrap_add_args (bwrap, (app_files_ro || opt_readonly) ? "--ro-bind" : "--bind", flatpak_file_get_path_cached (app_files), "/app", NULL); else flatpak_bwrap_add_args (bwrap, "--dir", "/app", NULL); if (extension_tmpfs_point) flatpak_bwrap_add_args (bwrap, "--tmpfs", extension_tmpfs_point, NULL); /* We add the actual bind below so that we're not shadowed by other extensions or their tmpfs */ if (extension_point) dest = extension_point; else if (is_app) dest = g_strdup ("/app"); else dest = g_strdup ("/usr"); flatpak_bwrap_add_args (bwrap, "--setenv", "FLATPAK_DEST", dest, "--setenv", "FLATPAK_ID", id, "--setenv", "FLATPAK_ARCH", runtime_ref_parts[2], NULL); /* Persist some stuff in /var. We can't persist everything because that breaks /var things * from the host to work. For example the /home -> /var/home on atomic. * The interesting things to contain during the build is /var/tmp (for tempfiles shared during builds) * and things like /var/lib/rpm, if the installation uses packages. */ flatpak_bwrap_add_args (bwrap, "--bind", flatpak_file_get_path_cached (var_lib), "/var/lib", NULL); flatpak_bwrap_add_args (bwrap, "--bind", flatpak_file_get_path_cached (var_tmp), "/var/tmp", NULL); flatpak_run_apply_env_vars (bwrap, app_context); if (is_app) { /* We don't actually know the final branchname yet, so use "nobranch" as fallback to avoid unexpected matches. This means any extension point used at build time must have explicit versions to work. */ g_autofree char *fake_ref = g_strdup_printf ("app/%s/%s/nobranch", id, runtime_ref_parts[2]); if (!flatpak_run_add_extension_args (bwrap, metakey, fake_ref, FALSE, &app_extensions, cancellable, error)) return FALSE; } if (!custom_usr && !flatpak_run_add_extension_args (bwrap, runtime_metakey, runtime_ref, FALSE, &runtime_extensions, cancellable, error)) return FALSE; /* Mount this after the above extensions so we always win */ if (extension_point) flatpak_bwrap_add_args (bwrap, "--bind", flatpak_file_get_path_cached (res_files), extension_point, NULL); if (!flatpak_run_add_app_info_args (bwrap, app_files, NULL, app_extensions, runtime_files, runtime_deploy_data, runtime_extensions, id, NULL, runtime_ref, app_id_dir, app_context, NULL, FALSE, TRUE, TRUE, &app_info_path, &instance_id_host_dir, error)) return FALSE; if (!flatpak_run_add_environment_args (bwrap, app_info_path, run_flags, id, app_context, app_id_dir, NULL, cancellable, error)) return FALSE; for (i = 0; opt_bind_mounts != NULL && opt_bind_mounts[i] != NULL; i++) { char *split = strchr (opt_bind_mounts[i], '='); if (split == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Missing '=' in bind mount option '%s'"), opt_bind_mounts[i]); return FALSE; } *split++ = 0; flatpak_bwrap_add_args (bwrap, "--bind", split, opt_bind_mounts[i], NULL); } if (opt_build_dir != NULL) { flatpak_bwrap_add_args (bwrap, "--chdir", opt_build_dir, NULL); } if (!flatpak_bwrap_bundle_args (bwrap, 1, -1, FALSE, error)) return FALSE; flatpak_bwrap_add_args (bwrap, command, NULL); flatpak_bwrap_append_argsv (bwrap, &argv[rest_argv_start + 2], rest_argc - 2); g_ptr_array_add (bwrap->argv, NULL); g_snprintf (pid_str, sizeof (pid_str), "%d", getpid ()); pid_path = g_build_filename (instance_id_host_dir, "pid", NULL); g_file_set_contents (pid_path, pid_str, -1, NULL); /* Ensure we unset O_CLOEXEC */ child_setup (bwrap->fds); if (execvpe (flatpak_get_bwrap (), (char **) bwrap->argv->pdata, bwrap->envp) == -1) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), _("Unable to start app")); return FALSE; } /* Not actually reached... */ return TRUE; }
int main (int argc, char **argv) { GOptionContext* context; GError *error = NULL; GFile *infile; GFile *outfile; GInputStream *instream; GOutputStream *outstream; GMainLoop *loop; ByzanzEncoder *encoder; g_set_prgname (argv[0]); #ifdef GETTEXT_PACKAGE bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("process a Byzanz debug recording")); #ifdef GETTEXT_PACKAGE g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); #endif g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print (_("Wrong option: %s\n"), error->message); usage (); g_error_free (error); return 1; } if (argc != 3) { usage (); return 0; } infile = g_file_new_for_commandline_arg (argv[1]); outfile = g_file_new_for_commandline_arg (argv[2]); loop = g_main_loop_new (NULL, FALSE); instream = G_INPUT_STREAM (g_file_read (infile, NULL, &error)); if (instream == NULL) { g_print ("%s\n", error->message); g_error_free (error); return 1; } outstream = G_OUTPUT_STREAM (g_file_replace (outfile, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error)); if (outstream == NULL) { g_print ("%s\n", error->message); g_error_free (error); return 1; } encoder = byzanz_encoder_new (byzanz_encoder_get_type_from_file (outfile), instream, outstream, FALSE, NULL); g_signal_connect (encoder, "notify", G_CALLBACK (encoder_notify), loop); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (encoder); g_object_unref (instream); g_object_unref (outstream); g_object_unref (infile); g_object_unref (outfile); return 0; }
int main (int argc, char *argv[]) { DrWright *drwright; DrwSelection *selection; gboolean no_check = FALSE; const GOptionEntry options[] = { { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, { "no-check", 'n', 0, G_OPTION_ARG_NONE, &no_check, N_("Don't check whether the notification area exists"), NULL }, { NULL } }; GOptionContext *option_context; GError *error = NULL; gboolean retval; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); option_context = g_option_context_new (NULL); #if GLIB_CHECK_VERSION (2, 12, 0) g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE); #endif g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE); g_option_context_add_group (option_context, gtk_get_option_group (TRUE)); retval = g_option_context_parse (option_context, &argc, &argv, &error); g_option_context_free (option_context); if (!retval) { g_print ("%s\n", error->message); g_error_free (error); exit (1); } g_set_application_name (_("Typing Monitor")); gtk_window_set_default_icon_name ("typing-monitor"); selection = drw_selection_start (); if (!drw_selection_is_master (selection)) { g_message ("The typing monitor is already running, exiting."); return 0; } if (!no_check && !have_tray ()) { GtkWidget *dialog; dialog = gtk_message_dialog_new ( NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, _("The typing monitor uses the notification area to display " "information. You don't seem to have a notification area " "on your panel. You can add it by right-clicking on your " "panel and choosing 'Add to panel', selecting 'Notification " "area' and clicking 'Add'.")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } drwright = drwright_new (); gtk_main (); return 0; }
gboolean flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(FlatpakDir) dir = NULL; g_autoptr(GHashTable) refs = NULL; GHashTableIter iter; gpointer key; gpointer value; g_autoptr(GHashTable) names = NULL; guint n_keys; g_autofree const char **keys = NULL; int i; const char *repository; const char **arches = flatpak_get_arches (); const char *opt_arches[] = {NULL, NULL}; context = g_option_context_new (_(" REMOTE - Show available runtimes and applications")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error)) return FALSE; if (!opt_app && !opt_runtime) opt_app = opt_runtime = TRUE; if (argc < 2) return usage_error (context, _("REMOTE must be specified"), error); if (argc > 2) return usage_error (context, _("Too many arguments"), error); repository = argv[1]; if (!flatpak_dir_list_remote_refs (dir, repository, &refs, cancellable, error)) return FALSE; names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (opt_arch != NULL) { if (strcmp (opt_arch, "*") == 0) arches = NULL; else { opt_arches[0] = opt_arch; arches = opt_arches; } } g_hash_table_iter_init (&iter, refs); while (g_hash_table_iter_next (&iter, &key, &value)) { const char *ref = key; const char *checksum = value; const char *name = NULL; g_auto(GStrv) parts = NULL; parts = flatpak_decompose_ref (ref, NULL); if (parts == NULL) { g_debug ("Invalid remote ref %s\n", ref); continue; } if (opt_only_updates) { g_autofree char *deployed = NULL; deployed = flatpak_dir_read_active (dir, ref, cancellable); if (deployed == NULL) continue; if (g_strcmp0 (deployed, checksum) == 0) continue; } if (arches != NULL && !g_strv_contains (arches, parts[2])) continue; if (strcmp (parts[0], "runtime") == 0 && !opt_runtime) continue; if (strcmp (parts[0], "app") == 0 && !opt_app) continue; if (!opt_show_details) name = parts[1]; else name = ref; if (g_hash_table_lookup (names, name) == NULL) g_hash_table_insert (names, g_strdup (name), g_strdup (checksum)); } keys = (const char **) g_hash_table_get_keys_as_array (names, &n_keys); g_qsort_with_data (keys, n_keys, sizeof (char *), (GCompareDataFunc) flatpak_strcmp0_ptr, NULL); FlatpakTablePrinter *printer = flatpak_table_printer_new (); for (i = 0; i < n_keys; i++) { flatpak_table_printer_add_column (printer, keys[i]); if (opt_show_details) { g_autofree char *value = NULL; value = g_strdup ((char *) g_hash_table_lookup (names, keys[i])); value[MIN (strlen (value), 12)] = 0; flatpak_table_printer_add_column (printer, value); } flatpak_table_printer_finish_row (printer); } flatpak_table_printer_print (printer); flatpak_table_printer_free (printer); return TRUE; }
gboolean flatpak_builtin_remote_add (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GPtrArray) dirs = NULL; FlatpakDir *dir; g_autoptr(GFile) file = NULL; g_auto(GStrv) remotes = NULL; g_autofree char *remote_url = NULL; const char *remote_name; const char *location = NULL; g_autoptr(GKeyFile) config = NULL; g_autoptr(GBytes) gpg_data = NULL; gboolean changed = FALSE; g_autoptr(GError) local_error = NULL; gboolean is_oci; context = g_option_context_new (_("NAME LOCATION - Add a remote repository")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, common_options, NULL); if (!flatpak_option_context_parse (context, add_options, &argc, &argv, FLATPAK_BUILTIN_FLAG_ONE_DIR | FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO, &dirs, cancellable, error)) return FALSE; dir = g_ptr_array_index (dirs, 0); if (argc < 2) return usage_error (context, _("NAME must be specified"), error); if (argc < 3) return usage_error (context, _("LOCATION must be specified"), error); if (argc > 3) return usage_error (context, _("Too many arguments"), error); if (opt_collection_id != NULL && !ostree_validate_collection_id (opt_collection_id, &local_error)) return flatpak_fail (error, _("‘%s’ is not a valid collection ID: %s"), opt_collection_id, local_error->message); if (opt_collection_id != NULL && (opt_no_gpg_verify || opt_gpg_import == NULL || opt_gpg_import[0] == NULL)) return flatpak_fail (error, _("GPG verification is required if collections are enabled")); remote_name = argv[1]; location = argv[2]; remotes = flatpak_dir_list_remotes (dir, cancellable, error); if (remotes == NULL) return FALSE; if (g_strv_contains ((const char **) remotes, remote_name)) { if (opt_if_not_exists) return TRUE; /* Do nothing */ return flatpak_fail (error, _("Remote %s already exists"), remote_name); } if (opt_from || flatpak_file_arg_has_suffix (location, ".flatpakrepo")) { load_options (location, &gpg_data); if (opt_url == NULL) return flatpak_fail (error, _("No url specified in flatpakrepo file")); } else { file = g_file_new_for_commandline_arg (location); if (g_file_is_native (file)) remote_url = g_file_get_uri (file); else remote_url = g_strdup (location); opt_url = remote_url; } /* Default to gpg verify, except for OCI registries */ is_oci = opt_url && g_str_has_prefix (opt_url, "oci+"); if (!opt_no_gpg_verify && !is_oci) opt_do_gpg_verify = TRUE; config = get_config_from_opts (dir, remote_name, &changed); if (opt_gpg_import != NULL) { gpg_data = flatpak_load_gpg_keys (opt_gpg_import, cancellable, error); if (gpg_data == NULL) return FALSE; } if (!flatpak_dir_modify_remote (dir, remote_name, config, gpg_data, cancellable, error)) return FALSE; /* Reload previously changed configuration */ if (!flatpak_dir_recreate_repo (dir, cancellable, error)) return FALSE; /* We can't retrieve the extra metadata until the remote has been added locally, since ostree_repo_remote_fetch_summary() works with the repository's name, not its URL. Don't propagate IO failed errors here because we might just be offline - the remote should already be usable. */ if (!flatpak_dir_update_remote_configuration (dir, remote_name, cancellable, &local_error)) { if (local_error->domain == G_RESOLVER_ERROR || g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_FAILED)) { g_printerr (_("Warning: Could not update extra metadata for '%s': %s\n"), remote_name, local_error->message); } else { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } } return TRUE; }
int main (int argc, char *argv[]) { int t_secs = 30; gboolean exit_no_nm = FALSE; gboolean wait_startup = FALSE; Timeout timeout; GOptionContext *opt_ctx = NULL; gboolean success; NMClient *client; NMState state = NM_STATE_UNKNOWN; GMainLoop *loop; gint64 remaining_ms; GError *error = NULL; GOptionEntry options[] = { {"timeout", 't', 0, G_OPTION_ARG_INT, &t_secs, N_("Time to wait for a connection, in seconds (without the option, default value is 30)"), "<timeout>"}, {"exit", 'x', 0, G_OPTION_ARG_NONE, &exit_no_nm, N_("Exit immediately if NetworkManager is not running or connecting"), NULL}, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &timeout.quiet, N_("Don't print anything"), NULL}, {"wait-for-startup", 's', 0, G_OPTION_ARG_NONE, &wait_startup, N_("Wait for NetworkManager startup instead of a connection"), NULL}, {NULL} }; timeout.start_timestamp_ms = g_get_monotonic_time () / (G_USEC_PER_SEC / 1000); timeout.quiet = FALSE; /* Set locale to be able to use environment variables */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); opt_ctx = g_option_context_new (NULL); g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE); g_option_context_set_ignore_unknown_options (opt_ctx, FALSE); g_option_context_set_help_enabled (opt_ctx, TRUE); g_option_context_add_main_entries (opt_ctx, options, NULL); g_option_context_set_summary (opt_ctx, _("Waits for NetworkManager to finish activating startup network connections.")); success = g_option_context_parse (opt_ctx, &argc, &argv, NULL); g_option_context_free (opt_ctx); if (!success) { g_printerr ("%s: %s\n", argv[0], _("Invalid option. Please use --help to see a list of valid options.")); return 2; } if (t_secs < 0 || t_secs > 3600) { g_printerr ("%s: %s\n", argv[0], _("Invalid option. Please use --help to see a list of valid options.")); return 2; } remaining_ms = t_secs * 1000; nm_g_type_init (); client = nm_client_new (NULL, &error); if (!client) { g_printerr (_("Error: Could not create NMClient object: %s."), error->message); g_error_free (error); return 2; } loop = g_main_loop_new (NULL, FALSE); g_object_set_data (G_OBJECT (client), WAIT_STARTUP_TAG, GUINT_TO_POINTER (wait_startup)); state = nm_client_get_state (client); if (!nm_client_get_nm_running (client)) { if (exit_no_nm) { g_object_unref (client); return 1; } } else if (wait_startup) { if (!nm_client_get_startup (client)) { g_object_unref (client); return 0; } } else { if ( state == NM_STATE_CONNECTED_LOCAL || state == NM_STATE_CONNECTED_SITE || state == NM_STATE_CONNECTED_GLOBAL) { g_object_unref (client); return 0; } } if (exit_no_nm && (state != NM_STATE_CONNECTING)) { g_object_unref (client); return 1; } if (remaining_ms == 0) { g_object_unref (client); return 1; } g_signal_connect (client, "notify", G_CALLBACK (client_properties_changed), loop); timeout.end_timestamp_ms = timeout.start_timestamp_ms + remaining_ms; timeout.progress_step_duration = (timeout.end_timestamp_ms - timeout.start_timestamp_ms + PROGRESS_STEPS/2) / PROGRESS_STEPS; g_timeout_add (timeout.quiet ? remaining_ms : 0, handle_timeout, &timeout); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (client); return 0; }
int main (int argc, char *argv[]) { UniqueApp *app; UniqueMessageData *msg; GError *error = NULL; GOptionContext *context; GOptionGroup *debug; gulong debug_flags = 0; LifereaDBus *dbus = NULL; const gchar *initial_state = "shown"; gchar *feed = NULL; int initialState; gboolean show_tray_icon, start_in_tray; #ifdef USE_SM gchar *opt_session_arg = NULL; #endif GOptionEntry entries[] = { { "mainwindow-state", 'w', 0, G_OPTION_ARG_STRING, &initial_state, N_("Start Liferea with its main window in STATE. STATE may be `shown', `iconified', or `hidden'"), N_("STATE") }, #ifdef USE_SM { "session", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &opt_session_arg, NULL, NULL }, #endif { "version", 'v', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version, N_("Show version information and exit"), NULL }, { "add-feed", 'a', 0, G_OPTION_ARG_STRING, &feed, N_("Add a new subscription"), N_("uri") }, { NULL } }; GOptionEntry debug_entries[] = { { "debug-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all types"), NULL }, { "debug-cache", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the cache handling"), NULL }, { "debug-conf", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages for the configuration handling"), NULL }, { "debug-db", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the database handling"), NULL }, { "debug-gui", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all GUI functions"), NULL }, { "debug-html", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Enables HTML rendering debugging. Each time Liferea renders HTML output it will also dump the generated HTML into ~/.liferea_1.6/output.xhtml"), NULL }, { "debug-net", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all network activity"), NULL }, { "debug-parsing", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of all parsing functions"), NULL }, { "debug-performance", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when a function takes too long to process"), NULL }, { "debug-trace", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages when entering/leaving functions"), NULL }, { "debug-update", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the feed update processing"), NULL }, { "debug-vfolder", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print debugging messages of the search folder matching"), NULL }, { "debug-verbose", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, debug_entries_parse_callback, N_("Print verbose debugging messages"), NULL }, { NULL } }; if (!g_thread_supported ()) g_thread_init (NULL); #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif debug = g_option_group_new ("debug", _("Print debugging messages for the given topic"), _("Print debugging messages for the given topic"), &debug_flags, NULL); g_option_group_set_translation_domain(debug, GETTEXT_PACKAGE); g_option_group_add_entries (debug, debug_entries); context = g_option_context_new (NULL); g_option_context_set_summary (context, N_("Liferea, the Linux Feed Reader")); g_option_context_set_description (context, N_("For more information, please visit http://liferea.sourceforge.net/")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_group (context, debug); g_option_context_add_group (context, gtk_get_option_group (FALSE)); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_print ("Error parsing options: %s\n", error->message); } set_debug_level (debug_flags); /* Configuration necessary for network options, so it has to be initialized before update_init() */ conf_init (); #ifdef USE_DBUS dbus_g_thread_init (); #endif /* We need to do the network initialization here to allow network-manager to be setup before gtk_init() */ update_init (); gtk_init (&argc, &argv); /* Single instance checks */ app = unique_app_new_with_commands ("net.sourceforge.liferea", NULL, "add_feed", COMMAND_ADD_FEED, NULL); if (unique_app_is_running (app)) { g_print ("Liferea is already running\n"); unique_app_send_message (app, UNIQUE_ACTIVATE, NULL); if (feed) { msg = unique_message_data_new (); unique_message_data_set_text (msg, feed, -1); unique_app_send_message (app, COMMAND_ADD_FEED, msg); } return 1; } else { g_signal_connect (app, "message-received", G_CALLBACK (message_received_cb), NULL); } /* GTK theme support */ g_set_application_name (_("Liferea")); gtk_window_set_default_icon_name ("liferea"); debug_start_measurement (DEBUG_DB); /* order is important! */ db_init (); /* initialize sqlite */ xml_init (); /* initialize libxml2 */ #ifdef HAVE_LIBNOTIFY notification_plugin_register (&libnotify_plugin); #endif social_init (); /* initialize social bookmarking */ #ifdef USE_DBUS dbus = liferea_dbus_new (); #else debug0 (DEBUG_GUI, "Compiled without DBUS support."); #endif #ifdef USE_AVAHI if (conf_get_bool_value (SYNC_AVAHI_ENABLED)) { LifereaAvahiPublisher *avahiPublisher = NULL; debug0 (DEBUG_CACHE, "Registering with AVAHI"); avahiPublisher = liferea_avahi_publisher_new (); liferea_avahi_publisher_publish (avahiPublisher, conf_get_str_value (SYNC_AVAHI_SERVICE_NAME), 23632); } else { debug0 (DEBUG_CACHE, "Avahi support available, but disabled by preferences."); } #else debug0 (DEBUG_CACHE, "Compiled without AVAHI support"); #endif /* how to start liferea, command line takes precedence over preferences */ conf_get_bool_value (SHOW_TRAY_ICON, &show_tray_icon); conf_get_bool_value (START_IN_TRAY, &start_in_tray); if (g_str_equal(initial_state, "iconified")) { initialState = MAINWINDOW_ICONIFIED; } else if (g_str_equal(initial_state, "hidden") || (show_tray_icon && start_in_tray)) { initialState = MAINWINDOW_HIDDEN; } else { initialState = MAINWINDOW_SHOWN; } liferea_shell_create (initialState); g_set_prgname ("liferea"); #ifdef USE_SM /* This must be after feedlist reading because some session managers will tell Liferea to exit if Liferea does not respond to SM requests within a minute or two. This starts the main loop soon after opening the SM connection. */ session_init (BIN_DIR G_DIR_SEPARATOR_S "liferea", opt_session_arg); session_set_cmd (NULL, initialState); #endif signal (SIGTERM, signal_handler); signal (SIGINT, signal_handler); signal (SIGHUP, signal_handler); #ifndef G_OS_WIN32 signal (SIGBUS, fatal_signal_handler); signal (SIGSEGV, fatal_signal_handler); #endif /* Note: we explicitely do not use the gdk_thread_* locking in Liferea because it freezes the program when running Flash applets in gtkmozembed */ runState = STATE_STARTING; debug_end_measurement (DEBUG_DB, "startup"); if (feed) feedlist_add_subscription (feed, NULL, NULL, 0); gtk_main (); g_object_unref (G_OBJECT (dbus)); return 0; }
gboolean flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) var_deploy_files = NULL; g_autoptr(GFile) base = NULL; g_autoptr(GFile) files_dir = NULL; g_autoptr(GFile) usr_dir = NULL; g_autoptr(GFile) var_dir = NULL; g_autoptr(GFile) var_tmp_dir = NULL; g_autoptr(GFile) var_run_dir = NULL; g_autoptr(GFile) metadata_file = NULL; g_autoptr(GString) metadata_contents = NULL; g_autoptr(GError) my_error = NULL; const char *app_id; const char *directory; const char *sdk_pref; const char *runtime_pref; const char *default_branch = NULL; g_autofree char *runtime_ref = NULL; g_autofree char *var_ref = NULL; g_autofree char *sdk_ref = NULL; FlatpakKinds kinds; int i; g_autoptr(FlatpakDir) sdk_dir = NULL; g_autoptr(FlatpakDir) runtime_dir = NULL; gboolean is_app = FALSE; gboolean is_extension = FALSE; gboolean is_runtime = FALSE; context = g_option_context_new (_("DIRECTORY APPNAME SDK RUNTIME [BRANCH] - Initialize a directory for building")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 5) return usage_error (context, _("RUNTIME must be specified"), error); if (argc > 6) return usage_error (context, _("Too many arguments"), error); directory = argv[1]; app_id = argv[2]; sdk_pref = argv[3]; runtime_pref = argv[4]; if (argc >= 6) default_branch = argv[5]; if (opt_type != NULL) { if (strcmp (opt_type, "app") == 0) is_app = TRUE; else if (strcmp (opt_type, "extension") == 0) is_extension = TRUE; else if (strcmp (opt_type, "runtime") == 0) is_runtime = TRUE; else return flatpak_fail (error, _("'%s' is not a valid build type name, use app, runtime or extension"), opt_type); } else is_app = TRUE; if (!flatpak_is_valid_name (app_id, &my_error)) return flatpak_fail (error, _("'%s' is not a valid application name: %s"), app_id, my_error->message); kinds = FLATPAK_KINDS_RUNTIME; sdk_dir = flatpak_find_installed_pref (sdk_pref, kinds, opt_arch, default_branch, TRUE, FALSE, FALSE, NULL, &sdk_ref, cancellable, error); if (sdk_dir == NULL) return FALSE; kinds = FLATPAK_KINDS_RUNTIME; if (is_extension) kinds |= FLATPAK_KINDS_APP; runtime_dir = flatpak_find_installed_pref (runtime_pref, kinds, opt_arch, default_branch, TRUE, FALSE, FALSE, NULL, &runtime_ref, cancellable, error); if (runtime_dir == NULL) return FALSE; base = g_file_new_for_commandline_arg (directory); if (!flatpak_mkdir_p (base, cancellable, error)) return FALSE; files_dir = g_file_get_child (base, "files"); if (opt_sdk_dir) usr_dir = g_file_get_child (base, opt_sdk_dir); else usr_dir = g_file_get_child (base, "usr"); var_dir = g_file_get_child (base, "var"); var_tmp_dir = g_file_get_child (var_dir, "tmp"); var_run_dir = g_file_get_child (var_dir, "run"); metadata_file = g_file_get_child (base, "metadata"); if (!opt_update && g_file_query_exists (files_dir, cancellable)) return flatpak_fail (error, _("Build directory %s already initialized"), directory); if (opt_writable_sdk || is_runtime) { g_autoptr(GFile) sdk_deploy_files = NULL; g_autoptr(FlatpakDeploy) sdk_deploy = NULL; sdk_deploy = flatpak_dir_load_deployed (sdk_dir, sdk_ref, NULL, cancellable, error); if (sdk_deploy == NULL) return FALSE; if (!flatpak_rm_rf (usr_dir, NULL, &my_error)) { if (!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_propagate_error (error, g_steal_pointer (&my_error)); return FALSE; } g_clear_error (&my_error); } sdk_deploy_files = flatpak_deploy_get_files (sdk_deploy); if (!flatpak_cp_a (sdk_deploy_files, usr_dir, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; if (opt_sdk_extensions && !copy_extensions (sdk_deploy, default_branch, opt_sdk_extensions, usr_dir, cancellable, error)) return FALSE; } if (opt_var) { var_ref = flatpak_build_runtime_ref (opt_var, default_branch, opt_arch); var_deploy_files = flatpak_find_files_dir_for_ref (var_ref, cancellable, error); if (var_deploy_files == NULL) return FALSE; } if (opt_update) return TRUE; if (!g_file_make_directory (files_dir, cancellable, error)) return FALSE; if (opt_base) { const char *base_branch; g_autofree char *base_ref = NULL; g_autoptr(GFile) base_deploy_files = NULL; g_autoptr(FlatpakDeploy) base_deploy = NULL; base_branch = opt_base_version ? opt_base_version : "master"; base_ref = flatpak_build_app_ref (opt_base, base_branch, opt_arch); base_deploy = flatpak_find_deploy_for_ref (base_ref, cancellable, error); if (base_deploy == NULL) return FALSE; base_deploy_files = flatpak_deploy_get_files (base_deploy); if (!flatpak_cp_a (base_deploy_files, files_dir, FLATPAK_CP_FLAGS_MERGE | FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; if (opt_base_extensions && !copy_extensions (base_deploy, base_branch, opt_base_extensions, files_dir, cancellable, error)) return FALSE; } if (var_deploy_files) { if (!flatpak_cp_a (var_deploy_files, var_dir, FLATPAK_CP_FLAGS_NONE, cancellable, error)) return FALSE; } else { if (!g_file_make_directory (var_dir, cancellable, error)) return FALSE; } if (!flatpak_mkdir_p (var_tmp_dir, cancellable, error)) return FALSE; if (!g_file_query_exists (var_run_dir, cancellable) && !g_file_make_symbolic_link (var_run_dir, "/run", cancellable, error)) return FALSE; metadata_contents = g_string_new (""); if (is_app) g_string_append (metadata_contents, "[Application]\n"); else g_string_append (metadata_contents, "[Runtime]\n"); g_string_append_printf (metadata_contents, "name=%s\n", app_id); /* The "runtime" can be an app in case we're building an extension */ if (g_str_has_prefix (runtime_ref, "runtime/")) g_string_append_printf (metadata_contents, "runtime=%s\n", runtime_ref + strlen ("runtime/")); if (g_str_has_prefix (sdk_ref, "runtime/")) g_string_append_printf (metadata_contents, "sdk=%s\n", sdk_ref + strlen ("runtime/")); if (opt_tags != NULL) { g_string_append (metadata_contents, "tags="); for (i = 0; opt_tags[i] != NULL; i++) { g_string_append (metadata_contents, opt_tags[i]); g_string_append_c (metadata_contents, ';'); } g_string_append_c (metadata_contents, '\n'); } if (is_extension) g_string_append_printf (metadata_contents, "\n" "[ExtensionOf]\n" "ref=%s\n", runtime_ref); if (!g_file_replace_contents (metadata_file, metadata_contents->str, metadata_contents->len, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) return FALSE; return TRUE; }
int main (int argc, char **argv) { #ifdef G_OS_WIN32 extern void link_shutdown (void); #endif GConfClient *client; #if DEVELOPMENT gboolean skip_warning_dialog; #endif GnomeProgram *program; GnomeClient *master_client; GOptionContext *context; char *filename; /* Make ElectricFence work. */ free (malloc (10)); bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); context = g_option_context_new (_("- The Evolution PIM and Email Client")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); #ifdef G_OS_WIN32 set_paths (); #endif program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PARAM_HUMAN_READABLE_NAME, _("Evolution"), NULL); #ifdef G_OS_WIN32 if (strcmp (_(""), "") == 0) { /* No message catalog installed for the current locale language, * so don't bother with the localisations provided by other things then * either. Reset thread locale to "en-US" and C library locale to "C". */ SetThreadLocale (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)); setlocale (LC_ALL, "C"); } #endif if (start_online && start_offline) { fprintf (stderr, _("%s: --online and --offline cannot be used together.\n Use %s --help for more information.\n"), argv[0], argv[0]); exit (1); } if (killev) { filename = g_build_filename (EVOLUTION_TOOLSDIR, "killev", NULL); execl (filename, "killev", NULL); /* Not reached */ exit (0); } client = gconf_client_get_default (); #if DEVELOPMENT if (force_migrate) { destroy_config (client); } #endif if (disable_preview) { gconf_client_set_bool (client, "/apps/evolution/mail/display/show_preview", FALSE, NULL); gconf_client_set_bool (client, "/apps/evolution/mail/display/safe_list", TRUE, NULL); gconf_client_set_bool (client, "/apps/evolution/addressbook/display/show_preview", FALSE, NULL); gconf_client_set_bool (client, "/apps/evolution/calendar/display/show_task_preview", FALSE, NULL); } setup_segv_redirect (); if (evolution_debug_log) { int fd; fd = g_open (evolution_debug_log, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd != -1) { dup2 (fd, STDOUT_FILENO); dup2 (fd, STDERR_FILENO); close (fd); } else g_warning ("Could not set up debugging output file."); } master_client = gnome_master_client (); g_signal_connect (G_OBJECT (master_client), "save_yourself", G_CALLBACK (gnome_master_client_save_yourself_cb), NULL); g_signal_connect (G_OBJECT (master_client), "die", G_CALLBACK (gnome_master_client_die_cb), NULL); glade_init (); e_cursors_init (); e_icon_factory_init (); e_passwords_init(); gtk_window_set_default_icon_name ("evolution"); if (setup_only) exit (0); gnome_sound_init ("localhost"); if (!disable_eplugin) { e_plugin_register_type(e_plugin_lib_get_type()); e_plugin_hook_register_type(es_menu_hook_get_type()); e_plugin_hook_register_type(es_event_hook_get_type()); #ifdef ENABLE_PROFILING e_plugin_hook_register_type(e_profile_event_hook_get_type()); #endif e_plugin_hook_register_type(e_plugin_type_hook_get_type()); e_plugin_hook_register_type(e_import_hook_get_type()); e_plugin_hook_register_type(E_TYPE_PLUGIN_UI_HOOK); e_plugin_load_plugins(); } #if DEVELOPMENT skip_warning_dialog = gconf_client_get_bool ( client, SKIP_WARNING_DIALOG_KEY, NULL); if (!skip_warning_dialog && !getenv ("EVOLVE_ME_HARDER")) gconf_client_set_bool ( client, SKIP_WARNING_DIALOG_KEY, show_development_warning (), NULL); else g_idle_add ((GSourceFunc) idle_cb, remaining_args); #else g_idle_add ((GSourceFunc) idle_cb, remaining_args); #endif g_object_unref (client); bonobo_main (); e_icon_factory_shutdown (); g_object_unref (program); gnome_sound_shutdown (); e_cursors_shutdown (); #ifdef G_OS_WIN32 link_shutdown (); #endif return 0; }
int main(int argc, char *argv[]) { UniqueApp *app; GtkStatusIcon *statusicon; GtkWidget *menu; GOptionContext *context; GError *error = NULL; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif /* Parse command-line options */ context = g_option_context_new (N_("- Bluetooth applet")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (option_debug == FALSE) { app = unique_app_new ("org.mate.Bluetooth.applet", NULL); if (unique_app_is_running (app)) { gdk_notify_startup_complete (); g_warning ("Applet is already running, exiting"); return 0; } } else { app = NULL; } g_set_application_name(_("Bluetooth Applet")); gtk_window_set_default_icon_name("bluetooth"); killswitch = bluetooth_killswitch_new (); g_signal_connect (G_OBJECT (killswitch), "state-changed", G_CALLBACK (killswitch_state_changed), NULL); menu = create_popupmenu(); client = bluetooth_client_new(); devices_model = bluetooth_client_get_model(client); g_signal_connect(G_OBJECT(devices_model), "row-inserted", G_CALLBACK(device_added), NULL); g_signal_connect(G_OBJECT(devices_model), "row-deleted", G_CALLBACK(device_removed), NULL); g_signal_connect (G_OBJECT (devices_model), "row-changed", G_CALLBACK (device_changed), NULL); /* Set the default adapter */ device_changed (devices_model, NULL, NULL, NULL); if (bluetooth_killswitch_has_killswitches (killswitch) != FALSE) { killswitch_state_changed (killswitch, bluetooth_killswitch_get_state (killswitch)); } /* Make sure all the unblocked adapters are powered, * so as to avoid seeing unpowered, but unblocked * devices */ bluetooth_set_adapter_powered (); settings = g_settings_new (SCHEMA_NAME); show_icon_pref = g_settings_get_boolean (settings, PREF_SHOW_ICON); g_signal_connect (G_OBJECT (settings), "changed::" PREF_SHOW_ICON, G_CALLBACK (show_icon_changed), NULL); statusicon = init_notification(); update_icon_visibility(); g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); setup_agents(); gtk_main(); gtk_widget_destroy(menu); g_object_unref(settings); cleanup_agents(); cleanup_notification(); g_object_unref(devices_model); g_object_unref(client); if (app != NULL) g_object_unref (app); return 0; }
gboolean flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GPtrArray) dirs = NULL; g_autoptr(FlatpakDir) dir = NULL; g_autofree char *remote = NULL; g_autofree char *remote_url = NULL; char **prefs = NULL; int i, n_prefs; g_autofree char *target_branch = NULL; g_autofree char *default_branch = NULL; FlatpakKinds kinds; g_autoptr(FlatpakTransaction) transaction = NULL; g_autoptr(FlatpakDir) dir_with_remote = NULL; gboolean auto_remote = FALSE; context = g_option_context_new (_("[LOCATION/REMOTE] [REF…] - Install applications or runtimes")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_ALL_DIRS | FLATPAK_BUILTIN_FLAG_OPTIONAL_REPO, &dirs, cancellable, error)) return FALSE; /* Start with the default or specified dir, this is fine for opt_bundle or opt_from */ dir = g_object_ref (g_ptr_array_index (dirs, 0)); if (!opt_bundle && !opt_from && argc >= 2) { if (flatpak_file_arg_has_suffix (argv[1], ".flatpakref")) opt_from = TRUE; if (flatpak_file_arg_has_suffix (argv[1], ".flatpak")) opt_bundle = TRUE; } if (opt_bundle) return install_bundle (dir, context, argc, argv, cancellable, error); if (opt_from) return install_from (dir, context, argc, argv, cancellable, error); if (argc < 2) return usage_error (context, _("At least one REF must be specified"), error); if (argc == 2) auto_remote = TRUE; kinds = flatpak_kinds_from_bools (opt_app, opt_runtime); if (!opt_noninteractive) g_print (_("Looking for matches…\n")); if (!auto_remote && (g_path_is_absolute (argv[1]) || g_str_has_prefix (argv[1], "./"))) { g_autoptr(GFile) remote_file = g_file_new_for_commandline_arg (argv[1]); remote_url = g_file_get_uri (remote_file); remote = g_strdup (remote_url); } else { g_autoptr(GError) local_error = NULL; /* If the remote was used, and no single dir was specified, find which * one based on the remote. If the remote isn't found assume it's a ref * and we should auto-detect the remote. */ if (!auto_remote && !flatpak_resolve_duplicate_remotes (dirs, argv[1], &dir_with_remote, cancellable, &local_error)) { if (g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_REMOTE_NOT_FOUND)) { auto_remote = TRUE; } else { g_propagate_error (error, g_steal_pointer (&local_error)); return FALSE; } } if (!auto_remote) { remote = g_strdup (argv[1]); g_clear_object (&dir); dir = g_object_ref (dir_with_remote); } else { g_autoptr(GPtrArray) remote_dir_pairs = NULL; RemoteDirPair *chosen_pair = NULL; remote_dir_pairs = g_ptr_array_new_with_free_func ((GDestroyNotify) remote_dir_pair_free); /* Search all remotes for a matching ref. This is imperfect * because it only takes the first specified ref into account and * doesn't distinguish between an exact match and a fuzzy match, but * that's okay because the user will be asked to confirm the remote */ for (i = 0; i < dirs->len; i++) { FlatpakDir *this_dir = g_ptr_array_index (dirs, i); g_auto(GStrv) remotes = NULL; guint j = 0; remotes = flatpak_dir_list_remotes (this_dir, cancellable, error); if (remotes == NULL) return FALSE; for (j = 0; remotes[j] != NULL; j++) { const char *this_remote = remotes[j]; g_autofree char *this_default_branch = NULL; g_autofree char *id = NULL; g_autofree char *arch = NULL; g_autofree char *branch = NULL; FlatpakKinds matched_kinds; g_auto(GStrv) refs = NULL; g_autoptr(GError) local_error = NULL; if (flatpak_dir_get_remote_disabled (this_dir, this_remote) || flatpak_dir_get_remote_noenumerate (this_dir, this_remote)) continue; this_default_branch = flatpak_dir_get_remote_default_branch (this_dir, this_remote); flatpak_split_partial_ref_arg_novalidate (argv[1], kinds, opt_arch, target_branch, &matched_kinds, &id, &arch, &branch); if (opt_no_pull) refs = flatpak_dir_find_local_refs (this_dir, this_remote, id, branch, this_default_branch, arch, flatpak_get_default_arch (), matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, &local_error); else refs = flatpak_dir_find_remote_refs (this_dir, this_remote, id, branch, this_default_branch, arch, flatpak_get_default_arch (), matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, &local_error); if (refs == NULL) { g_warning ("An error was encountered searching remote ‘%s’ for ‘%s’: %s", this_remote, argv[1], local_error->message); continue; } if (g_strv_length (refs) == 0) continue; else { RemoteDirPair *pair = remote_dir_pair_new (this_remote, this_dir); g_ptr_array_add (remote_dir_pairs, pair); } } } if (remote_dir_pairs->len == 0) return flatpak_fail (error, _("No remote refs found similar to ‘%s’"), argv[1]); if (!flatpak_resolve_matching_remotes (opt_yes, remote_dir_pairs, argv[1], &chosen_pair, error)) return FALSE; remote = g_strdup (chosen_pair->remote_name); g_clear_object (&dir); dir = g_object_ref (chosen_pair->dir); } } if (auto_remote) { prefs = &argv[1]; n_prefs = argc - 1; } else { prefs = &argv[2]; n_prefs = argc - 2; } /* Backwards compat for old "REMOTE NAME [BRANCH]" argument version */ if (argc == 4 && flatpak_is_valid_name (argv[2], NULL) && looks_like_branch (argv[3])) { target_branch = g_strdup (argv[3]); n_prefs = 1; } default_branch = flatpak_dir_get_remote_default_branch (dir, remote); if (opt_noninteractive) transaction = flatpak_quiet_transaction_new (dir, error); else transaction = flatpak_cli_transaction_new (dir, opt_yes, TRUE, error); if (transaction == NULL) return FALSE; flatpak_transaction_set_no_pull (transaction, opt_no_pull); flatpak_transaction_set_no_deploy (transaction, opt_no_deploy); flatpak_transaction_set_disable_static_deltas (transaction, opt_no_static_deltas); flatpak_transaction_set_disable_dependencies (transaction, opt_no_deps); flatpak_transaction_set_disable_related (transaction, opt_no_related); flatpak_transaction_set_reinstall (transaction, opt_reinstall); for (i = 0; i < n_prefs; i++) { const char *pref = prefs[i]; FlatpakKinds matched_kinds; g_autofree char *id = NULL; g_autofree char *arch = NULL; g_autofree char *branch = NULL; g_autofree char *ref = NULL; g_auto(GStrv) refs = NULL; guint refs_len; g_autoptr(GError) local_error = NULL; flatpak_split_partial_ref_arg_novalidate (pref, kinds, opt_arch, target_branch, &matched_kinds, &id, &arch, &branch); /* We used _novalidate so that the id can be partial, but we can still validate the branch */ if (branch != NULL && !flatpak_is_valid_branch (branch, &local_error)) return flatpak_fail_error (error, FLATPAK_ERROR_INVALID_REF, _("Invalid branch %s: %s"), branch, local_error->message); if (opt_no_pull) refs = flatpak_dir_find_local_refs (dir, remote, id, branch, default_branch, arch, flatpak_get_default_arch (), matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, error); else refs = flatpak_dir_find_remote_refs (dir, remote, id, branch, default_branch, arch, flatpak_get_default_arch (), matched_kinds, FIND_MATCHING_REFS_FLAGS_FUZZY, cancellable, error); if (refs == NULL) return FALSE; refs_len = g_strv_length (refs); if (refs_len == 0) { if (opt_no_pull) g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("Nothing matches %s in local repository for remote %s"), id, remote); else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("Nothing matches %s in remote %s"), id, remote); return FALSE; } if (!flatpak_resolve_matching_refs (remote, dir, opt_yes, refs, id, &ref, error)) return FALSE; if (!flatpak_transaction_add_install (transaction, remote, ref, (const char **)opt_subpaths, error)) { if (!g_error_matches (*error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED)) return FALSE; g_printerr (_("Skipping: %s\n"), (*error)->message); g_clear_error (error); } } if (!flatpak_transaction_run (transaction, cancellable, error)) { if (g_error_matches (*error, FLATPAK_ERROR, FLATPAK_ERROR_ABORTED)) { g_clear_error (error); return TRUE; } return FALSE; } return TRUE; }
// main function int main(int argc, char *argv[]) { gboolean show_version = FALSE; gboolean log_info = FALSE; gboolean log_debug = FALSE; gboolean no_daemon = FALSE; gboolean test_mode = FALSE; gint poll_interval = -1; gboolean success; GOptionContext *opt_ctx; thd_daemonize = TRUE; dbus_enable = FALSE; GOptionEntry options[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Print thermald version and exit"), NULL }, { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &no_daemon, N_( "Don't become a daemon: Default is daemon mode"), NULL }, { "loglevel=info", 0, 0, G_OPTION_ARG_NONE, &log_info, N_( "log severity: info level and up"), NULL }, { "loglevel=debug", 0, 0, G_OPTION_ARG_NONE, &log_debug, N_( "log severity: debug level and up: Max logging"), NULL }, { "test-mode", 0, 0, G_OPTION_ARG_NONE, &test_mode, N_( "Test Mode only: Allow non root user"), NULL }, { "poll-interval", 0, 0, G_OPTION_ARG_INT, &poll_interval, N_("Poll interval in seconds: Poll for zone temperature changes. " "If want to disable polling set to zero."), NULL }, { "dbus-enable", 0, 0, G_OPTION_ARG_NONE, &dbus_enable, N_( "Enable Dbus."), NULL }, { "exclusive-control", 0, 0, G_OPTION_ARG_NONE, &exclusive_control, N_( "Take over thermal control from kernel thermal driver."), NULL }, { "ingore-cpuid-check", 0, 0, G_OPTION_ARG_NONE, &ignore_cpuid_check, N_("Ignore CPU ID check."), NULL }, { NULL } }; if (!g_module_supported()) { fprintf(stderr, _("GModules are not supported on your platform!\n")); exit(1); } /* Set locale to be able to use environment variables */ setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, TDLOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); /* Parse options */ opt_ctx = g_option_context_new(NULL); g_option_context_set_translation_domain(opt_ctx, GETTEXT_PACKAGE); g_option_context_set_ignore_unknown_options(opt_ctx, FALSE); g_option_context_set_help_enabled(opt_ctx, TRUE); g_option_context_add_main_entries(opt_ctx, options, NULL); g_option_context_set_summary(opt_ctx, _( "Thermal daemon monitors temperature sensors and decides the best action " "based on the temperature readings and user preferences.")); success = g_option_context_parse(opt_ctx, &argc, &argv, NULL); g_option_context_free(opt_ctx); if (!success) { fprintf(stderr, _( "Invalid option. Please use --help to see a list of valid options.\n")); exit(1); } if (show_version) { fprintf(stdout, TD_DIST_VERSION "\n"); exit(0); } if (getuid() != 0 && !test_mode) { fprintf(stderr, _("You must be root to run thermald!\n")); exit(1); } if (g_mkdir_with_parents(TDRUNDIR, 0755) != 0) { fprintf(stderr, "Cannot create '%s': %s", TDRUNDIR, strerror(errno)); exit(1); } g_mkdir_with_parents(TDCONFDIR, 0755); // Don't care return value as directory // may already exist if (log_info) { thd_log_level |= G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO; } if (log_debug) { thd_log_level |= G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG; } if (poll_interval >= 0) { fprintf(stdout, "Polling enabled: %d\n", poll_interval); thd_poll_interval = poll_interval; } openlog("thermald", LOG_PID, LOG_USER | LOG_DAEMON | LOG_SYSLOG); // Don't care return val //setlogmask(LOG_CRIT | LOG_ERR | LOG_WARNING | LOG_NOTICE | LOG_DEBUG | LOG_INFO); thd_daemonize = !no_daemon; g_log_set_handler(NULL, G_LOG_LEVEL_MASK, thd_logger, NULL); if (no_daemon) signal(SIGINT, sig_int_handler); // dbus glib processing begin thd_dbus_server_proc(no_daemon); fprintf(stdout, "Exiting ..\n"); closelog(); }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionGroup *option_group; GOptionContext *context; const gchar *simulation_filename, *introspection_filename; gchar *simulation_code, *introspection_xml; MainData data; GPtrArray/*<DfsmObject>*/ *simulated_objects; const gchar *test_program_name; GPtrArray/*<string>*/ *test_program_argv; guint i; gchar *time_str, *command_line, *log_header, *seed_str; GDateTime *date_time; GFile *working_directory_file, *dbus_daemon_config_file; /* Set up localisation. */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif g_set_application_name (_("D-Bus Simulator")); /* Take a copy of the command line, for use in printing the log headers later. */ command_line = g_strjoinv (" ", argv); /* Parse command line options */ context = g_option_context_new (_("[simulation code file] [introspection XML file] -- [executable-file] [arguments]")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_set_summary (context, _("Simulates the server in a D-Bus client–server conversation.")); g_option_context_add_main_entries (context, main_entries, GETTEXT_PACKAGE); /* Logging option group */ option_group = g_option_group_new ("logging", _("Logging Options:"), _("Show help options for output logging"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, logging_entries); g_option_context_add_group (context, option_group); /* Testing option group */ option_group = g_option_group_new ("testing", _("Testing Options:"), _("Show help options for test runs and timeouts"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, testing_entries); g_option_context_add_group (context, option_group); /* Test program option group */ option_group = g_option_group_new ("test-program", _("Test Program Options:"), _("Show help options for the program under test"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, test_program_entries); g_option_context_add_group (context, option_group); /* dbus-daemon option group */ option_group = g_option_group_new ("dbus-daemon", _("D-Bus Daemon Options:"), _("Show help options for the dbus-daemon"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, dbus_daemon_entries); g_option_context_add_group (context, option_group); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_printerr (_("Error parsing command line options: %s"), error->message); g_printerr ("\n"); print_help_text (context); g_error_free (error); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } /* Extract the simulation and the introspection filenames. */ if (argc < 3) { g_printerr (_("Error parsing command line options: %s"), _("Simulation and introspection filenames must be provided")); g_printerr ("\n"); print_help_text (context); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } simulation_filename = argv[1]; introspection_filename = argv[2]; /* Extract the remaining arguments */ if (argc < 4) { g_printerr (_("Error parsing command line options: %s"), _("Test program must be provided")); g_printerr ("\n"); print_help_text (context); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } /* Work out where the test program's command line starts. g_option_context_parse() sometimes leaves the ‘--’ in argv. */ if (strcmp (argv[3], "--") == 0) { i = 4; } else { i = 3; } test_program_name = argv[i++]; test_program_argv = g_ptr_array_new_with_free_func (g_free); for (; i < (guint) argc; i++) { g_ptr_array_add (test_program_argv, g_strdup (argv[i])); } g_option_context_free (context); /* Set up logging. */ dsim_logging_init (test_program_log_file, test_program_log_fd, dbus_daemon_log_file, dbus_daemon_log_fd, simulator_log_file, simulator_log_fd, &error); if (error != NULL) { g_printerr (_("Error setting up logging: %s"), error->message); g_printerr ("\n"); g_error_free (error); g_free (command_line); exit (STATUS_LOGGING_PROBLEM); } /* Output a log header to each of the log streams. */ date_time = g_date_time_new_now_utc (); time_str = g_date_time_format (date_time, "%F %TZ"); g_date_time_unref (date_time); log_header = g_strdup_printf (_("Bendy Bus (number %s) left the depot at %s using command line: %s"), PACKAGE_VERSION, time_str, command_line); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "%s", log_header); g_log (dsim_logging_get_domain_name (DSIM_LOG_DBUS_DAEMON), G_LOG_LEVEL_MESSAGE, "%s", log_header); g_log (dsim_logging_get_domain_name (DSIM_LOG_TEST_PROGRAM), G_LOG_LEVEL_MESSAGE, "%s", log_header); g_free (log_header); g_free (time_str); g_free (command_line); /* Set up the random number generator. */ if (random_seed == 0) { random_seed = g_get_real_time (); } seed_str = g_strdup_printf ("%" G_GINT64_FORMAT, random_seed); g_message (_("Note: Setting random number generator seed to %s."), seed_str); g_free (seed_str); g_random_set_seed ((guint32) random_seed); /* Load the files. */ g_file_get_contents (simulation_filename, &simulation_code, NULL, &error); if (error != NULL) { g_printerr (_("Error loading simulation code from file ‘%s’: %s"), simulation_filename, error->message); g_printerr ("\n"); g_error_free (error); exit (STATUS_UNREADABLE_FILE); } g_file_get_contents (introspection_filename, &introspection_xml, NULL, &error); if (error != NULL) { g_printerr (_("Error loading introspection XML from file ‘%s’: %s"), introspection_filename, error->message); g_printerr ("\n"); g_error_free (error); g_free (simulation_code); exit (STATUS_UNREADABLE_FILE); } /* Build the DfsmObjects. */ simulated_objects = dfsm_object_factory_from_data (simulation_code, introspection_xml, &error); g_free (introspection_xml); g_free (simulation_code); if (error != NULL) { g_printerr (_("Error creating simulated DFSMs: %s"), error->message); g_printerr ("\n"); g_error_free (error); exit (STATUS_INVALID_CODE); } /* Prepare the main data struct, which will last for the lifetime of the program. */ data.main_loop = g_main_loop_new (NULL, FALSE); data.exit_status = STATUS_SUCCESS; data.exit_signal = EXIT_SIGNAL_INVALID; data.test_program = NULL; data.connection = NULL; data.simulated_objects = g_ptr_array_ref (simulated_objects); data.outstanding_registration_callbacks = 0; data.test_run_inactivity_timeout_id = 0; data.test_program_spawn_end_signal = 0; data.test_program_process_died_signal = 0; data.test_program_sigkill_timeout_id = 0; if (run_infinitely == TRUE || (run_iters == 0 && run_time == 0)) { data.num_test_runs_remaining = -1; } else { data.num_test_runs_remaining = run_iters; } g_ptr_array_unref (simulated_objects); /* Store the test program name and argv, since we can only spawn it once we know the bus address. */ data.test_program_name = g_strdup (test_program_name); data.test_program_argv = g_ptr_array_ref (test_program_argv); g_ptr_array_unref (test_program_argv); /* Set up signal handlers for SIGINT and SIGTERM so that we can close gracefully. */ g_unix_signal_add (SIGINT, (GSourceFunc) sigint_handler_cb, &data); g_unix_signal_add (SIGTERM, (GSourceFunc) sigterm_handler_cb, &data); /* Create a working directory. */ prepare_dbus_daemon_working_directory (&(data.working_directory_file), &working_directory_file, &dbus_daemon_config_file, &error); if (error != NULL) { g_printerr (_("Error creating dbus-daemon working directory: %s"), error->message); g_printerr ("\n"); g_error_free (error); main_data_clear (&data); dsim_logging_finalise (); exit (STATUS_TMP_DIR_ERROR); } /* Start up our own private dbus-daemon instance. */ data.dbus_daemon = dsim_dbus_daemon_new (working_directory_file, dbus_daemon_config_file); data.dbus_address = NULL; g_object_unref (dbus_daemon_config_file); g_object_unref (working_directory_file); g_signal_connect (data.dbus_daemon, "process-died", (GCallback) dbus_daemon_died_cb, &data); g_signal_connect (data.dbus_daemon, "notify::bus-address", (GCallback) dbus_daemon_notify_bus_address_cb, &data); dsim_program_wrapper_spawn (DSIM_PROGRAM_WRAPPER (data.dbus_daemon), &error); if (error != NULL) { g_printerr (_("Error spawning private dbus-daemon instance: %s"), error->message); g_printerr ("\n"); g_error_free (error); main_data_clear (&data); dsim_logging_finalise (); exit (STATUS_DAEMON_SPAWN_ERROR); } /* Start the main loop and wait for the dbus-daemon to send us its address. */ g_main_loop_run (data.main_loop); /* Free the main data struct. */ main_data_clear (&data); dsim_logging_finalise (); if (data.exit_signal != EXIT_SIGNAL_INVALID) { struct sigaction action; /* Propagate the signal to the default handler. */ action.sa_handler = SIG_DFL; sigemptyset (&action.sa_mask); action.sa_flags = 0; sigaction (data.exit_signal, &action, NULL); kill (getpid (), data.exit_signal); } return data.exit_status; }
gboolean flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) dst_repofile = NULL; g_autoptr(OstreeRepo) dst_repo = NULL; g_autoptr(GFile) src_repofile = NULL; g_autoptr(OstreeRepo) src_repo = NULL; g_autofree char *src_repo_uri = NULL; const char *dst_repo_arg; const char **dst_refs; int n_dst_refs = 0; g_autoptr(FlatpakRepoTransaction) transaction = NULL; g_autoptr(GPtrArray) src_refs = NULL; g_autoptr(GPtrArray) resolved_src_refs = NULL; OstreeRepoCommitState src_commit_state; struct timespec ts; guint64 timestamp; int i; context = g_option_context_new (_("DST-REPO [DST-REF…] - Make a new commit from existing commits")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 2) return usage_error (context, _("DST-REPO must be specified"), error); dst_repo_arg = argv[1]; dst_refs = (const char **) argv + 2; n_dst_refs = argc - 2; if (opt_src_repo == NULL && n_dst_refs != 1) return usage_error (context, _("If --src-repo is not specified, exactly one destination ref must be specified"), error); if (opt_src_ref != NULL && n_dst_refs != 1) return usage_error (context, _("If --src-ref is specified, exactly one destination ref must be specified"), error); if (opt_src_repo == NULL && opt_src_ref == NULL) return flatpak_fail (error, _("Either --src-repo or --src-ref must be specified.")); /* Always create a commit if we're eol:ing, even though the app is the same */ if (opt_endoflife != NULL || opt_endoflife_rebase != NULL) opt_force = TRUE; if (opt_endoflife_rebase) { opt_endoflife_rebase_new = g_new0 (char *, g_strv_length (opt_endoflife_rebase)); for (i = 0; opt_endoflife_rebase[i] != NULL; i++) { char *rebase_old = opt_endoflife_rebase[i]; char *rebase_new = strchr (rebase_old, '='); if (rebase_new == NULL) { return usage_error (context, _("Invalid argument format of use --end-of-life-rebase=OLDID=NEWID"), error); } *rebase_new = 0; rebase_new++; if (!flatpak_is_valid_name (rebase_old, error)) return glnx_prefix_error (error, _("Invalid name %s in --end-of-life-rebase"), rebase_old); if (!flatpak_is_valid_name (rebase_new, error)) return glnx_prefix_error (error, _("Invalid name %s in --end-of-life-rebase"), rebase_new); opt_endoflife_rebase_new[i] = rebase_new; } } if (opt_timestamp) { if (!parse_datetime (&ts, opt_timestamp, NULL)) return flatpak_fail (error, _("Could not parse '%s'"), opt_timestamp); } dst_repofile = g_file_new_for_commandline_arg (dst_repo_arg); if (!g_file_query_exists (dst_repofile, cancellable)) return flatpak_fail (error, _("'%s' is not a valid repository"), dst_repo_arg); dst_repo = ostree_repo_new (dst_repofile); if (!ostree_repo_open (dst_repo, cancellable, error)) return FALSE; if (opt_disable_fsync) ostree_repo_set_disable_fsync (dst_repo, TRUE); if (opt_src_repo) { src_repofile = g_file_new_for_commandline_arg (opt_src_repo); if (!g_file_query_exists (src_repofile, cancellable)) return flatpak_fail (error, _("'%s' is not a valid repository"), opt_src_repo); src_repo_uri = g_file_get_uri (src_repofile); src_repo = ostree_repo_new (src_repofile); if (!ostree_repo_open (src_repo, cancellable, error)) return FALSE; } else { src_repo = g_object_ref (dst_repo); } src_refs = g_ptr_array_new_with_free_func (g_free); if (opt_src_ref) { g_assert (n_dst_refs == 1); g_ptr_array_add (src_refs, g_strdup (opt_src_ref)); } else { g_assert (opt_src_repo != NULL); if (n_dst_refs == 0) { g_autofree const char **keys = NULL; g_autoptr(GHashTable) all_src_refs = NULL; if (!ostree_repo_list_refs (src_repo, NULL, &all_src_refs, cancellable, error)) return FALSE; keys = (const char **) g_hash_table_get_keys_as_array (all_src_refs, NULL); for (i = 0; keys[i] != NULL; i++) { if (g_str_has_prefix (keys[i], "runtime/") || g_str_has_prefix (keys[i], "app/")) g_ptr_array_add (src_refs, g_strdup (keys[i])); } n_dst_refs = src_refs->len; dst_refs = (const char **) src_refs->pdata; } else { for (i = 0; i < n_dst_refs; i++) g_ptr_array_add (src_refs, g_strdup (dst_refs[i])); } } resolved_src_refs = g_ptr_array_new_with_free_func (g_free); for (i = 0; i < src_refs->len; i++) { const char *src_ref = g_ptr_array_index (src_refs, i); char *resolved_ref; if (!ostree_repo_resolve_rev (src_repo, src_ref, FALSE, &resolved_ref, error)) return FALSE; g_ptr_array_add (resolved_src_refs, resolved_ref); } if (src_repo_uri != NULL) { OstreeRepoPullFlags pullflags = 0; GVariantBuilder builder; g_autoptr(OstreeAsyncProgress) progress = NULL; g_auto(GLnxConsoleRef) console = { 0, }; g_autoptr(GVariant) options = NULL; gboolean res; if (opt_untrusted) pullflags |= OSTREE_REPO_PULL_FLAGS_UNTRUSTED; glnx_console_lock (&console); if (console.is_tty) progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&builder, "{s@v}", "flags", g_variant_new_variant (g_variant_new_int32 (pullflags))); g_variant_builder_add (&builder, "{s@v}", "refs", g_variant_new_variant (g_variant_new_strv ((const char * const *) resolved_src_refs->pdata, resolved_src_refs->len))); g_variant_builder_add (&builder, "{s@v}", "depth", g_variant_new_variant (g_variant_new_int32 (0))); options = g_variant_ref_sink (g_variant_builder_end (&builder)); res = ostree_repo_pull_with_options (dst_repo, src_repo_uri, options, progress, cancellable, error); if (progress) ostree_async_progress_finish (progress); if (!res) return FALSE; } /* By now we have the commit with commit_id==resolved_ref and dependencies in dst_repo. We now create a new * commit based on the toplevel tree ref from that commit. * This is equivalent to: * ostree commit --skip-if-unchanged --repo=${destrepo} --tree=ref=${resolved_ref} */ transaction = flatpak_repo_transaction_start (dst_repo, cancellable, error); if (transaction == NULL) return FALSE; for (i = 0; i < resolved_src_refs->len; i++) { const char *dst_ref = dst_refs[i]; const char *resolved_ref = g_ptr_array_index (resolved_src_refs, i); g_autofree char *dst_parent = NULL; g_autoptr(GFile) dst_parent_root = NULL; g_autoptr(GFile) src_ref_root = NULL; g_autoptr(GVariant) src_commitv = NULL; g_autoptr(GVariant) dst_commitv = NULL; g_autoptr(OstreeMutableTree) mtree = NULL; g_autoptr(GFile) dst_root = NULL; g_autoptr(GVariant) commitv_metadata = NULL; g_autoptr(GVariant) metadata = NULL; const char *subject; const char *body; g_autofree char *commit_checksum = NULL; GVariantBuilder metadata_builder; gint j; const char *dst_collection_id = NULL; const char *main_collection_id = NULL; g_autoptr(GPtrArray) collection_ids = NULL; if (!ostree_repo_resolve_rev (dst_repo, dst_ref, TRUE, &dst_parent, error)) return FALSE; if (dst_parent != NULL && !ostree_repo_read_commit (dst_repo, dst_parent, &dst_parent_root, NULL, cancellable, error)) return FALSE; if (!ostree_repo_read_commit (dst_repo, resolved_ref, &src_ref_root, NULL, cancellable, error)) return FALSE; if (!ostree_repo_load_commit (dst_repo, resolved_ref, &src_commitv, &src_commit_state, error)) return FALSE; if (src_commit_state & OSTREE_REPO_COMMIT_STATE_PARTIAL) return flatpak_fail (error, _("Can't commit from partial source commit.")); /* Don't create a new commit if this is the same tree */ if (!opt_force && dst_parent_root != NULL && g_file_equal (dst_parent_root, src_ref_root)) { g_print (_("%s: no change\n"), dst_ref); continue; } mtree = ostree_mutable_tree_new (); if (!ostree_repo_write_directory_to_mtree (dst_repo, src_ref_root, mtree, NULL, cancellable, error)) return FALSE; if (!ostree_repo_write_mtree (dst_repo, mtree, &dst_root, cancellable, error)) return FALSE; commitv_metadata = g_variant_get_child_value (src_commitv, 0); g_variant_get_child (src_commitv, 3, "&s", &subject); if (opt_subject) subject = (const char *) opt_subject; g_variant_get_child (src_commitv, 4, "&s", &body); if (opt_body) body = (const char *) opt_body; dst_collection_id = ostree_repo_get_collection_id (dst_repo); collection_ids = g_ptr_array_new_with_free_func (g_free); if (dst_collection_id) { main_collection_id = dst_collection_id; g_ptr_array_add (collection_ids, g_strdup (dst_collection_id)); } if (opt_extra_collection_ids != NULL) { for (j = 0; opt_extra_collection_ids[j] != NULL; j++) { const char *cid = opt_extra_collection_ids[j]; if (main_collection_id == NULL) main_collection_id = cid; /* Fall back to first arg */ if (g_strcmp0 (cid, dst_collection_id) != 0) g_ptr_array_add (collection_ids, g_strdup (cid)); } } g_ptr_array_sort (collection_ids, (GCompareFunc) flatpak_strcmp0_ptr); /* Copy old metadata */ g_variant_builder_init (&metadata_builder, G_VARIANT_TYPE ("a{sv}")); /* Bindings. xa.ref is deprecated but added anyway for backwards compatibility. */ g_variant_builder_add (&metadata_builder, "{sv}", "ostree.collection-binding", g_variant_new_string (main_collection_id ? main_collection_id : "")); if (collection_ids->len > 0) { g_autoptr(GVariantBuilder) cr_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ss)")); for (j = 0; j < collection_ids->len; j++) g_variant_builder_add (cr_builder, "(ss)", g_ptr_array_index (collection_ids, j), dst_ref); g_variant_builder_add (&metadata_builder, "{sv}", "ostree.collection-refs-binding", g_variant_builder_end (cr_builder)); } g_variant_builder_add (&metadata_builder, "{sv}", "ostree.ref-binding", g_variant_new_strv (&dst_ref, 1)); g_variant_builder_add (&metadata_builder, "{sv}", "xa.ref", g_variant_new_string (dst_ref)); /* Record the source commit. This is nice to have, but it also means the commit-from gets a different commit id, which avoids problems with e.g. sharing .commitmeta files (signatures) */ g_variant_builder_add (&metadata_builder, "{sv}", "xa.from_commit", g_variant_new_string (resolved_ref)); for (j = 0; j < g_variant_n_children (commitv_metadata); j++) { g_autoptr(GVariant) child = g_variant_get_child_value (commitv_metadata, j); g_autoptr(GVariant) keyv = g_variant_get_child_value (child, 0); const char *key = g_variant_get_string (keyv, NULL); if (strcmp (key, "xa.ref") == 0 || strcmp (key, "xa.from_commit") == 0 || strcmp (key, "ostree.collection-binding") == 0 || strcmp (key, "ostree.collection-refs-binding") == 0 || strcmp (key, "ostree.ref-binding") == 0) continue; if (opt_endoflife && strcmp (key, OSTREE_COMMIT_META_KEY_ENDOFLIFE) == 0) continue; if (opt_endoflife_rebase && strcmp (key, OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE) == 0) continue; g_variant_builder_add_value (&metadata_builder, child); } if (opt_endoflife && *opt_endoflife) g_variant_builder_add (&metadata_builder, "{sv}", OSTREE_COMMIT_META_KEY_ENDOFLIFE, g_variant_new_string (opt_endoflife)); if (opt_endoflife_rebase) { g_auto(GStrv) dst_ref_parts = g_strsplit (dst_ref, "/", 0); for (j = 0; opt_endoflife_rebase[j] != NULL; j++) { const char *old_prefix = opt_endoflife_rebase[j]; if (flatpak_has_name_prefix (dst_ref_parts[1], old_prefix)) { g_autofree char *new_id = g_strconcat (opt_endoflife_rebase_new[j], dst_ref_parts[1] + strlen(old_prefix), NULL); g_autofree char *rebased_ref = g_build_filename (dst_ref_parts[0], new_id, dst_ref_parts[2], dst_ref_parts[3], NULL); g_variant_builder_add (&metadata_builder, "{sv}", OSTREE_COMMIT_META_KEY_ENDOFLIFE_REBASE, g_variant_new_string (rebased_ref)); break; } } } timestamp = ostree_commit_get_timestamp (src_commitv); if (opt_timestamp) timestamp = ts.tv_sec; metadata = g_variant_ref_sink (g_variant_builder_end (&metadata_builder)); if (!ostree_repo_write_commit_with_time (dst_repo, dst_parent, subject, body, metadata, OSTREE_REPO_FILE (dst_root), timestamp, &commit_checksum, cancellable, error)) return FALSE; g_print ("%s: %s\n", dst_ref, commit_checksum); if (!ostree_repo_load_commit (dst_repo, commit_checksum, &dst_commitv, NULL, error)) return FALSE; /* This doesn't copy the detached metadata. I'm not sure if this is a problem. * The main thing there is commit signatures, and we can't copy those, as the commit hash changes. */ if (opt_gpg_key_ids) { char **iter; for (iter = opt_gpg_key_ids; iter && *iter; iter++) { const char *keyid = *iter; g_autoptr(GError) my_error = NULL; if (!ostree_repo_sign_commit (dst_repo, commit_checksum, keyid, opt_gpg_homedir, cancellable, &my_error) && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, g_steal_pointer (&my_error)); return FALSE; } } } if (dst_collection_id != NULL) { OstreeCollectionRef ref = { (char *) dst_collection_id, (char *) dst_ref }; ostree_repo_transaction_set_collection_ref (dst_repo, &ref, commit_checksum); } else { ostree_repo_transaction_set_ref (dst_repo, NULL, dst_ref, commit_checksum); } if (opt_extra_collection_ids) { for (j = 0; opt_extra_collection_ids[j] != NULL; j++) { OstreeCollectionRef ref = { (char *) opt_extra_collection_ids[j], (char *) dst_ref }; ostree_repo_transaction_set_collection_ref (dst_repo, &ref, commit_checksum); } } /* Copy + Rewrite any deltas */ { const char *from[2]; gsize j, n_from = 0; if (dst_parent != NULL) from[n_from++] = dst_parent; from[n_from++] = NULL; for (j = 0; j < n_from; j++) { g_autoptr(GError) local_error = NULL; if (!rewrite_delta (src_repo, resolved_ref, dst_repo, commit_checksum, dst_commitv, from[j], &local_error)) g_debug ("Failed to copy delta: %s", local_error->message); } } } if (!ostree_repo_commit_transaction (dst_repo, NULL, cancellable, error)) return FALSE; if (opt_update_appstream && !flatpak_repo_generate_appstream (dst_repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, 0, cancellable, error)) return FALSE; if (!opt_no_update_summary && !flatpak_repo_update (dst_repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, cancellable, error)) return FALSE; return TRUE; }
int main (int argc, char **argv) { GtkWidget *window = NULL; GError *error = NULL; GOptionContext *context; char *dir, *description; int result = EXIT_SUCCESS; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); g_thread_init (NULL); gdk_threads_init (); gdk_threads_enter (); context = g_option_context_new (N_("[DIRECTORY]")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); description = g_strdup_printf (_("Report errors (in English, with LC_ALL=C) to <%s>."), PACKAGE_BUGREPORT); g_option_context_set_summary (context, N_("Giggle is a graphical frontend for the git content tracker.")); g_option_context_set_description (context, description); g_free (description); if (!g_option_context_parse (context, &argc, &argv, &error)) { char *basename = g_filename_display_basename (argv[0]); g_printerr ("%s: %s\n", basename, error->message); g_printerr (_("Try `%s --help' for more information.\n"), basename); result = EXIT_FAILURE; g_free (basename); goto end; } gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), ICONDIR); if (g_file_test ("pixmaps", G_FILE_TEST_IS_DIR)) gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), "pixmaps"); if (version) { g_print ("%s %s, " "Copyright (C) 2007-2008 Imendio AB, " "Copyright (C) 2008 Mathias Hasselmann\n", PACKAGE_NAME, PACKAGE_VERSION); goto end; } gtk_window_set_default_icon_name (PACKAGE); g_set_application_name ("Giggle"); window = giggle_window_new (); /* parse GIT_DIR into dir and unset it; if empty use the current_wd */ dir = g_strdup (g_getenv ("GIT_DIR")); if (!dir || !*dir) { g_free (dir); if (argc > 1 && *argv[1]) { dir = g_strdup (argv[1]); } else { dir = g_get_current_dir (); } } g_unsetenv ("GIT_DIR"); if (giggle_git_test_dir (dir)) { giggle_window_set_directory (GIGGLE_WINDOW (window), dir); } else { gtk_widget_show (window); } g_free (dir); /* window will show itself when it reads its initial size configuration */ if (diff_window) giggle_window_show_diff_window (GIGGLE_WINDOW (window)); gtk_main (); end: if (window) gtk_widget_destroy (window); gdk_threads_leave (); return result; }
int main (int argc, char *argv[]) { GError *error_parsearg = NULL; GOptionContext *context; GtkWidget *window, *vbox, *hbox2; GtkAdjustment *sadj, *madj, *hadj; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif gtk_init (&argc, &argv); notify_init ("Gtimer"); ca_context_create (&sound); context = g_option_context_new (_("- a simple countdown timer")); g_option_context_add_main_entries (context, entries, NULL); #ifdef ENABLE_NLS g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); #endif if (!g_option_context_parse (context, &argc, &argv, &error_parsearg)) { g_fprintf (stderr, "%s\n", error_parsearg->message); exit(1); } vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_spacing (GTK_BOX (hbox2), 5); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); timer_display = gtk_label_new (NULL); reset_display(); sadj = gtk_adjustment_new (0, 0, 60, 1, 1, 0); madj = gtk_adjustment_new (0, 0, 60, 1, 1, 0); hadj = gtk_adjustment_new (0, 0, 24, 1, 1, 0); spin_seconds = gtk_spin_button_new (sadj, 1, 0); spin_minutes = gtk_spin_button_new (madj, 1, 0); spin_hours = gtk_spin_button_new (hadj, 1, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_seconds), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_seconds), seconds); g_object_set (spin_seconds, "shadow-type", GTK_SHADOW_IN, NULL); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_minutes), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_minutes), minutes); g_object_set (spin_minutes, "shadow-type", GTK_SHADOW_IN, NULL); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_hours), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_hours), hours); g_object_set (spin_hours, "shadow-type", GTK_SHADOW_IN, NULL); entry = gtk_entry_new(); gtk_entry_set_text (GTK_ENTRY (entry), entry_text); button_timer = gtk_button_new(); gtk_button_set_label (GTK_BUTTON (button_timer), _("Start")); button_reset = gtk_button_new_with_label (_("Reset")); gtk_widget_set_sensitive (button_reset, FALSE); gtk_box_pack_start (GTK_BOX (hbox1), spin_hours, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (hbox1), spin_minutes, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (hbox1), spin_seconds, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (vbox), timer_display, FALSE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox2), button_timer, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox2), button_reset, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (vbox), hbox1); gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, TRUE, 5); gtk_container_add (GTK_CONTAINER (vbox), hbox2); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Gtimer"); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show_all (window); g_timeout_add_seconds (1, (GSourceFunc) timer_function, NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (button_timer, "clicked", G_CALLBACK (on_timer_button_clicked), NULL); g_signal_connect (button_reset, "clicked", G_CALLBACK (on_reset_button_clicked), NULL); gtk_main(); notify_uninit(); ca_context_destroy (sound); g_option_context_free (context); return 0; }
int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; EmpathyAuthFactory *factory; TpDebugSender *debug_sender; TpSimpleClientFactory *tp_factory; TpDBusDaemon *dbus; context = g_option_context_new (N_(" — Empathy authentication client")); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &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-auth-client init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (context); empathy_gtk_init (); gnutls_global_init (); g_set_application_name (_("Empathy authentication client")); /* Make empathy and empathy-auth-client appear as the same app in * gnome-shell */ g_set_prgname ("empathy"); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); /* There is no 'main' UI window so just use the default GdkScreen */ empathy_set_css_provider (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 dbus = tp_dbus_daemon_dup (NULL); tp_factory = tp_simple_client_factory_new (dbus); tp_simple_client_factory_add_account_features_varargs (tp_factory, TP_ACCOUNT_FEATURE_STORAGE, 0); factory = empathy_auth_factory_new (tp_factory); g_object_unref (tp_factory); g_object_unref (dbus); g_signal_connect (factory, "new-server-tls-handler", G_CALLBACK (auth_factory_new_tls_handler_cb), NULL); g_signal_connect (factory, "new-server-sasl-handler", G_CALLBACK (auth_factory_new_sasl_handler_cb), NULL); g_signal_connect (factory, "auth-password-failed", G_CALLBACK (auth_factory_auth_passsword_failed), NULL); if (!empathy_auth_factory_register (factory, &error)) { g_critical ("Failed to register the auth factory: %s\n", error->message); g_error_free (error); g_object_unref (factory); return EXIT_FAILURE; } DEBUG ("Empathy auth client started."); if (g_getenv ("EMPATHY_PERSIST") != NULL) { DEBUG ("Timed-exit disabled"); use_timer = FALSE; } /* Wait for the migration code to be done before starting the timer */ empathy_sanity_checking_run_async (sanity_cb, NULL); gtk_main (); g_object_unref (factory); g_object_unref (debug_sender); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { NMSstpPlugin *plugin; GMainLoop *main_loop; gboolean persist = FALSE; GOptionContext *opt_ctx = NULL; gchar *bus_name = NM_DBUS_SERVICE_SSTP; GOptionEntry options[] = { { "persist", 0, 0, G_OPTION_ARG_NONE, &persist, N_("Don't quit when VPN connection terminates"), NULL }, { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable verbose debug logging (may expose passwords)"), NULL }, { "bus-name", 0, 0, G_OPTION_ARG_STRING, &bus_name, N_("D-Bus name to use for this instance"), NULL }, {NULL} }; #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif /* locale will be set according to environment LC_* variables */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, NM_SSTP_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Parse options */ opt_ctx = g_option_context_new (NULL); g_option_context_set_translation_domain (opt_ctx, GETTEXT_PACKAGE); g_option_context_set_ignore_unknown_options (opt_ctx, FALSE); g_option_context_set_help_enabled (opt_ctx, TRUE); g_option_context_add_main_entries (opt_ctx, options, NULL); g_option_context_set_summary (opt_ctx, _("nm-sstp-service provides integrated SSTP VPN capability (compatible with Microsoft and other implementations) to NetworkManager.")); g_option_context_parse (opt_ctx, &argc, &argv, NULL); g_option_context_free (opt_ctx); if (getenv ("NM_PPP_DEBUG")) debug = TRUE; if (debug) g_message ("nm-sstp-service (version " DIST_VERSION ") starting..."); if (bus_name) setenv ("NM_DBUS_SERVICE_SSTP", bus_name, 0); plugin = nm_sstp_plugin_new (bus_name); if (!plugin) exit (EXIT_FAILURE); main_loop = g_main_loop_new (NULL, FALSE); if (!persist) g_signal_connect (plugin, "quit", G_CALLBACK (quit_mainloop), main_loop); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); g_object_unref (plugin); exit (EXIT_SUCCESS); }
gboolean flatpak_builtin_document_info (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GDBusConnection) session_bus = NULL; const char *file; XdpDbusDocuments *documents; g_autofree char *mountpoint = NULL; g_autofree char *basename = NULL; g_autofree char *doc_id = NULL; g_autofree char *doc_path = NULL; g_autofree char *origin = NULL; const char *app_id; const char **perms; g_autoptr(GVariant) apps = NULL; g_autoptr(GVariantIter) iter = NULL; context = g_option_context_new (_("FILE - Get information about an exported file")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 2) return usage_error (context, _("FILE must be specified"), error); file = argv[1]; basename = g_path_get_basename (file); session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error); if (session_bus == NULL) return FALSE; documents = xdp_dbus_documents_proxy_new_sync (session_bus, 0, "org.freedesktop.portal.Documents", "/org/freedesktop/portal/documents", NULL, error); if (documents == NULL) return FALSE; if (!xdp_dbus_documents_call_get_mount_point_sync (documents, &mountpoint, NULL, error)) return FALSE; if (!xdp_dbus_documents_call_lookup_sync (documents, file, &doc_id, NULL, error)) return FALSE; if (strcmp (doc_id, "") == 0) { g_print (_("Not exported\n")); return TRUE; } doc_path = g_build_filename (mountpoint, doc_id, basename, NULL); if (!xdp_dbus_documents_call_info_sync (documents, doc_id, &origin, &apps, NULL, error)) return FALSE; iter = g_variant_iter_new (apps); g_print ("id: %s\n", doc_id); g_print ("path: %s\n", doc_path); g_print ("origin: %s\n", origin); if (g_variant_iter_n_children (iter) > 0) g_print ("permissions:\n"); while (g_variant_iter_next (iter, "{&s^a&s}", &app_id, &perms)) { int i; g_print ("\t%s\t", app_id); for (i = 0; perms[i]; i++) { if (i > 0) g_print (", "); g_print ("%s", perms[i]); } g_print ("\n"); } return TRUE; }
gint main (gint argc, gchar **argv) { GtkWidget *window; GOptionContext *context; const gchar *filename; EvDocumentModel *model; GError *error = NULL; #ifdef G_OS_WIN32 if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) { /* stdout is fine, presumably redirected to a file or pipe */ } else { typedef BOOL (* WINAPI AttachConsole_t) (DWORD); AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole"); if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) { freopen ("CONOUT$", "w", stdout); dup2 (fileno (stdout), 1); freopen ("CONOUT$", "w", stderr); dup2 (fileno (stderr), 2); } } #endif /* Init glib threads asap */ if (!g_thread_supported ()) g_thread_init (NULL); #ifdef ENABLE_NLS /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("MATE Document Previewer")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_warning ("Error parsing command line arguments: %s", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (!filenames) { g_warning ("File argument is required"); return 1; } filename = filenames[0]; if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_warning ("Filename \"%s\" does not exist or is not a regular file", filename); return 1; } if (!ev_init ()) return 1; ev_stock_icons_init (); g_set_application_name (_("MATE Document Previewer")); gtk_window_set_default_icon_name ("atril"); model = ev_document_model_new (); window = ev_previewer_window_new (model); ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename); ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); ev_previewer_load_document (filename, model); gtk_main (); if (unlink_temp_file) ev_previewer_unlink_tempfile (filename); if (print_settings) ev_previewer_unlink_tempfile (print_settings); ev_shutdown (); ev_stock_icons_shutdown (); g_object_unref (model); return 0; }
static int application_command_line_cb (GApplication *application, GApplicationCommandLine *command_line, GnomeControlCenter *shell) { int argc; char **argv; int retval = 0; GOptionContext *context; GError *error = NULL; verbose = FALSE; show_overview = FALSE; show_help = FALSE; start_panels = NULL; argv = g_application_command_line_get_arguments (command_line, &argc); context = g_option_context_new (N_("- System Settings")); g_option_context_add_main_entries (context, all_options, GETTEXT_PACKAGE); g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_set_help_enabled (context, FALSE); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); g_option_context_free (context); return 1; } if (show_help || show_help_all || show_help_gtk) { gchar *help; GOptionGroup *group; if (show_help || show_help_all) group = NULL; else group = gtk_get_option_group (FALSE); help = g_option_context_get_help (context, FALSE, group); g_print ("%s", help); g_free (help); g_option_context_free (context); return 0; } g_option_context_free (context); cc_shell_log_set_debug (verbose); gnome_control_center_show (shell, GTK_APPLICATION (application)); if (show_overview) { gnome_control_center_set_overview_page (shell); } else if (start_panels != NULL && start_panels[0] != NULL) { const char *start_id; GError *err = NULL; start_id = start_panels[0]; if (start_panels[1]) g_debug ("Extra argument: %s", start_panels[1]); else g_debug ("No extra argument"); if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, (const gchar**)start_panels+1, &err)) { g_warning ("Could not load setting panel \"%s\": %s", start_id, (err) ? err->message : "Unknown error"); retval = 1; if (err) { g_error_free (err); err = NULL; } } } gnome_control_center_present (shell); gdk_notify_startup_complete (); g_strfreev (argv); if (start_panels != NULL) { g_strfreev (start_panels); start_panels = NULL; } show_overview = FALSE; return retval; }
int main (int argc, char **argv) { GConfChangeSet *changeset; GladeXML *dialog; GnomeProgram *program; GOptionContext *context; gboolean apply_only = FALSE; gboolean get_legacy = FALSE; GOptionEntry cap_options[] = { { "apply", 0, 0, G_OPTION_ARG_NONE, &apply_only, N_("Just apply settings and quit (compatibility only; now handled by daemon)"), NULL }, { "init-session-settings", 0, 0, G_OPTION_ARG_NONE, &apply_only, N_("Just apply settings and quit (compatibility only; now handled by daemon)"), NULL }, { "get-legacy", 0, 0, G_OPTION_ARG_NONE, &get_legacy, N_("Retrieve and store legacy settings"), NULL }, { NULL } }; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Since gstreamer and gnome-vfs require threads, we * have to initialise threads here as the first call to glib. */ g_thread_init (NULL); context = g_option_context_new (N_("- GNOME Sound Preferences")); #if GLIB_CHECK_VERSION (2, 12, 0) g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); #endif g_option_context_add_main_entries (context, cap_options, GETTEXT_PACKAGE); g_option_context_add_group (context, gst_init_get_option_group ()); program = gnome_program_init ("gnome-sound-properties", VERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_GOPTION_CONTEXT, context, NULL); activate_settings_daemon (); gconf_client = gconf_client_get_default (); gconf_client_add_dir (gconf_client, "/desktop/gnome/sound", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_add_dir (gconf_client, "/apps/metacity/general", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); if (get_legacy) { get_legacy_settings (); } else { dialog = create_dialog (); if (dialog) { changeset = gconf_change_set_new (); setup_dialog (dialog, changeset); setup_devices (); dialog_win = WID ("sound_prefs_dialog"); g_signal_connect (dialog_win, "response", G_CALLBACK (dialog_response_cb), changeset); g_signal_connect (dialog_win, "destroy", G_CALLBACK (gtk_main_quit), NULL); capplet_set_icon (dialog_win, "gnome-sound-properties"); gtk_widget_show (dialog_win); gtk_main (); gconf_change_set_unref (changeset); g_object_unref (dialog); } } g_object_unref (gconf_client); g_object_unref (program); return 0; }
gint main (gint argc, gchar **argv) { GtkApplication *application; GOptionContext *context; GError *error = NULL; int status = 1; #ifdef G_OS_WIN32 if (fileno (stdout) != -1 && _get_osfhandle (fileno (stdout)) != -1) { /* stdout is fine, presumably redirected to a file or pipe */ } else { typedef BOOL (* WINAPI AttachConsole_t) (DWORD); AttachConsole_t p_AttachConsole = (AttachConsole_t) GetProcAddress (GetModuleHandle ("kernel32.dll"), "AttachConsole"); if (p_AttachConsole != NULL && p_AttachConsole (ATTACH_PARENT_PROCESS)) { freopen ("CONOUT$", "w", stdout); dup2 (fileno (stdout), 1); freopen ("CONOUT$", "w", stderr); dup2 (fileno (stderr), 2); } } #endif #ifdef ENABLE_NLS /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("GNOME Document Previewer")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Error parsing command line arguments: %s\n", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (argc < 2) { g_printerr ("File argument is required\n"); return 1; } else if (argc > 2) { g_printerr ("Too many files\n"); return 1; } if (!g_file_test (argv[1], G_FILE_TEST_IS_REGULAR)) { g_printerr ("Filename \"%s\" does not exist or is not a regular file\n", argv[1]); return 1; } if (!ev_init ()) return 1; ev_stock_icons_init (); g_set_application_name (_("GNOME Document Previewer")); gtk_window_set_default_icon_name ("evince"); application = gtk_application_new (NULL, G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_OPEN); g_signal_connect (application, "activate", G_CALLBACK (activate_cb), NULL); g_signal_connect (application, "open", G_CALLBACK (open_cb), NULL); status = g_application_run (G_APPLICATION (application), argc, argv); if (unlink_temp_file) ev_previewer_unlink_tempfile (argv[1]); if (print_settings) ev_previewer_unlink_tempfile (print_settings); ev_shutdown (); ev_stock_icons_shutdown (); return status; }
gint main (gint argc, gchar **argv) { GtkWidget *window; GOptionContext *context; const gchar *filename; EvDocumentModel *model; GError *error = NULL; #ifdef ENABLE_NLS /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("MATE Document Previewer")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_warning ("Error parsing command line arguments: %s", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (!filenames) { g_warning ("File argument is required"); return 1; } filename = filenames[0]; if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_warning ("Filename \"%s\" does not exist or is not a regular file", filename); return 1; } if (!ev_init ()) return 1; ev_stock_icons_init (); g_set_application_name (_("MATE Document Previewer")); gtk_window_set_default_icon_name ("xreader"); model = ev_document_model_new (); window = ev_previewer_window_new (model); ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename); ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); ev_previewer_load_document (filename, model); gtk_main (); if (unlink_temp_file) ev_previewer_unlink_tempfile (filename); if (print_settings) ev_previewer_unlink_tempfile (print_settings); ev_shutdown (); ev_stock_icons_shutdown (); g_object_unref (model); return 0; }
static gboolean local_cmdline (GApplication *app, gchar ***arguments, gint *exit_status) { gint i; gchar **argv; gint argc = 0; gboolean retval = TRUE; GError *error = NULL; GOptionContext *optcontext; GOptionEntry options[] = { { "hidden", 'h', 0, G_OPTION_ARG_NONE, &hidden, N_("Don't display any dialogs; do any work (eg, importing) and exit"), NULL }, { "if-needed", 'n', 0, G_OPTION_ARG_NONE, &only_if_needed, N_("Don't display any dialogs unless there are only \"People Nearby\" accounts"), NULL }, { "select-account", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name, N_("Initially select given account (eg, " "gabble/jabber/foo_40example_2eorg0)"), N_("<account-id>") }, { NULL } }; optcontext = g_option_context_new (N_("- Empathy Accounts")); g_option_context_add_group (optcontext, gtk_get_option_group (FALSE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE); argv = *arguments; for (i = 0; argv[i] != NULL; i++) argc++; 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 init: %s", error->message); g_clear_error (&error); *exit_status = EXIT_FAILURE; } else { if (g_application_register (app, NULL, &error)) { g_application_activate (app); } else { g_warning ("Impossible to register empathy-application: %s", error->message); g_clear_error (&error); *exit_status = EXIT_FAILURE; } } g_option_context_free (optcontext); return retval; }