~ubuntu-branches/ubuntu/precise/network-manager-applet/precise

« back to all changes in this revision

Viewing changes to src/applet.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-03-29 14:19:26 UTC
  • mfrom: (1.2.28)
  • Revision ID: package-import@ubuntu.com-20120329141926-kjj8xb306nh6yuhj
Tags: 0.9.4.1-0ubuntu1
* New upstream release 0.9.4.1.
  - Bugfix release.
  - mobile: fix some memory leaks
  - applet: don't call nm_secret_agent_register() when the agent is registered
  - applet: fix an uninitialized variable
  - applet: track GNOME Shell version, not just whether it's running
  - Add NotShowIn=KDE to .desktop files (bgo #660046)
  - applet: fix pixbuf leak when mobile broadband is connected (lp:939802)
* debian/control: bump Build-Depends and Depends for libnm-*-dev and the
  network-manager(-dev) packages to 0.9.4.
* debian/control: drop unused Build-Depends on libpolkit-gobject-1-dev.
* debian/patches/04-autostart.patch: dropped, applied upstream.
* debian/patches/lp939802_fix_mobile_icon_leak.patch: dropped, applied
  upstream.
* debian/patches/lp289466_always_show_tray_icon.patch: refreshed.
* debian/patches/nm-applet-use-indicator.patch: refreshed and cleaned up.
* debian/patches/revert_git_policy_error_dialog_ba8381a.patch: revert commit
  ba8381a: don't show an error dialog when connection creation, disconnects,
  or activations fail; we already have a warning message.
* debian/patches/lp341684_device_sensitive_disconnect_notify.patch: drop the
  notification urgency back to NORMAL from CRITICAL for offline notifications
  since they otherwise "stick around" in Gnome Shell. (LP: #883443)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <glib/gi18n.h>
39
39
#include <unistd.h>
40
40
#include <sys/socket.h>
 
41
#include <stdlib.h>
41
42
 
 
43
#include <gio/gio.h>
42
44
#include <dbus/dbus-glib.h>
43
45
#include <dbus/dbus-glib-lowlevel.h>
44
46
 
498
500
                     gpointer user_data)
499
501
{
500
502
        NMApplet *applet = NM_APPLET (user_data);
 
503
 
501
504
        if (error)
502
505
                g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
503
506
 
536
539
static void
537
540
disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
538
541
{
 
542
        NMApplet *applet = NM_APPLET (user_data);
 
543
 
539
544
        if (error) {
540
545
                g_warning ("%s: device disconnect failed: (%d) %s",
541
546
                           __func__,
542
547
                           error ? error->code : -1,
543
548
                           error && error->message ? error->message : "(unknown)");
544
549
        }
 
550
 
 
551
        applet_schedule_update_icon (applet);
 
552
        applet_schedule_update_menu (applet);
545
553
}
546
554
 
547
555
void
550
558
{
551
559
        g_return_if_fail (NM_IS_DEVICE (device));
552
560
 
553
 
        nm_device_disconnect (device, disconnect_cb, NULL);
 
561
        nm_device_disconnect (device, disconnect_cb, applet);
554
562
}
555
563
 
556
564
static void
559
567
                        GError *error,
560
568
                        gpointer user_data)
561
569
{
562
 
        NMApplet *applet = NM_APPLET (user_data);
563
 
 
564
570
        if (error)
565
571
                g_warning ("Connection activation failed: %s", error->message);
566
572
 
567
 
        applet_schedule_update_icon (applet);
568
 
        applet_schedule_update_menu (applet);
 
573
        applet_schedule_update_icon (NM_APPLET (user_data));
569
574
}
570
575
 
571
576
void
1262
1267
//      nmi_dbus_signal_user_interface_activated (applet->connection);
1263
1268
}
1264
1269
 
 
1270
 
1265
1271
/*
1266
1272
 * nma_menu_configure_vpn_item_activate
1267
1273
 *
1822
1828
        nm_client_networking_set_enabled (applet->nm_client, state);
1823
1829
}
1824
1830
 
 
1831
 
1825
1832
#ifndef ENABLE_INDICATOR
1826
1833
static void
1827
1834
nma_set_notifications_enabled_cb (GtkWidget *widget, NMApplet *applet)
2380
2387
                if (!info->title)
2381
2388
                        info->title = g_strdup (_("Network"));
2382
2389
                if (info->state == NM_STATE_DISCONNECTED || info->state == NM_STATE_ASLEEP) {
2383
 
                        info->urgency = NOTIFY_URGENCY_CRITICAL;
2384
2390
                        info->text = _("Disconnected - you are now offline");
2385
2391
                } else
2386
2392
                        info->text = _("Disconnected");
2834
2840
                NMConnection *connection;
2835
2841
 
2836
2842
                connection = applet_find_active_connection_for_device (device, applet, NULL);
 
2843
                /* device class returns a referenced pixbuf */
