forked from xbmc/xbmc
/
GUIDialogVideoInfo.cpp
1969 lines (1715 loc) · 62.5 KB
/
GUIDialogVideoInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "GUIDialogVideoInfo.h"
#include "Application.h"
#include "guilib/GUIWindow.h"
#include "Util.h"
#include "guilib/GUIImage.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "video/windows/GUIWindowVideoNav.h"
#include "dialogs/GUIDialogFileBrowser.h"
#include "video/VideoInfoScanner.h"
#include "ApplicationMessenger.h"
#include "video/VideoInfoTag.h"
#include "guilib/GUIKeyboardFactory.h"
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogOK.h"
#include "dialogs/GUIDialogYesNo.h"
#include "dialogs/GUIDialogSelect.h"
#include "dialogs/GUIDialogProgress.h"
#include "filesystem/File.h"
#include "FileItem.h"
#include "storage/MediaManager.h"
#include "utils/AsyncFileCopy.h"
#include "profiles/ProfilesManager.h"
#include "settings/AdvancedSettings.h"
#include "settings/MediaSourceSettings.h"
#include "settings/Settings.h"
#include "input/Key.h"
#include "guilib/LocalizeStrings.h"
#include "ContextMenuManager.h"
#include "GUIUserMessages.h"
#include "TextureCache.h"
#include "music/MusicDatabase.h"
#include "URL.h"
#include "video/VideoLibraryQueue.h"
#include "video/VideoThumbLoader.h"
#include "filesystem/Directory.h"
#include "filesystem/VideoDatabaseDirectory.h"
#include "filesystem/VideoDatabaseDirectory/QueryParams.h"
#ifdef HAS_UPNP
#include "network/upnp/UPnP.h"
#endif
#include "utils/FileUtils.h"
using namespace std;
using namespace XFILE::VIDEODATABASEDIRECTORY;
using namespace XFILE;
#define CONTROL_IMAGE 3
#define CONTROL_TEXTAREA 4
#define CONTROL_BTN_TRACKS 5
#define CONTROL_BTN_REFRESH 6
#define CONTROL_BTN_PLAY 8
#define CONTROL_BTN_RESUME 9
#define CONTROL_BTN_GET_THUMB 10
#define CONTROL_BTN_PLAY_TRAILER 11
#define CONTROL_BTN_GET_FANART 12
#define CONTROL_BTN_DIRECTOR 13
#define CONTROL_LIST 50
// predicate used by sorting and set_difference
bool compFileItemsByDbId(const CFileItemPtr& lhs, const CFileItemPtr& rhs)
{
return lhs->HasVideoInfoTag() && rhs->HasVideoInfoTag() && lhs->GetVideoInfoTag()->m_iDbId < rhs->GetVideoInfoTag()->m_iDbId;
}
CGUIDialogVideoInfo::CGUIDialogVideoInfo(void)
: CGUIDialog(WINDOW_DIALOG_VIDEO_INFO, "DialogVideoInfo.xml")
, m_movieItem(new CFileItem)
{
m_bRefreshAll = true;
m_bRefresh = false;
m_hasUpdatedThumb = false;
m_castList = new CFileItemList;
m_loadType = KEEP_IN_MEMORY;
}
CGUIDialogVideoInfo::~CGUIDialogVideoInfo(void)
{
delete m_castList;
}
bool CGUIDialogVideoInfo::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
ClearCastList();
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BTN_REFRESH)
{
if (m_movieItem->GetVideoInfoTag()->m_type == MediaTypeTvShow)
{
bool bCanceled=false;
if (CGUIDialogYesNo::ShowAndGetInput(20377,20378,-1,-1,bCanceled))
{
m_bRefreshAll = true;
CVideoDatabase db;
if (db.Open())
{
db.SetPathHash(m_movieItem->GetVideoInfoTag()->m_strPath,"");
db.Close();
}
}
else
m_bRefreshAll = false;
if (bCanceled)
return false;
}
m_bRefresh = true;
Close();
return true;
}
else if (iControl == CONTROL_BTN_TRACKS)
{
m_bViewReview = !m_bViewReview;
Update();
}
else if (iControl == CONTROL_BTN_PLAY)
{
Play();
}
else if (iControl == CONTROL_BTN_RESUME)
{
Play(true);
}
else if (iControl == CONTROL_BTN_GET_THUMB)
{
OnGetArt();
}
else if (iControl == CONTROL_BTN_PLAY_TRAILER)
{
PlayTrailer();
}
else if (iControl == CONTROL_BTN_GET_FANART)
{
OnGetFanart();
}
else if (iControl == CONTROL_BTN_DIRECTOR)
{
std::string strDirector = StringUtils::Join(m_movieItem->GetVideoInfoTag()->m_director, g_advancedSettings.m_videoItemSeparator);
OnSearch(strDirector);
}
else if (iControl == CONTROL_LIST)
{
int iAction = message.GetParam1();
if (ACTION_SELECT_ITEM == iAction || ACTION_MOUSE_LEFT_CLICK == iAction)
{
CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), iControl);
OnMessage(msg);
int iItem = msg.GetParam1();
if (iItem < 0 || iItem >= m_castList->Size())
break;
std::string strItem = m_castList->Get(iItem)->GetLabel();
OnSearch(strItem);
}
}
}
break;
case GUI_MSG_NOTIFY_ALL:
{
if (IsActive() && message.GetParam1() == GUI_MSG_UPDATE_ITEM && message.GetItem())
{
CFileItemPtr item = std::static_pointer_cast<CFileItem>(message.GetItem());
if (item && m_movieItem->IsPath(item->GetPath()))
{ // Just copy over the stream details and the thumb if we don't already have one
if (!m_movieItem->HasArt("thumb"))
m_movieItem->SetArt("thumb", item->GetArt("thumb"));
m_movieItem->GetVideoInfoTag()->m_streamDetails = item->GetVideoInfoTag()->m_streamDetails;
}
return true;
}
}
}
return CGUIDialog::OnMessage(message);
}
void CGUIDialogVideoInfo::OnInitWindow()
{
m_bRefresh = false;
m_bRefreshAll = true;
m_hasUpdatedThumb = false;
m_bViewReview = true;
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTN_REFRESH, (CProfilesManager::Get().GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser) && !StringUtils::StartsWithNoCase(m_movieItem->GetVideoInfoTag()->m_strIMDBNumber, "xx"));
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"));
VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType();
if (type == VIDEODB_CONTENT_TVSHOWS || type == VIDEODB_CONTENT_MOVIES)
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"));
else
CONTROL_DISABLE(CONTROL_BTN_GET_FANART);
Update();
CGUIDialog::OnInitWindow();
}
bool CGUIDialogVideoInfo::OnAction(const CAction &action)
{
if (action.GetID() == ACTION_SHOW_INFO)
{
Close();
return true;
}
return CGUIDialog::OnAction(action);
}
void CGUIDialogVideoInfo::SetMovie(const CFileItem *item)
{
*m_movieItem = *item;
// setup cast list + determine type. We need to do this here as it makes
// sure that content type (among other things) is set correctly for the
// old fixed id labels that we have floating around (they may be using
// content type to determine visibility, so we'll set the wrong label)
ClearCastList();
VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType();
if (type == VIDEODB_CONTENT_MUSICVIDEOS)
{ // music video
CMusicDatabase database;
database.Open();
const std::vector<std::string> &artists = m_movieItem->GetVideoInfoTag()->m_artist;
for (std::vector<std::string>::const_iterator it = artists.begin(); it != artists.end(); ++it)
{
int idArtist = database.GetArtistByName(*it);
std::string thumb = database.GetArtForItem(idArtist, MediaTypeArtist, "thumb");
CFileItemPtr item(new CFileItem(*it));
if (!thumb.empty())
item->SetArt("thumb", thumb);
item->SetIconImage("DefaultArtist.png");
m_castList->Add(item);
}
m_castList->SetContent("musicvideos");
}
else
{ // movie/show/episode
for (CVideoInfoTag::iCast it = m_movieItem->GetVideoInfoTag()->m_cast.begin(); it != m_movieItem->GetVideoInfoTag()->m_cast.end(); ++it)
{
CFileItemPtr item(new CFileItem(it->strName));
if (!it->thumb.empty())
item->SetArt("thumb", it->thumb);
else if (CSettings::Get().GetBool("videolibrary.actorthumbs"))
{ // backward compatibility
std::string thumb = CScraperUrl::GetThumbURL(it->thumbUrl.GetFirstThumb());
if (!thumb.empty())
{
item->SetArt("thumb", thumb);
CTextureCache::Get().BackgroundCacheImage(thumb);
}
}
item->SetIconImage("DefaultActor.png");
item->SetLabel(it->strName);
item->SetLabel2(it->strRole);
m_castList->Add(item);
}
// determine type:
if (type == VIDEODB_CONTENT_TVSHOWS)
{
m_castList->SetContent("tvshows");
// special case stuff for shows (not currently retrieved from the library in filemode (ref: GetTvShowInfo vs GetTVShowsByWhere)
m_movieItem->m_dateTime = m_movieItem->GetVideoInfoTag()->m_premiered;
if(m_movieItem->GetVideoInfoTag()->m_iYear == 0 && m_movieItem->m_dateTime.IsValid())
m_movieItem->GetVideoInfoTag()->m_iYear = m_movieItem->m_dateTime.GetYear();
if (!m_movieItem->HasProperty("totalepisodes"))
{
m_movieItem->SetProperty("totalepisodes", m_movieItem->GetVideoInfoTag()->m_iEpisode);
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
m_movieItem->SetProperty("watchedepisodes", m_movieItem->GetVideoInfoTag()->m_playCount);
m_movieItem->SetProperty("unwatchedepisodes", m_movieItem->GetVideoInfoTag()->m_iEpisode - m_movieItem->GetVideoInfoTag()->m_playCount);
m_movieItem->GetVideoInfoTag()->m_playCount = (m_movieItem->GetVideoInfoTag()->m_iEpisode == m_movieItem->GetVideoInfoTag()->m_playCount) ? 1 : 0;
}
}
else if (type == VIDEODB_CONTENT_EPISODES)
{
m_castList->SetContent("episodes");
// special case stuff for episodes (not currently retrieved from the library in filemode (ref: GetEpisodeInfo vs GetEpisodesByWhere)
m_movieItem->m_dateTime = m_movieItem->GetVideoInfoTag()->m_firstAired;
if(m_movieItem->GetVideoInfoTag()->m_iYear == 0 && m_movieItem->m_dateTime.IsValid())
m_movieItem->GetVideoInfoTag()->m_iYear = m_movieItem->m_dateTime.GetYear();
// retrieve the season thumb.
// TODO: should we use the thumbloader for this?
CVideoDatabase db;
if (db.Open())
{
if (m_movieItem->GetVideoInfoTag()->m_iSeason > -1)
{
int seasonID = m_movieItem->GetVideoInfoTag()->m_iIdSeason;
if (seasonID < 0)
seasonID = db.GetSeasonId(m_movieItem->GetVideoInfoTag()->m_iIdShow,
m_movieItem->GetVideoInfoTag()->m_iSeason);
CGUIListItem::ArtMap thumbs;
if (db.GetArtForItem(seasonID, MediaTypeSeason, thumbs))
{
for (CGUIListItem::ArtMap::iterator i = thumbs.begin(); i != thumbs.end(); ++i)
m_movieItem->SetArt("season." + i->first, i->second);
}
}
db.Close();
}
}
else if (type == VIDEODB_CONTENT_MOVIES)
{
m_castList->SetContent("movies");
// local trailers should always override non-local, so check
// for a local one if the registered trailer is online
if (m_movieItem->GetVideoInfoTag()->m_strTrailer.empty() ||
URIUtils::IsInternetStream(m_movieItem->GetVideoInfoTag()->m_strTrailer))
{
std::string localTrailer = m_movieItem->FindTrailer();
if (!localTrailer.empty())
{
m_movieItem->GetVideoInfoTag()->m_strTrailer = localTrailer;
CVideoDatabase database;
if(database.Open())
{
database.SetSingleValue(VIDEODB_CONTENT_MOVIES, VIDEODB_ID_TRAILER,
m_movieItem->GetVideoInfoTag()->m_iDbId,
m_movieItem->GetVideoInfoTag()->m_strTrailer);
database.Close();
CUtil::DeleteVideoDatabaseDirectoryCache();
}
}
}
}
}
CVideoThumbLoader loader;
loader.LoadItem(m_movieItem.get());
}
void CGUIDialogVideoInfo::Update()
{
// setup plot text area
std::string strTmp = m_movieItem->GetVideoInfoTag()->m_strPlot;
if (m_movieItem->GetVideoInfoTag()->m_type != MediaTypeTvShow)
if (m_movieItem->GetVideoInfoTag()->m_playCount == 0 && !CSettings::Get().GetBool("videolibrary.showunwatchedplots"))
strTmp = g_localizeStrings.Get(20370);
StringUtils::Trim(strTmp);
SetLabel(CONTROL_TEXTAREA, strTmp);
CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_LIST, 0, 0, m_castList);
OnMessage(msg);
if (GetControl(CONTROL_BTN_TRACKS)) // if no CONTROL_BTN_TRACKS found - allow skinner full visibility control over CONTROL_TEXTAREA and CONTROL_LIST
{
if (m_bViewReview)
{
if (!m_movieItem->GetVideoInfoTag()->m_artist.empty())
{
SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 133);
}
else
{
SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 206);
}
SET_CONTROL_HIDDEN(CONTROL_LIST);
SET_CONTROL_VISIBLE(CONTROL_TEXTAREA);
}
else
{
SET_CONTROL_LABEL(CONTROL_BTN_TRACKS, 207);
SET_CONTROL_HIDDEN(CONTROL_TEXTAREA);
SET_CONTROL_VISIBLE(CONTROL_LIST);
}
}
// Check for resumability
if (m_movieItem->GetVideoInfoTag()->m_resumePoint.timeInSeconds > 0.0)
CONTROL_ENABLE(CONTROL_BTN_RESUME);
else
CONTROL_DISABLE(CONTROL_BTN_RESUME);
CONTROL_ENABLE(CONTROL_BTN_PLAY);
// update the thumbnail
const CGUIControl* pControl = GetControl(CONTROL_IMAGE);
if (pControl)
{
CGUIImage* pImageControl = (CGUIImage*)pControl;
pImageControl->FreeResources();
pImageControl->SetFileName(m_movieItem->GetArt("thumb"));
}
// tell our GUI to completely reload all controls (as some of them
// are likely to have had this image in use so will need refreshing)
if (m_hasUpdatedThumb)
{
CGUIMessage reload(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS);
g_windowManager.SendMessage(reload);
}
}
bool CGUIDialogVideoInfo::NeedRefresh() const
{
return m_bRefresh;
}
bool CGUIDialogVideoInfo::RefreshAll() const
{
return m_bRefreshAll;
}
/// \brief Search the current directory for a string got from the virtual keyboard
void CGUIDialogVideoInfo::OnSearch(std::string& strSearch)
{
CGUIDialogProgress *progress = (CGUIDialogProgress *)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
if (progress)
{
progress->SetHeading(194);
progress->SetLine(0, strSearch);
progress->SetLine(1, "");
progress->SetLine(2, "");
progress->StartModal();
progress->Progress();
}
CFileItemList items;
DoSearch(strSearch, items);
if (progress)
progress->Close();
if (items.Size())
{
CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
pDlgSelect->Reset();
pDlgSelect->SetHeading(283);
for (int i = 0; i < (int)items.Size(); i++)
{
CFileItemPtr pItem = items[i];
pDlgSelect->Add(pItem->GetLabel());
}
pDlgSelect->DoModal();
int iItem = pDlgSelect->GetSelectedLabel();
if (iItem < 0)
return;
CFileItem* pSelItem = new CFileItem(*items[iItem]);
OnSearchItemFound(pSelItem);
delete pSelItem;
}
else
{
CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0);
}
}
/// \brief Make the actual search for the OnSearch function.
/// \param strSearch The search string
/// \param items Items Found
void CGUIDialogVideoInfo::DoSearch(std::string& strSearch, CFileItemList& items)
{
CVideoDatabase db;
if (!db.Open())
return;
CFileItemList movies;
db.GetMoviesByActor(strSearch, movies);
for (int i = 0; i < movies.Size(); ++i)
{
std::string label = movies[i]->GetVideoInfoTag()->m_strTitle;
if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
label += StringUtils::Format(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
movies[i]->SetLabel(label);
}
CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20338) + "] ", items);
db.GetTvShowsByActor(strSearch, movies);
for (int i = 0; i < movies.Size(); ++i)
{
std::string label = movies[i]->GetVideoInfoTag()->m_strShowTitle;
if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
label += StringUtils::Format(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
movies[i]->SetLabel(label);
}
CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20364) + "] ", items);
db.GetEpisodesByActor(strSearch, movies);
for (int i = 0; i < movies.Size(); ++i)
{
std::string label = movies[i]->GetVideoInfoTag()->m_strTitle + " (" + movies[i]->GetVideoInfoTag()->m_strShowTitle + ")";
movies[i]->SetLabel(label);
}
CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20359) + "] ", items);
db.GetMusicVideosByArtist(strSearch, movies);
for (int i = 0; i < movies.Size(); ++i)
{
std::string label = StringUtils::Join(movies[i]->GetVideoInfoTag()->m_artist, g_advancedSettings.m_videoItemSeparator) + " - " + movies[i]->GetVideoInfoTag()->m_strTitle;
if (movies[i]->GetVideoInfoTag()->m_iYear > 0)
label += StringUtils::Format(" (%i)", movies[i]->GetVideoInfoTag()->m_iYear);
movies[i]->SetLabel(label);
}
CGUIWindowVideoBase::AppendAndClearSearchItems(movies, "[" + g_localizeStrings.Get(20391) + "] ", items);
db.Close();
}
/// \brief React on the selected search item
/// \param pItem Search result item
void CGUIDialogVideoInfo::OnSearchItemFound(const CFileItem* pItem)
{
VIDEODB_CONTENT_TYPE type = (VIDEODB_CONTENT_TYPE)pItem->GetVideoContentType();
CVideoDatabase db;
if (!db.Open())
return;
CVideoInfoTag movieDetails;
if (type == VIDEODB_CONTENT_MOVIES)
db.GetMovieInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
if (type == VIDEODB_CONTENT_EPISODES)
db.GetEpisodeInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
if (type == VIDEODB_CONTENT_TVSHOWS)
db.GetTvShowInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
if (type == VIDEODB_CONTENT_MUSICVIDEOS)
db.GetMusicVideoInfo(pItem->GetPath(), movieDetails, pItem->GetVideoInfoTag()->m_iDbId);
db.Close();
CFileItem item(*pItem);
*item.GetVideoInfoTag() = movieDetails;
SetMovie(&item);
// refresh our window entirely
Close();
DoModal();
}
void CGUIDialogVideoInfo::ClearCastList()
{
CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_LIST);
OnMessage(msg);
m_castList->Clear();
}
void CGUIDialogVideoInfo::Play(bool resume)
{
if (!m_movieItem->GetVideoInfoTag()->m_strEpisodeGuide.empty())
{
std::string strPath = StringUtils::Format("videodb://tvshows/titles/%i/",m_movieItem->GetVideoInfoTag()->m_iDbId);
Close();
g_windowManager.ActivateWindow(WINDOW_VIDEO_NAV,strPath);
return;
}
CFileItem movie(*m_movieItem->GetVideoInfoTag());
if (m_movieItem->GetVideoInfoTag()->m_strFileNameAndPath.empty())
movie.SetPath(m_movieItem->GetPath());
CGUIWindowVideoNav* pWindow = (CGUIWindowVideoNav*)g_windowManager.GetWindow(WINDOW_VIDEO_NAV);
if (pWindow)
{
// close our dialog
Close(true);
if (resume)
movie.m_lStartOffset = STARTOFFSET_RESUME;
else if (!CGUIWindowVideoBase::ShowResumeMenu(movie))
{
// The Resume dialog was closed without any choice
DoModal();
return;
}
pWindow->PlayMovie(&movie);
}
}
string CGUIDialogVideoInfo::ChooseArtType(const CFileItem &videoItem, map<string, string> ¤tArt)
{
// prompt for choice
CGUIDialogSelect *dialog = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
if (!dialog || !videoItem.HasVideoInfoTag())
return "";
CFileItemList items;
dialog->SetHeading(13511);
dialog->Reset();
dialog->SetUseDetails(true);
dialog->EnableButton(true, 13516);
CVideoDatabase db;
db.Open();
vector<string> artTypes = CVideoThumbLoader::GetArtTypes(videoItem.GetVideoInfoTag()->m_type);
// add in any stored art for this item that is non-empty.
db.GetArtForItem(videoItem.GetVideoInfoTag()->m_iDbId, videoItem.GetVideoInfoTag()->m_type, currentArt);
for (CGUIListItem::ArtMap::iterator i = currentArt.begin(); i != currentArt.end(); ++i)
{
if (!i->second.empty() && find(artTypes.begin(), artTypes.end(), i->first) == artTypes.end())
artTypes.push_back(i->first);
}
// add any art types that exist for other media items of the same type
vector<string> dbArtTypes;
db.GetArtTypes(videoItem.GetVideoInfoTag()->m_type, dbArtTypes);
for (vector<string>::const_iterator it = dbArtTypes.begin(); it != dbArtTypes.end(); ++it)
{
if (find(artTypes.begin(), artTypes.end(), *it) == artTypes.end())
artTypes.push_back(*it);
}
for (vector<string>::const_iterator i = artTypes.begin(); i != artTypes.end(); ++i)
{
string type = *i;
CFileItemPtr item(new CFileItem(type, "false"));
item->SetLabel(type);
if (videoItem.HasArt(type))
item->SetArt("thumb", videoItem.GetArt(type));
items.Add(item);
}
dialog->SetItems(&items);
dialog->DoModal();
if (dialog->IsButtonPressed())
{
// Get the new artwork name
std::string strArtworkName;
if (!CGUIKeyboardFactory::ShowAndGetInput(strArtworkName, g_localizeStrings.Get(13516), false))
return "";
return strArtworkName;
}
return dialog->GetSelectedItem()->GetLabel();
}
void CGUIDialogVideoInfo::OnGetArt()
{
map<string, string> currentArt;
string type = ChooseArtType(*m_movieItem, currentArt);
if (type.empty())
return; // cancelled
// TODO: this can be removed once these are unified.
if (type == "fanart")
OnGetFanart();
else
{
CFileItemList items;
// Current thumb
if (m_movieItem->HasArt(type))
{
CFileItemPtr item(new CFileItem("thumb://Current", false));
item->SetArt("thumb", m_movieItem->GetArt(type));
item->SetLabel(g_localizeStrings.Get(13512));
items.Add(item);
}
else if ((type == "poster" || type == "banner") && currentArt.find("thumb") != currentArt.end())
{ // add the 'thumb' type in
CFileItemPtr item(new CFileItem("thumb://Thumb", false));
item->SetArt("thumb", currentArt["thumb"]);
item->SetLabel(g_localizeStrings.Get(13512));
items.Add(item);
}
// Grab the thumbnails from the web
vector<std::string> thumbs;
int season = (m_movieItem->GetVideoInfoTag()->m_type == MediaTypeSeason) ? m_movieItem->GetVideoInfoTag()->m_iSeason : -1;
m_movieItem->GetVideoInfoTag()->m_strPictureURL.GetThumbURLs(thumbs, type, season);
for (unsigned int i = 0; i < thumbs.size(); ++i)
{
std::string strItemPath = StringUtils::Format("thumb://Remote%i", i);
CFileItemPtr item(new CFileItem(strItemPath, false));
item->SetArt("thumb", thumbs[i]);
item->SetIconImage("DefaultPicture.png");
item->SetLabel(g_localizeStrings.Get(13513));
// TODO: Do we need to clear the cached image?
// CTextureCache::Get().ClearCachedImage(thumb);
items.Add(item);
}
std::string localThumb = CVideoThumbLoader::GetLocalArt(*m_movieItem, type);
if (!localThumb.empty())
{
CFileItemPtr item(new CFileItem("thumb://Local", false));
item->SetArt("thumb", localThumb);
item->SetLabel(g_localizeStrings.Get(13514));
items.Add(item);
}
else
{ // no local thumb exists, so we are just using the IMDb thumb or cached thumb
// which is probably the IMDb thumb. These could be wrong, so allow the user
// to delete the incorrect thumb
CFileItemPtr item(new CFileItem("thumb://None", false));
item->SetIconImage("DefaultVideo.png");
item->SetLabel(g_localizeStrings.Get(13515));
items.Add(item);
}
std::string result;
VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("video"));
AddItemPathToFileBrowserSources(sources, *m_movieItem);
g_mediaManager.GetLocalDrives(sources);
if (CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(13511), result) &&
result != "thumb://Current") // user didn't choose the one they have
{
std::string newThumb;
if (StringUtils::StartsWith(result, "thumb://Remote"))
{
int number = atoi(result.substr(14).c_str());
newThumb = thumbs[number];
}
else if (result == "thumb://Thumb")
newThumb = currentArt["thumb"];
else if (result == "thumb://Local")
newThumb = localThumb;
else if (CFile::Exists(result))
newThumb = result;
else // none
newThumb.clear();
// update thumb in the database
CVideoDatabase db;
if (db.Open())
{
db.SetArtForItem(m_movieItem->GetVideoInfoTag()->m_iDbId, m_movieItem->GetVideoInfoTag()->m_type, type, newThumb);
db.Close();
}
CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show
m_movieItem->SetArt(type, newThumb);
if (m_movieItem->HasProperty("set_folder_thumb"))
{ // have a folder thumb to set as well
VIDEO::CVideoInfoScanner::ApplyThumbToFolder(m_movieItem->GetProperty("set_folder_thumb").asString(), newThumb);
}
m_hasUpdatedThumb = true;
}
}
// Update our screen
Update();
// re-open the art selection dialog as we come back from
// the image selection dialog
OnGetArt();
}
// Allow user to select a Fanart
void CGUIDialogVideoInfo::OnGetFanart()
{
CFileItemList items;
// Ensure the fanart is unpacked
m_movieItem->GetVideoInfoTag()->m_fanart.Unpack();
if (m_movieItem->HasArt("fanart"))
{
CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false));
itemCurrent->SetArt("thumb", m_movieItem->GetArt("fanart"));
itemCurrent->SetLabel(g_localizeStrings.Get(20440));
items.Add(itemCurrent);
}
// Grab the thumbnails from the web
for (unsigned int i = 0; i < m_movieItem->GetVideoInfoTag()->m_fanart.GetNumFanarts(); i++)
{
std::string strItemPath = StringUtils::Format("fanart://Remote%i",i);
CFileItemPtr item(new CFileItem(strItemPath, false));
std::string thumb = m_movieItem->GetVideoInfoTag()->m_fanart.GetPreviewURL(i);
item->SetArt("thumb", CTextureUtils::GetWrappedThumbURL(thumb));
item->SetIconImage("DefaultPicture.png");
item->SetLabel(g_localizeStrings.Get(20441));
// TODO: Do we need to clear the cached image?
// CTextureCache::Get().ClearCachedImage(thumb);
items.Add(item);
}
CFileItem item(*m_movieItem->GetVideoInfoTag());
std::string strLocal = item.GetLocalFanart();
if (!strLocal.empty())
{
CFileItemPtr itemLocal(new CFileItem("fanart://Local",false));
itemLocal->SetArt("thumb", strLocal);
itemLocal->SetLabel(g_localizeStrings.Get(20438));
// TODO: Do we need to clear the cached image?
CTextureCache::Get().ClearCachedImage(strLocal);
items.Add(itemLocal);
}
else
{
CFileItemPtr itemNone(new CFileItem("fanart://None", false));
itemNone->SetIconImage("DefaultVideo.png");
itemNone->SetLabel(g_localizeStrings.Get(20439));
items.Add(itemNone);
}
std::string result;
VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("video"));
AddItemPathToFileBrowserSources(sources, item);
g_mediaManager.GetLocalDrives(sources);
bool flip=false;
if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20437), result, &flip, 20445) ||
StringUtils::EqualsNoCase(result, "fanart://Current"))
return; // user cancelled
if (StringUtils::EqualsNoCase(result, "fanart://Local"))
result = strLocal;
if (StringUtils::StartsWith(result, "fanart://Remote"))
{
int iFanart = atoi(result.substr(15).c_str());
// set new primary fanart, and update our database accordingly
m_movieItem->GetVideoInfoTag()->m_fanart.SetPrimaryFanart(iFanart);
CVideoDatabase db;
if (db.Open())
{
db.UpdateFanart(*m_movieItem, (VIDEODB_CONTENT_TYPE)m_movieItem->GetVideoContentType());
db.Close();
}
result = m_movieItem->GetVideoInfoTag()->m_fanart.GetImageURL();
}
else if (StringUtils::EqualsNoCase(result, "fanart://None") || !CFile::Exists(result))
result.clear();
// set the fanart image
if (flip && !result.empty())
result = CTextureUtils::GetWrappedImageURL(result, "", "flipped");
CVideoDatabase db;
if (db.Open())
{
db.SetArtForItem(m_movieItem->GetVideoInfoTag()->m_iDbId, m_movieItem->GetVideoInfoTag()->m_type, "fanart", result);
db.Close();
}
CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show
m_movieItem->SetArt("fanart", result);
m_hasUpdatedThumb = true;
// Update our screen
Update();
}
void CGUIDialogVideoInfo::PlayTrailer()
{
CFileItem item;
item.SetPath(m_movieItem->GetVideoInfoTag()->m_strTrailer);
*item.GetVideoInfoTag() = *m_movieItem->GetVideoInfoTag();
item.GetVideoInfoTag()->m_streamDetails.Reset();
item.GetVideoInfoTag()->m_strTitle = StringUtils::Format("%s (%s)",
m_movieItem->GetVideoInfoTag()->m_strTitle.c_str(),
g_localizeStrings.Get(20410).c_str());
CVideoThumbLoader::SetArt(item, m_movieItem->GetArt());
item.GetVideoInfoTag()->m_iDbId = -1;
item.GetVideoInfoTag()->m_iFileId = -1;
// Close the dialog.
Close(true);
if (item.IsPlayList())
CApplicationMessenger::Get().MediaPlay(item);
else
CApplicationMessenger::Get().PlayFile(item);
}
void CGUIDialogVideoInfo::SetLabel(int iControl, const std::string &strLabel)
{
if (strLabel.empty())
{
SET_CONTROL_LABEL(iControl, 416); // "Not available"
}
else
{
SET_CONTROL_LABEL(iControl, strLabel);
}
}
std::string CGUIDialogVideoInfo::GetThumbnail() const
{
return m_movieItem->GetArt("thumb");
}
void CGUIDialogVideoInfo::AddItemPathToFileBrowserSources(VECSOURCES &sources, const CFileItem &item)
{
if (!item.HasVideoInfoTag())
return;
std::string itemDir = item.GetVideoInfoTag()->m_basePath;
//season
if (itemDir.empty())
itemDir = item.GetVideoInfoTag()->GetPath();
CFileItem itemTmp(itemDir, false);
if (itemTmp.IsVideo())
itemDir = URIUtils::GetParentPath(itemDir);
if (!itemDir.empty() && CDirectory::Exists(itemDir))
{
CMediaSource itemSource;
itemSource.strName = g_localizeStrings.Get(36041);
itemSource.strPath = itemDir;
sources.push_back(itemSource);
}
}
int CGUIDialogVideoInfo::ManageVideoItem(const CFileItemPtr &item)
{
if (item == NULL || !item->IsVideoDb() || !item->HasVideoInfoTag() || item->GetVideoInfoTag()->m_iDbId < 0)
return -1;
CVideoDatabase database;
if (!database.Open())
return -1;
const std::string &type = item->GetVideoInfoTag()->m_type;
int dbId = item->GetVideoInfoTag()->m_iDbId;
CContextButtons buttons;
if (type == MediaTypeMovie || type == MediaTypeVideoCollection ||
type == MediaTypeTvShow || type == MediaTypeEpisode ||
type == MediaTypeMusicVideo)
buttons.Add(CONTEXT_BUTTON_EDIT, 16105);
if (type == MediaTypeMovie || type == MediaTypeTvShow)
buttons.Add(CONTEXT_BUTTON_EDIT_SORTTITLE, 16107);
if (item->m_bIsFolder)
{
// Have both options for folders since we don't know whether all childs are watched/unwatched
buttons.Add(CONTEXT_BUTTON_MARK_UNWATCHED, 16104); //Mark as UnWatched
buttons.Add(CONTEXT_BUTTON_MARK_WATCHED, 16103); //Mark as Watched
}
else
{
if (item->GetOverlayImage() == "OverlayWatched.png")
buttons.Add(CONTEXT_BUTTON_MARK_UNWATCHED, 16104); //Mark as UnWatched
else
buttons.Add(CONTEXT_BUTTON_MARK_WATCHED, 16103); //Mark as Watched
}
if (type == MediaTypeMovie)
{
// only show link/unlink if there are tvshows available
if (database.HasContent(VIDEODB_CONTENT_TVSHOWS))
{
buttons.Add(CONTEXT_BUTTON_LINK_MOVIE, 20384);
if (database.IsLinkedToTvshow(dbId))
buttons.Add(CONTEXT_BUTTON_UNLINK_MOVIE, 20385);
}
// set or change movie set the movie belongs to
buttons.Add(CONTEXT_BUTTON_SET_MOVIESET, 20465);
}
if (type == MediaTypeEpisode &&
item->GetVideoInfoTag()->m_iBookmarkId > 0)
buttons.Add(CONTEXT_BUTTON_UNLINK_BOOKMARK, 20405);
// movie sets
if (item->m_bIsFolder && type == MediaTypeVideoCollection)
{
buttons.Add(CONTEXT_BUTTON_SET_MOVIESET_ART, 13511);
buttons.Add(CONTEXT_BUTTON_MOVIESET_ADD_REMOVE_ITEMS, 20465);
}
// tags
if (item->m_bIsFolder && type == "tag")
{
CVideoDbUrl videoUrl;
if (videoUrl.FromString(item->GetPath()))
{
const std::string &mediaType = videoUrl.GetItemType();
buttons.Add(CONTEXT_BUTTON_TAGS_ADD_ITEMS, StringUtils::Format(g_localizeStrings.Get(20460).c_str(), GetLocalizedVideoType(mediaType).c_str()));