component_licenses_table.py (6518B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\cosmetics\client\ships\qa\component_licenses_table.py 2 import blue 3 import eveicon 4 from carbonui import uiconst 5 from carbonui.control.forms import formComponent 6 from carbonui.control.forms.form import Form, FormActionSubmit, FormActionCancel 7 from carbonui.control.forms.formWindow import FormWindow 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbon.common.script.sys.serviceConst import ROLE_GML 10 from carbonui.control.scroll import Scroll 11 from carbonui.control.window import Window 12 from cosmetics.client.shipSkinComponentSvc import get_ship_skin_component_svc 13 from cosmetics.client.ships.ship_skin_signals import on_component_license_granted, on_component_license_cache_invalidated 14 from cosmetics.common.ships.skins.live_data.component_license_type import ComponentLicenseType 15 from cosmetics.common.ships.skins.static_data.component import ComponentsDataLoader 16 from eve.client.script.ui.control.entries.generic import Generic 17 from eve.client.script.ui.control.entries.util import GetFromClass 18 19 class ComponentLicensesTableWindow(Window): 20 __guid__ = 'ComponentLicensesTableWindow' 21 default_width = 600 22 default_height = 600 23 default_windowID = 'componentLicensesTableWindow' 24 default_minSize = [default_width, default_height] 25 26 def __init__(self, *args): 27 super(ComponentLicensesTableWindow, self).__init__(*args) 28 self.SetCaption('Ship SKIN Component Licenses') 29 self._rebuilding = False 30 self.scroll = Scroll(name='scroll', parent=self.sr.maincontainer, align=uiconst.TOALL) 31 self.populate() 32 on_component_license_granted.connect(self._on_component_license_granted) 33 on_component_license_cache_invalidated.connect(self._on_cache_invalidated) 34 35 def _OnClose(self, *args, **kw): 36 on_component_license_granted.disconnect(self._on_component_license_granted) 37 on_component_license_cache_invalidated.disconnect(self._on_cache_invalidated) 38 super(ComponentLicensesTableWindow, self)._OnClose(*args, **kw) 39 40 def populate(self): 41 self._rebuilding = True 42 components = ComponentsDataLoader.get_components_data() 43 entries = [] 44 for component_id, component in components.iteritems(): 45 infinite_license = get_ship_skin_component_svc().get_unbound_license(component_id, component.category) 46 finite_license = get_ship_skin_component_svc().get_bound_license(component_id, component.category) 47 data = [ str(x) or '' for x in [component_id, 48 component.name, 49 'Yes' if infinite_license else 'No', 50 finite_license.remaining_license_uses if finite_license else '-'] ] 51 entries.append(GetFromClass(ComponentLicenseTableEntry, {'label': '<t>'.join(data), 52 'component': component})) 53 54 self.scroll.Load(contentList=entries, headers=self._get_headers()) 55 self._rebuilding = False 56 57 def _get_headers(self): 58 return ['component id', 59 'component name', 60 'infinite license', 61 'finite license uses'] 62 63 def _on_component_license_granted(self, *args): 64 if not self._rebuilding: 65 self.scroll.Clear() 66 self.populate() 67 68 def _on_cache_invalidated(self, _licenses): 69 if not self._rebuilding: 70 self.scroll.Clear() 71 self.populate() 72 73 74 class ComponentLicenseTableEntry(Generic): 75 __guid__ = 'listentry.ComponentLicenseTableEntry' 76 __nonpersistvars__ = [] 77 78 def GetMenu(self): 79 if session and session.role & ROLE_GML: 80 menu = [('Grant Infinite', self._grant_infinite_license, ()), 81 ('Grant Finite', self._grant_finite_license, ()), 82 ('Revoke Infinite', self._revoke_infinite_license, ()), 83 ('Revoke Finite', self._revoke_finite_license, ()), 84 ('Copy Type ID Infinite', self._copy_type_id_for_license_type, (ComponentLicenseType.UNLIMITED,)), 85 ('Copy Type ID Finite', self._copy_type_id_for_license_type, (ComponentLicenseType.LIMITED,))] 86 return menu 87 88 def _grant_infinite_license(self): 89 get_ship_skin_component_svc().admin_grant_license(self.sr.node.component.component_id, ComponentLicenseType.UNLIMITED, self.sr.node.component.category) 90 91 def _revoke_infinite_license(self): 92 get_ship_skin_component_svc().admin_revoke_license(self.sr.node.component.component_id, ComponentLicenseType.UNLIMITED, self.sr.node.component.category) 93 94 def _grant_finite_license(self): 95 dialogue = QAGrantLicenseCountDialogue(component_id=self.sr.node.component.component_id, component_category=self.sr.node.component.category) 96 dialogue.ShowModal() 97 98 def _revoke_finite_license(self): 99 get_ship_skin_component_svc().admin_revoke_license(self.sr.node.component.component_id, ComponentLicenseType.LIMITED, self.sr.node.component.category) 100 101 def _copy_type_id_for_license_type(self, license_type): 102 component_type_id = '?' 103 for type_id, data in self.sr.node.component.component_item_data_by_type_id.iteritems(): 104 if data.license_type == license_type: 105 component_type_id = type_id 106 break 107 108 blue.pyos.SetClipboardData(str(component_type_id)) 109 110 111 class QAGrantLicenseCountDialogue(FormWindow): 112 default_windowID = 'QAGrantLicenseCountDialogue' 113 114 def ApplyAttributes(self, attributes): 115 super(FormWindow, self).ApplyAttributes(attributes) 116 self.window_name = 'Grant Finite Licenses' 117 self._component_id = attributes.component_id 118 self._component_category = attributes.component_category 119 components = [formComponent.Integer(name='Licenses to grant', label='Licenses to grant', value=1)] 120 self.form = Form(name=self.window_name, icon=eveicon.load, components=components, actions=[FormActionSubmit(label='OK', func=self.on_form_submit), FormActionCancel()]) 121 self.SetCaption(self.form.name) 122 if self.form.icon: 123 self.icon = self.form.icon 124 self.formCont = ContainerAutoSize(name='formCont', parent=self.content, align=uiconst.TOTOP, callback=self.OnFormContHeightChanged) 125 self.ConstructLayout() 126 self.ConnectSignals() 127 128 def on_form_submit(self, form): 129 get_ship_skin_component_svc().admin_grant_license(self._component_id, ComponentLicenseType.LIMITED, self._component_category, form.get_component('Licenses to grant').get_value())