home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from common import pref
- from contacts.buddylistsort import SpecialGroup
- from common import buddy
- from contacts import Contact
- from contacts.metacontacts import MetaContact
- from contacts.Group import Group, DGroup
- from common import profile
- from contacts.buddylistfilters import OfflineGroup, FakeRootGroup
- SERVICES_WITHOUT_GROUPS = []
-
- def can_drop_buddy_group(group):
- if isinstance(group, SpecialGroup) and not isinstance(group, FakeRootGroup):
- return False
-
- return profile.blist.sorter.user_ordering
-
-
- def above_below_middle(percent):
- border_space = pref('buddylist.border_space', 35) / 100
- if percent < border_space:
- return 'above'
- elif percent > 1 - border_space:
- return 'below'
- else:
- return 'middle'
-
-
- def above_below(percent):
- if percent <= 0.5:
- return 'above'
- else:
- return 'below'
-
-
- def buddy_buddy(model, frm, to, i, position, parent_position):
- if position in ('above', 'below'):
- parent = model.parent_of(to)
- frmparent = model.parent_of(frm)
- if can_drop_buddy_group(parent) and not isinstance(frmparent, OfflineGroup):
- return (to, position)
- else:
- return buddy_buddy(model, frm, to, i, position = 'middle', parent_position = parent_position)
- elif position == 'middle':
- return (to, 'middle')
-
-
-
- def group_buddy(model, frm, to, i, position, parent_position):
- to = model.parent_of(to)
- return group_group(model, frm, to, model.index_of(to), position, parent_position)
-
-
- def group_group(model, frm, to, i, position, parent_position):
- if isinstance(to, OfflineGroup):
- if i != 0:
- return item(model, frm, model[i - 1], i - 1, position = 'below', parent_position = 'below')
-
-
- return (to, parent_position)
-
-
- def buddy_group(model, frm, to, i, position, parent_position):
- if isinstance(model.parent_of(frm), OfflineGroup):
- return (to, 'middle')
-
- if position == 'above':
- if i == 0:
- return (to, 'middle')
- elif not model.is_expanded(i - 1):
- return (to, 'middle')
- else:
- return item(model, frm, model[i - 1], i - 1, position = 'below', parent_position = parent_position)
- elif position == 'below':
- if not model.is_expanded(i):
- return (to, 'middle')
- else:
- return (to, 'below')
- elif position == 'middle':
- return (to, 'middle')
- else:
- raise AssertionError, 'buddy_group needs a valid position (above/below/middle), got %r' % position
-
- BUDDY = (MetaContact, Contact, buddy)
- GROUP = (DGroup,)
- TYPES = (BUDDY, GROUP)
- origin = {
- (BUDDY, BUDDY): buddy_buddy,
- (BUDDY, GROUP): buddy_group,
- (GROUP, BUDDY): group_buddy,
- (GROUP, GROUP): group_group }
-
- def to_type(obj):
- for typ in TYPES:
- if isinstance(obj, typ):
- return typ
- continue
-
- return sentinel
-
-
- def item(model, frm, to, i, position = None, parent_position = None):
- typ_to = to_type(to)
- typ_frm = to_type(frm)
- if (typ_to, typ_frm) not in origin:
- return sentinel
- else:
- return origin[(typ_frm, typ_to)](model, frm, to, i, position, parent_position)
-
-
- def target(model, frm, to, i, percent, parent_percent):
- position = above_below_middle(percent)
- parent_position = above_below(parent_percent[1])
- result = item(model, frm, to, i, position, parent_position)
- return result
-
- ITEM_BOX = 'box'
- GROUP_BOX = 'group_box'
- ABOVE = 'above'
- BELOW = 'below'
- BELOW_GROUP = 'below_group'
- DISALLOW = 'disallow'
- FEEDBACK_TYPES = set([
- ITEM_BOX,
- GROUP_BOX,
- ABOVE,
- BELOW,
- BELOW_GROUP,
- DISALLOW])
-
- def feed_buddy_buddy(model, frm, to, position):
- if getattr(to, 'iswidget', False):
- return DISALLOW
-
- if isinstance(model.parent_of(to), OfflineGroup) and not isinstance(model.parent_of(frm), OfflineGroup):
- return DISALLOW
-
- if getattr(frm, 'service', None) in SERVICES_WITHOUT_GROUPS and not isinstance(frm, MetaContact):
- return ITEM_BOX
-
- if position == 'middle':
- return ITEM_BOX
-
- return position
-
-
- def feed_buddy_group(model, frm, to, position):
- if getattr(frm, 'service', None) in SERVICES_WITHOUT_GROUPS and not isinstance(frm, MetaContact):
- return DISALLOW
-
- if isinstance(to, SpecialGroup):
- if to.id == Group.FAKEROOT_ID:
- return GROUP_BOX
- else:
- return DISALLOW
-
- if isinstance(model.parent_of(frm), OfflineGroup):
- return DISALLOW
-
- if position == 'middle':
- return GROUP_BOX
- elif profile.blist.sorter.user_ordering:
- return BELOW
- else:
- return GROUP_BOX
-
-
- def feed_group_buddy(model, frm, to, position):
- pass
-
-
- def feed_group_group(model, frm, to, position):
- if isinstance(to, OfflineGroup):
- return DISALLOW
-
- if position == BELOW:
- return BELOW_GROUP
-
- return position
-
- feedback_types = {
- (BUDDY, BUDDY): feed_buddy_buddy,
- (BUDDY, GROUP): feed_buddy_group,
- (GROUP, BUDDY): feed_group_buddy,
- (GROUP, GROUP): feed_group_group }
-
- def feedback(model, frm, to, position):
- typ_to = to_type(to)
- typ_frm = to_type(frm)
- if to is frm or not allow_drag(frm):
- return DISALLOW
-
- result = feedback_types[(typ_frm, typ_to)](model, frm, to, position)
- return result
-
-
- def allow_drag(frm):
- if getattr(frm, 'iswidget', False):
- return False
-
- return True
-
-