From 7e83529afcd0ccfff5c65c99e4427bd6cf3f82ac Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 31 Oct 2017 15:19:30 +0100 Subject: Blocking setting in Contact Details --- main/src/ui/contact_details/blocking_provider.vala | 36 ++++++++++++++++++++++ main/src/ui/contact_details/dialog.vala | 1 + 2 files changed, 37 insertions(+) create mode 100644 main/src/ui/contact_details/blocking_provider.vala (limited to 'main/src/ui') diff --git a/main/src/ui/contact_details/blocking_provider.vala b/main/src/ui/contact_details/blocking_provider.vala new file mode 100644 index 00000000..bf59a083 --- /dev/null +++ b/main/src/ui/contact_details/blocking_provider.vala @@ -0,0 +1,36 @@ +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.ContactDetails { + +public class BlockingProvider : Plugins.ContactDetailsProvider, Object { + public string id { get { return "blocking"; } } + + private StreamInteractor stream_interactor; + + public BlockingProvider(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + } + + public void populate(Conversation conversation, Plugins.ContactDetails contact_details, Plugins.WidgetType type) { + if (type != Plugins.WidgetType.GTK) return; + if (conversation.type_ != Conversation.Type.CHAT) return; + + if (stream_interactor.get_module(BlockingManager.IDENTITY).is_supported(conversation.account)) { + bool is_blocked = stream_interactor.get_module(BlockingManager.IDENTITY).is_blocked(conversation.account, conversation.counterpart); + Switch sw = new Switch() { active=is_blocked, valign=Align.CENTER, visible=true }; + sw.state_set.connect((state) => { + if (state) { + stream_interactor.get_module(BlockingManager.IDENTITY).block(conversation.account, conversation.counterpart); + } else { + stream_interactor.get_module(BlockingManager.IDENTITY).unblock(conversation.account, conversation.counterpart); + } + return false; + }); + contact_details.add(_("Settings"), _("Block"), _("Communication and status updates in either direction are blocked"), sw); + } + } +} + +} diff --git a/main/src/ui/contact_details/dialog.vala b/main/src/ui/contact_details/dialog.vala index 147811f9..70e495d1 100644 --- a/main/src/ui/contact_details/dialog.vala +++ b/main/src/ui/contact_details/dialog.vala @@ -42,6 +42,7 @@ public class Dialog : Gtk.Dialog { Application app = GLib.Application.get_default() as Application; app.plugin_registry.register_contact_details_entry(new SettingsProvider(stream_interactor)); + app.plugin_registry.register_contact_details_entry(new BlockingProvider(stream_interactor)); app.plugin_registry.register_contact_details_entry(new MucConfigFormProvider(stream_interactor)); foreach (Plugins.ContactDetailsProvider provider in app.plugin_registry.contact_details_entries) { -- cgit v1.2.3-70-g09d2