-/* Your copyright here */
+/* Copyright (c) 2006, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
#include <config.h>
#include <glib.h>
-#include <glib/gi18n-lib.h>
-
-#define MODEST_DEFAULT_CONNECTION_POLICY_C
-gboolean exiting = FALSE;
-#include <modest-default-connection-policy.h>
-#undef MODEST_DEFAULT_CONNECTION_POLICY_C
+#include "modest-default-connection-policy.h"
+#include "modest-account-mgr.h"
+#include "modest-account-mgr-helpers.h"
+#include "modest-runtime.h"
+#include "modest-tny-account.h"
+#include "modest-ui-actions.h"
#include <tny-account.h>
+#include <tny-store-account.h>
static GObjectClass *parent_class = NULL;
static void
modest_default_connection_policy_on_connect (TnyConnectionPolicy *self, TnyAccount *account)
{
+ /* Set the username as succedded */
+ if (TNY_IS_STORE_ACCOUNT (account)) {
+ gboolean first_time = FALSE;
+ const gchar *id;
+ ModestAccountMgr *acc_mgr;
+
+ acc_mgr = modest_runtime_get_account_mgr ();
+ id = tny_account_get_id (account);
+ first_time = !modest_account_mgr_get_server_account_username_has_succeeded (acc_mgr, id);
+
+ /* If it's the first connection then perform a send&receive */
+ if (first_time) {
+ const gchar *account_name;
+ ModestWindow *top_window;
+
+ modest_account_mgr_set_server_account_username_has_succeeded (acc_mgr, id, TRUE);
+
+ /* Perform a send receive */
+ account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+ top_window = modest_window_mgr_get_current_top (modest_runtime_get_window_mgr ());
+ if (top_window)
+ modest_ui_actions_do_send_receive (account_name, FALSE, FALSE, TRUE, top_window);
+ }
+ }
+
return;
}
static void
modest_default_connection_policy_on_disconnect (TnyConnectionPolicy *self, TnyAccount *account)
{
- tny_account_cancel (account);
return;
}