Better error checking inserting images in editor
[modest] / src / widgets / modest-window.c
index 2469941..99b0015 100644 (file)
 #include "modest-tny-platform-factory.h"
 #include "modest-runtime.h"
 #include "modest-window-mgr.h"
+#include "modest-defs.h"
+#include <string.h> /* for strcmp */
+#include <gdk/gdkkeysyms.h>
 
 /* 'private'/'protected' functions */
 static void modest_window_class_init (ModestWindowClass *klass);
 static void modest_window_init       (ModestWindow *obj);
 static void modest_window_finalize   (GObject *obj);
+static void modest_window_dispose    (GObject *obj);
 
 static gdouble  modest_window_get_zoom_default           (ModestWindow *window);
 
@@ -85,8 +89,12 @@ modest_window_get_type (void)
                        (GInstanceInitFunc) modest_window_init,
                        NULL
                };
-#ifdef MODEST_PLATFORM_MAEMO
+#ifndef MODEST_TOOLKIT_GTK
+#ifdef MODEST_TOOLKIT_HILDON2
+               parent_type = HILDON_TYPE_STACKABLE_WINDOW;
+#else
                parent_type = HILDON_TYPE_WINDOW;
+#endif
 #else
                parent_type = GTK_TYPE_WINDOW;
 #endif 
@@ -105,6 +113,7 @@ modest_window_class_init (ModestWindowClass *klass)
        gobject_class = (GObjectClass*) klass;
 
        parent_class            = g_type_class_peek_parent (klass);
+       gobject_class->dispose  = modest_window_dispose;
        gobject_class->finalize = modest_window_finalize;
 
        klass->set_zoom_func = modest_window_set_zoom_default;
@@ -146,18 +155,35 @@ modest_window_finalize (GObject *obj)
 
        priv = MODEST_WINDOW_GET_PRIVATE(obj);
 
+       if (priv->dimming_state != NULL) {
+               g_slice_free (DimmedState, priv->dimming_state);
+               priv->dimming_state = NULL;
+       }
+
+       g_free (priv->active_account);
+       
+       G_OBJECT_CLASS(parent_class)->finalize (obj);
+}
+
+static void
+modest_window_dispose (GObject *obj)
+{
+       ModestWindowPrivate *priv;      
+
+       priv = MODEST_WINDOW_GET_PRIVATE(obj);
+
+       priv->ui_dimming_enabled = FALSE;
+
        if (priv->ui_manager) {
                g_object_unref (G_OBJECT(priv->ui_manager));
                priv->ui_manager = NULL;
        }
        if (priv->ui_dimming_manager) {
+               g_object_run_dispose (G_OBJECT (priv->ui_dimming_manager));
                g_object_unref (G_OBJECT(priv->ui_dimming_manager));
                priv->ui_dimming_manager = NULL;
        }
-
-       g_free (priv->active_account);
-       
-       G_OBJECT_CLASS(parent_class)->finalize (obj);
+       G_OBJECT_CLASS(parent_class)->dispose (obj);
 }
 
 
@@ -166,17 +192,32 @@ const gchar*
 modest_window_get_active_account (ModestWindow *self)
 {
        g_return_val_if_fail (self, NULL);
-
+       //g_warning ("%s: %s", __FUNCTION__, MODEST_WINDOW_GET_PRIVATE(self)->active_account);
        return MODEST_WINDOW_GET_PRIVATE(self)->active_account;
 }
 
 void
 modest_window_set_active_account (ModestWindow *self, const gchar *active_account)
 {
-       ModestWindowPrivate *priv;      
+       ModestWindowPrivate *priv;
 
+       g_return_if_fail (self);        
        priv = MODEST_WINDOW_GET_PRIVATE(self);
 
+       //g_warning ("%s: %s", __FUNCTION__, active_account);
+       
+       /* only 'real' account should be set here; for example the email signature
+        * depends on the current account, so if you reply to a message in your
+        * archive, it should take the signature from the real active account,
+        * not the non-existing one from your mmc-pseudo-account
+        */
+       if (active_account && ((strcmp (active_account, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) == 0) ||
+                              (strcmp (active_account, MODEST_MMC_ACCOUNT_ID) == 0))) {
+                       g_warning ("%s: %s is not a valid active account",
+                                  __FUNCTION__, active_account);
+                       return;
+       }
+       
        if (active_account == priv->active_account)
                return;
        else {
@@ -407,7 +448,7 @@ on_key_pressed (GtkWidget *self,
        case GDK_Escape: 
                if (modest_window_mgr_get_fullscreen_mode (mgr))
                        modest_ui_actions_on_change_fullscreen (NULL, MODEST_WINDOW(self));
-               else if (MODEST_IS_MSG_VIEW_WINDOW (self)||MODEST_IS_MSG_EDIT_WINDOW (self))
+               else if (MODEST_IS_MSG_VIEW_WINDOW (self))
                        modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (self));
                break;
        }