~ubuntu-branches/ubuntu/wily/blueman/wily-proposed

« back to all changes in this revision

Viewing changes to blueman/plugins/applet/Networking.py

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-01-21 08:54:58 UTC
  • mfrom: (2.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140121085458-riy3j6wk9vfd599j
Tags: 1.23-git201312311147-1ubuntu1
* Merge from debian unstable. Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE
  - debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
    + Avoid crashing when receiving event for cards blueman shouldn't handle
  - debian/control: Don't depend on python-appindicator
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
 
# Copyright (C) 2008 Tadas Dailyda <tadas at dailyda dot com>
3
 
#
4
 
# Licensed under the GNU General Public License Version 3
5
 
#
6
 
# This program is free software: you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation, either version 3 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
19
1
from blueman.Functions import *
20
2
from blueman.main.Config import Config
21
3
from blueman.bluez.ServiceInterface import ServiceInterface
26
8
 
27
9
import dbus
28
10
 
 
11
 
29
12
class Networking(AppletPlugin):
30
 
        __icon__ = "network"
31
 
        __description__ = _("Manages local network services, like NAP bridges")
32
 
        __author__ = "Walmis"
33
 
        
34
 
        def on_load(self, applet):
35
 
                self.Applet = applet
36
 
                self.Signals = SignalTracker()
37
 
                
38
 
                self.Config = Config("network")
39
 
                self.Signals.Handle("gobject", self.Config, "property-changed", self.on_config_changed)
40
 
                
41
 
                self.load_nap_settings()
42
 
                
43
 
        def on_manager_state_changed(self, state):
44
 
                if state:
45
 
                        self.update_status()
46
 
                
47
 
        def load_nap_settings(self):
48
 
                dprint("Loading NAP settings")
49
 
                def reply():
50
 
                        pass
51
 
                def err(excp):
52
 
                        lines = str(excp).splitlines()
53
 
                        d = gtk.MessageDialog( None, buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR)
54
 
                        d.props.text = _("Failed to apply network settings")
55
 
                        d.props.secondary_text = lines[-1] + "\n\n"+_("You might not be able to connect to the Bluetooth network via this machine")
56
 
                        d.run()
57
 
                        d.destroy()
58
 
                
59
 
                m = Mechanism()
60
 
                m.ReloadNetwork(reply_handler=reply, error_handler=err)
61
 
                
62
 
        def on_unload(self):
63
 
                self.Signals.DisconnectAll()
64
 
                
65
 
        def on_adapter_added(self, path):
66
 
                self.update_status()
67
 
                
68
 
        def update_status(self):
69
 
                self.set_nap(self.Config.props.nap_enable or False)
70
 
                self.set_gn(self.Config.props.gn_enable or False)               
71
 
 
72
 
 
73
 
        def on_config_changed(self, config, key, value):
74
 
                if key == "nap_enable":
75
 
                        self.set_nap(value)
76
 
                elif key == "gn_enable":
77
 
                        self.set_gn(value)
78
 
                
79
 
                
80
 
        def set_nap(self, on):
81
 
                dprint("set nap", on)
82
 
                if self.Applet.Manager != None:
83
 
                        adapters = self.Applet.Manager.ListAdapters()
84
 
                        for adapter in adapters:
85
 
                                s = ServiceInterface("org.bluez.NetworkServer", adapter.GetObjectPath(), ["Register", "Unregister"])
86
 
                                if on:
87
 
                                        s.Register("nap", "pan1")
88
 
                                else:
89
 
                                        s.Unregister("nap")
90
 
 
91
 
                                
92
 
        def set_gn(self, on):
93
 
                #latest bluez does not support gn
94
 
                pass
95
 
#               dprint("set gn", on)
96
 
#               m = Mechanism()
97
 
#               m.SetGN(on, reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
98
 
#
99
 
#               if self.Applet.Manager != None:
100
 
#                       adapters = self.Applet.Manager.ListAdapters()
101
 
#                       for adapter in adapters:
102
 
#                               s = ServiceInterface("org.bluez.NetworkServer", adapter.GetObjectPath(), ["Register", "Unregister"])
103
 
#                               if on:
104
 
#                                       s.Register("gn", "pan0")
105
 
#                               else:
106
 
#                                       s.Unregister("gn")
 
13
    __icon__ = "network"
 
14
    __description__ = _("Manages local network services, like NAP bridges")
 
15
    __author__ = "Walmis"
 
16
 
 
17
    def on_load(self, applet):
 
18
        self.Applet = applet
 
19
        self.Signals = SignalTracker()
 
20
 
 
21
        self.Config = Config("network")
 
22
        self.Signals.Handle("gobject", self.Config, "property-changed", self.on_config_changed)
 
23
 
 
24
        self.load_nap_settings()
 
25
 
 
26
    def on_manager_state_changed(self, state):
 
27
        if state:
 
28
            self.update_status()
 
29
 
 
30
    def load_nap_settings(self):
 
31
        dprint("Loading NAP settings")
 
32
 
 
33
        def reply():
 
34
            pass
 
35
 
 
36
        def err(excp):
 
37
            lines = str(excp).splitlines()
 
38
            d = gtk.MessageDialog(None, buttons=gtk.BUTTONS_OK, type=gtk.MESSAGE_ERROR)
 
39
            d.props.text = _("Failed to apply network settings")
 
40
            d.props.secondary_text = lines[-1] + "\n\n" + _(
 
41
                "You might not be able to connect to the Bluetooth network via this machine")
 
42
            d.run()
 
43
            d.destroy()
 
44
 
 
45
        m = Mechanism()
 
46
        m.ReloadNetwork(reply_handler=reply, error_handler=err)
 
47
 
 
48
    def on_unload(self):
 
49
        self.Signals.DisconnectAll()
 
50
 
 
51
    def on_adapter_added(self, path):
 
52
        self.update_status()
 
53
 
 
54
    def update_status(self):
 
55
        self.set_nap(self.Config.props.nap_enable or False)
 
56
 
 
57
 
 
58
    def on_config_changed(self, config, key, value):
 
59
        if key == "nap_enable":
 
60
            self.set_nap(value)
 
61
 
 
62
 
 
63
    def set_nap(self, on):
 
64
        dprint("set nap", on)
 
65
        if self.Applet.Manager != None:
 
66
            adapters = self.Applet.Manager.ListAdapters()
 
67
            for adapter in adapters:
 
68
                s = ServiceInterface("org.bluez.NetworkServer", adapter.GetObjectPath(), ["Register", "Unregister"])
 
69
                if on:
 
70
                    s.Register("nap", "pan1")
 
71
                else:
 
72
                    s.Unregister("nap")