/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jon Evans * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include #include #include #include extern const char* traceSettings; ///! Update the schema version whenever a migration is required const int commonSchemaVersion = 0; COMMON_SETTINGS::COMMON_SETTINGS() : JSON_SETTINGS( "kicad_common", SETTINGS_LOC::USER, commonSchemaVersion ), m_Appearance(), m_Env(), m_Input(), m_Graphics(), m_System() { // This only effect the first time KiCad is run. The user's setting will be used for all // subsequent runs. Menu icons are off by default on OSX and on for all other platforms. #if defined( __WXMAC__ ) bool defaultUseIconsInMenus = false; #else bool defaultUseIconsInMenus = true; #endif m_params.emplace_back( new PARAM( "appearance.canvas_scale", &m_Appearance.canvas_scale, 1.0 ) ); m_params.emplace_back( new PARAM( "appearance.icon_scale", &m_Appearance.icon_scale, 0 ) ); m_params.emplace_back( new PARAM( "appearance.use_icons_in_menus", &m_Appearance.use_icons_in_menus, defaultUseIconsInMenus ) ); m_params.emplace_back( new PARAM( "environment.show_warning_dialog", &m_Env.show_warning_dialog, false ) ); m_params.emplace_back( new PARAM_MAP( "environment.vars", &m_Env.vars, {} ) ); m_params.emplace_back( new PARAM( "input.auto_pan", &m_Input.auto_pan, false ) ); m_params.emplace_back( new PARAM( "input.center_on_zoom", &m_Input.center_on_zoom, true ) ); m_params.emplace_back( new PARAM( "input.immediate_actions", &m_Input.immediate_actions, true ) ); m_params.emplace_back( new PARAM( "input.mousewheel_pan", &m_Input.mousewheel_pan, false ) ); m_params.emplace_back( new PARAM( "input.prefer_select_to_drag", &m_Input.prefer_select_to_drag, true ) ); m_params.emplace_back( new PARAM( "input.warp_mouse_on_move", &m_Input.warp_mouse_on_move, true ) ); m_params.emplace_back( new PARAM( "graphics.opengl_antialiasing_mode", &m_Graphics.opengl_aa_mode, 0, 0, 4 ) ); m_params.emplace_back( new PARAM( "graphics.cairo_antialiasing_mode", &m_Graphics.cairo_aa_mode, 0, 0, 3 ) ); m_params.emplace_back( new PARAM( "system.autosave_interval", &m_System.autosave_interval, 600 ) ); m_params.emplace_back( new PARAM( "system.editor_name", &m_System.editor_name, "" ) ); m_params.emplace_back( new PARAM( "system.file_history_size", &m_System.file_history_size, 9 ) ); m_params.emplace_back( new PARAM( "system.language", &m_System.language, "Default" ) ); m_params.emplace_back( new PARAM( "system.pdf_viewer_name", &m_System.pdf_viewer_name, "" ) ); m_params.emplace_back( new PARAM( "system.use_system_pdf_viewer", &m_System.use_system_pdf_viewer, true ) ); m_params.emplace_back( new PARAM( "system.working_dir", &m_System.working_dir, "" ) ); } bool COMMON_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg ) { bool ret = true; ret &= fromLegacy( aCfg, "CanvasScale", "appearance.canvas_scale" ); ret &= fromLegacy( aCfg, "IconScale", "appearance.icon_scale" ); ret &= fromLegacy( aCfg, "UseIconsInMenus", "appearance.use_icons_in_menus" ); ret &= fromLegacy( aCfg, "ShowEnvVarWarningDialog", "environment.show_warning_dialog" ); auto load_env_vars = [&] () { wxString key, value; long index = 0; nlohmann::json::json_pointer ptr = PointerFromString( "environment.vars" ); aCfg->SetPath( "EnvironmentVariables" ); ( *this )[ptr] = nlohmann::json( {} ); while( aCfg->GetNextEntry( key, index ) ) { value = aCfg->Read( key, wxEmptyString ); if( !value.IsEmpty() ) { ptr.push_back( key.ToStdString() ); wxLogTrace( traceSettings, "Migrate Env: %s=%s", ptr.to_string(), value ); ( *this )[ptr] = value.ToUTF8(); ptr.pop_back(); } } aCfg->SetPath( ".." ); }; load_env_vars(); ret &= fromLegacy( aCfg, "AutoPAN", "input.auto_pan" ); ret &= fromLegacy( aCfg, "ImmediateActions", "input.immediate_actions" ); ret &= fromLegacy( aCfg, "MousewheelPAN", "input.mousewheel_pan" ); ret &= fromLegacy( aCfg, "PreferSelectionToDragging", "input.prefer_select_to_drag" ); ret &= fromLegacy( aCfg, "MoveWarpsCursor", "input.warp_mouse_on_move" ); ret &= fromLegacy( aCfg, "ZoomNoCenter", "input.center_on_zoom" ); // This was stored inverted in legacy config if( ret ) { auto p = PointerFromString( "input.center_on_zoom" ); ( *this )[p] = !( *this )[p]; } ret &= fromLegacy( aCfg, "OpenGLAntialiasingMode", "graphics.opengl_antialiasing_mode" ); ret &= fromLegacy( aCfg, "CairoAntialiasingMode", "graphics.cairo_antialiasing_mode" ); ret &= fromLegacy( aCfg, "AutoSaveInterval", "system.autosave_interval" ); ret &= fromLegacyString( aCfg, "Editor", "system.editor_name" ); ret &= fromLegacy( aCfg, "FileHistorySize", "system.file_history_size" ); ret &= fromLegacyString( aCfg, "LanguageID", "system.language" ); ret &= fromLegacyString( aCfg, "PdfBrowserName", "system.pdf_viewer_name" ); ret &= fromLegacy( aCfg, "UseSystemBrowser", "system.use_system_pdf_viewer" ); ret &= fromLegacyString( aCfg, "WorkingDir", "system.working_dir" ); return ret; }