Warning, /plasma/plasma-workspace/applets/digital-clock/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com> 0003 SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 import QtQuick 2.15 0008 import QtQuick.Layouts 1.1 0009 import org.kde.plasma.plasmoid 2.0 0010 import org.kde.plasma.core as PlasmaCore 0011 import org.kde.plasma.plasma5support 2.0 as P5Support 0012 import org.kde.plasma.private.digitalclock 1.0 0013 import org.kde.kquickcontrolsaddons 2.0 0014 import org.kde.kirigami 2.20 as Kirigami 0015 0016 import org.kde.kcmutils // KCMLauncher 0017 import org.kde.config // KAuthorized 0018 0019 PlasmoidItem { 0020 id: root 0021 0022 width: Kirigami.Units.gridUnit * 10 0023 height: Kirigami.Units.gridUnit * 4 0024 property string dateFormatString: setDateFormatString() 0025 Plasmoid.backgroundHints: PlasmaCore.Types.ShadowBackground | PlasmaCore.Types.ConfigurableBackground 0026 property date tzDate: { 0027 const data = dataSource.data[Plasmoid.configuration.lastSelectedTimezone]; 0028 if (data === undefined) { 0029 return new Date(); 0030 } 0031 // get the time for the given timezone from the dataengine 0032 const now = data["DateTime"]; 0033 // get current UTC time 0034 const msUTC = now.getTime() + (now.getTimezoneOffset() * 60000); 0035 // add the dataengine TZ offset to it 0036 return new Date(msUTC + (data["Offset"] * 1000)); 0037 } 0038 0039 function initTimezones() { 0040 const tz = [] 0041 if (Plasmoid.configuration.selectedTimeZones.indexOf("Local") === -1) { 0042 tz.push("Local"); 0043 } 0044 root.allTimezones = tz.concat(Plasmoid.configuration.selectedTimeZones); 0045 } 0046 0047 function timeForZone(zone, showSecondsForZone) { 0048 if (!compactRepresentationItem) { 0049 return ""; 0050 } 0051 0052 // get the time for the given timezone from the dataengine 0053 const now = dataSource.data[zone]["DateTime"]; 0054 // get current UTC time 0055 const msUTC = now.getTime() + (now.getTimezoneOffset() * 60000); 0056 // add the dataengine TZ offset to it 0057 const dateTime = new Date(msUTC + (dataSource.data[zone]["Offset"] * 1000)); 0058 0059 let formattedTime; 0060 if (showSecondsForZone) { 0061 formattedTime = Qt.formatTime(dateTime, compactRepresentationItem.timeFormatWithSeconds); 0062 } else { 0063 formattedTime = Qt.formatTime(dateTime, compactRepresentationItem.timeFormat); 0064 } 0065 0066 if (dateTime.getDay() !== dataSource.data["Local"]["DateTime"].getDay()) { 0067 formattedTime += " (" + Qt.formatDate(dateTime, compactRepresentationItem.dateFormat) + ")"; 0068 } 0069 0070 return formattedTime; 0071 } 0072 0073 function nameForZone(zone) { 0074 // add the timezone string to the clock 0075 if (Plasmoid.configuration.displayTimezoneAsCode) { 0076 return dataSource.data[zone]["Timezone Abbreviation"]; 0077 } else { 0078 return TimezonesI18n.i18nCity(dataSource.data[zone]["Timezone"]); 0079 } 0080 } 0081 0082 preferredRepresentation: compactRepresentation 0083 compactRepresentation: DigitalClock { 0084 activeFocusOnTab: true 0085 hoverEnabled: true 0086 0087 Accessible.name: tooltipLoader.item.Accessible.name 0088 Accessible.description: tooltipLoader.item.Accessible.description 0089 } 0090 fullRepresentation: CalendarView { } 0091 0092 toolTipItem: Loader { 0093 id: tooltipLoader 0094 0095 Layout.minimumWidth: item ? item.implicitWidth : 0 0096 Layout.maximumWidth: item ? item.implicitWidth : 0 0097 Layout.minimumHeight: item ? item.implicitHeight : 0 0098 Layout.maximumHeight: item ? item.implicitHeight : 0 0099 0100 source: Qt.resolvedUrl("Tooltip.qml") 0101 } 0102 0103 //We need Local to be *always* present, even if not disaplayed as 0104 //it's used for formatting in ToolTip.dateTimeChanged() 0105 property var allTimezones 0106 Connections { 0107 target: Plasmoid.configuration 0108 function onSelectedTimeZonesChanged() { root.initTimezones(); } 0109 } 0110 0111 Binding { 0112 target: root 0113 property: "hideOnWindowDeactivate" 0114 value: !Plasmoid.configuration.pin 0115 restoreMode: Binding.RestoreBinding 0116 } 0117 0118 P5Support.DataSource { 0119 id: dataSource 0120 engine: "time" 0121 connectedSources: allTimezones 0122 interval: intervalAlignment === P5Support.Types.NoAlignment ? 1000 : 60000 0123 intervalAlignment: { 0124 if (Plasmoid.configuration.showSeconds === 2 0125 || (Plasmoid.configuration.showSeconds === 1 0126 && compactRepresentationItem 0127 && compactRepresentationItem.containsMouse)) { 0128 return P5Support.Types.NoAlignment; 0129 } else { 0130 return P5Support.Types.AlignToMinute; 0131 } 0132 } 0133 } 0134 0135 function setDateFormatString() { 0136 // remove "dddd" from the locale format string 0137 // /all/ locales in LongFormat have "dddd" either 0138 // at the beginning or at the end. so we just 0139 // remove it + the delimiter and space 0140 let format = Qt.locale().dateFormat(Locale.LongFormat); 0141 format = format.replace(/(^dddd.?\s)|(,?\sdddd$)/, ""); 0142 return format; 0143 } 0144 0145 Plasmoid.contextualActions: [ 0146 PlasmaCore.Action { 0147 id: clipboardAction 0148 text: i18n("Copy to Clipboard") 0149 icon.name: "edit-copy" 0150 }, 0151 PlasmaCore.Action { 0152 text: i18n("Adjust Date and Time…") 0153 icon.name: "clock" 0154 visible: KAuthorized.authorize("kcm_clock") 0155 onTriggered: KCMLauncher.openSystemSettings("kcm_clock") 0156 }, 0157 PlasmaCore.Action { 0158 text: i18n("Set Time Format…") 0159 icon.name: "gnumeric-format-thousand-separator" 0160 visible: KAuthorized.authorizeControlModule("kcm_regionandlang") 0161 onTriggered: KCMLauncher.openSystemSettings("kcm_regionandlang") 0162 } 0163 ] 0164 0165 Component.onCompleted: { 0166 ClipboardMenu.setupMenu(clipboardAction); 0167 0168 root.initTimezones(); 0169 } 0170 }