~ubuntu-branches/ubuntu/vivid/blueman/vivid-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-24 18:33:36 UTC
  • mfrom: (2.3.8 sid)
  • Revision ID: package-import@ubuntu.com-20141224183336-cyb82ot0y8tz8flq
Tags: 1.99~alpha1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE.
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers.
* debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
  - Dropped, no longer applicable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
 
#
3
 
# Licensed under the GNU General Public License Version 3
4
 
#
5
 
# This program is free software: you can redistribute it and/or modify
6
 
# it under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation, either version 3 of the License, or
8
 
# (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
1
from blueman.Functions import *
19
2
from blueman.Constants import *
20
3
from blueman.plugins.AppletPlugin import AppletPlugin
21
4
from blueman.main.Config import Config
22
5
from blueman.main.SignalTracker import SignalTracker
23
6
from blueman.bluez.Device import Device as BluezDevice
 
7
from blueman.bluez.Network import Network
24
8
from blueman.main.Device import Device
25
9
from blueman.Lib import rfcomm_list
26
 
import gobject
 
10
from gi.repository import GObject
27
11
import weakref
28
12
import os
29
13
import cgi
30
 
import gtk
31
 
import pango
 
14
from gi.repository import Gtk
 
15
from gi.repository import Pango
32
16
import dbus
33
17
import time
34
18
import datetime
35
19
import gettext
36
20
 
37
21
 
38
 
class MonitorBase(gobject.GObject):
 
22
class MonitorBase(GObject.GObject):
39
23
    __gsignals__ = {
40
 
    'disconnected': (gobject.SIGNAL_NO_HOOKS, gobject.TYPE_NONE, ()),
41
 
    'stats': (gobject.SIGNAL_NO_HOOKS, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,)),
 
24
    'disconnected': (GObject.SignalFlags.NO_HOOKS, None, ()),
 
25
    'stats': (GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,)),
42
26
    }
43
27
 
44
28
    def __init__(self, device, interface):
45
 
        gobject.GObject.__init__(self)
 
29
        GObject.GObject.__init__(self)
46
30
 
47
31
        self.interface = interface
48
32
        self.device = device
110
94
        MonitorBase.__init__(self, device, interface)
111
95
        self.poller = None
112
96
 
113
 
        self.poller = gobject.timeout_add(5000, self.poll_stats)
 
97
        self.poller = GObject.timeout_add(5000, self.poll_stats)
114
98
 
115
99
    def __del__(self):
116
100
        print("deleting monitor")
147
131
            return
148
132
        self.config = None
149
133
        self.parent = parent
150
 
        builder = gtk.Builder()
 
134
        builder = Gtk.Builder()
151
135
        builder.add_from_file(UI_PATH + "/net-usage.ui")
152
136
        builder.set_translation_domain("blueman")
153
137
 
154
138
        self.dialog = builder.get_object("dialog")
155
139
        self.dialog.connect("response", self.on_response)
156
 
        cr1 = gtk.CellRendererText()
157
 
        cr1.props.ellipsize = pango.ELLIPSIZE_END
 
140
        cr1 = Gtk.CellRendererText()
 
141
        cr1.props.ellipsize = Pango.EllipsizeMode.END
158
142
 
159
143
        self.devices = {}
160
144
        self.signals = SignalTracker()
163
147
        self.signals.Handle(parent, "monitor-removed", self.monitor_removed)
164
148
        self.signals.Handle(parent, "stats", self.on_stats)
165
149
 
166
 
        cr2 = gtk.CellRendererText()
 
150
        cr2 = Gtk.CellRendererText()
167
151
        cr2.props.sensitive = False
168
 
        cr2.props.style = pango.STYLE_ITALIC
 
152
        cr2.props.style = Pango.Style.ITALIC
169
153
 
170
 
        self.liststore = gtk.ListStore(str, str, str, object)
 
154
        self.liststore = Gtk.ListStore(str, str, str, object)
171
155
 
172
156
        self.e_ul = builder.get_object("e_ul")
173
157
        self.e_dl = builder.get_object("e_dl")
208
192
                if self.parent.Applet.Manager:
209
193
                    for a in self.parent.Applet.Manager.ListAdapters():
210
194
                        try:
211
 
                            device = a.FindDevice(d)
 
