00001 #include <iostream>
00002 #include <cstdlib>
00003
00004
00005 #include <QKeyEvent>
00006
00007
00008 #include <mythcontext.h>
00009 #include <mythdbcon.h>
00010 #include <mythmainwindow.h>
00011 #include <mythuibuttontree.h>
00012 #include <mythuitext.h>
00013 #include <mythuiutils.h>
00014 #include <mythdialogbox.h>
00015 #include <mythdirs.h>
00016
00017
00018 #include "playlistcontainer.h"
00019 #include "musiccommon.h"
00020 #include "playlisteditorview.h"
00021 #include "smartplaylist.h"
00022 #include "musicutils.h"
00023
00024 MusicGenericTree::MusicGenericTree(MusicGenericTree *parent,
00025 const QString &name, const QString &action,
00026 MythUIButtonListItem::CheckState check,
00027 bool showArrow)
00028 : MythGenericTree(name)
00029 {
00030 m_check = check;
00031 m_action = action;
00032 m_showArrow = showArrow;
00033
00034 if (!action.isEmpty() && !action.isNull())
00035 setSelectable(true);
00036
00037 if (parent)
00038 {
00039 parent->addNode(this);
00040 parent->setDrawArrow(true);
00041 }
00042 }
00043
00044 MusicGenericTree::~MusicGenericTree(void)
00045 {
00046 }
00047
00048 void MusicGenericTree::setDrawArrow(bool flag)
00049 {
00050 m_showArrow = flag;
00051 if (m_buttonItem)
00052 m_buttonItem->setDrawArrow(true);
00053 }
00054
00055 void MusicGenericTree::setCheck(MythUIButtonListItem::CheckState state)
00056 {
00057 m_check = state;
00058 if (m_buttonItem)
00059 {
00060 m_buttonItem->setCheckable(m_check != MythUIButtonListItem::CantCheck);
00061 m_buttonItem->setChecked(m_check);
00062 }
00063 }
00064
00065 MythUIButtonListItem *MusicGenericTree::CreateListButton(MythUIButtonList *list)
00066 {
00067 MusicButtonItem *item = new MusicButtonItem(list, getString());
00068 item->SetData(qVariantFromValue((MythGenericTree*) this));
00069
00070 if (visibleChildCount() > 0)
00071 item->setDrawArrow(true);
00072
00073 if (m_showArrow)
00074 item->setDrawArrow(true);
00075
00076 item->setCheckable(m_check != MythUIButtonListItem::CantCheck);
00077 item->setChecked(m_check);
00078
00079 m_buttonItem = item;
00080
00081 return item;
00082 }
00083
00085
00086 #define LOC QString("PlaylistEditorView: ")
00087 #define LOC_WARN QString("PlaylistEditorView, Warning: ")
00088 #define LOC_ERR QString("PlaylistEditorView, Error: ")
00089
00090 PlaylistEditorView::PlaylistEditorView(MythScreenStack *parent, const QString &layout, bool restorePosition)
00091 :MusicCommon(parent, "playlisteditorview"),
00092 m_layout(layout), m_restorePosition(restorePosition),
00093 m_rootNode(NULL), m_playlistTree(NULL), m_breadcrumbsText(NULL),
00094 m_positionText(NULL)
00095 {
00096 gCoreContext->SaveSetting("MusicPlaylistEditorView", layout);
00097 }
00098
00099 PlaylistEditorView::~PlaylistEditorView()
00100 {
00101 saveTreePosition();
00102
00103 for (int x = 0; x < m_deleteList.count(); x++)
00104 delete m_deleteList.at(x);
00105 m_deleteList.clear();
00106
00107 if (m_rootNode)
00108 delete m_rootNode;
00109 }
00110
00111 bool PlaylistEditorView::Create(void)
00112 {
00113 bool err = false;
00114
00115 QString windowName;
00116
00117 if (m_layout == "gallery")
00118 {
00119 windowName = "playlisteditorview_gallery";
00120 m_currentView = MV_PLAYLISTEDITORGALLERY;
00121 }
00122 else
00123 {
00124 windowName = "playlisteditorview_tree";
00125 m_currentView = MV_PLAYLISTEDITORTREE;
00126 }
00127
00128
00129 err = LoadWindowFromXML("music-ui.xml", windowName, this);
00130
00131 if (!err)
00132 {
00133 gPlayer->removeListener(this);
00134 return false;
00135 }
00136
00137
00138 err = CreateCommon();
00139
00140
00141 UIUtilE::Assign(this, m_playlistTree , "playlist_tree", &err);
00142 UIUtilW::Assign(this, m_breadcrumbsText, "breadcrumbs", &err);
00143 UIUtilW::Assign(this, m_positionText, "position", &err);
00144
00145 if (err)
00146 {
00147 LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'").arg(windowName));
00148 gPlayer->removeListener(this);
00149 return false;
00150 }
00151
00152 createRootNode();
00153
00154 treeNodeChanged(m_rootNode->getChildAt(0));
00155
00156 m_playlistTree->AssignTree(m_rootNode);
00157
00158 if (m_restorePosition)
00159 {
00160 QStringList route = gCoreContext->GetSetting("MusicTreeLastActive", "").split("\n");
00161 restoreTreePosition(route);
00162 }
00163
00164 connect(m_playlistTree, SIGNAL(itemClicked(MythUIButtonListItem*)),
00165 this, SLOT(treeItemClicked(MythUIButtonListItem*)));
00166 connect(m_playlistTree, SIGNAL(nodeChanged(MythGenericTree*)),
00167 this, SLOT(treeNodeChanged(MythGenericTree*)));
00168 connect(m_playlistTree, SIGNAL(itemVisible(MythUIButtonListItem*)),
00169 this, SLOT(treeItemVisible(MythUIButtonListItem*)));
00170
00171 BuildFocusList();
00172
00173 return true;
00174 }
00175
00176 void PlaylistEditorView::customEvent(QEvent *event)
00177 {
00178 if (event->type() == MusicPlayerEvent::MetadataChangedEvent)
00179 {
00180
00181 reloadTree();
00182 }
00183 else if (event->type() == MusicPlayerEvent::AlbumArtChangedEvent)
00184 {
00185
00186 reloadTree();
00187 }
00188 else if (event->type() == MusicPlayerEvent::TrackRemovedEvent)
00189 {
00190 updateSelectedTracks();
00191 }
00192 else if (event->type() == MusicPlayerEvent::TrackAddedEvent)
00193 {
00194 updateSelectedTracks();
00195 }
00196 else if (event->type() == MusicPlayerEvent::AllTracksRemovedEvent)
00197 {
00198 updateSelectedTracks();
00199 }
00200 else if (event->type() == MusicPlayerEvent::PlaylistChangedEvent)
00201 {
00202
00203 reloadTree();
00204 }
00205 else if (event->type() == DialogCompletionEvent::kEventType)
00206 {
00207 DialogCompletionEvent *dce = static_cast<DialogCompletionEvent*>(event);
00208
00209
00210 if (dce->GetResult() < 0)
00211 return;
00212
00213 QString resultid = dce->GetId();
00214 QString resulttext = dce->GetResultText();
00215
00216 if (resultid == "smartplaylistmenu")
00217 {
00218 if (GetFocusWidget() != m_playlistTree)
00219 return;
00220
00221 MythGenericTree *node = m_playlistTree->GetCurrentNode();
00222 if (!node)
00223 return;
00224
00225 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00226 if (!mnode)
00227 return;
00228
00229 if (resulttext == tr("New Smart Playlist"))
00230 {
00231 QString category;
00232 if (mnode->getAction() == "smartplaylistcategory")
00233 category = mnode->getString();
00234
00235 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00236 SmartPlaylistEditor* editor = new SmartPlaylistEditor(mainStack);
00237
00238 if (!editor->Create())
00239 {
00240 delete editor;
00241 return;
00242 }
00243
00244 editor->newSmartPlaylist(category);
00245
00246 connect(editor, SIGNAL(smartPLChanged(const QString&, const QString&)),
00247 this, SLOT(smartPLChanged(QString, QString)));
00248
00249 mainStack->AddScreen(editor);
00250 }
00251 else if (resulttext == tr("Remove Smart Playlist"))
00252 {
00253 QString category = mnode->getParent()->getString();
00254 QString name = mnode->getString();
00255
00256 ShowOkPopup(QString("Are you sure you want to delete this Smart Playlist?\n"
00257 "Category: %1 - Name: %2").arg(category).arg(name),
00258 this, SLOT(deleteSmartPlaylist(bool)), true);
00259 }
00260 else if (resulttext == tr("Edit Smart Playlist"))
00261 {
00262 QString category = mnode->getParent()->getString();
00263 QString name = mnode->getString();
00264
00265 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00266 SmartPlaylistEditor* editor = new SmartPlaylistEditor(mainStack);
00267
00268 if (!editor->Create())
00269 {
00270 delete editor;
00271 return;
00272 }
00273
00274 editor->editSmartPlaylist(category, name);
00275
00276 connect(editor, SIGNAL(smartPLChanged(const QString&, const QString&)),
00277 this, SLOT(smartPLChanged(QString, QString)));
00278
00279 mainStack->AddScreen(editor);
00280 }
00281 else if (resulttext == tr("Replace Tracks"))
00282 {
00283 m_playlistOptions.insertPLOption = PL_REPLACE;
00284 doUpdatePlaylist();
00285 }
00286 else if (resulttext == tr("Add Tracks"))
00287 {
00288 m_playlistOptions.insertPLOption = PL_INSERTATEND;
00289 doUpdatePlaylist();
00290 }
00291 }
00292 else if (resultid == "playlistmenu")
00293 {
00294 if (GetFocusWidget() != m_playlistTree)
00295 return;
00296
00297 MythGenericTree *node = m_playlistTree->GetCurrentNode();
00298 if (!node)
00299 return;
00300
00301 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00302 if (!mnode)
00303 return;
00304
00305 if (resulttext == tr("Remove Playlist"))
00306 {
00307 QString name = mnode->getString();
00308
00309 ShowOkPopup(QString("Are you sure you want to delete this Playlist?\n"
00310 "Name: %1").arg(name),
00311 this, SLOT(deletePlaylist(bool)), true);
00312 }
00313 else if (resulttext == tr("Replace Tracks"))
00314 {
00315 m_playlistOptions.playPLOption = PL_CURRENT;
00316 m_playlistOptions.insertPLOption = PL_REPLACE;
00317 doUpdatePlaylist();
00318 }
00319 else if (resulttext == tr("Add Tracks"))
00320 {
00321 m_playlistOptions.insertPLOption = PL_INSERTATEND;
00322 doUpdatePlaylist();
00323 }
00324 }
00325 }
00326
00327 MusicCommon::customEvent(event);
00328 }
00329
00330 bool PlaylistEditorView::keyPressEvent(QKeyEvent *event)
00331 {
00332 if (!m_moveTrackMode && GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
00333 return true;
00334
00335 bool handled = false;
00336 QStringList actions;
00337 handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
00338
00339 for (int i = 0; i < actions.size() && !handled; i++)
00340 {
00341 QString action = actions[i];
00342 handled = true;
00343
00344 if ((action == "EDIT" || action == "INFO") && GetFocusWidget() == m_playlistTree)
00345 {
00346 handled = false;
00347
00348 MythGenericTree *node = m_playlistTree->GetCurrentNode();
00349 if (node)
00350 {
00351 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00352 if (mnode)
00353 {
00354 if (mnode->getAction() == "smartplaylist" && action == "EDIT")
00355 {
00356 QString category = mnode->getParent()->getString();
00357 QString name = mnode->getString();
00358
00359 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00360 SmartPlaylistEditor* editor = new SmartPlaylistEditor(mainStack);
00361
00362 if (!editor->Create())
00363 {
00364 delete editor;
00365 return true;
00366 }
00367
00368 editor->editSmartPlaylist(category, name);
00369 connect(editor, SIGNAL(smartPLChanged(const QString&, const QString&)),
00370 this, SLOT(smartPLChanged(QString, QString)));
00371
00372 mainStack->AddScreen(editor);
00373
00374 handled = true;
00375 }
00376 else if (mnode->getAction() == "smartplaylistcategory" && action == "EDIT")
00377 {
00378 QString category = mnode->getString();
00379
00380 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00381 SmartPlaylistEditor* editor = new SmartPlaylistEditor(mainStack);
00382
00383 if (!editor->Create())
00384 {
00385 delete editor;
00386 return true;
00387 }
00388
00389 editor->newSmartPlaylist(category);
00390
00391 connect(editor, SIGNAL(smartPLChanged(const QString&, const QString&)),
00392 this, SLOT(smartPLChanged(QString, QString)));
00393
00394 mainStack->AddScreen(editor);
00395
00396 handled = true;
00397 }
00398 else if (mnode->getAction() == "trackid")
00399 {
00400 Metadata *mdata = gMusicData->all_music->getMetadata(mnode->getInt());
00401 if (mdata)
00402 {
00403 if (action == "INFO")
00404 showTrackInfo(mdata);
00405 else
00406 editTrackInfo(mdata);
00407 }
00408
00409 handled = true;
00410 }
00411 }
00412 }
00413 }
00414 else if (action == "DELETE" && GetFocusWidget() == m_playlistTree)
00415 {
00416 handled = false;
00417
00418 MythGenericTree *node = m_playlistTree->GetCurrentNode();
00419 if (node)
00420 {
00421 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00422 if (mnode)
00423 {
00424 if (mnode->getAction() == "smartplaylist")
00425 {
00426 QString category = mnode->getParent()->getString();
00427 QString name = mnode->getString();
00428
00429 ShowOkPopup(QString("Are you sure you want to delete this Smart Playlist?\n"
00430 "Category: %1 - Name: %2").arg(category).arg(name),
00431 this, SLOT(deleteSmartPlaylist(bool)), true);
00432 handled = true;
00433 }
00434 else if (mnode->getAction() == "playlist")
00435 {
00436 QString name = mnode->getString();
00437
00438 ShowOkPopup(QString("Are you sure you want to delete this Playlist?\n"
00439 "Name: %1").arg(name),
00440 this, SLOT(deletePlaylist(bool)), true);
00441 handled = true;
00442 }
00443 }
00444 }
00445 }
00446 else if (action == "MARK")
00447 {
00448 MythUIButtonListItem *item = m_playlistTree->GetItemCurrent();
00449 if (item)
00450 treeItemClicked(item);
00451 }
00452 else
00453 handled = false;
00454 }
00455
00456 if (!handled && MusicCommon::keyPressEvent(event))
00457 handled = true;
00458
00459 if (!handled && MythScreenType::keyPressEvent(event))
00460 handled = true;
00461
00462 return handled;
00463 }
00464
00465 void PlaylistEditorView::ShowMenu(void)
00466 {
00467 if (GetFocusWidget() == m_playlistTree)
00468 {
00469 m_playlistOptions.playPLOption = PL_CURRENT;
00470 m_playlistOptions.insertPLOption = PL_REPLACE;
00471
00472 MythMenu *menu = NULL;
00473 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(m_playlistTree->GetCurrentNode());
00474
00475 if (!mnode)
00476 {
00477 MusicCommon::ShowMenu();
00478 return;
00479 }
00480
00481 if (mnode->getAction() == "smartplaylists" ||
00482 mnode->getAction() == "smartplaylistcategory" ||
00483 mnode->getAction() == "smartplaylist")
00484 {
00485 menu = createSmartPlaylistMenu();
00486 }
00487 else if (mnode->getAction() == "playlists" ||
00488 mnode->getAction() == "playlist")
00489 {
00490 menu = createPlaylistMenu();
00491 }
00492 else if (mnode->getAction() == "trackid")
00493 {
00494 }
00495 else
00496 {
00497 menu = createPlaylistOptionsMenu();
00498
00499 m_songList.clear();
00500 MetadataPtrList *tracks = qVariantValue<MetadataPtrList*> (mnode->GetData());
00501 for (int x = 0; x < tracks->count(); x++)
00502 {
00503 Metadata *mdata = tracks->at(x);
00504 if (mdata)
00505 m_songList.append((int)mdata->ID());
00506 }
00507 }
00508
00509 if (menu)
00510 {
00511 menu->AddItem(tr("More Options"), NULL, createMainMenu());
00512
00513 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00514
00515 MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
00516
00517 if (menuPopup->Create())
00518 popupStack->AddScreen(menuPopup);
00519 else
00520 delete menu;
00521
00522 return;
00523 }
00524 }
00525
00526 MusicCommon::ShowMenu();
00527 }
00528
00529 MythMenu* PlaylistEditorView::createPlaylistMenu(void)
00530 {
00531 MythMenu *menu = NULL;
00532
00533 if (GetFocusWidget() == m_playlistTree)
00534 {
00535 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(m_playlistTree->GetCurrentNode());
00536
00537 if (!mnode)
00538 return NULL;
00539
00540 if (mnode->getAction() == "playlist")
00541 {
00542 menu = new MythMenu(tr("Playlist Actions"), this, "playlistmenu");
00543 menu->AddItem(tr("Replace Tracks"));
00544 menu->AddItem(tr("Add Tracks"));
00545 menu->AddItem(tr("Remove Playlist"));
00546
00547
00548 m_songList.clear();
00549 int playlistID = mnode->getInt();
00550 Playlist *playlist = gMusicData->all_playlists->getPlaylist(playlistID);
00551
00552 if (playlist)
00553 {
00554 SongList songlist = playlist->getSongs();
00555
00556 for (int x = 0; x < songlist.count(); x++)
00557 {
00558 m_songList.append(songlist.at(x)->ID());
00559 }
00560 }
00561 }
00562 }
00563
00564 return menu;
00565 }
00566
00567 MythMenu* PlaylistEditorView::createSmartPlaylistMenu(void)
00568 {
00569 MythMenu *menu = NULL;
00570
00571 if (GetFocusWidget() == m_playlistTree)
00572 {
00573 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(m_playlistTree->GetCurrentNode());
00574
00575 if (!mnode)
00576 return NULL;
00577
00578 if (mnode->getAction() == "smartplaylists" || mnode->getAction() == "smartplaylistcategory")
00579 {
00580 QString label = tr("Smart Playlist Actions");
00581
00582 menu = new MythMenu(label, this, "smartplaylistmenu");
00583
00584 menu->AddItem(tr("New Smart Playlist"));
00585 }
00586 else if (mnode->getAction() == "smartplaylist")
00587 {
00588 menu = new MythMenu(tr("Smart Playlist Actions"), this, "smartplaylistmenu");
00589
00590 menu->AddItem(tr("Replace Tracks"));
00591 menu->AddItem(tr("Add Tracks"));
00592
00593 menu->AddItem(tr("Edit Smart Playlist"));
00594 menu->AddItem(tr("New Smart Playlist"));
00595 menu->AddItem(tr("Remove Smart Playlist"));
00596
00597
00598 m_songList.clear();
00599 QList<MythGenericTree*> *children = mnode->getAllChildren();
00600 for (int x = 0; x < children->count(); x++)
00601 {
00602 MythGenericTree *childnode = children->at(x);
00603 m_songList.append(childnode->getInt());
00604 }
00605 }
00606 }
00607
00608 return menu;
00609 }
00610
00611 void PlaylistEditorView::createRootNode(void )
00612 {
00613 if (!m_rootNode)
00614 m_rootNode = new MusicGenericTree(NULL, "Root Music Node");
00615
00616 MusicGenericTree *node = new MusicGenericTree(m_rootNode, tr("All Tracks"), "all tracks");
00617 node->setDrawArrow(true);
00618 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00619
00620 node = new MusicGenericTree(m_rootNode, tr("Albums"), "albums");
00621 node->setDrawArrow(true);
00622 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00623
00624 node = new MusicGenericTree(m_rootNode, tr("Artists"), "artists");
00625 node->setDrawArrow(true);
00626 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00627
00628 node = new MusicGenericTree(m_rootNode, tr("Genres"), "genres");
00629 node->setDrawArrow(true);
00630 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00631 #if 0
00632 node = new MusicGenericTree(m_rootNode, tr("Tags"), "tags");
00633 node->setDrawArrow(true);
00634 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00635 #endif
00636 node = new MusicGenericTree(m_rootNode, tr("Ratings"), "ratings");
00637 node->setDrawArrow(true);
00638 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00639
00640 node = new MusicGenericTree(m_rootNode, tr("Years"), "years");
00641 node->setDrawArrow(true);
00642 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00643
00644 node = new MusicGenericTree(m_rootNode, tr("Compilations"), "compilations");
00645 node->setDrawArrow(true);
00646
00647 MetadataPtrList *alltracks = gMusicData->all_music->getAllMetadata();
00648 MetadataPtrList *compTracks = new MetadataPtrList;
00649 m_deleteList.append(compTracks);
00650
00651 for (int x = 0; x < alltracks->count(); x++)
00652 {
00653 Metadata *mdata = alltracks->at(x);
00654 if (mdata)
00655 {
00656 if (mdata->Compilation())
00657 compTracks->append(mdata);
00658 }
00659 }
00660 node->SetData(qVariantFromValue(compTracks));
00661
00662 node = new MusicGenericTree(m_rootNode, tr("Directory"), "directory");
00663 node->setDrawArrow(true);
00664 node->SetData(qVariantFromValue(gMusicData->all_music->getAllMetadata()));
00665
00666 node = new MusicGenericTree(m_rootNode, tr("Playlists"), "playlists");
00667 node->setDrawArrow(true);
00668
00669 node = new MusicGenericTree(m_rootNode, tr("Smart Playlists"), "smartplaylists");
00670 node->setDrawArrow(true);
00671 }
00672
00673 void PlaylistEditorView::treeItemClicked(MythUIButtonListItem *item)
00674 {
00675 MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData());
00676 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00677
00678 if (!mnode)
00679 return;
00680
00681 if (mnode->getAction() == "trackid")
00682 {
00683 if (gPlayer->getPlaylist()->checkTrack(mnode->getInt()))
00684 {
00685
00686 gPlayer->removeTrack(mnode->getInt());
00687 mnode->setCheck(MythUIButtonListItem::NotChecked);
00688 }
00689 else
00690 {
00691
00692 gPlayer->addTrack(mnode->getInt(), true);
00693 mnode->setCheck(MythUIButtonListItem::FullChecked);
00694 }
00695 }
00696 else
00697 ShowMenu();
00698 }
00699
00700
00701 void PlaylistEditorView::treeItemVisible(MythUIButtonListItem *item)
00702 {
00703 MythGenericTree *node = qVariantValue<MythGenericTree*> (item->GetData());;
00704 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00705
00706 if (!mnode)
00707 return;
00708
00709 if (item->GetImage().isEmpty())
00710 {
00711 QString artFile;
00712
00713 if (mnode->getAction() == "trackid")
00714 {
00715 Metadata *mdata = gMusicData->all_music->getMetadata(mnode->getInt());
00716 if (mdata)
00717 artFile = mdata->getAlbumArtFile();
00718 }
00719 else if (mnode->getAction() == "album")
00720 {
00721
00722 MetadataPtrList *tracks = qVariantValue<MetadataPtrList*> (node->GetData());
00723 for (int x = 0; x < tracks->count(); x++)
00724 {
00725 Metadata *mdata = tracks->at(x);
00726 if (mdata)
00727 {
00728 artFile = mdata->getAlbumArtFile();
00729 if (!artFile.isEmpty())
00730 break;
00731 }
00732 }
00733 }
00734 else if (mnode->getAction() == "compartist")
00735 {
00736 artFile = findIcon("artist", mnode->getString().toLower());
00737 }
00738 else
00739 {
00740 artFile = findIcon(mnode->getAction(), mnode->getString().toLower());
00741 }
00742
00743 QString state = "default";
00744
00745 if (mnode->getAction() == "all tracks")
00746 {
00747 state = "alltracks";
00748 artFile="blank.png";
00749 }
00750 else if (mnode->getAction() == "genres")
00751 {
00752 state = "genres";
00753 artFile="blank.png";
00754 }
00755 else if (mnode->getAction() == "albums")
00756 {
00757 state = "albums";
00758 artFile="blank.png";
00759 }
00760 else if (mnode->getAction() == "artists")
00761 {
00762 state = "artists";
00763 artFile="blank.png";
00764 }
00765 else if (mnode->getAction() == "compartists")
00766 {
00767 state = "compartists";
00768 artFile="blank.png";
00769 }
00770 else if (mnode->getAction() == "ratings")
00771 {
00772 state = "ratings";
00773 artFile="blank.png";
00774 }
00775 else if (mnode->getAction() == "years")
00776 {
00777 state = "years";
00778 artFile="blank.png";
00779 }
00780 else if (mnode->getAction() == "compilations")
00781 {
00782 state = "compilations";
00783 artFile="blank.png";
00784 }
00785 else if (mnode->getAction() == "directory")
00786 {
00787 state = "directory";
00788 artFile="blank.png";
00789 }
00790 else if (mnode->getAction() == "playlists")
00791 {
00792 state = "playlists";
00793 artFile="blank.png";
00794 }
00795 else if (mnode->getAction() == "smartplaylists")
00796 {
00797 state = "smartplaylists";
00798 artFile="blank.png";
00799 }
00800
00801 item->DisplayState(state, "nodetype");
00802
00803 if (artFile.isEmpty())
00804 item->SetImage("");
00805 else
00806 item->SetImage(artFile);
00807 }
00808 }
00809
00810 void PlaylistEditorView::treeNodeChanged(MythGenericTree *node)
00811 {
00812 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
00813 if (!mnode)
00814 return;
00815
00816 if (m_breadcrumbsText)
00817 {
00818 QString route = node->getRouteByString().join(" -> ");
00819 route = route.remove("Root Music Node -> ");
00820 m_breadcrumbsText->SetText(route);
00821 }
00822
00823 if (m_positionText)
00824 {
00825 m_positionText->SetText(QString(tr("%1 of %2"))
00826 .arg(node->getPosition() + 1)
00827 .arg(node->siblingCount()));
00828 }
00829
00830 if (mnode->childCount() > 0 || mnode->getAction() == "trackid")
00831 return;
00832
00833 if (mnode->getAction() == "smartplaylists")
00834 {
00835 getSmartPlaylistCategories(mnode);
00836 }
00837 else if (mnode->getAction() == "smartplaylistcategory")
00838 {
00839 getSmartPlaylists(mnode);
00840 }
00841 else if (mnode->getAction() == "smartplaylist")
00842 {
00843 getSmartPlaylistTracks(mnode, mnode->getInt());
00844 }
00845 else if (mnode->getAction() == "playlists")
00846 {
00847 getPlaylists(mnode);
00848 }
00849 else if (mnode->getAction() == "playlist")
00850 {
00851 getPlaylistTracks(mnode, mnode->getInt());
00852 }
00853 else
00854 filterTracks(mnode);
00855 }
00856
00857 void PlaylistEditorView::filterTracks(MusicGenericTree *node)
00858 {
00859 MetadataPtrList *tracks = qVariantValue<MetadataPtrList*> (node->GetData());
00860
00861 if (!tracks)
00862 return;
00863
00864 if (node->getAction() == "all tracks")
00865 {
00866 QMap<QString, int> map;
00867
00868 for (int x = 0; x < tracks->count(); x++)
00869 {
00870 Metadata *mdata = tracks->at(x);
00871 if (mdata)
00872 {
00873 map.insertMulti(mdata->Title(), mdata->ID());
00874 }
00875 }
00876
00877 QMap<QString, int>::const_iterator i = map.constBegin();
00878 while (i != map.constEnd())
00879 {
00880 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "trackid");
00881 newnode->setInt(i.value());
00882 newnode->setDrawArrow(false);
00883 bool hasTrack = gPlayer->getPlaylist()->checkTrack(newnode->getInt());
00884 newnode->setCheck( hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
00885 ++i;
00886 }
00887 }
00888 else if (node->getAction() == "artists")
00889 {
00890 QMap<QString, MetadataPtrList*> map;
00891
00892 for (int x = 0; x < tracks->count(); x++)
00893 {
00894 Metadata *mdata = tracks->at(x);
00895 if (mdata)
00896 {
00897 if (map.contains(mdata->Artist()))
00898 {
00899 MetadataPtrList *filteredTracks = map.value(mdata->Artist());
00900 filteredTracks->append(mdata);
00901 }
00902 else
00903 {
00904 MetadataPtrList *filteredTracks = new MetadataPtrList;
00905 m_deleteList.append(filteredTracks);
00906 filteredTracks->append(mdata);
00907 map.insert(mdata->Artist(), filteredTracks);
00908 }
00909 }
00910 }
00911
00912 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
00913 while (i != map.constEnd())
00914 {
00915 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "artist");
00916 newnode->SetData(qVariantFromValue(i.value()));
00917 ++i;
00918 }
00919 }
00920 else if (node->getAction() == "compartists")
00921 {
00922 QMap<QString, MetadataPtrList*> map;
00923
00924 for (int x = 0; x < tracks->count(); x++)
00925 {
00926 Metadata *mdata = tracks->at(x);
00927 if (mdata)
00928 {
00929 if (mdata->CompilationArtist() != mdata->Artist())
00930 {
00931 if (map.contains(mdata->CompilationArtist()))
00932 {
00933 MetadataPtrList *filteredTracks = map.value(mdata->CompilationArtist());
00934 filteredTracks->append(mdata);
00935 }
00936 else
00937 {
00938 MetadataPtrList *filteredTracks = new MetadataPtrList;
00939 m_deleteList.append(filteredTracks);
00940 filteredTracks->append(mdata);
00941 map.insert(mdata->CompilationArtist(), filteredTracks);
00942 }
00943 }
00944 }
00945 }
00946
00947 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
00948 while (i != map.constEnd())
00949 {
00950 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "compartist");
00951 newnode->SetData(qVariantFromValue(i.value()));
00952 ++i;
00953 }
00954 }
00955 else if (node->getAction() == "albums")
00956 {
00957 QMap<QString, MetadataPtrList*> map;
00958
00959 for (int x = 0; x < tracks->count(); x++)
00960 {
00961 Metadata *mdata = tracks->at(x);
00962 if (mdata)
00963 {
00964 if (map.contains(mdata->Album()))
00965 {
00966 MetadataPtrList *filteredTracks = map.value(mdata->Album());
00967 filteredTracks->append(mdata);
00968 }
00969 else
00970 {
00971 MetadataPtrList *filteredTracks = new MetadataPtrList;
00972 m_deleteList.append(filteredTracks);
00973 filteredTracks->append(mdata);
00974 map.insert(mdata->Album(), filteredTracks);
00975 }
00976 }
00977 }
00978
00979 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
00980 while (i != map.constEnd())
00981 {
00982 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "album");
00983 newnode->SetData(qVariantFromValue(i.value()));
00984 ++i;
00985 }
00986
00987 }
00988 else if (node->getAction() == "genres")
00989 {
00990 QMap<QString, MetadataPtrList*> map;
00991
00992 for (int x = 0; x < tracks->count(); x++)
00993 {
00994 Metadata *mdata = tracks->at(x);
00995 if (mdata)
00996 {
00997 if (map.contains(mdata->Genre()))
00998 {
00999 MetadataPtrList *filteredTracks = map.value(mdata->Genre());
01000 filteredTracks->append(mdata);
01001 }
01002 else
01003 {
01004 MetadataPtrList *filteredTracks = new MetadataPtrList;
01005 m_deleteList.append(filteredTracks);
01006 filteredTracks->append(mdata);
01007 map.insert(mdata->Genre(), filteredTracks);
01008 }
01009 }
01010 }
01011
01012 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
01013 while (i != map.constEnd())
01014 {
01015 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "genre");
01016 newnode->SetData(qVariantFromValue(i.value()));
01017 ++i;
01018 }
01019 }
01020 else if (node->getAction() == "ratings")
01021 {
01022 QMap<QString, MetadataPtrList*> map;
01023
01024 for (int x = 0; x < tracks->count(); x++)
01025 {
01026 Metadata *mdata = tracks->at(x);
01027 if (mdata)
01028 {
01029 QString ratingStr = tr("%n Star(s)", "", mdata->Rating());
01030 if (map.contains(ratingStr))
01031 {
01032 MetadataPtrList *filteredTracks = map.value(ratingStr);
01033 filteredTracks->append(mdata);
01034 }
01035 else
01036 {
01037 MetadataPtrList *filteredTracks = new MetadataPtrList;
01038 m_deleteList.append(filteredTracks);
01039 filteredTracks->append(mdata);
01040 map.insert(ratingStr, filteredTracks);
01041 }
01042 }
01043 }
01044
01045 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
01046 while (i != map.constEnd())
01047 {
01048 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "rating");
01049 newnode->SetData(qVariantFromValue(i.value()));
01050 ++i;
01051 }
01052
01053 }
01054 else if (node->getAction() == "years")
01055 {
01056 QMap<QString, MetadataPtrList*> map;
01057
01058 for (int x = 0; x < tracks->count(); x++)
01059 {
01060 Metadata *mdata = tracks->at(x);
01061 if (mdata)
01062 {
01063 QString yearStr = QString("%1").arg(mdata->Year());
01064 if (map.contains(yearStr))
01065 {
01066 MetadataPtrList *filteredTracks = map.value(yearStr);
01067 filteredTracks->append(mdata);
01068 }
01069 else
01070 {
01071 MetadataPtrList *filteredTracks = new MetadataPtrList;
01072 m_deleteList.append(filteredTracks);
01073 filteredTracks->append(mdata);
01074 map.insert(yearStr, filteredTracks);
01075 }
01076 }
01077 }
01078
01079 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
01080 while (i != map.constEnd())
01081 {
01082 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "year");
01083 newnode->SetData(qVariantFromValue(i.value()));
01084 ++i;
01085 }
01086
01087 }
01088 else if (node->getAction() == "directory")
01089 {
01090 QMap<QString, MetadataPtrList*> map;
01091
01092
01093 QString dir;
01094 MusicGenericTree *climber = node;
01095 while (climber)
01096 {
01097 dir = climber->GetText() + '/' + dir;
01098 climber = (MusicGenericTree *) climber->getParent();
01099 }
01100
01101
01102 QString top2 = "Root Music Node/" + tr("Directory") + '/';
01103 if (dir.startsWith(top2))
01104 dir = dir.mid(top2.length());
01105
01106 for (int x = 0; x < tracks->count(); x++)
01107 {
01108 Metadata *mdata = tracks->at(x);
01109 if (mdata)
01110 {
01111 QString filename = mdata->Filename(false);
01112
01113 if (filename.startsWith(dir))
01114 filename = filename.mid(dir.length());
01115
01116 QStringList dirs = filename.split("/");
01117
01118 QString key = dirs.count() > 1 ? dirs[0] : "[TRACK]" + dirs[0];
01119 if (map.contains(key))
01120 {
01121 MetadataPtrList *filteredTracks = map.value(key);
01122 filteredTracks->append(mdata);
01123 }
01124 else
01125 {
01126 MetadataPtrList *filteredTracks = new MetadataPtrList;
01127 m_deleteList.append(filteredTracks);
01128 filteredTracks->append(mdata);
01129 map.insert(key, filteredTracks);
01130 }
01131 }
01132 }
01133
01134
01135 QMap<QString, MetadataPtrList*>::const_iterator i = map.constBegin();
01136 while (i != map.constEnd())
01137 {
01138 if (!i.key().startsWith("[TRACK]"))
01139 {
01140 MusicGenericTree *newnode = new MusicGenericTree(node, i.key(), "directory");
01141 newnode->SetData(qVariantFromValue(i.value()));
01142 }
01143 ++i;
01144 }
01145
01146
01147 i = map.constBegin();
01148 while (i != map.constEnd())
01149 {
01150 if (i.key().startsWith("[TRACK]"))
01151 {
01152 MusicGenericTree *newnode = new MusicGenericTree(node, i.key().mid(7), "trackid");
01153 newnode->setInt(i.value()->at(0)->ID());
01154 newnode->setDrawArrow(false);
01155 bool hasTrack = gPlayer->getPlaylist()->checkTrack(newnode->getInt());
01156 newnode->setCheck( hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
01157 }
01158 ++i;
01159 }
01160 }
01161 else if (node->getAction() == "artist" || node->getAction() == "compartist" ||
01162 node->getAction() == "album" || node->getAction() == "genre" ||
01163 node->getAction() == "rating" || node->getAction() == "year" ||
01164 node->getAction() == "compilations")
01165 {
01166
01167 QStringList fields;
01168 MusicGenericTree *climber = node;
01169 while (climber)
01170 {
01171 fields.append(climber->getAction());
01172 climber = (MusicGenericTree *) climber->getParent();
01173 }
01174
01175 MusicGenericTree *newnode = new MusicGenericTree(node, tr("All Tracks"), "all tracks");
01176 newnode->setDrawArrow(true);
01177 newnode->SetData(node->GetData());
01178
01179 if (!fields.contains("albums"))
01180 {
01181 newnode = new MusicGenericTree(node, tr("Albums"), "albums");
01182 newnode->setDrawArrow(true);
01183 newnode->SetData(node->GetData());
01184 }
01185
01186 if (!fields.contains("artists"))
01187 {
01188 newnode = new MusicGenericTree(node, tr("Artists"), "artists");
01189 newnode->setDrawArrow(true);
01190 newnode->SetData(node->GetData());
01191 }
01192
01193 if (!fields.contains("compartists"))
01194 {
01195
01196 bool showCompArtists = false;
01197 MusicGenericTree *mnode = node;
01198 do
01199 {
01200 if (mnode->getAction() == "compilations")
01201 {
01202 showCompArtists = true;
01203 break;
01204 }
01205
01206 mnode = (MusicGenericTree *) mnode->getParent();
01207
01208 } while (mnode);
01209
01210
01211 bool found = false;
01212 MetadataPtrList *tracks = qVariantValue<MetadataPtrList*> (node->GetData());
01213 for (int x = 0; x < tracks->count(); x++)
01214 {
01215 Metadata *mdata = tracks->at(x);
01216 if (mdata)
01217 {
01218 if (mdata->Artist() != mdata->CompilationArtist())
01219 {
01220 found = true;
01221 break;
01222 }
01223 }
01224 }
01225
01226 if (showCompArtists && found)
01227 {
01228 newnode = new MusicGenericTree(node, tr("Compilation Artists"), "compartists");
01229 newnode->setDrawArrow(true);
01230 newnode->SetData(node->GetData());
01231 }
01232 }
01233
01234 if (!fields.contains("genres"))
01235 {
01236 newnode = new MusicGenericTree(node, tr("Genres"), "genres");
01237 newnode->setDrawArrow(true);
01238 newnode->SetData(node->GetData());
01239 }
01240 #if 0
01241 if (!fields.contains("tags"))
01242 {
01243 newnode = new MusicGenericTree(node, tr("Tags"), "tags");
01244 newnode->setDrawArrow(true);
01245 newnode->SetData(node->GetData());
01246 }
01247 #endif
01248 if (!fields.contains("ratings"))
01249 {
01250 newnode = new MusicGenericTree(node, tr("Ratings"), "ratings");
01251 newnode->setDrawArrow(true);
01252 newnode->SetData(node->GetData());
01253 }
01254
01255 if (!fields.contains("years"))
01256 {
01257 newnode = new MusicGenericTree(node, tr("Years"), "years");
01258 newnode->setDrawArrow(true);
01259 newnode->SetData(node->GetData());
01260 }
01261 }
01262 }
01263
01264 void PlaylistEditorView::getSmartPlaylistCategories(MusicGenericTree *node)
01265 {
01266 MSqlQuery query(MSqlQuery::InitCon());
01267
01268 if (query.exec("SELECT categoryid, name FROM music_smartplaylist_categories ORDER BY name;"))
01269 {
01270 if (query.isActive() && query.size() > 0)
01271 {
01272 while (query.next())
01273 {
01274 MusicGenericTree *newnode =
01275 new MusicGenericTree(node, query.value(1).toString(), "smartplaylistcategory");
01276 newnode->setInt(query.value(0).toInt());
01277 }
01278 }
01279 }
01280 else
01281 {
01282 MythDB::DBError("Load smartplaylist categories", query);
01283 }
01284 }
01285
01286 void PlaylistEditorView::getSmartPlaylists(MusicGenericTree *node)
01287 {
01288 int categoryid = node->getInt();
01289
01290 MSqlQuery query(MSqlQuery::InitCon());
01291 query.prepare("SELECT smartplaylistid, name FROM music_smartplaylists WHERE categoryid = :CATEGORYID "
01292 "ORDER BY name;");
01293 query.bindValue(":CATEGORYID", categoryid);
01294 if (query.exec())
01295 {
01296 if (query.isActive() && query.size() > 0)
01297 {
01298 while (query.next())
01299 {
01300 MusicGenericTree *newnode =
01301 new MusicGenericTree(node, query.value(1).toString(), "smartplaylist");
01302 newnode->setInt(query.value(0).toInt());
01303 }
01304 }
01305 }
01306 else
01307 MythDB::DBError("Load smartplaylist names", query);
01308 }
01309
01310 void PlaylistEditorView::getSmartPlaylistTracks(MusicGenericTree *node, int playlistID)
01311 {
01312 MSqlQuery query(MSqlQuery::InitCon());
01313
01314
01315 QString matchType;
01316 QString orderBy;
01317 int limitTo;
01318
01319 query.prepare("SELECT smartplaylistid, matchtype, orderby, limitto "
01320 "FROM music_smartplaylists "
01321 "WHERE smartplaylistid = :SMARTPLAYLISTID;");
01322 query.bindValue(":SMARTPLAYLISTID", playlistID);
01323
01324 if (query.exec())
01325 {
01326 if (query.isActive() && query.size() > 0)
01327 {
01328 query.first();
01329 matchType = (query.value(1).toString() == "All") ? " AND " : " OR ";
01330 orderBy = query.value(2).toString();
01331 limitTo = query.value(3).toInt();
01332 }
01333 else
01334 {
01335 LOG(VB_GENERAL, LOG_WARNING,
01336 LOC + QString("Cannot find smartplaylist: %1").arg(playlistID));
01337 return;
01338 }
01339 }
01340 else
01341 {
01342 MythDB::DBError("Find SmartPlaylist", query);
01343 return;
01344 }
01345
01346
01347 QString whereClause = "WHERE ";
01348
01349 query.prepare("SELECT field, operator, value1, value2 "
01350 "FROM music_smartplaylist_items "
01351 "WHERE smartplaylistid = :ID;");
01352 query.bindValue(":ID", playlistID);
01353 if (query.exec())
01354 {
01355 bool bFirst = true;
01356 while (query.next())
01357 {
01358 QString fieldName = query.value(0).toString();
01359 QString operatorName = query.value(1).toString();
01360 QString value1 = query.value(2).toString();
01361 QString value2 = query.value(3).toString();
01362 if (!bFirst)
01363 whereClause += matchType + getCriteriaSQL(fieldName,
01364 operatorName, value1, value2);
01365 else
01366 {
01367 bFirst = false;
01368 whereClause += " " + getCriteriaSQL(fieldName, operatorName,
01369 value1, value2);
01370 }
01371 }
01372 }
01373
01374
01375 whereClause += getOrderBySQL(orderBy);
01376
01377
01378 if (limitTo > 0)
01379 whereClause += " LIMIT " + QString::number(limitTo);
01380
01381
01382
01383 QString theQuery;
01384
01385 theQuery = "SELECT song_id, name FROM music_songs "
01386 "LEFT JOIN music_directories ON"
01387 " music_songs.directory_id=music_directories.directory_id "
01388 "LEFT JOIN music_artists ON"
01389 " music_songs.artist_id=music_artists.artist_id "
01390 "LEFT JOIN music_albums ON"
01391 " music_songs.album_id=music_albums.album_id "
01392 "LEFT JOIN music_genres ON"
01393 " music_songs.genre_id=music_genres.genre_id "
01394 "LEFT JOIN music_artists AS music_comp_artists ON "
01395 "music_albums.artist_id=music_comp_artists.artist_id ";
01396 if (whereClause.length() > 0)
01397 theQuery += whereClause;
01398
01399 if (!query.exec(theQuery))
01400 {
01401 MythDB::DBError("Load songlist from query", query);
01402 return;
01403 }
01404
01405 while (query.next())
01406 {
01407 MusicGenericTree *newnode =
01408 new MusicGenericTree(node, query.value(1).toString(), "trackid");
01409 newnode->setInt(query.value(0).toInt());
01410 newnode->setDrawArrow(false);
01411 bool hasTrack = gPlayer->getPlaylist()->checkTrack(newnode->getInt());
01412 newnode->setCheck( hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
01413 }
01414
01415
01416 if (node->childCount() == 0)
01417 {
01418 MusicGenericTree *newnode =
01419 new MusicGenericTree(node, tr("** No matching tracks **"), "error");
01420 newnode->setDrawArrow(false);
01421 }
01422 }
01423
01424 void PlaylistEditorView::getPlaylists(MusicGenericTree *node)
01425 {
01426 QList<Playlist*> *playlists = gMusicData->all_playlists->getPlaylists();
01427
01428 for (int x =0; x < playlists->count(); x++)
01429 {
01430 Playlist *playlist = playlists->at(x);
01431 MusicGenericTree *newnode =
01432 new MusicGenericTree(node, playlist->getName(), "playlist");
01433 newnode->setInt(playlist->getID());
01434 }
01435 }
01436
01437 void PlaylistEditorView::getPlaylistTracks(MusicGenericTree *node, int playlistID)
01438 {
01439 Playlist *playlist = gMusicData->all_playlists->getPlaylist(playlistID);
01440 QList<Metadata*> songs = playlist->getSongs();
01441
01442 for (int x = 0; x < songs.count(); x++)
01443 {
01444 Metadata *mdata = songs.at(x);
01445 if (mdata)
01446 {
01447 MusicGenericTree *newnode = new MusicGenericTree(node, mdata->Title(), "trackid");
01448 newnode->setInt(mdata->ID());
01449 newnode->setDrawArrow(false);
01450 bool hasTrack = gPlayer->getPlaylist()->checkTrack(mdata->ID());
01451 newnode->setCheck(hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
01452 }
01453 }
01454
01455
01456 if (node->childCount() == 0)
01457 {
01458 MusicGenericTree *newnode =
01459 new MusicGenericTree(node, tr("** Empty Playlist!! **"), "error");
01460 newnode->setDrawArrow(false);
01461 }
01462 }
01463
01464 void PlaylistEditorView::updateSelectedTracks(void)
01465 {
01466 updateSelectedTracks(m_rootNode);
01467 }
01468
01469 void PlaylistEditorView::updateSelectedTracks(MusicGenericTree *node)
01470 {
01471 for (int x = 0; x < node->childCount(); x++)
01472 {
01473 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node->getChildAt(x));
01474 if (mnode)
01475 {
01476 if (mnode->getAction() == "trackid")
01477 {
01478 bool hasTrack = gPlayer->getPlaylist()->checkTrack(mnode->getInt());
01479 mnode->setCheck(hasTrack ? MythUIButtonListItem::FullChecked : MythUIButtonListItem::NotChecked);
01480 }
01481 else
01482 {
01483 if (mnode->childCount())
01484 updateSelectedTracks(mnode);
01485 }
01486 }
01487 }
01488 }
01489
01490 void PlaylistEditorView::reloadTree(void)
01491 {
01492 QStringList route = m_playlistTree->GetCurrentNode()->getRouteByString();
01493
01494 m_playlistTree->Reset();
01495
01496 for (int x = 0; x < m_deleteList.count(); x++)
01497 delete m_deleteList.at(x);
01498 m_deleteList.clear();
01499
01500 m_rootNode->deleteAllChildren();
01501 createRootNode();
01502 m_playlistTree->AssignTree(m_rootNode);
01503
01504 restoreTreePosition(route);
01505 }
01506
01507 void PlaylistEditorView::restoreTreePosition(const QStringList &route)
01508 {
01509 if (route.count() < 2)
01510 return;
01511
01512
01513 MythGenericTree *node = m_rootNode;
01514 for (int x = 1 ; x < route.count(); x++)
01515 {
01516 node = node->getChildByName(route.at(x));
01517
01518 if (node)
01519 treeNodeChanged(node);
01520 else
01521 break;
01522 }
01523
01524 m_playlistTree->SetNodeByString(route);
01525 }
01526
01527 void PlaylistEditorView::saveTreePosition(void)
01528 {
01529 if (m_playlistTree)
01530 {
01531 QString route = m_playlistTree->GetCurrentNode()->getRouteByString().join("\n");
01532 gCoreContext->SaveSetting("MusicTreeLastActive", route);
01533 }
01534 }
01535
01536 void PlaylistEditorView::smartPLChanged(const QString &category, const QString &name)
01537 {
01538 reloadTree();
01539
01540
01541 QStringList route;
01542 route << "Root Music Node" << tr("Smart Playlists") << category << name;
01543 restoreTreePosition(route);
01544 }
01545
01546 void PlaylistEditorView::deleteSmartPlaylist(bool ok)
01547 {
01548 if (!ok)
01549 return;
01550
01551 MythGenericTree *node = m_playlistTree->GetCurrentNode();
01552 if (node)
01553 {
01554 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
01555 if (mnode)
01556 {
01557 if (mnode->getAction() == "smartplaylist")
01558 {
01559 QString category = mnode->getParent()->getString();
01560 QString name = mnode->getString();
01561
01562 SmartPlaylistEditor::deleteSmartPlaylist(category, name);
01563 reloadTree();
01564 }
01565 }
01566 }
01567 }
01568
01569 void PlaylistEditorView::deletePlaylist(bool ok)
01570 {
01571 if (!ok)
01572 return;
01573
01574 MythGenericTree *node = m_playlistTree->GetCurrentNode();
01575 if (node)
01576 {
01577 MusicGenericTree *mnode = dynamic_cast<MusicGenericTree*>(node);
01578 if (mnode)
01579 {
01580 if (mnode->getAction() == "playlist")
01581 {
01582 int id = mnode->getInt();
01583
01584 gMusicData->all_playlists->deletePlaylist(id);
01585 m_playlistTree->RemoveCurrentItem(true);
01586 }
01587 }
01588 }
01589 }