Commit f34e7c10 authored by Nate Graham's avatar Nate Graham 🔩
Browse files

[applets/notifications] Port DnD checkbox to set the icon itself

Support for this was added in frameworks/plasma-framework@b7ee6962

So there's no need to roll our own solution anymore.
parent cc2f2ba8
......@@ -76,114 +76,94 @@ PlasmaComponents3.Page {
Layout.fillWidth: true
spacing: 0
RowLayout {
id: dndRow
spacing: units.smallSpacing
PlasmaComponents3.CheckBox {
id: dndCheck
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);
}
text: i18n("Do not disturb")
icon.name: "notifications-disabled"
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();
}
}
// 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.ModelContextMenu {
id: dndMenu
property date date
visualParent: dndCheck
PlasmaComponents3.Label {
text: i18n("Do not disturb")
}
onClicked: {
notificationSettings.notificationsInhibitedUntil = model.date;
notificationSettings.save();
}
PlasmaComponents.ModelContextMenu {
id: dndMenu
property date date
visualParent: dndCheck
model: {
var model = [];
onClicked: {
notificationSettings.notificationsInhibitedUntil = model.date;
notificationSettings.save();
}
// For 1 hour
var d = dndMenu.date;
d.setHours(d.getHours() + 1);
d.setSeconds(0);
model.push({date: d, text: i18n("For 1 hour")});
model: {
var model = [];
d = dndMenu.date;
d.setHours(d.getHours() + 4);
d.setSeconds(0);
model.push({date: d, text: i18n("For 4 hours")});
// For 1 hour
var d = dndMenu.date;
d.setHours(d.getHours() + 1);
// 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("For 1 hour")});
model.push({date: d, text: i18n("Until this evening")});
}
// Until next morning
if (dndMenu.date.getHours() > dndMorningHour) {
d = dndMenu.date;
d.setHours(d.getHours() + 4);
d.setDate(d.getDate() + 1);
d.setHours(dndMorningHour);
d.setMinutes(0);
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")});
}
model.push({date: d, text: i18n("Until tomorrow morning")});
}
// Until "turned off"
// 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;
// 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;
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;
}
}
}
......
Markdown is supported
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