def _Add(self):

        with ClientGUIDialogs.DialogTextEntry(self,
                                              'enter the ' + self._key_name,
                                              allow_blank=False) as dlg:

            if dlg.exec() == QW.QDialog.Accepted:

                key = dlg.GetValue()

                if key in self._GetExistingKeys():

                    QW.QMessageBox.warning(
                        self, 'Warning',
                        'That {} already exists!'.format(self._key_name))

                    return

                with ClientGUIDialogs.DialogTextEntry(self,
                                                      'enter the ' +
                                                      self._value_name,
                                                      allow_blank=True) as dlg:

                    if dlg.exec() == QW.QDialog.Accepted:

                        value = dlg.GetValue()

                        data = (key, value)

                        self._listctrl.AddDatas((data, ))
    def _Edit(self):

        for data in self._listctrl.GetData(only_selected=True):

            (key, value) = data

            if self._edit_keys:

                with ClientGUIDialogs.DialogTextEntry(
                        self,
                        'edit the ' + self._key_name,
                        default=key,
                        allow_blank=False) as dlg:

                    if dlg.exec() == QW.QDialog.Accepted:

                        edited_key = dlg.GetValue()

                        if edited_key != key and edited_key in self._GetExistingKeys(
                        ):

                            QW.QMessageBox.warning(
                                self, 'Warning',
                                'That {} already exists!'.format(
                                    self._key_name))

                            break

                    else:

                        break

            else:

                edited_key = key

            with ClientGUIDialogs.DialogTextEntry(self,
                                                  'edit the ' +
                                                  self._value_name,
                                                  default=value,
                                                  allow_blank=True) as dlg:

                if dlg.exec() == QW.QDialog.Accepted:

                    edited_value = dlg.GetValue()

                else:

                    break

            self._listctrl.DeleteDatas((data, ))

            edited_data = (edited_key, edited_value)

            self._listctrl.AddDatas((edited_data, ))

        self._listctrl.Sort()
Example #3
0
    def FetchTags(self):

        script = self._script_choice.GetValue()

        if script.UsesUserInput():

            message = 'Enter the custom input for the file lookup script.'

            with ClientGUIDialogs.DialogTextEntry(self, message) as dlg:

                if dlg.exec() != QW.QDialog.Accepted:

                    return

                file_identifier = dlg.GetValue()

        else:

            (m, ) = self._media

            file_identifier = script.ConvertMediaToFileIdentifier(m)

        stop_time = HydrusData.GetNow() + 30

        job_key = ClientThreading.JobKey(cancellable=True, stop_time=stop_time)

        self._script_management.SetJobKey(job_key)

        self._SetTags([])

        HG.client_controller.CallToThread(self.THREADFetchTags, script,
                                          job_key, file_identifier)
Example #4
0
 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()
Example #5
0
 def _Add( self ):
     
     with ClientGUIDialogs.DialogTextEntry( self, 'enter the ' + self._key_name, allow_blank = False ) as dlg:
         
         if dlg.exec() == QW.QDialog.Accepted:
             
             key = dlg.GetValue()
             
             if key in self._GetExistingKeys():
                 
                 QW.QMessageBox.warning( self, 'Warning', 'That {} already exists!'.format( self._key_name ) )
                 
                 return
                 
             
             with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit match' ) as dlg:
                 
                 string_match = ClientParsing.StringMatch()
                 
                 panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, string_match )
                 
                 dlg.SetPanel( panel )
                 
                 if dlg.exec() == QW.QDialog.Accepted:
                     
                     string_match = panel.GetValue()
                     
                     data = ( key, string_match )
                     
                     self._listctrl.AddDatas( ( data, ) )
    def _Edit(self):

        edited_datas = []

        for data in self._listctrl.GetData(only_selected=True):

            (key, string_match) = data

            with ClientGUIDialogs.DialogTextEntry(self,
                                                  'edit the ' + self._key_name,
                                                  default=key,
                                                  allow_blank=False) as dlg:

                if dlg.exec() == QW.QDialog.Accepted:

                    edited_key = dlg.GetValue()

                    if edited_key != key and edited_key in self._GetExistingKeys(
                    ):

                        QW.QMessageBox.warning(
                            self, 'Warning',
                            'That {} already exists!'.format(self._key_name))

                        break

                else:

                    break

            with ClientGUITopLevelWindowsPanels.DialogEdit(
                    self, 'edit match') as dlg:

                string_match = ClientStrings.StringMatch()

                panel = ClientGUIStringPanels.EditStringMatchPanel(
                    dlg, string_match)

                dlg.SetPanel(panel)

                if dlg.exec() == QW.QDialog.Accepted:

                    edited_string_match = panel.GetValue()

                else:

                    break

            self._listctrl.DeleteDatas((data, ))

            edited_data = (edited_key, edited_string_match)

            self._listctrl.AddDatas((edited_data, ))

            edited_datas.append(edited_data)

        self._listctrl.SelectDatas(edited_datas)

        self._listctrl.Sort()
Example #7
0
 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()
Example #8
0
 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()
