bool CLastFmManager::Unlove(const CMusicInfoTag& musicinfotag, bool askConfirmation /*= true*/) { if (!IsLastFmEnabled()) { CLog::Log(LOGERROR, "LastFmManager Unlove, lasfm is not enabled"); return false; } CStdString strTitle = musicinfotag.GetTitle(); CStdString strArtist = StringUtils::Join(musicinfotag.GetArtist(), g_advancedSettings.m_musicItemSeparator); if (strArtist.IsEmpty()) { CLog::Log(LOGERROR, "Last.fm Unlove no artistname provided."); return false; } if (strTitle.IsEmpty()) { CLog::Log(LOGERROR, "Last.fm Unlove no tracktitle provided."); return false; } CStdString strInfo; strInfo.Format("%s - %s", strArtist, strTitle); if (!askConfirmation || CGUIDialogYesNo::ShowAndGetInput(g_localizeStrings.Get(15200), g_localizeStrings.Get(15297), strInfo, "")) { if (CallXmlRpc("unLoveTrack", strArtist, strTitle)) { //update our local rating, now this is tricky because we only have an artist and title //and don't know if it was a local or radio song. //So we're going to try to get it from the database and check if the rating is 5, //if it is we can assume this was the song we loved before. CMusicDatabase musicdatabase; if (musicdatabase.Open()) { long songid = musicdatabase.GetSongByArtistAndAlbumAndTitle(strArtist, "%", strTitle); if (songid > 0) { CSong song; musicdatabase.GetSongById(songid, song); if (song.rating == '5') { //reset the rating musicdatabase.SetSongRating(song.strFileName, '0'); } } musicdatabase.Close(); } return true; } } return false; }
bool CLastFmManager::Love(const CMusicInfoTag& musicinfotag) { if (!IsLastFmEnabled()) { CLog::Log(LOGERROR, "LastFmManager Love, lastfm is not enabled."); return false; } CStdString strTitle = musicinfotag.GetTitle(); CStdString strArtist = StringUtils::Join(musicinfotag.GetArtist(), g_advancedSettings.m_musicItemSeparator); CStdString strFilePath; if (m_CurrentSong.CurrentSong && !m_CurrentSong.CurrentSong->IsLastFM()) { //path to update the rating for strFilePath = m_CurrentSong.CurrentSong->GetPath(); } if (CallXmlRpc("loveTrack",strArtist, strTitle)) { m_CurrentSong.IsLoved = true; //update the rating to 5, we loved it. CMusicInfoTag newTag(musicinfotag); newTag.SetRating('5'); CApplicationMessenger::Get().SetCurrentSongTag(newTag); //try updating the rating in the database if it's a local file. CMusicDatabase musicdatabase; if (musicdatabase.Open()) { CSong song; //update if the song exists in our database and there is no rating yet. if (musicdatabase.GetSongByFileName(strFilePath, song) && song.rating == '0') { musicdatabase.SetSongRating(strFilePath, '5'); } musicdatabase.Close(); } return true; } return false; }
bool CGUIDialogSongInfo::OnMessage(CGUIMessage& message) { switch (message.GetMessage()) { case GUI_MSG_WINDOW_DEINIT: { if (!m_cancelled && m_startRating != m_song->GetMusicInfoTag()->GetRating()) { CMusicDatabase db; if (db.Open()) // OpenForWrite() ? { db.SetSongRating(m_song->GetPath(), m_song->GetMusicInfoTag()->GetRating()); db.Close(); } m_needsUpdate = true; } else { // cancelled - reset the song rating SetRating(m_startRating); m_needsUpdate = false; } break; } case GUI_MSG_WINDOW_INIT: m_cancelled = false; break; case GUI_MSG_CLICKED: { int iControl = message.GetSenderId(); if (iControl == CONTROL_CANCEL) { m_cancelled = true; Close(); return true; } else if (iControl == CONTROL_OK) { m_cancelled = false; Close(); return true; } else if (iControl == CONTROL_ALBUMINFO) { CGUIWindowMusicBase *window = (CGUIWindowMusicBase *)g_windowManager.GetWindow(WINDOW_MUSIC_NAV); if (window) { CFileItem item(*m_song); CStdString path; path.Format("musicdb://3/%li",m_albumId); item.SetPath(path); item.m_bIsFolder = true; window->OnInfo(&item, true); } return true; } else if (iControl == CONTROL_GETTHUMB) { OnGetThumb(); return true; } } break; } return CGUIDialog::OnMessage(message); }