Changeset 1495

Show
Ignore:
Timestamp:
01/29/07 01:03:07
Author:
pvanhoof
Message:

Asynchronously connecting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1494 r1495  
     12007-01-29  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Finally, asynchronously connecting. Though, it's experimental. 
     4 
    152007-01-28  Philip Van Hoof  <pvanhoof@gnome.org> 
    26 
  • trunk/libtinymail-camel/tny-session-camel.c

    r1485 r1495  
    206206} 
    207207 
    208  
    209 typedef struct 
    210 { 
    211         TnySessionCamel *self; 
    212         GMainLoop *loop; 
    213         gchar* data; 
    214         TnyGetPassFunc func; 
    215         gboolean cancel; 
    216         gchar *prompt; 
    217         TnyAccount *account; 
    218 } GetPassWaitResults; 
    219  
    220  
    221 static gpointer  
    222 get_pwd_thread (gpointer data) 
    223 { 
    224         GetPassWaitResults *results = data; 
    225  
    226         while (!(g_main_loop_is_running (results->loop))) 
    227                 usleep (100); 
    228  
    229         tny_lockable_lock (results->self->priv->ui_lock); 
    230         results->data = results->func (results->account, results->prompt, &results->cancel); 
    231         tny_lockable_unlock (results->self->priv->ui_lock); 
    232  
    233         g_main_loop_quit (results->loop); 
    234  
    235         g_thread_exit (NULL); 
    236         return NULL; 
    237 } 
    238  
    239  
    240208static char * 
    241209tny_session_camel_get_password (CamelSession *session, CamelService *service, const char *domain, 
     
    250218        gboolean found = FALSE, freeprmpt = FALSE, cancel = FALSE; 
    251219        gchar *retval = NULL, *prmpt = (gchar*)prompt; 
    252         GetPassWaitResults results; 
    253         GThread *thread; gboolean inf; 
     220        GThread *thread; 
    254221 
    255222        while (G_LIKELY (copy)) 
     
    286253 
    287254 
    288                 inf = priv->in_auth_function; 
    289                 if (inf) return; 
     255                if (priv->in_auth_function)  
     256                       return; 
    290257 
    291258                g_mutex_lock (priv->colock); 
     
    293260                priv->in_auth_function = TRUE; 
    294261 
    295                 results.self = self; 
    296                 results.account = account; 
    297                 results.prompt = prmpt; 
    298                 results.data = NULL; 
    299                 results.cancel = FALSE; 
    300                 results.func = func; 
    301  
    302                 results.loop = g_main_loop_new (NULL, FALSE); 
    303  
    304                 thread = g_thread_create (get_pwd_thread, &results, TRUE, NULL); 
    305  
    306                 tny_lockable_unlock (priv->ui_lock); 
    307                 g_main_loop_run (results.loop); 
    308                 tny_lockable_lock (priv->ui_lock); 
    309  
    310                 g_main_loop_unref (results.loop); 
    311  
    312                 g_thread_join (thread); 
    313  
    314                 retval = results.data; 
    315                 cancel = results.cancel; 
     262                tny_lockable_lock (self->priv->ui_lock); 
     263                retval = func (account, prmpt, &cancel); 
     264                tny_lockable_unlock (self->priv->ui_lock); 
    316265 
    317266                priv->in_auth_function = FALSE; 
     
    355304 
    356305 
    357 typedef struct 
    358 { 
    359         TnySessionCamel *self; 
    360         GMainLoop *loop; 
    361         TnyForgetPassFunc func; 
    362         TnyAccount *account; 
    363 } ForGetPassWaitResults; 
    364  
    365  
    366 static gpointer  
    367 forget_pwd_thread (gpointer data) 
    368 { 
    369         ForGetPassWaitResults *results = data; 
    370  
    371         while (!(g_main_loop_is_running (results->loop))) 
    372                 usleep (100); 
    373  
    374         tny_lockable_lock (results->self->priv->ui_lock); 
    375         results->func (results->account); 
    376         tny_lockable_unlock (results->self->priv->ui_lock); 
    377  
    378         g_main_loop_quit (results->loop); 
    379  
    380         g_thread_exit (NULL); 
    381         return NULL; 
    382 } 
    383306 
    384307static void 
     
    392315        TnyAccount *account; 
    393316        gboolean found = FALSE; 
    394         ForGetPassWaitResults results; 
    395         GThread *thread; gboolean inf; 
     317        GThread *thread; 
    396318 
    397319        while (G_LIKELY (copy)) 
     
    412334        { 
    413335 
    414                 inf = priv->in_auth_function; 
    415                 if (inf) return; 
     336                if (priv->in_auth_function)  
     337                       return; 
    416338 
    417339                g_mutex_lock (priv->colock); 
     
    419341                priv->in_auth_function = TRUE; 
    420342 
    421                 results.self = self; 
    422                 results.account = account; 
    423                 results.func = func; 
    424                 results.loop = g_main_loop_new (NULL, FALSE); 
    425  
    426                 thread = g_thread_create (forget_pwd_thread, &results, TRUE, NULL); 
    427  
    428                 tny_lockable_unlock (priv->ui_lock); 
    429                 g_main_loop_run (results.loop); 
    430                 tny_lockable_lock (priv->ui_lock); 
    431  
    432                 g_main_loop_unref (results.loop); 
    433  
    434                 g_thread_join (thread); 
     343                tny_lockable_lock (self->priv->ui_lock); 
     344                func (account); 
     345                tny_lockable_unlock (self->priv->ui_lock); 
    435346 
    436347                priv->in_auth_function = FALSE; 
     
    444355 
    445356 
    446  
    447 typedef struct 
    448 { 
    449         TnySessionCamel *self; 
    450         GMainLoop *loop; 
    451         TnyAlertType tnytype; 
    452         gchar *prompt; 
    453         gboolean retval; 
    454 } AlertWaitResults; 
    455  
    456  
    457 static gpointer  
    458 alert_thread (gpointer data) 
    459 { 
    460         AlertWaitResults *results = data; 
    461  
    462         while (!(g_main_loop_is_running (results->loop))) 
    463                 usleep (100); 
    464  
    465         tny_lockable_lock (results->self->priv->ui_lock); 
    466         results->retval = tny_account_store_alert ( 
    467                 (TnyAccountStore*)results->self->priv->account_store,  
    468                 results->tnytype, (const gchar *) results->prompt); 
    469         tny_lockable_unlock (results->self->priv->ui_lock); 
    470  
    471         g_main_loop_quit (results->loop); 
    472  
    473         g_thread_exit (NULL); 
    474         return NULL; 
    475 } 
    476357 
    477358/* tny_session_camel_alert_user will for example be called when SSL is on and  
     
    487368        TnySessionCamelPriv *priv = self->priv; 
    488369        GThread *thread; gboolean inf; 
     370        gboolean retval = FALSE; 
    489371 
    490372        if (priv->account_store) 
     
    492374                TnyAccountStore *account_store = (TnyAccountStore*) priv->account_store; 
    493375                TnyAlertType tnytype; 
    494                 AlertWaitResults results; 
    495376 
    496377                switch (type) 
     
    508389                } 
    509390 
    510                 inf = priv->in_auth_function; 
    511                 if (inf) return
     391                if (priv->in_auth_function)  
     392                       return FALSE
    512393 
    513394                g_mutex_lock (priv->colock); 
     
    515396                priv->in_auth_function = TRUE; 
    516397 
    517                 results.self = self; 
    518                 results.tnytype = tnytype; 
    519                 results.prompt = g_strdup (prompt); 
    520                 results.retval = FALSE; 
    521                 results.loop = g_main_loop_new (NULL, FALSE); 
    522  
    523                 thread = g_thread_create (alert_thread, &results, TRUE, NULL); 
    524  
    525                 tny_lockable_unlock (priv->ui_lock); 
    526                 g_main_loop_run (results.loop); 
    527                 tny_lockable_lock (priv->ui_lock); 
    528  
    529                 g_main_loop_unref (results.loop); 
    530  
    531                 g_thread_join (thread); 
     398                tny_lockable_lock (self->priv->ui_lock); 
     399                retval = tny_account_store_alert ( 
     400                        (TnyAccountStore*) self->priv->account_store,  
     401                        tnytype, (const gchar *) prompt); 
     402                tny_lockable_unlock (self->priv->ui_lock); 
    532403 
    533404                priv->in_auth_function = FALSE; 
     
    535406                g_mutex_unlock (priv->colock); 
    536407 
    537                 g_free (results.prompt); 
    538  
    539                 return results.retval; 
    540         } 
    541          
    542         return FALSE; 
     408        } 
     409 
     410        return retval; 
    543411} 
    544412 
     
    813681        camel_session_set_online ((CamelSession *) self, online);  
    814682 
    815         /* TODO: This makes a mainloop (above) take over in the new thread 
    816         g_thread_create (background_connect_thread, info, FALSE, NULL); */ 
    817  
    818         background_connect_thread (info); 
     683        /* TODO: This makes a mainloop (above) take over in the new thread */ 
     684        g_thread_create (background_connect_thread, info, FALSE, NULL); 
     685 
     686        /* background_connect_thread (info); */ 
    819687 
    820688        return; 
  • trunk/libtinymail-gnome-desktop/tny-gnome-device.c

    r1065 r1495  
    133133                        g_print (_("Invalid network manager installation. Going to assume Offline status\n")); 
    134134                        priv->invnm = TRUE; 
     135 
     136                        libnm_glib_unregister_callback (priv->nm_ctx, priv->callback_id); 
     137                        libnm_glib_shutdown (priv->nm_ctx); 
     138 
    135139                        case LIBNM_NO_NETWORK_CONNECTION: 
    136140                        default: 
  • trunk/tinymail/tny-demoui-summary-view.c

    r1485 r1495  
    691691 
    692692        priv->last_mailbox_correct_select_set = FALSE; 
    693         priv->online_button = gtk_toggle_button_new (); 
     693        priv->online_button = gtk_toggle_button_new_with_label (GO_ONLINE_TXT); 
    694694        priv->current_accounts = NULL; 
    695695