* modest-defs.h, modest-main.c:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 22 Jan 2007 00:12:25 +0000 (00:12 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 22 Jan 2007 00:12:25 +0000 (00:12 +0000)
- move exit codes from main->defs
* modest-main.c, modest-icon-factory.[ch]:
- use the new ModestCacheMgr, no need for init/uninit funcs anymore

pmo-trunk-r687

src/modest-defs.h
src/modest-icon-factory.c
src/modest-icon-factory.h
src/modest-main.c

index 6629e59..d3d9749 100644 (file)
 #ifndef __MODEST_DEFS_H__
 #define __MODEST_DEFS_H__
 
+
+/* exit codes for the modest executable*/
+enum {
+       MODEST_ERR_NONE    = 0,  /* no error */
+       MODEST_ERR_OPTIONS,      /* error in the options */
+       MODEST_ERR_CONF,         /* error getting confuration db */
+       MODEST_ERR_UI,           /* error in the UI */
+       MODEST_ERR_HILDON,       /* error with Hildon (maemo-only) */
+       MODEST_ERR_RUN,          /* errr running */
+       MODEST_ERR_SEND,         /* error sending mail */
+       MODEST_ERR_INIT          /* error in initialization */
+};
+
+
 /* some interesting dirs. NOTE, they should be prefixed
  * with $HOME; also, except MODEST_DIR itself, they
  * need to be prefixed with MODEST_DIR;
@@ -43,7 +57,6 @@
 #define MODEST_LOCAL_FOLDERS_MAILDIR "local_folder"
 
 
-
 /* configuration key definitions for modest */
 #define MODEST_CONF_NAMESPACE          "/apps/modest"
 
index c1902a2..326705b 100644 (file)
 
 /* modest-icon-factory.c */
 
-#include <string.h>
-#include "modest-icon-factory.h"
+#include <modest-icon-factory.h>
+#include <modest-tny-platform-factory.h>
 
-static GHashTable *icon_hash = NULL;
-
-static
-gboolean equal_func (const gchar *s1, const gchar *s2)
+static GHashTable*
+get_icon_cache (void)
 {
-       return strcmp (s1, s2) == 0;
-}
+       TnyPlatformFactory *fakt;
+       ModestCacheMgr     *cache_mgr;
 
-static
-void free_pixbuf (GdkPixbuf *pixbuf)
-{
-       if (pixbuf)
-               g_object_unref (G_OBJECT(pixbuf));
-}
-
-
-void
-modest_icon_factory_init   (void)
-{
-       if (icon_hash) {
-               g_printerr ("modest: modest_icon_factory_init " 
-                           "should be called only once\n");
-               return;
-       }
+       fakt = modest_tny_platform_factory_get_instance ();
        
-       icon_hash = g_hash_table_new_full (g_str_hash,
-                                          (GEqualFunc)equal_func,
-                                          (GDestroyNotify)g_free,
-                                          (GDestroyNotify)free_pixbuf);
-}
-
-
-void
-modest_icon_factory_uninit (void)
-{
-       if (!icon_hash) {
-               g_printerr ("modest: modest_icon_factory_uninit "
-                          "must only be called with initialized "
-                          "ModestIconFactories\n");
-               return;
-       }
+       cache_mgr =  modest_tny_platform_factory_get_cache_mgr_instance
+               (MODEST_TNY_PLATFORM_FACTORY(fakt));
 
-       g_hash_table_destroy (icon_hash);
-       icon_hash = NULL;
+       return modest_cache_mgr_get_cache (cache_mgr,
+                                          MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
 }
 
 
-
 GdkPixbuf*
 modest_icon_factory_get_icon (const gchar *name)
 {
        GError *err = NULL;
        GdkPixbuf *pixbuf;
        gpointer orig_key;
-
-       g_return_val_if_fail (name, NULL);
+       static GHashTable *icon_cache = NULL;
        
-       if (!icon_hash) {
-               g_printerr ("modest: ModestIconFactory must be initialized first\n");
-               return NULL;
-       }
+       g_return_val_if_fail (name, NULL);
 
-       /* is it already in the hashtable?
-        * note: this can be NULL
-        */
-       if (!g_hash_table_lookup_extended (icon_hash, name, &orig_key,
-                                          (gpointer*)&pixbuf)) {
+       if (G_UNLIKELY(!icon_cache))
+               icon_cache = get_icon_cache ();
+       
+       if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key,
+                                                         (gpointer*)&pixbuf)) {
                pixbuf = gdk_pixbuf_new_from_file (name, &err);
                if (!pixbuf) {
                        g_printerr ("modest: error in icon factory while loading '%s': %s\n",
                                    name, err->message);
                        g_error_free (err);
                }
-               /* if we cannot find it, we still insert, so we get the error
+               /* if we cannot find it, we still insert (if we have a cache), so we get the error
                 * only once */
-               g_hash_table_insert (icon_hash, g_strdup(name),
-                                    (gpointer)pixbuf);
+               if (icon_cache)
+                       g_hash_table_insert (icon_cache, g_strdup(name),(gpointer)pixbuf);
        }
        return pixbuf;
 }
@@ -122,14 +86,13 @@ modest_icon_factory_get_icon_at_size (const gchar *name, guint width, guint heig
        /* FIXME, somehow, cache scaled icons as well... */
        GError *err = NULL;
        GdkPixbuf *pixbuf = NULL;
-
-       g_return_val_if_fail (name, NULL);
+       static GHashTable *icon_cache = NULL;
        
-       if (!icon_hash) {
-               g_printerr ("modest: ModestIconFactory must be initialized first\n");
-               return NULL;
-       }
+       g_return_val_if_fail (name, NULL);
 
+       if (G_UNLIKELY(!icon_cache))
+               icon_cache = get_icon_cache ();
+       
        pixbuf = gdk_pixbuf_new_from_file_at_size (name, width, height, &err);
        if (!pixbuf) {
                g_printerr ("modest: error in icon factory while loading '%s'@(%dx%d): %s\n",
@@ -138,9 +101,8 @@ modest_icon_factory_get_icon_at_size (const gchar *name, guint width, guint heig
        }
        
        /* we insert it, so it will be freed... FIXME... */
-       if (pixbuf)
-               g_hash_table_insert (icon_hash, g_strdup_printf ("%s-%d-%d",name,width,height),
+       if (pixbuf && icon_cache)
+               g_hash_table_insert (icon_cache, g_strdup_printf ("%s-%d-%d",name,width,height),
                                     (gpointer)pixbuf);
-       
        return pixbuf;
 }
index 5a4437e..f77e255 100644 (file)
 #include <gdk/gdkpixbuf.h>
 
 /**
- * modest_icon_factory_init
- *
- * initialize the modest_icon_factory, which is a runtime-wide singleton
- * this should be called only once, before doing anything else with the icon
- * factory
- */
-void modest_icon_factory_init   (void);
-
-
-/**
- * modest_icon_factory_uninit
- *
- * uninitialize the modest_icon_factory. this should be done after the icon
- * factory is no longer needed.
- */
-void modest_icon_factory_uninit (void);
-
-
-/**
  * modest_icon_factory_get_icon:
  * @name: the filename of a certain icon
  *
index 0397ef1..c7ba047 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <config.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtkwidget.h>
+
 #include <tny-list.h>
 #include <tny-transport-account.h>
 #include <tny-account-store.h>
 #include <tny-list.h>
 #include <tny-simple-list.h>
 
-#include <config.h>
+#include <modest-defs.h>
 #include <modest-conf.h>
 #include <modest-account-mgr.h>
 #include <modest-ui.h>
 #include <modest-tny-platform-factory.h>
 #include <modest-mail-operation.h>
 
-#include <camel/camel-url.h>
-
 #if MODEST_PLATFORM_ID==2 /* maemo */
 #include <libosso.h>
 #endif /* MODEST_PLATFORM==2 */
 
-/* return values */
-enum {
-       MODEST_ERR_NONE    = 0,
-       MODEST_ERR_OPTIONS, 
-       MODEST_ERR_CONF,    
-       MODEST_ERR_UI,      
-       MODEST_ERR_HILDON,  
-       MODEST_ERR_RUN,     
-       MODEST_ERR_SEND,    
-       MODEST_ERR_INIT,
-};
-
 static gboolean hildon_init (); /* NOP if HILDON is not defined */
 static int start_ui (const gchar* mailto, const gchar *cc,
                     const gchar *bcc, const gchar* subject, const gchar *body,
@@ -79,7 +67,6 @@ main (int argc, char *argv[])
        GOptionContext     *context       = NULL;
        TnyPlatformFactory *fact          = NULL;
        TnyAccountStore    *account_store = NULL;
-       ModestConf         *modest_conf   = NULL;
        
        GError *err = NULL;
        int retval  = MODEST_ERR_NONE;
@@ -131,15 +118,6 @@ main (int argc, char *argv[])
        /* Get platform factory */      
        fact = modest_tny_platform_factory_get_instance ();
 
-       /* Check modest conf */
-       modest_conf = modest_tny_platform_factory_get_conf_instance
-               (MODEST_TNY_PLATFORM_FACTORY(fact));
-       if (!modest_conf) {
-               g_printerr ("modest: failed to initialize config system, exiting\n");
-               retval = MODEST_ERR_CONF;
-               goto cleanup;
-       }
-
        if (!modest_init_local_folders ()) {
                g_printerr ("modest: failed to initialize local folders, exiting\n");
                retval = MODEST_ERR_INIT;
@@ -192,8 +170,6 @@ start_ui (const gchar* mailto, const gchar *cc, const gchar *bcc,
                goto cleanup;
        }
        
-       modest_icon_factory_init ();    
-
        if (!hildon_init ()) { /* NOP  if hildon is not defined */
                g_printerr ("modest: failed to initialize hildon, exiting\n");
                retval = MODEST_ERR_HILDON;
@@ -228,7 +204,6 @@ cleanup:
        if (modest_ui)
                g_object_unref (modest_ui);
 
-       modest_icon_factory_uninit ();
        return retval;
 }
        
@@ -292,8 +267,7 @@ send_mail (const gchar* mailto, const gchar *cc, const gchar *bcc,
                                             account, "test@example.com",
                                             mailto, cc, bcc, 
                                             subject, body, NULL);
-       
-       
+               
        if (modest_mail_operation_get_status (mail_operation) == 
            MODEST_MAIL_OPERATION_STATUS_FAILED) {
                retval = MODEST_ERR_SEND;