static gboolean _folder_is_any_of_type (TnyFolder *folder, TnyFolderType types[], guint ntypes);
static gboolean _invalid_msg_selected (ModestMainWindow *win, gboolean unique, ModestDimmingRule *rule);
-static gboolean _invalid_attach_selected (ModestWindow *win, gboolean unique, ModestDimmingRule *rule);
-static gboolean _invalid_clipboard_selected (ModestMsgViewWindow *win);
+static gboolean _invalid_attach_selected (ModestWindow *win, gboolean unique, gboolean for_view, ModestDimmingRule *rule);
+static gboolean _invalid_clipboard_selected (ModestWindow *win);
static gboolean _already_opened_msg (ModestWindow *win);
static gboolean _selected_msg_marked_as (ModestWindow *win, TnyHeaderFlags mask, gboolean opposite);
static gboolean _selected_folder_not_writeable (ModestMainWindow *win);
static gboolean _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win);
static gboolean _selected_folder_is_root (ModestMainWindow *win);
static gboolean _selected_folder_is_empty (ModestMainWindow *win);
+static gboolean _selected_folder_is_same_as_source (ModestWindow *win);
static gboolean _msg_download_in_progress (ModestMsgViewWindow *win);
static gboolean _msg_download_completed (ModestMainWindow *win);
static gboolean _selected_msg_sent_in_progress (ModestWindow *win);
static gboolean _sending_in_progress (ModestWindow *win);
static gboolean _marked_as_deleted (ModestWindow *win);
+static gboolean _invalid_attachment_for_purge (ModestWindow *win, ModestDimmingRule *rule);
gboolean
if (!dimmed) {
dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("ckct_ib_nothing_to_delete"));
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));
}
if (!dimmed) {
dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
gboolean
modest_ui_dimming_rules_on_paste_msgs (ModestWindow *win, gpointer user_data)
{
+ ModestDimmingRule *rule = NULL;
TnyFolderType types[3];
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
types[0] = TNY_FOLDER_TYPE_DRAFTS;
types[1] = TNY_FOLDER_TYPE_OUTBOX;
types[2] = TNY_FOLDER_TYPE_SENT;
/* Check dimmed rule */
+ if (!dimmed)
+ dimmed = _invalid_clipboard_selected (win);
if (!dimmed)
dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ if (!dimmed) {
+ dimmed = _selected_folder_is_same_as_source (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_copy_samefolder"));
+ }
return dimmed;
}
/* Check dimmed rule */
if (!dimmed)
- dimmed = _invalid_attach_selected (win, TRUE, rule);
+ dimmed = _invalid_attach_selected (win, TRUE, TRUE, rule);
return dimmed;
}
/* Check dimmed rule */
if (!dimmed)
- dimmed = _invalid_attach_selected (win, FALSE, rule);
+ dimmed = _invalid_attach_selected (win, FALSE, FALSE, rule);
return dimmed;
}
/* Check dimmed rule */
if (!dimmed) {
- dimmed = _invalid_attach_selected (win, FALSE, NULL);
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_display_more"));
+ dimmed = _invalid_attachment_for_purge (win, rule);
+ }
+
+ if (!dimmed) {
+ dimmed = _invalid_attach_selected (win, TRUE, TRUE, rule);
}
return dimmed;
/* Check dimmed rule */
if (!dimmed)
- dimmed = _invalid_clipboard_selected (MODEST_MSG_VIEW_WINDOW(win));
+ dimmed = _invalid_clipboard_selected (win);
return dimmed;
}
if (!dimmed) {
dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(),
TRUE);
- modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
}
return dimmed;
}
static gboolean
+_selected_folder_is_same_as_source (ModestWindow *win)
+{
+ ModestEmailClipboard *clipboard = NULL;
+ GtkWidget *folder_view = NULL;
+ TnyFolderStore *folder = NULL;
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+
+ /* Get folder view */
+ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ if (!folder_view)
+ return FALSE;
+
+ /* Get selected folder as destination folder */
+ folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (!(folder && TNY_IS_FOLDER(folder))) {
+ result = FALSE;
+ goto frees;
+ }
+
+ /* Check clipboard is cleared */
+ clipboard = modest_runtime_get_email_clipboard ();
+ if (modest_email_clipboard_cleared (clipboard)) {
+ result = FALSE;
+ goto frees;
+ }
+
+ /* Check source folder */
+ result = modest_email_clipboard_check_source_folder (clipboard,
+ (const TnyFolder *) folder);
+
+ /* Free */
+ frees:
+ g_object_unref (folder);
+
+ return result;
+}
+
+static gboolean
_selected_folder_is_any_of_type (ModestWindow *win,
TnyFolderType types[],
guint ntypes)
static gboolean
-_invalid_clipboard_selected (ModestMsgViewWindow *win)
+_invalid_clipboard_selected (ModestWindow *win)
{
- GtkClipboard *clipboard = NULL;
- gchar *selection = NULL;
- GtkWidget *focused = NULL;
gboolean result = FALSE;
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), TRUE);
+ 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 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));
+ /* Get focuesed widget */
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
- /* Check dimming */
- result = ((selection == NULL) ||
- (MODEST_IS_ATTACHMENTS_VIEW (focused)));
-
+ /* 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;
/* Get selected atachments */
attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
n_selected = g_list_length (attachments);
- for (node = attachments; node != NULL; node = g_list_next (node)) {
- TnyMimePart *mime_part = TNY_MIME_PART (node->data);
- TnyList *nested_list = tny_simple_list_new ();
- if (!tny_mime_part_is_attachment (mime_part)) {
- selected_messages = TRUE;
- break;
- }
- tny_mime_part_get_parts (mime_part, nested_list);
- if (tny_list_get_length (nested_list) > 0)
+
+ /* 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;
- g_object_unref (nested_list);
+ result = TRUE;
+ }
+ g_object_unref (nested_list);
+ }
}
- /* Check unique */
- if (unique)
- result = n_selected != 1;
- else
-
- result = n_selected < 1;
-
/* Set notifications */
- if (!result && rule != NULL) {
+ 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"));
}
}
return result;
}
+
+static gboolean
+_invalid_attachment_for_purge (ModestWindow *win, ModestDimmingRule *rule)
+{
+ gboolean result = FALSE;
+
+ if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ TnyMsg *msg;
+ TnyFolder *folder;
+ TnyAccount *account;
+
+ msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+ folder = tny_msg_get_folder (msg);
+ g_object_unref (msg);
+ account = modest_tny_folder_get_account (folder);
+ g_object_unref (folder);
+ if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (account))) {
+ } else {
+ const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
+ /* If it's POP then dim */
+ if (modest_protocol_info_get_transport_store_protocol (proto_str) ==
+ MODEST_PROTOCOL_STORE_POP) {
+ GList *attachments;
+ gint n_selected;
+ result = TRUE;
+ attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
+ n_selected = g_list_length (attachments);
+ g_list_free (attachments);
+
+ modest_dimming_rule_set_notification (
+ rule,
+ ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular",
+ "mail_ib_unable_to_pure_attach_pop_mail_plural", n_selected));
+ }
+ }
+ }
+
+ return result;
+}
+