home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / gui / buddylist / buddylistrules.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  7.3 KB  |  230 lines

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