Fixes associated with loading new audio/video files or clips from CDs/DVDs and used in Songs
Fixes #582 (closed) (at least partly)
This issue arises because of discrepancies around what is stored in QtCore.Qt.UserRole in the list of items in the media library and in the 'media/media files' settings value, whenever the item relates to an audio or video file.
On openlp initialisation the QtCore.Qt.UserRole values are set to the string values of what is stored in the 'media/media files' setting.
When a new audio or video file is added to the media library, then what is returned from the Qt file dialog is a pathlib.Path instance. This is compared in validate_and_load() in core/lib/mediamanageritem.py with the QtCore.Qt.UserRole values of the media library items, which have been read into an array full_list. This is to find duplicates, but it obviously doesn't find any, as the new file is a Path instance and this is being compared with full_list which is a list of string type.
Then the Path of the new file is added to the full_list array, and the array saved to the 'media/media files' setting. This 'media/media files' setting thus contains a mixture of Path instances and strings of paths for audio/video files:
- strings for those files which were added previously
- Paths for the file (or files) just added.
So in general, when a file is added to the media library, it appears in the 'media/media files' setting as a Path, and continues like that until another file is added to the library, when it then becomes a string of a path.
Within the songs plugin, clicking on new song or edit song results in the files from the media library being read (so that they can be used in setting the Linked Audio). These are read from the 'media/media files' setting and are returned as they are stored there. The songs code expects that the files are Path instances, but only the file(s) last added to the media library will be of type Path; the others will be of type string, and will result in an exception.
There are similar issues associated with clips from CDs/DVDs, when duplicates can again be introduced. These don't cause problems for new/edit song as only files are considered as contenders for the Linked Audio of songs.
This fix does the following:
- For new files and optical clips the Path is changed to a string before checking for duplicates. This enables duplicates to be identified correctly.
- New files and optical clips are added to the QtCore.Qt.UserRole values and Settings value as strings. This makes it consistent with the other media types. (Note that when this fix is applied the Settings value will continue to contain a mixture of Path and string values for files until a new audio/video file is loaded into the library.)
- The new/edit song functionality is changed to cope with either a string or Path being returned. (This functionality builds up a list of media for the Linked Audio tab and Paths (rather than strings of paths) continue to be entered into the QtCore.Qt.UserRole values of the items in this list of media.)