2837
2844
                dclass->get_icon (device, state, connection, out_pixbuf, out_indicator_icon, out_tip, applet);
2838
2845
                if (out_tip && !*out_tip)
2839
2846
                        *out_tip = get_tip_for_device_state (device, state, connection);
2900
2907
        NMVPNConnectionState vpn_state = NM_VPN_SERVICE_STATE_UNKNOWN;
2901
2908
        gboolean nm_running;
2902
2909
        NMActiveConnection *active_vpn = NULL;
2903
 
        int i;
2904
2910
 
2905
2911
        applet->update_icon_id = 0;
2906
2912
 
2931
2937
        case NM_STATE_ASLEEP:
2932
2938
                icon_name = g_strdup ("nm-no-connection");
2933
2939
                pixbuf = nma_icon_check_and_load (icon_name, &applet->no_connection_icon, applet);
2934
 
                if (pixbuf)
2935
 
                        g_object_ref (pixbuf);
 
2940
                g_object_ref (pixbuf);
2936
2941
                dev_tip = g_strdup (_("Networking disabled"));
2937
2942
                break;
2938
2943
        case NM_STATE_DISCONNECTED:
2939
2944
                icon_name = g_strdup ("nm-no-connection");
2940
2945
                pixbuf = nma_icon_check_and_load (icon_name, &applet->no_connection_icon, applet);
2941
 
                if (pixbuf)
2942
 
                        g_object_ref (pixbuf);
 
2946
                g_object_ref (pixbuf);
2943
2947
                dev_tip = g_strdup (_("No network connection"));
2944
2948
                break;
2945
2949
        default:
2948
2952
        }
2949
2953
 
2950
2954
        foo_set_icon (applet, ICON_LAYER_LINK, pixbuf, icon_name, dev_tip);
2951
 
 
2952
2955
        if (pixbuf)
2953
2956
                g_object_unref (pixbuf);
2954
 
 
2955
2957
        if (icon_name)
2956
2958
                g_free (icon_name);
2957
2959
 
2960
2962
        icon_name = NULL;
2961
2963
        active_vpn = applet_get_first_active_vpn_connection (applet, &vpn_state);
2962
2964
        if (active_vpn) {
2963
 
                vpn_tip = get_tip_for_vpn (active_vpn, vpn_state, applet);
 
2965
                int i;
2964
2966
 
2965
2967
                switch (vpn_state) {
2966
2968
                case NM_VPN_CONNECTION_STATE_ACTIVATED:
2968
2970
                        icon_name = g_strdup_printf ("nm-vpn-active-lock");
2969
2971
#else
2970
2972
                        icon_name = g_strdup_printf ("%s-secure", app_indicator_get_icon (applet->app_indicator));
2971
 
#endif
 
2973
#endif /* ENABLE_INDICATOR */
2972
2974
                        pixbuf = nma_icon_check_and_load (icon_name, &applet->vpn_lock_icon, applet);
2973
2975
                        break;
2974
2976
                case NM_VPN_CONNECTION_STATE_PREPARE:
2975
2977
                case NM_VPN_CONNECTION_STATE_NEED_AUTH:
2976
2978
                case NM_VPN_CONNECTION_STATE_CONNECT:
2977
2979
                case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
2978
 
                        for (i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++) {
2979
 
                                icon_name = g_strdup_printf ("nm-vpn-connecting%02d", i+1);
2980
 
                                nma_icon_check_and_load (icon_name, &applet->vpn_connecting_icons[i], applet);
2981
 
                                g_free (icon_name);
2982
 
                        }
2983
 
 
2984
 
                        pixbuf = applet->vpn_connecting_icons[applet->animation_step];
2985
 
                        applet->animation_step++;
2986
 
                        if (applet->animation_step >= NUM_VPN_CONNECTING_FRAMES)
2987
 
                                applet->animation_step = 0;
2988
 
 
 
2980
                        for (i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++) {
 
2981
                                char *name;
 
2982
 
 
2983
                                name = g_strdup_printf ("nm-vpn-connecting%02d", i+1);
 
2984
                                nma_icon_check_and_load (name, &applet->vpn_connecting_icons[i], applet);
 
2985
                                g_free (name);
 
2986
                        }
 
2987
 
 
2988
                        pixbuf = applet->vpn_connecting_icons[applet->animation_step];
2989
2989
#ifdef ENABLE_INDICATOR
2990
 
                        icon_name = g_strdup_printf ("nm-vpn-connecting%02d", applet->animation_step+1);
 
2990
                        icon_name = g_strdup_printf ("nm-vpn-connecting%02d", applet->animation_step+1);
2991
2991
#endif
 
2992
                        applet->animation_step++;
 
2993
                        if (applet->animation_step >= NUM_VPN_CONNECTING_FRAMES)
 
2994
                                applet->animation_step = 0;
2992
2995
                        break;
2993
2996
                default:
2994
2997
                        break;
2995
2998
                }
 
2999
 
 
3000
                vpn_tip = get_tip_for_vpn (active_vpn, vpn_state, applet);
2996
3001
        }
