#include <string.h>
#include "modest-ui-dimming-rules.h"
+#include "modest-ui-actions.h"
#include "modest-dimming-rule.h"
+#include "modest-debug.h"
#include "modest-tny-folder.h"
+#include "modest-tny-account.h"
+#include "modest-tny-msg.h"
+#include "modest-tny-mime-part.h"
#include "modest-text-utils.h"
+#include "modest-address-book.h"
#include <widgets/modest-attachments-view.h>
#include <modest-runtime.h>
#include <tny-simple-list.h>
+#include <widgets/modest-recpt-editor.h>
+#include <gtkhtml/gtkhtml.h>
+#include <modest-runtime.h>
+#ifdef MODEST_TOOLKIT_HILDON2
+#include <modest-header-window.h>
+#endif
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, gboolean for_view, ModestDimmingRule *rule);
+static gboolean _invalid_attach_selected (ModestWindow *win,
+ gboolean unique, gboolean for_view, gboolean for_remove,
+ ModestDimmingRule *rule);
static gboolean _purged_attach_selected (ModestWindow *win, gboolean all, ModestDimmingRule *rule);
static gboolean _clipboard_is_empty (ModestWindow *win);
static gboolean _invalid_clipboard_selected (ModestWindow *win, ModestDimmingRule *rule);
-static gboolean _already_opened_msg (ModestWindow *win, guint *n_messages);
-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_snd_level (ModestMainWindow *win);
+static gboolean _selected_folder_not_writeable (ModestMainWindow *win, gboolean for_paste);
+static gboolean _selected_folder_not_moveable (ModestMainWindow *win);
+static gboolean _selected_folder_not_renameable (ModestMainWindow *win);
+static gboolean _selected_folder_not_deletable (ModestMainWindow *win);
static gboolean _selected_folder_is_any_of_type (ModestWindow *win, TnyFolderType types[], guint ntypes);
static gboolean _selected_folder_is_root_or_inbox (ModestMainWindow *win);
-static gboolean _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win);
static gboolean _selected_folder_is_root (ModestMainWindow *win);
+static gboolean _header_view_is_all_selected (ModestMainWindow *win);
static gboolean _selected_folder_is_empty (ModestMainWindow *win);
+static gboolean _folder_view_has_focus (ModestWindow *win);
static gboolean _selected_folder_is_same_as_source (ModestWindow *win);
-static gboolean _msg_download_in_progress (ModestMsgViewWindow *win);
+static gboolean _msg_download_in_progress (ModestWindow *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_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule);
static gboolean _transfer_mode_enabled (ModestWindow *win);
+static gboolean _selected_folder_has_subfolder_with_same_name (ModestWindow *win);
+static void fill_list_of_caches (gpointer key, gpointer value, gpointer userdata);
+static gboolean _send_receive_in_progress (ModestWindow *win);
+static gboolean _msgs_send_in_progress (void);
-gboolean
-modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data)
+static DimmedState *
+_define_main_window_dimming_state (ModestMainWindow *window)
{
- ModestDimmingRule *rule = NULL;
- gboolean dimmed = FALSE;
+ DimmedState *state = NULL;
+ GtkWidget *focused_widget = NULL;
+ GtkWidget *header_view = NULL;
+ GtkTreeModel *model = NULL;
+ TnyList *selected_headers = NULL;
+ TnyIterator *iter = NULL;
+ TnyHeader *header = NULL;
+ ModestCacheMgr *cache_mgr = NULL;
+ GHashTable *send_queue_cache = NULL;
+ ModestTnySendQueue *send_queue = NULL;
+ GSList *send_queues = NULL, *node = NULL;
+ ModestWindowMgr *mgr = NULL;
+ gboolean found = FALSE;
+ gchar *msg_uid = NULL;
+ TnyHeaderFlags flags;
+ gboolean all_deleted = TRUE;
+ gboolean all_seen = TRUE;
+ gboolean all_cached = TRUE;
+ gboolean all_has_attach = TRUE;
+ TnyFolder *folder = NULL;
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
- g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
- rule = MODEST_DIMMING_RULE (user_data);
+ g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(window), NULL);
+
+ /* Init state */
+ state = g_slice_new0 (DimmedState);
+ state->n_selected = 0;
+ state->already_opened_msg = 0;
+ state->any_marked_as_deleted = FALSE;
+ state->all_marked_as_deleted = FALSE;
+ state->any_marked_as_seen = FALSE;
+ state->all_marked_as_seen = FALSE;
+ state->any_marked_as_cached = FALSE;
+ state->all_marked_as_cached = FALSE;
+ state->any_has_attachments = FALSE;
+ state->all_has_attachments = FALSE;
+ state->sent_in_progress = FALSE;
+ state->all_selected = FALSE;
+
+ /* Get focused widget */
+ focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
+ if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
+ state->n_selected++;
+ return state;
+ } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
+ header_view = focused_widget;
+ } else {
+ header_view = modest_main_window_get_child_widget (window, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+ }
+
+ /* Get header view and selected headers */
+ selected_headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
+ if (!selected_headers)
+ return state;
+
+ /* Examine selected headers */
+ iter = tny_list_create_iterator (selected_headers);
+ while (!tny_iterator_is_done (iter)) {
+ header = TNY_HEADER (tny_iterator_get_current (iter));
+ flags = tny_header_get_flags (header);
- /* Check dimmed rule */
- if (!dimmed) {
- dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ /* No selected */
+ state->n_selected++;
+
+ /* Already opened */
+ mgr = modest_runtime_get_window_mgr ();
+ if (modest_window_mgr_find_registered_header (mgr, header, NULL))
+ state->already_opened_msg++;
+
+
+ /* Mark as deleted */
+ all_deleted = all_deleted && (flags & TNY_HEADER_FLAG_DELETED);
+ state->all_marked_as_deleted = all_deleted;
+ if (!state->any_marked_as_deleted)
+ state->any_marked_as_deleted = flags & TNY_HEADER_FLAG_DELETED;
+
+ /* Mark as seen */
+ all_seen = all_seen && (flags & TNY_HEADER_FLAG_SEEN);
+ state->all_marked_as_seen = all_seen;
+ if (!state->any_marked_as_seen)
+ state->any_marked_as_seen = flags & TNY_HEADER_FLAG_SEEN;
+
+ /* Mark as cached */
+ all_cached = all_cached && (flags & TNY_HEADER_FLAG_CACHED);
+ state->all_marked_as_cached = all_cached;
+ if (!state->any_marked_as_cached)
+ state->any_marked_as_cached = flags & TNY_HEADER_FLAG_CACHED;
+
+ /* Mark has_attachments */
+ all_has_attach = all_has_attach && (flags & TNY_HEADER_FLAG_ATTACHMENTS);
+ state->all_has_attachments = all_has_attach;
+ if (!state->any_has_attachments)
+ state->any_has_attachments = flags & TNY_HEADER_FLAG_ATTACHMENTS;
+
+ /* sent in progress */
+ folder = tny_header_get_folder (header);
+ if (folder) {
+ if (modest_tny_folder_guess_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) {
+ msg_uid = modest_tny_send_queue_get_msg_id (header);
+ if (!state->sent_in_progress) {
+ cache_mgr = modest_runtime_get_cache_mgr ();
+ send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+ MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+
+ g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
+
+ for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) {
+ send_queue = MODEST_TNY_SEND_QUEUE (node->data);
+
+ /* Check if msg uid is being processed inside send queue */
+ found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid);
+ }
+ state->sent_in_progress = found;
+ }
+ }
+ g_object_unref (folder);
+ }
+ tny_iterator_next (iter);
+ g_object_unref (header);
}
- return dimmed;
+ /* check if all the headers are selected or not */
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(header_view));
+ if (model != NULL){
+ gint count;
+ count = gtk_tree_model_iter_n_children(model, NULL);
+ if(state->n_selected == count)
+ state->all_selected = TRUE;
+ }
+
+ /* Free */
+ g_free(msg_uid);
+ g_object_unref(selected_headers);
+ g_object_unref(iter);
+ g_slist_free (send_queues);
+
+ return state;
+}
+
+static DimmedState *
+_define_msg_view_window_dimming_state (ModestMsgViewWindow *window)
+{
+ DimmedState *state = NULL;
+ TnyHeader *header = NULL;
+ ModestCacheMgr *cache_mgr = NULL;
+ GHashTable *send_queue_cache = NULL;
+ ModestTnySendQueue *send_queue = NULL;
+ GSList *send_queues = NULL, *node = NULL;
+ gboolean found = FALSE;
+ gchar *msg_uid = NULL;
+ TnyHeaderFlags flags;
+ gboolean all_deleted = TRUE;
+ gboolean all_seen = TRUE;
+ gboolean all_cached = TRUE;
+ gboolean all_has_attach = TRUE;
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(window), NULL);
+
+ /* Init state */
+ state = g_slice_new0 (DimmedState);
+ state->n_selected = 0;
+ state->already_opened_msg = 0;
+ state->any_marked_as_deleted = FALSE;
+ state->all_marked_as_deleted = FALSE;
+ state->any_marked_as_seen = FALSE;
+ state->all_marked_as_seen = FALSE;
+ state->any_marked_as_cached = FALSE;
+ state->all_marked_as_cached = FALSE;
+ state->any_has_attachments = FALSE;
+ state->all_has_attachments = FALSE;
+ state->sent_in_progress = FALSE;
+
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(window));
+ if (header == NULL)
+ return state;
+ g_return_val_if_fail (TNY_IS_HEADER(header), state);
+ flags = tny_header_get_flags (header);
+
+ /* Selected */
+ state->n_selected++;
+
+ /* Mark as deleted */
+ all_deleted = all_deleted && (flags & TNY_HEADER_FLAG_DELETED);
+ state->all_marked_as_deleted = all_deleted;
+ if (!state->any_marked_as_deleted)
+ state->any_marked_as_deleted = flags & TNY_HEADER_FLAG_DELETED;
+
+ /* Mark as seen */
+ all_seen = all_seen && (flags & TNY_HEADER_FLAG_SEEN);
+ state->all_marked_as_seen = all_seen;
+ if (!state->any_marked_as_seen)
+ state->any_marked_as_seen = flags & TNY_HEADER_FLAG_SEEN;
+
+ /* Mark as cached */
+ all_cached = all_cached && (flags & TNY_HEADER_FLAG_CACHED);
+ state->all_marked_as_cached = all_cached;
+ if (!state->any_marked_as_cached)
+ state->any_marked_as_cached = flags & TNY_HEADER_FLAG_CACHED;
+
+ /* Mark has_attachments */
+ all_has_attach = all_has_attach && (flags & TNY_HEADER_FLAG_ATTACHMENTS);
+ state->all_has_attachments = all_has_attach;
+ if (!state->any_has_attachments)
+ state->any_has_attachments = (flags & TNY_HEADER_FLAG_ATTACHMENTS)?1:0;
+
+ /* sent in progress */
+ msg_uid = modest_tny_send_queue_get_msg_id (header);
+ if (!state->sent_in_progress) {
+ cache_mgr = modest_runtime_get_cache_mgr ();
+ send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+ MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+
+ g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
+
+ for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) {
+ send_queue = MODEST_TNY_SEND_QUEUE (node->data);
+
+ /* Check if msg uid is being processed inside send queue */
+ found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid);
+ }
+ state->sent_in_progress = found;
+ }
+
+ /* Free */
+ g_free(msg_uid);
+ g_object_unref (header);
+ g_slist_free (send_queues);
+
+ return state;
+}
+
+
+DimmedState *
+modest_ui_dimming_rules_define_dimming_state (ModestWindow *window)
+{
+ DimmedState *state = NULL;
+
+ g_return_val_if_fail (MODEST_IS_WINDOW(window), NULL);
+
+ if (MODEST_IS_MAIN_WINDOW (window))
+ state = _define_main_window_dimming_state (MODEST_MAIN_WINDOW(window));
+ else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+ state = _define_msg_view_window_dimming_state (MODEST_MSG_VIEW_WINDOW(window));
+ }
+
+ return state;
}
gboolean
-modest_ui_dimming_rules_on_csm_new_folder (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
-
- /* Check common new folder menu item dimming rules */
- dimmed = modest_ui_dimming_rules_on_new_folder (win, user_data);
-
- /* Check CSM specific dimming rules */
- if (!dimmed) {
- dimmed = _selected_folder_is_snd_level (MODEST_MAIN_WINDOW(win));
+
+ /* Check dimmed rule */
+ if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
+#ifndef MODEST_TOOLKIT_HILDON2
+ dimmed = _msg_download_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+#endif
+ } else if (MODEST_IS_MAIN_WINDOW(win)) {
+ dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(),
+ TRUE);
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
+ modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
}
-
+
return dimmed;
}
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed) {
+ modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
+ return dimmed;
+ }
+
/* Get selected folder as parent of new folder to create */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ if (!folder_view) /* folder view may not have been created yet */
+ return TRUE;
+
parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
if (!parent_folder)
return TRUE;
if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
dimmed = FALSE;
} else {
- const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
- /* If it's POP then dim */
- dimmed = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
- MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
+ ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (parent_folder));
+ if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+ ModestProtocolRegistry *protocol_registry;
+
+ protocol_registry = modest_runtime_get_protocol_registry ();
+ /* If account does not support folders (pop) then dim */
+ dimmed = (!modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type,
+ MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
+ }
}
- } else {
- /* TODO: the specs say that only one level of subfolder is allowed, is this true ? */
-
+ } else {
TnyFolderType types[3];
types[0] = TNY_FOLDER_TYPE_DRAFTS;
/* Apply folder rules */
if (!dimmed) {
- dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
+ dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win), FALSE);
if (dimmed)
modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
}
modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
}
}
+
+ /* if not the folder is selected then dim */
+ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ if (folder_view && !gtk_widget_is_focus (folder_view))
+ dimmed = TRUE;
+
g_object_unref (parent_folder);
return dimmed;
GtkWidget *header_view = NULL;
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);
- /* Get the folder view */
- folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ if (MODEST_IS_MAIN_WINDOW (win)) {
+ /* Get the folder view */
+ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+
+ /* Get header view */
+ header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
- /* Get header view */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
+ if (header_view && gtk_widget_is_focus (header_view))
+ dimmed = modest_ui_dimming_rules_on_delete_msg (win, rule);
+
+ if (folder_view && gtk_widget_is_focus (folder_view))
+ dimmed = modest_ui_dimming_rules_on_delete_folder (win, rule);
+
+ if (header_view && folder_view &&
+ !gtk_widget_is_focus (header_view) &&
+ !gtk_widget_is_focus (folder_view)) {
+ dimmed = TRUE;
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));
+ }
+
+#ifdef MODEST_TOOLKIT_HILDON2
+ } else if (MODEST_IS_HEADER_WINDOW (win)) {
+
+ if (!dimmed) {
+ dimmed = _transfer_mode_enabled (win);
+ }
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
+ if (!dimmed) {
+ GtkWidget *header_view;
+ TnyFolder *folder;
- if (header_view && gtk_widget_is_focus (header_view))
- dimmed = modest_ui_dimming_rules_on_delete_msg (win, rule);
+ header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
+ folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
+ if (folder) {
+ dimmed = (tny_folder_get_all_count (TNY_FOLDER (folder)) == 0);
+ g_object_unref (folder);
+ }
+ }
- if (folder_view && gtk_widget_is_focus (folder_view))
+#endif
+ } else {
dimmed = modest_ui_dimming_rules_on_delete_folder (win, rule);
+ }
return dimmed;
}
modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
- TnyFolderType types[5];
+ TnyFolderType types[6];
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
types[2] = TNY_FOLDER_TYPE_SENT;
types[3] = TNY_FOLDER_TYPE_INBOX;
types[4] = TNY_FOLDER_TYPE_ROOT;
+ types[5] = TNY_FOLDER_TYPE_ARCHIVE;
/* Check dimmed rule */
+ dimmed = _selected_folder_not_deletable (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
if (!dimmed) {
- dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
- }
- if (!dimmed) {
- dimmed = _selected_folder_is_any_of_type (win, types, 5);
+ dimmed = _selected_folder_is_any_of_type (win, types, 6);
if (dimmed)
modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
}
modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
}
if (!dimmed) {
- dimmed = _selected_folder_is_MMC_or_POP_root (MODEST_MAIN_WINDOW(win));
+ dimmed = _transfer_mode_enabled (win);
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
}
return dimmed;
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
+#ifdef MODEST_TOOLKIT_HILDON2
+ if (MODEST_IS_HEADER_WINDOW (win)) {
+ return FALSE;
+ }
+#endif
+
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);
-
+
/* Check dimmed rule */
- if (!dimmed) {
- dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
- }
+ dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
+
+ if (!dimmed)
+ dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
return dimmed;
modest_ui_dimming_rules_on_rename_folder (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
- TnyFolderType types[3];
+ TnyFolderType types[4];
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
types[0] = TNY_FOLDER_TYPE_DRAFTS;
types[1] = TNY_FOLDER_TYPE_OUTBOX;
types[2] = TNY_FOLDER_TYPE_SENT;
+ types[3] = TNY_FOLDER_TYPE_ARCHIVE;
/* Check dimmed rule */
+ dimmed = _selected_folder_not_renameable (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
if (!dimmed) {
- dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
+ dimmed = _selected_folder_is_root_or_inbox (MODEST_MAIN_WINDOW(win));
if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
if (!dimmed) {
- dimmed = _selected_folder_is_root_or_inbox (MODEST_MAIN_WINDOW(win));
+ dimmed = _selected_folder_is_any_of_type (win, types, 4);
if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
if (!dimmed) {
- dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ dimmed = _transfer_mode_enabled (win);
if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
+ const DimmedState *state = NULL;
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);
-
+ state = modest_window_get_dimming_state (win);
+
/* Check dimmed rule */
+ dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
if (!dimmed) {
- dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
- }
- if (!dimmed) {
- dimmed = _marked_as_deleted (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_message_already_deleted"));
+ dimmed = state->any_marked_as_deleted;
+ if (dimmed) {
+ gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win);
+ modest_dimming_rule_set_notification (rule, msg);
+ g_free (msg);
+ }
}
if (!dimmed) {
dimmed = _selected_msg_sent_in_progress (win);
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_ROOT;
+
+ /* Check dimmed rule */
+ dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
+
/* main window dimming rules */
if (MODEST_IS_MAIN_WINDOW(win)) {
- types[0] = TNY_FOLDER_TYPE_DRAFTS;
- types[1] = TNY_FOLDER_TYPE_OUTBOX;
- types[2] = TNY_FOLDER_TYPE_ROOT;
-
- /* Check dimmed rule */
- if (!dimmed) {
- dimmed = _selected_folder_is_any_of_type (win, types, 3);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
- }
if (!dimmed) {
dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
if (dimmed)
modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
}
if (!dimmed) {
- dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW(win));
+ dimmed = _msg_download_in_progress (win);
if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
}
}
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
- if (!dimmed) {
- dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
- }
+ dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
if (!dimmed) {
dimmed = _msg_download_completed (MODEST_MAIN_WINDOW(win));
if (dimmed)
gboolean
modest_ui_dimming_rules_always_dimmed (ModestWindow *win, gpointer user_data)
{
- gboolean dimmed = FALSE;
-
g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
-
- /* Check dimmed rule */
- if (!dimmed)
- dimmed = TRUE;
- return dimmed;
+ return TRUE;
+}
+
+static gboolean
+_message_already_sent (ModestMsgViewWindow *view_window)
+{
+ TnyHeader *header;
+ TnyFolder *folder;
+ gboolean already_sent = FALSE;
+
+ header = modest_msg_view_window_get_header (view_window);
+ if (header) {
+ folder = tny_header_get_folder (header);
+ if (folder) {
+ if (modest_tny_folder_guess_folder_type (folder) ==
+ TNY_FOLDER_TYPE_OUTBOX) {
+ ModestTnySendQueueStatus status =
+ modest_tny_all_send_queues_get_msg_status (header);
+ if (status == MODEST_TNY_SEND_QUEUE_UNKNOWN ||
+ status == MODEST_TNY_SEND_QUEUE_SENDING)
+ already_sent = TRUE;
+ }
+ g_object_unref (folder);
+ }
+ g_object_unref (header);
+ }
+ return already_sent;
}
+
gboolean
modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
- guint n_messages = 0;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
/* Check dimmed rule */
if (MODEST_IS_MAIN_WINDOW (win)) {
+ dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));
if (!dimmed) {
- dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
+ dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+ }
+ if (!dimmed) {
+ dimmed = state->sent_in_progress;
if (dimmed)
- modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
}
if (!dimmed) {
- dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+ dimmed = state->any_marked_as_deleted;
+ if (dimmed) {
+ gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win);
+ modest_dimming_rule_set_notification (rule, msg);
+ g_free (msg);
+ }
}
if (!dimmed) {
- dimmed = _already_opened_msg (win, &n_messages);
+ dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
if (dimmed) {
- gchar *num = g_strdup_printf ("%d", n_messages);
- gchar *message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"), num);
-/* modest_dimming_rule_set_notification (rule, _("mcen_nc_unable_to_delete_n_messages")); */
+ gchar *message = NULL;
+
+ message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"),
+ state->already_opened_msg);
modest_dimming_rule_set_notification (rule, message);
g_free(message);
- g_free(num);
}
- }
- if (!dimmed) {
- dimmed = _marked_as_deleted (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_message_already_deleted"));
- }
- if (!dimmed) {
- dimmed = _selected_msg_sent_in_progress (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
+
}
}
else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
if (!dimmed) {
- dimmed = _transfer_mode_enabled (win);
+ dimmed = state->any_marked_as_deleted;
+ if (dimmed) {
+ gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win);
+ modest_dimming_rule_set_notification (rule, msg);
+ g_free (msg);
+ }
+ }
+ if (!dimmed) {
+ dimmed = state->sent_in_progress;
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
}
+
+ /* This could happen if we're viewing a message of the
+ outbox that has been already sent */
+ if (!dimmed)
+ dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
+
+ /* The delete button should be dimmed when viewing an attachment,
+ * but should be enabled when viewing a message from the list,
+ * or when viewing a search result.
+ */
if (!dimmed) {
- dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW(win));
- if (dimmed) {
- gchar *num = g_strdup("1");
- gchar *message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"), num);
-/* modest_dimming_rule_set_notification (rule, _("mcen_nc_unable_to_delete_n_messages")); */
- modest_dimming_rule_set_notification (rule, message);
- g_free(message);
- g_free(num);
+ if (!modest_msg_view_window_is_search_result (MODEST_MSG_VIEW_WINDOW(win))) {
+ dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW(win));
+ if (dimmed) {
+ modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
+ }
}
}
}
/* Check dimmed rule */
header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
/* If the header view has the focus: */
if (header_view && gtk_widget_is_focus (header_view)) {
else {
/* If the folder view has the focus: */
GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
if (folder_view && gtk_widget_is_focus (folder_view)) {
TnyFolderStore *folder_store
= modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
}
g_object_unref (folder_store);
+ } else {
+ dimmed = TRUE;
+ modest_dimming_rule_set_notification (rule, "");
+ }
+ if (!dimmed) {
+ dimmed = _msg_download_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
}
- }
+ } else {
+ return TRUE;
+ }
}
/* msg view window dimming rules */
} else {
-
/* Check dimmed rule */
- if (!dimmed) {
- dimmed = _msg_download_in_progress (MODEST_MSG_VIEW_WINDOW(win));
+ if (MODEST_IS_MSG_VIEW_WINDOW (win))
+ dimmed = _msg_download_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+ if (!dimmed && MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ if (!modest_msg_view_window_is_search_result (MODEST_MSG_VIEW_WINDOW(win))) {
+ dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW (win));
+ }
if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
gboolean
-modest_ui_dimming_rules_on_mark_as_read_msg (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_mark_as_read_msg_in_view (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ TnyHeader *header;
TnyHeaderFlags flags;
gboolean dimmed = FALSE;
+
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
- flags = TNY_HEADER_FLAG_SEEN;
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+ if (!header) {
+ dimmed = TRUE;
+ }
- /* Check dimmed rule */
if (!dimmed) {
- dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+ flags = tny_header_get_flags (header);
+ if (flags & TNY_HEADER_FLAG_SEEN)
+ dimmed = TRUE;
}
- if (!dimmed) {
- dimmed = _selected_msg_marked_as (win, flags, FALSE);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
- }
+ if (header)
+ g_object_unref (header);
return dimmed;
}
+
gboolean
-modest_ui_dimming_rules_on_mark_as_unread_msg (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_mark_as_unread_msg_in_view (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ TnyHeader *header;
TnyHeaderFlags flags;
gboolean dimmed = FALSE;
+
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
- flags = TNY_HEADER_FLAG_SEEN;
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+ if (!header) {
+ dimmed = TRUE;
+ }
- /* Check dimmed rule */
- if (!dimmed)
- dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
if (!dimmed) {
- dimmed = _selected_msg_marked_as (win, flags, TRUE);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ flags = tny_header_get_flags (header);
+ if (!(flags & TNY_HEADER_FLAG_SEEN))
+ dimmed = TRUE;
}
+ if (header)
+ g_object_unref (header);
return dimmed;
}
gboolean
-modest_ui_dimming_rules_on_move_to (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_mark_as_read_msg (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ TnyHeaderFlags flags;
+ const DimmedState *state = NULL;
+ 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);
+ state = modest_window_get_dimming_state (win);
+
+ flags = TNY_HEADER_FLAG_SEEN;
+
+ /* Check dimmed rule */
+ dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+ if (!dimmed) {
+ dimmed = state->all_marked_as_seen;
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+ }
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_mark_as_unread_msg (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ TnyHeaderFlags flags;
+ const DimmedState *state = NULL;
+ 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);
+ state = modest_window_get_dimming_state (win);
+
+ flags = TNY_HEADER_FLAG_SEEN;
+
+ /* Check dimmed rule */
+ dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+ if (!dimmed) {
+ dimmed = !state->any_marked_as_seen;
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+ }
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_move_to (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
if (MODEST_IS_MAIN_WINDOW (win))
dimmed = modest_ui_dimming_rules_on_main_window_move_to (win, user_data);
+#ifdef MODEST_TOOLKIT_HILDON2
+ else if (MODEST_IS_HEADER_WINDOW (win))
+ dimmed = modest_ui_dimming_rules_on_header_window_move_to (win, user_data);
+#endif
else if (MODEST_IS_MSG_VIEW_WINDOW (win))
dimmed = modest_ui_dimming_rules_on_view_window_move_to (win, user_data);
modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user_data)
{
GtkWidget *folder_view = NULL;
- GtkWidget *header_view = NULL;
ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), TRUE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
/* Get the folder view */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
- /* Get header view */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
- /* Check diming rules for folders and messages transfer */
+ /* Check diming rules for folders transfer */
+ if (folder_view && gtk_widget_is_focus (folder_view)) {
+ TnyFolderType types[5];
+
+ types[0] = TNY_FOLDER_TYPE_DRAFTS;
+ types[1] = TNY_FOLDER_TYPE_OUTBOX;
+ types[2] = TNY_FOLDER_TYPE_SENT;
+ types[3] = TNY_FOLDER_TYPE_ROOT;
+ types[4] = TNY_FOLDER_TYPE_INBOX;
+
+ /* Apply folder rules */
+ dimmed = _selected_folder_not_moveable (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
+ if (!dimmed) {
+ dimmed = _selected_folder_is_any_of_type (win, types, 5);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
+ }
+ }
+
+ /* Check diming rules for messages transfer */
+ if (!dimmed) {
+ dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+ if (dimmed) {
+ gchar *message = g_strdup_printf(_("emev_nc_unabletomove_items"),
+ state->already_opened_msg);
+ modest_dimming_rule_set_notification (rule, message);
+ g_free(message);
+ }
+ }
if (!dimmed) {
- if (!gtk_widget_is_focus (folder_view))
+ if (!(folder_view && gtk_widget_is_focus (folder_view)))
dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
}
+ if (!dimmed) {
+ dimmed = _selected_msg_sent_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("sfil_ib_unable_to_move_selected_items"));
+ }
return dimmed;
}
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
if (!dimmed) {
- dimmed = _transfer_mode_enabled (win);
+ dimmed = modest_window_get_dimming_state (win)->any_marked_as_deleted;
+ if (dimmed) {
+ gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win);
+ modest_dimming_rule_set_notification (rule, msg);
+ g_free (msg);
+ }
+ }
+
+ if (!dimmed) {
+ dimmed = _selected_msg_sent_in_progress (win);
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item"));
}
+
+ /* This could happen if we're viewing a message of the outbox
+ that has been already sent */
+ if (!dimmed)
+ dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
+
if (!dimmed) {
- dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW(win));
+ if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ /* The move_to button should be dimmed when viewing an attachment,
+ * but should be enabled when viewing a message from the list,
+ * or when viewing a search result.
+ */
+ if (!modest_msg_view_window_is_search_result (MODEST_MSG_VIEW_WINDOW(win))) {
+ dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW (win));
+ }
+ }
+
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_move_mail_attachment"));
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item"));
}
return dimmed;
}
+#ifdef MODEST_TOOLKIT_HILDON2
gboolean
-modest_ui_dimming_rules_on_find_msg (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_header_window_move_to (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_HEADER_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
if (!dimmed) {
- dimmed = _transfer_mode_enabled (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+ GtkWidget *header_view;
+ TnyFolder *folder;
+
+ header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
+ folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
+ if (folder) {
+ dimmed = (tny_folder_get_all_count (TNY_FOLDER (folder)) == 0);
+ g_object_unref (folder);
+ }
}
return dimmed;
}
+#endif
gboolean
-modest_ui_dimming_rules_on_paste_msgs (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_find_msg (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
- TnyFolderType types[3];
gboolean dimmed = FALSE;
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+
+ /* Check dimmed rule */
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_paste (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[2] = TNY_FOLDER_TYPE_SENT;
/* Check dimmed rule */
+ dimmed = _clipboard_is_empty (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule,
+ _CS("ecoc_ib_edwin_nothing_to_paste"));
if (!dimmed) {
- dimmed = _clipboard_is_empty (win);
+ dimmed = _selected_folder_is_any_of_type (win, types, 3);
if (dimmed)
- modest_dimming_rule_set_notification (rule, dgettext("hildon-common-strings", "ecoc_ib_edwin_nothing_to_paste"));
+ modest_dimming_rule_set_notification (rule,
+ _CS("ckct_ib_unable_to_paste_here"));
}
if (!dimmed) {
- dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ dimmed = !_folder_view_has_focus (win);
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("ckct_ib_unable_to_paste_here"));
+ modest_dimming_rule_set_notification (rule,
+ _CS("ckct_ib_unable_to_paste_here"));
+ }
+ if (!dimmed) {
+ dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win), TRUE);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule,
+ _CS("ckct_ib_unable_to_paste_here"));
}
if (!dimmed) {
dimmed = _selected_folder_is_same_as_source (win);
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_copy_samefolder"));
+ modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_copy_target_error"));
}
-
+ if (!dimmed) {
+ dimmed = _selected_folder_has_subfolder_with_same_name (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_copy_target_error"));
+ }
+
return dimmed;
}
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
+ GtkWidget *focused = NULL;
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
- /* Check dimmed rule */
- if (!dimmed) {
- dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ /* Main window dimming rules */
+ if (MODEST_IS_MAIN_WINDOW (win))
+ dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
+
+ if (!dimmed && MODEST_IS_MAIN_WINDOW (win))
+ dimmed = _header_view_is_all_selected (MODEST_MAIN_WINDOW(win));
+
+ if (!dimmed && GTK_IS_ENTRY (focused)) {
+ const gchar *current_text;
+ current_text = gtk_entry_get_text (GTK_ENTRY (focused));
+ dimmed = ((current_text == NULL) || (current_text[0] == '\0'));
}
-
+
+ if (!dimmed && GTK_IS_TEXT_VIEW (focused)) {
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+ dimmed = (gtk_text_buffer_get_char_count (buffer) < 1);
+ }
+
+ if (dimmed && MODEST_IS_ATTACHMENTS_VIEW (focused))
+ dimmed = FALSE;
return dimmed;
}
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
- if (!dimmed)
- dimmed = _invalid_attach_selected (win, TRUE, TRUE, rule);
+ dimmed = _invalid_attach_selected (win, TRUE, TRUE, FALSE, rule);
if (!dimmed) {
dimmed = _purged_attach_selected (win, FALSE, NULL);
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
- if (!dimmed)
- dimmed = _invalid_attach_selected (win, FALSE, FALSE, rule);
+ dimmed = _invalid_attach_selected (win, FALSE, FALSE, FALSE, rule);
if (!dimmed) {
dimmed = _purged_attach_selected (win, FALSE, NULL);
modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
/* Check in main window if there's only one message selected */
- if (!dimmed && MODEST_IS_MAIN_WINDOW (win)) {
+ if (MODEST_IS_MAIN_WINDOW (win)) {
dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW (win), TRUE, rule);
}
/* Check in view window if there's any attachment selected */
if (!dimmed && MODEST_IS_MSG_VIEW_WINDOW (win)) {
- dimmed = _invalid_attach_selected (win, FALSE, FALSE, NULL);
+ dimmed = _invalid_attach_selected (win, FALSE, FALSE, TRUE, NULL);
if (dimmed)
modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected"));
}
+#ifndef MODEST_TOOLKIT_HILDON2
+ /* Messages as attachments could not be removed */
+ if (!dimmed && MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ TnyList *attachments;
+ TnyIterator *iter;
+ attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW (win));
+ if (attachments) {
+ iter = tny_list_create_iterator (attachments);
+ while (!tny_iterator_is_done (iter) && !dimmed) {
+ TnyMimePart *mime_part = (TnyMimePart *)
+ tny_iterator_get_current (iter);
+ if (modest_tny_mime_part_is_msg (mime_part))
+ dimmed = TRUE;
+ g_object_unref (mime_part);
+ tny_iterator_next (iter);
+ }
+ g_object_unref (iter);
+ g_object_unref (attachments);
+ }
+ }
+#endif
+
+ if (!dimmed) {
+
+ dimmed = _selected_msg_sent_in_progress (win);
+ if (dimmed) {
+ modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
+ }
+ }
+
/* cannot purge in editable drafts nor pop folders */
if (!dimmed) {
dimmed = _invalid_folder_for_purge (win, rule);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
}
/* Check if the selected message in main window has attachments */
if (!dimmed && MODEST_IS_MAIN_WINDOW (win)) {
- dimmed = _selected_msg_marked_as (win, TNY_HEADER_FLAG_ATTACHMENTS, TRUE);
+ dimmed = !(state->any_has_attachments);
if (dimmed)
modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
}
modest_dimming_rule_set_notification (rule, _("mail_ib_attach_not_local"));
}
-
return dimmed;
}
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
- if (!dimmed) {
+ if (MODEST_IS_MAIN_WINDOW (win)) {
dimmed = _clipboard_is_empty (win);
if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
+
+ if (!dimmed && MODEST_IS_MSG_EDIT_WINDOW (win)) {
+ dimmed = !modest_msg_edit_window_can_undo (MODEST_MSG_EDIT_WINDOW (win));
+ }
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_redo (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ gboolean dimmed = FALSE;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+
+ /* Check dimmed rule */
+ if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
+ dimmed = !modest_msg_edit_window_can_redo (MODEST_MSG_EDIT_WINDOW (win));
+ }
return dimmed;
}
modest_ui_dimming_rules_on_cut (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
/* Check common dimming rules */
- if (!dimmed) {
- dimmed = _invalid_clipboard_selected (win, rule);
- }
+ dimmed = _invalid_clipboard_selected (win, rule);
/* Check window specific dimming rules */
if (MODEST_IS_MAIN_WINDOW (win)) {
- if (!dimmed) {
- dimmed = _selected_folder_not_writeable (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_delete"));
- }
- if (!dimmed) {
- dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ /* Get focused widget */
+ GtkWidget *focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ if (MODEST_IS_HEADER_VIEW (focused)) {
+ if (!dimmed) {
+ dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+ }
+ if (!dimmed) {
+ dimmed = _selected_msg_sent_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
+ }
+ if (!dimmed) {
+ dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+ if(dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
+ }
}
- if (!dimmed) {
- dimmed = _selected_msg_sent_in_progress (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
+ else if (MODEST_IS_FOLDER_VIEW (focused)) {
+ TnyFolderType types[3];
+
+ types[0] = TNY_FOLDER_TYPE_DRAFTS;
+ types[1] = TNY_FOLDER_TYPE_OUTBOX;
+ types[2] = TNY_FOLDER_TYPE_SENT;
+
+ /* Apply folder rules */
+ if (!dimmed) {
+ dimmed = _selected_folder_not_deletable (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
+ }
+ if (!dimmed) {
+ dimmed = _selected_folder_is_root_or_inbox (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
+ }
+ if (!dimmed) {
+ dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
+ }
}
}
-
+
return dimmed;
}
modest_ui_dimming_rules_on_copy (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
-
+
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
/* Check common dimming rules */
- if (!dimmed) {
- dimmed = _invalid_clipboard_selected (win, rule);
- }
+ dimmed = _invalid_clipboard_selected (win, rule);
/* Check window specific dimming rules */
if (MODEST_IS_MAIN_WINDOW (win)) {
- if (!dimmed) {
- dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
- }
- if (!dimmed) {
- dimmed = _selected_msg_sent_in_progress (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
+ /* Get focused widget */
+ GtkWidget *focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ if (MODEST_IS_HEADER_VIEW (focused)) {
+ if (!dimmed) {
+ dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
+ }
+ if (!dimmed) {
+ dimmed = _selected_msg_sent_in_progress (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _(""));
+ }
+ if (!dimmed) {
+ dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+ if(dimmed)
+ modest_dimming_rule_set_notification (rule, _(""));
+ }
+ }
+ else if (MODEST_IS_FOLDER_VIEW (focused)) {
+ TnyFolderType types[3];
+
+ types[0] = TNY_FOLDER_TYPE_DRAFTS;
+ types[1] = TNY_FOLDER_TYPE_OUTBOX;
+ types[2] = TNY_FOLDER_TYPE_SENT;
+
+ if (!dimmed) {
+ dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _(""));
+ }
+ if (!dimmed) {
+ dimmed = _selected_folder_is_any_of_type (win, types, 3);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _(""));
+ }
}
}
}
gboolean
-modest_ui_dimming_rules_on_view_previous (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_set_style (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
- /* Check dimmed rule */
+ /* Check common dimming rules */
+ ModestMsgEditFormat format;
+ format = modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
+
+ dimmed = (format != MODEST_MSG_EDIT_FORMAT_HTML);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_item_unavailable_plaintext"));
+
if (!dimmed) {
- dimmed = _transfer_mode_enabled (win);
+ GtkWidget *body;
+ body = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
+
+ dimmed = ((body == NULL)||(!gtk_widget_is_focus (body)));
if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_move_cursor_to_message"));
}
- if (!dimmed) {
- dimmed = modest_msg_view_window_first_message_selected (MODEST_MSG_VIEW_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
- }
-
+
+
return dimmed;
}
gboolean
-modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_zoom (ModestWindow *win, gpointer user_data)
{
- ModestDimmingRule *rule = NULL;
+ ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
+
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
- /* Check dimmed rule */
- if (!dimmed) {
- dimmed = _transfer_mode_enabled (win);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
- }
- if (!dimmed) {
- dimmed = modest_msg_view_window_last_message_selected (MODEST_MSG_VIEW_WINDOW(win));
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
- }
-
- return dimmed;
-}
-
-
-gboolean
-modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
-{
- const gboolean dimmed =
- !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(),
- TRUE);
-
+ GtkWidget *body;
+ body = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
+
+ dimmed = ((body == NULL)||(!gtk_widget_is_focus (body)));
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_move_cursor_to_message"));
+
return dimmed;
}
gboolean
-modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_editor_paste (ModestWindow *win, gpointer user_data)
{
- ModestDimmingRule *rule = NULL;
- TnyFolderType types[1];
- guint n_messages = 0;
+ ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
gboolean dimmed = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ GtkWidget *focused = NULL;
+
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
- types[0] = TNY_FOLDER_TYPE_OUTBOX;
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
- /* Check dimmed rules */
+ dimmed = MODEST_IS_ATTACHMENTS_VIEW (focused);
+
if (!dimmed) {
- dimmed = _already_opened_msg (win, &n_messages);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_ib_message_unableto_cancel_send"));
+ dimmed = GTK_IS_TOGGLE_BUTTON (focused);
}
+
if (!dimmed) {
- dimmed = !_selected_folder_is_any_of_type (win, types, 1);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, "");
+ ModestEmailClipboard *e_clipboard = modest_runtime_get_email_clipboard ();
+ const gchar *clipboard_text = modest_msg_edit_window_get_clipboard_text (MODEST_MSG_EDIT_WINDOW (win));
+
+ dimmed = modest_email_clipboard_cleared (e_clipboard) &&
+ ((clipboard_text == NULL) || (clipboard_text[0] == '\0'));
}
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
+ gboolean dimmed = FALSE;
+ TnyList *selected_attachments = NULL;
+ gint n_att_selected = 0;
+ GtkWidget *attachments_view;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
+ rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
+
+ attachments_view = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS);
+
+ selected_attachments = modest_attachments_view_get_selection (
+ MODEST_ATTACHMENTS_VIEW (attachments_view));
+ n_att_selected = tny_list_get_length (selected_attachments);
+ g_object_unref (selected_attachments);
+
+ dimmed = (n_att_selected < 1);
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ const DimmedState *state = NULL;
+ gboolean dimmed = FALSE;
+ GtkWidget *subject_field, *body_field;
+ GtkTextBuffer *body_buffer;
+ const gchar *subject = NULL;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
+ rule = MODEST_DIMMING_RULE (user_data);
+ state = modest_window_get_dimming_state (win);
+
+ body_field = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
+ subject_field = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_SUBJECT);
+ body_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (body_field));
+ subject = gtk_entry_get_text (GTK_ENTRY (subject_field));
+
+ dimmed = (subject == NULL || subject[0] == '\0');
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_subject_not_modified"));
+
+ if (!dimmed) {
+ GtkWidget *to_field, *cc_field, *bcc_field;
+ GtkTextBuffer * to_buffer, *cc_buffer, *bcc_buffer;
+ cc_field = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_CC);
+ to_field = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_TO);
+ bcc_field = modest_msg_edit_window_get_child_widget (
+ MODEST_MSG_EDIT_WINDOW (win),
+ MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BCC);
+ to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (to_field));
+ cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (cc_field));
+ bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (bcc_field));
+
+ dimmed = ((gtk_text_buffer_get_char_count (to_buffer) +
+ gtk_text_buffer_get_char_count (cc_buffer) +
+ gtk_text_buffer_get_char_count (bcc_buffer)) == 0);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_ib_add_recipients_first"));
+ }
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_view_previous (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ gboolean dimmed = FALSE;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
+
+ /* Check dimmed rule */
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
+ if (!dimmed) {
+ dimmed = modest_msg_view_window_first_message_selected (
+ MODEST_MSG_VIEW_WINDOW(win));
+ modest_dimming_rule_set_notification (rule, NULL);
+ }
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ gboolean dimmed = FALSE;
+
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+
+ /* Check dimmed rule */
+ dimmed = _transfer_mode_enabled (win);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
+ if (!dimmed) {
+ dimmed = modest_msg_view_window_last_message_selected (MODEST_MSG_VIEW_WINDOW (win));
+ modest_dimming_rule_set_notification (rule, NULL);
+ }
+
+ return dimmed;
+}
+
+
+gboolean
+modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
+{
+ return !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(),
+ TRUE);
+}
+
+gboolean
+modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ TnyFolderType types[1];
+ const DimmedState *state = NULL;
+ 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);
+ state = modest_window_get_dimming_state (win);
+
+ types[0] = TNY_FOLDER_TYPE_OUTBOX;
+
+ /* Check dimmed rules */
+ dimmed = !_selected_folder_is_any_of_type (win, types, 1);
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, "");
if (!dimmed) {
- dimmed = !_sending_in_progress (win);
- if (dimmed)
+ dimmed = !state->sent_in_progress;
+ if (dimmed)
modest_dimming_rule_set_notification (rule, "");
}
}
gboolean
+modest_ui_dimming_rules_on_cancel_sending_all (ModestWindow *win, gpointer user_data)
+{
+ /* We dim if no msg send is in progress (and then cancelling send all has no
+ * effect */
+ return !_msgs_send_in_progress ();
+}
+
+gboolean
modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
-
+ ModestAccountMgr *mgr;
+ const gchar* account_name;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+ mgr = modest_runtime_get_account_mgr();
+
+ /* Check dimmed rule */
+ account_name = modest_window_get_active_account (win);
+ dimmed = modest_account_mgr_account_is_busy (mgr, account_name);
+
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+
+ return dimmed;
+}
+
+gboolean
+modest_ui_dimming_rules_on_send_receive_all (ModestWindow *win, gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+ gboolean dimmed = FALSE;
+
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
/* Check dimmed rule */
+ GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE);
+ if (g_slist_length (account_names) < 1)
+ dimmed = TRUE;
+ if (dimmed)
+ modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+
+ modest_account_mgr_free_account_names (account_names);
+
if (!dimmed) {
- dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(),
- TRUE);
- if (dimmed)
- modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+ dimmed = _send_receive_in_progress (win);
}
return dimmed;
}
+#ifdef MODEST_TOOLKIT_HILDON2
+gboolean
+modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data)
+{
+ TnyMsg *msg;
+ GSList *recipients, *node;
+ gboolean has_recipients_to_add;
+
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE);
+
+ msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+
+ /* Message is loaded asynchronously, so this could happen */
+ if (!msg) {
+#ifdef MODEST_TOOLKIT_HILDON2
+ TnyHeader *header;
+
+ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+ if (!header)
+ return TRUE;
+
+ recipients = modest_tny_msg_header_get_all_recipients_list (header);
+ g_object_unref (header);
+#else
+ return TRUE;
+#endif
+ } else {
+ recipients = modest_tny_msg_get_all_recipients_list (msg);
+ g_object_unref (msg);
+ }
+
+ has_recipients_to_add = FALSE;
+ for (node = recipients; node != NULL; node = g_slist_next (node)) {
+ if (!modest_address_book_has_address ((const gchar *) node->data)) {
+ has_recipients_to_add = TRUE;
+ break;
+ }
+ }
+
+ g_slist_foreach (recipients, (GFunc) g_free, NULL);
+ g_slist_free (recipients);
+
+ return !has_recipients_to_add;
+}
+#else
gboolean
modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_data)
{
ModestDimmingRule *rule = NULL;
gboolean dimmed = FALSE;
+ GtkWidget *focused = NULL;
- g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
rule = MODEST_DIMMING_RULE (user_data);
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ dimmed = !focused;
- /* Check dimmed rule */
if (!dimmed) {
- GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
gchar *selection = NULL;
- selection = gtk_clipboard_wait_for_text (clipboard);
-
- dimmed = !((selection != NULL) && (modest_text_utils_validate_recipient (selection)));
+ if (GTK_IS_TEXT_VIEW (focused)) {
+ GtkTextIter start, end;
+ GtkTextBuffer *buffer = NULL;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+ if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end)) {
+ selection = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+ }
+ } else if (GTK_IS_LABEL (focused)) {
+ selection = modest_text_utils_label_get_selection (GTK_LABEL (focused));
+ } else {
+ gboolean do_check = TRUE;
+ GtkClipboard *clipboard;
+ if (GTK_IS_HTML (focused)) {
+ const gchar *sel;
+ int len = -1;
+ sel = gtk_html_get_selection_html (GTK_HTML (focused), &len);
+ do_check = !((sel == NULL) || (sel[0] == '\0'));
+ } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
+ do_check = FALSE;
+ }
+ if (do_check) {
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ selection = gtk_clipboard_wait_for_text (clipboard);
+ } else {
+ selection = NULL;
+ }
+ }
+ dimmed = !((selection != NULL) && (modest_text_utils_validate_recipient (selection, NULL)));
}
return dimmed;
}
+#endif
/* *********************** static utility functions ******************** */
-static gboolean
-_marked_as_deleted (ModestWindow *win)
+
+static gboolean
+_selected_folder_not_writeable (ModestMainWindow *win,
+ gboolean for_paste)
{
+ GtkWidget *folder_view = NULL;
+ TnyFolderStore *parent_folder = NULL;
+ ModestEmailClipboard *clipboard = NULL;
+ ModestTnyFolderRules rules;
+ gboolean is_local_acc = FALSE;
+ gboolean xfer_folders = FALSE;
gboolean result = FALSE;
- TnyHeaderFlags flags;
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_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ /* If no folder view, always dimmed */
+ if (!folder_view)
+ return TRUE;
- flags = TNY_HEADER_FLAG_DELETED;
+ /* Get selected folder as parent of new folder to create */
+ parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (!(parent_folder && TNY_IS_FOLDER(parent_folder))) {
+ /* If it's the local account and its transfering folders, then do not dim */
+ if (TNY_IS_ACCOUNT (parent_folder)) {
+ is_local_acc = modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder));
+ if (for_paste) {
+ clipboard = modest_runtime_get_email_clipboard ();
+ xfer_folders = modest_email_clipboard_folder_copied (clipboard);
+ }
+ }
+ if (for_paste)
+ result = !(is_local_acc && xfer_folders);
+ else
+ result = !is_local_acc;
+ goto frees;
+ }
+
/* Check dimmed rule */
- result = _selected_msg_marked_as (win, flags, FALSE);
+ rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
+ result = rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE;
+
+ /* free */
+ frees:
+ if (parent_folder != NULL)
+ g_object_unref (parent_folder);
+
+ return result;
+}
+
+static gboolean
+_selected_folder_not_deletable (ModestMainWindow *win)
+{
+ GtkWidget *folder_view = NULL;
+ TnyFolderStore *parent_folder = NULL;
+ ModestTnyFolderRules rules;
+ 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_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ /* If no folder view, always dimmed */
+ if (!folder_view)
+ return TRUE;
+ /* Get selected folder as parent of new folder to create */
+ parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (!(parent_folder && TNY_IS_FOLDER(parent_folder))) {
+ result = TRUE;
+ goto frees;
+ }
+
+ /* Check dimmed rule */
+ rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
+ result = rules & MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE;
+
+ /* free */
+ frees:
+ if (parent_folder != NULL)
+ g_object_unref (parent_folder);
+
return result;
}
static gboolean
-_selected_folder_not_writeable (ModestMainWindow *win)
+_selected_folder_not_moveable (ModestMainWindow *win)
{
GtkWidget *folder_view = NULL;
TnyFolderStore *parent_folder = NULL;
/* Get folder view */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
/* If no folder view, always dimmed */
if (!folder_view)
return TRUE;
/* Get selected folder as parent of new folder to create */
parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
if (!(parent_folder && TNY_IS_FOLDER(parent_folder))) {
- if (parent_folder)
- g_object_unref (parent_folder);
+ result = TRUE;
+ goto frees;
+ }
+
+ /* Check dimmed rule */
+ rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
+ result = rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE;
+
+ /* free */
+ frees:
+ if (parent_folder != NULL)
+ g_object_unref (parent_folder);
+
+ return result;
+}
+
+static gboolean
+_selected_folder_not_renameable (ModestMainWindow *win)
+{
+ GtkWidget *folder_view = NULL;
+ TnyFolderStore *parent_folder = NULL;
+ ModestTnyFolderRules rules;
+ 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_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ /* If no folder view, always dimmed */
+ if (!folder_view)
return TRUE;
+
+ /* Get selected folder as parent of new folder to create */
+ parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (!(parent_folder && TNY_IS_FOLDER(parent_folder))) {
+ result = TRUE;
+ goto frees;
}
/* Check dimmed rule */
rules = modest_tny_folder_get_rules (TNY_FOLDER (parent_folder));
- result = rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE;
+ result = rules & MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE;
/* free */
- g_object_unref (parent_folder);
+ frees:
+ if (parent_folder != NULL)
+ g_object_unref (parent_folder);
return result;
}
/* Check pop and MMC accounts */
if (!result) {
- result = _selected_folder_is_MMC_or_POP_root (win);
+ result = _selected_folder_is_root (win);
}
return result;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
+ /* All accounts are root items: */
+ GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ if (folder_view) {
+ gboolean is_account = FALSE;
+ TnyFolderStore *folder_store =
+ modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (folder_store) {
+ is_account = TNY_IS_ACCOUNT (folder_store);
+
+ g_object_unref (folder_store);
+ folder_store = NULL;
+ }
+
+ if (is_account)
+ return TRUE;
+ }
+
+ /* Try something more precise: */
types[0] = TNY_FOLDER_TYPE_ROOT;
/* Check folder type */
result = _selected_folder_is_any_of_type (MODEST_WINDOW(win), types, 1);
- /* Check pop and MMC accounts */
- if (!result) {
- result = _selected_folder_is_MMC_or_POP_root (win);
- }
-
return result;
}
static gboolean
-_selected_folder_is_MMC_or_POP_root (ModestMainWindow *win)
+_header_view_is_all_selected (ModestMainWindow *win)
{
- GtkWidget *folder_view = NULL;
- TnyFolderStore *parent_folder = NULL;
- gboolean result = FALSE;
-
- folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
- /* Get selected folder as parent of new folder to create */
- parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
- if (!parent_folder)
- return TRUE;
-
- if (TNY_IS_ACCOUNT (parent_folder)) {
- /* If it's the local account then do not dim */
- if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
- result = FALSE;
- } else {
- /* If it's the MMC root folder then dim it */
- if (!strcmp (tny_account_get_id (TNY_ACCOUNT (parent_folder)), MODEST_MMC_ACCOUNT_ID)) {
- result = TRUE;
- } else {
- const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
- /* If it's POP then dim */
- result = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
- MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
- }
- }
- }
- g_object_unref (parent_folder);
-
- return result;
-}
+ const DimmedState *state = NULL;
+ g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
+ state = modest_window_get_dimming_state (MODEST_WINDOW(win));
+ return state->all_selected;
+}
static gboolean
_selected_folder_is_empty (ModestMainWindow *win)
{
- GtkWidget *folder_view = NULL;
+ GtkWidget *folder_view = NULL, *header_view = NULL;
TnyFolderStore *folder = NULL;
gboolean result = FALSE;
/* Get folder view */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+
+ header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+
/* If no folder view, always dimmed */
- if (!folder_view)
+ if (!folder_view || !header_view)
return TRUE;
/* Get selected folder as parent of new folder to create */
}
/* Check folder type */
- result = tny_folder_get_all_count (TNY_FOLDER (folder)) == 0;
+ if (modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)) ||
+ tny_folder_get_all_count (TNY_FOLDER (folder)) == 0)
+ result = TRUE;
/* free */
g_object_unref (folder);
}
static gboolean
+_folder_view_has_focus (ModestWindow *win)
+{
+ GtkWidget *folder_view = NULL;
+
+ 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_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ if (!folder_view)
+ return FALSE;
+
+ if (gtk_widget_is_focus(folder_view))
+ return TRUE;
+
+ return FALSE;
+}
+
+static gboolean
_selected_folder_is_same_as_source (ModestWindow *win)
{
ModestEmailClipboard *clipboard = NULL;
/* Get folder view */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
if (!folder_view)
return FALSE;
}
/* Check source folder */
- result = modest_email_clipboard_check_source_folder (clipboard,
- (const TnyFolder *) folder);
+ result = modest_email_clipboard_check_source_folder (clipboard, TNY_FOLDER (folder));
/* Free */
frees:
guint i=0;
gboolean result = FALSE;
- /*Get curent folder */
+ /*Get current folder */
if (MODEST_IS_MAIN_WINDOW(win)) {
/* Get folder view */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
/* If no folder view, always dimmed */
if (!folder_view)
- return TRUE;
+ return FALSE;
/* Get selected folder as parent of new folder to create */
folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
if (!(folder && TNY_IS_FOLDER(folder))) {
if (folder)
g_object_unref (folder);
- return TRUE;
+ return FALSE;
}
/* Check folder type */
/* free */
- g_object_unref (folder);
+ if (folder)
+ g_object_unref (folder);
return result;
}
_folder_is_any_of_type (TnyFolder *folder,
TnyFolderType types[],
guint ntypes)
-{
- TnyFolderType folder_type;
- gboolean result = FALSE;
- guint i;
-
- g_return_val_if_fail (TNY_IS_FOLDER(folder), FALSE);
-
- /* Get folder type */
- if (modest_tny_folder_is_local_folder (folder))
- folder_type = modest_tny_folder_get_local_folder_type (folder);
- else
- folder_type = modest_tny_folder_guess_folder_type (folder);
-
- /* Check foler type */
- for (i=0; i < ntypes; i++) {
- result = result || folder_type == types[i];
- }
-
- return result;
-}
-
-static gboolean
-_selected_folder_is_snd_level (ModestMainWindow *win)
-{
- GtkWidget *folder_view = NULL;
- GtkTreeSelection *sel = NULL;
- GtkTreeModel *model = NULL;
- GtkTreePath *path = NULL;
- GtkTreeIter iter;
- TnyFolderStore *folder = NULL;
- gboolean result = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), TRUE);
-
- /*Get curent folder */
- folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
- /* If no folder view, always dimmed */
- if (!folder_view)
- goto frees;
-
- /* Get selected folder as parent of new folder to create */
- folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
- if (!(folder && TNY_IS_FOLDER(folder))) {
- goto frees;
- }
-
- /* Check folder level */
- sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(folder_view));
- if (!gtk_tree_selection_get_selected (sel, &model, &iter))
- goto frees;
- path = gtk_tree_model_get_path (model, &iter);
- result = gtk_tree_path_get_depth (path) > 2;
-
- frees:
- if (folder != NULL)
- g_object_unref (folder);
- if (path != NULL)
- gtk_tree_path_free (path);
+{
+ TnyFolderType folder_type;
+ gboolean result = FALSE;
+ guint i;
+
+ g_return_val_if_fail (TNY_IS_FOLDER(folder), FALSE);
+
+ /* Get folder type */
+ folder_type = modest_tny_folder_guess_folder_type (folder);
+ if (folder_type == TNY_FOLDER_TYPE_INVALID)
+ g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
- return result;
+ /* Check foler type */
+ for (i=0; i < ntypes; i++) {
+ result = result || folder_type == types[i];
+ }
+ return result;
}
static gboolean
static gboolean
_invalid_clipboard_selected (ModestWindow *win,
- ModestDimmingRule *rule)
+ ModestDimmingRule *rule)
{
+ const DimmedState *state = NULL;
gboolean result = FALSE;
+ GtkWidget *focused = NULL;
- 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)));
+ g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
+ state = modest_window_get_dimming_state (win);
+ /* Get focuesed widget */
+ focused = gtk_window_get_focus (GTK_WINDOW (win));
+
+ if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
+ gboolean has_selection = FALSE;
+ if (GTK_IS_TEXT_VIEW (focused)) {
+ GtkTextBuffer *buffer = NULL;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+ has_selection = modest_text_utils_buffer_selection_is_valid (buffer);
+ } else if (GTK_IS_EDITABLE (focused)) {
+ has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (focused), NULL, NULL);
+ }
+ result = !has_selection;
+ } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ if (focused) {
+ MODEST_DEBUG_BLOCK (g_message ("FOCUSED %s", g_type_name (G_TYPE_FROM_INSTANCE (focused))););
+ if (GTK_IS_LABEL (focused) &&
+ !gtk_label_get_selection_bounds (GTK_LABEL (focused), NULL, NULL)) {
+ result = TRUE;
+ } else if (GTK_IS_TEXT_VIEW (focused)) {
+ GtkTextBuffer *buffer;
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+ result = !gtk_text_buffer_get_has_selection (buffer);
+ } else if (GTK_IS_HTML (focused)) {
+ const gchar *sel;
+ int len = -1;
+ sel = gtk_html_get_selection_html (GTK_HTML (focused), &len);
+ result = ((sel == NULL) || (sel[0] == '\0'));
+ } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
+ result = TRUE;
+ } else {
+ GtkClipboard *clipboard;
+ gchar *selection;
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
+ /* Get clipboard selection*/
+ selection = gtk_clipboard_wait_for_text (clipboard);
+ /* Check dimming */
+ result = (selection == NULL);
+ g_free (selection);
+ }
+ } else {
+ result = TRUE;
+ }
if (result)
- modest_dimming_rule_set_notification (rule, _(""));
+ modest_dimming_rule_set_notification (rule, "");
+
}
else if (MODEST_IS_MAIN_WINDOW (win)) {
- GtkWidget *header_view = NULL;
-
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
/* Check dimming */
- result = !modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view));
+ result = state->n_selected == 0;
if (result)
modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));
}
_invalid_attach_selected (ModestWindow *win,
gboolean unique,
gboolean for_view,
+ gboolean for_remove,
ModestDimmingRule *rule)
{
- GList *attachments, *node;
+ TnyList *attachments;
gint n_selected;
TnyHeaderFlags flags;
gboolean nested_attachments = FALSE;
gboolean selected_messages = FALSE;
+ const DimmedState *state = NULL;
gboolean result = FALSE;
+ g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
+ state = modest_window_get_dimming_state (win);
+
if (MODEST_IS_MAIN_WINDOW (win)) {
flags = TNY_HEADER_FLAG_ATTACHMENTS;
if (!result)
- result = _selected_msg_marked_as (win, flags, TRUE);
+ result = !state->any_has_attachments;
}
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);
+ n_selected = tny_list_get_length (attachments);
/* Check unique */
if (!result) {
/* 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);
+ TnyIterator *iter;
+ iter = tny_list_create_iterator (attachments);
+ while (!tny_iterator_is_done (iter) && !result) {
+ TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter));
TnyList *nested_list = tny_simple_list_new ();
- if (TNY_IS_MSG (mime_part)) {
- selected_messages = TRUE;
- result = TRUE;
+
+ if (!for_remove && modest_tny_mime_part_is_msg (mime_part)) {
+ TnyMsg *window_msg;
+ window_msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+ if ((TnyMimePart *) window_msg != mime_part) {
+ selected_messages = TRUE;
+ result = TRUE;
+ }
+ g_object_unref (window_msg);
}
tny_mime_part_get_parts (mime_part, nested_list);
- if (tny_list_get_length (nested_list) > 0) {
- nested_attachments = TRUE;
- result = TRUE;
+ if (!for_remove && tny_list_get_length (nested_list) > 0) {
+ nested_attachments = TRUE;
+ result = TRUE;
}
g_object_unref (nested_list);
+ g_object_unref (mime_part);
+ tny_iterator_next (iter);
}
+ g_object_unref (iter);
}
/* Set notifications */
}
/* Free */
- g_list_free (attachments);
+ g_object_unref (attachments);
}
return result;
static gboolean
_purged_attach_selected (ModestWindow *win, gboolean all, ModestDimmingRule *rule)
{
- GList *attachments = NULL, *node;
+ TnyList *attachments = NULL;
+ TnyIterator *iter;
gint purged = 0;
gint n_attachments = 0;
gboolean result = FALSE;
if (attachments == NULL)
return FALSE;
- for (node = attachments; node != NULL; node = g_list_next (node)) {
- TnyMimePart *mime_part = TNY_MIME_PART (node->data);
+ if (tny_list_get_length (attachments) == 0) {
+ g_object_unref (attachments);
+ return FALSE;
+ }
+
+ iter = tny_list_create_iterator (attachments);
+ while (!tny_iterator_is_done (iter)) {
+ TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter));
if (tny_mime_part_is_purged (mime_part)) {
purged++;
}
n_attachments++;
+ g_object_unref (mime_part);
+ tny_iterator_next (iter);
}
+ g_object_unref (iter);
/* Free */
- g_list_free (attachments);
+ g_object_unref (attachments);
if (all)
result = (purged == n_attachments);
else
result = (purged > 0);
+ /* This string no longer exists, refer to NB#75415 for more info
if (result && (rule != NULL))
modest_dimming_rule_set_notification (rule, _("mail_ib_attachment_already_purged"));
+ */
return result;
}
gboolean unique,
ModestDimmingRule *rule)
{
- GtkWidget *header_view = NULL;
GtkWidget *folder_view = NULL;
- gboolean selected_headers = FALSE;
+ const DimmedState *state = NULL;
gboolean result = FALSE;
g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), FALSE);
+ state = modest_window_get_dimming_state (MODEST_WINDOW(win));
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
/* Get folder view to check focus */
folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
-
- /* Get selected headers */
- selected_headers = modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view));
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
/* Check dimmed rule (TODO: check focus on widgets */
if (!result) {
- result = ((!selected_headers) ||
+ result = ((state->n_selected == 0 ) ||
(gtk_widget_is_focus (folder_view)));
if (result)
modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));
}
if (!result && unique) {
- result = modest_header_view_count_selected_headers (MODEST_HEADER_VIEW(header_view)) > 1;
+ result = state->n_selected > 1;
if (result)
modest_dimming_rule_set_notification (rule, _("mcen_ib_select_one_message"));
}
return result;
}
-static gboolean
-_already_opened_msg (ModestWindow *win,
- guint *n_messages)
-{
- //ModestWindow *window = NULL;
- ModestWindowMgr *mgr = NULL;
- GtkWidget *header_view = NULL;
- TnyList *selected_headers = NULL;
- TnyIterator *iter = NULL;
- TnyHeader *header = NULL;
- gboolean found;
-
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
-
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
-
- /* Check no selection */
- if (!modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view)))
- return FALSE;
-
- /* Get selected headers */
- selected_headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
- if (selected_headers == NULL)
- return FALSE;
-
- *n_messages = tny_list_get_length (selected_headers);
-
- /* Check dimmed rule (TODO: check focus on widgets */
- mgr = modest_runtime_get_window_mgr ();
- iter = tny_list_create_iterator (selected_headers);
- found = FALSE;
- while (!tny_iterator_is_done (iter)) {
- header = TNY_HEADER (tny_iterator_get_current (iter));
- found = modest_window_mgr_find_registered_header (mgr,header, NULL);
-
- g_object_unref (header);
- tny_iterator_next (iter);
-
- if (found)
- break;
- }
-
- /* free */
- if (selected_headers != NULL)
- g_object_unref (selected_headers);
- if (iter != NULL)
- g_object_unref (iter);
-
- return found;
-}
static gboolean
-_selected_msg_marked_as (ModestWindow *win,
- TnyHeaderFlags mask,
- gboolean opposite)
+_msg_download_in_progress (ModestWindow *win)
{
- GtkWidget *header_view = NULL;
- TnyList *selected_headers = NULL;
- TnyIterator *iter = NULL;
- TnyHeader *header = NULL;
- TnyHeaderFlags flags;
gboolean result = FALSE;
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
- /* Check no selection */
- if (!modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view)))
- return TRUE;
-
- /* Get selected headers */
- selected_headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
- if (selected_headers == NULL)
- return TRUE;
-
- /* Call the function for each header */
- iter = tny_list_create_iterator (selected_headers);
- while (!tny_iterator_is_done (iter) && !result) {
- header = TNY_HEADER (tny_iterator_get_current (iter));
-
- flags = tny_header_get_flags (header);
- if (opposite)
- result = (flags & mask) == 0;
- else
- result = (flags & mask) != 0;
+ g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
- g_object_unref (header);
- tny_iterator_next (iter);
+ if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+ result = modest_msg_view_window_toolbar_on_transfer_mode (MODEST_MSG_VIEW_WINDOW(win));
+ }
+ else if (MODEST_IS_MAIN_WINDOW (win)) {
+ result = modest_main_window_transfer_mode_enabled (MODEST_MAIN_WINDOW(win));
}
-
- /* free */
- if (selected_headers != NULL)
- g_object_unref (selected_headers);
- if (iter != NULL)
- g_object_unref (iter);
return result;
}
static gboolean
-_msg_download_in_progress (ModestMsgViewWindow *win)
+_msg_download_completed (ModestMainWindow *win)
{
- gboolean result = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE);
-
- result = modest_msg_view_window_toolbar_on_transfer_mode (win);
-
- return result;
+ const DimmedState *state = modest_window_get_dimming_state (MODEST_WINDOW(win));
+ return state->any_marked_as_cached;
}
-static gboolean
-_msg_download_completed (ModestMainWindow *win)
+static void
+fill_list_of_caches (gpointer key, gpointer value, gpointer userdata)
{
- GtkWidget *header_view = NULL;
- TnyList *selected_headers = NULL;
- TnyIterator *iter = NULL;
- TnyHeader *header = NULL;
- TnyHeaderFlags flags;
- gboolean result = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE);
-
-
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
- /* Check no selection */
- if (!modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view)))
- return TRUE;
-
- /* Get selected headers */
- selected_headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
- if (selected_headers == NULL)
- return TRUE;
-
- /* Check dimmed rule */
- result = TRUE;
- iter = tny_list_create_iterator (selected_headers);
- while (!tny_iterator_is_done (iter) && result) {
- header = TNY_HEADER (tny_iterator_get_current (iter));
-
- flags = tny_header_get_flags (header);
- /* TODO: is this the right flag?, it seems that some
- headers that have been previously downloaded do not
- come with it */
- result = (flags & TNY_HEADER_FLAG_CACHED);
-
- g_object_unref (header);
- tny_iterator_next (iter);
- }
-
- g_object_unref (iter);
-
- return result;
+ GSList **send_queues = (GSList **) userdata;
+ *send_queues = g_slist_prepend (*send_queues, value);
}
static gboolean
_selected_msg_sent_in_progress (ModestWindow *win)
{
- ModestTnySendQueue *send_queue = NULL;
- GtkWidget *header_view = NULL;
- ModestTnyAccountStore *acc_store = NULL;
- TnyAccount *account = NULL;
- TnyList *header_list = NULL;
- TnyIterator *iter = NULL;
- TnyHeader *header = NULL;
- const gchar *account_name = NULL;
- gboolean result = FALSE;
- gchar *id = NULL;
-
- /* Get transport account */
- acc_store = modest_runtime_get_account_store();
- account_name = modest_window_get_active_account (win);
-
- /* If no account defined, this action must be always dimmed */
- if (account_name == NULL) return FALSE;
- account = modest_tny_account_store_get_transport_account_for_open_connection (acc_store, account_name);
- if (!TNY_IS_TRANSPORT_ACCOUNT (account)) return FALSE;
-
- /* Get send queue for current ransport account */
- send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT(account));
- g_return_val_if_fail (MODEST_IS_TNY_SEND_QUEUE (send_queue), FALSE);
-
- if (MODEST_IS_MAIN_WINDOW(win)) {
-
- /* Get header view to check selected messages */
- header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
- MODEST_WIDGET_TYPE_HEADER_VIEW);
-
- /* Check no selection */
- if (!modest_header_view_has_selected_headers (MODEST_HEADER_VIEW(header_view)))
- return FALSE;
-
- /* Get selected headers */
- header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
-
- /* Get message header */
- if (!header_list) return FALSE;
- iter = tny_list_create_iterator (header_list);
- header = TNY_HEADER (tny_iterator_get_current (iter));
-
- /* Get message id */
- id = g_strdup(tny_header_get_message_id (header));
-
- } else if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
-
- /* Get message header */
- header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
-
- /* Get message id */
- id = g_strdup(tny_header_get_message_id (header));
- }
-
- /* Check if msg id is being processed inside send queue */
- result = modest_tny_send_queue_msg_is_being_sent (send_queue, id);
-
- /* Free */
- g_free(id);
- g_object_unref (header);
- g_object_unref(header_list);
- g_object_unref(iter);
-
- return result;
+ const DimmedState *state = modest_window_get_dimming_state (win);
+ return state->sent_in_progress;
}
static gboolean
-_sending_in_progress (ModestWindow *win)
-{
- gboolean result = FALSE;
-
- g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE);
-
- /* Check if send operation is in progress */
- result = modest_main_window_send_receive_in_progress (MODEST_MAIN_WINDOW (win));
-
- return result;
-}
-
-static gboolean
_invalid_folder_for_purge (ModestWindow *win,
ModestDimmingRule *rule)
{
- TnyMsg *msg = NULL;
TnyFolder *folder = NULL;
TnyAccount *account = NULL;
gboolean result = FALSE;
if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
/* Get folder and account of message */
- msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+ TnyMsg *msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
g_return_val_if_fail(msg != NULL, TRUE);
- folder = tny_msg_get_folder (msg);
+ folder = tny_msg_get_folder (msg);
+ g_object_unref (msg);
if (folder == NULL) {
- modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
- goto frees;
+ result = TRUE;
+ goto frees;
}
- g_object_unref (msg);
} else if (MODEST_IS_MAIN_WINDOW (win)) {
GtkWidget *folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
- MODEST_WIDGET_TYPE_FOLDER_VIEW);
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
if (!folder_view)
return FALSE;
- folder = TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
+ folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
+ /* Could be a folder store */
if (folder == NULL || ! TNY_IS_FOLDER (folder))
- return FALSE;
- g_object_ref (folder);
-
+ goto frees;
} else {
g_return_val_if_reached (FALSE);
}
if (_selected_folder_is_any_of_type (win, types, 2)) {
result = TRUE;
- modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_editable_msg"));
- } else {
- /* We're currently disabling purge in any local store */
- result = TRUE;
- modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
}
} 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;
+ ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (account));
+ /* If it's a remote folder then dim */
+ if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
+ protocol_type,
+ MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS)) {
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));
}
}
{
gboolean result = FALSE;
- g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), FALSE);
+ /* Check dimming */
+ if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
+ result = modest_msg_view_window_transfer_mode_enabled (MODEST_MSG_VIEW_WINDOW (win));
+ } else if (MODEST_IS_MAIN_WINDOW(win)) {
+ result = modest_main_window_transfer_mode_enabled (MODEST_MAIN_WINDOW (win));
+#ifdef MODEST_TOOLKIT_HILDON2
+ } else if (MODEST_IS_HEADER_WINDOW (win)) {
+ result = modest_header_window_transfer_mode_enabled (MODEST_HEADER_WINDOW (win));
+#endif
+ } else {
+ g_warning("_transfer_mode_enabled called with wrong window type");
+ }
+
+ return result;
+}
+
+static gboolean
+_selected_folder_has_subfolder_with_same_name (ModestWindow *win)
+{
+ GtkWidget *folder_view = NULL;
+ TnyFolderStore *folder = NULL;
+ ModestEmailClipboard *clipboard = NULL;
+ const gchar *folder_name = NULL;
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), TRUE);
+
+ /*Get current parent folder */
+ folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+ /* If no folder view, always dimmed */
+ if (!folder_view) return FALSE;
+
+ /* Get selected folder as parent of new folder to create */
+ folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
+ if (!(folder && TNY_IS_FOLDER(folder))) goto frees;
- /* Check dimming */
- result = modest_msg_view_window_transfer_mode_enabled (MODEST_MSG_VIEW_WINDOW (win));
+ /* get modest clipboard and source folder */
+ clipboard = modest_runtime_get_email_clipboard ();
+ folder_name = modest_email_clipboard_get_folder_name (clipboard);
+ if (folder_name == NULL) goto frees;
+
+ /* Check source subfolders names */
+ result = modest_tny_folder_has_subfolder_with_name (folder, folder_name,
+ TRUE);
+
+ /* Free */
+ frees:
+ if (folder != NULL)
+ g_object_unref (folder);
+
return result;
+}
+
+gboolean
+modest_ui_dimming_rules_on_save_to_drafts (ModestWindow *win,
+ gpointer user_data)
+{
+ ModestDimmingRule *rule = NULL;
+
+ g_return_val_if_fail (MODEST_MSG_EDIT_WINDOW (win), FALSE);
+ g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
+ rule = MODEST_DIMMING_RULE (user_data);
+
+ /* Check dimmed rule */
+ return !modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (win));
+}
+
+gboolean
+modest_ui_dimming_rules_on_insert_image (ModestWindow *win,
+ gpointer user_data)
+{
+ g_return_val_if_fail (MODEST_MSG_EDIT_WINDOW (win), FALSE);
+
+ ModestMsgEditFormat format =
+ modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
+
+ return (format != MODEST_MSG_EDIT_FORMAT_HTML);
+}
+
+static gboolean
+_send_receive_in_progress (ModestWindow *win)
+{
+ ModestMailOperationQueue *queue;
+ GSList *op_list, *node;
+ gboolean found_send_receive;
+
+ queue = modest_runtime_get_mail_operation_queue ();
+ op_list = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (win));
+
+ found_send_receive = FALSE;
+ for (node = op_list; node != NULL; node = g_slist_next (node)) {
+ ModestMailOperation *op;
+
+ op = (ModestMailOperation *) node->data;
+ if (modest_mail_operation_get_type_operation (op) == MODEST_MAIL_OPERATION_TYPE_SEND_AND_RECEIVE) {
+ found_send_receive = TRUE;
+ break;
+ }
+ }
+
+ g_slist_foreach (op_list, (GFunc) g_object_unref, NULL);
+ g_slist_free (op_list);
+
+ return found_send_receive;
+}
+
+static gboolean
+_msgs_send_in_progress (void)
+{
+ ModestCacheMgr *cache_mgr;
+ GHashTable *send_queue_cache;
+ ModestTnySendQueue *send_queue;
+ GSList *send_queues = NULL, *node = NULL;
+ gboolean found = FALSE;
+
+ cache_mgr = modest_runtime_get_cache_mgr ();
+ send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+ MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
+
+ g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
+
+ for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) {
+ send_queue = MODEST_TNY_SEND_QUEUE (node->data);
+
+ /* Check if msg uid is being processed inside send queue */
+ if (modest_tny_send_queue_sending_in_progress (send_queue)) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ g_slist_free (send_queues);
+
+ return found;
}