home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / buddylist / buddylistrules.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  6.0 KB  |  205 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from common import pref
  5. from contacts.buddylistsort import SpecialGroup
  6. from common import buddy
  7. from contacts import Contact
  8. from contacts.metacontacts import MetaContact
  9. from contacts.Group import Group, DGroup
  10. from common import profile
  11. from contacts.buddylistfilters import OfflineGroup, FakeRootGroup
  12. SERVICES_WITHOUT_GROUPS = []
  13.  
  14. def can_drop_buddy_group(group):
  15.     if isinstance(group, SpecialGroup) and not isinstance(group, FakeRootGroup):
  16.         return False
  17.     
  18.     return profile.blist.sorter.user_ordering
  19.  
  20.  
  21. def above_below_middle(percent):
  22.     border_space = pref('buddylist.border_space', 35) / 100
  23.     if percent < border_space:
  24.         return 'above'
  25.     elif percent > 1 - border_space:
  26.         return 'below'
  27.     else:
  28.         return 'middle'
  29.  
  30.  
  31. def above_below(percent):
  32.     if percent <= 0.5:
  33.         return 'above'
  34.     else:
  35.         return 'below'
  36.  
  37.  
  38. def buddy_buddy(model, frm, to, i, position, parent_position):
  39.     if position in ('above', 'below'):
  40.         parent = model.parent_of(to)
  41.         frmparent = model.parent_of(frm)
  42.         if can_drop_buddy_group(parent) and not isinstance(frmparent, OfflineGroup):
  43.             return (to, position)
  44.         else:
  45.             return buddy_buddy(model, frm, to, i, position = 'middle', parent_position = parent_position)
  46.     elif position == 'middle':
  47.         return (to, 'middle')
  48.     
  49.  
  50.  
  51. def group_buddy(model, frm, to, i, position, parent_position):
  52.     to = model.parent_of(to)
  53.     return group_group(model, frm, to, model.index_of(to), position, parent_position)
  54.  
  55.  
  56. def group_group(model, frm, to, i, position, parent_position):
  57.     if isinstance(to, OfflineGroup):
  58.         if i != 0:
  59.             return item(model, frm, model[i - 1], i - 1, position = 'below', parent_position = 'below')
  60.         
  61.     
  62.     return (to, parent_position)
  63.  
  64.  
  65. def buddy_group(model, frm, to, i, position, parent_position):
  66.     if isinstance(model.parent_of(frm), OfflineGroup):
  67.         return (to, 'middle')
  68.     
  69.     if position == 'above':
  70.         if i == 0:
  71.             return (to, 'middle')
  72.         elif not model.is_expanded(i - 1):
  73.             return (to, 'middle')
  74.         else:
  75.             return item(model, frm, model[i - 1], i - 1, position = 'below', parent_position = parent_position)
  76.     elif position == 'below':
  77.         if not model.is_expanded(i):
  78.             return (to, 'middle')
  79.         else:
  80.             return (to, 'below')
  81.     elif position == 'middle':
  82.         return (to, 'middle')
  83.     else:
  84.         raise AssertionError, 'buddy_group needs a valid position (above/below/middle), got %r' % position
  85.  
  86. BUDDY = (MetaContact, Contact, buddy)
  87. GROUP = (DGroup,)
  88. TYPES = (BUDDY, GROUP)
  89. origin = {
  90.     (BUDDY, BUDDY): buddy_buddy,
  91.     (BUDDY, GROUP): buddy_group,
  92.     (GROUP, BUDDY): group_buddy,
  93.     (GROUP, GROUP): group_group }
  94.  
  95. def to_type(obj):
  96.     for typ in TYPES:
  97.         if isinstance(obj, typ):
  98.             return typ
  99.             continue
  100.     
  101.     return sentinel
  102.  
  103.  
  104. def item(model, frm, to, i, position = None, parent_position = None):
  105.     typ_to = to_type(to)
  106.     typ_frm = to_type(frm)
  107.     if (typ_to, typ_frm) not in origin:
  108.         return sentinel
  109.     else:
  110.         return origin[(typ_frm, typ_to)](model, frm, to, i, position, parent_position)
  111.  
  112.  
  113. def target(model, frm, to, i, percent, parent_percent):
  114.     position = above_below_middle(percent)
  115.     parent_position = above_below(parent_percent[1])
  116.     result = item(model, frm, to, i, position, parent_position)
  117.     return result
  118.  
  119. ITEM_BOX = 'box'
  120. GROUP_BOX = 'group_box'
  121. ABOVE = 'above'
  122. BELOW = 'below'
  123. BELOW_GROUP = 'below_group'
  124. DISALLOW = 'disallow'
  125. FEEDBACK_TYPES = set([
  126.     ITEM_BOX,
  127.     GROUP_BOX,
  128.     ABOVE,
  129.     BELOW,
  130.     BELOW_GROUP,
  131.     DISALLOW])
  132.  
  133. def feed_buddy_buddy(model, frm, to, position):
  134.     if getattr(to, 'iswidget', False):
  135.         return DISALLOW
  136.     
  137.     if isinstance(model.parent_of(to), OfflineGroup) and not isinstance(model.parent_of(frm), OfflineGroup):
  138.         return DISALLOW
  139.     
  140.     if getattr(frm, 'service', None) in SERVICES_WITHOUT_GROUPS and not isinstance(frm, MetaContact):
  141.         return ITEM_BOX
  142.     
  143.     if position == 'middle':
  144.         return ITEM_BOX
  145.     
  146.     return position
  147.  
  148.  
  149. def feed_buddy_group(model, frm, to, position):
  150.     if getattr(frm, 'service', None) in SERVICES_WITHOUT_GROUPS and not isinstance(frm, MetaContact):
  151.         return DISALLOW
  152.     
  153.     if isinstance(to, SpecialGroup):
  154.         if to.id == Group.FAKEROOT_ID:
  155.             return GROUP_BOX
  156.         else:
  157.             return DISALLOW
  158.     
  159.     if isinstance(model.parent_of(frm), OfflineGroup):
  160.         return DISALLOW
  161.     
  162.     if position == 'middle':
  163.         return GROUP_BOX
  164.     elif profile.blist.sorter.user_ordering:
  165.         return BELOW
  166.     else:
  167.         return GROUP_BOX
  168.  
  169.  
  170. def feed_group_buddy(model, frm, to, position):
  171.     pass
  172.  
  173.  
  174. def feed_group_group(model, frm, to, position):
  175.     if isinstance(to, OfflineGroup):
  176.         return DISALLOW
  177.     
  178.     if position == BELOW:
  179.         return BELOW_GROUP
  180.     
  181.     return position
  182.  
  183. feedback_types = {
  184.     (BUDDY, BUDDY): feed_buddy_buddy,
  185.     (BUDDY, GROUP): feed_buddy_group,
  186.     (GROUP, BUDDY): feed_group_buddy,
  187.     (GROUP, GROUP): feed_group_group }
  188.  
  189. def feedback(model, frm, to, position):
  190.     typ_to = to_type(to)
  191.     typ_frm = to_type(frm)
  192.     if to is frm or not allow_drag(frm):
  193.         return DISALLOW
  194.     
  195.     result = feedback_types[(typ_frm, typ_to)](model, frm, to, position)
  196.     return result
  197.  
  198.  
  199. def allow_drag(frm):
  200.     if getattr(frm, 'iswidget', False):
  201.         return False
  202.     
  203.     return True
  204.  
  205.