def _Edit( self ): do_refresh = False selected_mappings = self._mappings_list_ctrl.GetData( only_selected = True ) for selected_mapping in selected_mappings: ( description, internal_ip, internal_port, external_port, protocol, duration ) = selected_mapping with ClientGUIDialogs.DialogInputUPnPMapping( self, external_port, protocol, internal_port, description, duration ) as dlg: if dlg.exec() == QW.QDialog.Accepted: ( external_port, protocol, internal_port, description, duration ) = dlg.GetInfo() HydrusNATPunch.RemoveUPnPMapping( external_port, protocol ) internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, protocol, description, duration = duration ) do_refresh = True else: break if do_refresh: self._RefreshMappings()
def _Add( self ): external_port = HC.DEFAULT_SERVICE_PORT protocol = 'TCP' internal_port = HC.DEFAULT_SERVICE_PORT description = 'hydrus service' duration = 0 with ClientGUIDialogs.DialogInputUPnPMapping( self, external_port, protocol, internal_port, description, duration ) as dlg: if dlg.exec() == QW.QDialog.Accepted: ( external_port, protocol, internal_port, description, duration ) = dlg.GetInfo() remove_existing = False if self._MappingExists( external_port, protocol ): remove_existing = True text = '{}:({}) is already mapped! Ok to overwrite whatever it currently is?' result = ClientGUIDialogsQuick.GetYesNo( self, text, yes_label = 'do it', no_label = 'forget it' ) if result != QW.QDialog.Accepted: return def work_callable(): if remove_existing: HydrusNATPunch.RemoveUPnPMapping( external_port, protocol ) internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, protocol, description, duration = duration ) return True def publish_callable( result ): self._mappings_listctrl_panel.setEnabled( True ) self._RefreshMappings() self._mappings_listctrl_panel.setEnabled( False ) async_job = ClientGUIAsync.AsyncQtJob( self, work_callable, publish_callable ) async_job.start()
def _Edit( self ): selected_mappings = self._mappings_list.GetData( only_selected = True ) if len( selected_mappings ) > 0: selected_mapping = selected_mappings[0] ( description, internal_ip, internal_port, old_external_port, old_protocol, duration ) = selected_mapping with ClientGUIDialogs.DialogInputUPnPMapping( self, old_external_port, old_protocol, internal_port, description, duration ) as dlg: if dlg.exec() == QW.QDialog.Accepted: ( external_port, protocol, internal_port, description, duration ) = dlg.GetInfo() remove_old = self._MappingExists( old_external_port, old_protocol ) remove_existing = ( old_external_port != external_port or old_protocol != protocol ) and self._MappingExists( external_port, protocol ) def work_callable(): if remove_old: HydrusNATPunch.RemoveUPnPMapping( old_external_port, old_protocol ) if remove_existing: HydrusNATPunch.RemoveUPnPMapping( external_port, protocol ) internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, protocol, description, duration = duration ) return True def publish_callable( result ): self._mappings_listctrl_panel.setEnabled( True ) self._RefreshMappings() self._mappings_listctrl_panel.setEnabled( False ) async_job = ClientGUIAsync.AsyncQtJob( self, work_callable, publish_callable ) async_job.start()
def _Add(self): do_refresh = False external_port = HC.DEFAULT_SERVICE_PORT protocol = 'TCP' internal_port = HC.DEFAULT_SERVICE_PORT description = 'hydrus service' duration = 0 with ClientGUIDialogs.DialogInputUPnPMapping(self, external_port, protocol, internal_port, description, duration) as dlg: if dlg.exec() == QW.QDialog.Accepted: (external_port, protocol, internal_port, description, duration) = dlg.GetInfo() for (existing_description, existing_internal_ip, existing_internal_port, existing_external_port, existing_protocol, existing_lease) in self._mappings: if external_port == existing_external_port and protocol == existing_protocol: QW.QMessageBox.critical( self, 'Error', 'That external port already exists!') return internal_client = HydrusNATPunch.GetLocalIP() HydrusNATPunch.AddUPnPMapping(internal_client, internal_port, external_port, protocol, description, duration=duration) do_refresh = True if do_refresh: self._RefreshMappings()