gint main (gint argc, gchar **argv) { GError *error = NULL; GtkWidget *dialog; GtkWidget *button; gint result; gint retval = EXIT_SUCCESS; gint default_response = GTK_RESPONSE_CANCEL; XfconfChannel *channel; gint configver; gchar *filename_46; gchar *filename_default; gboolean migrate_vendor_default; /* set translation domain */ lde_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); #ifndef NDEBUG /* terminate the program on warnings and critical messages */ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif gtk_init (&argc, &argv); if (!xfconf_init (&error)) { g_critical ("Failed to initialize Xfconf: %s", error->message); g_error_free (error); return EXIT_FAILURE; } channel = xfconf_channel_get (LDE_PANEL_CHANNEL_NAME); if (!xfconf_channel_has_property (channel, "/panels")) { /* lookup the old 4.6 config file */ filename_46 = lde_resource_lookup (LDE_RESOURCE_CONFIG, LDE_46_CONFIG); /* lookup the default configuration */ lde_resource_push_path (LDE_RESOURCE_CONFIG, XDGCONFIGDIR); filename_default = lde_resource_lookup (LDE_RESOURCE_CONFIG, DEFAULT_CONFIG_FILENAME); lde_resource_pop_path (LDE_RESOURCE_CONFIG); if (filename_46 == NULL && filename_default == NULL) { g_warning ("No default or old configuration found"); return EXIT_FAILURE; } /* if the default configuration does not match with the file found * by the resource lookup, migrate it without asking */ migrate_vendor_default = (g_strcmp0 (DEFAULT_CONFIG_PATH, filename_default) != 0); /* check if we auto-migrate the default configuration */ if (g_getenv ("LDE_PANEL_MIGRATE_DEFAULT") != NULL || migrate_vendor_default) { if (filename_46 != NULL) g_message ("Tried to auto-migrate, but old configuration found"); else if (filename_default == NULL) g_message ("Tried to auto-migrate, but no default configuration found"); else goto migrate_default; } /* create question dialog */ dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Welcome to the first start of the panel")); gtk_window_set_title (GTK_WINDOW (dialog), _("Panel")); gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PREFERENCES); gtk_window_stick (GTK_WINDOW (dialog)); gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE); if (filename_46 != NULL) { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s", _("Because the panel moved to a new system for storing the " "settings, it has to load a fresh initial configuration."), _("Choose below which setup you want for the first startup.")); button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Migrate old config"), GTK_RESPONSE_OK); gtk_widget_set_tooltip_text (button, _("Migrate the old 4.6 configuration to Xfconf")); default_response = GTK_RESPONSE_OK; } else { gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("Choose below which setup you want for the first startup.")); } if (filename_default != NULL) { button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Use default config"), GTK_RESPONSE_YES); gtk_widget_set_tooltip_text (button, _("Load the default configuration")); if (default_response == GTK_RESPONSE_CANCEL) default_response = GTK_RESPONSE_YES; } button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("One empty panel"), GTK_RESPONSE_CANCEL); gtk_widget_set_tooltip_text (button, _("Start with one empty panel")); gtk_dialog_set_default_response (GTK_DIALOG (dialog), default_response); result = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (result == GTK_RESPONSE_OK && filename_46 != NULL) { /* restore 4.6 config */ if (!migrate_46 (filename_46, channel, &error)) { lde_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration")); g_error_free (error); retval = EXIT_FAILURE; } } else if (result == GTK_RESPONSE_YES && filename_default != NULL) { migrate_default: /* apply default config */ if (!migrate_default (filename_default, &error)) { lde_dialog_show_error (NULL, error, _("Failed to load the default configuration")); g_error_free (error); retval = EXIT_FAILURE; } } g_free (filename_46); g_free (filename_default); } configver = xfconf_channel_get_int (channel, "/configver", -1); if (configver < LDE4_PANEL_CONFIG_VERSION) { g_message (_("Panel config needs migration...")); if (!migrate_config (channel, configver, &error)) { lde_dialog_show_error (NULL, error, _("Failed to migrate the existing configuration")); g_error_free (error); retval = EXIT_FAILURE; } else { g_message (_("Panel configuration has been updated.")); } /* migration complete, set new version */ xfconf_channel_set_int (channel, "/configver", LDE4_PANEL_CONFIG_VERSION); } xfconf_shutdown (); return retval; }
static void app_startup_handler(GApplication *app, gpointer data) { gmpv_handle *ctx = data; const gchar *vid_area_style = ".gmpv-vid-area{background-color: black}"; GSettingsBackend *config_backend; GtkCssProvider *style_provider; gboolean css_loaded; gboolean use_opengl; gboolean config_migrated; gboolean mpvinput_enable; gboolean csd_enable; gboolean dark_theme_enable; gchar *config_file; gchar *mpvinput; setlocale(LC_NUMERIC, "C"); g_set_application_name(_("GNOME MPV")); gtk_window_set_default_icon_name(ICON_NAME); bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); config_file = get_config_file_path(); config_backend = g_keyfile_settings_backend_new ( config_file, CONFIG_ROOT_PATH, CONFIG_ROOT_GROUP ); use_opengl = get_use_opengl(); ctx->mpv_ctx = mpv_create(); ctx->files = NULL; ctx->opengl_ctx = NULL; ctx->opengl_ready = FALSE; ctx->paused = TRUE; ctx->loaded = FALSE; ctx->new_file = TRUE; ctx->sub_visible = TRUE; ctx->init_load = TRUE; ctx->playlist_move_dest = -1; ctx->log_level_list = NULL; ctx->keybind_list = NULL; ctx->config = g_settings_new_with_backend(APP_ID, config_backend); ctx->app = GTK_APPLICATION(app); ctx->gui = MAIN_WINDOW(main_window_new(ctx->app, use_opengl)); ctx->fs_control = NULL; ctx->playlist_store = PLAYLIST_WIDGET(ctx->gui->playlist)->list_store; config_migrated = migrate_config(ctx); style_provider = gtk_css_provider_new(); css_loaded = gtk_css_provider_load_from_data (style_provider, vid_area_style, -1, NULL); if(!css_loaded) { g_warning ("Failed to apply background color css"); } gtk_style_context_add_provider_for_screen ( gtk_window_get_screen(GTK_WINDOW(ctx->gui)), GTK_STYLE_PROVIDER(style_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION ); g_object_unref(style_provider); csd_enable = g_settings_get_boolean (ctx->config, "csd-enable"); dark_theme_enable = g_settings_get_boolean (ctx->config, "dark-theme-enable"); mpvinput_enable = g_settings_get_boolean (ctx->config, "mpv-input-config-enable"); mpvinput = g_settings_get_string (ctx->config, "mpv-input-config-file"); if(csd_enable) { gtk_application_set_app_menu (ctx->app, G_MENU_MODEL(build_app_menu())); main_window_enable_csd(ctx->gui); } else { gtk_application_set_app_menu (ctx->app, NULL); gtk_application_set_menubar (ctx->app, G_MENU_MODEL(build_full_menu())); } gtk_widget_show_all(GTK_WIDGET(ctx->gui)); if(csd_enable) { control_box_set_fullscreen_btn_visible (CONTROL_BOX(ctx->gui->control_box), FALSE); } control_box_set_chapter_enabled (CONTROL_BOX(ctx->gui->control_box), FALSE); if(!main_window_get_use_opengl(ctx->gui)) { ctx->vid_area_wid = get_xid(ctx->gui->vid_area); } g_assert( main_window_get_use_opengl(ctx->gui) || ctx->vid_area_wid != -1 ); main_window_load_state(ctx->gui); setup_accelerators(ctx); setup_dnd_targets(ctx); actionctl_map_actions(ctx); connect_signals(ctx); load_keybind(ctx, mpvinput_enable?mpvinput:NULL, FALSE); mpris_init(ctx); media_keys_init(ctx); g_object_set( ctx->gui->settings, "gtk-application-prefer-dark-theme", dark_theme_enable, NULL ); g_timeout_add( SEEK_BAR_UPDATE_INTERVAL, (GSourceFunc)update_seek_bar, ctx ); if(config_migrated) { GtkWidget *dialog = gtk_message_dialog_new ( GTK_WINDOW(ctx->gui), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("Your configuration file has been " "moved to the new location at %s."), config_file ); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } g_free(config_file); g_free(mpvinput); }