def GetNonDupeName(self, name) -> str: existing_names = { service.GetName() for service in self._service_ids_to_services.values() } return HydrusData.GetNonDupeName(name, existing_names)
def _AddNewFavouriteSearch(self, search_row=None): existing_folders_to_names = self._GetExistingFoldersToNames() existing_names = { name for name in itertools.chain.from_iterable( existing_folders_to_names.values()) } if search_row is None: foldername = None name = 'new favourite search' default_local_file_service_key = HG.client_controller.services_manager.GetDefaultLocalFileServiceKey( ) location_search_context = ClientSearch.LocationSearchContext( current_service_keys=[default_local_file_service_key]) file_search_context = ClientSearch.FileSearchContext( location_search_context=location_search_context) synchronised = True media_sort = None media_collect = None else: (foldername, name, file_search_context, synchronised, media_sort, media_collect) = search_row name = HydrusData.GetNonDupeName(name, existing_names) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit favourite search') as dlg: panel = EditFavouriteSearchPanel(dlg, existing_folders_to_names, foldername, name, file_search_context, synchronised, media_sort, media_collect) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: row = panel.GetValue() self._DeleteRow(row[0], row[1]) self._favourite_searches.AddDatas((row, )) self._favourite_searches.Sort()
def _AddNewFavouriteSearch(self, search_row=None): existing_folders_to_names = self._GetExistingFoldersToNames() existing_names = { name for name in itertools.chain.from_iterable( existing_folders_to_names.values()) } if search_row is None: foldername = None name = 'new favourite search' file_search_context = ClientSearch.FileSearchContext( file_service_key=CC.LOCAL_FILE_SERVICE_KEY) synchronised = True media_sort = None media_collect = None else: (foldername, name, file_search_context, synchronised, media_sort, media_collect) = search_row name = HydrusData.GetNonDupeName(name, existing_names) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit favourite search') as dlg: panel = EditFavouriteSearchPanel(dlg, existing_folders_to_names, foldername, name, file_search_context, synchronised, media_sort, media_collect) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: row = panel.GetValue() self._DeleteRow(row[0], row[1]) self._favourite_searches.AddDatas((row, )) self._favourite_searches.Sort()
def GetServiceKeysToContentUpdates( self, media_result: ClientMediaResult.MediaResult, names_and_notes: typing.Collection[ typing.Tuple[ str, str ] ] ): content_updates = [] if self._get_notes: hash = media_result.GetHash() notes_manager = media_result.GetNotesManager() existing_names_to_notes = dict( notes_manager.GetNamesToNotes() ) for ( name, note ) in names_and_notes: if name in self._names_to_name_overrides: name = self._names_to_name_overrides[ name ] elif self._all_name_override is not None: name = self._all_name_override if name in existing_names_to_notes: name_exists = True existing_note = existing_names_to_notes[ name ] name_and_note_exists = existing_note == note new_note_is_an_extension = existing_note in note else: name_exists = False name_and_note_exists = False new_note_is_an_extension = False do_it = True if name_and_note_exists: do_it = False elif name_exists: if new_note_is_an_extension and self._extend_existing_note_if_possible: pass # yes let's do it with current name and note else: if self._conflict_resolution == NOTE_IMPORT_CONFLICT_IGNORE: do_it = False elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_RENAME: existing_names = set( existing_names_to_notes.keys() ) name = HydrusData.GetNonDupeName( name, existing_names ) elif self._conflict_resolution == NOTE_IMPORT_CONFLICT_APPEND: existing_note = existing_names_to_notes[ name ] sep = os.linesep * 2 note = sep.join( ( existing_note, note ) ) if do_it: existing_names_to_notes[ name ] = note content_updates.append( HydrusData.ContentUpdate( HC.CONTENT_TYPE_NOTES, HC.CONTENT_UPDATE_SET, ( hash, name, note ) ) ) service_keys_to_content_updates = {} if len( content_updates ) > 0: service_keys_to_content_updates[ CC.LOCAL_NOTES_SERVICE_KEY ] = content_updates return service_keys_to_content_updates
def SetNonDupeName( self, disallowed_names ): self._name = HydrusData.GetNonDupeName( self._name, disallowed_names )
def SetNonDupeName( obj, disallowed_names ): non_dupe_name = HydrusData.GetNonDupeName( obj.GetName(), disallowed_names ) obj.SetName( non_dupe_name )