2007-06-24 14:45:05 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2006-10-15 01:24:45 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-08-29 11:48:20 +02:00
|
|
|
import random
|
2007-11-04 15:07:15 +01:00
|
|
|
from gettext import gettext as _
|
|
|
|
import logging
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2006-10-03 16:31:32 +02:00
|
|
|
import hippo
|
2006-10-06 11:11:38 +02:00
|
|
|
import gobject
|
2007-09-09 06:02:26 +02:00
|
|
|
import gtk
|
2006-08-29 11:48:20 +02:00
|
|
|
|
2007-08-25 13:15:28 +02:00
|
|
|
from sugar.graphics.icon import CanvasIcon
|
2007-07-31 14:05:14 +02:00
|
|
|
from sugar.graphics import style
|
2007-08-25 13:15:28 +02:00
|
|
|
from sugar.graphics.icon import get_icon_state
|
2007-07-31 16:46:06 +02:00
|
|
|
from sugar.graphics import style
|
2007-09-09 06:02:26 +02:00
|
|
|
from sugar.graphics import palette
|
2007-11-04 15:07:15 +01:00
|
|
|
from sugar.graphics import iconentry
|
2007-11-20 15:41:44 +01:00
|
|
|
from sugar.graphics.menuitem import MenuItem
|
2007-07-05 11:22:09 +02:00
|
|
|
from sugar import profile
|
|
|
|
|
2007-02-26 12:23:00 +01:00
|
|
|
from model import accesspointmodel
|
2007-03-29 16:10:34 +02:00
|
|
|
from model.devices.network import mesh
|
2007-09-09 06:02:26 +02:00
|
|
|
from model.devices.network import wireless
|
2007-02-25 12:17:45 +01:00
|
|
|
from hardware import hardwaremanager
|
2007-03-29 16:10:34 +02:00
|
|
|
from hardware import nmclient
|
2006-09-25 16:01:11 +02:00
|
|
|
from view.BuddyIcon import BuddyIcon
|
2007-02-28 16:19:01 +01:00
|
|
|
from view.pulsingicon import PulsingIcon
|
2007-07-05 11:22:09 +02:00
|
|
|
from view.home.snowflakelayout import SnowflakeLayout
|
2007-11-04 15:07:15 +01:00
|
|
|
from view.home.spreadlayout import SpreadLayout
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2007-08-30 08:40:26 +02:00
|
|
|
from hardware.nmclient import NM_802_11_CAP_PROTO_WEP, NM_802_11_CAP_PROTO_WPA, NM_802_11_CAP_PROTO_WPA2
|
|
|
|
|
|
|
|
|
2007-08-16 12:58:40 +02:00
|
|
|
_ICON_NAME = 'network-wireless'
|
2007-02-26 12:23:00 +01:00
|
|
|
|
2007-02-28 16:19:01 +01:00
|
|
|
class AccessPointView(PulsingIcon):
|
2007-09-09 06:02:26 +02:00
|
|
|
def __init__(self, model, mesh_device=None):
|
2007-09-12 18:01:21 +02:00
|
|
|
PulsingIcon.__init__(self, size=style.STANDARD_ICON_SIZE, cache=True)
|
2007-02-25 12:17:45 +01:00
|
|
|
self._model = model
|
2007-09-09 06:02:26 +02:00
|
|
|
self._meshdev = mesh_device
|
|
|
|
self._disconnect_item = None
|
2007-11-04 15:07:15 +01:00
|
|
|
self._greyed_out = False
|
2007-02-25 12:17:45 +01:00
|
|
|
|
|
|
|
self.connect('activated', self._activate_cb)
|
2007-02-25 15:05:56 +01:00
|
|
|
|
|
|
|
model.connect('notify::strength', self._strength_changed_cb)
|
2007-02-25 17:34:15 +01:00
|
|
|
model.connect('notify::name', self._name_changed_cb)
|
2007-02-26 13:20:36 +01:00
|
|
|
model.connect('notify::state', self._state_changed_cb)
|
2007-02-25 15:05:56 +01:00
|
|
|
|
2007-08-30 08:01:12 +02:00
|
|
|
(stroke, fill) = model.get_nm_network().get_colors()
|
|
|
|
self._device_stroke = stroke
|
|
|
|
self._device_fill = fill
|
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
self._palette = self._create_palette()
|
|
|
|
self.set_palette(self._palette)
|
|
|
|
|
2007-02-25 15:05:56 +01:00
|
|
|
self._update_icon()
|
2007-02-25 17:34:15 +01:00
|
|
|
self._update_name()
|
2007-02-26 12:23:00 +01:00
|
|
|
self._update_state()
|
2007-02-25 15:05:56 +01:00
|
|
|
|
2007-08-30 08:40:26 +02:00
|
|
|
# Update badge
|
|
|
|
caps = model.props.capabilities
|
|
|
|
if model.get_nm_network().is_favorite():
|
2007-12-17 11:29:49 +01:00
|
|
|
self.props.badge_name = "emblem-favorite"
|
2007-08-30 08:40:26 +02:00
|
|
|
elif (caps & NM_802_11_CAP_PROTO_WEP) or (caps & NM_802_11_CAP_PROTO_WPA) or (caps & NM_802_11_CAP_PROTO_WPA2):
|
2007-10-19 20:30:09 +02:00
|
|
|
self.props.badge_name = "emblem-locked"
|
2007-08-30 08:40:26 +02:00
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
def _create_palette(self):
|
|
|
|
p = palette.Palette(self._model.props.name, menu_after_content=True)
|
|
|
|
if not self._meshdev:
|
|
|
|
return p
|
|
|
|
|
|
|
|
# Only show disconnect when there's a mesh device, because mesh takes
|
|
|
|
# priority over the normal wireless device. NM doesn't have a "disconnect"
|
|
|
|
# method for a device either (for various reasons) so this doesn't
|
|
|
|
# have a good mapping
|
|
|
|
self._disconnect_item = gtk.MenuItem(_('Disconnect...'))
|
|
|
|
self._disconnect_item.connect('activate', self._disconnect_activate_cb)
|
|
|
|
p.menu.append(self._disconnect_item)
|
|
|
|
if self._model.props.state == accesspointmodel.STATE_CONNECTED:
|
|
|
|
self._disconnect_item.show()
|
|
|
|
return p
|
|
|
|
|
|
|
|
def _disconnect_activate_cb(self, menuitem):
|
|
|
|
# Disconnection for an AP means activating the default mesh device
|
|
|
|
network_manager = hardwaremanager.get_network_manager()
|
|
|
|
if network_manager and self._meshdev:
|
|
|
|
network_manager.set_active_device(self._meshdev)
|
|
|
|
|
2007-02-25 15:05:56 +01:00
|
|
|
def _strength_changed_cb(self, model, pspec):
|
2007-02-25 11:39:35 +01:00
|
|
|
self._update_icon()
|
|
|
|
|
2007-02-25 17:34:15 +01:00
|
|
|
def _name_changed_cb(self, model, pspec):
|
|
|
|
self._update_name()
|
|
|
|
|
2007-02-26 12:23:00 +01:00
|
|
|
def _state_changed_cb(self, model, pspec):
|
|
|
|
self._update_state()
|
|
|
|
|
2007-02-25 12:17:45 +01:00
|
|
|
def _activate_cb(self, icon):
|
|
|
|
network_manager = hardwaremanager.get_network_manager()
|
2007-02-26 14:42:39 +01:00
|
|
|
if network_manager:
|
|
|
|
device = self._model.get_nm_device()
|
|
|
|
network = self._model.get_nm_network()
|
|
|
|
network_manager.set_active_device(device, network)
|
2007-02-25 12:17:45 +01:00
|
|
|
|
2007-02-25 17:34:15 +01:00
|
|
|
def _update_name(self):
|
2007-09-09 06:02:26 +02:00
|
|
|
self._palette.set_primary_text(self._model.props.name)
|
2007-02-25 17:34:15 +01:00
|
|
|
|
2007-02-25 11:39:35 +01:00
|
|
|
def _update_icon(self):
|
2007-08-25 13:15:28 +02:00
|
|
|
icon_name = get_icon_state(_ICON_NAME, self._model.props.strength)
|
2007-02-28 15:42:41 +01:00
|
|
|
if icon_name:
|
2007-08-30 08:40:26 +02:00
|
|
|
self.props.icon_name = icon_name
|
2007-02-26 12:23:00 +01:00
|
|
|
|
|
|
|
def _update_state(self):
|
|
|
|
if self._model.props.state == accesspointmodel.STATE_CONNECTING:
|
2007-09-09 06:02:26 +02:00
|
|
|
if self._disconnect_item:
|
|
|
|
self._disconnect_item.hide()
|
2007-03-30 01:40:05 +02:00
|
|
|
self.props.pulse_time = 1.0
|
2007-03-29 17:25:47 +02:00
|
|
|
self.props.colors = [
|
2007-08-26 14:16:09 +02:00
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
|
|
|
style.Color(self._device_fill).get_svg() ],
|
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
|
|
|
'#e2e2e2' ]
|
2007-03-29 17:25:47 +02:00
|
|
|
]
|
2007-02-26 12:23:00 +01:00
|
|
|
elif self._model.props.state == accesspointmodel.STATE_CONNECTED:
|
2007-09-09 06:02:26 +02:00
|
|
|
if self._disconnect_item:
|
|
|
|
self._disconnect_item.show()
|
2007-10-04 22:46:14 +02:00
|
|
|
self.props.pulse_time = 0.0
|
2007-03-29 17:25:47 +02:00
|
|
|
self.props.colors = [
|
2007-10-04 22:46:14 +02:00
|
|
|
[ '#ffffff',
|
2007-08-26 14:16:09 +02:00
|
|
|
style.Color(self._device_fill).get_svg() ],
|
|
|
|
[ '#ffffff',
|
|
|
|
style.Color(self._device_fill).get_svg() ]
|
2007-03-29 17:25:47 +02:00
|
|
|
]
|
2007-02-26 12:23:00 +01:00
|
|
|
elif self._model.props.state == accesspointmodel.STATE_NOTCONNECTED:
|
2007-09-09 06:02:26 +02:00
|
|
|
if self._disconnect_item:
|
|
|
|
self._disconnect_item.hide()
|
2007-03-29 17:25:47 +02:00
|
|
|
self.props.pulse_time = 0.0
|
2007-11-09 18:18:36 +01:00
|
|
|
self.props.colors = [
|
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
|
|
|
style.Color(self._device_fill).get_svg() ]
|
|
|
|
]
|
2007-02-25 11:39:35 +01:00
|
|
|
|
2007-11-09 18:18:36 +01:00
|
|
|
if self._greyed_out:
|
|
|
|
self.props.pulse_time = 0.0
|
|
|
|
self.props.colors = [['#D5D5D5', '#D5D5D5']]
|
2007-11-04 15:07:15 +01:00
|
|
|
|
|
|
|
def set_filter(self, query):
|
|
|
|
self._greyed_out = self._model.props.name.lower().find(query) == -1
|
|
|
|
self._update_state()
|
2007-03-29 21:00:27 +02:00
|
|
|
|
2007-08-26 14:16:09 +02:00
|
|
|
_MESH_ICON_NAME = 'network-mesh'
|
2007-03-29 21:00:27 +02:00
|
|
|
|
|
|
|
class MeshDeviceView(PulsingIcon):
|
2007-09-09 06:02:26 +02:00
|
|
|
def __init__(self, nm_device, channel):
|
|
|
|
if not channel in [1, 6, 11]:
|
|
|
|
raise ValueError("Invalid channel %d" % channel)
|
|
|
|
|
2007-09-12 18:01:21 +02:00
|
|
|
PulsingIcon.__init__(self, size=style.STANDARD_ICON_SIZE,
|
2007-09-08 12:10:35 +02:00
|
|
|
icon_name=_MESH_ICON_NAME, cache=True)
|
2007-09-09 06:02:26 +02:00
|
|
|
|
2007-03-29 16:10:34 +02:00
|
|
|
self._nm_device = nm_device
|
2007-09-09 06:02:26 +02:00
|
|
|
self.channel = channel
|
|
|
|
self.props.badge_name = "badge-channel-%d" % self.channel
|
2007-11-09 18:18:36 +01:00
|
|
|
self._greyed_out = False
|
2007-09-09 06:02:26 +02:00
|
|
|
|
|
|
|
self._disconnect_item = None
|
|
|
|
self._palette = self._create_palette()
|
|
|
|
self.set_palette(self._palette)
|
2007-03-29 16:10:34 +02:00
|
|
|
|
2007-03-29 21:00:27 +02:00
|
|
|
mycolor = profile.get_color()
|
|
|
|
self._device_fill = mycolor.get_fill_color()
|
|
|
|
self._device_stroke = mycolor.get_stroke_color()
|
|
|
|
|
2007-03-29 16:10:34 +02:00
|
|
|
self.connect('activated', self._activate_cb)
|
|
|
|
|
|
|
|
self._nm_device.connect('state-changed', self._state_changed_cb)
|
2007-09-09 06:02:26 +02:00
|
|
|
self._nm_device.connect('activation-stage-changed', self._state_changed_cb)
|
2007-03-29 16:10:34 +02:00
|
|
|
self._update_state()
|
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
def _create_palette(self):
|
|
|
|
p = palette.Palette(_("Mesh Network") + " " + str(self.channel), menu_after_content=True)
|
|
|
|
|
|
|
|
self._disconnect_item = gtk.MenuItem(_('Disconnect...'))
|
|
|
|
self._disconnect_item.connect('activate', self._disconnect_activate_cb)
|
|
|
|
p.menu.append(self._disconnect_item)
|
|
|
|
|
|
|
|
state = self._nm_device.get_state()
|
|
|
|
chan = wireless.freq_to_channel(self._nm_device.get_frequency())
|
|
|
|
if state == nmclient.DEVICE_STATE_ACTIVATED and chan == self.channel:
|
|
|
|
self._disconnect_item.show()
|
|
|
|
return p
|
|
|
|
|
|
|
|
def _disconnect_activate_cb(self, menuitem):
|
|
|
|
network_manager = hardwaremanager.get_network_manager()
|
|
|
|
if network_manager:
|
|
|
|
network_manager.set_active_device(self._nm_device)
|
|
|
|
|
2007-03-29 16:10:34 +02:00
|
|
|
def _activate_cb(self, icon):
|
|
|
|
network_manager = hardwaremanager.get_network_manager()
|
2007-09-09 06:02:26 +02:00
|
|
|
if network_manager:
|
|
|
|
freq = wireless.channel_to_freq(self.channel)
|
|
|
|
network_manager.set_active_device(self._nm_device, mesh_freq=freq)
|
2007-03-29 16:10:34 +02:00
|
|
|
|
|
|
|
def _state_changed_cb(self, model):
|
|
|
|
self._update_state()
|
|
|
|
|
|
|
|
def _update_state(self):
|
|
|
|
state = self._nm_device.get_state()
|
2007-09-09 06:02:26 +02:00
|
|
|
chan = wireless.freq_to_channel(self._nm_device.get_frequency())
|
2007-11-09 18:18:36 +01:00
|
|
|
if self._greyed_out:
|
|
|
|
self.props.colors = [['#D5D5D5', '#D5D5D5']]
|
|
|
|
elif state == nmclient.DEVICE_STATE_ACTIVATING and chan == self.channel:
|
2007-09-09 06:02:26 +02:00
|
|
|
self._disconnect_item.hide()
|
2007-03-29 21:00:27 +02:00
|
|
|
self.props.pulse_time = 0.75
|
|
|
|
self.props.colors = [
|
2007-08-28 21:25:04 +02:00
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
2007-09-09 06:02:26 +02:00
|
|
|
style.Color(self._device_fill).get_svg() ],
|
2007-08-28 21:25:04 +02:00
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
2007-09-09 06:02:26 +02:00
|
|
|
'#e2e2e2' ]
|
2007-03-29 21:00:27 +02:00
|
|
|
]
|
2007-09-09 06:02:26 +02:00
|
|
|
elif state == nmclient.DEVICE_STATE_ACTIVATED and chan == self.channel:
|
|
|
|
self._disconnect_item.show()
|
2007-10-04 22:46:14 +02:00
|
|
|
self.props.pulse_time = 0.0
|
2007-03-29 21:00:27 +02:00
|
|
|
self.props.colors = [
|
2007-10-04 22:46:14 +02:00
|
|
|
[ '#ffffff',
|
2007-09-09 06:02:26 +02:00
|
|
|
style.Color(self._device_fill).get_svg() ],
|
2007-08-28 21:25:04 +02:00
|
|
|
[ '#ffffff',
|
2007-09-09 06:02:26 +02:00
|
|
|
style.Color(self._device_fill).get_svg() ]
|
2007-03-29 21:00:27 +02:00
|
|
|
]
|
2007-09-09 06:02:26 +02:00
|
|
|
elif state == nmclient.DEVICE_STATE_INACTIVE or chan != self.channel:
|
|
|
|
self._disconnect_item.hide()
|
2007-03-29 21:00:27 +02:00
|
|
|
self.props.pulse_time = 0.0
|
|
|
|
self.props.colors = [
|
2007-08-28 21:25:04 +02:00
|
|
|
[ style.Color(self._device_stroke).get_svg(),
|
|
|
|
style.Color(self._device_fill).get_svg() ]
|
2007-03-29 21:00:27 +02:00
|
|
|
]
|
2007-09-09 06:02:26 +02:00
|
|
|
else:
|
|
|
|
raise RuntimeError("Shouldn't get here")
|
2007-03-29 16:10:34 +02:00
|
|
|
|
2007-11-09 18:18:36 +01:00
|
|
|
def set_filter(self, query):
|
|
|
|
self._greyed_out = (query != '')
|
|
|
|
self._update_state()
|
|
|
|
|
2007-07-05 11:22:09 +02:00
|
|
|
class ActivityView(hippo.CanvasBox):
|
2007-07-01 12:55:10 +02:00
|
|
|
def __init__(self, shell, model):
|
2007-07-05 11:22:09 +02:00
|
|
|
hippo.CanvasBox.__init__(self)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell = shell
|
|
|
|
self._model = model
|
|
|
|
self._icons = {}
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2007-07-05 11:22:09 +02:00
|
|
|
self._layout = SnowflakeLayout()
|
|
|
|
self.set_layout(self._layout)
|
|
|
|
|
2007-11-20 15:41:44 +01:00
|
|
|
self._icon = self._create_icon()
|
2007-07-05 11:22:09 +02:00
|
|
|
self._layout.add_center(self._icon)
|
2007-05-15 22:21:40 +02:00
|
|
|
|
2007-11-20 15:41:44 +01:00
|
|
|
self._update_palette()
|
2007-08-31 11:37:42 +02:00
|
|
|
|
2007-11-20 15:41:44 +01:00
|
|
|
activity = self._model.activity
|
|
|
|
activity.connect('notify::name', self._name_changed_cb)
|
|
|
|
activity.connect('notify::color', self._color_changed_cb)
|
|
|
|
activity.connect('notify::private', self._private_changed_cb)
|
|
|
|
activity.connect('joined', self._joined_changed_cb)
|
|
|
|
#FIXME: 'joined' signal not working, see #5032
|
|
|
|
|
|
|
|
def _create_icon(self):
|
|
|
|
icon = CanvasIcon(file_name=self._model.get_icon_name(),
|
|
|
|
xo_color=self._model.get_color(), cache=True,
|
|
|
|
size=style.STANDARD_ICON_SIZE)
|
|
|
|
icon.connect('activated', self._clicked_cb)
|
|
|
|
return icon
|
|
|
|
|
|
|
|
def _create_palette(self):
|
|
|
|
p = palette.Palette(self._model.activity.props.name)
|
|
|
|
|
|
|
|
private = self._model.activity.props.private
|
|
|
|
joined = self._model.activity.props.joined
|
|
|
|
|
|
|
|
if joined:
|
|
|
|
item = MenuItem(_('Resume'), 'activity-start')
|
|
|
|
item.connect('activate', self._clicked_cb)
|
|
|
|
item.show()
|
|
|
|
p.menu.append(item)
|
|
|
|
elif not private:
|
|
|
|
item = MenuItem(_('Join'), 'activity-start')
|
|
|
|
item.connect('activate', self._clicked_cb)
|
|
|
|
item.show()
|
|
|
|
p.menu.append(item)
|
|
|
|
|
|
|
|
return p
|
|
|
|
|
|
|
|
def _update_palette(self):
|
|
|
|
self._palette = self._create_palette()
|
|
|
|
self._icon.set_palette(self._palette)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
def has_buddy_icon(self, key):
|
|
|
|
return self._icons.has_key(key)
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
def add_buddy_icon(self, key, icon):
|
|
|
|
self._icons[key] = icon
|
2007-07-05 11:22:09 +02:00
|
|
|
self._layout.add(icon)
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
def remove_buddy_icon(self, key):
|
|
|
|
icon = self._icons[key]
|
|
|
|
del self._icons[key]
|
2008-01-09 21:21:06 +01:00
|
|
|
icon.destroy()
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _clicked_cb(self, item):
|
2007-10-09 13:15:06 +02:00
|
|
|
bundle_id = self._model.get_bundle_id()
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell.join_activity(bundle_id, self._model.get_id())
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2007-11-04 15:07:15 +01:00
|
|
|
def set_filter(self, query):
|
2007-11-08 20:06:53 +01:00
|
|
|
text_to_check = self._model.activity.props.name.lower() + \
|
|
|
|
self._model.activity.props.type.lower()
|
|
|
|
if text_to_check.find(query) == -1:
|
2007-11-09 18:18:36 +01:00
|
|
|
self._icon.props.stroke_color = '#D5D5D5'
|
|
|
|
self._icon.props.fill_color = '#E5E5E5'
|
2007-11-04 15:07:15 +01:00
|
|
|
else:
|
2007-11-08 20:06:53 +01:00
|
|
|
self._icon.props.xo_color = self._model.get_color()
|
2007-11-04 15:07:15 +01:00
|
|
|
|
2007-11-09 18:18:36 +01:00
|
|
|
for key, icon in self._icons.iteritems():
|
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(query)
|
|
|
|
|
2007-11-20 15:41:44 +01:00
|
|
|
def _name_changed_cb(self, activity, pspec):
|
|
|
|
self._update_palette()
|
|
|
|
|
|
|
|
def _color_changed_cb(self, activity, pspec):
|
|
|
|
self._layout.remove(self._icon)
|
|
|
|
self._icon = self._create_icon()
|
|
|
|
self._layout.add_center(self._icon)
|
|
|
|
self._icon.set_palette(self._palette)
|
|
|
|
|
|
|
|
def _private_changed_cb(self, activity, pspec):
|
|
|
|
self._update_palette()
|
|
|
|
|
|
|
|
def _joined_changed_cb(self, widget, event):
|
|
|
|
logging.debug('ActivityView._joined_changed_cb: AAAA!!!!')
|
|
|
|
|
2007-11-04 15:07:15 +01:00
|
|
|
_AUTOSEARCH_TIMEOUT = 1000
|
|
|
|
|
|
|
|
class MeshToolbar(gtk.Toolbar):
|
|
|
|
__gtype_name__ = 'MeshToolbar'
|
|
|
|
|
|
|
|
__gsignals__ = {
|
|
|
|
'query-changed': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
([str]))
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Toolbar.__init__(self)
|
|
|
|
|
|
|
|
self._query = None
|
|
|
|
self._autosearch_timer = None
|
|
|
|
|
|
|
|
self._add_separator()
|
|
|
|
|
|
|
|
tool_item = gtk.ToolItem()
|
|
|
|
tool_item.set_expand(True)
|
|
|
|
self.insert(tool_item, -1)
|
|
|
|
tool_item.show()
|
|
|
|
|
|
|
|
self._search_entry = iconentry.IconEntry()
|
|
|
|
self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY, 'system-search')
|
|
|
|
self._search_entry.add_clear_button()
|
|
|
|
self._search_entry.connect('activate', self._entry_activated_cb)
|
|
|
|
self._search_entry.connect('changed', self._entry_changed_cb)
|
|
|
|
tool_item.add(self._search_entry)
|
|
|
|
self._search_entry.show()
|
|
|
|
|
|
|
|
self._add_separator()
|
|
|
|
|
|
|
|
def _add_separator(self):
|
|
|
|
separator = gtk.SeparatorToolItem()
|
|
|
|
separator.set_size_request(style.GRID_CELL_SIZE, style.GRID_CELL_SIZE)
|
|
|
|
separator.props.draw = False
|
|
|
|
self.insert(separator, -1)
|
|
|
|
separator.show()
|
|
|
|
|
|
|
|
def _entry_activated_cb(self, entry):
|
|
|
|
if self._autosearch_timer:
|
|
|
|
gobject.source_remove(self._autosearch_timer)
|
|
|
|
new_query = entry.props.text
|
|
|
|
if self._query != new_query:
|
|
|
|
self._query = new_query
|
|
|
|
self.emit('query-changed', self._query)
|
|
|
|
|
|
|
|
def _entry_changed_cb(self, entry):
|
|
|
|
if not entry.props.text:
|
|
|
|
entry.activate()
|
|
|
|
return
|
|
|
|
|
|
|
|
if self._autosearch_timer:
|
|
|
|
gobject.source_remove(self._autosearch_timer)
|
|
|
|
self._autosearch_timer = gobject.timeout_add(_AUTOSEARCH_TIMEOUT,
|
|
|
|
self._autosearch_timer_cb)
|
|
|
|
|
|
|
|
def _autosearch_timer_cb(self):
|
|
|
|
logging.debug('_autosearch_timer_cb')
|
|
|
|
self._autosearch_timer = None
|
|
|
|
self._search_entry.activate()
|
|
|
|
return False
|
|
|
|
|
2007-07-05 21:22:37 +02:00
|
|
|
class MeshBox(hippo.CanvasBox):
|
2007-07-01 12:55:10 +02:00
|
|
|
def __init__(self, shell):
|
2007-11-04 15:07:15 +01:00
|
|
|
hippo.CanvasBox.__init__(self)
|
2006-09-15 15:28:18 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell = shell
|
|
|
|
self._model = shell.get_model().get_mesh()
|
|
|
|
self._buddies = {}
|
|
|
|
self._activities = {}
|
2007-02-25 11:39:35 +01:00
|
|
|
self._access_points = {}
|
2007-09-09 06:02:26 +02:00
|
|
|
self._mesh = {}
|
2006-12-04 20:12:24 +01:00
|
|
|
self._buddy_to_activity = {}
|
2007-03-30 01:08:44 +02:00
|
|
|
self._suspended = True
|
2007-11-04 15:07:15 +01:00
|
|
|
self._query = ''
|
2006-09-15 15:28:18 +02:00
|
|
|
|
2007-11-04 15:07:15 +01:00
|
|
|
self._toolbar = MeshToolbar()
|
|
|
|
self._toolbar.connect('query-changed', self._toolbar_query_changed_cb)
|
|
|
|
self.append(hippo.CanvasWidget(widget=self._toolbar))
|
|
|
|
|
|
|
|
self._layout_box = hippo.CanvasBox(background_color=0xe2e2e2ff)
|
|
|
|
self.append(self._layout_box, hippo.PACK_EXPAND)
|
|
|
|
|
2007-11-05 12:04:15 +01:00
|
|
|
self._layout = SpreadLayout()
|
2007-11-04 15:07:15 +01:00
|
|
|
self._layout_box.set_layout(self._layout)
|
2007-07-05 21:22:37 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
for buddy_model in self._model.get_buddies():
|
|
|
|
self._add_alone_buddy(buddy_model)
|
2006-09-12 12:19:20 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._model.connect('buddy-added', self._buddy_added_cb)
|
|
|
|
self._model.connect('buddy-removed', self._buddy_removed_cb)
|
|
|
|
self._model.connect('buddy-moved', self._buddy_moved_cb)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
for activity_model in self._model.get_activities():
|
|
|
|
self._add_activity(activity_model)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._model.connect('activity-added', self._activity_added_cb)
|
|
|
|
self._model.connect('activity-removed', self._activity_removed_cb)
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2007-02-25 11:39:35 +01:00
|
|
|
for ap_model in self._model.get_access_points():
|
|
|
|
self._add_access_point(ap_model)
|
|
|
|
|
|
|
|
self._model.connect('access-point-added',
|
|
|
|
self._access_point_added_cb)
|
|
|
|
self._model.connect('access-point-removed',
|
|
|
|
self._access_point_removed_cb)
|
|
|
|
|
2007-03-29 16:10:34 +02:00
|
|
|
if self._model.get_mesh():
|
2007-09-09 06:02:26 +02:00
|
|
|
self._mesh_added_cb(self._model, self._model.get_mesh())
|
2007-03-29 16:10:34 +02:00
|
|
|
|
|
|
|
self._model.connect('mesh-added',
|
|
|
|
self._mesh_added_cb)
|
|
|
|
self._model.connect('mesh-removed',
|
|
|
|
self._mesh_removed_cb)
|
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
def _mesh_added_cb(self, model, meshdev):
|
|
|
|
self._add_mesh_icon(meshdev, 1)
|
|
|
|
self._add_mesh_icon(meshdev, 6)
|
|
|
|
self._add_mesh_icon(meshdev, 11)
|
2007-03-29 16:10:34 +02:00
|
|
|
|
|
|
|
def _mesh_removed_cb(self, model):
|
2007-09-09 06:02:26 +02:00
|
|
|
self._remove_mesh_icon(1)
|
|
|
|
self._remove_mesh_icon(6)
|
|
|
|
self._remove_mesh_icon(11)
|
2007-03-29 16:10:34 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_added_cb(self, model, buddy_model):
|
|
|
|
self._add_alone_buddy(buddy_model)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_removed_cb(self, model, buddy_model):
|
|
|
|
self._remove_buddy(buddy_model)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _buddy_moved_cb(self, model, buddy_model, activity_model):
|
2007-07-18 08:05:09 +02:00
|
|
|
# Owner doesn't move from the center
|
|
|
|
if buddy_model.is_owner():
|
|
|
|
return
|
2006-12-04 20:12:24 +01:00
|
|
|
self._move_buddy(buddy_model, activity_model)
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _activity_added_cb(self, model, activity_model):
|
|
|
|
self._add_activity(activity_model)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _activity_removed_cb(self, model, activity_model):
|
|
|
|
self._remove_activity(activity_model)
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2007-02-25 11:39:35 +01:00
|
|
|
def _access_point_added_cb(self, model, ap_model):
|
|
|
|
self._add_access_point(ap_model)
|
|
|
|
|
|
|
|
def _access_point_removed_cb(self, model, ap_model):
|
2007-03-07 14:23:44 +01:00
|
|
|
self._remove_access_point(ap_model)
|
2007-02-25 11:39:35 +01:00
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
def _add_mesh_icon(self, meshdev, channel):
|
|
|
|
if self._mesh.has_key(channel):
|
|
|
|
self._remove_mesh_icon(channel)
|
|
|
|
if not meshdev:
|
2007-03-29 16:10:34 +02:00
|
|
|
return
|
2007-09-09 06:02:26 +02:00
|
|
|
self._mesh[channel] = MeshDeviceView(meshdev, channel)
|
|
|
|
self._layout.add(self._mesh[channel])
|
2007-03-29 16:10:34 +02:00
|
|
|
|
2007-09-09 06:02:26 +02:00
|
|
|
def _remove_mesh_icon(self, channel):
|
|
|
|
if not self._mesh.has_key(channel):
|
2007-03-29 16:10:34 +02:00
|
|
|
return
|
2007-09-09 06:02:26 +02:00
|
|
|
self._layout.remove(self._mesh[channel])
|
|
|
|
del self._mesh[channel]
|
2007-03-29 16:10:34 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _add_alone_buddy(self, buddy_model):
|
2007-07-01 12:55:10 +02:00
|
|
|
icon = BuddyIcon(self._shell, buddy_model)
|
2007-04-16 10:36:15 +02:00
|
|
|
if buddy_model.is_owner():
|
2007-11-05 12:04:15 +01:00
|
|
|
vertical_offset = - style.GRID_CELL_SIZE
|
|
|
|
self._layout.add_center(icon, vertical_offset)
|
2007-04-16 10:36:15 +02:00
|
|
|
else:
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.add(icon)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2007-11-04 15:07:15 +01:00
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(self._query)
|
|
|
|
|
2007-04-10 21:55:55 +02:00
|
|
|
self._buddies[buddy_model.get_key()] = icon
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _remove_alone_buddy(self, buddy_model):
|
2007-04-10 21:55:55 +02:00
|
|
|
icon = self._buddies[buddy_model.get_key()]
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.remove(icon)
|
2007-04-10 21:55:55 +02:00
|
|
|
del self._buddies[buddy_model.get_key()]
|
2008-01-09 21:21:06 +01:00
|
|
|
icon.destroy()
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _remove_buddy(self, buddy_model):
|
2007-04-10 21:55:55 +02:00
|
|
|
key = buddy_model.get_key()
|
|
|
|
if self._buddies.has_key(key):
|
2006-12-04 20:12:24 +01:00
|
|
|
self._remove_alone_buddy(buddy_model)
|
|
|
|
else:
|
|
|
|
for activity in self._activities.values():
|
2007-04-10 21:55:55 +02:00
|
|
|
if activity.has_buddy_icon(key):
|
|
|
|
activity.remove_buddy_icon(key)
|
2006-09-25 18:55:35 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _move_buddy(self, buddy_model, activity_model):
|
2007-04-10 21:55:55 +02:00
|
|
|
key = buddy_model.get_key()
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._remove_buddy(buddy_model)
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
if activity_model == None:
|
|
|
|
self._add_alone_buddy(buddy_model)
|
2007-11-20 15:41:44 +01:00
|
|
|
elif activity_model.get_id() in self._activities:
|
2006-12-04 20:12:24 +01:00
|
|
|
activity = self._activities[activity_model.get_id()]
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2007-09-12 18:01:21 +02:00
|
|
|
icon = BuddyIcon(self._shell, buddy_model,
|
|
|
|
style.SMALL_ICON_SIZE)
|
2007-04-10 21:55:55 +02:00
|
|
|
activity.add_buddy_icon(buddy_model.get_key(), icon)
|
2006-09-25 18:38:01 +02:00
|
|
|
|
2007-11-09 18:18:36 +01:00
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(self._query)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _add_activity(self, activity_model):
|
2007-07-01 12:55:10 +02:00
|
|
|
icon = ActivityView(self._shell, activity_model)
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.add(icon)
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2007-11-08 20:23:11 +01:00
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(self._query)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
self._activities[activity_model.get_id()] = icon
|
2006-09-25 16:40:15 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def _remove_activity(self, activity_model):
|
|
|
|
icon = self._activities[activity_model.get_id()]
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.remove(icon)
|
2006-12-04 20:12:24 +01:00
|
|
|
del self._activities[activity_model.get_id()]
|
2008-01-09 21:21:06 +01:00
|
|
|
icon.destroy()
|
2007-02-25 11:39:35 +01:00
|
|
|
|
|
|
|
def _add_access_point(self, ap_model):
|
2007-09-09 06:02:26 +02:00
|
|
|
meshdev = self._model.get_mesh()
|
|
|
|
icon = AccessPointView(ap_model, meshdev)
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.add(icon)
|
2007-02-25 11:39:35 +01:00
|
|
|
|
2007-11-08 20:23:11 +01:00
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(self._query)
|
|
|
|
|
2007-02-25 11:39:35 +01:00
|
|
|
self._access_points[ap_model.get_id()] = icon
|
|
|
|
|
|
|
|
def _remove_access_point(self, ap_model):
|
|
|
|
icon = self._access_points[ap_model.get_id()]
|
2007-07-06 00:46:12 +02:00
|
|
|
self._layout.remove(icon)
|
2007-02-25 11:39:35 +01:00
|
|
|
del self._access_points[ap_model.get_id()]
|
2007-03-30 01:08:44 +02:00
|
|
|
|
|
|
|
def suspend(self):
|
|
|
|
if not self._suspended:
|
|
|
|
self._suspended = True
|
|
|
|
for ap in self._access_points.values():
|
|
|
|
ap.props.paused = True
|
|
|
|
|
|
|
|
def resume(self):
|
|
|
|
if self._suspended:
|
|
|
|
self._suspended = False
|
|
|
|
for ap in self._access_points.values():
|
|
|
|
ap.props.paused = False
|
2007-11-04 15:07:15 +01:00
|
|
|
|
|
|
|
def _toolbar_query_changed_cb(self, toolbar, query):
|
|
|
|
self._query = query.lower()
|
|
|
|
for icon in self._layout_box.get_children():
|
|
|
|
if hasattr(icon, 'set_filter'):
|
|
|
|
icon.set_filter(self._query)
|
|
|
|
|
2007-11-20 14:06:18 +01:00
|
|
|
def focus_search_entry(self):
|
|
|
|
self._toolbar._search_entry.grab_focus()
|