1
# Copyright (C) 2009 Valmantas Paliksa <walmis at balticum-tv dot lt>
3
# Licensed under the GNU General Public License Version 3
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.
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.
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/>.
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
10
from gi.repository import GObject
14
from gi.repository import Gtk
15
from gi.repository import Pango
38
class MonitorBase(gobject.GObject):
22
class MonitorBase(GObject.GObject):
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,)),
44
28
def __init__(self, device, interface):
45
gobject.GObject.__init__(self)
29
GObject.GObject.__init__(self)
47
31
self.interface = interface
48
32
self.device = device
110
94
MonitorBase.__init__(self, device, interface)
111
95
self.poller = None
113
self.poller = gobject.timeout_add(5000, self.poll_stats)
97
self.poller = GObject.timeout_add(5000, self.poll_stats)
115
99
def __del__(self):
116
100
print("deleting monitor")
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")
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
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)
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
170
self.liststore = gtk.ListStore(str, str, str, object)
154
self.liststore = Gtk.ListStore(str, str, str, object)
172
156
self.e_ul = builder.get_object("e_ul")
173
157
self.e_dl = builder.get_object("e_dl")
220
204
if self.cb_device.get_active() == -1:
221
205
self.cb_device.set_active(0)
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"
281
265
self.update_time()
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?"))
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())
331
315
__author__ = "Walmis"
332
316
__autoload__ = False
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,)),
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,)),
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()
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")
351
335
item = create_menuitem(_("Network Usage"), get_icon("network-wireless", 16))
374
358
ls = rfcomm_list()
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)
381
365
self.monitor_interface(NMMonitor, device, path)