aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-12-11 18:39:55 +0100
committerfiaxh <git@mx.ax.lt>2017-12-13 21:11:33 +0100
commitf25fadde2d6c9492b9cafe2cddbcc7b966942e47 (patch)
tree84b25287be10372933e2ea4f708231e9ec5e142a /main
parentfc0d7feb5aef16e0024cfeb73286038998e926d2 (diff)
downloaddino-f25fadde2d6c9492b9cafe2cddbcc7b966942e47.tar.gz
dino-f25fadde2d6c9492b9cafe2cddbcc7b966942e47.zip
Fallback display for all file types
Diffstat (limited to 'main')
-rw-r--r--main/CMakeLists.txt1
-rw-r--r--main/data/conversation_summary/message_item.ui1
-rw-r--r--main/src/ui/conversation_summary/conversation_item_skeleton.vala1
-rw-r--r--main/src/ui/conversation_summary/default_file_display.vala95
-rw-r--r--main/src/ui/conversation_summary/file_populator.vala129
-rw-r--r--main/src/ui/conversation_summary/image_display.vala130
6 files changed, 232 insertions, 125 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 876e4a66..4a799758 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -102,6 +102,7 @@ SOURCES
src/ui/conversation_summary/conversation_item_skeleton.vala
src/ui/conversation_summary/conversation_view.vala
src/ui/conversation_summary/date_separator_populator.vala
+ src/ui/conversation_summary/default_file_display.vala
src/ui/conversation_summary/default_message_display.vala
src/ui/conversation_summary/file_populator.vala
src/ui/conversation_summary/image_display.vala
diff --git a/main/data/conversation_summary/message_item.ui b/main/data/conversation_summary/message_item.ui
index a6937d10..dd982ca9 100644
--- a/main/data/conversation_summary/message_item.ui
+++ b/main/data/conversation_summary/message_item.ui
@@ -11,7 +11,6 @@
<property name="height_request">30</property>
<property name="margin_top">2</property>
<property name="width_request">30</property>
- <property name="visible">True</property>
<property name="yalign">0</property>
</object>
<packing>
diff --git a/main/src/ui/conversation_summary/conversation_item_skeleton.vala b/main/src/ui/conversation_summary/conversation_item_skeleton.vala
index aa18c9d8..585cfa7a 100644
--- a/main/src/ui/conversation_summary/conversation_item_skeleton.vala
+++ b/main/src/ui/conversation_summary/conversation_item_skeleton.vala
@@ -68,6 +68,7 @@ public class ConversationItemSkeleton : Grid {
private void setup(Plugins.MetaConversationItem item) {
update_time();
if (item.requires_avatar) {
+ image.visible = true;
Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(30, 30, image.scale_factor)).set_greyscale(item.dim).draw_jid(stream_interactor, item.jid, conversation.account));
}
if (item.requires_header) {
diff --git a/main/src/ui/conversation_summary/default_file_display.vala b/main/src/ui/conversation_summary/default_file_display.vala
new file mode 100644
index 00000000..413871ca
--- /dev/null
+++ b/main/src/ui/conversation_summary/default_file_display.vala
@@ -0,0 +1,95 @@
+using Gdk;
+using Gtk;
+
+using Dino.Entities;
+
+namespace Dino.Ui.ConversationSummary {
+
+public class DefaultFileDisplay : Plugins.MetaConversationItem {
+ public override Jid? jid { get; set; }
+ public override DateTime? sort_time { get; set; }
+ public override DateTime? display_time { get; set; }
+ public override Encryption? encryption { get; set; }
+ public override Entities.Message.Marked? mark { get; set; }
+
+ public override bool can_merge { get; set; default=true; }
+ public override bool requires_avatar { get; set; default=true; }
+ public override bool requires_header { get; set; default=true; }
+
+ private const int MAX_HEIGHT = 300;
+ private const int MAX_WIDTH = 600;
+
+ private StreamInteractor stream_interactor;
+ private FileTransfer file_transfer;
+
+ public DefaultFileDisplay(StreamInteractor stream_interactor, FileTransfer file_transfer) {
+ this.stream_interactor = stream_interactor;
+ this.file_transfer = file_transfer;
+
+ this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? new Jid.with_resource(file_transfer.account.bare_jid.to_string(), file_transfer.account.resourcepart) : file_transfer.counterpart;
+ this.sort_time = file_transfer.time;
+ this.seccondary_sort_indicator = file_transfer.id + 0.2903;
+ this.display_time = file_transfer.time;
+ this.encryption = file_transfer.encryption;
+ this.mark = file_to_message_state(file_transfer.state);
+ file_transfer.notify["state"].connect_after(() => {
+ this.mark = file_to_message_state(file_transfer.state);
+ });
+ }
+
+ public override Object? get_widget(Plugins.WidgetType widget_type) {
+ Box main_box = new Box(Orientation.HORIZONTAL, 4) { halign=Align.START, visible=true };
+ string? content_type = ContentType.from_mime_type(file_transfer.mime_type);
+ string? icon_name = ContentType.get_generic_icon_name(file_transfer.mime_type);
+ Image content_type_image = new Image.from_icon_name(icon_name, IconSize.DND) { visible=true };
+ main_box.add(content_type_image);
+
+ Box right_box = new Box(Orientation.VERTICAL, 0) { visible=true };
+ Label name_label = new Label(file_transfer.file_name) { xalign=0, yalign=0, visible=true};
+ right_box.add(name_label);
+ Label mime_label = new Label("<span size='small'>" + _("File") + ": " + file_transfer.mime_type + "</span>") { use_markup=true, xalign=0, yalign=1, visible=true};
+ mime_label.get_style_context().add_class("dim-label");
+ right_box.add(mime_label);
+ main_box.add(right_box);
+
+ EventBox event_box = new EventBox() { halign=Align.START, visible=true };
+ event_box.add(main_box);
+
+ event_box.enter_notify_event.connect((event) => {
+ event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.HAND2));
+ return false;
+ });
+ event_box.leave_notify_event.connect((event) => {
+ event.get_window().set_cursor(new Cursor.for_display(Gdk.Display.get_default(), CursorType.XTERM));
+ return false;
+ });
+ event_box.button_release_event.connect((event_button) => {
+ if (event_button.button == 1) {
+ try{
+ AppInfo.launch_default_for_uri("file://" + file_transfer.get_uri(), null);
+ } catch (Error err) {
+ print("Tryed to open " + file_transfer.get_uri());
+ }
+ }
+ return false;
+ });
+
+ return event_box;
+ }
+
+ private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
+ switch (state) {
+ case FileTransfer.State.IN_PROCESS:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.COMPLETE:
+ return Entities.Message.Marked.NONE;
+ case FileTransfer.State.NOT_STARTED:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.FAILED:
+ return Entities.Message.Marked.WONTSEND;
+ }
+ assert_not_reached();
+ }
+}
+
+}
diff --git a/main/src/ui/conversation_summary/file_populator.vala b/main/src/ui/conversation_summary/file_populator.vala
index 4dc6aaec..af7bc992 100644
--- a/main/src/ui/conversation_summary/file_populator.vala
+++ b/main/src/ui/conversation_summary/file_populator.vala
@@ -41,132 +41,13 @@ class FilePopulator : Plugins.ConversationItemPopulator, Object {
public void populate_between_widgets(Conversation conversation, DateTime from, DateTime to) { }
private void insert_file(FileTransfer transfer) {
+ Plugins.MetaConversationItem item = null;
if (transfer.mime_type != null && transfer.mime_type.has_prefix("image")) {
- item_collection.insert_item(new ImageItem(stream_interactor, transfer));
+ item = new ImageDisplay(stream_interactor, transfer);
+ } else {
+ item = new DefaultFileDisplay(stream_interactor, transfer);
}
- }
-}
-
-public class ImageItem : Plugins.MetaConversationItem {
- public override Jid? jid { get; set; }
- public override DateTime? sort_time { get; set; }
- public override DateTime? display_time { get; set; }
- public override Encryption? encryption { get; set; }
- public override Entities.Message.Marked? mark { get; set; }
-
- public override bool can_merge { get; set; default=true; }
- public override bool requires_avatar { get; set; default=true; }
- public override bool requires_header { get; set; default=true; }
-
- private const int MAX_HEIGHT = 300;
- private const int MAX_WIDTH = 600;
-
- private StreamInteractor stream_interactor;
- private FileTransfer file_transfer;
-
- public ImageItem(StreamInteractor stream_interactor, FileTransfer file_transfer) {
- this.stream_interactor = stream_interactor;
- this.file_transfer = file_transfer;
-
- this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? new Jid.with_resource(file_transfer.account.bare_jid.to_string(), file_transfer.account.resourcepart) : file_transfer.counterpart;
- this.sort_time = file_transfer.time;
- this.seccondary_sort_indicator = file_transfer.id + 0.2903;
- this.display_time = file_transfer.time;
- this.encryption = file_transfer.encryption;
- this.mark = file_to_message_state(file_transfer.state);
- file_transfer.notify["state"].connect_after(() => {
- this.mark = file_to_message_state(file_transfer.state);
- });
- }
-
- public override Object? get_widget(Plugins.WidgetType widget_type) {
- Image image = new Image() { halign=Align.START, visible = true };
- Gdk.Pixbuf pixbuf;
- try {
- pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri());
- } catch (Error error) {
- return null;
- }
-
- int max_scaled_height = MAX_HEIGHT * image.scale_factor;
- if (pixbuf.height > max_scaled_height) {
- pixbuf = pixbuf.scale_simple((int) ((double) max_scaled_height / pixbuf.height * pixbuf.width), max_scaled_height, Gdk.InterpType.BILINEAR);
- }
- int max_scaled_width = MAX_WIDTH * image.scale_factor;
- if (pixbuf.width > max_scaled_width) {
- pixbuf = pixbuf.scale_simple(max_scaled_width, (int) ((double) max_scaled_width / pixbuf.width * pixbuf.height), Gdk.InterpType.BILINEAR);
- }
- pixbuf = AvatarGenerator.crop_corners(pixbuf, 3 * image.get_scale_factor());
- Util.image_set_from_scaled_pixbuf(image, pixbuf);
- Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
-
- Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
- Widget toolbar = builder.get_object("main") as Widget;
- Util.force_background(toolbar, "rgba(0, 0, 0, 0.5)");
- Util.force_css(toolbar, "* { padding: 3px; border-radius: 3px; }");
-
- Label url_label = builder.get_object("url_label") as Label;
- Util.force_color(url_label, "#eee");
- file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); });
- update_info(url_label, file_transfer.info);
-
- Image copy_image = builder.get_object("copy_image") as Image;
- Util.force_css(copy_image, "*:not(:hover) { color: #eee; }");
- Button copy_button = builder.get_object("copy_button") as Button;
- Util.force_css(copy_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
- copy_button.clicked.connect(() => {
- if (file_transfer.info != null) Clipboard.get_default(Gdk.Display.get_default()).set_text(file_transfer.info, file_transfer.info.length);
- });
-
- Image open_image = builder.get_object("open_image") as Image;
- Util.force_css(open_image, "*:not(:hover) { color: #eee; }");
- Button open_button = builder.get_object("open_button") as Button;
- Util.force_css(open_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
- open_button.clicked.connect(() => {
- try{
- AppInfo.launch_default_for_uri(file_transfer.info, null);
- } catch (Error err) {
- print("Tryed to open " + file_transfer.info);
- }
- });
-
- Revealer toolbar_revealer = new Revealer() { transition_type=RevealerTransitionType.CROSSFADE, transition_duration=400, visible=true };
- toolbar_revealer.add(toolbar);
-
- Grid grid = new Grid() { visible=true };
- grid.attach(toolbar_revealer, 0, 0, 1, 1);
- grid.attach(image, 0, 0, 1, 1);
-
- EventBox event_box = new EventBox() { halign=Align.START, visible=true };
- event_box.add(grid);
- event_box.enter_notify_event.connect(() => { toolbar_revealer.reveal_child = true; return false; });
- event_box.leave_notify_event.connect(() => { toolbar_revealer.reveal_child = false; return false; });
-
- return event_box;
- }
-
- private void update_info(Label url_label, string? info) {
- string url = info ?? "";
- if (url.has_prefix("https://")) url = url.substring(8);
- if (url.has_prefix("http://")) url = url.substring(7);
- if (url.has_prefix("www.")) url = url.substring(4);
- string[] slash_split = url.split("/");
- if (slash_split.length > 2) url = slash_split[0] + "/…/" + slash_split[slash_split.length - 1];
- url_label.label = url;
- }
-
- private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
- switch (state) {
- case FileTransfer.State.IN_PROCESS:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.COMPLETE:
- return Entities.Message.Marked.NONE;
- case FileTransfer.State.NOT_STARTED:
- return Entities.Message.Marked.UNSENT;
- case FileTransfer.State.FAILED:
- return Entities.Message.Marked.WONTSEND;
- }
- assert_not_reached();
+ item_collection.insert_item(item);
}
}
diff --git a/main/src/ui/conversation_summary/image_display.vala b/main/src/ui/conversation_summary/image_display.vala
index e69de29b..3f1b0bd6 100644
--- a/main/src/ui/conversation_summary/image_display.vala
+++ b/main/src/ui/conversation_summary/image_display.vala
@@ -0,0 +1,130 @@
+using Gtk;
+
+using Dino.Entities;
+
+namespace Dino.Ui.ConversationSummary {
+
+public class ImageDisplay : Plugins.MetaConversationItem {
+ public override Jid? jid { get; set; }
+ public override DateTime? sort_time { get; set; }
+ public override DateTime? display_time { get; set; }
+ public override Encryption? encryption { get; set; }
+ public override Entities.Message.Marked? mark { get; set; }
+
+ public override bool can_merge { get; set; default=true; }
+ public override bool requires_avatar { get; set; default=true; }
+ public override bool requires_header { get; set; default=true; }
+
+ private const int MAX_HEIGHT = 300;
+ private const int MAX_WIDTH = 600;
+
+ private StreamInteractor stream_interactor;
+ private FileTransfer file_transfer;
+
+ public ImageDisplay(StreamInteractor stream_interactor, FileTransfer file_transfer) {
+ this.stream_interactor = stream_interactor;
+ this.file_transfer = file_transfer;
+
+ this.jid = file_transfer.direction == FileTransfer.DIRECTION_SENT ? new Jid.with_resource(file_transfer.account.bare_jid.to_string(), file_transfer.account.resourcepart) : file_transfer.counterpart;
+ this.sort_time = file_transfer.time;
+ this.seccondary_sort_indicator = file_transfer.id + 0.2903;
+ this.display_time = file_transfer.time;
+ this.encryption = file_transfer.encryption;
+ this.mark = file_to_message_state(file_transfer.state);
+ file_transfer.notify["state"].connect_after(() => {
+ this.mark = file_to_message_state(file_transfer.state);
+ });
+ }
+
+ public override Object? get_widget(Plugins.WidgetType widget_type) {
+ Image image = new Image() { halign=Align.START, visible = true };
+ Gdk.Pixbuf pixbuf;
+ try {
+ pixbuf = new Gdk.Pixbuf.from_file(file_transfer.get_uri());
+ } catch (Error error) {
+ return null;
+ }
+
+ int max_scaled_height = MAX_HEIGHT * image.scale_factor;
+ if (pixbuf.height > max_scaled_height) {
+ pixbuf = pixbuf.scale_simple((int) ((double) max_scaled_height / pixbuf.height * pixbuf.width), max_scaled_height, Gdk.InterpType.BILINEAR);
+ }
+ int max_scaled_width = MAX_WIDTH * image.scale_factor;
+ if (pixbuf.width > max_scaled_width) {
+ pixbuf = pixbuf.scale_simple(max_scaled_width, (int) ((double) max_scaled_width / pixbuf.width * pixbuf.height), Gdk.InterpType.BILINEAR);
+ }
+ pixbuf = AvatarGenerator.crop_corners(pixbuf, 3 * image.get_scale_factor());
+ Util.image_set_from_scaled_pixbuf(image, pixbuf);
+ Util.force_css(image, "* { box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1); margin: 2px; border-radius: 3px; }");
+
+ Builder builder = new Builder.from_resource("/im/dino/Dino/conversation_summary/image_toolbar.ui");
+ Widget toolbar = builder.get_object("main") as Widget;
+ Util.force_background(toolbar, "rgba(0, 0, 0, 0.5)");
+ Util.force_css(toolbar, "* { padding: 3px; border-radius: 3px; }");
+
+ Label url_label = builder.get_object("url_label") as Label;
+ Util.force_color(url_label, "#eee");
+ file_transfer.notify["info"].connect_after(() => { update_info(url_label, file_transfer.info); });
+ update_info(url_label, file_transfer.info);
+
+ Image copy_image = builder.get_object("copy_image") as Image;
+ Util.force_css(copy_image, "*:not(:hover) { color: #eee; }");
+ Button copy_button = builder.get_object("copy_button") as Button;
+ Util.force_css(copy_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
+ copy_button.clicked.connect(() => {
+ if (file_transfer.info != null) Clipboard.get_default(Gdk.Display.get_default()).set_text(file_transfer.info, file_transfer.info.length);
+ });
+
+ Image open_image = builder.get_object("open_image") as Image;
+ Util.force_css(open_image, "*:not(:hover) { color: #eee; }");
+ Button open_button = builder.get_object("open_button") as Button;
+ Util.force_css(open_button, "*:hover { background-color: rgba(255,255,255,0.3); border-color: transparent; }");
+ open_button.clicked.connect(() => {
+ try{
+ AppInfo.launch_default_for_uri(file_transfer.info, null);
+ } catch (Error err) {
+ print("Tryed to open " + file_transfer.info);
+ }
+ });
+
+ Revealer toolbar_revealer = new Revealer() { transition_type=RevealerTransitionType.CROSSFADE, transition_duration=400, visible=true };
+ toolbar_revealer.add(toolbar);
+
+ Grid grid = new Grid() { visible=true };
+ grid.attach(toolbar_revealer, 0, 0, 1, 1);
+ grid.attach(image, 0, 0, 1, 1);
+
+ EventBox event_box = new EventBox() { halign=Align.START, visible=true };
+ event_box.add(grid);
+ event_box.enter_notify_event.connect(() => { toolbar_revealer.reveal_child = true; return false; });
+ event_box.leave_notify_event.connect(() => { toolbar_revealer.reveal_child = false; return false; });
+
+ return event_box;
+ }
+
+ private void update_info(Label url_label, string? info) {
+ string url = info ?? "";
+ if (url.has_prefix("https://")) url = url.substring(8);
+ if (url.has_prefix("http://")) url = url.substring(7);
+ if (url.has_prefix("www.")) url = url.substring(4);
+ string[] slash_split = url.split("/");
+ if (slash_split.length > 2) url = slash_split[0] + "/…/" + slash_split[slash_split.length - 1];
+ url_label.label = url;
+ }
+
+ private Entities.Message.Marked file_to_message_state(FileTransfer.State state) {
+ switch (state) {
+ case FileTransfer.State.IN_PROCESS:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.COMPLETE:
+ return Entities.Message.Marked.NONE;
+ case FileTransfer.State.NOT_STARTED:
+ return Entities.Message.Marked.UNSENT;
+ case FileTransfer.State.FAILED:
+ return Entities.Message.Marked.WONTSEND;
+ }
+ assert_not_reached();
+ }
+}
+
+}