diff options
author | fiaxh <git@mx.ax.lt> | 2017-09-05 23:53:18 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-09-06 00:15:18 +0200 |
commit | 8944029128e3d0f9e32b61e00e880d92fceabb31 (patch) | |
tree | 8cf872969d3349c61278b19273e76c65036c429d /main/src/ui/chat_input | |
parent | 312372350e24d1ebd8afbb0029fac04f2b64eb83 (diff) | |
download | dino-8944029128e3d0f9e32b61e00e880d92fceabb31.tar.gz dino-8944029128e3d0f9e32b61e00e880d92fceabb31.zip |
Move encryption menu into ChatInput, PGP support for MUCs
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r-- | main/src/ui/chat_input/encryption_button.vala | 74 | ||||
-rw-r--r-- | main/src/ui/chat_input/view.vala | 5 |
2 files changed, 79 insertions, 0 deletions
diff --git a/main/src/ui/chat_input/encryption_button.vala b/main/src/ui/chat_input/encryption_button.vala new file mode 100644 index 00000000..6ae3e8af --- /dev/null +++ b/main/src/ui/chat_input/encryption_button.vala @@ -0,0 +1,74 @@ +using Gtk; +using Gee; + +using Dino.Entities; + +namespace Dino.Ui { + +public class EncryptionButton : MenuButton { + + private Conversation? conversation; + private RadioButton? button_unencrypted; + private Map<RadioButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<RadioButton, Plugins.EncryptionListEntry>(); + + public EncryptionButton() { + relief = ReliefStyle.NONE; + use_popover = true; + image = new Image.from_icon_name("changes-allow-symbolic", IconSize.BUTTON); + get_style_context().add_class("flat"); + + Builder builder = new Builder.from_resource("/im/dino/menu_encryption.ui"); + popover = builder.get_object("menu_encryption") as PopoverMenu; + Box encryption_box = builder.get_object("encryption_box") as Box; + button_unencrypted = builder.get_object("button_unencrypted") as RadioButton; + button_unencrypted.toggled.connect(encryption_changed); + + Application app = GLib.Application.get_default() as Application; + foreach (var e in app.plugin_registry.encryption_list_entries) { + RadioButton btn = new RadioButton.with_label(button_unencrypted.get_group(), e.name); + encryption_radios[btn] = e; + btn.toggled.connect(encryption_changed); + btn.visible = true; + encryption_box.pack_end(btn, false); + } + clicked.connect(update_encryption_menu_state); + } + + private void encryption_changed() { + foreach (RadioButton e in encryption_radios.keys) { + if (e.get_active()) { + conversation.encryption = encryption_radios[e].encryption; + update_encryption_menu_icon(); + return; + } + } + conversation.encryption = Encryption.NONE; + update_encryption_menu_icon(); + } + + private void update_encryption_menu_state() { + foreach (RadioButton e in encryption_radios.keys) { + e.set_sensitive(encryption_radios[e].can_encrypt(conversation)); + if (conversation.encryption == encryption_radios[e].encryption) e.set_active(true); + } + if (conversation.encryption == Encryption.NONE) { + button_unencrypted.set_active(true); + } + } + + private void update_encryption_menu_icon() { + if (conversation.encryption == Encryption.NONE) { + set_image(new Image.from_icon_name("changes-allow-symbolic", IconSize.BUTTON)); + } else { + set_image(new Image.from_icon_name("changes-prevent-symbolic", IconSize.BUTTON)); + } + } + + public new void set_conversation(Conversation conversation) { + this.conversation = conversation; + update_encryption_menu_state(); + update_encryption_menu_icon(); + } +} + +} diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala index 06e59e54..ef749505 100644 --- a/main/src/ui/chat_input/view.vala +++ b/main/src/ui/chat_input/view.vala @@ -12,6 +12,7 @@ public class View : Box { [GtkChild] private ScrolledWindow scrolled; [GtkChild] private TextView text_input; + [GtkChild] private Box box; public string text { owned get { return text_input.buffer.text; } @@ -25,6 +26,7 @@ public class View : Box { private OccupantsTabCompletor occupants_tab_completor; private SmileyConverter smiley_converter; private EditHistory edit_history; + private EncryptionButton encryption_widget = new EncryptionButton() { yalign=0, visible=true }; public View(StreamInteractor stream_interactor) { this.stream_interactor = stream_interactor; @@ -32,6 +34,8 @@ public class View : Box { smiley_converter = new SmileyConverter(stream_interactor, text_input); edit_history = new EditHistory(text_input, GLib.Application.get_default()); + box.add(encryption_widget); + encryption_widget.get_style_context().add_class("dino-chatinput-button"); scrolled.get_vscrollbar().get_preferred_height(out vscrollbar_min_height, null); scrolled.vadjustment.notify["upper"].connect_after(on_upper_notify); text_input.key_press_event.connect(on_text_input_key_press); @@ -41,6 +45,7 @@ public class View : Box { public void initialize_for_conversation(Conversation conversation) { occupants_tab_completor.initialize_for_conversation(conversation); edit_history.initialize_for_conversation(conversation); + encryption_widget.set_conversation(conversation); if (this.conversation != null) entry_cache[this.conversation] = text_input.buffer.text; this.conversation = conversation; |