diff --git a/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp b/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp --- a/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp +++ b/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp @@ -61,6 +61,8 @@ deviceView->header()->setSectionResizeMode(0, QHeaderView::Stretch); auto emitChanged = [this] { + m_devices->setAutomaticMountOnLogin(automountOnLogin->isChecked()); + m_devices->setAutomaticMountOnPlugin(automountOnPlugin->isChecked()); #if KCONFIGWIDGETS_VERSION < QT_VERSION_CHECK(5, 64, 0) emit changed(); #else diff --git a/solid-device-automounter/kcm/DeviceModel.h b/solid-device-automounter/kcm/DeviceModel.h --- a/solid-device-automounter/kcm/DeviceModel.h +++ b/solid-device-automounter/kcm/DeviceModel.h @@ -57,6 +57,9 @@ 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 @@ QList m_disconnected; QHash m_loginForced; QHash m_attachedForced; + bool m_automaticLogin; + bool m_automaticAttached; }; #endif diff --git a/solid-device-automounter/kcm/DeviceModel.cpp b/solid-device-automounter/kcm/DeviceModel.cpp --- a/solid-device-automounter/kcm/DeviceModel.cpp +++ b/solid-device-automounter/kcm/DeviceModel.cpp @@ -132,6 +132,9 @@ m_attached.clear(); m_disconnected.clear(); + m_automaticLogin = AutomounterSettings::automountOnLogin(); + m_automaticAttached = AutomounterSettings::automountOnPlugin(); + foreach (const QString &dev, AutomounterSettings::knownDevices()) { addNewDevice(dev); } @@ -178,19 +181,27 @@ 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() && index.column() > 0) { + if (index.column() == 1 && m_automaticLogin) { + // on login column & automount on login was checked + return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; + } else if (index.column() == 2 && m_automaticAttached) { + // on attached column & automount on attach was checked + return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; + } + return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; + } else { + // tree root elements and first column + if (m_automaticLogin && m_automaticAttached) { + return Qt::NoItemFlags; } else { return Qt::ItemIsEnabled; } } - - return Qt::NoItemFlags; } bool DeviceModel::setData(const QModelIndex &index, const QVariant &value, int role) @@ -328,3 +339,25 @@ 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)); + } + } +}