Changeset 2643
- Timestamp:
- 08/15/07 14:38:47
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-maemo/tny-maemo-conic-device.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r2642 r2643 1 2007-08-15 Philip Van Hoof <pvanhoof@gnome.org> 2 3 * Improved the TnyMaemoConicDevice a bit 4 1 5 2007-08-15 Murray Cumming <murrayc@murrayc.com> 2 6 trunk/libtinymail-maemo/tny-maemo-conic-device.c
r2642 r2643 34 34 35 35 #ifdef MAEMO_CONIC_DUMMY 36 36 37 /* #include "coniciap-private.h" 37 * This is not installed, so we predeclare 38 * the struct instead. 39 * Of course, this is a hack and could break if the private API 40 * changes. 41 * It would be better for libconic to support scratchbox. 42 */ 38 * This is not installed, so we predeclare the struct instead. Of course, this 39 * is a hack and could break if the private API changes. It would be better for 40 * libconic to support scratchbox. */ 41 43 42 struct _ConIcIap 44 43 { … … 61 60 typedef struct { 62 61 ConIcConnection *cnx; 63 gboolean is_online; 64 gchar *iap; 65 gboolean forced; /* Whether the is_online value is forced rather than real. */ 66 62 gboolean is_online; 63 gchar *iap; 64 gboolean forced; /* Whether the is_online value is forced rather than real. */ 67 65 /* When non-NULL, we are waiting for the success or failure signal. */ 68 66 GMainLoop *loop; 69 70 #ifdef MAEMO_CONIC_DUMMY 67 #ifdef MAEMO_CONIC_DUMMY 71 68 gint dummy_env_check_timeout; 72 69 #endif /* MAEMO_CONIC_DUMMY */ … … 75 72 #define TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE(o) \ 76 73 (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_MAEMO_CONIC_DEVICE, TnyMaemoConicDevicePriv)) 77 78 74 79 75 typedef struct { … … 89 85 /* We lock the gdk thread because tinymail wants implementations to do this 90 86 * before emitting _any_ signals. 91 * See http://www.tinymail.org/trac/tinymail/wiki/HowTnyLockable 92 */ 87 * See http://www.tinymail.org/trac/tinymail/wiki/HowTnyLockable */ 88 93 89 gdk_threads_enter (); 94 90 g_signal_emit (info->self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], … … 117 113 * about this - it would be nice if libconic documented that). 118 114 * But if there is no mainloop, then just emit it, as tinymail 119 * requires when there is no mainloop: 120 */ 115 * requires when there is no mainloop: */ 116 121 117 /* TODO: We have no way to check for this now, and 122 118 * at this time it's not even clear whether tinymail should/can really 123 * demand this. murrayc. 15th Aug. 2007. 124 */ 119 * demand this. murrayc. 15th Aug. 2007. */ 120 125 121 if (TRUE) /* TODO: But NULL is not allowed here: g_main_loop_is_running (NULL)) */ 126 122 { 127 123 /* Emit it in an idle handler: */ 128 124 EmitStatusInfo *info = g_slice_new (EmitStatusInfo); 129 130 125 info->self = g_object_ref (self); 131 126 info->status = status; 132 133 127 g_idle_add_full (G_PRIORITY_DEFAULT, conic_emit_status_idle, 134 128 info, conic_emit_status_destroy); 129 135 130 } else { 136 131 /* Emit it directly: */ 137 138 /* We lock the gdk thread because tinymail wants implementations to do this139 * before emitting _any_ signals.140 * See http://www.tinymail.org/trac/tinymail/wiki/HowTnyLockable 141 */ 132 133 /* We lock the gdk thread because tinymail wants implementations 134 * to do this before emitting _any_ signals. 135 * See http://www.tinymail.org/trac/tinymail/wiki/HowTnyLockable */ 136 142 137 gdk_threads_enter (); 143 138 g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], … … 155 150 TnyMaemoConicDevicePriv *priv; 156 151 gboolean status_before = FALSE; 157 152 158 153 g_return_if_fail (TNY_IS_DEVICE(device)); 159 154 self = TNY_MAEMO_CONIC_DEVICE (device); … … 161 156 162 157 status_before = tny_maemo_conic_device_is_online (device); 163 164 158 priv->forced = FALSE; 165 159 166 160 if (status_before != tny_maemo_conic_device_is_online (device)) 167 161 conic_emit_status (device, !status_before); 162 163 return; 168 164 } 169 165 … … 171 167 172 168 static void 173 stop_loop(TnyMaemoConicDevice *self) 174 { 175 TnyMaemoConicDevicePriv *priv 176 = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 177 178 if (priv->loop) { 169 stop_loop (TnyMaemoConicDevice *self) 170 { 171 TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 172 if (priv->loop) 179 173 g_main_loop_quit (priv->loop); 180 }174 return; 181 175 } 182 176 … … 184 178 on_connection_event (ConIcConnection *cnx, ConIcConnectionEvent *event, gpointer user_data) 185 179 { 186 TnyMaemoConicDevice *device ;187 TnyMaemoConicDevicePriv *priv ;180 TnyMaemoConicDevice *device = TNY_MAEMO_CONIC_DEVICE (user_data); 181 TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (device); 188 182 gboolean is_online = FALSE; 183 gboolean emit = FALSE; 184 185 /* Don't emit nor make any changes in case of forced state */ 186 if (priv->forced) 187 return; 189 188 190 189 g_return_if_fail (CON_IC_IS_CONNECTION(cnx)); 191 g_return_if_fail (user_data); 192 193 device = TNY_MAEMO_CONIC_DEVICE(user_data); 194 priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (device); 195 190 191 #ifdef DEBUG 196 192 g_message (__FUNCTION__); 197 198 switch (con_ic_connection_event_get_error(event)) { 199 case CON_IC_CONNECTION_ERROR_NONE: 200 break; 201 case CON_IC_CONNECTION_ERROR_INVALID_IAP: 202 g_warning ("conic: IAP is invalid"); 203 break; 204 case CON_IC_CONNECTION_ERROR_CONNECTION_FAILED: 205 g_warning ("conic: connection failed"); 206 break; 207 case CON_IC_CONNECTION_ERROR_USER_CANCELED: 208 g_warning ("conic: user cancelled"); 209 break; 210 default: 211 g_return_if_reached (); 212 } 213 214 switch (con_ic_connection_event_get_status(event)) { 215 case CON_IC_STATUS_CONNECTED: 216 priv->iap = g_strdup (con_ic_event_get_iap_id ((ConIcEvent*)(event))); 217 is_online = TRUE; 218 219 /* Stop blocking 220 * tny_maemo_conic_device_connect(), if we are: */ 221 stop_loop (device); 222 223 /* g_message ("new status: CONNECTED (%s)", priv->iap); */ 224 break; 225 case CON_IC_STATUS_DISCONNECTED: 226 priv->iap = NULL; 227 is_online = FALSE; 228 229 /* Stop blocking 230 * tny_maemo_conic_device_connect(), if we are: */ 231 stop_loop (device); 232 233 /* g_message ("new status: DISCONNECTED"); */ 234 break; 235 case CON_IC_STATUS_DISCONNECTING: 236 is_online = FALSE; 237 /* g_message ("new status: DISCONNECTING"); */ 238 break; 239 default: 240 g_return_if_reached (); 193 #endif 194 195 switch (con_ic_connection_event_get_error(event)) 196 { 197 case CON_IC_CONNECTION_ERROR_NONE: 198 break; 199 case CON_IC_CONNECTION_ERROR_INVALID_IAP: 200 g_warning ("conic: IAP is invalid"); 201 break; 202 case CON_IC_CONNECTION_ERROR_CONNECTION_FAILED: 203 g_warning ("conic: connection failed"); 204 break; 205 case CON_IC_CONNECTION_ERROR_USER_CANCELED: 206 g_warning ("conic: user cancelled"); 207 break; 208 default: 209 g_return_if_reached (); 210 } 211 212 switch (con_ic_connection_event_get_status(event)) 213 { 214 case CON_IC_STATUS_CONNECTED: 215 if (priv->iap) 216 g_free (priv->iap); 217 priv->iap = g_strdup (con_ic_event_get_iap_id ((ConIcEvent*)(event))); 218 if (!priv->is_online) 219 emit = TRUE; 220 is_online = TRUE; 221 /* Stop blocking tny_maemo_conic_device_connect(), if we are: */ 222 stop_loop (device); 223 break; 224 225 case CON_IC_STATUS_DISCONNECTED: 226 priv->iap = NULL; 227 if (priv->is_online) 228 emit = TRUE; 229 is_online = FALSE; 230 /* Stop blocking tny_maemo_conic_device_connect(), if we are: */ 231 stop_loop (device); 232 break; 233 234 case CON_IC_STATUS_DISCONNECTING: 235 break; 236 default: 237 g_return_if_reached (); 241 238 } 242 239 243 240 priv->is_online = is_online; 244 priv->forced = FALSE; /* is_online is now accurate. */ 241 242 #ifdef DEBUG 245 243 g_message ("DEBUG: %s: emitting signal CONNECTION_CHANGED: %s", 246 244 __FUNCTION__, is_online ? "online" : "offline"); 247 248 conic_emit_status (TNY_DEVICE (device), is_online); 249 245 #endif 246 247 if (emit) 248 conic_emit_status (TNY_DEVICE (device), is_online); 249 250 return; 250 251 } 251 252 #endif /* MAEMO_CONIC_DUMMY */ … … 284 285 * which will be read later: */ 285 286 gchar *filename = get_dummy_filename (); 286 287 287 288 g_file_set_contents (filename, "debug id0", -1, &error); 288 289 if(error) { … … 291 292 error = NULL; 292 293 } 293 294 294 295 g_free (filename); 295 296 296 297 return TRUE; 297 298 } … … 319 320 tny_maemo_conic_device_connect (TnyMaemoConicDevice *self, const gchar* iap_id) 320 321 { 321 #ifdef MAEMO_CONIC_DUMMY322 #ifdef MAEMO_CONIC_DUMMY 322 323 return dummy_con_ic_connection_connect_by_id (self, iap_id); 323 #else324 #else 324 325 TnyMaemoConicDevicePriv *priv = NULL; 325 326 gboolean request_failed = FALSE; … … 365 366 366 367 return priv->is_online; 367 #endif /* MAEMO_CONIC_DUMMY */368 #endif /* MAEMO_CONIC_DUMMY */ 368 369 } 369 370 … … 413 414 414 415 #ifdef MAEMO_CONIC_DUMMY 415 416 416 static gboolean 417 417 on_dummy_connection_check (gpointer user_data) … … 498 498 priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 499 499 500 #ifdef MAEMO_CONIC_DUMMY500 #ifdef MAEMO_CONIC_DUMMY 501 501 on_dummy_connection_check (self); 502 502 /* Handle the special "none" text: */ 503 503 if (priv->iap && (strcmp (priv->iap, MAEMO_CONIC_DUMMY_IAP_ID_NONE) == 0)) 504 504 return NULL; 505 #endif505 #endif 506 506 507 507 return priv->iap; … … 525 525 tny_maemo_conic_device_get_iap (TnyMaemoConicDevice *self, const gchar *iap_id) 526 526 { 527 #ifdef MAEMO_CONIC_DUMMY527 #ifdef MAEMO_CONIC_DUMMY 528 528 ConIcIap *iap = NULL; 529 #else529 #else 530 530 TnyMaemoConicDevicePriv *priv = NULL; 531 #endif532 531 #endif 532 533 533 g_return_val_if_fail (TNY_IS_MAEMO_CONIC_DEVICE(self), NULL); 534 534 g_return_val_if_fail (iap_id, NULL); 535 535 536 #ifdef MAEMO_CONIC_DUMMY536 #ifdef MAEMO_CONIC_DUMMY 537 537 /* Note that we have re-declared the private struct so that we 538 538 * can do this, which is very bad and fragile: */ 539 iap = g_object_new (CON_IC_TYPE_IAP, NULL);540 iap->id = g_strdup(iap_id);541 iap->name = g_strdup_printf("%s name", iap->id);542 return iap;543 #else539 iap = g_object_new (CON_IC_TYPE_IAP, NULL); 540 iap->id = g_strdup(iap_id); 541 iap->name = g_strdup_printf("%s name", iap->id); 542 return iap; 543 #else 544 544 priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 545 545 g_return_val_if_fail (priv->cnx, NULL); … … 551 551 */ 552 552 return con_ic_connection_get_iap (priv->cnx, iap_id); 553 #endif553 #endif 554 554 } 555 555 … … 578 578 579 579 #ifdef MAEMO_CONIC_DUMMY 580 580 581 /* libconic does not return a list of connections when running 581 582 * in scratchbox, though it might do this in future when … … 583 584 * So we return a fake list so we can exercise funcationality 584 585 * that uses connections: */ 585 for (i = 0; i < 10; ++i) {586 /* con_ic_iap_new (id) would checkc for a gconf dir and587 * fails, though _new() functions should just call g_object_new().588 *589 gchar *id = g_strdup_printf("debug id%d", i);590 ConIcIap *iap = con_ic_iap_new (id);591 g_free (id);592 */593 594 /* Note that we have re-declared the private struct so that we595 * can do this, which is very bad and fragile: */596 ConIcIap *iap = g_object_new (CON_IC_TYPE_IAP, NULL);597 iap->id = g_strdup_printf("debug id%d", i);598 iap->name = g_strdup_printf("%s name", iap->id);599 600 result = g_slist_append (result, iap);601 }602 603 return result;586 for (i = 0; i < 10; ++i) { 587 /* con_ic_iap_new (id) would checkc for a gconf dir and 588 * fails, though _new() functions should just call g_object_new(). 589 * 590 gchar *id = g_strdup_printf("debug id%d", i); 591 ConIcIap *iap = con_ic_iap_new (id); 592 g_free (id); 593 */ 594 595 /* Note that we have re-declared the private struct so that we 596 * can do this, which is very bad and fragile: */ 597 ConIcIap *iap = g_object_new (CON_IC_TYPE_IAP, NULL); 598 iap->id = g_strdup_printf("debug id%d", i); 599 iap->name = g_strdup_printf("%s name", iap->id); 600 601 result = g_slist_append (result, iap); 602 } 603 604 return result; 604 605 #else 605 606 priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); … … 667 668 #ifdef MAEMO_CONIC_DUMMY 668 669 return; 669 #endif /*MAEMO_CONIC_DUMMY*/ 670 670 #else 671 671 already_offline = !tny_maemo_conic_device_is_online (device); 672 673 672 priv->forced = TRUE; 674 675 673 /* Signal if it changed: */ 676 674 if (!already_offline) 677 675 conic_emit_status (device, FALSE); 676 return; 677 #endif 678 678 } 679 679 … … 683 683 g_return_val_if_fail (TNY_IS_DEVICE(self), FALSE); 684 684 685 #ifdef MAEMO_CONIC_DUMMY685 #ifdef MAEMO_CONIC_DUMMY 686 686 on_dummy_connection_check (self); 687 #endif /* MAEMO_CONIC_DUMMY */688 687 #endif /* MAEMO_CONIC_DUMMY */ 688 689 689 return TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self)->is_online; 690 690 } … … 695 695 { 696 696 TnyMaemoConicDevice *self = (TnyMaemoConicDevice *)instance; 697 698 697 TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (self); 698 699 /* We should not have a real is_online, based on what libconic has told us: */ 700 priv->forced = FALSE; 699 701 priv->iap = NULL; 700 702 /* priv->is_online = FALSE; */ 701 702 /* TODO: This is a hack that fixes a problem 703 * (Our signal is not emitted before the gtk mainloop is started, 704 * because we use an idle handler for that and we don't know how to 705 * detect when the mainloop has not yet started. 706 * The downside is that we now don't know that we are really offline, 707 * so we can't ask the user to go online. 708 * This must be fixed properly. 709 */ 703 704 /* TODO: This is a hack that fixes a problem: Our signal is not emitted 705 * before the gtk mainloop is started, because we use an idle handler 706 * for that and we don't know how to detect when the mainloop has not 707 * yet started. The downside is that we now don't know that we are really 708 * offline, so we can't ask the user to go online. This must be fixed 709 * properly. */ 710 710 711 priv->is_online = TRUE; 711 712 #ifndef MAEMO_CONIC_DUMMY 712 713 714 #ifndef MAEMO_CONIC_DUMMY 713 715 priv->cnx = con_ic_connection_new (); 714 716 if (!priv->cnx) { … … 716 718 } 717 719 718 /* This might be necessary to make the connection object 719 * actually emit the signal, though the documentation says 720 * that they should be sent even when this is not set, 721 * when we explicitly try to connect. 722 * The signal still does not seem to be emitted. 723 */ 720 /* This might be necessary to make the connection object actually emit 721 * the signal, though the documentation says that they should be sent 722 * even when this is not set, when we explicitly try to connect. The 723 * signal still does not seem to be emitted. */ 724 724 725 g_object_set (priv->cnx, "automatic-connection-events", TRUE, NULL); 725 726 … … 727 728 G_CALLBACK(on_connection_event), self); 728 729 729 /* 730 * This will get us in connected state only if there is already a connection. 731 * thus, this will setup our state correctly when we receive the signals. 732 */ 730 /* This will get us in connected state only if there is already a connection. 731 * thus, this will setup our state correctly when we receive the signals. */ 732 733 733 if (!con_ic_connection_connect (priv->cnx, CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED)) 734 734 g_warning ("could not send connect dbus message"); 735 735 736 #endif /* MAEMO_CONIC_DUMMY */ 737 738 /* We should not have a real is_online, based on what libconic has told us: */ 739 priv->forced = FALSE; 740 741 #ifdef MAEMO_CONIC_DUMMY 736 #endif /* MAEMO_CONIC_DUMMY */ 737 738 739 #ifdef MAEMO_CONIC_DUMMY 740 742 741 /* Allow debuggers to fake a connection change by setting an environment 743 * variable, which we check ever 1 second. 744 * This should match one of the fake iap IDs that we created in 745 * tny_maemo_conic_device_get_iap_list(). 746 */ 742 * variable, which we check ever 1 second. This should match one of the 743 * fake iap IDs that we created in tny_maemo_conic_device_get_iap_list().*/ 744 747 745 priv->dummy_env_check_timeout = 748 746 g_timeout_add (1000, on_dummy_connection_check, self); 749 #endif /* MAEMO_CONIC_DUMMY */747 #endif /* MAEMO_CONIC_DUMMY */ 750 748 } 751 749 … … 767 765 { 768 766 TnyMaemoConicDevicePriv *priv = TNY_MAEMO_CONIC_DEVICE_GET_PRIVATE (obj); 769 770 #ifndef MAEMO_CONIC_DUMMY767 768 #ifndef MAEMO_CONIC_DUMMY 771 769 if (priv->cnx && CON_IC_IS_CONNECTION(priv->cnx)) { 772 770 if (!tny_maemo_conic_device_disconnect (TNY_MAEMO_CONIC_DEVICE(obj),priv->iap)) … … 775 773 priv->cnx = NULL; 776 774 } 777 #endif /* MAEMO_CONIC_DUMMY */ 778 779 #ifdef MAEMO_CONIC_DUMMY 775 #else 780 776 if (priv->dummy_env_check_timeout) { 781 777 g_source_remove (priv->dummy_env_check_timeout); 782 778 priv->dummy_env_check_timeout = 0; 783 779 } 784 #endif /* MAEMO_CONIC_DUMMY */785 780 #endif /* MAEMO_CONIC_DUMMY */ 781 786 782 if (priv->iap) { 787 783 g_free (priv->iap);
