Commit 0c57ce17 authored by Bharadwaj Raju's avatar Bharadwaj Raju Committed by Nate Graham
Browse files

kcms/nightcolor: Make Night Color enabled/disabled status part of the combobox

Currently we have a situation where in order to change the Night Color mode,
you have to go through Automatic mode first (and thereby make a geolocation
network request) as it's the default setting. With this commit, you turn on
Night Color and choose an activation mode all in a single step using the
combobox, bypassing this issue and simplifying the UI too.
parent 48af5ae6
Pipeline #229741 passed with stage
in 6 minutes and 18 seconds
......@@ -85,22 +85,82 @@ KCM.SimpleKCM {
Kirigami.FormLayout {
id: parentLayout
QQC2.CheckBox {
id: activator
text: i18n("Activate blue light filter")
checked: kcm.nightColorSettings.active
onCheckedChanged: kcm.nightColorSettings.active = checked
KCM.SettingStateBinding {
configObject: kcm.nightColorSettings
settingName: "Active"
extraEnabledConditions: true//cA.nightColorAvailable
QQC2.ComboBox {
id: modeSwitcher
// Work around https://bugs.kde.org/show_bug.cgi?id=403153
Layout.minimumWidth: Kirigami.Units.gridUnit * 17
Kirigami.FormData.label: i18n("Switching times:")
model: [
i18n("Always off"), // This is not actually a Mode, but represents Night Color being disabled
i18n("Sunset and sunrise at current location"),
i18n("Sunset and sunrise at manual location"),
i18n("Custom times"),
i18n("Always on night color")
]
Connections {
target: kcm.nightColorSettings
function onActiveChanged() {
if (!kcm.nightColorSettings.active) {
modeSwitcher.currentIndex = 0;
} else {
modeSwitcher.currentIndex = kcm.nightColorSettings.mode + 1;
}
}
function onModeChanged() {
if (kcm.nightColorSettings.active) {
modeSwitcher.currentIndex = kcm.nightColorSettings.mode + 1;
}
}
}
onCurrentIndexChanged: {
kcm.nightColorSettings.active = (currentIndex !== 0);
if (currentIndex !== 0) {
kcm.nightColorSettings.mode = currentIndex - 1;
}
if (currentIndex - 1 == NightColorMode.Automatic && kcm.nightColorSettings.active) {
startLocator();
} else {
endLocator();
}
}
KCM.SettingHighlighter {
highlight: true
}
// Inform about geolocation access in auto mode
// The system settings window likes to take over
// the cursor with a plain label. The TextEdit
// 'takes priority' over the system settings
// window trying to eat the mouse, allowing
// us to use the HoverHandler boilerplate for
// proper link handling
TextEdit {
Layout.maximumWidth: modeSwitcher.width
visible: modeSwitcher.currentIndex - 1 === NightColorMode.Automatic && kcm.nightColorSettings.active
enabled: kcm.nightColorSettings.active
textFormat: TextEdit.RichText
wrapMode: Text.Wrap
readOnly: true
color: Kirigami.Theme.textColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectionColor: Kirigami.Theme.highlightColor
text: xi18nc("@info", "The device's location will be periodically updated using GPS (if available), or by sending network information to <link url='https://location.services.mozilla.com'>Mozilla Location Service</link>.")
font: Kirigami.Theme.smallFont
onLinkActivated: (url) => Qt.openUrlExternally(url)
HoverHandler {
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
// Workaround for Layout.margins not working in Kirigami FormLayout (bug 434625)
Item { implicitHeight: Kirigami.Units.largeSpacing }
Item {
Kirigami.FormData.isSection: true
}
......@@ -241,76 +301,11 @@ KCM.SimpleKCM {
]
}
QQC2.ComboBox {
id: modeSwitcher
// Work around https://bugs.kde.org/show_bug.cgi?id=403153
Layout.minimumWidth: Kirigami.Units.gridUnit * 17
Kirigami.FormData.label: i18n("Switching times:")
enabled: activator.checked
model: [
i18n("Sunset and sunrise at current location"),
i18n("Sunset and sunrise at manual location"),
i18n("Custom times"),
i18n("Always on night color")
]
currentIndex: kcm.nightColorSettings.mode
onCurrentIndexChanged: {
kcm.nightColorSettings.mode = currentIndex;
if (currentIndex == NightColorMode.Automatic && kcm.nightColorSettings.active) {
startLocator();
} else {
endLocator();
}
}
KCM.SettingStateBinding {
configObject: kcm.nightColorSettings
settingName: "Mode"
extraEnabledConditions: kcm.nightColorSettings.active
}
}
// Inform about geolocation access in auto mode
// The system settings window likes to take over
// the cursor with a plain label. The TextEdit
// 'takes priority' over the system settings
// window trying to eat the mouse, allowing
// us to use the HoverHandler boilerplate for
// proper link handling
TextEdit {
Layout.maximumWidth: modeSwitcher.width
visible: modeSwitcher.currentIndex === NightColorMode.Automatic && kcm.nightColorSettings.active
enabled: activator.checked
textFormat: TextEdit.RichText
wrapMode: Text.Wrap
readOnly: true
color: Kirigami.Theme.textColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectionColor: Kirigami.Theme.highlightColor
text: xi18nc("@info", "The device's location will be periodically updated using GPS (if available), or by sending network information to <link url='https://location.services.mozilla.com'>Mozilla Location Service</link>.")
font: Kirigami.Theme.smallFont
onLinkActivated: (url) => Qt.openUrlExternally(url)
HoverHandler {
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
// Workaround for Layout.margins not working in Kirigami FormLayout (bug 434625)
Item { implicitHeight: Kirigami.Units.largeSpacing }
// Show current location in auto mode
QQC2.Label {
visible: kcm.nightColorSettings.mode === NightColorMode.Automatic && kcm.nightColorSettings.active
&& root.doneLocating
enabled: activator.checked
enabled: kcm.nightColorSettings.active
wrapMode: Text.Wrap
text: i18n("Latitude: %1° Longitude: %2°", Math.round(locator.latitude * 100)/100, Math.round(locator.longitude * 100)/100)
}
......@@ -321,7 +316,7 @@ KCM.SimpleKCM {
// Match combobox width
Layout.minimumWidth: modeSwitcher.width
Layout.maximumWidth: modeSwitcher.width
visible: kcm.nightColorSettings.mode === NightColorMode.Timings
visible: kcm.nightColorSettings.mode === NightColorMode.Timings && kcm.nightColorSettings.active
Kirigami.FormData.label: i18n("Begin night color at:")
backend: kcm.nightColorSettings.eveningBeginFixed
onBackendChanged: {
......@@ -344,7 +339,7 @@ KCM.SimpleKCM {
// Match combobox width
Layout.minimumWidth: modeSwitcher.width
Layout.maximumWidth: modeSwitcher.width
visible: kcm.nightColorSettings.mode === NightColorMode.Timings
visible: kcm.nightColorSettings.mode === NightColorMode.Timings && kcm.nightColorSettings.active
Kirigami.FormData.label: i18n("Begin day color at:")
backend: kcm.nightColorSettings.morningBeginFixed
onBackendChanged: {
......@@ -364,7 +359,7 @@ KCM.SimpleKCM {
QQC2.SpinBox {
id: transTimeField
visible: kcm.nightColorSettings.mode === NightColorMode.Timings
visible: kcm.nightColorSettings.mode === NightColorMode.Timings && kcm.nightColorSettings.active
// Match width of combobox and input fields
Layout.minimumWidth: modeSwitcher.width
Kirigami.FormData.label: i18n("Transition duration:")
......@@ -404,7 +399,7 @@ KCM.SimpleKCM {
var diffMorEve = eve > mor ? eve - mor : mor - eve;
var diffMin = Math.min(diffMorEve, day - diffMorEve);
return diffMin <= trTime;
return diffMin <= trTime && kcm.nightColorSettings.active;
}
font.italic: true
text: i18n("Error: Transition time overlaps.")
......@@ -413,9 +408,9 @@ KCM.SimpleKCM {
// Show location chooser in manual location mode
LocationsFixedView {
visible: kcm.nightColorSettings.mode === NightColorMode.Location
visible: kcm.nightColorSettings.mode === NightColorMode.Location && kcm.nightColorSettings.active
Layout.alignment: Qt.AlignHCenter
enabled: activator.checked
enabled: kcm.nightColorSettings.active
}
// Show start/end times in automatic and manual location modes
......@@ -434,7 +429,7 @@ KCM.SimpleKCM {
TimingsView {
id: timings
visible: kcm.nightColorSettings.mode === NightColorMode.Location ||
(kcm.nightColorSettings.mode === NightColorMode.Automatic && root.doneLocating)
(kcm.nightColorSettings.mode === NightColorMode.Automatic && root.doneLocating) && kcm.nightColorSettings.active
anchors.centerIn: parent
enabled: kcm.nightColorSettings.active
latitude: kcm.nightColorSettings.mode === NightColorMode.Automatic
......
Supports Markdown
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