diff options
author | fiaxh <git@mx.ax.lt> | 2017-08-02 17:29:55 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-08-03 15:59:04 +0200 |
commit | ea174ab632ced082eb0f1c51cea1bc9dc5c7c89e (patch) | |
tree | 8f83d1379a48e7aa49af5a5146d76a4c595f2363 /main/src/ui/conversation_titlebar/encryption_entry.vala | |
parent | f83e1188c5dcf1981832f296203f94503b467e30 (diff) | |
download | dino-ea174ab632ced082eb0f1c51cea1bc9dc5c7c89e.tar.gz dino-ea174ab632ced082eb0f1c51cea1bc9dc5c7c89e.zip |
Http file upload
Diffstat (limited to 'main/src/ui/conversation_titlebar/encryption_entry.vala')
-rw-r--r-- | main/src/ui/conversation_titlebar/encryption_entry.vala | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/main/src/ui/conversation_titlebar/encryption_entry.vala b/main/src/ui/conversation_titlebar/encryption_entry.vala new file mode 100644 index 00000000..18c09773 --- /dev/null +++ b/main/src/ui/conversation_titlebar/encryption_entry.vala @@ -0,0 +1,83 @@ +using Gtk; +using Gee; + +using Dino.Entities; + +namespace Dino.Ui { + +class EncryptionEntry : Plugins.ConversationTitlebarEntry { + public override string id { get { return "encryption"; } } + + public override double order { get { return 2; } } + public override Plugins.ConversationTitlebarWidget get_widget() { + return new EncryptionWidget() { visible=true }; + } +} + +class EncryptionWidget : MenuButton, Plugins.ConversationTitlebarWidget { + + private Conversation? conversation; + private RadioButton? button_unencrypted; + private Map<RadioButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<RadioButton, Plugins.EncryptionListEntry>(); + + public EncryptionWidget() { + Builder builder = new Builder.from_resource("/org/dino-im/menu_encryption.ui"); + PopoverMenu menu = 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); + set_use_popover(true); + set_popover(menu); + set_image(new Image.from_icon_name("changes-allow-symbolic", IconSize.BUTTON)); + } + + 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() { + visible = (conversation.type_ == Conversation.Type.CHAT); + if (conversation.type_ == Conversation.Type.CHAT) { + 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(); + } +} + +} |