Changeset 1713
- Timestamp:
- 03/09/07 17:42:59
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-camel/tny-camel-account.c (modified) (3 diffs)
- trunk/libtinymail-camel/tny-camel-account.h (modified) (1 diff)
- trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c (modified) (20 diffs)
- trunk/libtinymail-gpe/tny-gpe-account-store.c (modified) (15 diffs)
- trunk/libtinymail-maemo/tny-maemo-account-store.c (modified) (17 diffs)
- trunk/libtinymail-olpc/tny-olpc-account-store.c (modified) (12 diffs)
- trunk/libtinymail/tny-account-store.c (modified) (1 diff)
- trunk/libtinymail/tny-account-store.h (modified) (2 diffs)
- trunk/libtinymail/tny-account.c (modified) (1 diff)
- trunk/libtinymail/tny-account.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1708 r1713 1 2007-03-09 Philip Van Hoof <pvanhoof@gnome.org> 2 3 * Added the tny_account_store_find_account API. It's possible that in 4 future a set and get find strategy API will be added. For now, finding 5 using only the url-string will suffice (and adding the find strategy 6 later wont break the existing API, or at least doesn't have to as far 7 as I can see now -- I might laugh at this entry in future, we'll see) 8 9 * Changes to the TnyAccountStore implementations, it's more typical 10 now to let the account store store the instances internally, rather 11 than letting it always return new instances. How else are you going 12 to find the original TnyAccount instance with 13 tny_account_store_find_account? 14 15 * Added the tny_account_matches_url_string API, to determine whether a 16 specific account instance matches a specific url_string. 17 18 * This was a major API change 19 1 20 2007-03-06 Philip Van Hoof <pvanhoof@gnome.org> 2 21 trunk/libtinymail-camel/tny-camel-account.c
r1712 r1713 49 49 50 50 static GObjectClass *parent_class = NULL; 51 52 static gboolean 53 tny_camel_account_matches_url_string (TnyAccount *self, const gchar *url_string) 54 { 55 return TNY_CAMEL_ACCOUNT_GET_CLASS (self)->matches_url_string_func (self, url_string); 56 } 57 58 static gboolean 59 tny_camel_account_matches_url_string_default (TnyAccount *self, const gchar *url_string) 60 { 61 /* TODO implement */ 62 return FALSE; 63 } 51 64 52 65 static TnyAccountType … … 922 935 klass->get_account_type_func = tny_camel_account_get_account_type; 923 936 klass->cancel_func = tny_camel_account_cancel; 937 klass->matches_url_string_func = tny_camel_account_matches_url_string; 924 938 925 939 return; … … 957 971 class->get_account_type_func = tny_camel_account_get_account_type_default; 958 972 class->cancel_func = tny_camel_account_cancel_default; 973 class->matches_url_string_func = tny_camel_account_matches_url_string_default; 959 974 960 975 class->add_option_func = tny_camel_account_add_option_default; trunk/libtinymail-camel/tny-camel-account.h
r1665 r1713 74 74 void (*try_connect_func) (TnyAccount *self, GError **err); 75 75 void (*cancel_func) (TnyAccount *self); 76 gboolean (*matches_url_string_func) (TnyAccount *self, const gchar *url_string); 76 77 77 78 void (*add_option_func) (TnyCamelAccount *self, const gchar *option); trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c
r1485 r1713 67 67 TnyDevice *device; 68 68 guint notify; 69 GList *accounts; 69 70 }; 70 71 … … 291 292 } 292 293 294 static void 295 kill_stored_accounts (TnyGnomeAccountStorePriv *priv) 296 { 297 if (priv->accounts) 298 { 299 g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 300 g_list_free (priv->accounts); 301 priv->accounts = NULL; 302 } 303 304 return; 305 } 293 306 294 307 static void … … 297 310 { 298 311 TnyAccountStore *self = user_data; 312 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 299 313 300 314 gchar *key = g_strdup (entry->key); 301 315 gchar *ptr = strrchr (key, '/'); ptr++; 302 316 317 303 318 if (!strcmp (ptr, "count")) 304 319 { 320 kill_stored_accounts (priv); 305 321 g_signal_emit (self, 306 322 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 307 308 323 } 309 324 … … 313 328 } 314 329 315 316 static const gchar* 317 tny_gnome_account_store_get_cache_dir (TnyAccountStore *self) 318 { 319 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 320 321 if (G_UNLIKELY (!priv->cache_dir)) 322 { 323 /* Note that there's no listener for this key. If it changes, 324 the camelsession should be destroyed and rebuild from scratch. 325 Which basically means reloading the accounts aswell. 326 327 So say you're a nut who wants this key to be updatable at 328 runtime, you'll have to unload all the accounts here, and of 329 course reload them. All the functionality for that is already 330 available. Perhaps I should just do it ... hmm, maybe another 331 day. Soon. Perhaps. I don't know. Probably . . . . bleh. 332 333 Oh and, not to forget! You should probably also move the old 334 cache location to the new one. Or cleanup the old one. */ 335 336 gchar *cache_dir = gconf_client_get_string (priv->client, 337 "/apps/tinymail/cache_dir", NULL); 338 priv->cache_dir = g_build_filename (g_get_home_dir (), 339 cache_dir, NULL); 340 g_free (cache_dir); 341 } 342 343 return priv->cache_dir; 344 } 345 346 347 static void 348 tny_gnome_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 330 static void 331 load_accounts (TnyAccountStore *self) 349 332 { 350 333 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 351 334 gint i=0, count, port; 352 353 g_assert (TNY_IS_LIST (list));354 335 355 336 count = gconf_client_get_int (priv->client, … … 363 344 364 345 key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 365 346 366 347 if (!gconf_client_dir_exists (priv->client, (const gchar*)key, NULL)) 367 348 { … … 371 352 g_free (key); 372 353 373 374 354 key = g_strdup_printf ("/apps/tinymail/accounts/%d/disabled", i); 375 355 if (gconf_client_get_bool (priv->client, (const gchar*) key, NULL)) … … 384 364 (const gchar*) key, NULL); 385 365 g_free (key); 386 366 387 367 key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", i); 388 368 proto = gconf_client_get_string (priv->client, … … 394 374 (const gchar*) key, NULL); 395 375 g_free (key); 396 397 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 398 { 399 if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 400 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 401 } else if (type && (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS)) 402 { 403 if (!g_ascii_strncasecmp (proto, "imap", 4)) 404 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 405 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 406 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 407 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 408 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 409 else /* Unknown, create a generic one? */ 410 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 411 } 376 377 if (!g_ascii_strncasecmp (proto, "smtp", 4)) 378 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 379 else if (!g_ascii_strncasecmp (proto, "imap", 4)) 380 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 381 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 382 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 383 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 384 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 385 else /* Unknown, create a generic one? */ 386 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 412 387 413 388 if (type) … … 423 398 (const gchar*) key, NULL); 424 399 g_free (key); 425 426 400 427 401 if (name) … … 451 425 } 452 426 453 /* Because we only check for the n first bytes, the pops, imaps and smtps also work */454 427 if (!g_ascii_strncasecmp (proto, "pop", 3) || 455 428 !g_ascii_strncasecmp (proto, "imap", 4)) … … 457 430 gchar *user, *hostname; 458 431 459 /* TODO: Add other supported and tested providers here */460 432 key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 461 433 user = gconf_client_get_string (priv->client, … … 499 471 g_free (key); 500 472 501 /*502 * Setting the password function must happen after503 * setting the host, user and protocol.504 */505 506 473 tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 507 474 per_account_forget_pass_func); … … 510 477 per_account_get_pass_func); 511 478 512 tny_list_prepend (list, (GObject*)account); 513 g_object_unref (G_OBJECT (account)); 514 479 priv->accounts = g_list_prepend (priv->accounts, account); 515 480 } 516 481 … … 521 486 g_free (proto); 522 487 } 523 524 return; 488 } 489 490 static TnyAccount* 491 tny_gnome_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 492 { 493 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 494 TnyAccount *found = NULL; 495 496 if (!priv->accounts) 497 load_accounts (self); 498 499 if (priv->accounts) 500 { 501 GList *copy = priv->accounts; 502 while (copy) 503 { 504 TnyAccount *account = copy->data; 505 506 if (tny_account_matches_url_string (account, url_string)) 507 { 508 found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 509 break; 510 } 511 512 copy = g_list_next (copy); 513 } 514 } 515 516 return found; 517 } 518 519 520 static const gchar* 521 tny_gnome_account_store_get_cache_dir (TnyAccountStore *self) 522 { 523 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 524 525 if (G_UNLIKELY (!priv->cache_dir)) 526 { 527 /* Note that there's no listener for this key. If it changes, 528 the camelsession should be destroyed and rebuild from scratch. 529 Which basically means reloading the accounts aswell. 530 531 So say you're a nut who wants this key to be updatable at 532 runtime, you'll have to unload all the accounts here, and of 533 course reload them. All the functionality for that is already 534 available. Perhaps I should just do it ... hmm, maybe another 535 day. Soon. Perhaps. I don't know. Probably . . . . bleh. 536 537 Oh and, not to forget! You should probably also move the old 538 cache location to the new one. Or cleanup the old one. */ 539 540 gchar *cache_dir = gconf_client_get_string (priv->client, 541 "/apps/tinymail/cache_dir", NULL); 542 priv->cache_dir = g_build_filename (g_get_home_dir (), 543 cache_dir, NULL); 544 g_free (cache_dir); 545 } 546 547 return priv->cache_dir; 548 } 549 550 551 static void 552 tny_gnome_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 553 { 554 TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 555 556 g_assert (TNY_IS_LIST (list)); 557 558 if (!priv->accounts) 559 load_accounts (self); 560 561 if (priv->accounts) 562 { 563 GList *copy = priv->accounts; 564 while (copy) 565 { 566 TnyAccount *account = copy->data; 567 568 if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 569 { 570 if (TNY_IS_STORE_ACCOUNT (account)) 571 tny_list_prepend (list, (GObject*)account); 572 } else if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 573 { 574 if (TNY_IS_TRANSPORT_ACCOUNT (account)) 575 tny_list_prepend (list, (GObject*)account); 576 } 577 578 copy = g_list_next (copy); 579 } 580 } 581 582 return; 525 583 } 526 584 … … 586 644 g_free (key); 587 645 588 count++;646 count++; 589 647 590 648 gconf_client_set_int (priv->client, "/apps/tinymail/accounts/count", … … 643 701 tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 644 702 645 646 703 return TNY_ACCOUNT_STORE (self); 647 704 } … … 655 712 TnyPlatformFactory *platfact; 656 713 714 priv->accounts = NULL; 657 715 priv->client = gconf_client_get_default (); 658 716 … … 663 721 664 722 platfact = TNY_PLATFORM_FACTORY (tny_gnome_platform_factory_get_instance ()); 665 priv->device = tny_platform_factory_new_device (platfact); 666 /* tny_device_force_online (priv->device); */ 667 723 priv->device = tny_platform_factory_new_device (platfact); 668 724 669 725 return; … … 679 735 tny_gnome_account_store_notify_remove (TNY_ACCOUNT_STORE (self)); 680 736 g_object_unref (G_OBJECT (priv->client)); 737 738 kill_stored_accounts (priv); 681 739 682 740 if (G_LIKELY (priv->cache_dir)) … … 729 787 klass->get_device_func = tny_gnome_account_store_get_device; 730 788 klass->alert_func = tny_gnome_account_store_alert; 789 klass->find_account_func = tny_gnome_account_store_find_account; 731 790 732 791 return; trunk/libtinymail-gpe/tny-gpe-account-store.c
r1485 r1713 60 60 TnyDevice *device; 61 61 guint notify; 62 GList *accounts; 62 63 }; 63 64 … … 170 171 } 171 172 173 174 static void 175 kill_stored_accounts (TnyGpeAccountStorePriv *priv) 176 { 177 if (priv->accounts) 178 { 179 g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 180 g_list_free (priv->accounts); 181 priv->accounts = NULL; 182 } 183 184 return; 185 } 186 172 187 static void 173 188 gconf_listener_account_changed (GConfClient *client, guint cnxn_id, … … 177 192 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 178 193 179 180 194 gchar *key = g_strdup (entry->key); 181 195 gchar *ptr = strrchr (key, '/'); ptr++; … … 183 197 if (!strcmp (ptr, "count")) 184 198 { 199 kill_stored_accounts (priv); 185 200 g_signal_emit (self, 186 201 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 187 188 202 } 189 203 … … 193 207 } 194 208 195 196 static const gchar* 197 tny_gpe_account_store_get_cache_dir (TnyAccountStore *self) 198 { 199 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 200 201 if (G_UNLIKELY (!priv->cache_dir)) 202 { 203 /* Note that there's no listener for this key. If it changes, 204 the camelsession should be destroyed and rebuild from scratch. 205 Which basically means reloading the accounts aswell. 206 207 So say you're a nut who wants this key to be updatable at 208 runtime, you'll have to unload all the accounts here, and of 209 course reload them. All the functionality for that is already 210 available. Perhaps I should just do it ... hmm, maybe another 211 day. Soon. Perhaps. I don't know. Probably . . . . bleh. 212 213 Oh and, not to forget! You should probably also move the old 214 cache location to the new one. Or cleanup the old one. */ 215 216 gchar *cache_dir = gconf_client_get_string (priv->client, 217 "/apps/tinymail/cache_dir", NULL); 218 priv->cache_dir = g_build_filename (g_get_home_dir (), 219 cache_dir, NULL); 220 g_free (cache_dir); 221 } 222 223 return priv->cache_dir; 224 } 225 226 227 static void 228 tny_gpe_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 229 { 230 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 209 static void 210 load_accounts (TnyAccountStore *self) 211 { 212 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 213 231 214 gint i=0, count, port; 232 215 233 g_assert (TNY_IS_LIST (list));234 235 216 count = gconf_client_get_int (priv->client, 236 "/apps/tinymail/accounts/count", NULL);217 "/apps/tinymail/accounts/count", NULL); 237 218 238 219 for (i=0; i < count; i++) … … 273 254 (const gchar*) key, NULL); 274 255 g_free (key); 275 276 277 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 278 { 279 if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 280 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 281 } else if (type && types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 282 { 283 if (!g_ascii_strncasecmp (proto, "imap", 4)) 284 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 285 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 286 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 287 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 288 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 289 else /* Unknown, create a generic one? */ 290 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 291 } 292 256 257 if (!g_ascii_strncasecmp (proto, "smtp", 4)) 258 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 259 else if (!g_ascii_strncasecmp (proto, "imap", 4)) 260 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 261 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 262 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 263 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 264 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 265 else /* Unknown, create a generic one? */ 266 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 267 293 268 if (type) 294 269 g_free (type); … … 330 305 } 331 306 332 /* Because we only check for the n first bytes, the pops, imaps and smtps also work */333 307 if (!g_ascii_strncasecmp (proto, "pop", 3) || 334 308 !g_ascii_strncasecmp (proto, "imap", 4)) … … 336 310 gchar *user, *hostname; 337 311 338 /* TODO: Add other supported and tested providers here */339 312 key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 340 313 user = gconf_client_get_string (priv->client, … … 378 351 g_free (key); 379 352 380 /*381 * Setting the password function must happen after382 * setting the host, user and protocol.383 */384 385 353 tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 386 354 per_account_forget_pass_func); … … 389 357 per_account_get_pass_func); 390 358 391 392 tny_list_prepend (list, (GObject*)account); 393 g_object_unref (G_OBJECT (account)); 394 359 priv->accounts = g_list_prepend (priv->accounts, account); 395 360 } 396 361 … … 402 367 403 368 } 404 405 return; 369 } 370 371 static TnyAccount* 372 tny_gpe_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 373 { 374 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 375 TnyAccount *found = NULL; 376 377 if (!priv->accounts) 378 load_accounts (self); 379 380 if (priv->accounts) 381 { 382 GList *copy = priv->accounts; 383 while (copy) 384 { 385 TnyAccount *account = copy->data; 386 387 if (tny_account_matches_url_string (account, url_string)) 388 { 389 found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 390 break; 391 } 392 393 copy = g_list_next (copy); 394 } 395 } 396 397 return found; 398 } 399 400 401 static const gchar* 402 tny_gpe_account_store_get_cache_dir (TnyAccountStore *self) 403 { 404 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 405 406 if (G_UNLIKELY (!priv->cache_dir)) 407 { 408 /* Note that there's no listener for this key. If it changes, 409 the camelsession should be destroyed and rebuild from scratch. 410 Which basically means reloading the accounts aswell. 411 412 So say you're a nut who wants this key to be updatable at 413 runtime, you'll have to unload all the accounts here, and of 414 course reload them. All the functionality for that is already 415 available. Perhaps I should just do it ... hmm, maybe another 416 day. Soon. Perhaps. I don't know. Probably . . . . bleh. 417 418 Oh and, not to forget! You should probably also move the old 419 cache location to the new one. Or cleanup the old one. */ 420 421 gchar *cache_dir = gconf_client_get_string (priv->client, 422 "/apps/tinymail/cache_dir", NULL); 423 priv->cache_dir = g_build_filename (g_get_home_dir (), 424 cache_dir, NULL); 425 g_free (cache_dir); 426 } 427 428 return priv->cache_dir; 429 } 430 431 432 static void 433 tny_gpe_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 434 { 435 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 436 437 g_assert (TNY_IS_LIST (list)); 438 439 if (!priv->accounts) 440 load_accounts (self); 441 442 if (priv->accounts) 443 { 444 GList *copy = priv->accounts; 445 while (copy) 446 { 447 TnyAccount *account = copy->data; 448 449 if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 450 { 451 if (TNY_IS_STORE_ACCOUNT (account)) 452 tny_list_prepend (list, (GObject*)account); 453 } else if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 454 { 455 if (TNY_IS_TRANSPORT_ACCOUNT (account)) 456 tny_list_prepend (list, (GObject*)account); 457 } 458 459 copy = g_list_next (copy); 460 } 461 } 462 463 return; 406 464 } 407 465 … … 538 596 TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 539 597 TnyPlatformFactory *platfact; 540 598 599 priv->accounts = NULL; 541 600 priv->client = gconf_client_get_default (); 542 601 … … 549 608 550 609 priv->device = tny_platform_factory_new_device (platfact); 551 /* tny_device_force_online (priv->device); */ 552 610 553 611 return; 554 612 } … … 563 621 tny_gpe_account_store_notify_remove (TNY_ACCOUNT_STORE (self)); 564 622 g_object_unref (G_OBJECT (priv->client)); 623 624 kill_stored_accounts (priv); 565 625 566 626 if (G_LIKELY (priv->cache_dir)) … … 613 673 klass->get_device_func = tny_gpe_account_store_get_device; 614 674 klass->alert_func = tny_gpe_account_store_alert; 675 klass->find_account_func = tny_gpe_account_store_find_account; 615 676 616 677 return; trunk/libtinymail-maemo/tny-maemo-account-store.c
r1485 r1713 60 60 TnyDevice *device; 61 61 guint notify; 62 GList *accounts; 62 63 }; 63 64 … … 120 121 { 121 122 TnyGetPassFunc func; 122 123 123 124 if (G_LIKELY (passwords)) 124 125 { … … 171 172 } 172 173 174 175 static void 176 kill_stored_accounts (TnyMaemoAccountStorePriv *priv) 177 { 178 if (priv->accounts) 179 { 180 g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 181 g_list_free (priv->accounts); 182 priv->accounts = NULL; 183 } 184 185 return; 186 } 187 173 188 static void 174 189 gconf_listener_account_changed (GConfClient *client, guint cnxn_id, … … 178 193 TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 179 194 180 181 195 gchar *key = g_strdup (entry->key); 182 196 gchar *ptr = strrchr (key, '/'); ptr++; … … 184 198 if (!strcmp (ptr, "count")) 185 199 { 200 kill_stored_accounts (priv); 186 201 g_signal_emit (self, 187 202 tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 188 189 203 } 190 204 … … 194 208 } 195 209 196 197 static const gchar* 198 tny_maemo_account_store_get_cache_dir (TnyAccountStore *self) 199 { 200 TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 201 202 if (G_UNLIKELY (!priv->cache_dir)) 203 { 204 /* Note that there's no listener for this key. If it changes, 205 the camelsession should be destroyed and rebuild from scratch. 206 Which basically means reloading the accounts aswell. 207 208 So say you're a nut who wants this key to be updatable at 209 runtime, you'll have to unload all the accounts here, and of 210 course reload them. All the functionality for that is already 211 available. Perhaps I should just do it ... hmm, maybe another 212 day. Soon. Perhaps. I don't know. Probably . . . . bleh. 213 214 Oh and, not to forget! You should probably also move the old 215 cache location to the new one. Or cleanup the old one. */ 216 217 gchar *cache_dir = gconf_client_get_string (priv->client, 218 "/apps/tinymail/cache_dir", NULL); 219 priv->cache_dir = g_build_filename (g_get_home_dir (), 220 cache_dir, NULL); 221 g_free (cache_dir); 222 } 223 224 return priv->cache_dir; 225 } 226 227 228 static void 229 tny_maemo_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 230 { 231 TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 210 static void 211 load_accounts (TnyAccountStore *self) 212 { 213 TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 214 232 215 gint i=0, count, port; 233 234 g_assert (TNY_IS_LIST (list));235 216 236 217 count = gconf_client_get_int (priv->client, … … 239 220 for (i=0; i < count; i++) 240 221 { 222 241 223 gchar *proto, *type, *key, *name, *mech; 242 224 TnyAccount *account = NULL; … … 274 256 (const gchar*) key, NULL); 275 257 g_free (key); 276 277 278 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 279 { 280 if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 281 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 282 } else if (type && types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 283 { 284 if (!g_ascii_strncasecmp (proto, "imap", 4)) 285 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 286 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 287 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 288 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 289 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 290 else /* Unknown, create a generic one? */ 291 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 292 } 293 258 259 if (!g_ascii_strncasecmp (proto, "smtp", 4)) 260 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 261 else if (!g_ascii_strncasecmp (proto, "imap", 4)) 262 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 263 else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 264 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 265 else if (!g_ascii_strncasecmp (proto, "pop", 3)) 266 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 267 else /* Unknown, create a generic one? */ 268 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 269 294 270 if (type) 295 271 g_free (type); … … 330 306 } 331 307 332 /* Because we only check for the n first bytes, the pops, imaps and smtps also work */333 308 if (!g_ascii_strncasecmp (proto, "pop", 3) || 334 309 !g_ascii_strncasecmp (proto, "imap", 4)) … … 336 311 gchar *user, *hostname; 337 312 338 /* TODO: Add other supported and tested providers here */339 313 key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 340 314 user = gconf_client_get_string (priv->client, … … 378 352 g_free (key); 379 353 380 /*381 * Setting the password function must happen after382 * setting the host, user and protocol.383 */384 385 354 tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 386 355 per_account_forget_pass_func); … … 389 358 per_account_get_pass_func); 390 359 391 392 tny_list_prepend (list, (GObject*)account); 393 g_object_unref (G_OBJECT (account)); 360 priv->accounts = g_list_prepend (priv->accounts, account); 394 361 395 362 } … … 401 368 g_free (mech); 402 369 403 404 } 405 406 return; 370 } 371 } 372 373 static TnyAccount* 374 tny_maemo_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 375 { 376 TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 377 TnyAccount *found = NULL; 378 379 if (!priv->accounts) 380 load_accounts (self); 381 382 if (priv->accounts) 383 { 384 GList *copy = priv->accounts; 385 while (copy) 386 { 387 TnyAccount *account = copy->data; 388 389 if (tny_account_matches_url_string (account, url_string)) 390 { 391 found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 392 break; 393 } 394 395 copy = g_list_next (copy); 396 } 397 } 398 399 return found; 400 } 401 402 403 static const gchar* &n
