Skip to content

Commit

Permalink
mythmusic: Remove a load of redundant code from playlistcontainer.cpp
Browse files Browse the repository at this point in the history
(cherry picked from commit 09adeb6)

Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information
Paul Harrison authored and stuartm committed Nov 10, 2012
1 parent dc3f3be commit 0b63eb4
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 107 deletions.
5 changes: 0 additions & 5 deletions mythplugins/mythmusic/mythmusic/main.cpp
Expand Up @@ -197,7 +197,6 @@ static void loadMusic()
qApp->processEvents();
usleep(50000);
}
gMusicData->all_playlists->postLoad();

gMusicData->all_streams->createPlaylist();

Expand Down Expand Up @@ -312,8 +311,6 @@ static void runScan(void)
if (gMusicData->all_playlists && gMusicData->all_playlists->cleanOutThreads())
{
gMusicData->all_playlists->save();
int x = gMusicData->all_playlists->getPending();
SavePending(x);
}

// force a complete reload of the tracks and playlists
Expand Down Expand Up @@ -708,8 +705,6 @@ void mythplugin_destroy(void)
if (gMusicData->all_playlists && gMusicData->all_playlists->cleanOutThreads())
{
gMusicData->all_playlists->save();
int x = gMusicData->all_playlists->getPending();
SavePending(x);
}

delete gPlayer;
Expand Down
1 change: 0 additions & 1 deletion mythplugins/mythmusic/mythmusic/metadata.cpp
Expand Up @@ -1834,7 +1834,6 @@ void MusicData::reloadMusic(void)
qApp->processEvents();
usleep(50000);
}
all_playlists->postLoad();

if (busy)
busy->Close();
Expand Down
93 changes: 2 additions & 91 deletions mythplugins/mythmusic/mythmusic/playlistcontainer.cpp
Expand Up @@ -48,10 +48,8 @@ bool PlaylistContainer::checkCDTrack(int track)

PlaylistContainer::PlaylistContainer(
AllMusic *all_music, const QString &host_name) :
m_activePlaylist(NULL), m_backupPlaylist(NULL),
m_streamPlaylist(NULL),
m_allPlaylists(NULL), m_allMusic(all_music),
m_pendingWritebackIndex(-1),
m_activePlaylist(NULL), m_streamPlaylist(NULL),
m_allPlaylists(NULL), m_allMusic(all_music),

m_playlistsLoader(new PlaylistLoadingThread(this, all_music)),
m_doneLoading(false), m_myHost(host_name),
Expand All @@ -72,8 +70,6 @@ PlaylistContainer::~PlaylistContainer()

if (m_activePlaylist)
delete m_activePlaylist;
if (m_backupPlaylist)
delete m_backupPlaylist;
if (m_streamPlaylist)
delete m_streamPlaylist;
if (m_allPlaylists)
Expand Down Expand Up @@ -102,9 +98,6 @@ void PlaylistContainer::load()
m_activePlaylist = new Playlist();
m_activePlaylist->setParent(this);

m_backupPlaylist = new Playlist();
m_backupPlaylist->setParent(this);

m_streamPlaylist = new Playlist();
m_streamPlaylist->setParent(this);

Expand All @@ -114,19 +107,15 @@ void PlaylistContainer::load()

m_activePlaylist->loadPlaylist("default_playlist_storage", m_myHost);

m_backupPlaylist->loadPlaylist("backup_playlist_storage", m_myHost);

m_streamPlaylist->loadPlaylist("stream_playlist", m_myHost);

MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT playlist_id FROM music_playlists "
"WHERE playlist_name != :DEFAULT"
" AND playlist_name != :BACKUP "
" AND playlist_name != :STREAM "
" AND (hostname = '' OR hostname = :HOST) "
"ORDER BY playlist_name;");
query.bindValue(":DEFAULT", "default_playlist_storage");
query.bindValue(":BACKUP", "backup_playlist_storage");
query.bindValue(":STREAM", "stream_playlist");
query.bindValue(":HOST", m_myHost);

Expand All @@ -146,12 +135,7 @@ void PlaylistContainer::load()
// ... cause it's sitting on this PtrList
}
}
postLoad();

m_pendingWritebackIndex = 0;

int x = gCoreContext->GetNumSetting("LastMusicPlaylistPush");
setPending(x);
m_doneLoading = true;
}

Expand Down Expand Up @@ -212,7 +196,6 @@ void PlaylistContainer::save(void)
}

m_activePlaylist->savePlaylist("default_playlist_storage", m_myHost);
m_backupPlaylist->savePlaylist("backup_playlist_storage", m_myHost);
m_streamPlaylist->savePlaylist("stream_playlist", m_myHost);
}

