Changeset 1398
- Timestamp:
- 01/13/07 04:27:31
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-camel/tny-session-camel.c (modified) (14 diffs)
- trunk/libtinymail-camel/tny-session-camel.h (modified) (4 diffs)
- trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c (modified) (3 diffs)
- trunk/libtinymail-gpe/tny-gpe-account-store.c (modified) (2 diffs)
- trunk/libtinymail-maemo/tny-maemo-account-store.c (modified) (2 diffs)
- trunk/libtinymail-olpc/tny-olpc-account-store.c (modified) (2 diffs)
- trunk/libtinymail/Makefile.am (modified) (2 diffs)
- trunk/libtinymail/tny-lockable.c (added)
- trunk/libtinymail/tny-lockable.h (added)
- trunk/libtinymail/tny-noop-lockable.c (added)
- trunk/libtinymail/tny-noop-lockable.h (added)
- trunk/libtinymail/tny-shared.h (modified) (1 diff)
- trunk/libtinymailui-gtk/Makefile.am (modified) (2 diffs)
- trunk/libtinymailui-gtk/tny-gtk-lockable.c (added)
- trunk/libtinymailui-gtk/tny-gtk-lockable.h (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1397 r1398 1 2007-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 1 11 2007-01-12 Philip Van Hoof <pvanhoof@gnome.org> 2 12 trunk/libtinymail-camel/tny-session-camel.c
r1391 r1398 41 41 #include <tny-camel-transport-account.h> 42 42 43 #include <tny-noop-lockable.h> 44 43 45 #include "tny-session-camel-priv.h" 44 46 #include "tny-camel-store-account-priv.h" … … 204 206 205 207 206 /* Will be called at camel_service_connect in case the account needs a password. 207 its implementation can contani GUI things. */ 208 typedef 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 219 static gboolean 220 get_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 233 static gpointer 234 get_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 208 242 static char * 209 243 tny_session_camel_get_password (CamelSession *session, CamelService *service, const char *domain, 210 244 const char *prompt, const char *item, guint32 flags, CamelException *ex) 211 245 { 246 TnySessionCamel *self = (TnySessionCamel *) session; 247 212 248 GList *copy = password_funcs; 213 249 TnyGetPassFunc func; … … 215 251 gboolean found = FALSE, freeprmpt = FALSE, cancel = FALSE; 216 252 gchar *retval = NULL, *prmpt = (gchar*)prompt; 253 GetPassWaitResults results; 254 GThread *thread; 217 255 218 256 while (G_LIKELY (copy)) … … 246 284 } 247 285 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; 249 313 250 314 if (freeprmpt) … … 259 323 } 260 324 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 **/ 336 void 337 tny_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 346 typedef struct 347 { 348 TnySessionCamel *self; 349 GMainLoop *loop; 350 TnyForgetPassFunc func; 351 TnyAccount *account; 352 } ForGetPassWaitResults; 353 354 static gboolean 355 forget_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 368 static gpointer 369 forget_pwd_thread (gpointer results) 370 { 371 g_idle_add (forget_pwd_idle_handler, results); 372 g_thread_exit (NULL); 373 return NULL; 374 } 375 263 376 static void 264 377 tny_session_camel_forget_password (CamelSession *session, CamelService *service, const char *domain, const char *item, CamelException *ex) 265 378 { 379 TnySessionCamel *self = (TnySessionCamel *)session; 380 266 381 GList *copy = forget_password_funcs; 267 382 TnyForgetPassFunc func; 268 383 TnyAccount *account; 269 384 gboolean found = FALSE; 385 ForGetPassWaitResults results; 386 GThread *thread; 270 387 271 388 while (G_LIKELY (copy)) … … 284 401 285 402 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 432 typedef struct 433 { 434 TnySessionCamel *self; 435 GMainLoop *loop; 436 TnyAlertType tnytype; 437 gchar *prompt; 438 gboolean retval; 439 } AlertWaitResults; 440 441 static gboolean 442 alert_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 457 static gpointer 458 alert_thread (gpointer results) 459 { 460 g_idle_add (alert_idle_handler, results); 461 g_thread_exit (NULL); 462 return NULL; 289 463 } 290 464 … … 299 473 { 300 474 TnySessionCamel *self = (TnySessionCamel *)session; 475 GThread *thread; 301 476 302 477 if (self->account_store) … … 304 479 TnyAccountStore *account_store = (TnyAccountStore*)self->account_store; 305 480 TnyAlertType tnytype; 481 AlertWaitResults results; 306 482 307 483 switch (type) … … 319 495 } 320 496 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; 322 522 } 323 523 … … 453 653 instance->device = NULL; 454 654 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; 455 660 } 456 661 … … 492 697 TnySessionCamel *self = user_data; 493 698 699 if (self->in_auth_function) 700 return; 701 494 702 camel_session_set_online ((CamelSession *) self, online); 495 703 … … 596 804 (camel_object_new (TNY_TYPE_SESSION_CAMEL)); 597 805 598 retval->camel_dir = NULL;599 806 tny_session_camel_set_account_store (retval, account_store); 600 807 … … 613 820 self->connchanged_signal); 614 821 } 822 823 if (self->ui_lock) 824 g_object_unref (G_OBJECT (self->ui_lock)); 615 825 616 826 if (self->camel_dir) … … 636 846 camel_session_class->thread_msg_free = tny_session_camel_ms_thread_msg_free; 637 847 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;642 848 643 849 return; trunk/libtinymail-camel/tny-session-camel.h
r1383 r1398 25 25 #include <tny-shared.h> 26 26 #include <tny-camel-shared.h> 27 #include <tny-lockable.h> 27 28 28 29 G_BEGIN_DECLS … … 43 44 GList *current_accounts; 44 45 gchar *camel_dir; 46 gboolean in_auth_function; 47 TnyLockable *ui_lock; 45 48 }; 46 49 … … 48 51 { 49 52 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 55 53 }; 56 54 … … 62 60 void tny_session_camel_set_device (TnySessionCamel *self, TnyDevice *device); 63 61 62 void tny_session_camel_set_ui_locker (TnySessionCamel *self, TnyLockable *ui_lock); 63 64 64 G_END_DECLS 65 65 trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c
r1384 r1398 47 47 #include <tny-session-camel.h> 48 48 49 #include <tny-gtk-lockable.h> 50 49 51 #ifdef GNOME 50 52 #include <libgnomeui/gnome-password-dialog.h> … … 139 141 while (gtk_events_pending ()) 140 142 gtk_main_iteration (); 143 141 144 } else { 142 145 … … 616 619 priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 617 620 621 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 622 623 618 624 return TNY_ACCOUNT_STORE (self); 619 625 } trunk/libtinymail-gpe/tny-gpe-account-store.c
r1383 r1398 45 45 #include <tny-gpe-device.h> 46 46 47 #include <tny-gtk-lockable.h> 47 48 48 49 /* "GConf vs. Camel" account implementation */ … … 502 503 priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 503 504 505 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 506 504 507 return TNY_ACCOUNT_STORE (self); 505 508 } trunk/libtinymail-maemo/tny-maemo-account-store.c
r1383 r1398 45 45 #include <tny-maemo-device.h> 46 46 47 #include <tny-gtk-lockable.h> 47 48 48 49 /* "GConf vs. Camel" account implementation */ … … 504 505 priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 505 506 507 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 508 506 509 return TNY_ACCOUNT_STORE (self); 507 510 } trunk/libtinymail-olpc/tny-olpc-account-store.c
r1383 r1398 43 43 #include <tny-session-camel.h> 44 44 #include <tny-olpc-device.h> 45 46 #include <tny-gtk-lockable.h> 45 47 46 48 /* GKeyFile vs. Camel implementation */ … … 371 373 priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 372 374 375 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 376 373 377 return TNY_ACCOUNT_STORE (self); 374 378 } trunk/libtinymail/Makefile.am
r1377 r1398 14 14 tny-msg.h \ 15 15 tny-device.h \ 16 tny-lockable.h \ 17 tny-noop-lockable.h \ 16 18 tny-account.h \ 17 19 tny-store-account.h \ … … 38 40 tny-folder.c \ 39 41 tny-device.c \ 42 tny-lockable.c \ 43 tny-noop-lockable.c \ 40 44 tny-account.c \ 41 45 tny-store-account.c \ trunk/libtinymail/tny-shared.h
r1377 r1398 83 83 typedef struct _TnyPair TnyPair; 84 84 typedef struct _TnyPairClass TnyPairClass; 85 typedef struct _TnyLockable TnyLockable; 86 typedef struct _TnyLockableIface TnyLockableIface; 87 typedef struct _TnyNoopLockable TnyNoopLockable; 88 typedef struct _TnyNoopLockableClass TnyNoopLockableClass; 85 89 86 90 G_END_DECLS trunk/libtinymailui-gtk/Makefile.am
r1280 r1398 13 13 tny-gtk-mime-part-save-strategy.h \ 14 14 tny-gtk-msg-view.h \ 15 tny-gtk-lockable.h \ 15 16 tny-gtk-msg-window.h \ 16 17 tny-gtk-text-mime-part-view.h \ … … 27 28 tny-gtk-mime-part-save-strategy.c \ 28 29 tny-gtk-msg-view.c \ 30 tny-gtk-lockable.c \ 29 31 tny-gtk-text-mime-part-view.c \ 30 32 tny-gtk-attachment-mime-part-view.c \
