Commit 9c813eaa authored by Michael Gratton's avatar Michael Gratton 🤞

Replace Gtk.IconView with FlowBox for displaying email attachments.

parent a2644f24
......@@ -390,6 +390,7 @@ src/mailer/main.vala
[type: gettext/glade]ui/composer-menus.ui
[type: gettext/glade]ui/composer-widget.ui
[type: gettext/glade]ui/conversation-email.ui
[type: gettext/glade]ui/conversation-email-attachment-view.ui
[type: gettext/glade]ui/conversation-email-menus.ui
[type: gettext/glade]ui/conversation-message.ui
[type: gettext/glade]ui/conversation-message-menus.ui
......
......@@ -1955,8 +1955,7 @@ public class GearyController : Geary.BaseObject {
}
}
private void on_attachments_activated(
Gee.Collection<ConversationEmail.AttachmentInfo> attachments) {
private void on_attachments_activated(Gee.Collection<Geary.Attachment> attachments) {
if (GearyApplication.instance.config.ask_open_attachment) {
QuestionDialog ask_to_open = new QuestionDialog.with_checkbox(main_window,
_("Are you sure you want to open these attachments?"),
......@@ -1969,9 +1968,17 @@ public class GearyController : Geary.BaseObject {
GearyApplication.instance.config.ask_open_attachment = !ask_to_open.is_checked;
}
foreach (ConversationEmail.AttachmentInfo info in attachments) {
if (info.app == null) {
string content_type = info.attachment.content_type.get_mime_type();
foreach (Geary.Attachment attachment in attachments) {
string gio_content_type = ContentType.from_mime_type(
attachment.content_type.get_mime_type()
);
AppInfo? app = null;
if (!ContentType.can_be_executable(gio_content_type) &&
!ContentType.is_unknown(gio_content_type)) {
app = AppInfo.get_default_for_type(gio_content_type, false);
}
if (app == null) {
string content_type = attachment.content_type.get_mime_type();
Gtk.AppChooserDialog app_chooser =
new Gtk.AppChooserDialog.for_content_type(
this.main_window,
......@@ -1979,21 +1986,18 @@ public class GearyController : Geary.BaseObject {
content_type
);
if (app_chooser.run() == Gtk.ResponseType.OK) {
info.app = app_chooser.get_app_info();
app = app_chooser.get_app_info();
}
app_chooser.hide();
}
if (info.app != null) {
if (app != null) {
List<File> files = new List<File>();
files.append(info.attachment.file);
files.append(attachment.file);
try {
info.app.launch(files, null);
app.launch(files, null);
} catch (Error error) {
warning(
"Failed to launch %s: %s\n",
info.app.get_name(),
error.message
);
warning("Failed to launch %s: %s\n",
app.get_name(), error.message);
}
}
}
......@@ -2016,11 +2020,7 @@ public class GearyController : Geary.BaseObject {
: Gtk.FileChooserConfirmation.SELECT_AGAIN;
}
private void on_save_attachments(
Gee.Collection<ConversationEmail.AttachmentInfo> attachments) {
if (attachments.size == 0)
return;
private void on_save_attachments(Gee.Collection<Geary.Attachment> attachments) {
Gtk.FileChooserAction action = (attachments.size == 1)
? Gtk.FileChooserAction.SAVE
: Gtk.FileChooserAction.SELECT_FOLDER;
......@@ -2029,10 +2029,10 @@ public class GearyController : Geary.BaseObject {
if (last_save_directory != null)
dialog.set_current_folder(last_save_directory.get_path());
if (attachments.size == 1) {
Gee.Iterator<ConversationEmail.AttachmentInfo> it = attachments.iterator();
Gee.Iterator<Geary.Attachment> it = attachments.iterator();
it.next();
ConversationEmail.AttachmentInfo info = it.get();
dialog.set_current_name(info.attachment.file.get_basename());
Geary.Attachment attachment = it.get();
dialog.set_current_name(attachment.file.get_basename());
dialog.set_do_overwrite_confirmation(true);
// use custom overwrite confirmation so it looks consistent whether one or many
// attachments are being saved
......@@ -2057,9 +2057,9 @@ public class GearyController : Geary.BaseObject {
debug("Saving attachments to %s", destination.get_path());
// Save each one, checking for overwrite only if multiple attachments are being written
foreach (ConversationEmail.AttachmentInfo info in attachments) {
File source_file = info.attachment.file;
File dest_file = (attachments.size == 1) ? destination : destination.get_child(info.attachment.file.get_basename());
foreach (Geary.Attachment attachment in attachments) {
File source_file = attachment.file;
File dest_file = (attachments.size == 1) ? destination : destination.get_child(attachment.file.get_basename());
if (attachments.size > 1 && dest_file.query_exists() && !do_overwrite_confirmation(dest_file))
return;
......
......@@ -9,6 +9,7 @@ set(RESOURCE_LIST
STRIPBLANKS "composer-menus.ui"
STRIPBLANKS "composer-widget.ui"
STRIPBLANKS "conversation-email.ui"
STRIPBLANKS "conversation-email-attachment-view.ui"
STRIPBLANKS "conversation-email-menus.ui"
STRIPBLANKS "conversation-message.ui"
STRIPBLANKS "conversation-message-menus.ui"
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.14"/>
<template class="ConversationEmailAttachmentView" parent="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkImage" id="icon">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixel_size">32</property>
<property name="icon_name">x-office-document</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="height">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="filename">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="label">filename.ext</property>
<property name="ellipsize">middle</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="description">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">start</property>
<property name="label">type (size)</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<requires lib="gtk+" version="3.14"/>
<template class="ConversationEmail" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
......@@ -109,17 +109,8 @@
</packing>
</child>
</object>
<object class="GtkListStore" id="attachments_model">
<columns>
<!-- column-name icon -->
<column type="GdkPixbuf"/>
<!-- column-name label -->
<column type="gchararray"/>
<!-- column-name attachment_info -->
<column type="GObject"/>
</columns>
</object>
<object class="GtkGrid" id="attachments">
<property name="name">box</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
......@@ -136,41 +127,105 @@
</packing>
</child>
<child>
<object class="GtkIconView" id="attachments_view">
<object class="GtkFlowBox" id="attachments_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin">6</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<property name="max_children_per_line">4</property>
<property name="selection_mode">multiple</property>
<property name="item_orientation">horizontal</property>
<property name="model">attachments_model</property>
<property name="spacing">6</property>
<signal name="button-press-event" handler="on_attachments_view_button_press_event" swapped="no"/>
<signal name="item-activated" handler="on_attachments_view_activated" swapped="no"/>
<signal name="selection-changed" handler="on_attachments_view_selection_changed" swapped="no"/>
<property name="activate_on_single_click">False</property>
<signal name="child-activated" handler="on_attachments_child_activated" swapped="no"/>
<signal name="selected-children-changed" handler="on_attachments_selected_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkActionBar" id="attachments_actions">
<property name="visible">True</property>
<property name="can_focus">False</property>
<style>
<class name="background"/>
</style>
<child>
<object class="GtkButton" id="open_attachments">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Open selected attachments</property>
<property name="action_name">eml.open_attachments</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-open-symbolic</property>
</object>
</child>
</object>
<packing>
</packing>
</child>
<child>
<object class="GtkCellRendererPixbuf" id="icon"/>
<attributes>
<attribute name="pixbuf">0</attribute>
</attributes>
<object class="GtkButton" id="save_attachments">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Save selected attachments</property>
<property name="action_name">eml.save_attachments</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-save-symbolic</property>
</object>
</child>
</object>
<packing>
</packing>
</child>
<child>
<object class="GtkCellRendererText" id="file_name">
<property name="xpad">6</property>
<object class="GtkButton" id="select_all_attachments">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">Select all attachments</property>
<property name="action_name">eml.select_all_attachments</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">edit-select-all-symbolic</property>
</object>
</child>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
<packing>
</packing>
</child>
<style>
<class name="geary-attachments"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<style>
<class name="view"/>
</style>
</object>
<object class="GtkListStore" id="attachments_model">
<columns>
<!-- column-name icon -->
<column type="GdkPixbuf"/>
<!-- column-name label -->
<column type="gchararray"/>
<!-- column-name attachment_info -->
<column type="GObject"/>
</columns>
</object>
<object class="GtkInfoBar" id="draft_infobar">
<property name="app_paintable">True</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment