aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui')
-rw-r--r--main/src/ui/application.vala49
-rw-r--r--main/src/ui/conversation_selector/conversation_selector.vala2
-rw-r--r--main/src/ui/conversation_summary/file_widget.vala43
-rw-r--r--main/src/ui/manage_accounts/add_account_dialog.vala17
-rw-r--r--main/src/ui/manage_accounts/dialog.vala4
-rw-r--r--main/src/ui/notifications.vala18
-rw-r--r--main/src/ui/unified_window_controller.vala2
7 files changed, 93 insertions, 42 deletions
diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala
index 57ebe11a..d5ec0170 100644
--- a/main/src/ui/application.vala
+++ b/main/src/ui/application.vala
@@ -44,23 +44,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
public void handle_uri(string jid, string query, Gee.Map<string, string> options) {
switch (query) {
case "join":
- Dialog dialog = new Dialog.with_buttons(_("Join Conference"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL);
- dialog.modal = true;
- Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button;
- ok_button.get_style_context().add_class("suggested-action");
- ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor) { ok_button=ok_button };
- conference_fragment.jid = jid;
- Box content_area = dialog.get_content_area();
- content_area.add(conference_fragment);
- dialog.response.connect((response_id) => {
- if (response_id == ResponseType.OK) {
- stream_interactor.get_module(MucManager.IDENTITY).join(conference_fragment.account, new Jid(conference_fragment.jid), conference_fragment.nick, conference_fragment.password);
- dialog.destroy();
- } else if (response_id == ResponseType.CANCEL) {
- dialog.destroy();
- }
- });
- dialog.present();
+ show_join_muc_dialog(null, new Jid(jid));
break;
case "message":
Gee.List<Account> accounts = stream_interactor.get_accounts();
@@ -133,6 +117,14 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
add_action(conference_action);
set_accels_for_action("app.add_conference", new string[]{"<Ctrl>G"});
+ SimpleAction accept_muc_invite_action = new SimpleAction("open-muc-join", VariantType.INT32);
+ accept_muc_invite_action.activate.connect((variant) => {
+ Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32());
+ if (conversation == null) return;
+ show_join_muc_dialog(conversation.account, conversation.counterpart);
+ });
+ add_action(accept_muc_invite_action);
+
SimpleAction loop_conversations_action = new SimpleAction("loop_conversations", null);
loop_conversations_action.activate.connect(() => { window.loop_conversations(false); });
add_action(loop_conversations_action);
@@ -161,5 +153,28 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
dialog.set_transient_for(get_active_window());
dialog.present();
}
+
+ private void show_join_muc_dialog(Account? account, Jid jid) {
+ Dialog dialog = new Dialog.with_buttons(_("Join Conference"), window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.USE_HEADER_BAR, _("Join"), ResponseType.OK, _("Cancel"), ResponseType.CANCEL);
+ dialog.modal = true;
+ Button ok_button = dialog.get_widget_for_response(ResponseType.OK) as Button;
+ ok_button.get_style_context().add_class("suggested-action");
+ ConferenceDetailsFragment conference_fragment = new ConferenceDetailsFragment(stream_interactor) { ok_button=ok_button };
+ conference_fragment.jid = jid.to_string();
+ if (account != null) {
+ conference_fragment.account = account;
+ }
+ Box content_area = dialog.get_content_area();
+ content_area.add(conference_fragment);
+ dialog.response.connect((response_id) => {
+ if (response_id == ResponseType.OK) {
+ stream_interactor.get_module(MucManager.IDENTITY).join(conference_fragment.account, new Jid(conference_fragment.jid), conference_fragment.nick, conference_fragment.password);
+ dialog.destroy();
+ } else if (response_id == ResponseType.CANCEL) {
+ dialog.destroy();
+ }
+ });
+ dialog.present();
+ }
}
diff --git a/main/src/ui/conversation_selector/conversation_selector.vala b/main/src/ui/conversation_selector/conversation_selector.vala
index 66cb3495..869f6403 100644
--- a/main/src/ui/conversation_selector/conversation_selector.vala
+++ b/main/src/ui/conversation_selector/conversation_selector.vala
@@ -93,7 +93,7 @@ public class ConversationSelector : ListBox {
private void remove_conversation(Conversation conversation) {
select_fallback_conversation(conversation);
- if (rows.has_key(conversation) && !conversation.active) {
+ if (rows.has_key(conversation)) {
remove(rows[conversation]);
rows.unset(conversation);
}
diff --git a/main/src/ui/conversation_summary/file_widget.vala b/main/src/ui/conversation_summary/file_widget.vala
index 19b89906..f03096fe 100644
--- a/main/src/ui/conversation_summary/file_widget.vala
+++ b/main/src/ui/conversation_summary/file_widget.vala
@@ -23,7 +23,6 @@ public class FileWidget : Box {
// default box
private Box main_box;
- private string? icon_name;
private Image content_type_image;
private Image download_image;
private Spinner spinner;
@@ -135,10 +134,11 @@ public class FileWidget : Box {
}
private Widget getDefaultWidget(FileTransfer file_transfer) {
- main_box = new Box(Orientation.HORIZONTAL, 4) { halign=Align.FILL, hexpand=true, visible=true };
- icon_name = ContentType.get_generic_icon_name(file_transfer.mime_type ?? "application/octet-stream");
- content_type_image = new Image.from_icon_name(icon_name + "-symbolic", IconSize.DND) { visible=true };
- download_image = new Image.from_icon_name("folder-download-symbolic", IconSize.MENU) { visible=true };
+ string icon_name = get_file_icon_name(file_transfer.mime_type);
+
+ main_box = new Box(Orientation.HORIZONTAL, 10) { halign=Align.FILL, hexpand=true, visible=true };
+ content_type_image = new Image.from_icon_name(icon_name, IconSize.DND) { opacity=0.5, visible=true };
+ download_image = new Image.from_icon_name("dino-file-download-symbolic", IconSize.DND) { opacity=0.7, visible=true };
spinner = new Spinner() { active=true, visible=true };
EventBox stack_event_box = new EventBox() { visible=true };
@@ -173,10 +173,9 @@ public class FileWidget : Box {
Timeout.add(20, () => {
if (pointer_inside) {
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
+ content_type_image.opacity = 0.7;
if (file_transfer.state == FileTransfer.State.NOT_STARTED) {
image_stack.set_visible_child_name("download_image");
- } else if (file_transfer.state == FileTransfer.State.COMPLETE) {
- content_type_image.opacity = 1;
}
}
return false;
@@ -191,10 +190,9 @@ public class FileWidget : Box {
Timeout.add(20, () => {
if (!pointer_inside) {
event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
+ content_type_image.opacity = 0.5;
if (file_transfer.state == FileTransfer.State.NOT_STARTED) {
image_stack.set_visible_child_name("content_type_image");
- } else if (file_transfer.state == FileTransfer.State.COMPLETE) {
- content_type_image.opacity = 0.5;
}
}
return false;
@@ -249,14 +247,11 @@ public class FileWidget : Box {
state = State.IMAGE;
}
- content_type_image.opacity = 0.5;
-
- var mime_split = (file_transfer.mime_type ?? "").split("/");
- var mime_caps = mime_split.length == 2 ? mime_split[1].up() : file_transfer.mime_type;
+ string? mime_description = file_transfer.mime_type != null ? ContentType.get_description(file_transfer.mime_type) : null;
switch (file_transfer.state) {
case FileTransfer.State.COMPLETE:
- mime_label.label = "<span size='small'>" + _("%s file").printf(mime_caps) + "</span>";
+ mime_label.label = "<span size='small'>" + mime_description + "</span>";
image_stack.set_visible_child_name("content_type_image");
break;
case FileTransfer.State.IN_PROGRESS:
@@ -264,8 +259,8 @@ public class FileWidget : Box {
image_stack.set_visible_child_name("spinner");
break;
case FileTransfer.State.NOT_STARTED:
- if (mime_caps != null) {
- mime_label.label = "<span size='small'>" + _("%s file offered: %s").printf(mime_caps, get_size_string(file_transfer.size)) + "</span>";
+ if (mime_description != null) {
+ mime_label.label = "<span size='small'>" + _("%s offered: %s").printf(mime_description, get_size_string(file_transfer.size)) + "</span>";
} else if (file_transfer.size != -1) {
mime_label.label = "<span size='small'>" + _("File offered: %s").printf(get_size_string(file_transfer.size)) + "</span>";
} else {
@@ -280,6 +275,22 @@ public class FileWidget : Box {
}
}
+ private static string get_file_icon_name(string? mime_type) {
+ if (mime_type == null) return "dino-file-symbolic";
+
+ string generic_icon_name = ContentType.get_generic_icon_name(mime_type) ?? "";
+ switch (generic_icon_name) {
+ case "audio-x-generic": return "dino-file-music-symbolic";
+ case "image-x-generic": return "dino-file-image-symbolic";
+ case "text-x-generic": return "dino-file-document-symbolic";
+ case "text-x-generic-template": return "dino-file-document-symbolic";
+ case "video-x-generic": return "dino-file-video-symbolic";
+ case "x-office-document": return "dino-file-document-symbolic";
+ case "x-office-spreadsheet": return "dino-file-table-symbolic";
+ default: return "dino-file-symbolic";
+ }
+ }
+
private static string get_size_string(int size) {
if (size < 1024) {
return @"$(size) B";
diff --git a/main/src/ui/manage_accounts/add_account_dialog.vala b/main/src/ui/manage_accounts/add_account_dialog.vala
index 558738aa..cefc3261 100644
--- a/main/src/ui/manage_accounts/add_account_dialog.vala
+++ b/main/src/ui/manage_accounts/add_account_dialog.vala
@@ -70,12 +70,14 @@ public class AddAccountDialog : Gtk.Dialog {
};
private StreamInteractor stream_interactor;
+ private Database db;
private HashMap<ListBoxRow, string> list_box_jids = new HashMap<ListBoxRow, string>();
private Jid? server_jid = null;
private Xep.InBandRegistration.Form? form = null;
- public AddAccountDialog(StreamInteractor stream_interactor) {
+ public AddAccountDialog(StreamInteractor stream_interactor, Database db) {
this.stream_interactor = stream_interactor;
+ this.db = db;
this.title = _("Add Account");
// Sign in - Jid
@@ -258,8 +260,8 @@ public class AddAccountDialog : Gtk.Dialog {
break;
}
} else {
+ add_activate_account(account);
show_success();
- added(account);
}
}
@@ -343,9 +345,9 @@ public class AddAccountDialog : Gtk.Dialog {
case "password": password = field.get_value_string(); break;
}
}
- Account account = new Account(new Jid(username + "@" + server_jid.domainpart), null, password, null);
+ Account account = new Account(new Jid.components(username, server_jid.domainpart, null), null, password, null);
+ add_activate_account(account);
show_success();
- added(account);
} else {
display_notification(error);
}
@@ -360,6 +362,13 @@ public class AddAccountDialog : Gtk.Dialog {
});
}
+ private void add_activate_account(Account account) {
+ account.enabled = true;
+ account.persist(db);
+ stream_interactor.connect_account(account);
+ added(account);
+ }
+
private void animate_window_resize(Widget widget) { // TODO code duplication
int def_height, curr_width, curr_height;
get_size(out curr_width, out curr_height);
diff --git a/main/src/ui/manage_accounts/dialog.vala b/main/src/ui/manage_accounts/dialog.vala
index bcc0f017..e605e083 100644
--- a/main/src/ui/manage_accounts/dialog.vala
+++ b/main/src/ui/manage_accounts/dialog.vala
@@ -108,10 +108,9 @@ public class Dialog : Gtk.Dialog {
}
private void show_add_account_dialog() {
- AddAccountDialog add_account_dialog = new AddAccountDialog(stream_interactor);
+ AddAccountDialog add_account_dialog = new AddAccountDialog(stream_interactor, db);
add_account_dialog.set_transient_for(this);
add_account_dialog.added.connect((account) => {
- account.persist(db);
AccountRow account_item = add_account(account);
account_list.select_row(account_item);
account_list.queue_draw();
@@ -174,7 +173,6 @@ public class Dialog : Gtk.Dialog {
private bool change_account_state(bool state) {
selected_account.enabled = state;
if (state) {
- if (selected_account.enabled) account_disabled(selected_account);
account_enabled(selected_account);
} else {
account_disabled(selected_account);
diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala
index 78e8f47e..b8792bee 100644
--- a/main/src/ui/notifications.vala
+++ b/main/src/ui/notifications.vala
@@ -44,6 +44,7 @@ public class Notifications : Object {
stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((content_item, conversation) => notify_content_item.begin(content_item, conversation));
stream_interactor.get_module(NotificationEvents.IDENTITY).notify_subscription_request.connect(notify_subscription_request);
stream_interactor.get_module(NotificationEvents.IDENTITY).notify_connection_error.connect(notify_connection_error);
+ stream_interactor.get_module(NotificationEvents.IDENTITY).notify_muc_invite.connect(on_invite_received);
}
private async void notify_content_item(ContentItem content_item, Conversation conversation) {
@@ -117,6 +118,23 @@ public class Notifications : Object {
window.get_application().send_notification(account.id.to_string() + "-connection-error", notification);
}
+ private async void on_invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason) {
+ string display_name = Util.get_display_name(stream_interactor, from_jid, account);
+ string display_room = room_jid.bare_jid.to_string();
+ Notification notification = new Notification(_("Invitation to %s").printf(display_room));
+ string body = _("%s invited you to %s").printf(display_name, display_room);
+ notification.set_body(body);
+
+ Cairo.ImageSurface jid_avatar = yield (new AvatarGenerator(40, 40)).draw_jid(stream_interactor, from_jid, account);
+ notification.set_icon(get_pixbuf_icon(jid_avatar));
+
+ Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(room_jid, account, Conversation.Type.GROUPCHAT);
+ notification.set_default_action_and_target_value("app.open-muc-join", new Variant.int32(conversation.id));
+ notification.add_button_with_target_value(_("Deny"), "app.deny-invite", conversation.id);
+ notification.add_button_with_target_value(_("Accept"), "app.open-muc-join", conversation.id);
+ window.get_application().send_notification(null, notification);
+ }
+
private Icon get_pixbuf_icon(Cairo.ImageSurface surface) throws Error {
Gdk.Pixbuf avatar = Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height());
uint8[] buffer;
diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala
index dd5ed52d..1ca3daae 100644
--- a/main/src/ui/unified_window_controller.vala
+++ b/main/src/ui/unified_window_controller.vala
@@ -76,7 +76,7 @@ public class UnifiedWindowController : Object {
});
window.welcome_placeholder.primary_button.clicked.connect(() => {
- ManageAccounts.AddAccountDialog dialog = new ManageAccounts.AddAccountDialog(stream_interactor);
+ ManageAccounts.AddAccountDialog dialog = new ManageAccounts.AddAccountDialog(stream_interactor, db);
dialog.set_transient_for(app.get_active_window());
dialog.present();
});