-
-
Notifications
You must be signed in to change notification settings - Fork 419
PICARD-2287: Copy and Paste multiple Tags #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6dfe80f
Fixed bug in copying with multiple files selected
StevilKnevil d85a6ca
Copy multiple tags as JSON
StevilKnevil f032b58
Paste JSON as tags
StevilKnevil cd84954
Merge remote-tracking branch 'upstream/master'
StevilKnevil c9a8fbb
Merge remote-tracking branch 'upstream/master'
StevilKnevil b228e2b
Store the json as a custom mimetype on the clipboard
StevilKnevil 5884cf1
Merge remote-tracking branch 'upstream/master' into copy-paste-multip…
StevilKnevil ad035ad
Added Tests and escaped TSV
StevilKnevil c5ab0bc
Move code from _paste_value() to new _paste_multiple() and _load_data…
zas 73eeee5
Move code from _paste_value() to new _paste_single()
zas be0012b
Split _set_tag_values() into _set_tag_values_delayed_updates() and _u…
zas 71ed43d
_paste_multiple(): only update objects once
zas 5393143
_paste_single(): delay object updates
zas bd4c317
Move object updating code to _paste_value() and reduce code redundancy
zas 9ad5be3
_update_objects(): do not catch exceptions, as it may hide issues
zas 02336f0
Merge pull request #1 from zas/paste_updates
StevilKnevil 120e08a
Rework Copy & Paste Actions
StevilKnevil f8b688a
Merge pull request #2 from StevilKnevil/Rework-c&p-actions
StevilKnevil de02cd7
More permissive copy
StevilKnevil ad4b168
Added mime data helper
StevilKnevil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2025 Stevil Knevil | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
|
||
from collections import namedtuple | ||
|
||
|
||
class MimeDataHelper: | ||
""" | ||
A registry for encoding and decoding functions based on MIME types. | ||
|
||
This class allows users to register custom encode and decode functions | ||
for specific MIME types. These functions can then be used to handle | ||
data serialization and deserialization for those MIME types. | ||
""" | ||
|
||
MimeConverters = namedtuple('MimeConverters', ('encode_func', 'decode_func')) | ||
|
||
def __init__(self): | ||
self._registry = {} | ||
|
||
def register(self, mimetype, encode_func=None, decode_func=None): | ||
""" | ||
Registers encode and decode functions for a specific MIME type. | ||
|
||
Args: | ||
mimetype (str): The MIME type to register. | ||
encode_func (callable or None): A function that encodes data for the MIME type, or None. | ||
decode_func (callable or None): A function that decodes data for the MIME type, or None. | ||
""" | ||
if encode_func is not None and not callable(encode_func): | ||
raise ValueError("encode_func must be callable or None.") | ||
if decode_func is not None and not callable(decode_func): | ||
raise ValueError("decode_func must be callable or None.") | ||
if self.is_registered(mimetype): | ||
raise ValueError(f"MIME type '{mimetype}' is already registered.") | ||
|
||
self._registry[mimetype] = self.MimeConverters( | ||
encode_func=encode_func, | ||
decode_func=decode_func | ||
) | ||
|
||
def is_registered(self, mimetype): | ||
return mimetype in self._registry | ||
|
||
def encode_func(self, mimetype): | ||
return self._registry[mimetype].encode_func | ||
|
||
def decode_func(self, mimetype): | ||
return self._registry[mimetype].decode_func | ||
|
||
def encode_funcs(self): | ||
""" | ||
Return a generator of registered MIMETYPES and their handling encoding functions. | ||
""" | ||
for mimetype, converters in self._registry.items(): | ||
if converters.encode_func: | ||
yield mimetype, self._registry[mimetype].encode_func | ||
|
||
def decode_funcs(self, mimedata): | ||
""" | ||
Return a generator of decoding functions that can handle mimetypes in the given mimedata. | ||
Args: | ||
mimedata (QMimeData): The MIME data to check. | ||
""" | ||
for mimetype, converters in self._registry.items(): | ||
if mimedata.hasFormat(mimetype) and converters.decode_func: | ||
yield self._registry[mimetype].decode_func |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.