| 306 | ******************************************************************************/ |
| 307 | |
| 308 | static int openWorkspace(FilePath& path) { |
| 309 | // Run initialize workspace wizard as many times as needed until a valid |
| 310 | // workspace is selected. |
| 311 | Q_ASSERT(sTheme); |
| 312 | std::unique_ptr<InitializeWorkspaceWizard> wizard( |
| 313 | new InitializeWorkspaceWizard(*sTheme, false)); |
| 314 | wizard->setWorkspacePath(path); // can throw |
| 315 | while (wizard->getNeedsToBeShown()) { |
| 316 | if (wizard->exec() != QDialog::Accepted) { |
| 317 | throw UserCanceled(__FILE__, __LINE__); |
| 318 | } |
| 319 | Workspace::setMostRecentlyUsedWorkspacePath(wizard->getWorkspacePath()); |
| 320 | |
| 321 | // Just to be on the safe side that the workspace is now *really* ready |
| 322 | // to open (created, upgraded, initialized, ...), check the status again |
| 323 | // before continue opening the workspace. |
| 324 | wizard->setWorkspacePath(wizard->getWorkspacePath()); // can throw |
| 325 | wizard->restart(); |
| 326 | } |
| 327 | |
| 328 | // Open the workspace (can throw). If it is locked, a dialog will show |
| 329 | // an error and possibly provides an option to override the lock. |
| 330 | Workspace ws(wizard->getWorkspacePath(), wizard->getDataDir(), |
| 331 | DirectoryLockHandlerDialog::createDirectoryLockCallback()); |
| 332 | |
| 333 | // We don't need the wizard anymore (and it disturbes the Funq tests). |
| 334 | const bool wsContainsNewerFileFormats = |
| 335 | wizard->getWorkspaceContainsNewerFileFormats(); |
| 336 | wizard.reset(); |
| 337 | |
| 338 | // Apply UI theme from workspace settings. |
| 339 | auto applyUiTheme = [&]() { setTheme(ws.getSettings().uiTheme.get()); }; |
| 340 | applyUiTheme(); |
| 341 | QObject::connect(&ws.getSettings().uiTheme, &WorkspaceSettingsItem::edited, |
| 342 | &ws.getSettings().uiTheme, applyUiTheme); |
| 343 | |
| 344 | // Now since workspace settings are loaded, switch to the language defined |
| 345 | // there (until now, the system language was used). |
| 346 | // Note: Until LibrePCB 2.0.1 we also set QLocale::setDefault(locale), but |
| 347 | // this is probably wrong as the setting is intended to change only the |
| 348 | // language, not the locale. Most translation locales have no country set |
| 349 | // anyway (e.g. only "de", not "de_CH"), so we don't know the user's country. |
| 350 | auto applyApplicationLocale = [&ws]() { |
| 351 | const QString name = ws.getSettings().applicationLocale.get(); |
| 352 | const QLocale locale = name.isEmpty() ? QLocale::system() : QLocale(name); |
| 353 | Application::setTranslationLocale(locale); |
| 354 | EditorCommandSet::instance().updateTranslations(); |
| 355 | slint::update_all_translations(); |
| 356 | }; |
| 357 | applyApplicationLocale(); |
| 358 | QObject::connect(&ws.getSettings().applicationLocale, |
| 359 | &WorkspaceSettingsItem::edited, |
| 360 | &ws.getSettings().applicationLocale, applyApplicationLocale); |
| 361 | |
| 362 | // Setup global parts information provider (with cache). |
| 363 | PartInformationProvider::instance().setCacheDir(Application::getCacheDir()); |
| 364 | auto applyPartInformationProviderSettings = [&ws]() { |
| 365 | const auto ep = ws.getSettings().getApiEndpointForPartsInfo(); |
no test coverage detected