2997
 
 
2998
3002
        foo_set_icon (applet, ICON_LAYER_VPN, pixbuf, icon_name, vpn_tip);
2999
 
 
3000
3003
        if (icon_name)
3001
3004
                g_free (icon_name);
3002
3005
 
3244
3247
        }
3245
3248
}
3246
3249
 
 
3250
static void
 
3251
applet_agent_registered_cb (AppletAgent *agent,
 
3252
                            GParamSpec *pspec,
 
3253
                            gpointer user_data)
 
3254
{
 
3255
        NMApplet *applet = NM_APPLET (user_data);
 
3256
 
 
3257
        /* If the shell is running and the agent just got registered, unregister it */
 
3258
        if (   (applet->shell_version >= 3.4)
 
3259
            && nm_secret_agent_get_registered (NM_SECRET_AGENT (agent))) {
 
3260
                g_message ("Stopping registered applet secret agent because GNOME Shell is running");
 
3261
                nm_secret_agent_unregister (NM_SECRET_AGENT (agent));
 
3262
        }
 
3263
}
 
3264
 
3247
3265
/*****************************************************************************/
3248
3266
 
3249
3267
static void
3608
3626
                   embedded ? "embedded in" : "removed from");
3609
3627
}
3610
3628
 
 
3629
#if GLIB_CHECK_VERSION(2,26,0)
 
3630
static gboolean
 
3631
delayed_start_agent (gpointer user_data)
 
3632
{
 
3633
        NMApplet *applet = user_data;
 
3634
 
 
3635
        applet->agent_start_id = 0;
 
3636
 
 
3637
        g_assert (applet->agent);
 
3638
 
 
3639
        /* If the agent is already running, there's nothing to do. */
 
3640
        if (nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent)) == TRUE)
 
3641
                return FALSE;
 
3642
 
 
3643
        if (nm_secret_agent_register (NM_SECRET_AGENT (applet->agent)))
 
3644
                g_message ("Starting applet secret agent because GNOME Shell disappeared");
 
3645
        else
 
3646
                g_warning ("Failed to start applet secret agent!");
 
3647
        return FALSE;
 
3648
}
 
3649
 
 
3650
static gboolean
 
3651
get_shell_version (GDBusProxy *proxy, gdouble *out_version)
 
3652
{
 
3653
        GVariant *v;
 
3654
        char *version, *p;
 
3655
        gboolean success = FALSE;
 
3656
        gdouble converted;
 
3657
 
 
3658
        /* Ask for the shell's version */
 
3659
        v = g_dbus_proxy_get_cached_property (proxy, "ShellVersion");
 
3660
        if (v) {
 
3661
                g_warn_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING));
 
3662
                version = g_variant_dup_string (v, NULL);
 
3663
                if (version) {
 
3664
                        /* Terminate at the second dot if there is one */
 
3665
                        p = strchr (version, '.');
 
3666
                        if (p && (p = strchr (p + 1, '.')))
 
3667
                                *p = '\0';
 
3668
 
 
3669
                        converted = strtod (version, NULL);
 
3670
                        g_warn_if_fail (converted > 0);
 
3671
                        g_warn_if_fail (converted < 1000);
 
3672
                        if (converted > 0 && converted < 1000) {
 
3673
                                *out_version = converted;
 
3674
                                success = TRUE;
 
3675
                        }
 
3676
                        g_free (version);
 
3677
                }
 
