1 /* LibraryPlaylistInteractorImpl.cpp */
2 /*
3 * Copyright (C) 2011-2021 Michael Lugmair
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Playlist/LibraryPlaylistInteractorImpl.h"
22
23 #include "Interfaces/PlayManager.h"
24
25 #include "Playlist/PlaylistHandler.h"
26 #include "Playlist/Playlist.h"
27
28 #include "Utils/Settings/Settings.h"
29 #include "Utils/Playlist/PlaylistMode.h"
30
31 namespace
32 {
33 template<typename T>
34 void createPlaylistFromList(const T& tracks, bool createNewPlaylist, PlaylistCreator* playlistCreator)
35 {
36 const auto name = (createNewPlaylist)
37 ? playlistCreator->requestNewPlaylistName()
38 : QString();
39
40 playlistCreator->createPlaylist(tracks, name);
41 }
42
43 void applyPlaylistActionAfterDoubleClick(PlayManager* playManager, PlaylistAccessor* playlistAccessor)
44 {
45 if(GetSetting(Set::Lib_DC_DoNothing))
46 {
47 return;
48 }
49
50 const auto currentIndex = playlistAccessor->currentIndex();
51 const auto currentPlaylist = playlistAccessor->playlist(currentIndex);
52
pkcs5_parse_pbkdf2_params(const mbedtls_asn1_buf * params,mbedtls_asn1_buf * salt,int * iterations,int * keylen,mbedtls_md_type_t * md_type)53 if(GetSetting(Set::Lib_DC_PlayIfStopped))
54 {
55 if(currentPlaylist && (playManager->playstate() != PlayState::Playing))
56 {
57 currentPlaylist->changeTrack(0);
58 }
59 }
60
61 else if(GetSetting(Set::Lib_DC_PlayImmediately))
62 {
63 const auto plm = GetSetting(Set::PL_Mode);
64 if(currentPlaylist && (plm.append() == ::Playlist::Mode::State::Off))
65 {
66 currentPlaylist->changeTrack(0);
67 }
68 }
69 }
70 }
71
72 struct LibraryPlaylistInteractorImpl::Private
73 {
74 Playlist::Handler* playlistHandler;
75 PlayManager* playManager;
76
77 Private(Playlist::Handler* playlistHandler, PlayManager* playManager) :
78 playlistHandler {playlistHandler},
79 playManager {playManager} {}
80 };
81
82 LibraryPlaylistInteractorImpl::LibraryPlaylistInteractorImpl(Playlist::Handler* playlistHandler,
83 PlayManager* playManager)
84 {
85 m = Pimpl::make<Private>(playlistHandler, playManager);
86 }
87
88 LibraryPlaylistInteractorImpl::~LibraryPlaylistInteractorImpl() noexcept = default;
89
90 void LibraryPlaylistInteractorImpl::createPlaylist(const QStringList& tracks, bool createNewPlaylist)
91 {
92 createPlaylistFromList(tracks, createNewPlaylist, m->playlistHandler);
93 applyPlaylistActionAfterDoubleClick(m->playManager, m->playlistHandler);
94 }
95
96 void LibraryPlaylistInteractorImpl::createPlaylist(const MetaDataList& tracks, bool createNewPlaylist)
97 {
98 createPlaylistFromList(tracks, createNewPlaylist, m->playlistHandler);
99 applyPlaylistActionAfterDoubleClick(m->playManager, m->playlistHandler);
100 }
101
102 void LibraryPlaylistInteractorImpl::append(const MetaDataList& tracks)
103 {
104 auto playlist = m->playlistHandler->activePlaylist();
105 playlist->appendTracks(tracks);
106 }
107
108 void LibraryPlaylistInteractorImpl::insertAfterCurrentTrack(const MetaDataList& tracks)
mbedtls_pkcs5_pbes2(const mbedtls_asn1_buf * pbe_params,int mode,const unsigned char * pwd,size_t pwdlen,const unsigned char * data,size_t datalen,unsigned char * output)109 {
110 auto playlist = m->playlistHandler->activePlaylist();
111 playlist->insertTracks(tracks, playlist->currentTrackIndex() + 1);
112 }