enum {
ACCOUNT_CHANGED_SIGNAL,
ACCOUNT_REMOVED_SIGNAL,
+ ACCOUNT_BUSY_SIGNAL,
LAST_SIGNAL
};
NULL, NULL,
modest_marshal_VOID__STRING_POINTER_BOOLEAN,
G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+ signals[ACCOUNT_BUSY_SIGNAL] =
+ g_signal_new ("account_busy_changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(ModestAccountMgrClass,account_busy_changed),
+ NULL, NULL,
+ modest_marshal_VOID__STRING_BOOLEAN,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
}
MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
priv->modest_conf = NULL;
+ priv->busy_accounts = NULL;
priv->timeout = g_timeout_add (1000 /* milliseconds */, on_timeout_notify_changes, obj);
}
}
}
-#if 0
-/* Not used. */
-GSList*
-modest_account_mgr_search_server_accounts (ModestAccountMgr * self,
- const gchar * account_name,
- ModestTransportStoreProtocol proto)
-{
- GSList *accounts;
- GSList *cursor;
- ModestAccountMgrPrivate *priv;
- gchar *key;
- GError *err = NULL;
-
- g_return_val_if_fail (self, NULL);
-
- key = _modest_account_mgr_get_account_keyname (account_name, NULL, TRUE);
- priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-
- /* get the list of all server accounts */
- accounts = modest_conf_list_subkeys (priv->modest_conf, key, &err);
- if (err) {
- g_printerr ("modest: failed to get subkeys for '%s' (%s)\n", key,
- err->message);
- g_error_free(err);
- return NULL;
- }
-
- /* filter out the ones with the wrong protocol */
- /* we could optimize for unknown proto / unknown type, but it will only
- * make the code more complex */
- cursor = accounts;
- while (cursor) {
- gchar *account = _modest_account_mgr_account_from_key ((gchar*)cursor->data, NULL, NULL);
- gchar *acc_proto = modest_account_mgr_get_string (self, account, MODEST_ACCOUNT_PROTO,TRUE);
- ModestTransportStoreProtocol this_proto =
- modest_protocol_info_get_transport_store_protocol (acc_proto);
- if (this_proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN && this_proto != proto) {
- GSList *nxt = cursor->next;
- accounts = g_slist_delete_link (accounts, cursor);
- cursor = nxt;
- } else
- cursor = cursor->next;
-
- g_free (account);
- g_free (acc_proto);
- }
-
- /* +1 because we must remove the ending '/' as well */
- strip_prefix_from_elements (accounts, strlen(key)+1);
- return accounts;
-}
-#endif
GSList*
modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled)
continue;
const gchar* account_name_key = (const gchar*)iter->data;
- /* printf ("DEBUG: %s: account_name_key=%s\n", __FUNCTION__, account_name_key); */
gchar* unescaped_name = account_name_key ?
modest_conf_key_unescape (account_name_key)
: NULL;
- /* printf (" DEBUG: %s: unescaped name=%s\n", __FUNCTION__, unescaped_name); */
gboolean add = TRUE;
if (only_enabled) {
}
}
- if (add) {
+ if (add)
result = g_slist_append (result, unescaped_name);
- }
- else {
+ else
g_free (unescaped_name);
- }
-
+
+ g_free (iter->data);
+ iter->data = NULL;
+
iter = g_slist_next (iter);
}
- /* TODO: Free the strings too? */
+
+ /* we already freed the strings in the loop */
g_slist_free (accounts);
+
accounts = NULL;
-
return result;
}
+void
+modest_account_mgr_free_account_names (GSList *account_names)
+{
+ g_slist_foreach (account_names, (GFunc)g_free, NULL);
+ g_slist_free (account_names);
+}
+
+
+
gchar *
modest_account_mgr_get_string (ModestAccountMgr *self, const gchar *name,
const gchar *key, gboolean server_account) {
GSList *cursor = NULL;
cursor = account_names = modest_account_mgr_account_names (self,
- TRUE /* enabled accounts, because disabled accounts are not user visible. */);
+ TRUE /* enabled accounts, because disabled accounts are not user visible. */);
gboolean found = FALSE;
modest_account_mgr_free_account_data (self, account_data);
cursor = cursor->next;
}
- g_slist_free (account_names);
+ modest_account_mgr_free_account_names (account_names);
+ account_names = NULL;
return found;
}
{
/* Check that at least one account exists: */
GSList *account_names = modest_account_mgr_account_names (self,
- enabled);
+ enabled);
gboolean accounts_exist = account_names != NULL;
- g_slist_free (account_names);
+
+ modest_account_mgr_free_account_names (account_names);
+ account_names = NULL;
return accounts_exist;
}
+
+static int
+compare_account_name(gconstpointer a, gconstpointer b)
+{
+ const gchar* account_name = (const gchar*) a;
+ const gchar* account_name2 = (const gchar*) b;
+ return strcmp(account_name, account_name2);
+}
+
+void
+modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name,
+ gboolean busy)
+{
+ ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+ if (busy)
+ {
+ GSList *account_names = modest_account_mgr_account_names (self,
+ TRUE);
+ GSList* account =
+ g_slist_find_custom(account_names, account_name, (GCompareFunc) compare_account_name);
+ if (account && !modest_account_mgr_account_is_busy(self, account_name))
+ {
+ priv->busy_accounts = g_slist_append(priv->busy_accounts, g_strdup(account_name));
+ g_signal_emit_by_name(G_OBJECT(self), "account-busy-changed", account_name, TRUE);
+ }
+ modest_account_mgr_free_account_names (account_names);
+ account_names = NULL;
+ } else {
+ GSList* account =
+ g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name);
+ if (account)
+ {
+ g_free(account->data);
+ priv->busy_accounts = g_slist_delete_link(priv->busy_accounts, account);
+ g_signal_emit_by_name(G_OBJECT(self), "account-busy-changed", account_name, FALSE);
+ }
+ }
+}
+
+gboolean
+modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name)
+{
+ ModestAccountMgrPrivate* priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+ return (g_slist_find_custom(priv->busy_accounts, account_name, (GCompareFunc) compare_account_name)
+ != NULL);
+}
+