~renatofilho/indicator-server/device-switch

« back to all changes in this revision

Viewing changes to network/network-menu.vala

  • Committer: Olivier Tilloy
  • Author(s): Alberto Ruiz
  • Date: 2012-11-01 09:40:17 UTC
  • mfrom: (212.2.22 trunk)
  • Revision ID: olivier.tilloy@canonical.com-20121101094017-7l2vr330i0q1388o
Fix some memory leaks issues on device removal/addition.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
        internal class WifiMenu
10
10
        {
11
 
                private Menu              gmenu;
12
 
                private Menu              apsmenu;
13
 
                private MenuItem          device_item;
14
 
                internal DeviceWifi       device;
15
 
                private Application       app;
16
 
                private NM.Client         client;
 
11
                private  Menu        gmenu;
 
12
                private  Menu        apsmenu;
 
13
                private  MenuItem    device_item;
 
14
                public   DeviceWifi  device;
 
15
                private  Application app;
 
16
                private  NM.Client   client;
17
17
 
18
18
                public WifiMenu (NM.Client client, DeviceWifi device, Menu global_menu, Application app)
19
19
                {
28
28
                        device_item.set_section (apsmenu);
29
29
                        gmenu.append_item (device_item);
30
30
 
 
31
                        device.access_point_added.connect (access_point_added_cb);
 
32
                        device.access_point_removed.connect (access_point_removed_cb);
 
33
                        device.notify.connect (active_access_point_changed);
 
34
 
31
35
                        var aps = device.get_access_points ();
 
36
 
 
37
                        if (aps == null)
 
38
                                return;
 
39
 
32
40
                        for (uint i = 0; i<aps.length; i++)
33
41
                        {
34
42
                                insert_ap (aps.get (i));
35
43
                        }
36
 
 
37
 
                        device.access_point_added.connect (access_point_added_cb);
38
 
                        device.access_point_removed.connect (access_point_removed_cb);
39
 
                        device.notify.connect (active_access_point_changed);
40
44
                }
41
45
 
42
46
                ~WifiMenu ()
128
132
                        }
129
133
 
130
134
                        var conns = rs.list_connections ();
131
 
                        if (conns.length() > 0)
 
135
                        if (conns.length () > 0)
132
136
                        {
133
137
                                dev_conns = device.filter_connections (conns);
134
 
                                if (dev_conns.length() > 0)
 
138
                                if (dev_conns.length () > 0)
135
139
                                        has_connection = ap_has_connections (ap, dev_conns);
136
140
                        }
137
141
 
214
218
 
215
219
                private static bool ap_has_connections (AccessPoint ap, SList<NM.Connection>? dev_conns)
216
220
                {
217
 
                        if (dev_conns.length() < 1)
 
221
                        if (dev_conns.length () < 1)
218
222
                                return false;
219
223
 
220
224
                        var ap_conns = ap.filter_connections (dev_conns);
221
 
                        return ap_conns.length() > 0;
 
225
                        return ap_conns.length () > 0;
222
226
                }
223
227
 
224
228
                private void remove_ap (AccessPoint ap)
255
259
 
256
260
        public class NetworkMenu : Application
257
261
        {
258
 
                private Menu gmenu;
259
 
                private NM.Client client;
260
 
                private ActionManager am;
 
262
                private Menu                gmenu;
 
263
                private NM.Client           client;
 
264
                private ActionManager       am;
 
265
                private List<WifiMenu>      devices;
261
266
 
262
267
                public NetworkMenu ()
263
268
                {
324
329
                private void add_wifi_device (NM.DeviceWifi device)
325
330
                {
326
331
                        //FIXME: Get rid of wifimenu on device removal
327
 
                        WifiMenu* menu = new WifiMenu (client, device, gmenu, this);
 
332
                        for (int i = 0; i < gmenu.get_n_items (); i++)
 
333
                        {
 
334
                                string path;
 
335
 
 
336
                                if (!gmenu.get_item_attribute (i, "x-canonical-wifi-device-path", "s", out path))
 
337
                                        continue;
 
338
                                if (path == device.get_path ())
 
339
                                        return;
 
340
                        }
 
341
 
 
342
                        devices.append (new WifiMenu (client, device, gmenu, this));
328
343
                }
329
344
 
330
345
                private void remove_wifi_device (NM.DeviceWifi device)
331
346
                {
 
347
                        //TODO: Move this code to WifiMenu
 
348
                        if (device == null)
 
349
                                return;
 
350
 
332
351
                        for (int i = 0; i < gmenu.get_n_items (); i++)
333
352
                        {
334
353
                                string path;
341
360
                                gmenu.remove (i);
342
361
                                return;
343
362
                        }
 
363
 
 
364
                        for (uint i = 0; i < devices.length (); i++)
 
365
                        {
 
366
                                var wifimenu = devices.nth_data (i);
 
367
                                if (wifimenu        != null &&
 
368
                                        wifimenu.device != null &&
 
369
                                        wifimenu.device.get_path () == device.get_path ())
 
370
                                {
 
371
                                        devices.remove (wifimenu);
 
372
                                }
 
373
                        }
344
374
                }
345
375
 
346
376
                private void device_state_changed (NM.Device  device,