Commit 37e9bd06 authored by Méven Car's avatar Méven Car

Solid-device-automounter/kcm: Enable/Disable columns automount...

Solid-device-automounter/kcm: Enable/Disable columns automount onLogin/onAttached depending on corresponding checkbox

Summary: To make clear to the user what automount options imply.

Test Plan:
Before:

{F8049400}

After:
{F8049404}

{F8049407}

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

Reviewed By: ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27057
parent 95c06101
......@@ -61,6 +61,8 @@ DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &
deviceView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
auto emitChanged = [this] {
m_devices->setAutomaticMountOnLogin(automountOnLogin->isChecked());
m_devices->setAutomaticMountOnPlugin(automountOnPlugin->isChecked());
emit markAsChanged();
};
......
......@@ -138,6 +138,9 @@ void DeviceModel::reload()
m_attached.clear();
m_disconnected.clear();
m_automaticLogin = AutomounterSettings::automountOnLogin();
m_automaticAttached = AutomounterSettings::automountOnPlugin();
foreach (const QString &dev, AutomounterSettings::knownDevices()) {
addNewDevice(dev);
}
......@@ -184,19 +187,44 @@ QModelIndex DeviceModel::parent(const QModelIndex &index) const
Qt::ItemFlags DeviceModel::flags(const QModelIndex &index) const
{
if (index.isValid()) {
if (index.parent().isValid()) {
if (index.column() > 0) {
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
} else if (index.column() == 0) {
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}
if (!index.isValid()) {
return Qt::NoItemFlags;
}
if (!index.parent().isValid()) {
// first child section elements
if (m_automaticLogin && m_automaticAttached) {
return Qt::NoItemFlags;
} else {
return Qt::ItemIsEnabled;
}
}
return Qt::NoItemFlags;
switch (index.column()) {
case 0:
// first column
if (m_automaticLogin && m_automaticAttached) {
return Qt::NoItemFlags;
} else {
return Qt::ItemIsEnabled;
}
case 1:
// on login column
if (m_automaticLogin) {
// automount on login was checked
return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
case 2:
// on attached column
if (m_automaticAttached) {
// automount on attach was checked
return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
}
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
default:
Q_UNREACHABLE();
}
}
bool DeviceModel::setData(const QModelIndex &index, const QVariant &value, int role)
......@@ -334,3 +362,25 @@ int DeviceModel::columnCount(const QModelIndex &parent) const
Q_UNUSED(parent);
return 3;
}
void DeviceModel::setAutomaticMountOnLogin(bool automaticLogin)
{
if (m_automaticLogin != automaticLogin) {
m_automaticLogin = automaticLogin;
for (int parent = 0; parent < rowCount(); parent++) {
const auto parentIndex = index(parent, 0);
emit dataChanged(index(0, 1, parentIndex), index(rowCount(parentIndex), 1, parentIndex));
}
}
}
void DeviceModel::setAutomaticMountOnPlugin(bool automaticAttached)
{
if (m_automaticAttached != automaticAttached) {
m_automaticAttached = automaticAttached;
for (int parent = 0; parent < rowCount(); parent++) {
const auto parentIndex = index(parent, 0);
emit dataChanged(index(0, 2, parentIndex), index(rowCount(parentIndex), 2, parentIndex));
}
}
}
......@@ -57,6 +57,9 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void setAutomaticMountOnLogin(bool automaticLogin);
void setAutomaticMountOnPlugin(bool automaticAttached);
public slots:
void forgetDevice(const QString &udi);
void reload();
......@@ -72,6 +75,8 @@ private:
QList<QString> m_disconnected;
QHash<QString, bool> m_loginForced;
QHash<QString, bool> m_attachedForced;
bool m_automaticLogin;
bool m_automaticAttached;
};
#endif
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