diff options
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main.vala | 2 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar.vala | 139 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/encryption_entry.vala | 83 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/menu_entry.vala | 47 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/occupants_entry.vala | 50 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/view.vala | 69 | ||||
-rw-r--r-- | main/src/ui/occupant_menu/list.vala | 4 |
7 files changed, 252 insertions, 142 deletions
diff --git a/main/src/main.vala b/main/src/main.vala index ce633e30..c4c441a1 100644 --- a/main/src/main.vala +++ b/main/src/main.vala @@ -34,7 +34,7 @@ void main(string[] args) { return -1; }); - foreach (string plugin in new string[]{"omemo", "openpgp"}) { + foreach (string plugin in new string[]{"omemo", "openpgp", "http-files"}) { try { loader.load(plugin, app); } catch (Error e) { diff --git a/main/src/ui/conversation_titlebar.vala b/main/src/ui/conversation_titlebar.vala deleted file mode 100644 index be532392..00000000 --- a/main/src/ui/conversation_titlebar.vala +++ /dev/null @@ -1,139 +0,0 @@ -using Gtk; -using Gee; - -using Dino.Entities; - -namespace Dino.Ui { - -[GtkTemplate (ui = "/org/dino-im/conversation_titlebar.ui")] -public class ConversationTitlebar : Gtk.HeaderBar { - - [GtkChild] private MenuButton menu_button; - [GtkChild] private MenuButton encryption_button; - [GtkChild] private MenuButton groupchat_button; - - private RadioButton? button_unencrypted; - private Map<RadioButton, Plugins.EncryptionListEntry> encryption_radios = new HashMap<RadioButton, Plugins.EncryptionListEntry>(); - - private StreamInteractor stream_interactor; - private Window window; - private Conversation? conversation; - - public ConversationTitlebar(StreamInteractor stream_interactor, Window window) { - this.stream_interactor = stream_interactor; - this.window = window; - create_conversation_menu(); - create_encryption_menu(); - - stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { - Idle.add(() => { - if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { - update_subtitle(subject); - } - return false; - }); - }); - } - - public void initialize_for_conversation(Conversation conversation) { - this.conversation = conversation; - update_encryption_menu_state(); - update_encryption_menu_icon(); - update_groupchat_menu(); - update_title(); - update_subtitle(); - } - - 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() { - encryption_button.visible = (conversation.type_ == Conversation.Type.CHAT); - if (conversation.type_ == Conversation.Type.CHAT) { - if (conversation.encryption == Encryption.NONE) { - encryption_button.set_image(new Image.from_icon_name("changes-allow-symbolic", IconSize.BUTTON)); - } else { - encryption_button.set_image(new Image.from_icon_name("changes-prevent-symbolic", IconSize.BUTTON)); - } - } - } - - private void update_groupchat_menu() { - groupchat_button.visible = conversation.type_ == Conversation.Type.GROUPCHAT; - if (conversation.type_ == Conversation.Type.GROUPCHAT) { - groupchat_button.set_use_popover(true); - OccupantMenu.View menu = new OccupantMenu.View(stream_interactor, window, conversation); - groupchat_button.set_popover(menu); - } - } - - private void update_title() { - set_title(Util.get_conversation_display_name(stream_interactor, conversation)); - } - - private void update_subtitle(string? subtitle = null) { - if (subtitle != null) { - set_subtitle(subtitle); - } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { - string subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); - set_subtitle(subject != "" ? subject : null); - } else { - set_subtitle(null); - } - } - - private void create_conversation_menu() { - Builder builder = new Builder.from_resource("/org/dino-im/menu_conversation.ui"); - MenuModel menu = builder.get_object("menu_conversation") as MenuModel; - menu_button.set_menu_model(menu); - - SimpleAction contact_details_action = new SimpleAction("contact_details", null); - contact_details_action.activate.connect(() => { - ContactDetails.Dialog contact_details_dialog = new ContactDetails.Dialog(stream_interactor, conversation); - contact_details_dialog.set_transient_for((Window) get_toplevel()); - contact_details_dialog.present(); - }); - GLib.Application.get_default().add_action(contact_details_action); - } - - 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 create_encryption_menu() { - 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); - } - encryption_button.clicked.connect(update_encryption_menu_state); - encryption_button.set_use_popover(true); - encryption_button.set_popover(menu); - encryption_button.set_image(new Image.from_icon_name("changes-allow-symbolic", IconSize.BUTTON)); - } -} - -}
\ No newline at end of file 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(); + } +} + +} diff --git a/main/src/ui/conversation_titlebar/menu_entry.vala b/main/src/ui/conversation_titlebar/menu_entry.vala new file mode 100644 index 00000000..6cead69d --- /dev/null +++ b/main/src/ui/conversation_titlebar/menu_entry.vala @@ -0,0 +1,47 @@ +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +class MenuEntry : Plugins.ConversationTitlebarEntry { + public override string id { get { return "menu"; } } + + StreamInteractor stream_interactor; + + public MenuEntry(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + } + + public override double order { get { return 0; } } + public override Plugins.ConversationTitlebarWidget get_widget() { + return new MenuWidget(stream_interactor) { visible=true }; + } +} + +class MenuWidget : MenuButton, Plugins.ConversationTitlebarWidget { + + private Conversation? conversation; + + public MenuWidget(StreamInteractor stream_interactor) { + image = new Image.from_icon_name("open-menu-symbolic", IconSize.MENU); + + Builder builder = new Builder.from_resource("/org/dino-im/menu_conversation.ui"); + MenuModel menu = builder.get_object("menu_conversation") as MenuModel; + set_menu_model(menu); + + SimpleAction contact_details_action = new SimpleAction("contact_details", null); + contact_details_action.activate.connect(() => { + ContactDetails.Dialog contact_details_dialog = new ContactDetails.Dialog(stream_interactor, conversation); + contact_details_dialog.set_transient_for((Window) get_toplevel()); + contact_details_dialog.present(); + }); + GLib.Application.get_default().add_action(contact_details_action); + } + + public new void set_conversation(Conversation conversation) { + this.conversation = conversation; + } +} + +} diff --git a/main/src/ui/conversation_titlebar/occupants_entry.vala b/main/src/ui/conversation_titlebar/occupants_entry.vala new file mode 100644 index 00000000..c305bed7 --- /dev/null +++ b/main/src/ui/conversation_titlebar/occupants_entry.vala @@ -0,0 +1,50 @@ +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +class OccupantsEntry : Plugins.ConversationTitlebarEntry { + public override string id { get { return "occupants"; } } + + StreamInteractor stream_interactor; + Window window; + + public OccupantsEntry(StreamInteractor stream_interactor, Window window) { + this.stream_interactor = stream_interactor; + this.window = window; + } + + public override double order { get { return 3; } } + public override Plugins.ConversationTitlebarWidget get_widget() { + return new OccupantsWidget(stream_interactor, window) { visible=true }; + } +} + +class OccupantsWidget : MenuButton, Plugins.ConversationTitlebarWidget { + + private Conversation? conversation; + private StreamInteractor stream_interactor; + private Window window; + + public OccupantsWidget(StreamInteractor stream_interactor, Window window) { + + image = new Image.from_icon_name("system-users-symbolic", IconSize.MENU); + + this.stream_interactor = stream_interactor; + this.window = window; + set_use_popover(true); + } + + public new void set_conversation(Conversation conversation) { + this.conversation = conversation; + + visible = conversation.type_ == Conversation.Type.GROUPCHAT; + if (conversation.type_ == Conversation.Type.GROUPCHAT) { + OccupantMenu.View menu = new OccupantMenu.View(stream_interactor, window, conversation); + set_popover(menu); + } + } +} + +} diff --git a/main/src/ui/conversation_titlebar/view.vala b/main/src/ui/conversation_titlebar/view.vala new file mode 100644 index 00000000..7debddd6 --- /dev/null +++ b/main/src/ui/conversation_titlebar/view.vala @@ -0,0 +1,69 @@ +using Gtk; +using Gee; + +using Dino.Entities; + +namespace Dino.Ui { + +public class ConversationTitlebar : Gtk.HeaderBar { + + private StreamInteractor stream_interactor; + private Window window; + private Conversation? conversation; + private Gee.List<Plugins.ConversationTitlebarWidget> widgets = new ArrayList<Plugins.ConversationTitlebarWidget>(); + + public ConversationTitlebar(StreamInteractor stream_interactor, Window window) { + this.stream_interactor = stream_interactor; + this.window = window; + + show_close_button = true; + hexpand = true; + + Application app = GLib.Application.get_default() as Application; + app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor)); + app.plugin_registry.register_contact_titlebar_entry(new EncryptionEntry()); + app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor, window)); + + foreach(var e in app.plugin_registry.conversation_titlebar_entries) { + Plugins.ConversationTitlebarWidget widget = e.get_widget(); + widgets.add(widget); + pack_end(widget); + } + + stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { + Idle.add(() => { + if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { + update_subtitle(subject); + } + return false; + }); + }); + } + + public void initialize_for_conversation(Conversation conversation) { + this.conversation = conversation; + update_title(); + update_subtitle(); + + foreach (Plugins.ConversationTitlebarWidget widget in widgets) { + widget.set_conversation(conversation); + } + } + + private void update_title() { + set_title(Util.get_conversation_display_name(stream_interactor, conversation)); + } + + private void update_subtitle(string? subtitle = null) { + if (subtitle != null) { + set_subtitle(subtitle); + } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { + string subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); + set_subtitle(subject != "" ? subject : null); + } else { + set_subtitle(null); + } + } +} + +} diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala index 50e6b300..42ff3da6 100644 --- a/main/src/ui/occupant_menu/list.vala +++ b/main/src/ui/occupant_menu/list.vala @@ -14,7 +14,7 @@ public class List : Box { [GtkChild] public ListBox list_box; [GtkChild] private SearchEntry search_entry; - private Conversation? conversation; + private Conversation conversation; private string[]? filter_values; private HashMap<Jid, ListRow> rows = new HashMap<Jid, ListRow>(Jid.hash_func, Jid.equals_func); @@ -167,4 +167,4 @@ public class List : Box { } } -}
\ No newline at end of file +} |