PROP_SUBJECT,
PROP_SUBJECT_EDITABLE,
PROP_BODY,
- PROP_BODY_EDITABLE
+ PROP_BODY_EDITABLE,
+ PROP_WITH_ATTACHMENTS
};
enum
GValue *value,
GParamSpec *pspec);
+static void solipa_mail_ui_on_iv_attachment_selection_changed (GtkIconView *iconview,
+ gpointer user_data);
+
static void solipa_mail_ui_on_btn_attachment_add_clicked (GtkButton *button,
gpointer user_data);
static void solipa_mail_ui_on_btn_attachment_remove_clicked (GtkButton *button,
GtkWidget *subject;
GtkWidget *body;
GtkWidget *iv_attachments;
+ GtkWidget *btn_attachment_remove;
GtkListStore *lstore_attachments;
};
TRUE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_WITH_ATTACHMENTS,
+ g_param_spec_boolean ("with-attachments",
+ "With attachments",
+ "With attachments",
+ TRUE,
+ G_PARAM_READWRITE));
+
/**
* SolipaMailUI::btn_cancel_clicked:
* @solipa_mail_ui:
priv->lstore_attachments = GTK_LIST_STORE (gtk_builder_get_object (builder, "lstore_mail_attachments"));
priv->iv_attachments = GTK_WIDGET (gtk_builder_get_object (builder, "iconview1"));
+ priv->btn_attachment_remove = GTK_WIDGET (gtk_builder_get_object (builder, "button10"));
- gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->iv_attachments), COL_ATTACHMENTS_FILE_NAME);
+ gtk_icon_view_set_text_column (GTK_ICON_VIEW (priv->iv_attachments), COL_ATTACHMENTS_FILE_NAME_BASE);
+ gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->iv_attachments), COL_ATTACHMENTS_ICON);
+ g_signal_connect (gtk_builder_get_object (builder, "iconview1"), "selection-changed",
+ G_CALLBACK (solipa_mail_ui_on_iv_attachment_selection_changed), (gpointer)solipa_mail_ui);
g_signal_connect (gtk_builder_get_object (builder, "button9"), "clicked",
G_CALLBACK (solipa_mail_ui_on_btn_attachment_add_clicked), (gpointer)solipa_mail_ui);
- g_signal_connect (gtk_builder_get_object (builder, "button10"), "clicked",
+ g_signal_connect (priv->btn_attachment_remove, "clicked",
G_CALLBACK (solipa_mail_ui_on_btn_attachment_remove_clicked), (gpointer)solipa_mail_ui);
g_signal_connect (gtk_builder_get_object (builder, "button6"), "clicked",
CamelInternetAddress *addr;
+ GtkTreeIter iter;
+ gchar *filename;
+
g_return_val_if_fail (IS_SOLIPA_MAIL_UI (mailui), FALSE);
SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (mailui);
solipa_mail_set_body (smail, body, NULL);
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->lstore_attachments), &iter))
+ {
+ do
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_attachments), &iter,
+ COL_ATTACHMENTS_FILE_NAME, &filename,
+ -1);
+ solipa_mail_add_attachment (smail, filename);
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->lstore_attachments), &iter));
+ }
+
if (g_strcmp0 (g_strstrip (smtpuri), "") != 0)
{
solipa_mail_send (smail, smtpuri);
gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->body), g_value_get_boolean (value));
break;
+ case PROP_WITH_ATTACHMENTS:
+ gtk_widget_set_visible (priv->iv_attachments, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
g_value_set_boolean (value, gtk_text_view_get_editable (GTK_TEXT_VIEW (priv->body)));
break;
+ case PROP_WITH_ATTACHMENTS:
+ g_value_set_boolean (value, gtk_widget_get_visible (priv->iv_attachments));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
/* CALLBACK */
+static void
+solipa_mail_ui_on_iv_attachment_selection_changed (GtkIconView *iconview,
+ gpointer user_data)
+{
+ GList *items;
+
+ SolipaMailUI *solipa_mail_ui = (SolipaMailUI *)user_data;
+ SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (solipa_mail_ui);
+
+ items = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (priv->iv_attachments));
+ if (items == NULL)
+ {
+ gtk_widget_set_sensitive (priv->btn_attachment_remove, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (priv->btn_attachment_remove, TRUE);
+ g_list_foreach (items, (GFunc)gtk_tree_path_free, NULL);
+ g_list_free (items);
+ }
+}
+
static void
solipa_mail_ui_on_btn_attachment_add_clicked (GtkButton *button,
gpointer user_data)
gchar *filename;
GtkTreeIter iter;
+ GError *error;
+ GFile *file;
+ GFileInfo *file_info;
+ GIcon *icon;
+ GInputStream *istream;
+ GdkPixbuf *pixbuf;
+
dialog = gtk_file_chooser_dialog_new ("Choose a file to attach.",
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename == NULL)
+ {
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ file = g_file_new_for_path (filename);
+ if (!g_file_query_exists (file, NULL))
+ {
+ gtk_widget_destroy (dialog);
+ return;
+ }
+ error = NULL;
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_ICON,
+ 0,
+ NULL,
+ &error);
+
+ pixbuf = NULL;
+ icon = g_file_info_get_icon (file_info);
+ if (icon != NULL)
+ {
+ if (G_IS_THEMED_ICON (icon))
+ {
+ GtkIconTheme *theme;
+ const gchar * const *names;
+
+ theme = gtk_icon_theme_get_default ();
+ names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+
+ error = NULL;
+ pixbuf = gtk_icon_theme_load_icon (theme,
+ names[0],
+ 64,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ &error);
+ }
+ else
+ {
+ error = NULL;
+ istream = g_loadable_icon_load (G_LOADABLE_ICON (G_FILE_ICON (icon)),
+ 64,
+ NULL, NULL,
+ &error);
+ error = NULL;
+ pixbuf = gdk_pixbuf_new_from_stream (istream, NULL, &error);
+ }
+ }
+
+ if (pixbuf == NULL)
+ {
+ GtkIconSet *icon_set;
+ icon_set = gtk_icon_factory_lookup_default ("gtk-file");
+ pixbuf = gtk_icon_set_render_icon (icon_set,
+ gtk_widget_get_style (priv->iv_attachments),
+ GTK_TEXT_DIR_NONE,
+ GTK_STATE_NORMAL,
+ GTK_ICON_SIZE_DND,
+ priv->iv_attachments, NULL);
+ }
+
gtk_list_store_append (priv->lstore_attachments, &iter);
gtk_list_store_set (priv->lstore_attachments, &iter,
COL_ATTACHMENTS_FILE_NAME, filename,
+ COL_ATTACHMENTS_FILE_NAME_BASE, g_file_get_basename (file),
+ COL_ATTACHMENTS_ICON, pixbuf,
-1);
g_free (filename);
}
solipa_mail_ui_on_btn_attachment_remove_clicked (GtkButton *button,
gpointer user_data)
{
+ GList *items;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
SolipaMailUI *solipa_mail_ui = (SolipaMailUI *)user_data;
SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (solipa_mail_ui);
+
+ items = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (priv->iv_attachments));
+ if (items != NULL)
+ {
+ do
+ {
+ path = (GtkTreePath *)items->data;
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->lstore_attachments), &iter, path);
+ gtk_list_store_remove (priv->lstore_attachments, &iter);
+ items = g_list_next (items);
+ } while (items != NULL);
+ }
}
static void