Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass Do Not Disturb #84

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Widgets/AppSettingsView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Widgets.AppSettingsView : Gtk.Grid {
private SettingsOption bubbles_option;
private SettingsOption sound_option;
private SettingsOption remember_option;
private Gtk.Switch bypass_do_not_disturb_switch;

construct {
app_image = new Gtk.Image () {
Expand All @@ -37,11 +38,27 @@ public class Widgets.AppSettingsView : Gtk.Grid {
};
app_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

var bypass_do_not_disturb_label = new Granite.HeaderLabel (_("Bypass Do Not Disturb")) {
margin_start = 3
};

bypass_do_not_disturb_switch = new Gtk.Switch () {
margin = 6,
margin_end = 3
};

var bypass_do_not_disturb_grid = new Gtk.Grid () {
margin_top = 6
};
bypass_do_not_disturb_grid.attach (bypass_do_not_disturb_label, 0, 0);
bypass_do_not_disturb_grid.attach (bypass_do_not_disturb_switch, 1, 0);

var header = new Gtk.Grid () {
column_spacing = 12
};
header.attach (app_image, 0, 0);
header.attach (app_label, 1, 0);
header.attach (bypass_do_not_disturb_grid, 2, 0);

bubbles_option = new SettingsOption (
"/io/elementary/switchboard/bubbles.svg",
Expand Down Expand Up @@ -77,12 +94,16 @@ public class Widgets.AppSettingsView : Gtk.Grid {
remove_bindings ();
update_selected_app ();
});

bypass_do_not_disturb_switch.notify["state"].connect (update_view);
NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view);
}

private void remove_bindings () {
Settings.unbind (bubbles_option.widget, "state");
Settings.unbind (sound_option.widget, "state");
Settings.unbind (remember_option.widget, "state");
Settings.unbind (bypass_do_not_disturb_switch, "state");
}

private void update_selected_app () {
Expand All @@ -93,8 +114,19 @@ public class Widgets.AppSettingsView : Gtk.Grid {
selected_app.settings.bind ("bubbles", bubbles_option.widget, "state", GLib.SettingsBindFlags.DEFAULT);
selected_app.settings.bind ("sounds", sound_option.widget, "state", GLib.SettingsBindFlags.DEFAULT);
selected_app.settings.bind ("remember", remember_option.widget, "state", GLib.SettingsBindFlags.DEFAULT);
selected_app.settings.bind ("bypass-do-not-disturb", bypass_do_not_disturb_switch, "state", GLib.SettingsBindFlags.DEFAULT);

app_label.label = selected_app.app_info.get_display_name ();
app_image.gicon = selected_app.app_info.get_icon ();

update_view ();
}

private void update_view () {
if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb") && !bypass_do_not_disturb_switch.state) {
bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = false;
} else {
bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = true;
}
}
}
31 changes: 2 additions & 29 deletions src/Widgets/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,16 @@
*/

public class Widgets.MainView : Gtk.Paned {
private Gtk.Stack stack;
//private Gtk.Stack stack;

construct {
var sidebar = new Sidebar ();

var app_settings_view = new AppSettingsView ();
app_settings_view.show_all ();

var description = _("While in Do Not Disturb mode, notifications and alerts will be hidden and notification sounds will be silenced.");
description += "\n\n";
description += _("System notifications, such as volume and display brightness, will be unaffected.");

var alert_view = new Granite.Widgets.AlertView (
_("elementary OS is in Do Not Disturb mode"),
description,
"notification-disabled"
);
alert_view.show_all ();

stack = new Gtk.Stack ();
stack.add_named (app_settings_view, "app-settings-view");
stack.add_named (alert_view, "alert-view");

pack1 (sidebar, true, false);
pack2 (stack, true, false);
pack2 (app_settings_view, true, false);
set_position (240);

update_view ();

NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view);
}

private void update_view () {
if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb")) {
stack.visible_child_name = "alert-view";
} else {
stack.visible_child_name = "app-settings-view";
}
}
}
7 changes: 0 additions & 7 deletions src/Widgets/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public class Widgets.Sidebar : Gtk.Grid {

app_list.row_selected.connect (show_row);

NotificationsPlug.notify_settings.bind (
"do-not-disturb",
app_list,
"sensitive",
SettingsBindFlags.INVERT_BOOLEAN
);

NotificationsPlug.notify_settings.bind (
"do-not-disturb",
do_not_disturb_switch,
Expand Down