#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;
#define MODEST_LOCAL_FOLDERS_MAILDIR "local_folder"
-
/* configuration key definitions for modest */
#define MODEST_CONF_NAMESPACE "/apps/modest"
/* 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;
}
/* 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",
}
/* 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;
}
* 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,
GOptionContext *context = NULL;
TnyPlatformFactory *fact = NULL;
TnyAccountStore *account_store = NULL;
- ModestConf *modest_conf = NULL;
GError *err = NULL;
int retval = MODEST_ERR_NONE;
/* 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;
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;
if (modest_ui)
g_object_unref (modest_ui);
- modest_icon_factory_uninit ();
return retval;
}
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;