Mercurial > pidgin
comparison libpurple/network.c @ 24301:785db7300ef2
Improve our NetworkManager support in a couple of ways:
* We no longer show error minidialogs when the network is not available.
* We no longer ask NetworkManager (over DBus) for the network state with
every call to purple_network_is_available(). We now cache the result.
* Be a little more robust when we're not sure of the connection status.
Fixes #7323
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 26 Oct 2008 00:29:27 +0000 |
parents | 91169093449d |
children | a6742d9eadf3 b38cbefca6ad |
comparison
equal
deleted
inserted
replaced
24300:9ebd288d7b77 | 24301:785db7300ef2 |
---|---|
64 #include <NetworkManager.h> | 64 #include <NetworkManager.h> |
65 | 65 |
66 static DBusGConnection *nm_conn = NULL; | 66 static DBusGConnection *nm_conn = NULL; |
67 static DBusGProxy *nm_proxy = NULL; | 67 static DBusGProxy *nm_proxy = NULL; |
68 static DBusGProxy *dbus_proxy = NULL; | 68 static DBusGProxy *dbus_proxy = NULL; |
69 static NMState nm_state = NM_STATE_UNKNOWN; | |
70 static gboolean have_nm_state = FALSE; | |
69 | 71 |
70 #elif defined _WIN32 | 72 #elif defined _WIN32 |
71 static int current_network_count; | 73 static int current_network_count; |
72 #endif | 74 #endif |
73 | 75 |
594 | 596 |
595 gboolean | 597 gboolean |
596 purple_network_is_available(void) | 598 purple_network_is_available(void) |
597 { | 599 { |
598 #ifdef HAVE_NETWORKMANAGER | 600 #ifdef HAVE_NETWORKMANAGER |
599 NMState state = nm_get_network_state(); | 601 if (!have_nm_state) |
600 if (state == NM_STATE_UNKNOWN) | |
601 { | 602 { |
602 purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n"); | 603 have_nm_state = TRUE; |
603 return TRUE; | 604 nm_state = nm_get_network_state(); |
604 } | 605 if (nm_state == NM_STATE_UNKNOWN) |
605 else if (state == NM_STATE_CONNECTED) | 606 purple_debug_warning("network", "NetworkManager not active. Assuming connection exists.\n"); |
607 } | |
608 | |
609 if (nm_state == NM_STATE_UNKNOWN || nm_state == NM_STATE_CONNECTED) | |
606 return TRUE; | 610 return TRUE; |
607 | 611 |
608 return FALSE; | 612 return FALSE; |
609 | 613 |
610 #elif defined _WIN32 | 614 #elif defined _WIN32 |
616 | 620 |
617 #ifdef HAVE_NETWORKMANAGER | 621 #ifdef HAVE_NETWORKMANAGER |
618 static void | 622 static void |
619 nm_update_state(NMState state) | 623 nm_update_state(NMState state) |
620 { | 624 { |
621 static NMState prev = NM_STATE_UNKNOWN; | 625 NMState prev = nm_state; |
622 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops(); | 626 PurpleConnectionUiOps *ui_ops = purple_connections_get_ui_ops(); |
627 | |
628 have_nm_state = TRUE; | |
629 nm_state = state; | |
623 | 630 |
624 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL); | 631 purple_signal_emit(purple_network_get_handle(), "network-configuration-changed", NULL); |
625 | 632 |
626 switch(state) | 633 switch(state) |
627 { | 634 { |
628 case NM_STATE_CONNECTED: | 635 case NM_STATE_CONNECTED: |
629 /* Call res_init in case DNS servers have changed */ | 636 /* Call res_init in case DNS servers have changed */ |
630 res_init(); | 637 res_init(); |
631 if (ui_ops != NULL && ui_ops->network_connected != NULL) | 638 if (ui_ops != NULL && ui_ops->network_connected != NULL) |
632 ui_ops->network_connected(); | 639 ui_ops->network_connected(); |
633 prev = state; | |
634 break; | 640 break; |
635 case NM_STATE_ASLEEP: | 641 case NM_STATE_ASLEEP: |
636 case NM_STATE_CONNECTING: | 642 case NM_STATE_CONNECTING: |
637 case NM_STATE_DISCONNECTED: | 643 case NM_STATE_DISCONNECTED: |
638 if (prev != NM_STATE_CONNECTED) | 644 if (prev != NM_STATE_CONNECTED && prev != NM_STATE_UNKNOWN) |
639 break; | 645 break; |
640 if (ui_ops != NULL && ui_ops->network_disconnected != NULL) | 646 if (ui_ops != NULL && ui_ops->network_disconnected != NULL) |
641 ui_ops->network_disconnected(); | 647 ui_ops->network_disconnected(); |
642 prev = state; | |
643 break; | 648 break; |
644 case NM_STATE_UNKNOWN: | 649 case NM_STATE_UNKNOWN: |
645 default: | 650 default: |
646 break; | 651 break; |
647 } | 652 } |
662 | 667 |
663 if (!nm_proxy) | 668 if (!nm_proxy) |
664 return NM_STATE_UNKNOWN; | 669 return NM_STATE_UNKNOWN; |
665 | 670 |
666 if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) { | 671 if (!dbus_g_proxy_call(nm_proxy, "state", &err, G_TYPE_INVALID, G_TYPE_UINT, &state, G_TYPE_INVALID)) { |
667 /* XXX: Print an error? */ | |
668 g_error_free(err); | 672 g_error_free(err); |
669 return NM_STATE_UNKNOWN; | 673 return NM_STATE_UNKNOWN; |
670 } | 674 } |
671 | 675 |
672 return state; | 676 return state; |