diff options
Diffstat (limited to 'main/src/windows/conversation_details.vala')
-rw-r--r-- | main/src/windows/conversation_details.vala | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/main/src/windows/conversation_details.vala b/main/src/windows/conversation_details.vala index 1dac02c7..7ffa01f1 100644 --- a/main/src/windows/conversation_details.vala +++ b/main/src/windows/conversation_details.vala @@ -11,7 +11,7 @@ namespace Dino.Ui.ConversationDetails { [GtkChild] public unowned Box about_box; [GtkChild] public unowned Button pin_button; [GtkChild] public unowned Adw.ButtonContent pin_button_content; - [GtkChild] public unowned Button block_button; + [GtkChild] public unowned MenuButton block_button; [GtkChild] public unowned Adw.ButtonContent block_button_content; [GtkChild] public unowned Button notification_button_toggle; [GtkChild] public unowned Adw.ButtonContent notification_button_toggle_content; @@ -22,6 +22,8 @@ namespace Dino.Ui.ConversationDetails { [GtkChild] public unowned ViewModel.ConversationDetails model { get; } + private SimpleAction block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(ViewModel.ConversationDetails.BlockState.UNBLOCK)); + class construct { install_action("notification.on", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.ON); } ); install_action("notification.off", null, (widget, action_name) => { ((Dialog) widget).model.notification_changed(ViewModel.ConversationDetails.NotificationSetting.OFF); } ); @@ -31,7 +33,6 @@ namespace Dino.Ui.ConversationDetails { construct { pin_button.clicked.connect(() => { model.pin_changed(); }); - block_button.clicked.connect(() => { model.block_changed(); }); notification_button_toggle.clicked.connect(() => { model.notification_flipped(); }); notification_button_split.clicked.connect(() => { model.notification_flipped(); }); @@ -47,10 +48,32 @@ namespace Dino.Ui.ConversationDetails { model.settings_rows.items_changed.connect(create_preferences_rows); model.notify["room-configuration-rows"].connect(create_preferences_rows); + // Create block action + SimpleActionGroup block_action_group = new SimpleActionGroup(); + block_action = new SimpleAction.stateful("block", VariantType.INT32, new Variant.int32(0)); + block_action.activate.connect((parameter) => { + block_action.set_state(parameter); + model.block_changed((ViewModel.ConversationDetails.BlockState) parameter.get_int32()); + }); + block_action_group.insert(block_action); + this.insert_action_group("block", block_action_group); + + // Create block menu model + Menu block_menu_model = new Menu(); + string[] menu_labels = new string[] { _("Block user"), _("Block entire domain"), _("Unblock") }; + ViewModel.ConversationDetails.BlockState[] menu_states = new ViewModel.ConversationDetails.BlockState[] { ViewModel.ConversationDetails.BlockState.USER, ViewModel.ConversationDetails.BlockState.DOMAIN, ViewModel.ConversationDetails.BlockState.UNBLOCK }; + for (int i = 0; i < menu_labels.length; i++) { + MenuItem item = new MenuItem(menu_labels[i], null); + item.set_action_and_target_value("block.block", new Variant.int32(menu_states[i])); + block_menu_model.append_item(item); + } + block_button.menu_model = block_menu_model; + #if Adw_1_4 // TODO: replace with putting buttons in new line on small screens notification_button_menu_content.can_shrink = true; #endif + update_blocked_button(); } private void update_pinned_button() { @@ -64,13 +87,22 @@ namespace Dino.Ui.ConversationDetails { } private void update_blocked_button() { - block_button_content.icon_name = "dino-block-symbolic"; - block_button_content.label = model.blocked ? _("Blocked") : _("Block"); - if (model.blocked) { - block_button.add_css_class("error"); - } else { - block_button.remove_css_class("error"); + switch (model.blocked) { + case USER: + block_button_content.label = _("Blocked"); + block_button.add_css_class("error"); + break; + case DOMAIN: + block_button_content.label = _("Domain blocked"); + block_button.add_css_class("error"); + break; + case UNBLOCK: + block_button_content.label = _("Block"); + block_button.remove_css_class("error"); + break; } + + block_action.set_state(new Variant.int32(model.blocked)); } private void update_notification_button() { @@ -229,4 +261,4 @@ namespace Dino.Ui.ConversationDetails { return preference_group; } } -}
\ No newline at end of file +} |