Changeset 578

Show
Ignore:
Timestamp:
07/26/06 12:24:39
Author:
pvanhoof
Message:

Implemented an extremely simple non-gconf account store

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r530 r578  
    5151AC_PROG_LIBTOOL 
    5252 
     53dnl ### default value 
     54build_gnome=true 
     55 
     56dnl ### Select the platform library ## 
     57AC_ARG_WITH(platform, 
     58[  --with-platform=gnome-desktop                platform to compile [gnome-desktop]], 
     59[case "${with_platform}" in 
     60  gnome-desktop) PLATFORMDIR=libtinymail-gnome-desktop ;; 
     61  olpc) 
     62        PLATFORMDIR=libtinymail-olpc 
     63        build_gtkhtml=false 
     64        build_mozembed=false 
     65        build_gnome=false 
     66        with_html_component=none 
     67        ;; 
     68  maemo) 
     69        PLATFORMDIR=libtinymail-maemo 
     70        build_gtkhtml=false 
     71        build_mozembed=false 
     72        build_gnome=false 
     73        with_html_component=none 
     74        ;; 
     75  gpe) PLATFORMDIR=libtinymail-gpe ;; 
     76  *) PLATFORMDIR=${with_platform} 
     77esac], [PLATFORMDIR=libtinymail-gnome-desktop 
     78        with_platform=gnome-desktop]) 
     79AC_SUBST(PLATFORMDIR) 
     80 
    5381 
    5482dnl ### Enable gnome features ## 
     
    5987  no)  build_gnome=false ;; 
    6088  *) AC_MSG_ERROR(bad value ${enableval} for --enable-gnome) ;; 
    61 esac],[build_gnome=true]) 
     89esac],[build_gnome=$build_gnome]) 
    6290AM_CONDITIONAL(BUILD_GNOME, test x$build_gnome = xtrue) 
    6391 
     
    106134AM_CONDITIONAL(BUILD_UNITTESTS, test x$build_unittests = xtrue) 
    107135 
    108 dnl ### Select the platform library ## 
    109 AC_ARG_WITH(platform, 
    110 [  --with-platform=gnome-desktop                platform to compile [gnome-desktop]], 
    111 [case "${with_platform}" in 
    112   gnome-desktop) PLATFORMDIR=libtinymail-gnome-desktop ;; 
    113   olpc) PLATFORMDIR=libtinymail-olpc ;; 
    114   maemo) PLATFORMDIR=libtinymail-maemo ;; 
    115   gpe) PLATFORMDIR=libtinymail-gpe ;; 
    116   *) PLATFORMDIR=${with_platform} 
    117 esac], [PLATFORMDIR=libtinymail-gnome-desktop 
    118         with_platform=gnome-desktop]) 
    119 AC_SUBST(PLATFORMDIR) 
    120  
    121136dnl ### gtk-doc 
    122137GTK_DOC_CHECK([1.0]) 
     
    179194dnl ### libtinymail-olpc, a platform library implementation for the One Laptop Per Child device ## 
    180195if test x$PLATFORMDIR = xlibtinymail-olpc; then 
    181  PKG_CHECK_MODULES(LIBTINYMAIL_OLPC, gconf-2.0 glib-2.0 >= 2.8 gobject-2.0 gconf-2.0 gtk+-2.0) 
     196 PKG_CHECK_MODULES(LIBTINYMAIL_OLPC, glib-2.0 >= 2.8 gobject-2.0 gtk+-2.0) 
    182197else 
    183198 LIBTINYMAIL_OLPC_CFLAGS= 
     
    190205dnl ### libtinymail-maemo, a platform library implementation for the maemo platform ## 
    191206if test x$PLATFORMDIR = xlibtinymail-maemo; then 
    192  PKG_CHECK_MODULES(LIBTINYMAIL_MAEMO, gconf-2.0 glib-2.0 >= 2.8 gobject-2.0 gconf-2.0 gtk+-2.0) 
     207 PKG_CHECK_MODULES(LIBTINYMAIL_MAEMO, glib-2.0 >= 2.8 gobject-2.0 gconf-2.0 gtk+-2.0) 
    193208else 
    194209 LIBTINYMAIL_MAEMO_CFLAGS= 
     
    200215dnl ### libtinymail-gpe, a platform library implementation for the GPE platform ## 
    201216if test x$PLATFORMDIR = xlibtinymail-gpe; then 
    202  PKG_CHECK_MODULES(LIBTINYMAIL_GPE, gconf-2.0 glib-2.0 >= 2.8 gobject-2.0 gconf-2.0 gtk+-2.0) 
     217 PKG_CHECK_MODULES(LIBTINYMAIL_GPE, glib-2.0 >= 2.8 gobject-2.0 gconf-2.0 gtk+-2.0) 
    203218else 
    204219 LIBTINYMAIL_GPE_CFLAGS= 
     
    223238 
    224239dnl ### tinymail, the demo-ui ## 
    225 dnl Try to remove the gtk+ and gconf dependency by refactoring to libraries 
    226 PKG_CHECK_MODULES(TINYMAIL, glib-2.0 >= 2.6 gobject-2.0 gconf-2.0 gtk+-2.0 $extratnypkgs) 
     240PKG_CHECK_MODULES(TINYMAIL, glib-2.0 >= 2.6 gobject-2.0 gtk+-2.0 $extratnypkgs) 
    227241AC_SUBST(TINYMAIL_CFLAGS) 
    228242AC_SUBST(TINYMAIL_LIBS) 
  • trunk/libtinymail-olpc/tny-account-store.c

    r551 r578  
    2424#include <glib.h> 
    2525#include <gtk/gtk.h> 
    26 #include <gconf/gconf-client.h> 
    2726 
    2827#include <tny-platform-factory-iface.h> 
     
    5251struct _TnyAccountStorePriv 
    5352{ 
    54         GConfClient *client; 
    55         gchar *cache_dir; 
    5653        TnySessionCamel *session; 
    5754        TnyDeviceIface *device; 
     
    7875        if (G_UNLIKELY (!retval)) 
    7976        { 
    80                 /* This crashes on subsequent calls (any gtk widget creation does) */ 
    8177                GtkDialog *dialog = GTK_DIALOG (tny_password_dialog_new ()); 
    8278         
     
    168164} 
    169165 
    170 static void 
    171 gconf_listener_account_changed (GConfClient *client, guint cnxn_id, 
    172                         GConfEntry *entry, gpointer user_data) 
    173 { 
    174         TnyAccountStoreIface *self = user_data; 
    175         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    176  
    177  
    178         gchar *key = g_strdup (entry->key); 
    179         gchar *ptr = strrchr (key, '/'); ptr++; 
    180  
    181         if (!strcmp (ptr, "count")) 
    182         { 
    183                 g_signal_emit (self,  
    184                         tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNTS_RELOADED], 0); 
    185  
    186         } 
    187  
    188         g_free (key); 
    189  
    190         return; 
    191 } 
    192  
    193166 
    194167static const gchar* 
    195168tny_account_store_get_cache_dir (TnyAccountStoreIface *self) 
    196169{ 
    197         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    198  
    199         if (G_UNLIKELY (!priv->cache_dir)) 
    200         { 
    201                 /* Note that there's no listener for this key. If it changes, 
    202                    the camelsession should be destroyed and rebuild from scratch. 
    203                    Which basically means reloading the accounts aswell.  
    204                    
    205                    So say you're a nut who wants this key to be updatable at  
    206                    runtime, you'll have to unload all the accounts here, and of 
    207                    course reload them. All the functionality for that is already 
    208                    available. Perhaps I should just do it ... hmm, maybe another 
    209                    day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
    210  
    211                    Oh and, not to forget! You should probably also move the old 
    212                    cache location to the new one. Or cleanup the old one. */ 
    213  
    214                 gchar *cache_dir = gconf_client_get_string (priv->client,  
    215                         "/apps/tinymail/cache_dir", NULL); 
    216                 priv->cache_dir = g_build_filename (g_get_home_dir (),  
    217                         cache_dir, NULL); 
    218                 g_free (cache_dir); 
    219         } 
    220  
    221         return priv->cache_dir; 
     170        return g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(), ".tinymail"); 
    222171} 
    223172 
     
    228177        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    229178        gint i=0, count; 
    230  
    231         count = gconf_client_get_int (priv->client,  
    232                         "/apps/tinymail/accounts/count", NULL); 
    233  
    234         for (i=0; i < count; i++) 
    235         { 
    236                 gchar *proto, *type, *key, *name; 
     179        const gchar *filen; 
     180        gchar *configd; 
     181        gchar *key = NULL; 
     182        GDir *dir ; 
     183 
     184        configd = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir(),  
     185                ".tinymail", "accounts"); 
     186        dir = g_dir_open (configd, 0, NULL); 
     187        g_free (configd); 
     188 
     189        if (!dir) 
     190                return; 
     191 
     192        for (filen = g_dir_read_name (dir); filen; filen = g_dir_read_name (dir)) 
     193        { 
     194          FILE *file = fopen (filen, "r"); 
     195 
     196          if (file) 
     197          { 
     198                gchar *tok, proto[200], type[200], key[200], name[200], options[1000]; 
    237199                TnyAccountIface *account = NULL; 
    238                 GSList *options; 
    239  
    240                 key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
    241                  
    242                 if (!gconf_client_dir_exists (priv->client, (const gchar*)key, NULL)) 
    243                 { 
    244                         g_free (key); 
    245                         continue; 
    246                 } 
    247                 g_free (key); 
    248  
    249                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/type", i); 
    250                 type = gconf_client_get_string (priv->client,  
    251                         (const gchar*) key, NULL); 
    252                 g_free (key); 
     200 
     201                fscanf (file, "type=%s", &type); 
    253202 
    254203                if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
     
    275224                        tny_account_iface_set_account_store (account, self); 
    276225 
    277                         if (type) 
    278                                 g_free (type); 
    279  
    280                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", i); 
    281                         proto = gconf_client_get_string (priv->client,  
    282                                 (const gchar*) key, NULL); 
    283                         g_free (key); 
     226                        fscanf (file, "proto=%s", &proto); 
    284227                        tny_account_iface_set_proto (TNY_ACCOUNT_IFACE (account), proto); 
    285228 
    286                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/name", i); 
    287                         name = gconf_client_get_string (priv->client,  
    288                                 (const gchar*) key, NULL); 
    289                         g_free (key); 
     229                        fscanf (file, "name=%s", &name); 
    290230                        tny_account_iface_set_name (TNY_ACCOUNT_IFACE (account), name); 
    291                         g_free (name); 
    292  
    293  
    294                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/options", i); 
    295                         options = gconf_client_get_list (priv->client,  
    296                                 (const gchar*) key, GCONF_VALUE_STRING, NULL); 
    297                         g_free (key); 
    298  
    299                         if (options) 
     231 
     232 
     233                        fscanf (file, "options=%s", &options); 
     234                        tok = strtok (options, ","); 
     235 
     236                        while (tok) 
    300237                        { 
    301                                 while (options) 
    302                                 { 
    303                                         tny_account_add_option (TNY_ACCOUNT (account), options->data); 
    304                                         g_free (options->data); 
    305                                         options = g_slist_next (options); 
    306                                 } 
    307                                 g_slist_free (options); 
     238                                tny_account_add_option (TNY_ACCOUNT (account), tok); 
     239                                tok = strtok (NULL, ","); 
    308240                        } 
    309241 
     
    316248 
    317249                                /* TODO: Add other supported and tested providers here */ 
    318                                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
    319                                 user = gconf_client_get_string (priv->client,  
    320                                         (const gchar*) key, NULL); 
    321  
    322                                 g_free (key); 
     250                                fscanf (file, "user=%s", &user); 
    323251                                tny_account_iface_set_user (TNY_ACCOUNT_IFACE (account), user); 
    324252 
    325                                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/hostname", i); 
    326                                 hostname = gconf_client_get_string (priv->client,  
    327                                         (const gchar*) key, NULL); 
    328                                 g_free (key);  
     253 
     254                                fscanf (file, "hostname=%s", &hostname); 
    329255                                tny_account_iface_set_hostname (TNY_ACCOUNT_IFACE (account),  
    330256                                        hostname); 
    331257                                 
    332                                 g_free (hostname); g_free (proto); g_free (user); 
    333258                        } else { 
    334259                                gchar *url_string; 
     
    337262                                /* Assuming there's a url_string in this case */ 
    338263 
    339                                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/url_string", i); 
    340                                 url_string = gconf_client_get_string (priv->client,  
    341                                         (const gchar*) key, NULL); 
    342  
    343                                 g_free (key); 
     264                                fscanf (file, "url_string=%s", &url_string); 
    344265                                tny_account_iface_set_url_string (TNY_ACCOUNT_IFACE (account), url_string); 
    345                                 g_free (url_string); 
    346266                        } 
    347267 
    348                         key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
    349                         tny_account_iface_set_id (TNY_ACCOUNT_IFACE (account), key); 
    350                         g_free (key); 
     268                        tny_account_iface_set_id (TNY_ACCOUNT_IFACE (account), filen); 
    351269 
    352270                        /*  
     
    363281                        tny_list_iface_prepend (list, account); 
    364282                } 
     283 
     284                fclose (file); 
     285          } 
     286         
     287        }        
     288        g_dir_close (dir); 
     289 
     290 
     291        tny_session_camel_set_current_accounts (priv->session, list); 
     292 
     293        return;  
     294} 
     295 
     296 
     297 
     298static void 
     299tny_account_store_add_account (TnyAccountStoreIface *self, TnyAccountIface *account, const gchar *type) 
     300{ 
     301        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
     302        gchar *filen = g_build_filename (g_get_home_dir(),  ".tinymail",  
     303                tny_account_iface_get_name (account)); 
     304         
     305        FILE *file = fopen (filen, "w"); 
     306 
     307        if (file) 
     308        { 
     309 
     310                fprintf (file, "type=%s", type); 
     311                fprintf (file, "proto=%s", tny_account_iface_get_proto (account)); 
     312                fprintf (file, "name=%s", tny_account_iface_get_name (account)); 
     313                fprintf (file, "options="); 
     314                fprintf (file, "user=%s", tny_account_iface_get_user (account)); 
     315                fprintf (file, "hostname=%s", tny_account_iface_get_hostname (account)); 
     316 
     317 
     318                fclose (file); 
    365319        } 
    366320 
    367         tny_session_camel_set_current_accounts (priv->session, list); 
    368  
    369         return;  
    370 } 
    371  
    372  
    373 static void 
    374 tny_account_store_notify_add (TnyAccountStoreIface *self) 
    375 { 
    376         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    377         priv->notify = gconf_client_notify_add (priv->client,  
    378                 "/apps/tinymail/accounts", gconf_listener_account_changed, 
    379                 self, NULL, NULL); 
    380         return; 
    381 } 
    382  
    383 static void 
    384 tny_account_store_notify_remove (TnyAccountStoreIface *self) 
    385 { 
    386         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    387         gconf_client_notify_remove (priv->client, priv->notify); 
    388         return; 
    389 } 
    390  
    391 /* 
    392         gconftool-2 -s /apps/tinymail/cache_dir -t string .tinymail 
    393  
    394         gconftool-2 -s /apps/tinymail/accounts/count -t int COUNT 
    395         gconftool-2 -s /apps/tinymail/accounts/0/proto -t string [smtp|imap|pop] 
    396         gconftool-2 -s /apps/tinymail/accounts/0/type -t string [transport|store] 
    397  
    398         gconftool-2 -s /apps/tinymail/accounts/0/user -t string username 
    399         gconftool-2 -s /apps/tinymail/accounts/0/hostname -t string mailserver 
    400 or 
    401         gconftool-2 -s /apps/tinymail/accounts/0/url_string -t string url_string 
    402  
    403 */ 
    404  
    405 static void 
    406 tny_account_store_add_account (TnyAccountStoreIface *self, TnyAccountIface *account, const gchar *type) 
    407 { 
    408         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    409         gchar *key = NULL; 
    410         gint count = gconf_client_get_int (priv->client, "/apps/tinymail/accounts/count", NULL); 
    411  
    412         count++; 
    413  
    414         key = g_strdup_printf ("/apps/tinymail/accounts/%d/hostname", count); 
    415         gconf_client_set_string (priv->client, (const gchar*) key,  
    416                 tny_account_iface_get_hostname (account), NULL); 
    417         g_free (key);  
    418  
    419         key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", count); 
    420         gconf_client_set_string (priv->client, (const gchar*) key,  
    421                 tny_account_iface_get_proto (account), NULL); 
    422         g_free (key);  
    423  
    424         key = g_strdup_printf ("/apps/tinymail/accounts/%d/type", count); 
    425         gconf_client_set_string (priv->client, (const gchar*) key, type, NULL); 
    426         g_free (key);  
    427  
    428         key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", count); 
    429         gconf_client_set_string (priv->client, (const gchar*) key,  
    430                 tny_account_iface_get_user (account), NULL); 
    431         g_free (key);  
    432  
    433         gconf_client_set_int (priv->client, "/apps/tinymail/accounts/count",  
    434                 count, NULL); 
    435  
    436321        return; 
    437322} 
     
    444329        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    445330 
    446         tny_account_store_notify_remove (self); 
    447331        tny_account_store_add_account (self, TNY_ACCOUNT_IFACE (account), "store"); 
    448         tny_account_store_notify_add (self); 
    449332 
    450333        g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNT_INSERTED], 0, account); 
     
    458341        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    459342 
    460         tny_account_store_notify_remove (self); 
    461343        tny_account_store_add_account (self, TNY_ACCOUNT_IFACE (account), "transport"); 
    462         tny_account_store_notify_add (self); 
    463344 
    464345        g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNT_INSERTED], 0, account); 
     
    503384        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    504385 
    505         priv->client = gconf_client_get_default (); 
    506  
    507         gconf_client_add_dir (priv->client, "/apps/tinymail",  
    508                 GCONF_CLIENT_PRELOAD_RECURSIVE, NULL); 
    509  
    510         tny_account_store_notify_add (TNY_ACCOUNT_STORE_IFACE (self)); 
    511386 
    512387        return; 
     
    516391static void 
    517392tny_account_store_finalize (GObject *object) 
    518 
    519         TnyAccountStore *self = (TnyAccountStore *)object;       
    520         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    521  
    522         tny_account_store_notify_remove (TNY_ACCOUNT_STORE_IFACE (self)); 
    523         g_object_unref (G_OBJECT (priv->client)); 
    524  
    525         if (G_LIKELY (priv->cache_dir)) 
    526                 g_free (priv->cache_dir); 
    527  
     393{        
    528394        (*parent_class->finalize) (object); 
    529395