Exemplo n.º 1
0
 def _GetCurrentSort( self ) -> ClientMedia.MediaSort:
     
     sort_order = self._sort_order_choice.GetValue()
     
     media_sort = ClientMedia.MediaSort( self._sort_type, sort_order )
     
     return media_sort
    def _GetCurrentSort(self) -> ClientMedia.MediaSort:

        sort_order = self._sort_order_choice.GetValue()

        if sort_order is None:

            sort_order = CC.SORT_ASC

        media_sort = ClientMedia.MediaSort(self._sort_type, sort_order)

        return media_sort
Exemplo n.º 3
0
 def CollectValuesChanged( self ):
     
     ( namespaces, rating_service_keys, description ) = self._collect_comboctrl.GetValues()
     
     self._UpdateLabel()
     
     collect_unmatched = self._collect_unmatched.GetValue()
     
     self._media_collect = ClientMedia.MediaCollect( namespaces = namespaces, rating_service_keys = rating_service_keys, collect_unmatched = collect_unmatched )
     
     self._BroadcastCollect()
Exemplo n.º 4
0
 def __init__( self, parent, management_controller = None ):
     
     QW.QWidget.__init__( self, parent )
     
     self._management_controller = management_controller
     
     self._sort_type = ( 'system', CC.SORT_FILES_BY_FILESIZE )
     
     self._sort_type_button = ClientGUICommon.BetterButton( self, 'sort', self._SortTypeButtonClick )
     self._sort_order_choice = ClientGUICommon.BetterChoice( self )
     
     type_width = ClientGUIFunctions.ConvertTextToPixelWidth( self._sort_type_button, 14 )
     
     self._sort_type_button.setMinimumWidth( type_width )
     
     asc_width = ClientGUIFunctions.ConvertTextToPixelWidth( self._sort_order_choice, 14 )
     
     self._sort_order_choice.setMinimumWidth( asc_width )
     
     self._sort_order_choice.addItem( '', CC.SORT_ASC )
     
     self._UpdateSortTypeLabel()
     self._UpdateAscLabels()
     
     #
     
     hbox = QP.HBoxLayout( margin = 0 )
     
     QP.AddToLayout( hbox, self._sort_type_button, CC.FLAGS_EXPAND_BOTH_WAYS )
     QP.AddToLayout( hbox, self._sort_order_choice, CC.FLAGS_CENTER_PERPENDICULAR )
     
     self.setLayout( hbox )
     
     HG.client_controller.sub( self, 'ACollectHappened', 'a_collect_happened' )
     HG.client_controller.sub( self, 'BroadcastSort', 'do_page_sort' )
     
     if self._management_controller is not None and self._management_controller.HasVariable( 'media_sort' ):
         
         media_sort = self._management_controller.GetVariable( 'media_sort' )
         
         try:
             
             self.SetSort( media_sort )
             
         except:
             
             default_sort = ClientMedia.MediaSort( ( 'system', CC.SORT_FILES_BY_FILESIZE ), CC.SORT_ASC )
             
             self.SetSort( default_sort )
             
         
     
     self._sort_order_choice.currentIndexChanged.connect( self.EventSortAscChoice )
    def eventFilter(self, watched, event):

        if watched == self._collect_comboctrl:

            if event.type() == QC.QEvent.MouseButtonPress and event.button(
            ) == QC.Qt.MiddleButton:

                self.SetCollect(
                    ClientMedia.MediaCollect(collect_unmatched=self.
                                             _media_collect.collect_unmatched))

                return True

        return False
    def _UpdateSortTypeLabel(self):

        example_sort = ClientMedia.MediaSort(self._sort_type, CC.SORT_ASC)

        self._sort_type_button.setText(example_sort.GetSortTypeString())

        (sort_metatype, sort_data) = self._sort_type

        show_tdt = sort_metatype == 'namespaces' and HG.client_controller.new_options.GetBoolean(
            'advanced_mode')

        if show_tdt:

            if sort_metatype == 'namespaces':

                (namespaces, current_tag_display_type) = sort_data

                tag_display_types = [
                    ClientTags.TAG_DISPLAY_ACTUAL,
                    ClientTags.TAG_DISPLAY_SELECTION_LIST,
                    ClientTags.TAG_DISPLAY_SINGLE_MEDIA
                ]

                choice_tuples = [
                    (ClientTags.tag_display_str_lookup[tag_display_type],
                     tag_display_type)
                    for tag_display_type in tag_display_types
                ]

                self._sort_tag_display_type_button.blockSignals(True)

                self._sort_tag_display_type_button.SetChoiceTuples(
                    choice_tuples)

                self._sort_tag_display_type_button.SetValue(
                    current_tag_display_type)

                self._sort_tag_display_type_button.blockSignals(False)

        self._sort_tag_display_type_button.setVisible(show_tdt)
Exemplo n.º 7
0
    def _FetchRelatedTags(self, max_time_to_take):
        def do_it(service_key, hash, search_tags, max_results,
                  max_time_to_take):
            def qt_code(predicates):

                if not self or not QP.isValid(self):

                    return

                self._last_fetched_predicates = predicates

                self._UpdateTagDisplay()

                self._have_fetched = True

            predicates = HG.client_controller.Read('related_tags', service_key,
                                                   hash, search_tags,
                                                   max_results,
                                                   max_time_to_take)

            predicates = ClientSearch.SortPredicates(predicates)

            QP.CallAfter(qt_code, predicates)

        self._related_tags.SetPredicates([])

        (m, ) = self._media

        hash = m.GetHash()

        search_tags = ClientMedia.GetMediasTags(
            self._media, self._service_key, ClientTags.TAG_DISPLAY_STORAGE,
            (HC.CONTENT_STATUS_CURRENT, HC.CONTENT_STATUS_PENDING))

        max_results = 100

        HG.client_controller.CallToThread(do_it, self._service_key, hash,
                                          search_tags, max_results,
                                          max_time_to_take)
Exemplo n.º 8
0
def FilterSuggestedTagsForMedia(tags: typing.Sequence[str],
                                medias: typing.Collection[ClientMedia.Media],
                                service_key: bytes) -> typing.List[str]:

    tags_filtered_set = set(tags)

    (current_tags_to_count, deleted_tags_to_count, pending_tags_to_count,
     petitioned_tags_to_count) = ClientMedia.GetMediasTagCount(
         medias, service_key, ClientTags.TAG_DISPLAY_STORAGE)

    current_tags_to_count.update(pending_tags_to_count)

    num_media = len(medias)

    for (tag, count) in current_tags_to_count.items():

        if count == num_media:

            tags_filtered_set.discard(tag)

    tags_filtered = [tag for tag in tags if tag in tags_filtered_set]

    return tags_filtered