Example #9
0
        def qt_code():

            with ClientGUIDialogs.DialogChooseNewServiceMethod(None) as dlg:

                HG.test_controller.CallLaterQtSafe(dlg, 1, HitButton,
                                                   dlg._register)

                result = dlg.exec()

                self.assertEqual(result, QW.QDialog.Accepted)

                register = dlg.GetRegister()

                self.assertEqual(register, True)

            with ClientGUIDialogs.DialogChooseNewServiceMethod(None) as dlg:

                HG.test_controller.CallLaterQtSafe(dlg, 1, HitButton,
                                                   dlg._setup)

                result = dlg.exec()

                self.assertEqual(result, QW.QDialog.Accepted)

                register = dlg.GetRegister()

                self.assertEqual(register, False)

            with ClientGUIDialogs.DialogChooseNewServiceMethod(None) as dlg:

                HG.test_controller.CallLaterQtSafe(dlg, 1, HitCancelButton,
                                                   dlg)

                result = dlg.exec()

                self.assertEqual(result, QW.QDialog.Rejected)
    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()
Example #11
0
def ApplyContentApplicationCommandToMedia( parent, command, media ):
    
    data = command.GetData()
    
    ( service_key, content_type, action, value ) = data
    
    try:
        
        service = HG.client_controller.services_manager.GetService( service_key )
        
    except HydrusExceptions.DataMissing:
        
        command_processed = False
        
        return command_processed
        
    
    service_type = service.GetServiceType()
    
    hashes = set()
    
    for m in media:
        
        hashes.add( m.GetHash() )
        
    
    if service_type in HC.REAL_TAG_SERVICES:
        
        tag = value
        
        can_add = False
        can_pend = False
        can_delete = False
        can_petition = True
        can_rescind_pend = False
        can_rescind_petition = False
        
        for m in media:
            
            tags_manager = m.GetTagsManager()
            
            current = tags_manager.GetCurrent( service_key, ClientTags.TAG_DISPLAY_STORAGE )
            pending = tags_manager.GetPending( service_key, ClientTags.TAG_DISPLAY_STORAGE )
            petitioned = tags_manager.GetPetitioned( service_key, ClientTags.TAG_DISPLAY_STORAGE )
            
            if tag not in current:
                
                can_add = True
                
            
            if tag not in current and tag not in pending:
                
                can_pend = True
                
            
            if tag in current and action == HC.CONTENT_UPDATE_FLIP:
                
                can_delete = True
                
            
            if tag in current and tag not in petitioned and action == HC.CONTENT_UPDATE_FLIP:
                
                can_petition = True
                
            
            if tag in pending and action == HC.CONTENT_UPDATE_FLIP:
                
                can_rescind_pend = True
                
            
            if tag in petitioned:
                
                can_rescind_petition = True
                
            
        
        reason = None
        
        if service_type == HC.LOCAL_TAG:
            
            tags = [ tag ]
            
            if can_add:
                
                content_update_action = HC.CONTENT_UPDATE_ADD
                
                tag_parents_manager = HG.client_controller.tag_parents_manager
                
                parents = tag_parents_manager.GetParents( service_key, tag )
                
                tags.extend( parents )
                
            elif can_delete:
                
                content_update_action = HC.CONTENT_UPDATE_DELETE
                
            else:
                
                return True
                
            
            rows = [ ( tag, hashes ) for tag in tags ]
            
        else:
            
            if can_rescind_petition:
                
                content_update_action = HC.CONTENT_UPDATE_RESCIND_PETITION
                
                rows = [ ( tag, hashes ) ]
                
            elif can_pend:
                
                tags = [ tag ]
                
                content_update_action = HC.CONTENT_UPDATE_PEND
                
                tag_parents_manager = HG.client_controller.tag_parents_manager
                
                parents = tag_parents_manager.GetParents( service_key, tag )
                
                tags.extend( parents )
                
                rows = [ ( tag, hashes ) for tag in tags ]
                
            elif can_rescind_pend:
                
                content_update_action = HC.CONTENT_UPDATE_RESCIND_PEND
                
                rows = [ ( tag, hashes ) ]
                
            elif can_petition:
                
                message = 'Enter a reason for this tag to be removed. A janitor will review your petition.'
                
                from hydrus.client.gui import ClientGUIDialogs
                
                with ClientGUIDialogs.DialogTextEntry( parent, message ) as dlg:
                    
                    if dlg.exec() == QW.QDialog.Accepted:
                        
                        content_update_action = HC.CONTENT_UPDATE_PETITION
                        
                        reason = dlg.GetValue()
                        
                        rows = [ ( tag, hashes ) ]
                        
                    else:
                        
                        return True
                        
                    
                
            else:
                
                return True
                
            
        
        content_updates = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, content_update_action, row, reason = reason ) for row in rows ]
        
    elif service_type in ( HC.LOCAL_RATING_LIKE, HC.LOCAL_RATING_NUMERICAL ):
        
        if action in ( HC.CONTENT_UPDATE_SET, HC.CONTENT_UPDATE_FLIP ):
            
            rating = value
            
            can_set = False
            can_unset = False
            
            for m in media:
                
                ratings_manager = m.GetRatingsManager()
                
                current_rating = ratings_manager.GetRating( service_key )
                
                if current_rating == rating and action == HC.CONTENT_UPDATE_FLIP:
                    
                    can_unset = True
                    
                else:
                    
                    can_set = True
                    
                
            
            if can_set:
                
                row = ( rating, hashes )
                
            elif can_unset:
                
                row = ( None, hashes )
                
            else:
                
                return True
                
            
            content_updates = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, row ) ]
            
        elif action in ( HC.CONTENT_UPDATE_INCREMENT, HC.CONTENT_UPDATE_DECREMENT ):
            
            if service_type == HC.LOCAL_RATING_NUMERICAL:
                
                if action == HC.CONTENT_UPDATE_INCREMENT:
                    
                    direction = 1
                    initialisation_rating = 0.0
                    
                elif action == HC.CONTENT_UPDATE_DECREMENT:
                    
                    direction = -1
                    initialisation_rating = 1.0
                    
                
                num_stars = service.GetNumStars()
                
                if service.AllowZero():
                    
                    num_stars += 1
                    
                
                one_star_value = 1.0 / ( num_stars - 1 )
                
                ratings_to_hashes = collections.defaultdict( set )
                
                for m in media:
                    
                    ratings_manager = m.GetRatingsManager()
                    
                    current_rating = ratings_manager.GetRating( service_key )
                    
                    if current_rating is None:
                        
                        new_rating = initialisation_rating
                        
                    else:
                        
                        new_rating = current_rating + ( one_star_value * direction )
                        
                        new_rating = max( min( new_rating, 1.0 ), 0.0 )
                        
                    
                    if current_rating != new_rating:
                        
                        ratings_to_hashes[ new_rating ].add( m.GetHash() )
                        
                    
                
                content_updates = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, ( rating, hashes ) ) for ( rating, hashes ) in ratings_to_hashes.items() ]
                
            else:
                
                return True
                
            
        
    else:
        
        return False
        
    
    if len( content_updates ) > 0:
        
        HG.client_controller.Write( 'content_updates', { service_key : content_updates } )
        
    
    return True
