2017-08-02 15:29:55 +00:00
|
|
|
using Gtk;
|
|
|
|
using Gee;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
namespace Dino.Ui {
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
public class EncryptionButton {
|
2017-08-02 15:29:55 +00:00
|
|
|
|
2019-08-02 01:15:12 +00:00
|
|
|
public signal void encryption_changed(Plugins.EncryptionListEntry? encryption_entry);
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
private MenuButton menu_button;
|
2017-08-02 15:29:55 +00:00
|
|
|
private Conversation? conversation;
|
2022-02-14 13:55:59 +00:00
|
|
|
private CheckButton? button_unencrypted;
|
|
|
|
private Map<CheckButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<CheckButton, Plugins.EncryptionListEntry>();
|
2018-01-12 20:03:09 +00:00
|
|
|
private string? current_icon;
|
2019-05-26 20:18:08 +00:00
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
public EncryptionButton(StreamInteractor stream_interactor, MenuButton menu_button) {
|
2019-05-26 20:18:08 +00:00
|
|
|
this.stream_interactor = stream_interactor;
|
2022-02-14 13:55:59 +00:00
|
|
|
this.menu_button = menu_button;
|
2017-09-05 21:53:18 +00:00
|
|
|
|
2017-12-03 18:42:15 +00:00
|
|
|
Builder builder = new Builder.from_resource("/im/dino/Dino/menu_encryption.ui");
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.popover = builder.get_object("menu_encryption") as PopoverMenu;
|
2017-08-02 15:29:55 +00:00
|
|
|
Box encryption_box = builder.get_object("encryption_box") as Box;
|
2022-02-14 13:55:59 +00:00
|
|
|
button_unencrypted = builder.get_object("button_unencrypted") as CheckButton;
|
2019-08-02 01:15:12 +00:00
|
|
|
button_unencrypted.toggled.connect(encryption_button_toggled);
|
2017-09-05 21:53:18 +00:00
|
|
|
|
2020-03-08 21:15:53 +00:00
|
|
|
stream_interactor.get_module(MucManager.IDENTITY).room_info_updated.connect((account, muc_jid) => {
|
|
|
|
if (conversation != null && conversation.account.equals(account) && conversation.counterpart.equals(muc_jid)) {
|
|
|
|
update_visibility();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-02 15:29:55 +00:00
|
|
|
Application app = GLib.Application.get_default() as Application;
|
2017-09-05 21:53:18 +00:00
|
|
|
foreach (var e in app.plugin_registry.encryption_list_entries) {
|
2022-02-14 13:55:59 +00:00
|
|
|
CheckButton btn = new CheckButton.with_label(e.name);
|
|
|
|
btn.set_group(button_unencrypted);
|
2017-08-02 15:29:55 +00:00
|
|
|
encryption_radios[btn] = e;
|
2019-08-02 01:15:12 +00:00
|
|
|
btn.toggled.connect(encryption_button_toggled);
|
2017-08-02 15:29:55 +00:00
|
|
|
btn.visible = true;
|
2022-02-14 13:55:59 +00:00
|
|
|
encryption_box.prepend(btn);
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.activate.connect(update_encryption_menu_state);
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 01:15:12 +00:00
|
|
|
private void encryption_button_toggled() {
|
2022-02-14 13:55:59 +00:00
|
|
|
foreach (CheckButton e in encryption_radios.keys) {
|
2017-08-02 15:29:55 +00:00
|
|
|
if (e.get_active()) {
|
|
|
|
conversation.encryption = encryption_radios[e].encryption;
|
2019-08-02 01:15:12 +00:00
|
|
|
encryption_changed(encryption_radios[e]);
|
2017-08-02 15:29:55 +00:00
|
|
|
update_encryption_menu_icon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 01:15:12 +00:00
|
|
|
|
|
|
|
// Selected unencrypted
|
2017-08-02 15:29:55 +00:00
|
|
|
conversation.encryption = Encryption.NONE;
|
|
|
|
update_encryption_menu_icon();
|
2019-08-02 01:15:12 +00:00
|
|
|
encryption_changed(null);
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void update_encryption_menu_state() {
|
2022-02-14 13:55:59 +00:00
|
|
|
foreach (CheckButton e in encryption_radios.keys) {
|
2019-08-02 01:15:12 +00:00
|
|
|
if (conversation.encryption == encryption_radios[e].encryption) {
|
|
|
|
e.set_active(true);
|
|
|
|
encryption_changed(encryption_radios[e]);
|
|
|
|
}
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
if (conversation.encryption == Encryption.NONE) {
|
|
|
|
button_unencrypted.set_active(true);
|
2019-08-02 01:15:12 +00:00
|
|
|
encryption_changed(null);
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
private void set_icon(string icon) {
|
|
|
|
if (icon != current_icon) {
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.set_icon_name(icon);
|
2018-01-12 20:03:09 +00:00
|
|
|
current_icon = icon;
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:03:09 +00:00
|
|
|
private void update_encryption_menu_icon() {
|
|
|
|
set_icon(conversation.encryption == Encryption.NONE ? "changes-allow-symbolic" : "changes-prevent-symbolic");
|
|
|
|
}
|
|
|
|
|
2020-03-08 21:15:53 +00:00
|
|
|
private void update_visibility() {
|
2020-06-17 12:30:46 +00:00
|
|
|
if (conversation.encryption != Encryption.NONE) {
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.visible = true;
|
2020-06-17 12:30:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (conversation.type_) {
|
|
|
|
case Conversation.Type.CHAT:
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.visible = true;
|
2020-06-17 12:30:46 +00:00
|
|
|
break;
|
|
|
|
case Conversation.Type.GROUPCHAT_PM:
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.visible = false;
|
2020-06-17 12:30:46 +00:00
|
|
|
break;
|
|
|
|
case Conversation.Type.GROUPCHAT:
|
2022-02-14 13:55:59 +00:00
|
|
|
menu_button.visible = stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart);
|
2020-06-17 12:30:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-08 21:15:53 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
public void set_conversation(Conversation conversation) {
|
2017-08-02 15:29:55 +00:00
|
|
|
this.conversation = conversation;
|
|
|
|
update_encryption_menu_state();
|
|
|
|
update_encryption_menu_icon();
|
2020-03-08 21:15:53 +00:00
|
|
|
update_visibility();
|
2017-08-02 15:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:55:59 +00:00
|
|
|
}
|