Exemplo n.º 9
0
def AddKnownURLsViewCopyMenu(win, menu, focus_media, selected_media=None):

    # figure out which urls this focused file has

    focus_urls = focus_media.GetLocationsManager().GetURLs()

    focus_matched_labels_and_urls = []
    focus_unmatched_urls = []
    focus_labels_and_urls = []

    if len(focus_urls) > 0:

        for url in focus_urls:

            try:

                url_class = HG.client_controller.network_engine.domain_manager.GetURLClass(
                    url)

            except HydrusExceptions.URLClassException:

                continue

            if url_class is None:

                focus_unmatched_urls.append(url)

            else:

                label = url_class.GetName() + ': ' + url

                focus_matched_labels_and_urls.append((label, url))

        focus_matched_labels_and_urls.sort()
        focus_unmatched_urls.sort()

        focus_labels_and_urls = list(focus_matched_labels_and_urls)

        focus_labels_and_urls.extend(
            ((url, url) for url in focus_unmatched_urls))

    # figure out which urls these selected files have

    selected_media_url_classes = set()
    multiple_or_unmatching_selection_url_classes = False

    if selected_media is not None and len(selected_media) > 1:

        selected_media = ClientMedia.FlattenMedia(selected_media)

        SAMPLE_SIZE = 256

        if len(selected_media) > SAMPLE_SIZE:

            selected_media_sample = random.sample(selected_media, SAMPLE_SIZE)

        else:

            selected_media_sample = selected_media

        for media in selected_media_sample:

            media_urls = media.GetLocationsManager().GetURLs()

            for url in media_urls:

                try:

                    url_class = HG.client_controller.network_engine.domain_manager.GetURLClass(
                        url)

                except HydrusExceptions.URLClassException:

                    continue

                if url_class is None:

                    multiple_or_unmatching_selection_url_classes = True

                else:

                    selected_media_url_classes.add(url_class)

        if len(selected_media_url_classes) > 1:

            multiple_or_unmatching_selection_url_classes = True

    if len(focus_labels_and_urls) > 0 or len(
            selected_media_url_classes
    ) > 0 or multiple_or_unmatching_selection_url_classes:

        urls_menu = QW.QMenu(menu)

        urls_visit_menu = QW.QMenu(urls_menu)
        urls_copy_menu = QW.QMenu(urls_menu)

        # copy each this file's urls (of a particular type)

        if len(focus_labels_and_urls) > 0:

            for (label, url) in focus_labels_and_urls:

                ClientGUIMenus.AppendMenuItem(
                    urls_visit_menu, label,
                    'Open this url in your web browser.',
                    ClientPaths.LaunchURLInWebBrowser, url)
                ClientGUIMenus.AppendMenuItem(
                    urls_copy_menu, label, 'Copy this url to your clipboard.',
                    HG.client_controller.pub, 'clipboard', 'text', url)

        # copy this file's urls

        there_are_focus_url_classes_to_action = len(
            focus_matched_labels_and_urls) > 1
        multiple_or_unmatching_focus_url_classes = len(
            focus_unmatched_urls) > 0 and len(
                focus_labels_and_urls
            ) > 1  # if there are unmatched urls and more than one thing total

        if there_are_focus_url_classes_to_action or multiple_or_unmatching_focus_url_classes:

            ClientGUIMenus.AppendSeparator(urls_visit_menu)
            ClientGUIMenus.AppendSeparator(urls_copy_menu)

        if there_are_focus_url_classes_to_action:

            urls = [url for (label, url) in focus_matched_labels_and_urls]

            label = 'open this file\'s ' + HydrusData.ToHumanInt(
                len(urls)) + ' recognised urls in your web browser'

            ClientGUIMenus.AppendMenuItem(
                urls_visit_menu, label, 'Open these urls in your web browser.',
                OpenURLs, urls)

            urls_string = os.linesep.join(urls)

            label = 'copy this file\'s ' + HydrusData.ToHumanInt(
                len(urls)) + ' recognised urls to your clipboard'

            ClientGUIMenus.AppendMenuItem(
                urls_copy_menu, label, 'Copy these urls to your clipboard.',
                HG.client_controller.pub, 'clipboard', 'text', urls_string)

        if multiple_or_unmatching_focus_url_classes:

            urls = [url for (label, url) in focus_labels_and_urls]

            label = 'open this file\'s ' + HydrusData.ToHumanInt(
                len(urls)) + ' urls in your web browser'

            ClientGUIMenus.AppendMenuItem(
                urls_visit_menu, label, 'Open these urls in your web browser.',
                OpenURLs, urls)

            urls_string = os.linesep.join(urls)

            label = 'copy this file\'s ' + HydrusData.ToHumanInt(
                len(urls)) + ' urls to your clipboard'

            ClientGUIMenus.AppendMenuItem(urls_copy_menu, label,
                                          'Copy this url to your clipboard.',
                                          HG.client_controller.pub,
                                          'clipboard', 'text', urls_string)

        # now by url match type

        there_are_selection_url_classes_to_action = len(
            selected_media_url_classes) > 0

        if there_are_selection_url_classes_to_action or multiple_or_unmatching_selection_url_classes:

            ClientGUIMenus.AppendSeparator(urls_visit_menu)
            ClientGUIMenus.AppendSeparator(urls_copy_menu)

        if there_are_selection_url_classes_to_action:

            selected_media_url_classes = list(selected_media_url_classes)

            selected_media_url_classes.sort(
                key=lambda url_class: url_class.GetName())

            for url_class in selected_media_url_classes:

                label = 'open files\' ' + url_class.GetName(
                ) + ' urls in your web browser'

                ClientGUIMenus.AppendMenuItem(
                    urls_visit_menu, label,
                    'Open this url class in your web browser for all files.',
                    OpenMediaURLClassURLs, selected_media, url_class)

                label = 'copy files\' ' + url_class.GetName() + ' urls'

                ClientGUIMenus.AppendMenuItem(
                    urls_copy_menu, label,
                    'Copy this url class for all files.',
                    CopyMediaURLClassURLs, selected_media, url_class)

        # now everything

        if multiple_or_unmatching_selection_url_classes:

            label = 'open all files\' urls'

            ClientGUIMenus.AppendMenuItem(
                urls_visit_menu, label,
                'Open urls in your web browser for all files.', OpenMediaURLs,
                selected_media)

            label = 'copy all files\' urls'

            ClientGUIMenus.AppendMenuItem(urls_copy_menu, label,
                                          'Copy urls for all files.',
                                          CopyMediaURLs, selected_media)

        #

        ClientGUIMenus.AppendMenu(urls_menu, urls_visit_menu, 'open')
        ClientGUIMenus.AppendMenu(urls_menu, urls_copy_menu, 'copy')

        ClientGUIMenus.AppendMenu(menu, urls_menu, 'known urls')
    def test_SERIALISABLE_TYPE_DUPLICATE_ACTION_OPTIONS(self):
        def test(obj, dupe_obj):

            self.assertEqual(obj.ToTuple(), dupe_obj.ToTuple())

        duplicate_action_options_delete_and_move = ClientDuplicates.DuplicateActionOptions(
            [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_MOVE,
              ClientTags.TagFilter())],
            [(TC.LOCAL_RATING_LIKE_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_MOVE),
             (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY,
              HC.CONTENT_MERGE_ACTION_MOVE)])
        duplicate_action_options_copy = ClientDuplicates.DuplicateActionOptions(
            [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_COPY,
              ClientTags.TagFilter())],
            [(TC.LOCAL_RATING_LIKE_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_COPY),
             (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY,
              HC.CONTENT_MERGE_ACTION_COPY)])
        duplicate_action_options_merge = ClientDuplicates.DuplicateActionOptions(
            [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY,
              HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE, ClientTags.TagFilter())],
            [(TC.LOCAL_RATING_LIKE_SERVICE_KEY,
              HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE),
             (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY,
              HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE)])

        inbox = True
        size = 40960
        mime = HC.IMAGE_JPEG
        width = 640
        height = 480
        duration = None
        num_frames = None
        has_audio = False
        num_words = None

        local_locations_manager = ClientMediaManagers.LocationsManager(
            {CC.LOCAL_FILE_SERVICE_KEY, CC.COMBINED_LOCAL_FILE_SERVICE_KEY},
            set(), set(), set(), inbox)
        trash_locations_manager = ClientMediaManagers.LocationsManager(
            {CC.TRASH_SERVICE_KEY, CC.COMBINED_LOCAL_FILE_SERVICE_KEY}, set(),
            set(), set(), inbox)
        deleted_locations_manager = ClientMediaManagers.LocationsManager(
            set(), {CC.COMBINED_LOCAL_FILE_SERVICE_KEY}, set(), set(), inbox)

        # duplicate to generate proper dicts

        one_tags_manager = ClientMediaManagers.TagsManager(
            {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT: {'one'}
                }
            }, {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT: {'one'}
                }
            }).Duplicate()
        two_tags_manager = ClientMediaManagers.TagsManager(
            {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT: {'two'}
                }
            }, {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT: {'two'}
                }
            }).Duplicate()
        substantial_tags_manager = ClientMediaManagers.TagsManager(
            {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT:
                    {'test tag', 'series:namespaced test tag'}
                }
            }, {
                CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: {
                    HC.CONTENT_STATUS_CURRENT:
                    {'test tag', 'series:namespaced test tag'}
                }
            }).Duplicate()
        empty_tags_manager = ClientMediaManagers.TagsManager({},
                                                             {}).Duplicate()

        one_ratings_manager = ClientMediaManagers.RatingsManager({
            TC.LOCAL_RATING_LIKE_SERVICE_KEY:
            1.0,
            TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY:
            0.8
        })
        two_ratings_manager = ClientMediaManagers.RatingsManager({
            TC.LOCAL_RATING_LIKE_SERVICE_KEY:
            0.0,
            TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY:
            0.6
        })
        substantial_ratings_manager = ClientMediaManagers.RatingsManager({
            TC.LOCAL_RATING_LIKE_SERVICE_KEY:
            1.0,
            TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY:
            0.8
        })
        empty_ratings_manager = ClientMediaManagers.RatingsManager({})

        notes_manager = ClientMediaManagers.NotesManager({})

        file_viewing_stats_manager = ClientMediaManagers.FileViewingStatsManager.STATICGenerateEmptyManager(
        )

        #

        local_hash_has_values = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            1, local_hash_has_values, size, mime, width, height, duration,
            num_frames, has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, substantial_tags_manager,
            local_locations_manager, substantial_ratings_manager,
            notes_manager, file_viewing_stats_manager)

        local_media_has_values = ClientMedia.MediaSingleton(media_result)

        #

        other_local_hash_has_values = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            2, other_local_hash_has_values, size, mime, width, height,
            duration, num_frames, has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, substantial_tags_manager,
            local_locations_manager, substantial_ratings_manager,
            notes_manager, file_viewing_stats_manager)

        other_local_media_has_values = ClientMedia.MediaSingleton(media_result)

        #

        local_hash_empty = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            3, local_hash_empty, size, mime, width, height, duration,
            num_frames, has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, empty_tags_manager, local_locations_manager,
            empty_ratings_manager, notes_manager, file_viewing_stats_manager)

        local_media_empty = ClientMedia.MediaSingleton(media_result)

        #

        trashed_hash_empty = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            4, trashed_hash_empty, size, mime, width, height, duration,
            num_frames, has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, empty_tags_manager, trash_locations_manager,
            empty_ratings_manager, notes_manager, file_viewing_stats_manager)

        trashed_media_empty = ClientMedia.MediaSingleton(media_result)

        #

        deleted_hash_empty = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            5, deleted_hash_empty, size, mime, width, height, duration,
            num_frames, has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, empty_tags_manager, deleted_locations_manager,
            empty_ratings_manager, notes_manager, file_viewing_stats_manager)

        deleted_media_empty = ClientMedia.MediaSingleton(media_result)

        #

        one_hash = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            6, one_hash, size, mime, width, height, duration, num_frames,
            has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, one_tags_manager, local_locations_manager,
            one_ratings_manager, notes_manager, file_viewing_stats_manager)

        one_media = ClientMedia.MediaSingleton(media_result)

        #

        two_hash = HydrusData.GenerateKey()

        file_info_manager = ClientMediaManagers.FileInfoManager(
            7, two_hash, size, mime, width, height, duration, num_frames,
            has_audio, num_words)

        media_result = ClientMediaResult.MediaResult(
            file_info_manager, two_tags_manager, local_locations_manager,
            two_ratings_manager, notes_manager, file_viewing_stats_manager)

        two_media = ClientMedia.MediaSingleton(media_result)

        #

        self._dump_and_load_and_test(duplicate_action_options_delete_and_move,
                                     test)
        self._dump_and_load_and_test(duplicate_action_options_copy, test)
        self._dump_and_load_and_test(duplicate_action_options_merge, test)

        #

        def assertSCUEqual(one, two):

            self.assertEqual(
                TC.ConvertServiceKeysToContentUpdatesToComparable(one),
                TC.ConvertServiceKeysToContentUpdatesToComparable(two))

        file_deletion_reason = 'test delete'

        #

        result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates(
            local_media_has_values,
            local_media_empty,
            delete_second=True,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.LOCAL_FILE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES,
                                     HC.CONTENT_UPDATE_DELETE,
                                     {local_hash_empty},
                                     reason=file_deletion_reason)
        ]

        assertSCUEqual(result, scu)

        #

        result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates(
            local_media_has_values,
            trashed_media_empty,
            delete_second=True,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.TRASH_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES,
                                     HC.CONTENT_UPDATE_DELETE,
                                     {trashed_hash_empty},
                                     reason=file_deletion_reason)
        ]

        assertSCUEqual(result, scu)

        #

        result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates(
            local_media_has_values,
            deleted_media_empty,
            delete_second=True,
            file_deletion_reason=file_deletion_reason)

        self.assertEqual(result, {})

        #

        result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates(
            local_media_has_values,
            other_local_media_has_values,
            delete_second=True,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE,
                ('test tag', {other_local_hash_has_values})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE,
                ('series:namespaced test tag', {other_local_hash_has_values}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (None, {other_local_hash_has_values}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (None, {other_local_hash_has_values}))
        ]
        scu[CC.LOCAL_FILE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES,
                                     HC.CONTENT_UPDATE_DELETE,
                                     {other_local_hash_has_values},
                                     reason=file_deletion_reason)
        ]

        assertSCUEqual(result, scu)

        #

        result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates(
            local_media_empty,
            other_local_media_has_values,
            delete_second=True,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('test tag', {local_hash_empty})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD,
                ('series:namespaced test tag', {local_hash_empty})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE,
                ('test tag', {other_local_hash_has_values})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE,
                ('series:namespaced test tag', {other_local_hash_has_values}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (1.0, {local_hash_empty})),
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (None, {other_local_hash_has_values}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (0.8, {local_hash_empty})),
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (None, {other_local_hash_has_values}))
        ]
        scu[CC.LOCAL_FILE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES,
                                     HC.CONTENT_UPDATE_DELETE,
                                     {other_local_hash_has_values},
                                     reason=file_deletion_reason)
        ]

        assertSCUEqual(result, scu)

        #
        #

        result = duplicate_action_options_copy.ProcessPairIntoContentUpdates(
            local_media_has_values,
            local_media_empty,
            file_deletion_reason=file_deletion_reason)

        self.assertEqual(result, {})

        #

        result = duplicate_action_options_copy.ProcessPairIntoContentUpdates(
            local_media_empty,
            other_local_media_has_values,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('test tag', {local_hash_empty})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD,
                ('series:namespaced test tag', {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (1.0, {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (0.8, {local_hash_empty}))
        ]

        assertSCUEqual(result, scu)

        #
        #

        result = duplicate_action_options_merge.ProcessPairIntoContentUpdates(
            local_media_has_values,
            local_media_empty,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('test tag', {local_hash_empty})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD,
                ('series:namespaced test tag', {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (1.0, {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (0.8, {local_hash_empty}))
        ]

        assertSCUEqual(result, scu)

        #

        result = duplicate_action_options_merge.ProcessPairIntoContentUpdates(
            local_media_empty,
            other_local_media_has_values,
            file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('test tag', {local_hash_empty})),
            HydrusData.ContentUpdate(
                HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD,
                ('series:namespaced test tag', {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (1.0, {local_hash_empty}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     (0.8, {local_hash_empty}))
        ]

        assertSCUEqual(result, scu)

        #

        result = duplicate_action_options_merge.ProcessPairIntoContentUpdates(
            one_media, two_media, file_deletion_reason=file_deletion_reason)

        scu = {}

        scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('one', {two_hash})),
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS,
                                     HC.CONTENT_UPDATE_ADD,
                                     ('two', {one_hash}))
        ]
        scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD, (1.0, {two_hash}))
        ]
        scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [
            HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS,
                                     HC.CONTENT_UPDATE_ADD, (0.8, {two_hash}))
        ]

        assertSCUEqual(result, scu)
Exemplo n.º 11
0
    def _PopulateSortMenuOrList(self, menu=None):

        sort_types = []

        menu_items_and_sort_types = []

        submetatypes_to_menus = {}

        for system_sort_type in CC.SYSTEM_SORT_TYPES_SORT_CONTROL_SORTED:

            sort_type = ('system', system_sort_type)

            sort_types.append(sort_type)

            if menu is not None:

                submetatype = CC.system_sort_type_submetatype_string_lookup[
                    system_sort_type]

                if submetatype is None:

                    menu_to_add_to = menu

                else:

                    if submetatype not in submetatypes_to_menus:

                        submenu = QW.QMenu(menu)

                        submetatypes_to_menus[submetatype] = submenu

                        ClientGUIMenus.AppendMenu(menu, submenu, submetatype)

                    menu_to_add_to = submetatypes_to_menus[submetatype]

                label = CC.sort_type_basic_string_lookup[system_sort_type]

                menu_item = ClientGUIMenus.AppendMenuItem(
                    menu_to_add_to, label, 'Select this sort type.',
                    self._SetSortTypeFromUser, sort_type)

                menu_items_and_sort_types.append((menu_item, sort_type))

        default_namespace_sorts = HG.client_controller.new_options.GetDefaultNamespaceSorts(
        )

        if menu is not None:

            submenu = QW.QMenu(menu)

            ClientGUIMenus.AppendMenu(menu, submenu, 'namespaces')

        for namespace_sort in default_namespace_sorts:

            sort_type = namespace_sort.sort_type

            sort_types.append(sort_type)

            if menu is not None:

                example_sort = ClientMedia.MediaSort(sort_type, CC.SORT_ASC)

                label = example_sort.GetSortTypeString()

                menu_item = ClientGUIMenus.AppendMenuItem(
                    submenu, label, 'Select this sort type.',
                    self._SetSortTypeFromUser, sort_type)

                menu_items_and_sort_types.append((menu_item, sort_type))

        if menu is not None:

            ClientGUIMenus.AppendMenuItem(submenu, 'custom',
                                          'Set a custom namespace sort',
                                          self._SetCustomNamespaceSortFromUser)

        rating_service_keys = HG.client_controller.services_manager.GetServiceKeys(
            (HC.LOCAL_RATING_LIKE, HC.LOCAL_RATING_NUMERICAL))

        if len(rating_service_keys) > 0:

            if menu is not None:

                submenu = QW.QMenu(menu)

                ClientGUIMenus.AppendMenu(menu, submenu, 'ratings')

            for service_key in rating_service_keys:

                sort_type = ('rating', service_key)

                sort_types.append(sort_type)

                if menu is not None:

                    example_sort = ClientMedia.MediaSort(
                        sort_type, CC.SORT_ASC)

                    label = example_sort.GetSortTypeString()

                    menu_item = ClientGUIMenus.AppendMenuItem(
                        submenu, label, 'Select this sort type.',
                        self._SetSortTypeFromUser, sort_type)

                    menu_items_and_sort_types.append((menu_item, sort_type))

        if menu is not None:

            for (menu_item, sort_choice) in menu_items_and_sort_types:

                if sort_choice == self._sort_type:

                    menu_item.setCheckable(True)
                    menu_item.setChecked(True)

        return sort_types
Exemplo n.º 12
0
 def _UpdateSortTypeLabel( self ):
     
     example_sort = ClientMedia.MediaSort( self._sort_type, CC.SORT_ASC )
     
     self._sort_type_button.setText( example_sort.GetSortTypeString() )