| 436 | } |
| 437 | |
| 438 | void DeviceImpl::connectDev() |
| 439 | { |
| 440 | m_state = DEV_CONNECTING; |
| 441 | DebugTimer pluginConnBm; |
| 442 | DebugTimer connectDevBm; |
| 443 | ConnectionLoadingBar *connectionLoadingBar = new ConnectionLoadingBar(); |
| 444 | connectionLoadingBar->setProgressBarMaximum(m_plugins.size()); |
| 445 | StatusBarManager::pushUrgentWidget(connectionLoadingBar, "Connection Loading Bar"); |
| 446 | connectDevBm.startTimer(); |
| 447 | Preferences *pref = Preferences::GetInstance(); |
| 448 | bool disconnectDevice = false; |
| 449 | connbtn->hide(); |
| 450 | discbtn->show(); |
| 451 | discbtn->setEnabled(false); |
| 452 | m_icon->setFocus(); // temporarily set focus somewhere else |
| 453 | |
| 454 | // the device will always signal connecting->connected->disconnecting->disconnected |
| 455 | // connection process started |
| 456 | Q_EMIT connecting(); |
| 457 | QCoreApplication::processEvents(); |
| 458 | for(int i = 0; i < m_plugins.size(); ++i) { |
| 459 | pluginConnBm.startTimer(); |
| 460 | connectionLoadingBar->setCurrentPlugin(m_plugins[i]->name()); |
| 461 | QCoreApplication::processEvents(); |
| 462 | bool pluginConnectionSucceeded = m_plugins[i]->onConnect(); |
| 463 | DEBUGTIMER_LOG(pluginConnBm, m_plugins[i]->name() + " connection took:"); |
| 464 | connectionLoadingBar->addProgress(1); // TODO: might change to better reflect the time |
| 465 | QCoreApplication::processEvents(); |
| 466 | if(pluginConnectionSucceeded) { |
| 467 | if(pref->get("general_save_session").toBool()) { |
| 468 | QSettings s = QSettings(scopy::config::settingsFolderPath() + "/" + |
| 469 | m_plugins[i]->name() + ".ini", |
| 470 | QSettings::IniFormat); |
| 471 | m_plugins[i]->loadSettings(s); |
| 472 | } |
| 473 | m_connectedPlugins.push_back(m_plugins[i]); |
| 474 | setPingPlugin(m_plugins[i]); |
| 475 | } else { |
| 476 | QJsonValue obj = m_plugins[i]->metadata().value("disconnectDevOnConnectFailure"); |
| 477 | if(obj != QJsonValue::Undefined) { |
| 478 | disconnectDevice = obj.toBool(); |
| 479 | } else { |
| 480 | qWarning(CAT_DEVICEIMPL) << "Undefined json value"; |
| 481 | } |
| 482 | |
| 483 | if(disconnectDevice) { |
| 484 | break; |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | if(disconnectDevice || m_connectedPlugins.isEmpty()) { |
| 490 | // connectionFailed will trigger deviceDisconnect on a queued connection |
| 491 | Q_EMIT connectionFailed(); |
| 492 | } else { |
| 493 | discbtn->setEnabled(true); |
| 494 | discbtn->setFocus(); |
| 495 | bindPing(); |
no test coverage detected