21 std::this_thread::sleep_for(250ms);
27#define LOC QString("PlaylistContainer: ")
28#define LOC_WARN QString("PlaylistContainer, Warning: ")
29#define LOC_ERR QString("PlaylistContainer, Error: ")
35 m_ratingWeight(
gCoreContext->GetNumSetting(
"IntelliRatingWeight", 2)),
36 m_playCountWeight(
gCoreContext->GetNumSetting(
"IntelliPlayCountWeight", 2)),
37 m_lastPlayWeight(
gCoreContext->GetNumSetting(
"IntelliLastPlayWeight", 2)),
38 m_randomWeight(
gCoreContext->GetNumSetting(
"IntelliRandomWeight", 2))
63 int &lastplay,
int &random)
const
87 query.
prepare(
"SELECT playlist_id FROM music_playlists "
88 "WHERE playlist_name != :DEFAULT"
89 " AND playlist_name != :BACKUP "
90 " AND playlist_name != :STREAM "
91 " AND (hostname = '' OR hostname = :HOST) "
92 "ORDER BY playlist_name;");
94 query.
bindValue(
":BACKUP",
"backup_playlist_storage");
106 auto *temp_playlist =
new Playlist();
108 temp_playlist->setParent(
this);
109 temp_playlist->loadPlaylistByID(query.
value(0).toInt(),
m_myHost);
133 playlist->describeYourself();
146 auto idmatch = [id](
const auto & playlist)
147 {
return playlist->
getID() == id; };
148 auto it = std::ranges::find_if(std::as_const(*
m_allPlaylists), idmatch);
152 LOG(VB_GENERAL, LOG_ERR,
153 "getPlaylistName() called with unknown index number");
161 auto namematch = [name](
const auto & playlist)
162 {
return playlist->
getName() == name; };
163 auto it = std::ranges::find_if(std::as_const(*
m_allPlaylists), namematch);
167 LOG(VB_GENERAL, LOG_ERR, QString(
"getPlaylistName() called with unknown name: %1").arg(name));
176 if ((*it)->hasChanged())
177 (*it)->savePlaylist((*it)->getName(),
m_myHost);
187 new_list->setParent(
this);
190 new_list->savePlaylist(name,
m_myHost);
198 new_list->setParent(
this);
201 new_list->savePlaylist(name,
m_myHost);
213 LOG(VB_GENERAL, LOG_ERR,
LOC +
"copyToActive() " +
214 QString(
"Unknown playlist: %1").arg(index));
225 list_to_rename->
setName(new_name);
235 LOG(VB_GENERAL, LOG_ERR,
LOC +
"deletePlaylist() " +
236 QString(
"Unknown playlist: %1").arg(kill_me));
244 query.
prepare(
"DELETE FROM music_playlists WHERE playlist_id = :ID ;");
263 auto indexmatch = [index](
const auto & playlist)
264 {
return playlist->getID() == index; };
265 auto it = std::ranges::find_if(std::as_const(*
m_allPlaylists), indexmatch);
267 return (*it)->getName();
270 LOG(VB_GENERAL, LOG_ERR,
LOC +
271 "getPlaylistName() called with unknown index number");
274 return tr(
"Something is Wrong");
282 auto itemfound = [a_name,which_id](
const auto & playlist)
283 {
return playlist->getName() == a_name &&
284 playlist->getID() != which_id; };
285 return std::ranges::none_of(std::as_const(*
m_allPlaylists), itemfound);
294 res.append(playlist->getName());
QSqlQuery wrapper that fetches a DB connection from the connection pool.
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
QVariant value(int i) const
int numRowsAffected() const
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
bool isFinished(void) const
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
static void DBError(const QString &where, const MSqlQuery &query)
void describeYourself(void) const
Playlist * getPlaylist(int id)
PlaylistLoadingThread * m_playlistsLoader
void renamePlaylist(int index, const QString &new_name)
PlaylistContainer(AllMusic *all_music)
void FillIntelliWeights(int &rating, int &playcount, int &lastplay, int &random) const
void copyToActive(int index)
void createNewPlaylist(const QString &name)
QString getPlaylistName(int index, bool &reference)
bool nameIsUnique(const QString &a_name, int which_id)
void deletePlaylist(int kill_me)
Playlist * m_streamPlaylist
QList< Playlist * > * m_allPlaylists
void copyNewPlaylist(const QString &name)
Playlist * m_activePlaylist
QStringList getPlaylistNames(void)
PlaylistContainer * m_parent
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
void setName(const QString &a_name)
void copyTracks(Playlist *to_ptr, bool update_display)
void resync(void)
make sure all tracks are still valid after a scan
void describeYourself(void) const
void removeAllTracks(void)
void setParent(PlaylistContainer *myparent)
void savePlaylist(const QString &a_name, const QString &a_host)
void loadPlaylist(const QString &a_name, const QString &a_host)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
def rating(profile, smoonURL, gate)
static constexpr const char * DEFAULT_STREAMLIST_NAME
static constexpr const char * DEFAULT_PLAYLIST_NAME