diff --git a/applets/notifications/package/contents/ui/FullRepresentation.qml b/applets/notifications/package/contents/ui/FullRepresentation.qml --- a/applets/notifications/package/contents/ui/FullRepresentation.qml +++ b/applets/notifications/package/contents/ui/FullRepresentation.qml @@ -65,213 +65,6 @@ } } - // header - ColumnLayout { - id: header - visible: !Kirigami.Settings.isMobile - Layout.fillWidth: true - spacing: 0 - - RowLayout { - Layout.fillWidth: true - spacing: 0 - - RowLayout { - id: dndRow - spacing: units.smallSpacing - enabled: NotificationManager.Server.valid - - PlasmaComponents3.CheckBox { - id: dndCheck - text: i18n("Do not disturb") - spacing: units.smallSpacing - checkable: true - checked: Globals.inhibited - - // Let the menu open on press - onPressed: { - if (!Globals.inhibited) { - dndMenu.date = new Date(); - // shows ontop of CheckBox to hide the fact that it's unchecked - // until you actually select something :) - dndMenu.open(0, 0); - } - } - // but disable only on click - onClicked: { - if (Globals.inhibited) { - Globals.revokeInhibitions(); - } - } - - contentItem: RowLayout { - spacing: dndCheck.spacing - - PlasmaCore.IconItem { - Layout.leftMargin: dndCheck.mirrored ? 0 : dndCheck.indicator.width + dndCheck.spacing - Layout.rightMargin: dndCheck.mirrored ? dndCheck.indicator.width + dndCheck.spacing : 0 - source: "notifications-disabled" - Layout.preferredWidth: units.iconSizes.smallMedium - Layout.preferredHeight: units.iconSizes.smallMedium - } - - PlasmaComponents.Label { - text: i18n("Do not disturb") - } - } - - PlasmaComponents.ModelContextMenu { - id: dndMenu - property date date - visualParent: dndCheck - - onClicked: { - notificationSettings.notificationsInhibitedUntil = model.date; - notificationSettings.save(); - } - - model: { - var model = []; - - // For 1 hour - var d = dndMenu.date; - d.setHours(d.getHours() + 1); - d.setSeconds(0); - model.push({date: d, text: i18n("For 1 hour")}); - - d = dndMenu.date; - d.setHours(d.getHours() + 4); - d.setSeconds(0); - model.push({date: d, text: i18n("For 4 hours")}); - - // Until this evening - if (dndMenu.date.getHours() < dndEveningHour) { - d = dndMenu.date; - // TODO make the user's preferred time schedule configurable - d.setHours(dndEveningHour); - d.setMinutes(0); - d.setSeconds(0); - model.push({date: d, text: i18n("Until this evening")}); - } - - // Until next morning - if (dndMenu.date.getHours() > dndMorningHour) { - d = dndMenu.date; - d.setDate(d.getDate() + 1); - d.setHours(dndMorningHour); - d.setMinutes(0); - d.setSeconds(0); - model.push({date: d, text: i18n("Until tomorrow morning")}); - } - - // Until Monday - // show Friday and Saturday, Sunday is "0" but for that you can use "until tomorrow morning" - if (dndMenu.date.getDay() >= 5) { - d = dndMenu.date; - d.setHours(dndMorningHour); - // wraps around if necessary - d.setDate(d.getDate() + (7 - d.getDay() + 1)); - d.setMinutes(0); - d.setSeconds(0); - model.push({date: d, text: i18n("Until Monday")}); - } - - // Until "turned off" - d = dndMenu.date; - // Just set it to one year in the future so we don't need yet another "do not disturb enabled" property - d.setFullYear(d.getFullYear() + 1); - model.push({date: d, text: i18n("Until turned off")}); - - return model; - } - } - } - } - - Item { - Layout.fillWidth: true - } - - PlasmaComponents.ToolButton { - iconName: "configure" - // remove mnemonics - tooltip: plasmoid.action("openKcm").text.replace(/([^&]*)&(.)([^&]*)/g, function (match, p1, p2, p3) { - return p1.concat(p2, p3); - }); - visible: plasmoid.action("openKcm").enabled - onClicked: plasmoid.action("openKcm").trigger() - } - - PlasmaComponents.ToolButton { - iconName: "edit-clear-history" - tooltip: i18n("Clear History") - enabled: plasmoid.action("clearHistory").visible - onClicked: action_clearHistory() - } - } - - PlasmaExtras.DescriptiveLabel { - Layout.leftMargin: dndCheck.mirrored ? 0 : dndCheck.indicator.width + 2 * dndCheck.spacing + units.iconSizes.smallMedium - Layout.rightMargin: dndCheck.mirrored ? dndCheck.indicator.width + 2 * dndCheck.spacing + units.iconSizes.smallMedium : 0 - Layout.fillWidth: true - wrapMode: Text.WordWrap - textFormat: Text.PlainText - text: { - if (!Globals.inhibited) { - return ""; - } - - var inhibitedUntil = notificationSettings.notificationsInhibitedUntil; - var inhibitedByApp = notificationSettings.notificationsInhibitedByApplication; - var inhibitedByMirroredScreens = notificationSettings.inhibitNotificationsWhenScreensMirrored - && notificationSettings.screensMirrored; - - var sections = []; - - // Show until time if valid but not if too far int he future - if (!isNaN(inhibitedUntil.getTime()) && inhibitedUntil.getTime() - new Date().getTime() < 365 * 24 * 60 * 60 * 1000 /* 1 year*/) { - sections.push(i18nc("Do not disturb until date", "Until %1", - KCoreAddons.Format.formatRelativeDateTime(inhibitedUntil, Locale.ShortFormat))); - } - - if (inhibitedByApp) { - var inhibitionAppNames = notificationSettings.notificationInhibitionApplications; - var inhibitionAppReasons = notificationSettings.notificationInhibitionReasons; - - for (var i = 0, length = inhibitionAppNames.length; i < length; ++i) { - var name = inhibitionAppNames[i]; - var reason = inhibitionAppReasons[i]; - - if (reason) { - sections.push(i18nc("Do not disturb until app has finished (reason)", "While %1 is active (%2)", name, reason)); - } else { - sections.push(i18nc("Do not disturb until app has finished", "While %1 is active", name)); - } - } - } - - if (inhibitedByMirroredScreens) { - sections.push(i18nc("Do not disturb because external mirrored screens connected", "Screens are mirrored")) - } - - return sections.join(" · "); - } - visible: text !== "" - } - } - - PlasmaCore.SvgItem { - visible: header.visible - elementId: "horizontal-line" - Layout.fillWidth: true - // why is this needed here but not in the delegate? - Layout.preferredHeight: naturalSize.height - svg: PlasmaCore.Svg { - id: lineSvg - imagePath: "widgets/line" - } - } - // actual notifications PlasmaExtras.ScrollArea { Layout.fillWidth: true @@ -626,4 +419,211 @@ } } } + + PlasmaCore.SvgItem { + visible: footer.visible + elementId: "horizontal-line" + Layout.fillWidth: true + // why is this needed here but not in the delegate? + Layout.preferredHeight: naturalSize.height + svg: PlasmaCore.Svg { + id: lineSvg + imagePath: "widgets/line" + } + } + + // footer + ColumnLayout { + id: footer + visible: !Kirigami.Settings.isMobile + Layout.fillWidth: true + spacing: 0 + + RowLayout { + Layout.fillWidth: true + spacing: 0 + + RowLayout { + id: dndRow + spacing: units.smallSpacing + enabled: NotificationManager.Server.valid + + PlasmaComponents3.CheckBox { + id: dndCheck + text: i18n("Do not disturb") + spacing: units.smallSpacing + checkable: true + checked: Globals.inhibited + + // Let the menu open on press + onPressed: { + if (!Globals.inhibited) { + dndMenu.date = new Date(); + // shows ontop of CheckBox to hide the fact that it's unchecked + // until you actually select something :) + dndMenu.open(0, 0); + } + } + // but disable only on click + onClicked: { + if (Globals.inhibited) { + Globals.revokeInhibitions(); + } + } + + contentItem: RowLayout { + spacing: dndCheck.spacing + + PlasmaCore.IconItem { + Layout.leftMargin: dndCheck.mirrored ? 0 : dndCheck.indicator.width + dndCheck.spacing + Layout.rightMargin: dndCheck.mirrored ? dndCheck.indicator.width + dndCheck.spacing : 0 + source: "notifications-disabled" + Layout.preferredWidth: units.iconSizes.smallMedium + Layout.preferredHeight: units.iconSizes.smallMedium + } + + PlasmaComponents.Label { + text: i18n("Do not disturb") + } + } + + PlasmaComponents.ModelContextMenu { + id: dndMenu + property date date + visualParent: dndCheck + + onClicked: { + notificationSettings.notificationsInhibitedUntil = model.date; + notificationSettings.save(); + } + + model: { + var model = []; + + // For 1 hour + var d = dndMenu.date; + d.setHours(d.getHours() + 1); + d.setSeconds(0); + model.push({date: d, text: i18n("For 1 hour")}); + + d = dndMenu.date; + d.setHours(d.getHours() + 4); + d.setSeconds(0); + model.push({date: d, text: i18n("For 4 hours")}); + + // Until this evening + if (dndMenu.date.getHours() < dndEveningHour) { + d = dndMenu.date; + // TODO make the user's preferred time schedule configurable + d.setHours(dndEveningHour); + d.setMinutes(0); + d.setSeconds(0); + model.push({date: d, text: i18n("Until this evening")}); + } + + // Until next morning + if (dndMenu.date.getHours() > dndMorningHour) { + d = dndMenu.date; + d.setDate(d.getDate() + 1); + d.setHours(dndMorningHour); + d.setMinutes(0); + d.setSeconds(0); + model.push({date: d, text: i18n("Until tomorrow morning")}); + } + + // Until Monday + // show Friday and Saturday, Sunday is "0" but for that you can use "until tomorrow morning" + if (dndMenu.date.getDay() >= 5) { + d = dndMenu.date; + d.setHours(dndMorningHour); + // wraps around if necessary + d.setDate(d.getDate() + (7 - d.getDay() + 1)); + d.setMinutes(0); + d.setSeconds(0); + model.push({date: d, text: i18n("Until Monday")}); + } + + // Until "turned off" + d = dndMenu.date; + // Just set it to one year in the future so we don't need yet another "do not disturb enabled" property + d.setFullYear(d.getFullYear() + 1); + model.push({date: d, text: i18n("Until turned off")}); + + return model; + } + } + } + } + + Item { + Layout.fillWidth: true + } + + PlasmaComponents.ToolButton { + iconName: "configure" + // remove mnemonics + tooltip: plasmoid.action("openKcm").text.replace(/([^&]*)&(.)([^&]*)/g, function (match, p1, p2, p3) { + return p1.concat(p2, p3); + }); + visible: plasmoid.action("openKcm").enabled + onClicked: plasmoid.action("openKcm").trigger() + } + + PlasmaComponents.ToolButton { + iconName: "edit-clear-history" + tooltip: i18n("Clear History") + enabled: plasmoid.action("clearHistory").visible + onClicked: action_clearHistory() + } + } + + PlasmaExtras.DescriptiveLabel { + Layout.leftMargin: dndCheck.mirrored ? 0 : dndCheck.indicator.width + 2 * dndCheck.spacing + units.iconSizes.smallMedium + Layout.rightMargin: dndCheck.mirrored ? dndCheck.indicator.width + 2 * dndCheck.spacing + units.iconSizes.smallMedium : 0 + Layout.fillWidth: true + wrapMode: Text.WordWrap + textFormat: Text.PlainText + text: { + if (!Globals.inhibited) { + return ""; + } + + var inhibitedUntil = notificationSettings.notificationsInhibitedUntil; + var inhibitedByApp = notificationSettings.notificationsInhibitedByApplication; + var inhibitedByMirroredScreens = notificationSettings.inhibitNotificationsWhenScreensMirrored + && notificationSettings.screensMirrored; + + var sections = []; + + // Show until time if valid but not if too far int he future + if (!isNaN(inhibitedUntil.getTime()) && inhibitedUntil.getTime() - new Date().getTime() < 365 * 24 * 60 * 60 * 1000 /* 1 year*/) { + sections.push(i18nc("Do not disturb until date", "Until %1", + KCoreAddons.Format.formatRelativeDateTime(inhibitedUntil, Locale.ShortFormat))); + } + + if (inhibitedByApp) { + var inhibitionAppNames = notificationSettings.notificationInhibitionApplications; + var inhibitionAppReasons = notificationSettings.notificationInhibitionReasons; + + for (var i = 0, length = inhibitionAppNames.length; i < length; ++i) { + var name = inhibitionAppNames[i]; + var reason = inhibitionAppReasons[i]; + + if (reason) { + sections.push(i18nc("Do not disturb until app has finished (reason)", "While %1 is active (%2)", name, reason)); + } else { + sections.push(i18nc("Do not disturb until app has finished", "While %1 is active", name)); + } + } + } + + if (inhibitedByMirroredScreens) { + sections.push(i18nc("Do not disturb because external mirrored screens connected", "Screens are mirrored")) + } + + return sections.join(" · "); + } + visible: text !== "" + } + } }