Commit 470d3e9f authored by Momo Cao's avatar Momo Cao Committed by Nate Graham
Browse files

Add option to display timezone's UTC offset

BUG: 377810
FIXED-IN: 5.22
parent 2d064fc1
......@@ -53,9 +53,14 @@
<label>Whether the mouse wheel switches between the timezones configured in selectedTimeZones.</label>
<default>false</default>
</entry>
<entry name="displayTimezoneAsCode" type="Bool">
<label>Whether the timezone is displayed as a code i.e. "GMT" or full text i.e. "London".</label>
<default>true</default>
<entry name="displayTimezoneFormat" type="Enum">
<label>Whether the timezone is displayed as a code i.e. "GMT", full text i.e. "London" or UTC offset "+1".</label>
<choices name="Settings::displayTimezoneFormat">
<choice name="Code" />
<choice name="FullText" />
<choice name="UTCOffset" />
</choices>
<default>Code</default>
</entry>
<entry name="showWeekNumbers" type="Bool">
<label>Whether the calendar should show week numbers.</label>
......
......@@ -46,7 +46,7 @@ Item {
}
property string lastSelectedTimezone: plasmoid.configuration.lastSelectedTimezone
property bool displayTimezoneAsCode: plasmoid.configuration.displayTimezoneAsCode
property int displayTimezoneFormat: plasmoid.configuration.displayTimezoneFormat
property int use24hFormat: plasmoid.configuration.use24hFormat
property string lastDate: ""
......@@ -66,7 +66,7 @@ Item {
setupLabels();
}
onDisplayTimezoneAsCodeChanged: { setupLabels(); }
onDisplayTimezoneFormatChanged: { setupLabels(); }
onStateChanged: { setupLabels(); }
onLastSelectedTimezoneChanged: { timeFormatCorrection(Qt.locale().timeFormat(Locale.ShortFormat)) }
......@@ -611,8 +611,20 @@ Item {
var timezoneString = "";
if (showTimezone) {
timezoneString = plasmoid.configuration.displayTimezoneAsCode ? dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Timezone Abbreviation"]
: TimezonesI18n.i18nCity(dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Timezone City"]);
// format timezone as tz code, city or UTC offset
if (displayTimezoneFormat === 0) {
timezoneString = dataSource.data[lastSelectedTimezone]["Timezone Abbreviation"]
} else if (displayTimezoneFormat === 1) {
timezoneString = TimezonesI18n.i18nCity(dataSource.data[lastSelectedTimezone]["Timezone City"]);
} else if (displayTimezoneFormat === 2) {
var lastOffset = dataSource.data[lastSelectedTimezone]["Offset"];
var symbol = lastOffset > 0 ? '+' : '';
var hours = Math.floor(lastOffset / 3600);
var minutes = Math.floor(lastOffset % 3600 / 60);
timezoneString = "UTC" + symbol + hours.toString().padStart(2, '0') + ":" + minutes.toString().padStart(2, '0');
}
timezoneLabel.text = (main.showDate || main.oneLineMode) && plasmoid.formFactor === PlasmaCore.Types.Horizontal ? "(" + timezoneString + ")" : timezoneString;
} else {
// this clears the label and that makes it hidden
......
......@@ -39,7 +39,7 @@ QtLayouts.ColumnLayout {
property alias cfg_italicText: italicCheckBox.checked
property alias cfg_showLocalTimezone: showLocalTimezone.checked
property alias cfg_displayTimezoneAsCode: timezoneCodeRadio.checked
property alias cfg_displayTimezoneFormat: displayTimezoneFormat.currentIndex
property alias cfg_showSeconds: showSeconds.checked
property alias cfg_showDate: showDate.checked
......@@ -126,18 +126,17 @@ QtLayouts.ColumnLayout {
Kirigami.FormData.isSection: true
}
QtLayouts.ColumnLayout {
QtLayouts.RowLayout {
Kirigami.FormData.label: i18n("Display time zone as:")
Kirigami.FormData.buddyFor: timezoneCityRadio
QtControls.RadioButton {
id: timezoneCityRadio
text: i18n("Time zone city")
}
QtControls.RadioButton {
id: timezoneCodeRadio
text: i18n("Time zone code")
QtControls.ComboBox {
id: displayTimezoneFormat
model: [
i18n("Code"),
i18n("City"),
i18n("Offset from UTC time"),
]
onActivated: cfg_displayTimezoneFormat = currentIndex
}
}
......@@ -295,12 +294,6 @@ QtLayouts.ColumnLayout {
}
Component.onCompleted: {
if (plasmoid.configuration.displayTimezoneAsCode) {
timezoneCodeRadio.checked = true;
} else {
timezoneCityRadio.checked = true;
}
if (!plasmoid.configuration.showLocalTimezone) {
showLocalTimeZoneWhenDifferent.checked = true;
}
......
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