Changeset 1398

Show
Ignore:
Timestamp:
01/13/07 04:27:31
Author:
pvanhoof
Message:

Introduction of the TnyLockable type and infrastructure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1397 r1398  
     12007-01-13  Philip Van Hoof <pvanhoof@gnome.org> 
     2 
     3        * Introduction of the TnyLockable type 
     4        * Implementation of TnyGtkLockable and TnyNoopLockable 
     5        * Ui locking in TnySessionCamel 
     6        * Async authentication in TnySessionCamel 
     7        * Async alerts in TnySessionCamel 
     8 
     9        * This was a major API change 
     10 
    1112007-01-12  Philip Van Hoof <pvanhoof@gnome.org> 
    212 
  • trunk/libtinymail-camel/tny-session-camel.c

    r1391 r1398  
    4141#include <tny-camel-transport-account.h> 
    4242 
     43#include <tny-noop-lockable.h> 
     44 
    4345#include "tny-session-camel-priv.h" 
    4446#include "tny-camel-store-account-priv.h" 
     
    204206 
    205207 
    206 /* Will be called at camel_service_connect in case the account needs a password. 
    207    its implementation can contani GUI things. */ 
     208typedef struct 
     209
     210        TnySessionCamel *self; 
     211        GMainLoop *loop; 
     212        gchar* data; 
     213        TnyGetPassFunc func; 
     214        gboolean cancel; 
     215        gchar *prompt; 
     216        TnyAccount *account; 
     217} GetPassWaitResults; 
     218 
     219static gboolean 
     220get_pwd_idle_handler (gpointer data) 
     221
     222        GetPassWaitResults *results = data; 
     223 
     224        tny_lockable_lock (results->self->ui_lock); 
     225        results->data = results->func (results->account, results->prompt, &results->cancel); 
     226        tny_lockable_unlock (results->self->ui_lock); 
     227 
     228        g_main_loop_quit (results->loop); 
     229 
     230        return FALSE; 
     231
     232 
     233static gpointer  
     234get_pwd_thread (gpointer results) 
     235
     236        g_idle_add (get_pwd_idle_handler, results); 
     237        g_thread_exit (NULL); 
     238        return NULL; 
     239
     240 
     241 
    208242static char * 
    209243tny_session_camel_get_password (CamelSession *session, CamelService *service, const char *domain, 
    210244              const char *prompt, const char *item, guint32 flags, CamelException *ex) 
    211245{ 
     246        TnySessionCamel *self = (TnySessionCamel *) session; 
     247 
    212248        GList *copy = password_funcs; 
    213249        TnyGetPassFunc func; 
     
    215251        gboolean found = FALSE, freeprmpt = FALSE, cancel = FALSE; 
    216252        gchar *retval = NULL, *prmpt = (gchar*)prompt; 
     253        GetPassWaitResults results; 
     254        GThread *thread; 
    217255 
    218256        while (G_LIKELY (copy)) 
     
    246284                } 
    247285 
    248                 retval = func (account, prompt, &cancel); 
     286                self->in_auth_function = TRUE; 
     287         
     288                results.self = self; 
     289                results.account = account; 
     290                results.prompt = prmpt; 
     291                results.data = NULL; 
     292                results.cancel = FALSE; 
     293                results.func = func; 
     294 
     295                results.loop = g_main_loop_new (NULL, TRUE); 
     296 
     297                thread = g_thread_create (get_pwd_thread, &results, TRUE, NULL); 
     298                g_thread_join (thread); 
     299                 
     300                if (g_main_loop_is_running (results.loop)) 
     301                { 
     302                                tny_lockable_unlock (self->ui_lock); 
     303                                g_main_loop_run (results.loop); 
     304                                tny_lockable_lock (self->ui_lock); 
     305                } 
     306 
     307                g_main_loop_unref (results.loop); 
     308 
     309                retval = results.data; 
     310                cancel = results.cancel; 
     311 
     312                self->in_auth_function = FALSE; 
    249313 
    250314                if (freeprmpt) 
     
    259323} 
    260324 
    261  
    262 /* Will be called at camel_service_connect in case the entered password was wrong */ 
     325/** 
     326 * tny_session_camel_set_ui_locker: 
     327 * @self: a #TnySessionCamel instance 
     328 * @ui_lock: a #TnyLockable instance  
     329 * 
     330 * Set the user interface toolkit locker. The lock and unlock methods of this 
     331 * locker should be implemented with the lock and unlock functionality of your 
     332 * user interface toolkit. 
     333 * 
     334 * Good examples are gdk_threads_enter () and gdk_threads_leave () in gtk+. 
     335 **/ 
     336void  
     337tny_session_camel_set_ui_locker (TnySessionCamel *self, TnyLockable *ui_lock) 
     338
     339        if (self->ui_lock) 
     340                g_object_unref (G_OBJECT (self->ui_lock)); 
     341        self->ui_lock = TNY_LOCKABLE (g_object_ref (ui_lock)); 
     342
     343 
     344 
     345 
     346typedef struct 
     347
     348        TnySessionCamel *self; 
     349        GMainLoop *loop; 
     350        TnyForgetPassFunc func; 
     351        TnyAccount *account; 
     352} ForGetPassWaitResults; 
     353 
     354static gboolean 
     355forget_pwd_idle_handler (gpointer data) 
     356
     357        ForGetPassWaitResults *results = data; 
     358 
     359        tny_lockable_lock (results->self->ui_lock); 
     360        results->func (results->account); 
     361        tny_lockable_unlock (results->self->ui_lock); 
     362 
     363        g_main_loop_quit (results->loop); 
     364 
     365        return FALSE; 
     366
     367 
     368static gpointer  
     369forget_pwd_thread (gpointer results) 
     370
     371        g_idle_add (forget_pwd_idle_handler, results); 
     372        g_thread_exit (NULL); 
     373        return NULL; 
     374
     375 
    263376static void 
    264377tny_session_camel_forget_password (CamelSession *session, CamelService *service, const char *domain, const char *item, CamelException *ex) 
    265378{ 
     379        TnySessionCamel *self = (TnySessionCamel *)session; 
     380 
    266381        GList *copy = forget_password_funcs; 
    267382        TnyForgetPassFunc func; 
    268383        TnyAccount *account; 
    269384        gboolean found = FALSE; 
     385        ForGetPassWaitResults results; 
     386        GThread *thread; 
    270387 
    271388        while (G_LIKELY (copy)) 
     
    284401 
    285402        if (G_LIKELY (found)) 
    286                 func (account); 
    287  
    288         return; 
     403        { 
     404                self->in_auth_function = TRUE; 
     405         
     406                results.self = self; 
     407                results.account = account; 
     408                results.func = func; 
     409 
     410                results.loop = g_main_loop_new (NULL, TRUE); 
     411 
     412                thread = g_thread_create (forget_pwd_thread, &results, TRUE, NULL); 
     413                g_thread_join (thread); 
     414                 
     415                if (g_main_loop_is_running (results.loop)) 
     416                { 
     417                                tny_lockable_unlock (self->ui_lock); 
     418                                g_main_loop_run (results.loop); 
     419                                tny_lockable_lock (self->ui_lock); 
     420                } 
     421 
     422                g_main_loop_unref (results.loop); 
     423 
     424                self->in_auth_function = FALSE; 
     425        } 
     426 
     427        return; 
     428
     429 
     430 
     431 
     432typedef struct 
     433
     434        TnySessionCamel *self; 
     435        GMainLoop *loop; 
     436        TnyAlertType tnytype; 
     437        gchar *prompt; 
     438        gboolean retval; 
     439} AlertWaitResults; 
     440 
     441static gboolean 
     442alert_idle_handler (gpointer data) 
     443
     444        AlertWaitResults *results = data; 
     445 
     446        tny_lockable_lock (results->self->ui_lock); 
     447        results->retval = tny_account_store_alert ( 
     448                (TnyAccountStore*)results->self->account_store,  
     449                results->tnytype, (const gchar *) results->prompt); 
     450        tny_lockable_unlock (results->self->ui_lock); 
     451 
     452        g_main_loop_quit (results->loop); 
     453 
     454        return FALSE; 
     455
     456 
     457static gpointer  
     458alert_thread (gpointer results) 
     459
     460        g_idle_add (alert_idle_handler, results); 
     461        g_thread_exit (NULL); 
     462        return NULL; 
    289463} 
    290464 
     
    299473{ 
    300474        TnySessionCamel *self = (TnySessionCamel *)session; 
     475        GThread *thread; 
    301476 
    302477        if (self->account_store) 
     
    304479                TnyAccountStore *account_store = (TnyAccountStore*)self->account_store; 
    305480                TnyAlertType tnytype; 
     481                AlertWaitResults results; 
    306482 
    307483                switch (type) 
     
    319495                } 
    320496 
    321                 return tny_account_store_alert (account_store, tnytype, prompt); 
     497                self->in_auth_function = TRUE; 
     498         
     499                results.self = self; 
     500                results.tnytype = tnytype; 
     501                results.prompt = g_strdup (prompt); 
     502                results.retval = FALSE; 
     503 
     504                results.loop = g_main_loop_new (NULL, TRUE); 
     505 
     506                thread = g_thread_create (alert_thread, &results, TRUE, NULL); 
     507                g_thread_join (thread); 
     508                 
     509                if (g_main_loop_is_running (results.loop)) 
     510                {                                        
     511                                tny_lockable_unlock (self->ui_lock); 
     512                                g_main_loop_run (results.loop); 
     513                                tny_lockable_lock (self->ui_lock); 
     514                } 
     515                g_main_loop_unref (results.loop); 
     516 
     517                self->in_auth_function = FALSE; 
     518 
     519                g_free (results.prompt); 
     520 
     521                return results.retval; 
    322522        } 
    323523         
     
    453653        instance->device = NULL; 
    454654        instance->camel_dir = NULL; 
     655        instance->ui_lock = tny_noop_lockable_new (); 
     656        instance->camel_dir = NULL; 
     657        instance->in_auth_function = FALSE; 
     658 
     659        return; 
    455660} 
    456661 
     
    492697        TnySessionCamel *self = user_data; 
    493698         
     699        if (self->in_auth_function) 
     700                return; 
     701 
    494702        camel_session_set_online ((CamelSession *) self, online);  
    495703 
     
    596804                        (camel_object_new (TNY_TYPE_SESSION_CAMEL)); 
    597805 
    598         retval->camel_dir = NULL; 
    599806        tny_session_camel_set_account_store (retval, account_store); 
    600807 
     
    613820                        self->connchanged_signal); 
    614821        } 
     822 
     823        if (self->ui_lock) 
     824                g_object_unref (G_OBJECT (self->ui_lock)); 
    615825 
    616826        if (self->camel_dir) 
     
    636846        camel_session_class->thread_msg_free = tny_session_camel_ms_thread_msg_free; 
    637847        camel_session_class->thread_status = tny_session_camel_ms_thread_status; 
    638  
    639         tny_session_camel_class->set_pass_func_func = tny_session_camel_set_pass_func; 
    640         tny_session_camel_class->set_forget_pass_func_func = tny_session_camel_set_forget_pass_func; 
    641         tny_session_camel_class->set_account_store_func = tny_session_camel_set_account_store; 
    642848 
    643849        return; 
  • trunk/libtinymail-camel/tny-session-camel.h

    r1383 r1398  
    2525#include <tny-shared.h> 
    2626#include <tny-camel-shared.h> 
     27#include <tny-lockable.h> 
    2728 
    2829G_BEGIN_DECLS 
     
    4344        GList *current_accounts; 
    4445        gchar *camel_dir; 
     46        gboolean in_auth_function; 
     47        TnyLockable *ui_lock; 
    4548}; 
    4649 
     
    4851{ 
    4952        CamelSessionClass parent_class; 
    50  
    51         void (*set_pass_func_func) (TnySessionCamel *self, TnyAccount *account, TnyGetPassFunc get_pass_func); 
    52         void (*set_forget_pass_func_func) (TnySessionCamel *self, TnyAccount *account, TnyForgetPassFunc forget_pass_func); 
    53         void (*set_account_store_func) (TnySessionCamel *self, TnyAccountStore *account_store); 
    54  
    5553}; 
    5654 
     
    6260void tny_session_camel_set_device (TnySessionCamel *self, TnyDevice *device); 
    6361 
     62void tny_session_camel_set_ui_locker (TnySessionCamel *self, TnyLockable *ui_lock); 
     63 
    6464G_END_DECLS 
    6565 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1384 r1398  
    4747#include <tny-session-camel.h> 
    4848 
     49#include <tny-gtk-lockable.h> 
     50 
    4951#ifdef GNOME 
    5052#include <libgnomeui/gnome-password-dialog.h> 
     
    139141                while (gtk_events_pending ()) 
    140142                        gtk_main_iteration (); 
     143 
    141144        } else { 
    142145 
     
    616619        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
    617620 
     621        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
     622 
     623 
    618624        return TNY_ACCOUNT_STORE (self); 
    619625} 
  • trunk/libtinymail-gpe/tny-gpe-account-store.c

    r1383 r1398  
    4545#include <tny-gpe-device.h> 
    4646 
     47#include <tny-gtk-lockable.h> 
    4748 
    4849/* "GConf vs. Camel" account implementation */ 
     
    502503        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
    503504 
     505        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
     506 
    504507        return TNY_ACCOUNT_STORE (self); 
    505508} 
  • trunk/libtinymail-maemo/tny-maemo-account-store.c

    r1383 r1398  
    4545#include <tny-maemo-device.h> 
    4646 
     47#include <tny-gtk-lockable.h> 
    4748 
    4849/* "GConf vs. Camel" account implementation */ 
     
    504505        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
    505506 
     507        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
     508 
    506509        return TNY_ACCOUNT_STORE (self); 
    507510} 
  • trunk/libtinymail-olpc/tny-olpc-account-store.c

    r1383 r1398  
    4343#include <tny-session-camel.h> 
    4444#include <tny-olpc-device.h> 
     45 
     46#include <tny-gtk-lockable.h> 
    4547 
    4648/* GKeyFile vs. Camel implementation */ 
     
    371373        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
    372374 
     375        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
     376 
    373377        return TNY_ACCOUNT_STORE (self); 
    374378} 
  • trunk/libtinymail/Makefile.am

    r1377 r1398  
    1414        tny-msg.h \ 
    1515        tny-device.h \ 
     16        tny-lockable.h \ 
     17        tny-noop-lockable.h \ 
    1618        tny-account.h \ 
    1719        tny-store-account.h \ 
     
    3840        tny-folder.c \ 
    3941        tny-device.c \ 
     42        tny-lockable.c \ 
     43        tny-noop-lockable.c \ 
    4044        tny-account.c \ 
    4145        tny-store-account.c \ 
  • trunk/libtinymail/tny-shared.h

    r1377 r1398  
    8383typedef struct _TnyPair TnyPair; 
    8484typedef struct _TnyPairClass TnyPairClass; 
     85typedef struct _TnyLockable TnyLockable; 
     86typedef struct _TnyLockableIface TnyLockableIface; 
     87typedef struct _TnyNoopLockable TnyNoopLockable; 
     88typedef struct _TnyNoopLockableClass TnyNoopLockableClass; 
    8589 
    8690G_END_DECLS 
  • trunk/libtinymailui-gtk/Makefile.am

    r1280 r1398  
    1313        tny-gtk-mime-part-save-strategy.h \ 
    1414        tny-gtk-msg-view.h \ 
     15        tny-gtk-lockable.h \ 
    1516        tny-gtk-msg-window.h \ 
    1617        tny-gtk-text-mime-part-view.h \ 
     
    2728        tny-gtk-mime-part-save-strategy.c \ 
    2829        tny-gtk-msg-view.c \ 
     30        tny-gtk-lockable.c \ 
    2931        tny-gtk-text-mime-part-view.c \ 
    3032        tny-gtk-attachment-mime-part-view.c \