From 5ebdbf8a8b902faab2da8039edf4413ebe4df6e0 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Tue, 6 Aug 2019 16:47:06 +0200 Subject: [PATCH] Use own file type icons --- main/CMakeLists.txt | 9 ++++ .../icons/dino-file-document-symbolic.svg | 6 +++ .../icons/dino-file-download-symbolic.svg | 5 +++ main/data/icons/dino-file-image-symbolic.svg | 6 +++ main/data/icons/dino-file-music-symbolic.svg | 7 +++ main/data/icons/dino-file-symbolic.svg | 4 ++ main/data/icons/dino-file-table-symbolic.svg | 10 +++++ main/data/icons/dino-file-video-symbolic.svg | 5 +++ main/data/icons/dino-qr-code-symbolic.svg | 15 ++++++- .../ui/conversation_summary/file_widget.vala | 43 ++++++++++++------- 10 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 main/data/icons/dino-file-document-symbolic.svg create mode 100644 main/data/icons/dino-file-download-symbolic.svg create mode 100644 main/data/icons/dino-file-image-symbolic.svg create mode 100644 main/data/icons/dino-file-music-symbolic.svg create mode 100644 main/data/icons/dino-file-symbolic.svg create mode 100644 main/data/icons/dino-file-table-symbolic.svg create mode 100644 main/data/icons/dino-file-video-symbolic.svg diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index c874f34d..ee254836 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -24,6 +24,15 @@ set(RESOURCE_LIST icons/im.dino.Dino-symbolic.svg icons/dino-tick-symbolic.svg + icons/dino-file-document-symbolic.svg + icons/dino-file-download-symbolic.svg + icons/dino-file-image-symbolic.svg + icons/dino-file-music-symbolic.svg + icons/dino-file-pdf-symbolic.svg + icons/dino-file-symbolic.svg + icons/dino-file-table-symbolic.svg + icons/dino-file-video-symbolic.svg + add_conversation/add_contact_dialog.ui add_conversation/add_groupchat_dialog.ui add_conversation/conference_details_fragment.ui diff --git a/main/data/icons/dino-file-document-symbolic.svg b/main/data/icons/dino-file-document-symbolic.svg new file mode 100644 index 00000000..8901a817 --- /dev/null +++ b/main/data/icons/dino-file-document-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/main/data/icons/dino-file-download-symbolic.svg b/main/data/icons/dino-file-download-symbolic.svg new file mode 100644 index 00000000..5dada23d --- /dev/null +++ b/main/data/icons/dino-file-download-symbolic.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/main/data/icons/dino-file-image-symbolic.svg b/main/data/icons/dino-file-image-symbolic.svg new file mode 100644 index 00000000..0cae7f18 --- /dev/null +++ b/main/data/icons/dino-file-image-symbolic.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/main/data/icons/dino-file-music-symbolic.svg b/main/data/icons/dino-file-music-symbolic.svg new file mode 100644 index 00000000..ef7ae56c --- /dev/null +++ b/main/data/icons/dino-file-music-symbolic.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/main/data/icons/dino-file-symbolic.svg b/main/data/icons/dino-file-symbolic.svg new file mode 100644 index 00000000..748c4e7b --- /dev/null +++ b/main/data/icons/dino-file-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/main/data/icons/dino-file-table-symbolic.svg b/main/data/icons/dino-file-table-symbolic.svg new file mode 100644 index 00000000..c04b1244 --- /dev/null +++ b/main/data/icons/dino-file-table-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/main/data/icons/dino-file-video-symbolic.svg b/main/data/icons/dino-file-video-symbolic.svg new file mode 100644 index 00000000..c4afc836 --- /dev/null +++ b/main/data/icons/dino-file-video-symbolic.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/main/data/icons/dino-qr-code-symbolic.svg b/main/data/icons/dino-qr-code-symbolic.svg index 0465fac3..92394eca 100644 --- a/main/data/icons/dino-qr-code-symbolic.svg +++ b/main/data/icons/dino-qr-code-symbolic.svg @@ -1,4 +1,15 @@ - - + + + + + + + + + + + + + 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 = "" + _("%s file").printf(mime_caps) + ""; + mime_label.label = "" + mime_description + ""; 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 = "" + _("%s file offered: %s").printf(mime_caps, get_size_string(file_transfer.size)) + ""; + if (mime_description != null) { + mime_label.label = "" + _("%s offered: %s").printf(mime_description, get_size_string(file_transfer.size)) + ""; } else if (file_transfer.size != -1) { mime_label.label = "" + _("File offered: %s").printf(get_size_string(file_transfer.size)) + ""; } 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";