Changeset View
Standalone View
src/kcmodule/devices/devices.cpp
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 172 | { | |||
---|---|---|---|---|---|
182 | const int size = IconSize(KIconLoader::Dialog); | 182 | const int size = IconSize(KIconLoader::Dialog); | ||
183 | m_ui->deviceList->setIconSize(QSize(size, size)); | 183 | m_ui->deviceList->setIconSize(QSize(size, size)); | ||
184 | 184 | | |||
185 | m_devicesModel = new BluezQt::DevicesModel(m_manager, this); | 185 | m_devicesModel = new BluezQt::DevicesModel(m_manager, this); | ||
186 | m_proxyModel = new DevicesProxyModel(this); | 186 | m_proxyModel = new DevicesProxyModel(this); | ||
187 | m_proxyModel->setSourceModel(m_devicesModel); | 187 | m_proxyModel->setSourceModel(m_devicesModel); | ||
188 | m_ui->deviceList->setModel(m_proxyModel); | 188 | m_ui->deviceList->setModel(m_proxyModel); | ||
189 | 189 | | |||
190 | m_ui->deviceList->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||||
191 | | ||||
190 | if (m_manager->devices().isEmpty()) { | 192 | if (m_manager->devices().isEmpty()) { | ||
191 | showNoDevicesMessage(); | 193 | showNoDevicesMessage(); | ||
192 | m_ui->deviceListWidget->hide(); | 194 | m_ui->deviceListWidget->hide(); | ||
193 | } | 195 | } | ||
194 | 196 | | |||
195 | bluetoothOperationalChanged(m_manager->isBluetoothOperational()); | 197 | bluetoothOperationalChanged(m_manager->isBluetoothOperational()); | ||
196 | connect(m_manager, &BluezQt::Manager::bluetoothOperationalChanged, this, &KCMBlueDevilDevices::bluetoothOperationalChanged); | 198 | connect(m_manager, &BluezQt::Manager::bluetoothOperationalChanged, this, &KCMBlueDevilDevices::bluetoothOperationalChanged); | ||
197 | connect(m_manager, &BluezQt::Manager::deviceAdded, this, &KCMBlueDevilDevices::deviceAdded); | 199 | connect(m_manager, &BluezQt::Manager::deviceAdded, this, &KCMBlueDevilDevices::deviceAdded); | ||
198 | connect(m_manager, &BluezQt::Manager::deviceRemoved, this, &KCMBlueDevilDevices::deviceRemoved); | 200 | connect(m_manager, &BluezQt::Manager::deviceRemoved, this, &KCMBlueDevilDevices::deviceRemoved); | ||
199 | connect(m_ui->deviceList->selectionModel(), &QItemSelectionModel::currentChanged, this, &KCMBlueDevilDevices::currentChanged); | 201 | connect(m_ui->deviceList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &KCMBlueDevilDevices::selectionChanged); | ||
200 | } | 202 | } | ||
201 | 203 | | |||
202 | void KCMBlueDevilDevices::addDevice() | 204 | void KCMBlueDevilDevices::addDevice() | ||
203 | { | 205 | { | ||
204 | QProcess::startDetached(QStringLiteral("bluedevil-wizard")); | 206 | QProcess::startDetached(QStringLiteral("bluedevil-wizard")); | ||
205 | } | 207 | } | ||
206 | 208 | | |||
207 | void KCMBlueDevilDevices::removeDevice() | 209 | void KCMBlueDevilDevices::removeDevice() | ||
208 | { | 210 | { | ||
211 | if (multipleDevicesSelected()) { | ||||
212 | removeDevices(); | ||||
213 | } else { | ||||
214 | removeCurrentDevice(); | ||||
215 | } | ||||
216 | } | ||||
217 | | ||||
218 | void KCMBlueDevilDevices::removeCurrentDevice() | ||||
ngraham: You could rename this function to `removeSelectedDevices()` and handle both single and multi… | |||||
Done, looks cleaner now - there's still an if-statement for different dialog messages but less duplication overall. umanovskis: Done, looks cleaner now - there's still an if-statement for different dialog messages but less… | |||||
219 | { | ||||
209 | BluezQt::DevicePtr device = currentDevice(); | 220 | BluezQt::DevicePtr device = currentDevice(); | ||
210 | if (!device) { | 221 | if (!device) { | ||
211 | return; | 222 | return; | ||
212 | } | 223 | } | ||
213 | 224 | | |||
214 | if (KMessageBox::questionYesNo(this, i18n("Are you sure that you want to remove device \"%1\" from the list of known devices?", device->friendlyName()), | 225 | if (KMessageBox::questionYesNo(this, i18n("Are you sure that you want to remove device \"%1\" from the list of known devices?", device->friendlyName()), | ||
215 | i18nc("Title of window that asks for confirmation when removing a device", "Device removal")) == KMessageBox::Yes) { | 226 | i18nc("Title of window that asks for confirmation when removing a device", "Device removal")) == KMessageBox::Yes) { | ||
216 | device->adapter()->removeDevice(device); | 227 | device->adapter()->removeDevice(device); | ||
217 | } | 228 | } | ||
218 | } | 229 | } | ||
219 | 230 | | |||
220 | void KCMBlueDevilDevices::currentChanged() | 231 | void KCMBlueDevilDevices::removeDevices() | ||
232 | { | ||||
233 | const QModelIndexList indexes = m_ui->deviceList->selectionModel()->selectedIndexes(); | ||||
234 | if (KMessageBox::questionYesNo(this, i18n("Are you sure that you want to remove %1 devices from the list of known devices?", indexes.size()), | ||||
235 | i18nc("Title of window that asks for confirmation when removing a device", "Device removal")) == KMessageBox::Yes) { | ||||
Need to override the button titles so they say "Remove" and "Cancel". "Yes" and "No" are never acceptable dialog button text. Also, are you sure this needs a confirmation dialog at all? These are usually seen by the user as very annoying. If you feel like there should be more safety here, consider adding an Undo feature instead, and exposing it with a KMessageWidget/Kirigami.InlineMessage with an Undo button that appears somewhere in the UI after the items are removed. ngraham: Need to override the button titles so they say "Remove" and "Cancel". "Yes" and "No" are never… | |||||
This is my first time touching any Qt or KDE code so I apologize if my questions seem obvious. I assume that the confirmation dialog, or undo feature, should act in the same way for removing one and multiple devices. Would I then modify the old function on the same commit here, or a different one? How would I go about adding Undo? I don't see anything like an existing command stack - would converting the remove command to a QAction be the way, or is there some other convention? umanovskis: This is my first time touching any Qt or KDE code so I apologize if my questions seem obvious. | |||||
236 | for (QModelIndex index : indexes) { | ||||
237 | BluezQt::DevicePtr device = m_devicesModel->device(m_proxyModel->mapToSource(index)); | ||||
238 | if (device) { | ||||
239 | device->adapter()->removeDevice(device); | ||||
240 | } | ||||
241 | } | ||||
242 | } | ||||
243 | } | ||||
244 | | ||||
245 | void KCMBlueDevilDevices::selectionChanged() | ||||
221 | { | 246 | { | ||
222 | if (currentDevice()) { | 247 | if (multipleDevicesSelected()) { | ||
248 | showConfigureMessage(); | ||||
249 | m_ui->removeButton->setEnabled(true); | ||||
250 | } | ||||
251 | else if (currentDevice()) { | ||||
223 | showDeviceDetails(); | 252 | showDeviceDetails(); | ||
224 | m_ui->removeButton->setEnabled(true); | 253 | m_ui->removeButton->setEnabled(true); | ||
225 | } else { | 254 | } else { | ||
226 | showConfigureMessage(); | 255 | showConfigureMessage(); | ||
227 | m_ui->removeButton->setEnabled(false); | 256 | m_ui->removeButton->setEnabled(false); | ||
228 | } | 257 | } | ||
229 | 258 | | |||
230 | Q_EMIT changed(false); | 259 | Q_EMIT changed(false); | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 309 | { | |||
300 | m_contentLayout->setCurrentWidget(widget); | 329 | m_contentLayout->setCurrentWidget(widget); | ||
301 | } | 330 | } | ||
302 | 331 | | |||
303 | bool KCMBlueDevilDevices::showingDeviceDetails() const | 332 | bool KCMBlueDevilDevices::showingDeviceDetails() const | ||
304 | { | 333 | { | ||
305 | return m_contentLayout->currentWidget() == m_deviceDetails; | 334 | return m_contentLayout->currentWidget() == m_deviceDetails; | ||
306 | } | 335 | } | ||
307 | 336 | | |||
337 | bool KCMBlueDevilDevices::multipleDevicesSelected() const | ||||
338 | { | ||||
339 | return m_ui->deviceList->selectionModel()->selectedIndexes().size() > 1; | ||||
340 | } | ||||
341 | | ||||
308 | BluezQt::DevicePtr KCMBlueDevilDevices::currentDevice() const | 342 | BluezQt::DevicePtr KCMBlueDevilDevices::currentDevice() const | ||
309 | { | 343 | { | ||
310 | const QModelIndex index = m_proxyModel->mapToSource(m_ui->deviceList->currentIndex()); | 344 | const QModelIndex index = m_proxyModel->mapToSource(m_ui->deviceList->currentIndex()); | ||
311 | return m_devicesModel->device(index); | 345 | return m_devicesModel->device(index); | ||
312 | } | 346 | } | ||
313 | 347 | | |||
314 | #include "devices.moc" | 348 | #include "devices.moc" |
You could rename this function to removeSelectedDevices() and handle both single and multi-selection behaviors in it.