2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIDialogVideoInfo.h"
22 #include "Application.h"
23 #include "guilib/GUIWindow.h"
25 #include "guilib/GUIImage.h"
26 #include "utils/StringUtils.h"
27 #include "utils/URIUtils.h"
28 #include "video/windows/GUIWindowVideoNav.h"
29 #include "dialogs/GUIDialogFileBrowser.h"
30 #include "video/VideoInfoScanner.h"
31 #include "ApplicationMessenger.h"
32 #include "video/VideoInfoTag.h"
33 #include "guilib/GUIKeyboardFactory.h"
34 #include "guilib/GUIWindowManager.h"
35 #include "dialogs/GUIDialogOK.h"
36 #include "dialogs/GUIDialogYesNo.h"
37 #include "dialogs/GUIDialogSelect.h"
38 #include "dialogs/GUIDialogProgress.h"
39 #include "filesystem/File.h"
41 #include "storage/MediaManager.h"
42 #include "utils/AsyncFileCopy.h"
43 #include "profiles/ProfilesManager.h"
44 #include "settings/AdvancedSettings.h"
45 #include "settings/MediaSourceSettings.h"
46 #include "settings/Settings.h"
47 #include "guilib/Key.h"
48 #include "guilib/LocalizeStrings.h"
49 #include "GUIUserMessages.h"
50 #include "TextureCache.h"
51 #include "music/MusicDatabase.h"
53 #include "video/VideoThumbLoader.h"
54 #include "filesystem/Directory.h"
55 #include "filesystem/VideoDatabaseDirectory.h"
57 #include "network/upnp/UPnP.h"
61 using namespace XFILE;
63 #define CONTROL_IMAGE 3
64 #define CONTROL_TEXTAREA 4
65 #define CONTROL_BTN_TRACKS 5
66 #define CONTROL_BTN_REFRESH 6
67 #define CONTROL_BTN_PLAY 8
68 #define CONTROL_BTN_RESUME 9
69 #define CONTROL_BTN_GET_THUMB 10
70 #define CONTROL_BTN_PLAY_TRAILER 11
71 #define CONTROL_BTN_GET_FANART 12
72 #define CONTROL_BTN_DIRECTOR 13
74 #define CONTROL_LIST 50
76 CGUIDialogVideoInfo::CGUIDialogVideoInfo(void)
77 : CGUIDialog(WINDOW_DIALOG_VIDEO_INFO, "DialogVideoInfo.xml")
78 , m_movieItem(new CFileItem)
82 m_hasUpdatedThumb = false;
83 m_castList = new CFileItemList;
84 m_loadType = KEEP_IN_MEMORY;
87 CGUIDialogVideoInfo::~CGUIDialogVideoInfo(void)
92 bool CGUIDialogVideoInfo::OnMessage(CGUIMessage& message)
94 switch ( message.GetMessage() )
96 case GUI_MSG_WINDOW_DEINIT:
102 case GUI_MSG_CLICKED:
104 int iControl = message.GetSenderId();
105 if (iControl == CONTROL_BTN_REFRESH)
107 if (m_movieItem->GetVideoInfoTag()->m_iSeason < 0 && !m_movieItem->GetVideoInfoTag()->m_strShowTitle.IsEmpty()) // tv show
109 bool bCanceled=false;
110 if (CGUIDialogYesNo::ShowAndGetInput(20377,20378,-1,-1,bCanceled))
112 m_bRefreshAll = true;
116 db.SetPathHash(m_movieItem->GetVideoInfoTag()->m_strPath,"");
121 m_bRefreshAll = false;
130 else if (iControl == CONTROL_BTN_TRACKS)
132 m_bViewReview = !m_bViewReview;
135 else if (iControl == CONTROL_BTN_PLAY)
139 else if (iControl == CONTROL_BTN_RESUME)
143 else if (iControl == CONTROL_BTN_GET_THUMB)
147 else if (iControl == CONTROL_BTN_PLAY_TRAILER)
151 else if (iControl == CONTROL_BTN_GET_FANART)
155 else if (iControl == CONTROL_BTN_DIRECTOR)
157 CStdString strDirector = StringUtils::Join(m_movieItem->GetVideoInfoTag()->m_director, g_advancedSettings.m_videoItemSeparator);
158 OnSearch(strDirector);
160 else if (iControl == CONTROL_LIST)
162 int iAction = message.GetParam1();
163 if (ACTION_SELECT_ITEM == iAction || ACTION_MOUSE_LEFT_CLICK == iAction)
165 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControl);
167 int iItem = msg.GetParam1();
168 if (iItem < 0 || iItem >= m_castList->Size())
170 CStdString strItem = m_castList->Get(iItem)->GetLabel();
172 strFind.Format(" %s ",g_localizeStrings.Get(20347));
173 int iPos = strItem.Find(strFind);
175 iPos = strItem.size();
176 CStdString tmp = strItem.Left(iPos);
182 case GUI_MSG_NOTIFY_ALL:
184 if (IsActive() && message.GetParam1() == GUI_MSG_UPDATE_ITEM && message.GetItem())
186 CFileItemPtr item = boost::static_pointer_cast<CFileItem>(message.GetItem());
187 if (item && m_movieItem->GetPath().Equals(item->GetPath()))
188 { // Just copy over the stream details and the thumb if we don't already have one
189 if (!m_movieItem->HasArt("thumb"))
190 m_movieItem->SetArt("thumb", item->GetArt("thumb"));
191 m_movieItem->GetVideoInfoTag()->m_streamDetails = item->GetVideoInfoTag()->m_streamDetails;
198 return CGUIDialog::OnMessage(message);
201 void CGUIDialogVideoInfo::OnInitWindow()
204 m_bRefreshAll = true;
205 m_hasUpdatedThumb = false;
206 m_bViewReview = true;
208 CVideoDatabase database;
209 ADDON::ScraperPtr scraper;
213 scraper = database.GetScraperForPath(m_movieItem->GetVideoInfoTag()->GetPath());
217 CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_REFRESH, (CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser) && !StringUtils::StartsWithNoCase(m_movieItem->GetVideoInfoTag()->m_strIMDBNumber, "xx") && scraper);
218 CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_GET_THUMB, (CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser) && !StringUtils::StartsWithNoCase(m_movieItem->GetVideoInfoTag()->m_strIMDBNumber.c_str() + 2, "plugin"));
220 VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType();
221 if (type == VIDEODB_CONTENT_TVSHOWS || type == VIDEODB_CONTENT_MOVIES)
222 CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_GET_FANART, (CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser) && !StringUtils::StartsWithNoCase(m_movieItem->GetVideoInfoTag()->m_strIMDBNumber.c_str() + 2, "plugin"));
224 CONTROL_DISABLE(CONTROL_BTN_GET_FANART);
228 CGUIDialog::OnInitWindow();
231 bool CGUIDialogVideoInfo::OnAction(const CAction &action)
233 if (action.GetID() == ACTION_SHOW_INFO)
238 return CGUIDialog::OnAction(action);
241 void CGUIDialogVideoInfo::SetMovie(const CFileItem *item)
243 *m_movieItem = *item;
244 // setup cast list + determine type. We need to do this here as it makes
245 // sure that content type (among other things) is set correctly for the
246 // old fixed id labels that we have floating around (they may be using
247 // content type to determine visibility, so we'll set the wrong label)
249 VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType();
250 if (type == VIDEODB_CONTENT_MUSICVIDEOS)
252 CMusicDatabase database;
254 const std::vector<std::string> &artists = m_movieItem->GetVideoInfoTag()->m_artist;
255 for (std::vector<std::string>::const_iterator it = artists.begin(); it != artists.end(); ++it)
257 int idArtist = database.GetArtistByName(*it);
258 CStdString thumb = database.GetArtForItem(idArtist, "artist", "thumb");
259 CFileItemPtr item(new CFileItem(*it));
261 item->SetArt("thumb", thumb);
262 item->SetIconImage("DefaultArtist.png");
263 m_castList->Add(item);
265 m_castList->SetContent("musicvideos");
268 { // movie/show/episode
269 for (CVideoInfoTag::iCast it = m_movieItem->GetVideoInfoTag()->m_cast.begin(); it != m_movieItem->GetVideoInfoTag()->m_cast.end(); ++it)
271 CStdString character;
272 if (it->strRole.IsEmpty())
273 character = it->strName;
275 character.Format("%s %s %s", it->strName.c_str(), g_localizeStrings.Get(20347).c_str(), it->strRole.c_str());
276 CFileItemPtr item(new CFileItem(it->strName));
277 if (!it->thumb.IsEmpty())
278 item->SetArt("thumb", it->thumb);
279 else if (CSettings::Get().GetBool("videolibrary.actorthumbs"))
280 { // backward compatibility
281 CStdString thumb = CScraperUrl::GetThumbURL(it->thumbUrl.GetFirstThumb());
282 if (!thumb.IsEmpty())
284 item->SetArt("thumb", thumb);
285 CTextureCache::Get().BackgroundCacheImage(thumb);
288 item->SetIconImage("DefaultActor.png");
289 item->SetLabel(character);
290 m_castList->Add(item);
293 if (type == VIDEODB_CONTENT_TVSHOWS)
295 m_castList->SetContent("tvshows");
296 // special case stuff for shows (not currently retrieved from the library in filemode (ref: GetTvShowInfo vs GetTVShowsByWhere)
297 m_movieItem->m_dateTime = m_movieItem->GetVideoInfoTag()->m_premiered;
298 if(m_movieItem->GetVideoInfoTag()->m_iYear == 0 && m_movieItem->m_dateTime.IsValid())
299 m_movieItem->GetVideoInfoTag()->m_iYear = m_movieItem->m_dateTime.GetYear();
300 m_movieItem->SetProperty("totalepisodes", m_movieItem->GetVideoInfoTag()->m_iEpisode);
301 m_movieItem->SetProperty("numepisodes", m_movieItem->GetVideoInfoTag()->m_iEpisode); // info view has no concept of current watched/unwatched filter as we could come here from files view, but set for consistency
302 m_movieItem->SetProperty("watchedepisodes", m_movieItem->GetVideoInfoTag()->m_playCount);
303 m_movieItem->SetProperty("unwatchedepisodes", m_movieItem->GetVideoInfoTag()->m_iEpisode - m_movieItem->GetVideoInfoTag()->m_playCount);
304 m_movieItem->GetVideoInfoTag()->m_playCount = (m_movieItem->GetVideoInfoTag()->m_iEpisode == m_movieItem->GetVideoInfoTag()->m_playCount) ? 1 : 0;
306 else if (type == VIDEODB_CONTENT_EPISODES)
308 m_castList->SetContent("episodes");
309 // special case stuff for episodes (not currently retrieved from the library in filemode (ref: GetEpisodeInfo vs GetEpisodesByWhere)
310 m_movieItem->m_dateTime = m_movieItem->GetVideoInfoTag()->m_firstAired;
311 if(m_movieItem->GetVideoInfoTag()->m_iYear == 0 && m_movieItem->m_dateTime.IsValid())
312 m_movieItem->GetVideoInfoTag()->m_iYear = m_movieItem->m_dateTime.GetYear();
313 // retrieve the season thumb.
314 // TODO: should we use the thumbloader for this?
318 if (m_movieItem->GetVideoInfoTag()->m_iSeason > -1)
320 int seasonID = m_movieItem->GetVideoInfoTag()->m_iIdSeason;
322 seasonID = db.GetSeasonId(m_movieItem->GetVideoInfoTag()->m_iIdShow,
323 m_movieItem->GetVideoInfoTag()->m_iSeason);
324 CGUIListItem::ArtMap thumbs;
325 if (db.GetArtForItem(seasonID, "season", thumbs))
327 for (CGUIListItem::ArtMap::iterator i = thumbs.begin(); i != thumbs.end(); i++)
328 m_movieItem->SetArt("season." + i->first, i->second);
334 else if (type == VIDEODB_CONTENT_MOVIES)
336 m_castList->SetContent("movies");
338 // local trailers should always override non-local, so check
339 // for a local one if the registered trailer is online
340 if (m_movieItem->GetVideoInfoTag()->m_strTrailer.IsEmpty() ||
341 URIUtils::IsInternetStream(m_movieItem->GetVideoInfoTag()->m_strTrailer))
343 CStdString localTrailer = m_movieItem->FindTrailer();
344 if (!localTrailer.IsEmpty())
346 m_movieItem->GetVideoInfoTag()->m_strTrailer = localTrailer;
347 CVideoDatabase database;
350 database.SetSingleValue(VIDEODB_CONTENT_MOVIES, VIDEODB_ID_TRAILER,
351 m_movieItem->GetVideoInfoTag()->m_iDbId,
352 m_movieItem->GetVideoInfoTag()->m_strTrailer);
354 CUtil::DeleteVideoDatabaseDirectoryCache();
360 CVideoThumbLoader loader;
361 loader.LoadItem(m_movieItem.get());
364 void CGUIDialogVideoInfo::Update()
366 // setup plot text area
367 CStdString strTmp = m_movieItem->GetVideoInfoTag()->m_strPlot;
368 if (!(!m_movieItem->GetVideoInfoTag()->m_strShowTitle.IsEmpty() && m_movieItem->GetVideoInfoTag()->m_iSeason == 0)) // dont apply to tvshows
369 if (m_movieItem->GetVideoInfoTag()->m_playCount == 0 && !CSettings::Get().GetBool("videolibrary.showunwatchedplots"))
370 strTmp = g_localizeStrings.Get(20370);
373 SetLabel(CONTROL_TEXTAREA, strTmp);
375 CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_LIST, 0, 0, m_castList);
378 if (GetControl(CONTROL_BTN_TRACKS)) // if no CONTROL_BTN_TRACKS found - allow skinner full visibility control over CONTROL_TEXTAREA and CONTROL_LIST
382 if (!m_movieItem->GetVideoInfoTag()->m_artist.empty())
384 SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 133);
388 SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 206);
391 SET_CONTROL_HIDDEN(CONTROL_LIST);
392 SET_CONTROL_VISIBLE(CONTROL_TEXTAREA);
396 SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 207);
398 SET_CONTROL_HIDDEN(CONTROL_TEXTAREA);
399 SET_CONTROL_VISIBLE(CONTROL_LIST);
403 // Check for resumability
404 if (m_movieItem->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0.0)
405 CONTROL_ENABLE(CONTROL_BTN_RESUME);
407 CONTROL_DISABLE(CONTROL_BTN_RESUME);
409 CONTROL_ENABLE(CONTROL_BTN_PLAY);
411 // update the thumbnail
412 const CGUIControl* pControl = GetControl(CONTROL_IMAGE);
415 CGUIImage* pImageControl = (CGUIImage*)pControl;
416 pImageControl->FreeResources();
417 pImageControl->SetFileName(m_movieItem->GetArt("thumb"));
419 // tell our GUI to completely reload all controls (as some of them
420 // are likely to have had this image in use so will need refreshing)
421 if (m_hasUpdatedThumb)
423 CGUIMessage reload(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS);
424 g_windowManager.SendMessage(reload);
428 bool CGUIDialogVideoInfo::NeedRefresh() const
433 bool CGUIDialogVideoInfo::RefreshAll() const
435 return m_bRefreshAll;
438 /// \brief Search the current directory for a string got from the virtual keyboard
439 void CGUIDialogVideoInfo::OnSearch(CStdString& strSearch)
441 CGUIDialogProgress *progress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
444 progress->SetHeading(194);
445 progress->SetLine(0, strSearch);
446 progress->SetLine(1, "");
447 progress->SetLine(2, "");
448 progress->StartModal();
449 progress->Progress();
452 DoSearch(strSearch, items);
459 CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
461 pDlgSelect->SetHeading(283);
463 for (int i = 0; i < (int)items.Size(); i++)
465 CFileItemPtr pItem = items[i];
466 pDlgSelect->Add(pItem->GetLabel());
469 pDlgSelect->DoModal();
471 int iItem = pDlgSelect->GetSelectedLabel();
475 CFileItem* pSelItem = new CFileItem(*items[iItem]);
477 OnSearchItemFound(pSelItem);
483 CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0);
487 /// \brief Make the actual search for the OnSearch function.
488 /// \param strSearch The search string
489 /// \param items Items Found
490 void CGUIDialogVideoInfo::DoSearch(CStdString& strSearch, CFileItemList& items)
496 CFileItemList movies;
497 db.GetMoviesByActor(strSearch, movies);
498 for (int i = 0; i < movies.Size(); ++i)
500 CStdString label = movies[i]->GetVideoInfoTag()->m_strTitle;
501 if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
502 label.AppendFormat(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
503 movies[i]->SetLabel(label);
505 CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20338) + "] ", items);
507 db.GetTvShowsByActor(strSearch, movies);
508 for (int i = 0; i < movies.Size(); ++i)
510 CStdString label = movies[i]->GetVideoInfoTag()->m_strShowTitle;
511 if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
512 label.AppendFormat(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
513 movies[i]->SetLabel(label);
515 CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20364) + "] ", items);
517 db.GetEpisodesByActor(strSearch, movies);
518 for (int i = 0; i < movies.Size(); ++i)
520 CStdString label = movies[i]->GetVideoInfoTag()->m_strTitle + " (" + movies[i]->GetVideoInfoTag()->m_strShowTitle + ")";
521 movies[i]->SetLabel(label);
523 CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20359) + "] ", items);
525 db.GetMusicVideosByArtist(strSearch, movies);
526 for (int i = 0; i < movies.Size(); ++i)
528 CStdString label = StringUtils::Join(movies[i]->GetVideoInfoTag()->m_artist, g_advancedSettings.m_videoItemSeparator) + " - " + movies[i]->GetVideoInfoTag()->m_strTitle;
529 if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
530 label.AppendFormat(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
531 movies[i]->SetLabel(label);
533 CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20391) + "] ", items);
537 /// \brief React on the selected search item
538 /// \param pItem Search result item
539 void CGUIDialogVideoInfo::OnSearchItemFound(const CFileItem* pItem)
541 VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)pItem->GetVideoContentType();
547 CVideoInfoTag movieDetails;
548 if (type == VIDEODB_CONTENT_MOVIES)
549 db.GetMovieInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
550 if (type == VIDEODB_CONTENT_EPISODES)
551 db.GetEpisodeInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
552 if (type == VIDEODB_CONTENT_TVSHOWS)
553 db.GetTvShowInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
554 if (type == VIDEODB_CONTENT_MUSICVIDEOS)
555 db.GetMusicVideoInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
558 CFileItem item(*pItem);
559 *item.GetVideoInfoTag() = movieDetails;
561 // refresh our window entirely
566 void CGUIDialogVideoInfo::ClearCastList()
568 CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_LIST);
573 void CGUIDialogVideoInfo::Play(bool resume)
575 if (!m_movieItem->GetVideoInfoTag()->m_strEpisodeGuide.IsEmpty())
578 strPath.Format("videodb://tvshows/titles/%i/",m_movieItem->GetVideoInfoTag()->m_iDbId);
580 g_windowManager.ActivateWindow(WINDOW_VIDEO_NAV,strPath);
584 CFileItem movie(*m_movieItem->GetVideoInfoTag());
585 if (m_movieItem->GetVideoInfoTag()->m_strFileNameAndPath.IsEmpty())
586 movie.SetPath(m_movieItem->GetPath());
587 CGUIWindowVideoNav* pWindow = (CGUIWindowVideoNav*)g_windowManager.GetWindow(WINDOW_VIDEO_NAV);
593 movie.m_lStartOffset = STARTOFFSET_RESUME;
594 else if (!CGUIWindowVideoBase::ShowResumeMenu(movie))
596 // The Resume dialog was closed without any choice
600 pWindow->PlayMovie(&movie);
604 string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt)
607 CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
608 if (!dialog || !videoItem.HasVideoInfoTag())
612 dialog->SetHeading(13511);
614 dialog->SetUseDetails(true);
615 dialog->EnableButton(true, 13516);
620 vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type);
622 // add in any stored art for this item that is non-empty.
623 db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt);
624 for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i)
626 if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end())
627 artTypes.push_back(i->first);
630 // add any art types that exist for other media items of the same type
631 vector<string> dbArtTypes;
632 db.GetArtTypes(videoItem.GetVideoInfoTag()->m_type, dbArtTypes);
633 for (vector<string>::const_iterator it = dbArtTypes.begin(); it != dbArtTypes.end(); it++)
635 if (find(artTypes.begin(), artTypes.end(), *it) == artTypes.end())
636 artTypes.push_back(*it);
639 for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i)
642 CFileItemPtr item(new CFileItem(type, "false"));
643 item->SetLabel(type);
644 if (videoItem.HasArt(type))
645 item->SetArt("thumb", videoItem.GetArt(type));
649 dialog->SetItems(&items);
652 if (dialog->IsButtonPressed())
654 // Get the new artwork name
655 CStdString strArtworkName;
656 if (!CGUIKeyboardFactory::ShowAndGetInput(strArtworkName, g_localizeStrings.Get(13516), false))
659 return strArtworkName;
662 return dialog->GetSelectedItem()->GetLabel();
665 void CGUIDialogVideoInfo::OnGetArt()
667 map<string, string> currentArt;
668 string type = ChooseArtType(*m_movieItem, currentArt);
672 // TODO: this can be removed once these are unified.
673 if (type == "fanart")
680 if (m_movieItem->HasArt(type))
682 CFileItemPtr item(new CFileItem("thumb://Current", false));
683 item->SetArt("thumb", m_movieItem->GetArt(type));
684 item->SetLabel(g_localizeStrings.Get(13512));
687 else if ((type == "poster" || type == "banner") && currentArt.find("thumb") != currentArt.end())
688 { // add the 'thumb' type in
689 CFileItemPtr item(new CFileItem("thumb://Thumb", false));
690 item->SetArt("thumb", currentArt["thumb"]);
691 item->SetLabel(g_localizeStrings.Get(13512));
695 // Grab the thumbnails from the web
696 vector<CStdString> thumbs;
697 int season = (m_movieItem->GetVideoInfoTag()->m_type == "season") ? m_movieItem->GetVideoInfoTag()->m_iSeason : -1;
698 m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetThumbURLs(thumbs, type, season);
700 for (unsigned int i = 0; i < thumbs.size(); ++i)
702 CStdString strItemPath;
703 strItemPath.Format("thumb://Remote%i", i);
704 CFileItemPtr item(new CFileItem(strItemPath, false));
705 item->SetArt("thumb", thumbs[i]);
706 item->SetIconImage("DefaultPicture.png");
707 item->SetLabel(g_localizeStrings.Get(13513));
709 // TODO: Do we need to clear the cached image?
710 // CTextureCache::Get().ClearCachedImage(thumb);
714 CStdString localThumb = CVideoThumbLoader::GetLocalArt(*m_movieItem, type);
715 if (!localThumb.empty())
717 CFileItemPtr item(new CFileItem("thumb://Local", false));
718 item->SetArt("thumb", localThumb);
719 item->SetLabel(g_localizeStrings.Get(13514));
723 { // no local thumb exists, so we are just using the IMDb thumb or cached thumb
724 // which is probably the IMDb thumb. These could be wrong, so allow the user
725 // to delete the incorrect thumb
726 CFileItemPtr item(new CFileItem("thumb://None", false));
727 item->SetIconImage("DefaultVideo.png");
728 item->SetLabel(g_localizeStrings.Get(13515));
733 VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("video"));
734 AddItemPathToFileBrowserSources(sources, *m_movieItem);
735 g_mediaManager.GetLocalDrives(sources);
736 if (CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(13511), result) &&
737 result != "thumb://Current") // user didn't choose the one they have
740 if (result.Left(14) == "thumb://Remote")
742 int number = atoi(result.Mid(14));
743 newThumb = thumbs[number];
745 else if (result == "thumb://Thumb")
746 newThumb = currentArt["thumb"];
747 else if (result == "thumb://Local")
748 newThumb = localThumb;
749 else if (CFile::Exists(result))
754 // update thumb in the database
758 db.SetArtForItem(m_movieItem->GetVideoInfoTag()->m_iDbId, m_movieItem->GetVideoInfoTag()->m_type, type, newThumb);
761 CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show
762 m_movieItem->SetArt(type, newThumb);
763 if (m_movieItem->HasProperty("set_folder_thumb"))
764 { // have a folder thumb to set as well
765 VIDEO::CVideoInfoScanner::ApplyThumbToFolder(m_movieItem->GetProperty("set_folder_thumb").asString(), newThumb);
767 m_hasUpdatedThumb = true;
774 // re-open the art selection dialog as we come back from
775 // the image selection dialog
779 // Allow user to select a Fanart
780 void CGUIDialogVideoInfo::OnGetFanart()
784 CFileItem item(*m_movieItem->GetVideoInfoTag());
785 if (item.HasArt("fanart"))
787 CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false));
788 itemCurrent->SetArt("thumb", item.GetArt("fanart"));
789 itemCurrent->SetLabel(g_localizeStrings.Get(20440));
790 items.Add(itemCurrent);
793 // ensure the fanart is unpacked
794 m_movieItem->GetVideoInfoTag()->m_fanart.Unpack();
796 // Grab the thumbnails from the web
797 for (unsigned int i = 0; i < m_movieItem->GetVideoInfoTag()->m_fanart.GetNumFanarts(); i++)
799 CStdString strItemPath;
800 strItemPath.Format("fanart://Remote%i",i);
801 CFileItemPtr item(new CFileItem(strItemPath, false));
802 CStdString thumb = m_movieItem->GetVideoInfoTag()->m_fanart.GetPreviewURL(i);
803 item->SetArt("thumb", CTextureUtils::GetWrappedThumbURL(thumb));
804 item->SetIconImage("DefaultPicture.png");
805 item->SetLabel(g_localizeStrings.Get(20441));
807 // TODO: Do we need to clear the cached image?
808 // CTextureCache::Get().ClearCachedImage(thumb);
812 CStdString strLocal = item.GetLocalFanart();
813 if (!strLocal.IsEmpty())
815 CFileItemPtr itemLocal(new CFileItem("fanart://Local",false));
816 itemLocal->SetArt("thumb", strLocal);
817 itemLocal->SetLabel(g_localizeStrings.Get(20438));
819 // TODO: Do we need to clear the cached image?
820 CTextureCache::Get().ClearCachedImage(strLocal);
821 items.Add(itemLocal);
825 CFileItemPtr itemNone(new CFileItem("fanart://None", false));
826 itemNone->SetIconImage("DefaultVideo.png");
827 itemNone->SetLabel(g_localizeStrings.Get(20439));
832 VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("video"));
833 AddItemPathToFileBrowserSources(sources, item);
834 g_mediaManager.GetLocalDrives(sources);
836 if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20437), result, &flip, 20445) || result.Equals("fanart://Current"))
837 return; // user cancelled
839 if (result.Equals("fanart://Local"))
842 if (result.Left(15) == "fanart://Remote")
844 int iFanart = atoi(result.Mid(15).c_str());
845 // set new primary fanart, and update our database accordingly
846 m_movieItem->GetVideoInfoTag()->m_fanart.SetPrimaryFanart(iFanart);
850 db.UpdateFanart(*m_movieItem, (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType());
853 result = m_movieItem->GetVideoInfoTag()->m_fanart.GetImageURL();
855 else if (result.Equals("fanart://None") || !CFile::Exists(result))
858 // set the fanart image
859 if (flip && !result.IsEmpty())
860 result = CTextureUtils::GetWrappedImageURL(result, "", "flipped");
864 db.SetArtForItem(m_movieItem->GetVideoInfoTag()->m_iDbId, m_movieItem->GetVideoInfoTag()->m_type, "fanart", result);
868 CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show
869 m_movieItem->SetArt("fanart", result);
870 m_hasUpdatedThumb = true;
876 void CGUIDialogVideoInfo::PlayTrailer()
879 item.SetPath(m_movieItem->GetVideoInfoTag()->m_strTrailer);
880 *item.GetVideoInfoTag() = *m_movieItem->GetVideoInfoTag();
881 item.GetVideoInfoTag()->m_streamDetails.Reset();
882 item.GetVideoInfoTag()->m_strTitle.Format("%s (%s)",m_movieItem->GetVideoInfoTag()->m_strTitle.c_str(),g_localizeStrings.Get(20410));
883 CVideoThumbLoader::SetArt(item, m_movieItem->GetArt());
884 item.GetVideoInfoTag()->m_iDbId = -1;
885 item.GetVideoInfoTag()->m_iFileId = -1;
890 if (item.IsPlayList())
891 CApplicationMessenger::Get().MediaPlay(item);
893 CApplicationMessenger::Get().PlayFile(item);
896 void CGUIDialogVideoInfo::SetLabel(int iControl, const CStdString &strLabel)
898 if (strLabel.IsEmpty())
900 SET_CONTROL_LABEL(iControl, 416); // "Not available"
904 SET_CONTROL_LABEL(iControl, strLabel);
908 std::string CGUIDialogVideoInfo::GetThumbnail() const
910 return m_movieItem->GetArt("thumb");
913 void CGUIDialogVideoInfo::AddItemPathToFileBrowserSources(VECSOURCES &sources, const CFileItem &item)
915 if (!item.HasVideoInfoTag())
918 CStdString itemDir = item.GetVideoInfoTag()->m_basePath;
921 if (itemDir.IsEmpty())
922 itemDir = item.GetVideoInfoTag()->GetPath();
924 CFileItem itemTmp(itemDir, false);
925 if (itemTmp.IsVideo())
926 itemDir = URIUtils::GetParentPath(itemDir);
928 if (!itemDir.IsEmpty() && CDirectory::Exists(itemDir))
930 CMediaSource itemSource;
931 itemSource.strName = g_localizeStrings.Get(36041);
932 itemSource.strPath = itemDir;
933 sources.push_back(itemSource);
937 int CGUIDialogVideoInfo::ManageVideoItem(const CFileItemPtr &item)
939 if (item == NULL || !item->IsVideoDb() || !item->HasVideoInfoTag() || item->GetVideoInfoTag()->m_iDbId < 0)
942 CVideoDatabase database;
943 if (!database.Open())
946 VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)item->GetVideoContentType();
947 int dbId = item->GetVideoInfoTag()->m_iDbId;
949 CContextButtons buttons;
950 buttons.Add(CONTEXT_BUTTON_EDIT, 16105);
952 if (type == VIDEODB_CONTENT_MOVIES || type == VIDEODB_CONTENT_TVSHOWS)
953 buttons.Add(CONTEXT_BUTTON_EDIT_SORTTITLE, 16107);
955 if (item->m_bIsFolder)
957 // Have both options for folders since we don't know whether all childs are watched/unwatched
958 buttons.Add(CONTEXT_BUTTON_MARK_UNWATCHED, 16104); //Mark as UnWatched
959 buttons.Add(CONTEXT_BUTTON_MARK_WATCHED, 16103); //Mark as Watched
963 if (item->GetOverlayImage().Equals("OverlayWatched.png"))
964 buttons.Add(CONTEXT_BUTTON_MARK_UNWATCHED, 16104); //Mark as UnWatched
966 buttons.Add(CONTEXT_BUTTON_MARK_WATCHED, 16103); //Mark as Watched
969 if (type == VIDEODB_CONTENT_MOVIES)
971 // only show link/unlink if there are tvshows available
972 if (database.HasContent(VIDEODB_CONTENT_TVSHOWS))
974 buttons.Add(CONTEXT_BUTTON_LINK_MOVIE, 20384);
975 if (database.IsLinkedToTvshow(dbId))
976 buttons.Add(CONTEXT_BUTTON_UNLINK_MOVIE, 20385);
979 // set or change movie set the movie belongs to
980 buttons.Add(CONTEXT_BUTTON_SET_MOVIESET, 20465);
983 if (type == VIDEODB_CONTENT_EPISODES &&
984 item->GetVideoInfoTag()->m_iBookmarkId > 0)
985 buttons.Add(CONTEXT_BUTTON_UNLINK_BOOKMARK, 20405);
988 int button = CGUIDialogContextMenu::ShowAndGetChoice(buttons);
991 switch ((CONTEXT_BUTTON)button)
993 case CONTEXT_BUTTON_EDIT:
994 result = UpdateVideoItemTitle(item);
997 case CONTEXT_BUTTON_EDIT_SORTTITLE:
998 result = UpdateVideoItemSortTitle(item);
1001 case CONTEXT_BUTTON_MARK_WATCHED:
1002 result = MarkWatched(item, true);
1005 case CONTEXT_BUTTON_MARK_UNWATCHED:
1006 result = MarkWatched(item, false);
1009 case CONTEXT_BUTTON_LINK_MOVIE:
1010 result = LinkMovieToTvShow(item, false, database);
1013 case CONTEXT_BUTTON_UNLINK_MOVIE:
1014 result = LinkMovieToTvShow(item, true, database);
1017 case CONTEXT_BUTTON_SET_MOVIESET:
1019 CFileItemPtr selectedSet;
1020 if (GetSetForMovie(item.get(), selectedSet))
1021 result = SetMovieSet(item.get(), selectedSet.get());
1025 case CONTEXT_BUTTON_UNLINK_BOOKMARK:
1026 database.DeleteBookMarkForEpisode(*item->GetVideoInfoTag());
1044 //Add change a title's name
1045 bool CGUIDialogVideoInfo::UpdateVideoItemTitle(const CFileItemPtr &pItem)
1047 // dont allow update while scanning
1048 if (g_application.IsVideoScanning())
1050 CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0);
1054 CVideoDatabase database;
1055 if (!database.Open())
1058 int iDbId = pItem->GetVideoInfoTag()->m_iDbId;
1059 CVideoInfoTag detail;
1060 VIDEODB_CONTENT_TYPE iType = (VIDEODB_CONTENT_TYPE)pItem->GetVideoContentType();
1061 if (iType == VIDEODB_CONTENT_MOVIES)
1062 database.GetMovieInfo("", detail, iDbId);
1063 else if (iType == VIDEODB_CONTENT_MOVIE_SETS)
1064 database.GetSetInfo(iDbId, detail);
1065 else if (iType == VIDEODB_CONTENT_EPISODES)
1066 database.GetEpisodeInfo(pItem->GetPath(), detail, iDbId);
1067 else if (iType == VIDEODB_CONTENT_TVSHOWS)
1068 database.GetTvShowInfo(pItem->GetVideoInfoTag()->m_strFileNameAndPath, detail, iDbId);
1069 else if (iType == VIDEODB_CONTENT_MUSICVIDEOS)
1070 database.GetMusicVideoInfo(pItem->GetVideoInfoTag()->m_strFileNameAndPath, detail, iDbId);
1072 // get the new title
1073 if (!CGUIKeyboardFactory::ShowAndGetInput(detail.m_strTitle, g_localizeStrings.Get(16105), false))
1076 database.UpdateMovieTitle(iDbId, detail.m_strTitle, iType);
1080 bool CGUIDialogVideoInfo::MarkWatched(const CFileItemPtr &item, bool bMark)
1082 if (!CProfilesManager::Get().GetCurrentProfile().canWriteDatabases())
1085 // dont allow update while scanning
1086 if (g_application.IsVideoScanning())
1088 CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0);
1092 CVideoDatabase database;
1093 if (!database.Open())
1096 CFileItemList items;
1097 if (item->m_bIsFolder)
1099 CStdString strPath = item->GetPath();
1100 CDirectory::GetDirectory(strPath, items);
1105 for (int i = 0; i < items.Size(); ++i)
1107 CFileItemPtr pTmpItem = items[i];
1108 if (pTmpItem->m_bIsFolder)
1110 MarkWatched(pTmpItem, bMark);
1114 if (pTmpItem->HasVideoInfoTag() &&
1115 ((bMark && pTmpItem->GetVideoInfoTag()->m_playCount) ||
1116 (!bMark && !pTmpItem->GetVideoInfoTag()->m_playCount)))
1120 if (!URIUtils::IsUPnP(item->GetPath()) || !UPNP::CUPnP::MarkWatched(*pTmpItem, bMark))
1123 // Clear resume bookmark
1125 database.ClearBookMarksOfFile(pTmpItem->GetPath(), CBookmark::RESUME);
1127 database.SetPlayCount(*pTmpItem, bMark ? 1 : 0);
1136 bool CGUIDialogVideoInfo::GetMoviesForSet(const CFileItem *setItem, CFileItemList &originalMovies, CFileItemList &selectedMovies)
1138 CVideoDatabase videodb;
1139 if (!videodb.Open())
1142 CStdString strHeading; strHeading.Format(g_localizeStrings.Get(20457));
1144 baseDir.Format("videodb://movies/sets/%d", setItem->GetVideoInfoTag()->m_iDbId);
1146 if (!CDirectory::GetDirectory(baseDir, originalMovies) || originalMovies.Size() <= 0) // keep a copy of the original members of the set
1149 CFileItemList listItems;
1150 if (!videodb.GetSortedVideos(MediaTypeMovie, "videodb://movies", SortDescription(), listItems) || listItems.Size() <= 0)
1153 CGUIDialogSelect *dialog = (CGUIDialogSelect *)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
1157 listItems.Sort(SortByLabel, SortOrderAscending, SortAttributeIgnoreArticle);
1160 dialog->SetMultiSelection(true);
1161 dialog->SetHeading(strHeading);
1162 dialog->SetItems(&listItems);
1163 vector<int> selectedIndices;
1164 for (int i = 0; i < originalMovies.Size(); i++)
1166 for (int listIndex = 0; listIndex < listItems.Size(); listIndex++)
1168 if (listItems.Get(listIndex)->GetVideoInfoTag()->m_iDbId == originalMovies[i]->GetVideoInfoTag()->m_iDbId)
1170 selectedIndices.push_back(listIndex);
1175 dialog->SetSelected(selectedIndices);
1176 dialog->EnableButton(true, 186);
1179 if (dialog->IsConfirmed())
1181 selectedMovies.Copy(dialog->GetSelectedItems());
1182 return (selectedMovies.Size() > 0);
1188 bool CGUIDialogVideoInfo::GetSetForMovie(const CFileItem *movieItem, CFileItemPtr &selectedSet)
1190 CVideoDatabase videodb;
1191 if (!videodb.Open())
1194 CFileItemList listItems;
1195 CStdString baseDir = "videodb://movies/sets/";
1196 if (!CDirectory::GetDirectory(baseDir, listItems) || listItems.Size() <= 0)
1198 listItems.Sort(SortByLabel, SortOrderAscending, SortAttributeIgnoreArticle);
1200 int currentSetId = 0;
1201 CStdString currentSetLabel;
1203 if (movieItem->GetVideoInfoTag()->m_iSetId > currentSetId)
1205 currentSetId = movieItem->GetVideoInfoTag()->m_iSetId;
1206 currentSetLabel = videodb.GetSetById(currentSetId);
1209 if (currentSetId > 0)
1212 CStdString strClear; strClear.Format(g_localizeStrings.Get(20467), currentSetLabel);
1213 CFileItemPtr clearItem(new CFileItem(strClear));
1214 clearItem->GetVideoInfoTag()->m_iDbId = -1; // -1 will be used to clear set
1215 listItems.AddFront(clearItem, 0);
1216 // add keep current set item
1217 CStdString strKeep; strKeep.Format(g_localizeStrings.Get(20469), currentSetLabel);
1218 CFileItemPtr keepItem(new CFileItem(strKeep));
1219 keepItem->GetVideoInfoTag()->m_iDbId = currentSetId;
1220 listItems.AddFront(keepItem, 1);
1223 CGUIDialogSelect *dialog = (CGUIDialogSelect *)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
1227 CStdString strHeading;
1228 strHeading.Format(g_localizeStrings.Get(20466));
1230 dialog->SetHeading(strHeading);
1231 dialog->SetItems(&listItems);
1232 if (currentSetId >= 0)
1234 for (int listIndex = 0; listIndex < listItems.Size(); listIndex++)
1236 if (listItems.Get(listIndex)->GetVideoInfoTag()->m_iDbId == currentSetId)
1238 dialog->SetSelected(listIndex);
1243 dialog->EnableButton(true, 20468); // new set via button
1246 if (dialog->IsButtonPressed())
1247 { // creating new set
1248 CStdString newSetTitle;
1249 if (!CGUIKeyboardFactory::ShowAndGetInput(newSetTitle, g_localizeStrings.Get(20468), false))
1251 int idSet = videodb.AddSet(newSetTitle);
1252 map<string, string> movieArt, setArt;
1253 if (!videodb.GetArtForItem(idSet, "set", setArt))
1255 videodb.GetArtForItem(movieItem->GetVideoInfoTag()->m_iDbId, "movie", movieArt);
1256 videodb.SetArtForItem(idSet, "set", movieArt);
1258 CFileItemPtr newSet(new CFileItem(newSetTitle));
1259 newSet->GetVideoInfoTag()->m_iDbId = idSet;
1260 selectedSet = newSet;
1263 else if (dialog->IsConfirmed())
1265 selectedSet = dialog->GetSelectedItem();
1266 return (selectedSet != NULL);
1272 bool CGUIDialogVideoInfo::SetMovieSet(const CFileItem *movieItem, const CFileItem *selectedSet)
1274 CVideoDatabase videodb;
1275 if (!videodb.Open())
1278 videodb.SetMovieSet(movieItem->GetVideoInfoTag()->m_iDbId, selectedSet->GetVideoInfoTag()->m_iDbId);
1282 bool CGUIDialogVideoInfo::UpdateVideoItemSortTitle(const CFileItemPtr &pItem)
1284 // dont allow update while scanning
1285 if (g_application.IsVideoScanning())
1287 CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0);
1291 CVideoDatabase database;
1292 if (!database.Open())
1295 int iDbId = pItem->GetVideoInfoTag()->m_iDbId;
1296 CVideoInfoTag detail;
1297 VIDEODB_CONTENT_TYPE iType = (VIDEODB_CONTENT_TYPE)pItem->GetVideoContentType();
1298 if (iType == VIDEODB_CONTENT_MOVIES)
1299 database.GetMovieInfo("", detail, iDbId);
1300 else if (iType == VIDEODB_CONTENT_TVSHOWS)
1301 database.GetTvShowInfo(pItem->GetVideoInfoTag()->m_strFileNameAndPath, detail, iDbId);
1303 CStdString currentTitle;
1304 if (detail.m_strSortTitle.IsEmpty())
1305 currentTitle = detail.m_strTitle;
1307 currentTitle = detail.m_strSortTitle;
1309 // get the new sort title
1310 if (!CGUIKeyboardFactory::ShowAndGetInput(currentTitle, g_localizeStrings.Get(16107), false))
1313 return database.UpdateVideoSortTitle(iDbId, currentTitle, iType);
1316 bool CGUIDialogVideoInfo::LinkMovieToTvShow(const CFileItemPtr &item, bool bRemove, CVideoDatabase &database)
1318 int dbId = item->GetVideoInfoTag()->m_iDbId;
1324 if (!database.GetLinksToTvShow(dbId, ids))
1327 for (unsigned int i = 0; i < ids.size(); ++i)
1330 database.GetTvShowInfo("", tag, ids[i]);
1331 CFileItemPtr show(new CFileItem(tag));
1337 database.GetTvShowsNav("videodb://tvshows/titles", list);
1339 // remove already linked shows
1341 if (!database.GetLinksToTvShow(dbId, ids))
1344 for (int i = 0; i < list.Size(); )
1347 for (j = 0; j < ids.size(); ++j)
1349 if (list[i]->GetVideoInfoTag()->m_iDbId == ids[j])
1352 if (j == ids.size())
1359 int iSelectedLabel = 0;
1360 if (list.Size() > 1)
1362 list.Sort(SortByLabel, SortOrderAscending, CSettings::Get().GetBool("filelists.ignorethewhensorting") ? SortAttributeIgnoreArticle : SortAttributeNone);
1363 CGUIDialogSelect* pDialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
1365 pDialog->SetItems(&list);
1366 pDialog->SetHeading(20356);
1368 iSelectedLabel = pDialog->GetSelectedLabel();
1371 if (iSelectedLabel > -1)
1372 return database.LinkMovieToTvshow(dbId, list[iSelectedLabel]->GetVideoInfoTag()->m_iDbId, bRemove);