+_invalid_clipboard_selected (ModestWindow *win)
+{
+ gboolean result = FALSE;
+
+ if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ GtkClipboard *clipboard = NULL;
+ gchar *selection = NULL;
+ GtkWidget *focused = NULL;
+
+ /* Get clipboard selection*/
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ selection = gtk_clipboard_wait_for_text (clipboard);
+
+ /* Get focuesed widget */
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ /* Check dimming */
+ result = ((selection == NULL) ||
+ (MODEST_IS_ATTACHMENTS_VIEW (focused)));
+ }
+ else if (MODEST_IS_MAIN_WINDOW (win)) {
+ ModestEmailClipboard *clipboard = NULL;
+
+ clipboard = modest_runtime_get_email_clipboard ();
+ if (modest_email_clipboard_cleared (clipboard))
+ result = TRUE;
+ }
+
+ return result;
+}
+
+
+static gboolean
+_invalid_attach_selected (ModestWindow *win,
+ gboolean unique,
+ gboolean for_view,
+ ModestDimmingRule *rule)
+{
+ GList *attachments, *node;
+ gint n_selected;
+ TnyHeaderFlags flags;
+ gboolean nested_attachments = FALSE;
+ gboolean selected_messages = FALSE;
+ gboolean result = FALSE;
+
+ if (MODEST_IS_MAIN_WINDOW (win)) {
+ flags = TNY_HEADER_FLAG_ATTACHMENTS;
+ if (!result)
+ result = _selected_msg_marked_as (win, flags, TRUE);
+ }
+ else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+
+ /* Get selected atachments */
+ attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
+ n_selected = g_list_length (attachments);
+
+ /* Check unique */
+ if (!result) {
+ if (unique)
+ result = n_selected != 1;
+ else
+
+ result = n_selected < 1;
+ }
+
+ /* Check attached type (view operation not required) */
+ if (!result && !for_view) {
+ for (node = attachments; node != NULL && !result; node = g_list_next (node)) {
+ TnyMimePart *mime_part = TNY_MIME_PART (node->data);
+ TnyList *nested_list = tny_simple_list_new ();
+ if (TNY_IS_MSG (mime_part)) {
+ selected_messages = TRUE;
+ result = TRUE;
+ }
+ tny_mime_part_get_parts (mime_part, nested_list);
+ if (tny_list_get_length (nested_list) > 0) {
+ nested_attachments = TRUE;
+ result = TRUE;
+ }
+ g_object_unref (nested_list);
+ }
+ }
+
+ /* Set notifications */
+ if (result && rule != NULL) {
+ if (selected_messages) {
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_save_attach_mail"));
+ } else if (nested_attachments) {
+ modest_dimming_rule_set_notification (rule, _("FIXME:unable to save attachments with nested elements"));
+ } else if (n_selected == 0) {
+ modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected"));
+ } else if (unique) {
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_display_more"));
+ }
+ }
+
+ /* Free */
+ g_list_free (attachments);
+ }
+
+ return result;
+}
+
+static gboolean