Expand All @@ -237,36 +220,10 @@ void PlaylistContainer::copyNewPlaylist(QString name)
new_list->Changed();
m_allPlaylists->push_back(new_list);
m_activePlaylist->copyTracks(new_list, false);
m_pendingWritebackIndex = 0;
}

void PlaylistContainer::popBackPlaylist()
{
Playlist *destination = getPlaylist(m_pendingWritebackIndex);
if (!destination)
{
LOG(VB_GENERAL, LOG_WARNING, LOC + "popBackPlaylist() " +
QString("Unknown playlist: %1") .arg(m_pendingWritebackIndex));
return;
}
destination->removeAllTracks();
destination->Changed();
m_activePlaylist->copyTracks(destination, false);
m_activePlaylist->removeAllTracks();
m_backupPlaylist->copyTracks(m_activePlaylist, true);
m_pendingWritebackIndex = 0;

m_activePlaylist->Changed();
m_backupPlaylist->Changed();
}

void PlaylistContainer::copyToActive(int index)
{
m_backupPlaylist->removeAllTracks();
m_activePlaylist->copyTracks(m_backupPlaylist, false);

m_pendingWritebackIndex = index;

m_activePlaylist->removeAllTracks();
Playlist *copy_from = getPlaylist(index);
if (!copy_from)
Expand All @@ -278,7 +235,6 @@ void PlaylistContainer::copyToActive(int index)
copy_from->copyTracks(m_activePlaylist, true);

m_activePlaylist->Changed();
m_backupPlaylist->Changed();
}


Expand All @@ -301,21 +257,6 @@ void PlaylistContainer::deletePlaylist(int kill_me)
QString("Unknown playlist: %1").arg(kill_me));
return;
}
// First, we need to take out any **track** on any other
// playlist that is actually a reference to this
// playlist

if (kill_me == m_pendingWritebackIndex)
popBackPlaylist();

m_activePlaylist->removeTrack(kill_me * -1);

QList<Playlist*>::iterator it = m_allPlaylists->begin();
for (; it != m_allPlaylists->end(); ++it)
{
if ((*it) != list_to_kill)
(*it)->removeTrack(kill_me * -1);
}

MSqlQuery query(MSqlQuery::InitCon());
query.prepare("DELETE FROM music_playlists WHERE playlist_id = :ID ;");
Expand Down Expand Up @@ -354,32 +295,6 @@ QString PlaylistContainer::getPlaylistName(int index, bool &reference)
return QObject::tr("Something is Wrong");
}


void PlaylistContainer::postLoad()
{
//FIXME remove this and the other post load stuff?

// Now that everything is loaded, we need to recheck all
// tracks and update those that refer to a playlist
#if 0
m_activePlaylist->postLoad();
m_backupPlaylist->postLoad();

QList<Playlist*>::iterator it = m_allPlaylists->begin();
for (; it != m_allPlaylists->end(); ++it)
(*it)->postLoad();
#endif
}

bool PlaylistContainer::pendingWriteback()
{
if (m_pendingWritebackIndex > 0)
{
return true;
}
return false;
}

bool PlaylistContainer::nameIsUnique(QString a_name, int which_id)
{
if (a_name == "default_playlist_storage")
Expand Down Expand Up @@ -423,10 +338,6 @@ bool PlaylistContainer::cleanOutThreads()

void PlaylistContainer::clearActive()
{
m_backupPlaylist->removeAllTracks();
m_activePlaylist->removeAllTracks();
m_backupPlaylist->Changed();
m_activePlaylist->Changed();
m_pendingWritebackIndex = 0;
}

10 changes: 0 additions & 10 deletions mythplugins/mythmusic/mythmusic/playlistcontainer.h
Expand Up @@ -43,16 +43,9 @@ class PlaylistContainer

QString getPlaylistName(int index, bool &reference);

void postLoad();

void deletePlaylist(int index);
void renamePlaylist(int index, QString new_name);

void popBackPlaylist();
bool pendingWriteback();
void setPending(int x) {m_pendingWritebackIndex = x;}
int getPending() {return m_pendingWritebackIndex;}

bool nameIsUnique(QString a_name, int which_id);

void clearActive();
Expand All @@ -68,14 +61,11 @@ class PlaylistContainer

private:
Playlist *m_activePlaylist;
Playlist *m_backupPlaylist;
Playlist *m_streamPlaylist;
QList<int> m_cdPlaylist;
QList<Playlist*> *m_allPlaylists;
AllMusic *m_allMusic;

int m_pendingWritebackIndex;

PlaylistLoadingThread *m_playlistsLoader;
bool m_doneLoading;
QString m_myHost;
Expand Down

0 comments on commit 0b63eb4

Please sign in to comment.