3678
                g_variant_unref (v);
 
3679
        }
 
3680
        return success;
 
3681
}
 
3682
 
 
3683
static void
 
3684
name_owner_changed_cb (GDBusProxy *proxy, GParamSpec *pspec, gpointer user_data)
 
3685
{
 
3686
        NMApplet *applet = user_data;
 
3687
        char *owner;
 
3688
 
 
3689
        owner = g_dbus_proxy_get_name_owner (proxy);
 
3690
        if (owner) {
 
3691
                applet->shell_version = 0;
 
3692
                if (applet->agent_start_id)
 
3693
                        g_source_remove (applet->agent_start_id);
 
3694
 
 
3695
                if (   get_shell_version (proxy, &applet->shell_version)
 
3696
                    && applet->shell_version >= 3.4
 
3697
                    && applet->agent
 
3698
                    && nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent))) {
 
3699
                        g_message ("Stopping applet secret agent because GNOME Shell appeared");
 
3700
                        nm_secret_agent_unregister (NM_SECRET_AGENT (applet->agent));
 
3701
                }
 
3702
        } else {
 
3703
                /* If the shell quit and our agent wasn't already registered, do it
 
3704
                 * now on a delay (just in case the shell is restarting.
 
3705
                 */
 
3706
                applet->shell_version = 0;
 
3707
                if (applet->agent_start_id)
 
3708
                        g_source_remove (applet->agent_start_id);
 
3709
 
 
3710
                if (nm_secret_agent_get_registered (NM_SECRET_AGENT (applet->agent)) == FALSE)
 
3711
                        applet->agent_start_id = g_timeout_add_seconds (4, delayed_start_agent, applet);
 
3712
        }
 
3713
        g_free (owner);
 
3714
}
 
3715
#endif
 
3716
 
3611
3717
static gboolean
3612
3718
dbus_setup (NMApplet *applet, GError **error)
3613
3719
{
3771
3877
                          G_CALLBACK (applet_agent_get_secrets_cb), applet);
3772
3878
        g_signal_connect (applet->agent, APPLET_AGENT_CANCEL_SECRETS,
3773
3879
                          G_CALLBACK (applet_agent_cancel_secrets_cb), applet);
 
3880
        g_signal_connect (applet->agent, "notify::" NM_SECRET_AGENT_REGISTERED,
 
3881
                          G_CALLBACK (applet_agent_registered_cb), applet);
3774
3882
 
3775
3883
        /* Initialize device classes */
3776
3884
        applet->wired_class = applet_device_wired_get_class (applet);
3798
3906
                          G_CALLBACK (applet_embedded_cb), NULL);
3799
3907
        applet_embedded_cb (G_OBJECT (applet->status_icon), NULL, NULL);
3800
3908
 
 
3909
#if GLIB_CHECK_VERSION(2,26,0)
 
3910
        /* Watch GNOME Shell so we can unregister our applet agent if it appears */
 
3911
        applet->shell_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
 
3912
                                                             G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
 
3913
                                                             NULL,
 
3914
                                                             "org.gnome.Shell",
 
3915
                                                             "/org/gnome/Shell",
 
3916
                                                             "org.gnome.Shell",
 
3917
                                                             NULL,
 
3918
                                                             NULL);
 
3919
        g_signal_connect (applet->shell_proxy,
 
3920
                          "notify::g-name-owner",
 
3921
                          G_CALLBACK (name_owner_changed_cb),
 
3922
                          applet);
 
3923
        name_owner_changed_cb (applet->shell_proxy, NULL, applet);
 
3924
#endif
 
3925
 
3801
3926
        return G_OBJECT (applet);
3802
3927
 
3803
3928
error:
3874
3999
        if (applet->session_bus)
3875
4000
                dbus_g_connection_unref (applet->session_bus);
3876
4001
 
 
4002
#if GLIB_CHECK_VERSION(2,26,0)
 
4003
        if (applet->shell_proxy)
 
4004
                g_object_unref (applet->shell_proxy);
 
4005
#endif
 
4006
        if (applet->agent_start_id)
 
4007
                g_source_remove (applet->agent_start_id);
 
4008
 
3877
4009
        G_OBJECT_CLASS (nma_parent_class)->finalize (object);
3878
4010
}
3879
4011