Commit 07b4f3fb authored by Méven Car's avatar Méven Car Committed by Méven Car

Solid-device-automounter/kcm: Use KConfigXT in ui

Summary:
 * Make default button work
 * Move connection from cpp to .ui
 * Slight label change

Test Plan: Use default button

Reviewers: ervin, ngraham, #plasma, bport, crossi

Reviewed By: ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27127
parent 616a9916
......@@ -41,6 +41,7 @@ K_PLUGIN_FACTORY(DeviceAutomounterKCMFactory, registerPlugin<DeviceAutomounterKC
DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)//DeviceAutomounterKCMFactory::componentData(), parent)
, m_devices(new DeviceModel(this))
{
KAboutData *about = new KAboutData(QStringLiteral("kcm_device_automounter"),
i18n("Device Automounter"),
......@@ -54,26 +55,21 @@ DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &
setAboutData(about);
setupUi(this);
m_devices = new DeviceModel(this);
addConfig(AutomounterSettings::self(), this);
deviceView->setModel(m_devices);
deviceView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
deviceView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
auto emitChanged = [this] {
m_devices->setAutomaticMountOnLogin(automountOnLogin->isChecked());
m_devices->setAutomaticMountOnPlugin(automountOnPlugin->isChecked());
m_devices->setAutomaticMountOnLogin(kcfg_AutomountOnLogin->isChecked());
m_devices->setAutomaticMountOnPlugin(kcfg_AutomountOnPlugin->isChecked());
emit markAsChanged();
};
connect(automountOnLogin, &QCheckBox::stateChanged, this, emitChanged);
connect(automountOnPlugin, &QCheckBox::stateChanged, this, emitChanged);
connect(automountEnabled, &QCheckBox::stateChanged, this, emitChanged);
connect(automountUnknownDevices, &QCheckBox::stateChanged, this, emitChanged);
connect(m_devices, &DeviceModel::dataChanged, this, emitChanged);
connect(automountEnabled, &QCheckBox::stateChanged, this, &DeviceAutomounterKCM::enabledChanged);
connect(deviceView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &DeviceAutomounterKCM::updateForgetDeviceButton);
connect(forgetDevice, &QAbstractButton::clicked, this, &DeviceAutomounterKCM::forgetSelectedDevices);
......@@ -113,35 +109,26 @@ void DeviceAutomounterKCM::forgetSelectedDevices()
emit markAsChanged();
}
void DeviceAutomounterKCM::enabledChanged()
{
automountOnLogin->setEnabled(automountEnabled->isChecked());
automountOnPlugin->setEnabled(automountEnabled->isChecked());
automountUnknownDevices->setEnabled(automountEnabled->isChecked());
deviceView->setEnabled(automountEnabled->isChecked());
}
void DeviceAutomounterKCM::load()
{
automountEnabled->setChecked(AutomounterSettings::automountEnabled());
automountUnknownDevices->setChecked(AutomounterSettings::automountUnknownDevices());
automountOnLogin->setChecked(AutomounterSettings::automountOnLogin());
automountOnPlugin->setChecked(AutomounterSettings::automountOnPlugin());
KCModule::load();
bool automountEnabled = AutomounterSettings::self()->automountEnabled();
kcfg_AutomountUnknownDevices->setEnabled(automountEnabled);
kcfg_AutomountOnLogin->setEnabled(automountEnabled);
kcfg_AutomountOnPlugin->setEnabled(automountEnabled);
m_devices->reload();
enabledChanged();
loadLayout();
}
void DeviceAutomounterKCM::save()
{
KCModule::save();
saveLayout();
const bool enabled = automountEnabled->isChecked();
AutomounterSettings::setAutomountEnabled(enabled);
AutomounterSettings::setAutomountUnknownDevices(automountUnknownDevices->isChecked());
AutomounterSettings::setAutomountOnLogin(automountOnLogin->isChecked());
AutomounterSettings::setAutomountOnPlugin(automountOnPlugin->isChecked());
const bool enabled = kcfg_AutomountEnabled->isChecked();
QStringList validDevices;
for (int i = 0; i < m_devices->rowCount(); ++i) {
......
......@@ -26,6 +26,7 @@
#include "ui_DeviceAutomounterKCM.h"
class DeviceModel;
class AutomounterSettings;
class DeviceAutomounterKCM : public KCModule, public Ui::DeviceAutomounterKCM
{
......@@ -40,7 +41,6 @@ public slots:
void save() override;
private slots:
void enabledChanged();
void updateForgetDeviceButton();
void forgetSelectedDevices();
......@@ -49,7 +49,6 @@ private:
void loadLayout();
DeviceModel *m_devices;
};
#endif
......@@ -12,7 +12,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="automountEnabled">
<widget class="QCheckBox" name="kcfg_AutomountEnabled">
<property name="whatsThis">
<string>When this is unchecked, no device automounting of any kind will happen, regardless of anything selected in the &quot;Device Overrides&quot; section.</string>
</property>
......@@ -40,7 +40,7 @@
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="automountUnknownDevices">
<widget class="QCheckBox" name="kcfg_AutomountUnknownDevices">
<property name="whatsThis">
<string>When this is checked, only remembered devices will be automatically mounted. A device is 'remembered' if it has ever been mounted before. For instance, plugging in a USB media player to charge is not sufficient to 'remember' it - if the files are not accessed, it will not be automatically mounted the next time it is seen. Once they have been accessed, however, the device's contents will be automatically made available to the system.</string>
</property>
......@@ -50,22 +50,22 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="automountOnLogin">
<widget class="QCheckBox" name="kcfg_AutomountOnLogin">
<property name="whatsThis">
<string>If any removable storage devices are connected to your system when you login to your desktop, their contents will automatically be made available to your system for other programs to read.</string>
</property>
<property name="text">
<string>Mount all removable media at login</string>
<string>Automatically mount all removable media at login</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="automountOnPlugin">
<widget class="QCheckBox" name="kcfg_AutomountOnPlugin">
<property name="whatsThis">
<string>When this is checked, the contents of any storage device will automatically be made available to the system when it is plugged in or attached.</string>
</property>
<property name="text">
<string>Automatically mount removable media when attached</string>
<string>Automatically mount all removable media when attached</string>
</property>
</widget>
</item>
......@@ -149,5 +149,70 @@ If &quot;Enable automatic mounting of removable media&quot; is unchecked, the ov
</layout>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>kcfg_AutomountEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_AutomountOnLogin</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>307</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>81</y>
</hint>
</hints>
</connection>
<connection>
<sender>kcfg_AutomountEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_AutomountOnPlugin</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>307</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>111</y>
</hint>
</hints>
</connection>
<connection>
<sender>kcfg_AutomountEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>kcfg_AutomountUnknownDevices</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>307</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
<y>51</y>
</hint>
</hints>
</connection>
<connection>
<sender>kcfg_AutomountEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>deviceView</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>307</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>307</x>
<y>244</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment