* some cleanups for debugging:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 14 Nov 2007 22:19:31 +0000 (22:19 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 14 Nov 2007 22:19:31 +0000 (22:19 +0000)
- move debugging macro's to modest-debug.h (new file)
- capitalize/rename the macros to make it clearer they are macro's
- add the new MODEST_DEBUG_BLOCK; example:
MODEST_DEBUG_BLOCK(
g_debug ("DEBUG: modest: %s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used);
);
         - this code will *only* run when the MODEST_DEBUG envir var contains "debug-code"
 - add something like this to your .emacs to make these blocks clear:
  (font-lock-add-keywords nil
                          '(("\\<\\(FIXME\\|TODO\\|XXX+\\|BUG\\|MODEST_DEBUG_BLOCK\\)"
                             1 font-lock-warning-face prepend))))
 - some coverity fixes in modest-tny-account.c (free stuff in error cases)
 - update the manpage

pmo-trunk-r3737

man/modest.1
src/Makefile.am
src/modest-debug.h [new file with mode: 0644]
src/modest-init.c
src/modest-runtime.c
src/modest-runtime.h
src/modest-singletons.c
src/modest-tny-account-store.c
src/modest-tny-account.c
src/widgets/modest-window-mgr.c

index b0f2965..287837b 100644 (file)
@@ -58,6 +58,8 @@ to trigger certain debugging features:
 .IP "abort-on-warning"
 Abort the program when any Gtk/Glib warning or error occurs. This can be
 useful when running inside a debugger.
 .IP "abort-on-warning"
 Abort the program when any Gtk/Glib warning or error occurs. This can be
 useful when running inside a debugger.
+.IP "debug-code"
+Run various pieces of debug-only code in modest
 .IP "log-actions"
 Log actions to the log file (not available yet)
 .IP "debug-objects"
 .IP "log-actions"
 Log actions to the log file (not available yet)
 .IP "debug-objects"
index 08ba46e..bb9ae88 100644 (file)
@@ -1,6 +1,6 @@
 #
 # Makefile.am
 #
 # Makefile.am
-# Time-stamp: <2007-10-26 12:47:06 (djcb)>
+# Time-stamp: <2007-11-14 22:42:34 (djcb)>
 
 SUBDIRS=$(MODEST_PLATFORM) widgets $(dbus_api)
 
 
 SUBDIRS=$(MODEST_PLATFORM) widgets $(dbus_api)
 
@@ -49,6 +49,7 @@ modest_SOURCES=\
        modest-conf.c \
        modest-conf.h \
        modest-defs.h \
        modest-conf.c \
        modest-conf.h \
        modest-defs.h \
+       modest-debug.h \
        modest-dimming-rule.c \
        modest-dimming-rule.h \
        modest-dimming-rules-group.c \
        modest-dimming-rule.c \
        modest-dimming-rule.h \
        modest-dimming-rules-group.c \
diff --git a/src/modest-debug.h b/src/modest-debug.h
new file mode 100644 (file)
index 0000000..828480b
--- /dev/null
@@ -0,0 +1,99 @@
+/* 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.
+ */
+
+#ifndef __MODEST_DEBUG_H__
+#define __MODEST_DEBUG_H__
+
+#include "modest-runtime.h"
+
+/* some debugging macros */
+
+/**
+ * MODEST_RUNTIME_VERIFY_OBJECT_LAST_REF:
+ * @OBJ: some (GObject) ptr
+ * @NAME: name of @OBJ
+ * 
+ * macro to check whether @obj holds only one more ref (ie. after the
+ * next unref it will die)
+ * 
+ * not, a g_warning will be issued on stderr. NOTE: this is only active
+ * when MODEST_DEBUG contains "debug-objects".
+ *
+ ***/
+#define MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(OBJ,name)                                                 \
+       do {                                                                                           \
+               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_OBJECTS)                   \
+                       if (G_IS_OBJECT(OBJ) && G_OBJECT(OBJ)->ref_count != 1)                         \
+                               g_warning ("%s:%d: %s ("                                               \
+                                          #OBJ ") still holds a ref count of %d",                     \
+                                          __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count);          \
+       } while (0)
+
+
+
+
+/**
+ * MODEST_DEBUG_BLOCK:
+ * @BLOCK: some block of code
+ * 
+ * macro to which run its argument (block) only when MODEST_DEBUG contains "debug-code"
+ * 
+ ***/
+#define MODEST_DEBUG_BLOCK(BLOCK)                                                                     \
+       do {                                                                                           \
+               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_CODE)   {                  \
+                       BLOCK                                                                          \
+               }                                                                                      \
+        } while (0)                                                                                    
+
+
+/**
+ * MODEST_DEBUG_NOT_IMPLEMENTED:
+ * @WIN: the parent GtkWindow, or NULL
+ *
+ * give a not-implemented-yet warning popup or g_warning
+ *
+ ***/
+#define MODEST_DEBUG_NOT_IMPLEMENTED(WIN)    \
+       do {                                   \
+               if (gtk_main_level() > 0) {    \
+                       GtkWidget *popup;      \
+                       popup = gtk_message_dialog_new (WIN,\
+                                                       GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,\
+                                                       GTK_MESSAGE_WARNING, \
+                                                       GTK_BUTTONS_OK, \
+                                                       "Not yet implemented");\
+                       gtk_dialog_run (GTK_DIALOG(popup));             \
+                       gtk_widget_destroy (popup);                     \
+               } else                                                  \
+                       g_warning ("%s:%d: Not yet implemented",__FILE__,__LINE__); \
+       } while (0)                                                     \
+                                                                       
+
+#endif /*__MODEST_DEBUG_H__*/
index 92dbfd1..619b31e 100644 (file)
@@ -526,9 +526,9 @@ init_debug_g_type (void)
        gflags = 0;
        mflags = modest_runtime_get_debug_flags ();
 
        gflags = 0;
        mflags = modest_runtime_get_debug_flags ();
 
-       if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)
+       if (mflags & MODEST_RUNTIME_DEBUG_OBJECTS)
                gflags |= G_TYPE_DEBUG_OBJECTS;
                gflags |= G_TYPE_DEBUG_OBJECTS;
-       if (mflags & MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS)
+       if (mflags & MODEST_RUNTIME_DEBUG_SIGNALS)
                gflags |= G_TYPE_DEBUG_SIGNALS;
 
        g_type_init_with_debug_flags (gflags);
                gflags |= G_TYPE_DEBUG_SIGNALS;
 
        g_type_init_with_debug_flags (gflags);
index 7f43703..3d3843c 100644 (file)
@@ -46,6 +46,7 @@
 #include <modest-account-mgr-helpers.h>
 #include <modest-icon-names.h>
 #include <modest-ui-actions.h>
 #include <modest-account-mgr-helpers.h>
 #include <modest-icon-names.h>
 #include <modest-ui-actions.h>
+#include <modest-debug.h>
 
 static ModestSingletons       *_singletons    = NULL;
 
 
 static ModestSingletons       *_singletons    = NULL;
 
@@ -85,15 +86,15 @@ modest_runtime_uninit (void)
                return TRUE;    /* uninit maybe called if runtime_init failed */
        
        g_return_val_if_fail (MODEST_IS_SINGLETONS(_singletons), FALSE);
                return TRUE;    /* uninit maybe called if runtime_init failed */
        
        g_return_val_if_fail (MODEST_IS_SINGLETONS(_singletons), FALSE);
-
+       
        if (_account_store) {
        if (_account_store) {
-               modest_runtime_verify_object_last_ref(_account_store,"");
-               g_object_unref(G_OBJECT(_account_store));
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(_account_store,"");
+               g_object_unref(_account_store);
                _account_store = NULL;
        }
                _account_store = NULL;
        }
-
-       modest_runtime_verify_object_last_ref(_singletons,"");
-       g_object_unref(G_OBJECT(_singletons));
+       
+       MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(_singletons,"");
+       g_object_unref(_singletons);
        _singletons = NULL;
 
        
        _singletons = NULL;
 
        
@@ -245,9 +246,10 @@ modest_runtime_get_debug_flags ()
        static const GDebugKey debug_keys[] = {
                { "abort-on-warning",   MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
                { "log-actions",        MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
        static const GDebugKey debug_keys[] = {
                { "abort-on-warning",   MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING },
                { "log-actions",        MODEST_RUNTIME_DEBUG_LOG_ACTIONS },
-               { "debug-objects",      MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS },
-               { "debug-signals",      MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS },
-               { "factory-settings",   MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS}
+               { "debug-objects",      MODEST_RUNTIME_DEBUG_OBJECTS },
+               { "debug-signals",      MODEST_RUNTIME_DEBUG_SIGNALS },
+               { "factory-settings",   MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS},
+               { "debug-code",         MODEST_RUNTIME_DEBUG_CODE}
        };
        const gchar *str;
        static ModestRuntimeDebugFlags debug_flags = -1;
        };
        const gchar *str;
        static ModestRuntimeDebugFlags debug_flags = -1;
index dbe2460..98b92e0 100644 (file)
@@ -50,9 +50,10 @@ G_BEGIN_DECLS
 typedef enum {
        MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING      = 1 << 0,
        MODEST_RUNTIME_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
 typedef enum {
        MODEST_RUNTIME_DEBUG_ABORT_ON_WARNING      = 1 << 0,
        MODEST_RUNTIME_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
-       MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS         = 1 << 2, /* for g_type_init */
-       MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS         = 1 << 3, /* for g_type_init */
-       MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS      = 1 << 4  /* reset to factory defaults */
+       MODEST_RUNTIME_DEBUG_OBJECTS               = 1 << 2, /* for g_type_init */
+       MODEST_RUNTIME_DEBUG_SIGNALS               = 1 << 3, /* for g_type_init */
+       MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS      = 1 << 4, /* reset to factory defaults */
+       MODEST_RUNTIME_DEBUG_CODE                  = 1 << 5  /* print various debugging messages */
 } ModestRuntimeDebugFlags;
 
 /**
 } ModestRuntimeDebugFlags;
 
 /**
@@ -210,51 +211,6 @@ void modest_runtime_remove_all_send_queues ();
  **/
 ModestWindowMgr* modest_runtime_get_window_mgr (void);
 
  **/
 ModestWindowMgr* modest_runtime_get_window_mgr (void);
 
-/**
- * modest_runtime_verify_object_last_ref
- * @OBJ: some (GObject) ptr
- * @NAME: name of @OBJ
- * 
- * macro to check whether @obj holds only one more ref (ie. after the
- * next unref it will die)
- * 
- * not, a g_warning will be issued on stderr. NOTE: this is only active
- * when MODEST_DEBUG contains "debug-objects".
- *
- ***/
-#define modest_runtime_verify_object_last_ref(OBJ,name)                                                       \
-       do {                                                                                           \
-               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)             \
-                       if (G_IS_OBJECT(OBJ) && G_OBJECT(OBJ)->ref_count != 1)                         \
-                               g_warning ("%s:%d: %s ("                                               \
-                                          #OBJ ") still holds a ref count of %d",                     \
-                                          __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count);          \
-       } while (0)
-
-
-
-/**
- * modest_runtime_not_implemented
- * @WIN: the parent GtkWindow, or NULL
- *
- * give a not-implemented-yet warning popup or g_warning
- *
- ***/
-#define modest_runtime_not_implemented(WIN)    \
-       do {                                   \
-               if (gtk_main_level() > 0) {    \
-                       GtkWidget *popup;      \
-                       popup = gtk_message_dialog_new (WIN,\
-                                                       GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,\
-                                                       GTK_MESSAGE_WARNING, \
-                                                       GTK_BUTTONS_OK, \
-                                                       "Not yet implemented");\
-                       gtk_dialog_run (GTK_DIALOG(popup));             \
-                       gtk_widget_destroy (popup);                     \
-               } else                                                  \
-                       g_warning ("%s:%d: Not yet implemented",__FILE__,__LINE__); \
-       } while (0)                                                     \
-
 
 G_END_DECLS
 
 
 G_END_DECLS
 
index daabcb3..23d45d1 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "modest-singletons.h"
 #include "modest-runtime.h"
 
 #include "modest-singletons.h"
 #include "modest-runtime.h"
+#include "modest-debug.h"
 
 /* 'private'/'protected' functions */
 static void modest_singletons_class_init (ModestSingletonsClass *klass);
 
 /* 'private'/'protected' functions */
 static void modest_singletons_class_init (ModestSingletonsClass *klass);
@@ -160,37 +161,37 @@ modest_singletons_finalize (GObject *obj)
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
        
        if (priv->window_mgr) {
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
        
        if (priv->window_mgr) {
-               modest_runtime_verify_object_last_ref(priv->window_mgr,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->window_mgr,"");
                g_object_unref (G_OBJECT(priv->window_mgr));
                priv->window_mgr = NULL;
        }
        
        if (priv->email_clipboard) {
                g_object_unref (G_OBJECT(priv->window_mgr));
                priv->window_mgr = NULL;
        }
        
        if (priv->email_clipboard) {
-               modest_runtime_verify_object_last_ref(priv->email_clipboard,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->email_clipboard,"");
                g_object_unref (G_OBJECT(priv->email_clipboard));
                priv->email_clipboard = NULL;
        }
 
        if (priv->cache_mgr) {
                g_object_unref (G_OBJECT(priv->email_clipboard));
                priv->email_clipboard = NULL;
        }
 
        if (priv->cache_mgr) {
-               modest_runtime_verify_object_last_ref(priv->cache_mgr,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->cache_mgr,"");
                g_object_unref (G_OBJECT(priv->cache_mgr));
                priv->cache_mgr = NULL;
        }
 
        if (priv->device) {
                g_object_unref (G_OBJECT(priv->cache_mgr));
                priv->cache_mgr = NULL;
        }
 
        if (priv->device) {
-               modest_runtime_verify_object_last_ref(priv->device,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->device,"");
                g_object_unref (G_OBJECT(priv->device));
                priv->device = NULL;
        }
 
        if (priv->platform_fact) {
                g_object_unref (G_OBJECT(priv->device));
                priv->device = NULL;
        }
 
        if (priv->platform_fact) {
-               modest_runtime_verify_object_last_ref(priv->platform_fact,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->platform_fact,"");
                g_object_unref (G_OBJECT(priv->platform_fact));
                priv->platform_fact = NULL;
        }
 
        if (priv->mail_op_queue) {
                g_object_unref (G_OBJECT(priv->platform_fact));
                priv->platform_fact = NULL;
        }
 
        if (priv->mail_op_queue) {
-               modest_runtime_verify_object_last_ref(priv->mail_op_queue,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->mail_op_queue,"");
                g_object_unref (G_OBJECT(priv->mail_op_queue));
                priv->mail_op_queue = NULL;
        }
                g_object_unref (G_OBJECT(priv->mail_op_queue));
                priv->mail_op_queue = NULL;
        }
@@ -200,13 +201,13 @@ modest_singletons_finalize (GObject *obj)
         * cancells any mail operations which in turn access the account
         * manager (see modest_mail_operation_notify_end()). */
        if (priv->account_mgr) {
         * cancells any mail operations which in turn access the account
         * manager (see modest_mail_operation_notify_end()). */
        if (priv->account_mgr) {
-               modest_runtime_verify_object_last_ref(priv->account_mgr,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->account_mgr,"");
                g_object_unref (G_OBJECT(priv->account_mgr));
                priv->account_mgr = NULL;
        }
        
        if (priv->conf) {
                g_object_unref (G_OBJECT(priv->account_mgr));
                priv->account_mgr = NULL;
        }
        
        if (priv->conf) {
-               modest_runtime_verify_object_last_ref(priv->conf,"");
+               MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->conf,"");
                g_object_unref (G_OBJECT(priv->conf));
                priv->conf = NULL;
        }
                g_object_unref (G_OBJECT(priv->conf));
                priv->conf = NULL;
        }
index 6eef5c9..b338b4f 100644 (file)
@@ -53,6 +53,7 @@
 #include <modest-account-settings-dialog.h>
 #include <maemo/modest-maemo-utils.h>
 #include <modest-signal-mgr.h>
 #include <modest-account-settings-dialog.h>
 #include <maemo/modest-maemo-utils.h>
 #include <modest-signal-mgr.h>
+#include <modest-debug.h>
 
 #include "modest-tny-account-store.h"
 #include "modest-tny-platform-factory.h"
 
 #include "modest-tny-account-store.h"
 #include "modest-tny-platform-factory.h"
@@ -316,7 +317,7 @@ account_verify_last_ref (TnyAccount *account, const gchar *str)
        g_return_if_fail (account && TNY_IS_ACCOUNT(account));
 
        txt = g_strdup_printf ("%s: %s", str ? str : "?", tny_account_get_name(account));
        g_return_if_fail (account && TNY_IS_ACCOUNT(account));
 
        txt = g_strdup_printf ("%s: %s", str ? str : "?", tny_account_get_name(account));
-       modest_runtime_verify_object_last_ref(G_OBJECT(account),txt);
+       MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(G_OBJECT(account),txt);
        g_free (txt);
 }
 
        g_free (txt);
 }
 
@@ -615,12 +616,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
        /* TODO: Settting cancel to FALSE does not actually cancel everything.
         * We still get multiple requests afterwards, so we end up showing the 
         * same dialogs repeatedly.
        /* TODO: Settting cancel to FALSE does not actually cancel everything.
         * We still get multiple requests afterwards, so we end up showing the 
         * same dialogs repeatedly.
-        */
-        
-       printf ("DEBUG: modest: %s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used);
-         
-       g_return_val_if_fail (account, NULL);
-         
+        */       
        const TnyAccountStore *account_store = NULL;
        ModestTnyAccountStore *self = NULL;
        ModestTnyAccountStorePrivate *priv;
        const TnyAccountStore *account_store = NULL;
        ModestTnyAccountStore *self = NULL;
        ModestTnyAccountStorePrivate *priv;
@@ -629,6 +625,12 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
        gpointer pwd_ptr = NULL;
        gboolean already_asked = FALSE;
 
        gpointer pwd_ptr = NULL;
        gboolean already_asked = FALSE;
 
+       g_return_val_if_fail (account, NULL);
+       
+       MODEST_DEBUG_BLOCK(
+               g_debug ("DEBUG: modest: %s: prompt (not shown) = %s\n", __FUNCTION__, prompt_not_used);
+       );
+       
        /* Initialize the output parameter: */
        if (cancel)
                *cancel = FALSE;
        /* Initialize the output parameter: */
        if (cancel)
                *cancel = FALSE;
@@ -658,9 +660,10 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
                                                      server_account_name,
                                                      NULL,
                                                      (gpointer*)&pwd_ptr);
                                                      server_account_name,
                                                      NULL,
                                                      (gpointer*)&pwd_ptr);
-                                                     
-       printf ("DEBUG: modest: %s: Already asked = %d\n", __FUNCTION__, already_asked);
-
+       MODEST_DEBUG_BLOCK(
+               g_debug ("DEBUG: modest: %s: Already asked = %d\n", __FUNCTION__, already_asked);
+       );
+               
        /* If the password is not already there, try ModestConf */
        if (!already_asked) {
                pwd  = modest_account_mgr_get_server_account_password (priv->account_mgr,
        /* If the password is not already there, try ModestConf */
        if (!already_asked) {
                pwd  = modest_account_mgr_get_server_account_password (priv->account_mgr,
@@ -676,7 +679,10 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
                 */
                const gboolean settings_have_password = 
                        modest_account_mgr_get_server_account_has_password (priv->account_mgr, server_account_name);
                 */
                const gboolean settings_have_password = 
                        modest_account_mgr_get_server_account_has_password (priv->account_mgr, server_account_name);
-               printf ("DEBUG: modest: %s: settings_have_password=%d\n", __FUNCTION__, settings_have_password);
+               MODEST_DEBUG_BLOCK(
+                       printf ("DEBUG: modest: %s: settings_have_password=%d\n",
+                               __FUNCTION__, settings_have_password);
+               );
                if (settings_have_password) {
                        /* The password must be wrong, so show the account settings dialog so it can be corrected: */
                        show_wrong_password_dialog (account);
                if (settings_have_password) {
                        /* The password must be wrong, so show the account settings dialog so it can be corrected: */
                        show_wrong_password_dialog (account);
@@ -725,10 +731,7 @@ get_password (TnyAccount *account, const gchar * prompt_not_used, gboolean *canc
                username = NULL;
        } else
                if (cancel)
                username = NULL;
        } else
                if (cancel)
-                       *cancel = FALSE;
-    /* printf("  DEBUG: %s: returning %s\n", __FUNCTION__, pwd); */
-       
+                       *cancel = FALSE;        
        return pwd;
 }
 
        return pwd;
 }
 
index 2527fbe..d1695de 100644 (file)
@@ -43,6 +43,7 @@
 #include <tny-camel-imap-store-account.h>
 #include <tny-camel-pop-store-account.h>
 #include <tny-folder-stats.h>
 #include <tny-camel-imap-store-account.h>
 #include <tny-camel-pop-store-account.h>
 #include <tny-folder-stats.h>
+#include <modest-debug.h>
 #include <string.h>
 #ifdef MODEST_HAVE_HILDON0_WIDGETS
 #include <hildon-widgets/hildon-file-system-info.h>
 #include <string.h>
 #ifdef MODEST_HAVE_HILDON0_WIDGETS
 #include <hildon-widgets/hildon-file-system-info.h>
@@ -58,17 +59,16 @@ TnyFolder *
 modest_tny_account_get_special_folder (TnyAccount *account,
                                       TnyFolderType special_type)
 {
 modest_tny_account_get_special_folder (TnyAccount *account,
                                       TnyFolderType special_type)
 {
-       TnyList *folders;
-       TnyIterator *iter;
+       TnyList *folders = NULL;
+       TnyIterator *iter = NULL;
        TnyFolder *special_folder = NULL;
        TnyFolder *special_folder = NULL;
-
+       TnyAccount *local_account  = NULL;
+       GError *error = NULL;
        
        g_return_val_if_fail (account, NULL);
        g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM,
                              NULL);
        
        
        g_return_val_if_fail (account, NULL);
        g_return_val_if_fail (0 <= special_type && special_type < TNY_FOLDER_TYPE_NUM,
                              NULL);
        
-       TnyAccount *local_account  = NULL;
-
        /* The accounts have already been instantiated by 
         * modest_tny_account_store_get_accounts(), which is the 
         * TnyAccountStore::get_accounts_func() implementation,
        /* The accounts have already been instantiated by 
         * modest_tny_account_store_get_accounts(), which is the 
         * TnyAccountStore::get_accounts_func() implementation,
@@ -77,84 +77,76 @@ modest_tny_account_get_special_folder (TnyAccount *account,
         
        /* Per-account outbox folders are each in their own on-disk directory: */
        if (special_type == TNY_FOLDER_TYPE_OUTBOX) {
         
        /* Per-account outbox folders are each in their own on-disk directory: */
        if (special_type == TNY_FOLDER_TYPE_OUTBOX) {
-               const gchar *modest_account_name = 
+
+               gchar *account_id;
+               const gchar *modest_account_name;
+
+               modest_account_name =
                        modest_tny_account_get_parent_modest_account_name_for_server_account (account);
                        modest_tny_account_get_parent_modest_account_name_for_server_account (account);
-               
-               if (modest_account_name) {
-                       gchar *account_id = g_strdup_printf (
-                               MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s", 
-                               modest_account_name);
-                       
-                       local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
-                                                                                    MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
-                                                                                    account_id);
-                       if (!local_account) {
-                               g_printerr ("modest: %s: modest_tny_account_store_get_tny_account_by(ID) returned NULL for %s\n", __FUNCTION__, account_id);
+               if (!modest_account_name) {
+                       g_warning ("%s: could not get modest account name", __FUNCTION__);
                        return NULL;
                        return NULL;
-                       }
-               
-                       g_free (account_id);
-               } else {
-                       g_warning ("%s: modest_account_name was NULL.", __FUNCTION__);
                }
                }
-       } else {
+               
+               account_id = g_strdup_printf (
+                       MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s", 
+                       modest_account_name);
+               
+               local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
+                                                                            MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+                                                                            account_id);
+               g_free (account_id);            
+       } else 
                /* Other local folders are all in one on-disk directory: */
                local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
                                                                             MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
                                                                             MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
                /* Other local folders are all in one on-disk directory: */
                local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
                                                                             MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
                                                                             MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
-       }
-       
        if (!local_account) {
                g_printerr ("modest: cannot get local account\n");
        if (!local_account) {
                g_printerr ("modest: cannot get local account\n");
-               return NULL;
+               goto cleanup;
        }
 
        folders = TNY_LIST (tny_simple_list_new ());
        }
 
        folders = TNY_LIST (tny_simple_list_new ());
-
+       
        /* There is no need to do this _async, as these are local folders. */
        /* TODO: However, this seems to fail sometimes when the network is busy, 
         * returning an empty list. murrayc. */ 
        /* There is no need to do this _async, as these are local folders. */
        /* TODO: However, this seems to fail sometimes when the network is busy, 
         * returning an empty list. murrayc. */ 
-       GError *error = NULL;
-       tny_folder_store_get_folders (TNY_FOLDER_STORE (local_account),
-                                     folders, NULL, &error);
+       tny_folder_store_get_folders (TNY_FOLDER_STORE (local_account), folders, NULL, &error);
        if (error) {
        if (error) {
-               g_warning ("%s: tny_folder_store_get_folders() failed:\n  error=%s\n", 
-                       __FUNCTION__, error->message);
+               g_warning ("%s: tny_folder_store_get_folders() failed:%s\n", __FUNCTION__, error->message);
+               g_error_free (error);
+               goto cleanup;
        }
                                      
        if (tny_list_get_length (folders) == 0) {
                gchar* url_string = tny_account_get_url_string (local_account);
        }
                                      
        if (tny_list_get_length (folders) == 0) {
                gchar* url_string = tny_account_get_url_string (local_account);
-               g_printerr ("modest: %s: tny_folder_store_get_folders() returned an empty list for account with URL '%s'\n", 
-                       __FUNCTION__, url_string);
+               g_printerr ("modest: %s: tny_folder_store_get_folders(%s) returned an empty list\n", 
+                           __FUNCTION__, url_string);
                g_free (url_string);
                g_free (url_string);
+               goto cleanup;
        }
        
        iter = tny_list_create_iterator (folders);
 
        while (!tny_iterator_is_done (iter)) {
        }
        
        iter = tny_list_create_iterator (folders);
 
        while (!tny_iterator_is_done (iter)) {
-               TnyFolder *folder =
-                       TNY_FOLDER (tny_iterator_get_current (iter));
+               TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (iter));
                if (folder) {
                        if (modest_tny_folder_get_local_or_mmc_folder_type (folder) == special_type) {
                                special_folder = folder;
                                break; /* Leaving a ref for the special_folder return value. */
                        }
                if (folder) {
                        if (modest_tny_folder_get_local_or_mmc_folder_type (folder) == special_type) {
                                special_folder = folder;
                                break; /* Leaving a ref for the special_folder return value. */
                        }
-               
-                       g_object_unref (G_OBJECT(folder));
+                       g_object_unref (folder);
                }
                }
-
                tny_iterator_next (iter);
        }
                tny_iterator_next (iter);
        }
-       
-       g_object_unref (G_OBJECT (folders));
-       g_object_unref (G_OBJECT (iter));
-       g_object_unref (G_OBJECT (local_account));
 
 
-       /*
-       if (!special_folder) {
-               g_warning ("%s: Returning NULL.", __FUNCTION__);        
-       }
-       */
+cleanup:
+       if (folders)
+               g_object_unref (folders);
+       if (iter)
+               g_object_unref (iter);
+       if (local_account)
+               g_object_unref (local_account);
        
        return special_folder;
 }
        
        return special_folder;
 }
@@ -175,18 +167,14 @@ create_tny_account (ModestAccountMgr *account_mgr,
                    TnySessionCamel *session,
                    ModestServerAccountData *account_data)
 {
                    TnySessionCamel *session,
                    ModestServerAccountData *account_data)
 {
+       TnyAccount *tny_account = NULL;
+       const gchar* proto_name;
+       
        g_return_val_if_fail (account_mgr, NULL);
        g_return_val_if_fail (session, NULL);
        g_return_val_if_fail (account_data, NULL);
        g_return_val_if_fail (account_mgr, NULL);
        g_return_val_if_fail (session, NULL);
        g_return_val_if_fail (account_data, NULL);
-
-       /* sanity checks */
-       if (account_data->proto == MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN) {
-               g_printerr ("modest: '%s' does not provide a protocol\n",
-                           account_data->account_name);
-               return NULL;
-       }
-
-       TnyAccount *tny_account = NULL;
+       g_return_val_if_fail (account_data->proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN,
+                             NULL);
        
        switch (account_data->proto) {
        case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
        
        switch (account_data->proto) {
        case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
@@ -205,9 +193,10 @@ create_tny_account (ModestAccountMgr *account_mgr,
        default:
                g_return_val_if_reached (NULL);
        }
        default:
                g_return_val_if_reached (NULL);
        }
+
        if (!tny_account) {
        if (!tny_account) {
-               g_printerr ("modest: could not create tny account for '%s'\n",
-                           account_data->account_name);
+               g_printerr ("modest: %s: could not create tny account for '%s'\n",
+                           __FUNCTION__, account_data->account_name);
                return NULL;
        }
        tny_account_set_id (tny_account, account_data->account_name);
                return NULL;
        }
        tny_account_set_id (tny_account, account_data->account_name);
@@ -216,8 +205,7 @@ create_tny_account (ModestAccountMgr *account_mgr,
        tny_camel_account_set_session (TNY_CAMEL_ACCOUNT (tny_account), session);
     
        /* Proto */
        tny_camel_account_set_session (TNY_CAMEL_ACCOUNT (tny_account), session);
     
        /* Proto */
-       const gchar* proto_name =
-               modest_protocol_info_get_transport_store_protocol_name(account_data->proto);
+       proto_name =  modest_protocol_info_get_transport_store_protocol_name(account_data->proto);
        tny_account_set_proto (tny_account, proto_name);
 
        return tny_account;
        tny_account_set_proto (tny_account, proto_name);
 
        return tny_account;
@@ -277,24 +265,25 @@ static gboolean
 update_tny_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
                    ModestServerAccountData *account_data)
 {
 update_tny_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
                    ModestServerAccountData *account_data)
 {
-       gchar *url = NULL;
-       
        g_return_val_if_fail (account_mgr, FALSE);
        g_return_val_if_fail (account_data, FALSE);
        g_return_val_if_fail (account_mgr, FALSE);
        g_return_val_if_fail (account_data, FALSE);
+       g_return_val_if_fail (account_data->account_name, FALSE);
        g_return_val_if_fail (tny_account, FALSE);
        g_return_val_if_fail (tny_account, FALSE);
-
+       
        tny_account_set_id (tny_account, account_data->account_name);
        tny_account_set_id (tny_account, account_data->account_name);
-              
+       
        /* mbox and maildir accounts use a URI instead of the rest:
         * Note that this is not where we create the special local folders account.
         * We do that in modest_tny_account_new_for_local_folders() instead. */
        if (account_data->uri)  
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
        else {
        /* mbox and maildir accounts use a URI instead of the rest:
         * Note that this is not where we create the special local folders account.
         * We do that in modest_tny_account_new_for_local_folders() instead. */
        if (account_data->uri)  
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
        else {
-               /* Set camel-specific options: */
-               
+               /* Set camel-specific options: */               
                /* Enable secure connection settings: */
                const gchar* option_security = NULL;
                /* Enable secure connection settings: */
                const gchar* option_security = NULL;
+               const gchar* auth_mech_name = NULL;
+
+
                switch (account_data->security) {
                case MODEST_PROTOCOL_CONNECTION_NORMAL:
                        option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_NEVER;
                switch (account_data->security) {
                case MODEST_PROTOCOL_CONNECTION_NORMAL:
                        option_security = MODEST_ACCOUNT_OPTION_SSL "=" MODEST_ACCOUNT_OPTION_SSL_NEVER;
@@ -320,8 +309,6 @@ update_tny_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
                                                      option_security);
                
                /* Secure authentication: */
                                                      option_security);
                
                /* Secure authentication: */
-
-               const gchar* auth_mech_name = NULL;
                switch (account_data->secure_auth) {
                case MODEST_PROTOCOL_AUTH_NONE:
                        /* IMAP and POP need at least a password,
                switch (account_data->secure_auth) {
                case MODEST_PROTOCOL_AUTH_NONE:
                        /* IMAP and POP need at least a password,
@@ -354,7 +341,7 @@ update_tny_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
                        
                default:
                        g_warning ("%s: Unhandled secure authentication setting %d for "
                        
                default:
                        g_warning ("%s: Unhandled secure authentication setting %d for "
-                               "account=%s (%s)", __FUNCTION__, account_data->secure_auth,
+                                  "account_name=%s (%s)", __FUNCTION__, account_data->secure_auth,
                                   account_data->account_name, account_data->hostname);
                        break;
                }
                                   account_data->account_name, account_data->hostname);
                        break;
                }
@@ -381,12 +368,12 @@ update_tny_account (TnyAccount *tny_account, ModestAccountMgr *account_mgr,
                        tny_account_set_port (tny_account, account_data->port);
        }
 
                        tny_account_set_port (tny_account, account_data->port);
        }
 
-       /* FIXME: for debugging. 
-        * Let's keep this because it is very useful for debugging. */
-       url = tny_account_get_url_string (TNY_ACCOUNT(tny_account));
-       g_debug ("%s:\n  account-url: %s\n", __FUNCTION__, url);
-
-       g_free (url);
+       MODEST_DEBUG_BLOCK (
+               gchar *url = tny_account_get_url_string (TNY_ACCOUNT(tny_account));
+               g_debug ("%s:\n  account-url: %s\n", __FUNCTION__, url);
+               g_free (url);
+       );
+       
        return TRUE;
 }
 
        return TRUE;
 }
 
@@ -436,80 +423,6 @@ modest_tny_account_new_from_server_account_name (ModestAccountMgr *account_mgr,
 }
 
 
 }
 
 
-#if 0
-gboolean
-modest_tny_account_update_from_server_account_name (TnyAccount *tny_account,
-                                                   ModestAccountMgr *account_mgr,
-                                                   const gchar *server_account_name)
-{
-       ModestServerAccountData *account_data;
-       gboolean valid_account_type;
-       
-       g_return_val_if_fail (tny_account, FALSE);
-       g_return_val_if_fail (server_account_name, FALSE);
-       
-       account_data =  modest_account_mgr_get_server_account_data (account_mgr, 
-                                                                   server_account_name);
-       if (!account_data) {
-               g_warning ("%s: failed to get server account data for %s",
-                          __FUNCTION__, server_account_name);
-               return FALSE;
-       }
-
-       valid_account_type = FALSE;
-
-       /* you cannot change the protocol type of an existing account;
-        * so double check we don't even try
-        */
-       switch (account_data->proto) {
-       case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
-       case MODEST_PROTOCOL_TRANSPORT_SMTP:
-               if (!TNY_IS_CAMEL_TRANSPORT_ACCOUNT(tny_account))
-                       g_warning ("%s: expecting transport account", __FUNCTION__);
-               else
-                       valid_account_type = TRUE;
-               break;
-       case MODEST_PROTOCOL_STORE_POP:
-               if (!TNY_IS_CAMEL_POP_STORE_ACCOUNT(tny_account))
-                       g_warning ("%s: expecting pop account", __FUNCTION__);
-               else
-                       valid_account_type = TRUE;
-               break;
-       case MODEST_PROTOCOL_STORE_IMAP:
-               if (!TNY_IS_CAMEL_IMAP_STORE_ACCOUNT(tny_account))
-                       g_warning ("%s: expecting imap account", __FUNCTION__);
-               else
-                       valid_account_type = TRUE;
-               break;
-       case MODEST_PROTOCOL_STORE_MAILDIR:
-       case MODEST_PROTOCOL_STORE_MBOX:
-               if (!TNY_IS_CAMEL_STORE_ACCOUNT(tny_account))
-                       g_warning ("%s: expecting store account", __FUNCTION__);
-               else
-                       valid_account_type = TRUE;
-               break;
-       default:
-               g_warning ("invalid account type");
-       }
-
-       if (!valid_account_type) {
-               g_warning ("%s: protocol type cannot be changed", __FUNCTION__);
-               modest_account_mgr_free_server_account_data (account_mgr, account_data);
-               return FALSE;
-       }
-       
-       if (!update_tny_account (tny_account, account_mgr, account_data)) {
-               g_warning ("%s: failed to update account", __FUNCTION__);
-               modest_account_mgr_free_server_account_data (account_mgr, account_data);
-               return FALSE;
-       }
-
-       modest_account_mgr_free_server_account_data (account_mgr, account_data);
-       return TRUE;
-}
-#endif
-
-
 
 
 /* we need these dummy functions, or tinymail will complain */
 
 
 /* we need these dummy functions, or tinymail will complain */
@@ -682,9 +595,9 @@ typedef struct
 
 /* Gets the memory card name: */
 static void 
 
 /* Gets the memory card name: */
 static void 
-on_modest_file_system_info(HildonFileSystemInfoHandle *handle,
-                             HildonFileSystemInfo *info,
-                             const GError *error, gpointer data)
+on_modest_file_system_info (HildonFileSystemInfoHandle *handle,
+                           HildonFileSystemInfo *info,
+                           const GError *error, gpointer data)
 {
        GetMmcAccountNameData *callback_data = (GetMmcAccountNameData*)data;
 
 {
        GetMmcAccountNameData *callback_data = (GetMmcAccountNameData*)data;
 
index 6c2f191..0638190 100644 (file)
@@ -36,6 +36,7 @@
 #include "widgets/modest-main-window.h"
 #include "widgets/modest-msg-edit-window.h"
 #include "widgets/modest-msg-view-window.h"
 #include "widgets/modest-main-window.h"
 #include "widgets/modest-msg-edit-window.h"
 #include "widgets/modest-msg-view-window.h"
+#include "modest-debug.h"
 
 
 /* 'private'/'protected' functions */
 
 
 /* 'private'/'protected' functions */
@@ -839,7 +840,9 @@ modest_window_mgr_get_main_window (ModestWindowMgr *self, gboolean create)
        if (!priv->main_window && create) {
                /* modest_window_mgr_register_window will set priv->main_window */
                modest_window_mgr_register_window (self, modest_main_window_new ());
        if (!priv->main_window && create) {
                /* modest_window_mgr_register_window will set priv->main_window */
                modest_window_mgr_register_window (self, modest_main_window_new ());
-               g_debug ("%s: created main window: %p\n", __FUNCTION__, priv->main_window);
+               MODEST_DEBUG_BLOCK(
+                       g_debug ("%s: created main window: %p\n", __FUNCTION__, priv->main_window);
+               );
        }
        
        return priv->main_window;
        }
        
        return priv->main_window;