void StreamView::streamItemVisible(MythUIButtonListItem *item) { if (!item) return; if (!item->GetText("imageloaded").isEmpty()) return; Metadata *mdata = qVariantValue<Metadata*> (item->GetData()); if (mdata) { if (!mdata->LogoUrl().isEmpty()) { QString artFile = findIcon("stream", QString("%1").arg(mdata->ID())); if (artFile.isEmpty()) { // download image and cache it for later QUrl url(mdata->LogoUrl()); QFileInfo fi(url.path()); QString saveFilename = GetConfDir() + QString("/MythMusic/Icons/%1/%2.%3") .arg("stream").arg(mdata->ID()).arg(fi.suffix()); GetMythDownloadManager()->queueDownload(mdata->LogoUrl(), saveFilename, this); } else { item->SetImage(artFile); } } else item->SetImage(""); } item->SetText(" ", "imageloaded"); }
void SearchView::trackClicked(MythUIButtonListItem *item) { Metadata *mdata = qVariantValue<Metadata*> (item->GetData()); if (mdata) { if (gPlayer->getPlaylist()->checkTrack(mdata->ID())) gPlayer->getPlaylist()->removeTrack(mdata->ID()); else gPlayer->getPlaylist()->addTrack(mdata->ID(), true); } }
void StreamView::updateStream(Metadata *mdata) { // sanity check this is a radio stream int repo = ID_TO_REPO(mdata->ID()); if (repo != RT_Radio) { LOG(VB_GENERAL, LOG_ERR, "StreamView asked to update a stream but it isn't a radio stream!"); return; } gMusicData->all_streams->updateStream(mdata); // force the icon to reload incase it changed QFile::remove(mdata->getAlbumArtFile()); mdata->reloadAlbumArtImages(); updateStreamList(); // find the stream and make it the active item for (int x = 0; x < m_streamList->GetCount(); x++) { MythUIButtonListItem *item = m_streamList->GetItemAt(x); Metadata *itemsdata = qVariantValue<Metadata*> (item->GetData()); if (itemsdata) { if (mdata->ID() == itemsdata->ID()) { m_streamList->SetItemCurrent(item); break; } } } }
void StreamView::addStream(Metadata *mdata) { // sanity check this is a radio stream int repo = ID_TO_REPO(mdata->ID()); if (repo != RT_Radio) { LOG(VB_GENERAL, LOG_ERR, "StreamView asked to add a stream but it isn't a radio stream!"); return; } gMusicData->all_streams->addStream(mdata); updateStreamList(); // find the new stream and make it the active item for (int x = 0; x < m_streamList->GetCount(); x++) { MythUIButtonListItem *item = m_streamList->GetItemAt(x); Metadata *itemsdata = qVariantValue<Metadata*> (item->GetData()); if (itemsdata) { if (mdata->ID() == itemsdata->ID()) { m_streamList->SetItemCurrent(item); break; } } } }
void AllMusic::addCDTrack(const Metadata &the_track) { Metadata *mdata = new Metadata(the_track); mdata->setID(m_cdData.count() + 1); mdata->setRepo(RT_CD); m_cdData.append(mdata); music_map[mdata->ID()] = mdata; }
void StreamView::updateStreamList(void) { m_streamList->Reset(); bool foundActiveStream = false; for (int x = 0; x < gPlayer->getPlaylist()->getSongs().count(); x++) { Metadata *mdata = gPlayer->getPlaylist()->getSongs().at(x); MythUIButtonListItem *item = new MythUIButtonListItem(m_streamList, "", qVariantFromValue(mdata)); MetadataMap metadataMap; if (mdata) mdata->toMap(metadataMap); item->SetTextFromMap(metadataMap); item->SetText("", "imageloaded"); item->SetFontState("normal"); item->DisplayState("default", "playstate"); // if this is the current radio stream update its play state to match the player if (gPlayer->getCurrentMetadata() && mdata->ID() == gPlayer->getCurrentMetadata()->ID()) { if (gPlayer->isPlaying()) { item->SetFontState("running"); item->DisplayState("playing", "playstate"); } else if (gPlayer->isPaused()) { item->SetFontState("idle"); item->DisplayState("paused", "playstate"); } else { item->SetFontState("normal"); item->DisplayState("stopped", "playstate"); } m_streamList->SetItemCurrent(item); foundActiveStream = true; } } if (m_streamList->GetCount() > 0 && !foundActiveStream) { m_streamList->SetItemCurrent(0); gPlayer->stop(true); } if (m_noStreams) m_noStreams->SetVisible((m_streamList->GetCount() == 0)); if (m_streamList->GetCount() == 0) LOG(VB_GENERAL, LOG_ERR, "StreamView hasn't found any streams!"); }
void SearchView::ShowMenu(void) { if (GetFocusWidget() == m_tracksList) { QString label = tr("Search Actions"); MythMenu *menu = new MythMenu(label, this, "searchviewmenu"); MythUIButtonListItem *item = m_tracksList->GetItemCurrent(); if (item) { Metadata *mdata = qVariantValue<Metadata*> (item->GetData()); if (mdata) { if (gPlayer->getPlaylist()->checkTrack(mdata->ID())) menu->AddItem(tr("Remove From Playlist")); else { menu->AddItem(tr("Add To Playlist")); menu->AddItem(tr("Add To Playlist And Play")); } } } if (GetFocusWidget() == m_tracksList || GetFocusWidget() == m_currentPlaylist) menu->AddItem(tr("Search List...")); menu->AddItem(tr("More Options"), NULL, createMainMenu()); MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); MythDialogBox *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu"); if (menuPopup->Create()) popupStack->AddScreen(menuPopup); else delete menu; } else MusicCommon::ShowMenu(); }
void SearchView::customEvent(QEvent *event) { bool handled = false; if (event->type() == MusicPlayerEvent::TrackRemovedEvent || event->type() == MusicPlayerEvent::TrackAddedEvent) { MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event); if (!mpe) return; int trackID = mpe->TrackID; for (int x = 0; x < m_tracksList->GetCount(); x++) { MythUIButtonListItem *item = m_tracksList->GetItemAt(x); Metadata *mdata = qVariantValue<Metadata*> (item->GetData()); if (mdata && (mdata->ID() == (Metadata::IdType) trackID || trackID == -1)) { if (gPlayer->getPlaylist()->checkTrack(mdata->ID())) item->DisplayState("on", "selectedstate"); else item->DisplayState("off", "selectedstate"); } } // call the default handler in MusicCommon so the playlist and UI is updated MusicCommon::customEvent(event); handled = true; if (m_playTrack) { m_playTrack = false; if (event->type() == MusicPlayerEvent::TrackAddedEvent) { // make the added track current and play it m_currentPlaylist->SetItemCurrent(m_currentPlaylist->GetCount() - 1); playlistItemClicked(m_currentPlaylist->GetItemCurrent()); } } } else if (event->type() == MusicPlayerEvent::AllTracksRemovedEvent) { for (int x = 0; x < m_tracksList->GetCount(); x++) { MythUIButtonListItem *item = m_tracksList->GetItemAt(x); if (item) item->DisplayState("off", "selectedstate"); } } else if (event->type() == MusicPlayerEvent::MetadataChangedEvent) { MusicPlayerEvent *mpe = dynamic_cast<MusicPlayerEvent *>(event); if (!mpe) return; uint trackID = mpe->TrackID; for (int x = 0; x < m_tracksList->GetCount(); x++) { MythUIButtonListItem *item = m_tracksList->GetItemAt(x); Metadata *mdata = qVariantValue<Metadata*> (item->GetData()); if (mdata && mdata->ID() == trackID) { MetadataMap metadataMap; mdata->toMap(metadataMap); item->SetTextFromMap(metadataMap); } } // if (trackID == gPlayer->getCurrentMetadata()->ID()) // updateTrackInfo(gPlayer->getCurrentMetadata()); } else if (event->type() == DialogCompletionEvent::kEventType) { DialogCompletionEvent *dce = dynamic_cast<DialogCompletionEvent *>(event); if (!dce) return; // make sure the user didn't ESCAPE out of the menu if (dce->GetResult() < 0) return; QString resultid = dce->GetId(); QString resulttext = dce->GetResultText(); if (resultid == "searchviewmenu") { if (resulttext == tr("Add To Playlist") || resulttext == tr("Remove From Playlist")) { if (GetFocusWidget() == m_tracksList) { MythUIButtonListItem *item = m_tracksList->GetItemCurrent(); if (item) { m_playTrack = false; trackClicked(item); } } } else if (resulttext == tr("Add To Playlist And Play")) { if (GetFocusWidget() == m_tracksList) { MythUIButtonListItem *item = m_tracksList->GetItemCurrent(); if (item) { m_playTrack = true; trackClicked(item); } } } else if (resulttext == tr("Search List...")) searchButtonList(); } } if (!handled) MusicCommon::customEvent(event); }
void SearchView::updateTracksList(void) { m_tracksList->Reset(); MythUIButtonListItem *item = m_fieldList->GetItemCurrent(); if (!item) return; QString searchStr = m_criteriaEdit->GetText(); int field = item->GetData().toInt(); QString sql; MSqlQuery query(MSqlQuery::InitCon()); if (searchStr.isEmpty()) { sql = "SELECT song_id " "FROM music_songs "; query.prepare(sql); } else { switch(field) { case 1: // artist { sql = "SELECT song_id " "FROM music_songs " "LEFT JOIN music_artists ON " " music_songs.artist_id=music_artists.artist_id " "WHERE music_artists.artist_name LIKE '%" + searchStr + "%' "; query.prepare(sql); break; } case 2: // album { sql = "SELECT song_id " "FROM music_songs " "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id " "WHERE music_albums.album_name LIKE '%" + searchStr + "%' "; query.prepare(sql); break; } case 3: // title { sql = "SELECT song_id " "FROM music_songs " "WHERE music_songs.name LIKE '%" + searchStr + "%' "; query.prepare(sql); break; } case 4: // genre { sql = "SELECT song_id " "FROM music_songs " "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id " "WHERE music_genres.genre LIKE '%" + searchStr + "%' "; query.prepare(sql); break; } case 5: // tags { //TODO add tag query } case 0: // all fields default: { sql = "SELECT song_id " "FROM music_songs " "LEFT JOIN music_artists ON " " music_songs.artist_id=music_artists.artist_id " "LEFT JOIN music_albums ON music_songs.album_id=music_albums.album_id " "LEFT JOIN music_artists AS music_comp_artists ON " " music_albums.artist_id=music_comp_artists.artist_id " "LEFT JOIN music_genres ON music_songs.genre_id=music_genres.genre_id " "WHERE music_songs.name LIKE '%" + searchStr + "%' " "OR music_artists.artist_name LIKE '%" + searchStr + "%' " "OR music_albums.album_name LIKE '%" + searchStr + "%' " "OR music_genres.genre LIKE '%" + searchStr + "%' "; query.prepare(sql); } } } if (!query.exec() || !query.isActive()) { MythDB::DBError("Search music database", query); return; } while (query.next()) { int trackid = query.value(0).toInt(); Metadata *mdata = gMusicData->all_music->getMetadata(trackid); if (mdata) { MythUIButtonListItem *newitem = new MythUIButtonListItem(m_tracksList, ""); newitem->SetData(qVariantFromValue(mdata)); MetadataMap metadataMap; mdata->toMap(metadataMap); newitem->SetTextFromMap(metadataMap); if (gPlayer->getPlaylist()->checkTrack(mdata->ID())) newitem->DisplayState("on", "selectedstate"); else newitem->DisplayState("off", "selectedstate"); // TODO rating state etc } } trackVisible(m_tracksList->GetItemCurrent()); if (m_matchesText) m_matchesText->SetText(QString("%1").arg(m_tracksList->GetCount())); }