| 183 | } |
| 184 | |
| 185 | void MainWindow::disableCurrentDevice() { |
| 186 | auto idx = m_tree->currentIndex(); |
| 187 | if (!idx.isValid()) return; |
| 188 | QString name = m_model->deviceField(idx, "name").toString(); |
| 189 | if (name.isEmpty()) return; |
| 190 | |
| 191 | QString location = m_model->deviceField(idx, "location").toString(); |
| 192 | QString btAddress = m_model->deviceField(idx, "btAddress").toString(); |
| 193 | if (btAddress.isEmpty()) |
| 194 | btAddress = m_model->deviceField(idx, "rawLocation").toString(); |
| 195 | if (location == "connected via Bluetooth") { |
| 196 | static const QRegularExpression kMacRe( |
| 197 | "^[0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){5}$"); |
| 198 | if (!kMacRe.match(btAddress).hasMatch()) { |
| 199 | QMessageBox::warning(this, "Disconnect failed", |
| 200 | "Invalid device address."); |
| 201 | return; |
| 202 | } |
| 203 | if (QMessageBox::question(this, "Disconnect device", |
| 204 | QString("This will disconnect %1.\n\nContinue?") |
| 205 | .arg(name.toHtmlEscaped())) |
| 206 | != QMessageBox::Yes) |
| 207 | return; |
| 208 | |
| 209 | QProcess proc; |
| 210 | proc.start("bluetoothctl", {"disconnect", btAddress}); |
| 211 | bool ok = proc.waitForFinished(5000); |
| 212 | QString out = QString::fromUtf8(proc.readAllStandardOutput()).trimmed(); |
| 213 | if (!ok || (!out.contains("Successful", Qt::CaseInsensitive) |
| 214 | && proc.exitCode() != 0)) { |
| 215 | QString err = QString::fromUtf8( |
| 216 | proc.readAllStandardError()).trimmed(); |
| 217 | QMessageBox::warning(this, "Disconnect failed", |
| 218 | QString("Could not disconnect %1:\n\n%2") |
| 219 | .arg(name.toHtmlEscaped(), |
| 220 | (err.isEmpty() ? out : err).toHtmlEscaped())); |
| 221 | return; |
| 222 | } |
| 223 | refresh(); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | QString driver = m_model->deviceField(idx, "driver").toString(); |
| 228 | if (driver.isEmpty()) return; |
| 229 | |
| 230 | bool disabled = m_model->deviceField(idx, "disabled").toBool(); |
| 231 | QString action = disabled ? "enable" : "disable"; |
| 232 | |
| 233 | if (QMessageBox::question(this, |
| 234 | QString("%1 device").arg(disabled ? "Enable" : "Disable"), |
| 235 | QString("This will %1 %2.\n\nContinue?").arg(action, name.toHtmlEscaped())) |
| 236 | != QMessageBox::Yes) |
| 237 | return; |
| 238 | |
| 239 | if (!setModuleBlacklisted(driver, !disabled, this)) |
| 240 | return; |
| 241 | |
| 242 | QMessageBox::information(this, "Done", |
nothing calls this directly
no test coverage detected