195
                            device = a.find_device(d)
212
196
                            device = Device(device)
213
197
                            name = self.get_caption(device.Alias, device.Address)
214
198
                        except:
220
204
            if self.cb_device.get_active() == -1:
221
205
                self.cb_device.set_active(0)
222
206
        else:
223
 
            d = gtk.MessageDialog(parent=self.dialog, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_INFO,
224
 
                                  buttons=gtk.BUTTONS_CLOSE, message_format=_(
 
207
            d = Gtk.MessageDialog(parent=self.dialog, flags=Gtk.DialogFlags.MODAL, type=Gtk.MessageType.INFO,
 
208
                                  buttons=Gtk.ButtonsType.CLOSE, message_format=_(
225
209
                    "No usage statistics are available yet. Try establishing a connection first and then check this page."))
226
210
            d.props.icon_name = "blueman"
227
211
            d.run()
281
265
        self.update_time()
282
266
 
283
267
    def on_reset(self, button):
284
 
        d = gtk.MessageDialog(parent=self.dialog, flags=gtk.DIALOG_MODAL, type=gtk.MESSAGE_QUESTION,
285
 
                              buttons=gtk.BUTTONS_YES_NO,
 
268
        d = Gtk.MessageDialog(parent=self.dialog, flags=Gtk.DialogFlags.MODAL, type=Gtk.MessageType.QUESTION,
 
269
                              buttons=Gtk.ButtonsType.YES_NO,
286
270
                              message_format=_("Are you sure you want to reset the counter?"))
287
271
        res = d.run()
288
272
        d.destroy()
289
 
        if res == gtk.RESPONSE_YES:
 
273
        if res == Gtk.ResponseType.YES:
290
274
            self.config.props.rx = "0"
291
275
            self.config.props.tx = "0"
292
276
            self.config.props.time = int(time.time())
323
307
                return
324
308
 
325
309
 
326
 
class NetUsage(AppletPlugin, gobject.GObject):
 
310
class NetUsage(AppletPlugin, GObject.GObject):
327
311
    __depends__ = ["Menu"]
328
312
    __icon__ = "network-wireless"
329
313
    __description__ = _(
331
315
    __author__ = "Walmis"
332
316
    __autoload__ = False
333
317
    __gsignals__ = {
334
 
    'monitor-added': (gobject.SIGNAL_NO_HOOKS, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
335
 
    'monitor-removed': (gobject.SIGNAL_NO_HOOKS, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
 
318
    'monitor-added': (GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_PYOBJECT,)),
 
319
    'monitor-removed': (GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_PYOBJECT,)),
336
320
    #monitor, tx, rx
337
321
    'stats': (
338
 
    gobject.SIGNAL_NO_HOOKS, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,)),
 
322
    GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT,)),
339
323
    }
340
324
 
341
325
    def on_load(self, applet):
342
 
        gobject.GObject.__init__(self)
 
326
        GObject.GObject.__init__(self)
343
327
        self.monitors = []
344
328
        self.devices = weakref.WeakValueDictionary()
345
329
        self.signals = SignalTracker()
346
330
 
347
331
        bus = self.bus = dbus.SystemBus()
348
 
        self.signals.Handle("dbus", bus, self.on_network_property_changed, "PropertyChanged", "org.bluez.Network",
 
332
        self.signals.Handle('bluez', Network(), self.on_network_property_changed, 'PropertyChanged',
349
333
                            path_keyword="path")
350
334
 
351
335
        item = create_menuitem(_("Network Usage"), get_icon("network-wireless", 16))
374
358
                ls = rfcomm_list()
375
359
                for dev in ls:
376
360
                    if dev["id"] == portid:
377
 
                        adapter = self.Applet.Manager.GetAdapter(dev["src"])
378
 
                        device = adapter.FindDevice(dev["dst"])
 
361
                        adapter = self.Applet.Manager.get_adapter(dev["src"])
 
362
                        device = adapter.find_device(dev["dst"])
379
363
                        device = Device(device)
380
364
 
381
365
                        self.monitor_interface(NMMonitor, device, path)
416
400
 
417
401
    def on_stats(self, monitor, tx, rx):
418
402
        self.emit("stats", monitor, tx, rx)
419
 
                
420
 
        
421
 
                        
422