Example #12
0
def GetContentUpdatesForAppliedContentApplicationCommandTags( parent: QW.QWidget, service_key: bytes, service_type: int, action: int, media: typing.Collection[ ClientMedia.MediaSingleton ], tag: str ):
    
    hashes = set()
    
    for m in media:
        
        hashes.add( m.GetHash() )
        
    
    rows = [ ( tag, hashes ) ]
    
    can_add = False
    can_pend = False
    can_delete = False
    can_petition = True
    can_rescind_pend = False
    can_rescind_petition = False
    
    for m in media:
        
        tags_manager = m.GetTagsManager()
        
        current = tags_manager.GetCurrent( service_key, ClientTags.TAG_DISPLAY_STORAGE )
        pending = tags_manager.GetPending( service_key, ClientTags.TAG_DISPLAY_STORAGE )
        petitioned = tags_manager.GetPetitioned( service_key, ClientTags.TAG_DISPLAY_STORAGE )
        
        if tag not in current:
            
            can_add = True
            
        
        if tag not in current and tag not in pending:
            
            can_pend = True
            
        
        if tag in current and action == HC.CONTENT_UPDATE_FLIP:
            
            can_delete = True
            
        
        if tag in current and tag not in petitioned and action == HC.CONTENT_UPDATE_FLIP:
            
            can_petition = True
            
        
        if tag in pending and action == HC.CONTENT_UPDATE_FLIP:
            
            can_rescind_pend = True
            
        
        if tag in petitioned:
            
            can_rescind_petition = True
            
        
    
    reason = None
    
    if service_type == HC.LOCAL_TAG:
        
        if can_add:
            
            content_update_action = HC.CONTENT_UPDATE_ADD
            
        elif can_delete:
            
            content_update_action = HC.CONTENT_UPDATE_DELETE
            
        else:
            
            return []
            
        
    else:
        
        if can_rescind_petition:
            
            content_update_action = HC.CONTENT_UPDATE_RESCIND_PETITION
            
        elif can_pend:
            
            content_update_action = HC.CONTENT_UPDATE_PEND
            
        elif can_rescind_pend:
            
            content_update_action = HC.CONTENT_UPDATE_RESCIND_PEND
            
        elif can_petition:
            
            message = 'Enter a reason for this tag to be removed. A janitor will review your petition.'
            
            from hydrus.client.gui import ClientGUIDialogs
            
            with ClientGUIDialogs.DialogTextEntry( parent, message ) as dlg:
                
                if dlg.exec() == QW.QDialog.Accepted:
                    
                    content_update_action = HC.CONTENT_UPDATE_PETITION
                    
                    reason = dlg.GetValue()
                    
                else:
                    
                    return []
                    
                
            
        else:
            
            return []
            
        
    
    content_updates = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, content_update_action, row, reason = reason ) for row in rows ]
    
    return content_updates