-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIWindowVideoNav.cpp
1776 lines (1593 loc) · 61.6 KB
/
GUIWindowVideoNav.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-2012 Team XBMC
* http://www.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 "GUIUserMessages.h"
#include "GUIWindowVideoNav.h"
#include "music/windows/GUIWindowMusicNav.h"
#include "utils/FileUtils.h"
#include "Util.h"
#include "utils/RegExp.h"
#include "PlayListPlayer.h"
#include "GUIPassword.h"
#include "dialogs/GUIDialogFileBrowser.h"
#include "filesystem/VideoDatabaseDirectory.h"
#include "playlists/PlayListFactory.h"
#include "dialogs/GUIDialogOK.h"
#include "addons/AddonManager.h"
#include "PartyModeManager.h"
#include "music/MusicDatabase.h"
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogYesNo.h"
#include "dialogs/GUIDialogSelect.h"
#include "filesystem/Directory.h"
#include "filesystem/File.h"
#include "FileItem.h"
#include "Application.h"
#include "ApplicationMessenger.h"
#include "settings/Settings.h"
#include "settings/AdvancedSettings.h"
#include "settings/GUISettings.h"
#include "guilib/LocalizeStrings.h"
#include "storage/MediaManager.h"
#include "utils/log.h"
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
#include "TextureCache.h"
#include "guilib/GUIKeyboardFactory.h"
#include "video/VideoInfoScanner.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "pvr/recordings/PVRRecording.h"
using namespace XFILE;
using namespace VIDEODATABASEDIRECTORY;
using namespace std;
#define CONTROL_BTNVIEWASICONS 2
#define CONTROL_BTNSORTBY 3
#define CONTROL_BTNSORTASC 4
#define CONTROL_BTNTYPE 5
#define CONTROL_BTNSEARCH 8
#define CONTROL_LABELFILES 12
#define CONTROL_BTN_FILTER 19
#define CONTROL_BTNSHOWMODE 10
#define CONTROL_BTNSHOWALL 14
#define CONTROL_UNLOCK 11
#define CONTROL_FILTER 15
#define CONTROL_BTNPARTYMODE 16
#define CONTROL_BTNFLATTEN 17
#define CONTROL_LABELEMPTY 18
CGUIWindowVideoNav::CGUIWindowVideoNav(void)
: CGUIWindowVideoBase(WINDOW_VIDEO_NAV, "MyVideoNav.xml")
{
m_thumbLoader.SetObserver(this);
}
CGUIWindowVideoNav::~CGUIWindowVideoNav(void)
{
}
bool CGUIWindowVideoNav::OnAction(const CAction &action)
{
if (action.GetID() == ACTION_TOGGLE_WATCHED)
{
CFileItemPtr pItem = m_vecItems->Get(m_viewControl.GetSelectedItem());
if (pItem->IsParentFolder())
return false;
if (pItem && pItem->GetVideoInfoTag()->m_playCount == 0)
return OnContextButton(m_viewControl.GetSelectedItem(),CONTEXT_BUTTON_MARK_WATCHED);
if (pItem && pItem->GetVideoInfoTag()->m_playCount > 0)
return OnContextButton(m_viewControl.GetSelectedItem(),CONTEXT_BUTTON_MARK_UNWATCHED);
}
return CGUIWindowVideoBase::OnAction(action);
}
bool CGUIWindowVideoNav::OnMessage(CGUIMessage& message)
{
switch (message.GetMessage())
{
case GUI_MSG_WINDOW_RESET:
m_vecItems->SetPath("");
break;
case GUI_MSG_WINDOW_DEINIT:
if (m_thumbLoader.IsLoading())
m_thumbLoader.StopThread();
break;
case GUI_MSG_WINDOW_INIT:
{
/* We don't want to show Autosourced items (ie removable pendrives, memorycards) in Library mode */
m_rootDir.AllowNonLocalSources(false);
SetProperty("flattened", g_settings.m_bMyVideoNavFlatten);
if (message.GetNumStringParams() && message.GetStringParam(0).Equals("Files") &&
g_settings.GetSourcesFromType("video")->empty())
{
message.SetStringParam("");
}
if (!CGUIWindowVideoBase::OnMessage(message))
return false;
return true;
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BTNPARTYMODE)
{
if (g_partyModeManager.IsEnabled())
g_partyModeManager.Disable();
else
{
if (!g_partyModeManager.Enable(PARTYMODECONTEXT_VIDEO))
{
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE,false);
return false;
}
// Playlist directory is the root of the playlist window
if (m_guiState.get()) m_guiState->SetPlaylistDirectory("playlistvideo://");
return true;
}
UpdateButtons();
}
if (iControl == CONTROL_BTNSEARCH)
{
OnSearch();
}
else if (iControl == CONTROL_BTNSHOWMODE)
{
g_settings.CycleWatchMode(m_vecItems->GetContent());
g_settings.Save();
OnFilterItems(GetProperty("filter").asString());
return true;
}
else if (iControl == CONTROL_BTNFLATTEN)
{
g_settings.m_bMyVideoNavFlatten = !g_settings.m_bMyVideoNavFlatten;
g_settings.Save();
SetProperty("flattened", g_settings.m_bMyVideoNavFlatten);
CUtil::DeleteVideoDatabaseDirectoryCache();
SetupShares();
Update("");
return true;
}
else if (iControl == CONTROL_BTNSHOWALL)
{
if (g_settings.GetWatchMode(m_vecItems->GetContent()) == VIDEO_SHOW_ALL)
g_settings.SetWatchMode(m_vecItems->GetContent(), VIDEO_SHOW_UNWATCHED);
else
g_settings.SetWatchMode(m_vecItems->GetContent(), VIDEO_SHOW_ALL);
g_settings.Save();
OnFilterItems(GetProperty("filter").asString());
return true;
}
}
break;
// update the display
case GUI_MSG_SCAN_FINISHED:
case GUI_MSG_REFRESH_THUMBS:
Refresh();
break;
}
return CGUIWindowVideoBase::OnMessage(message);
}
CStdString CGUIWindowVideoNav::GetQuickpathName(const CStdString& strPath) const
{
if (strPath.Equals("videodb://1/1/"))
return "MovieGenres";
else if (strPath.Equals("videodb://1/2/"))
return "MovieTitles";
else if (strPath.Equals("videodb://1/3/"))
return "MovieYears";
else if (strPath.Equals("videodb://1/4/"))
return "MovieActors";
else if (strPath.Equals("videodb://1/5/"))
return "MovieDirectors";
else if (strPath.Equals("videodb://1/6/"))
return "MovieStudios";
else if (strPath.Equals("videodb://1/7/"))
return "MovieSets";
else if (strPath.Equals("videodb://1/8/"))
return "MovieCountries";
else if (strPath.Equals("videodb://1/9/"))
return "MovieTags";
else if (strPath.Equals("videodb://1/"))
return "Movies";
else if (strPath.Equals("videodb://2/1/"))
return "TvShowGenres";
else if (strPath.Equals("videodb://2/2/"))
return "TvShowTitles";
else if (strPath.Equals("videodb://2/3/"))
return "TvShowYears";
else if (strPath.Equals("videodb://2/4/"))
return "TvShowActors";
else if (strPath.Equals("videodb://2/5/"))
return "TvShowStudios";
else if (strPath.Equals("videodb://2/9/"))
return "TvShowTags";
else if (strPath.Equals("videodb://2/"))
return "TvShows";
else if (strPath.Equals("videodb://3/1/"))
return "MusicVideoGenres";
else if (strPath.Equals("videodb://3/2/"))
return "MusicVideoTitles";
else if (strPath.Equals("videodb://3/3/"))
return "MusicVideoYears";
else if (strPath.Equals("videodb://3/4/"))
return "MusicVideoArtists";
else if (strPath.Equals("videodb://3/5/"))
return "MusicVideoDirectors";
else if (strPath.Equals("videodb://3/9/"))
return "MusicVideoTags";
else if (strPath.Equals("videodb://3/"))
return "MusicVideos";
else if (strPath.Equals("videodb://4/"))
return "RecentlyAddedMovies";
else if (strPath.Equals("videodb://5/"))
return "RecentlyAddedEpisodes";
else if (strPath.Equals("videodb://6/"))
return "RecentlyAddedMusicVideos";
else if (strPath.Equals("special://videoplaylists/"))
return "Playlists";
else if (strPath.Equals("sources://video/"))
return "Files";
else
{
CLog::Log(LOGERROR, " CGUIWindowVideoNav::GetQuickpathName: Unknown parameter (%s)", strPath.c_str());
return strPath;
}
}
bool CGUIWindowVideoNav::GetDirectory(const CStdString &strDirectory, CFileItemList &items)
{
CFileItem directory(strDirectory, true);
if (m_thumbLoader.IsLoading())
m_thumbLoader.StopThread();
items.ClearProperties();
bool bResult = CGUIWindowVideoBase::GetDirectory(strDirectory, items);
if (bResult)
{
if (items.IsVideoDb())
{
XFILE::CVideoDatabaseDirectory dir;
CQueryParams params;
dir.GetQueryParams(items.GetPath(),params);
VIDEODATABASEDIRECTORY::NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath());
items.SetArt("thumb", "");
if (node == VIDEODATABASEDIRECTORY::NODE_TYPE_EPISODES ||
node == NODE_TYPE_SEASONS ||
node == NODE_TYPE_RECENTLY_ADDED_EPISODES)
{
CLog::Log(LOGDEBUG, "WindowVideoNav::GetDirectory");
// grab the show thumb
CVideoInfoTag details;
m_database.GetTvShowInfo("", details, params.GetTvShowId());
map<string, string> art;
if (m_database.GetArtForItem(details.m_iDbId, details.m_type, art))
{
items.AppendArt(art, "tvshow");
items.SetArtFallback("fanart", "tvshow.fanart");
if (node == NODE_TYPE_SEASONS)
{ // set an art fallback for "thumb"
if (items.HasArt("tvshow.poster"))
items.SetArtFallback("thumb", "tvshow.poster");
else if (items.HasArt("tvshow.banner"))
items.SetArtFallback("thumb", "tvshow.banner");
}
}
// Grab fanart data
items.SetProperty("fanart_color1", details.m_fanart.GetColor(0));
items.SetProperty("fanart_color2", details.m_fanart.GetColor(1));
items.SetProperty("fanart_color3", details.m_fanart.GetColor(2));
// save the show description (showplot)
items.SetProperty("showplot", details.m_strPlot);
// the container folder thumb is the parent (i.e. season or show)
if (node == NODE_TYPE_EPISODES || node == NODE_TYPE_RECENTLY_ADDED_EPISODES)
{
items.SetContent("episodes");
// grab the season thumb as the folder thumb
int seasonID = m_database.GetSeasonId(details.m_iDbId, params.GetSeason());
CGUIListItem::ArtMap seasonArt;
if (m_database.GetArtForItem(seasonID, "season", seasonArt))
{
items.AppendArt(art, "season");
// set an art fallback for "thumb"
if (items.HasArt("season.poster"))
items.SetArtFallback("thumb", "season.poster");
else if (items.HasArt("season.banner"))
items.SetArtFallback("thumb", "season.banner");
}
}
else
items.SetContent("seasons");
}
else if (node == NODE_TYPE_TITLE_MOVIES ||
node == NODE_TYPE_RECENTLY_ADDED_MOVIES)
items.SetContent("movies");
else if (node == NODE_TYPE_TITLE_TVSHOWS)
items.SetContent("tvshows");
else if (node == NODE_TYPE_TITLE_MUSICVIDEOS ||
node == NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS)
items.SetContent("musicvideos");
else if (node == NODE_TYPE_GENRE)
items.SetContent("genres");
else if (node == NODE_TYPE_COUNTRY)
items.SetContent("countries");
else if (node == NODE_TYPE_ACTOR)
{
if (params.GetContentType() == VIDEODB_CONTENT_MUSICVIDEOS)
items.SetContent("artists");
else
items.SetContent("actors");
}
else if (node == NODE_TYPE_DIRECTOR)
items.SetContent("directors");
else if (node == NODE_TYPE_STUDIO)
items.SetContent("studios");
else if (node == NODE_TYPE_YEAR)
items.SetContent("years");
else if (node == NODE_TYPE_MUSICVIDEOS_ALBUM)
items.SetContent("albums");
else if (node == NODE_TYPE_SETS)
items.SetContent("sets");
else if (node == NODE_TYPE_TAGS)
items.SetContent("tags");
else
items.SetContent("");
}
else if (!items.IsVirtualDirectoryRoot())
{ // load info from the database
CStdString label;
if (items.GetLabel().IsEmpty() && m_rootDir.IsSource(items.GetPath(), g_settings.GetSourcesFromType("video"), &label))
items.SetLabel(label);
if (!items.IsSourcesPath())
LoadVideoInfo(items);
}
CVideoDbUrl videoUrl;
if (videoUrl.FromString(items.GetPath()) && items.GetContent() == "tags" &&
!items.Contains("newtag://" + videoUrl.GetType()))
{
CFileItemPtr newTag(new CFileItem("newtag://" + videoUrl.GetType(), false));
newTag->SetLabel(g_localizeStrings.Get(20462));
newTag->SetLabelPreformated(true);
newTag->SetSpecialSort(SortSpecialOnTop);
items.Add(newTag);
}
}
return bResult;
}
void CGUIWindowVideoNav::LoadVideoInfo(CFileItemList &items)
{
LoadVideoInfo(items, m_database);
}
void CGUIWindowVideoNav::LoadVideoInfo(CFileItemList &items, CVideoDatabase &database, bool allowReplaceLabels)
{
// TODO: this could possibly be threaded as per the music info loading,
// we could also cache the info
if (!items.GetContent().IsEmpty() && !items.IsPlugin())
return; // don't load for listings that have content set and weren't created from plugins
CStdString content = items.GetContent();
// determine content only if it isn't set
if (content.IsEmpty())
{
content = database.GetContentForPath(items.GetPath());
items.SetContent(content.IsEmpty() ? "files" : content);
}
/*
If we have a matching item in the library, so we can assign the metadata to it. In addition, we can choose
* whether the item is stacked down (eg in the case of folders representing a single item)
* whether or not we assign the library's labels to the item, or leave the item as is.
As certain users (read: certain developers) don't want either of these to occur, we compromise by stacking
items down only if stacking is available and enabled.
Similarly, we assign the "clean" library labels to the item only if the "Replace filenames with library titles"
setting is enabled.
*/
const bool stackItems = items.GetProperty("isstacked").asBoolean() || (StackingAvailable(items) && g_settings.m_videoStacking);
const bool replaceLabels = allowReplaceLabels && g_guiSettings.GetBool("myvideos.replacelabels");
CFileItemList dbItems;
/* NOTE: In the future when GetItemsForPath returns all items regardless of whether they're "in the library"
we won't need the fetchedPlayCounts code, and can "simply" do this directly on absense of content. */
bool fetchedPlayCounts = false;
if (!content.IsEmpty())
{
database.GetItemsForPath(content, items.GetPath(), dbItems);
dbItems.SetFastLookup(true);
}
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr pItem = items[i];
CFileItemPtr match;
if (!content.IsEmpty()) /* optical media will be stacked down, so it's path won't match the base path */
match = dbItems.Get(pItem->IsOpticalMediaFile() ? pItem->GetLocalMetadataPath() : pItem->GetPath());
if (match)
{
pItem->UpdateInfo(*match, replaceLabels);
if (stackItems)
{
if (match->m_bIsFolder)
pItem->SetPath(match->GetVideoInfoTag()->m_strPath);
else
pItem->SetPath(match->GetVideoInfoTag()->m_strFileNameAndPath);
// if we switch from a file to a folder item it means we really shouldn't be sorting files and
// folders separately
if (pItem->m_bIsFolder != match->m_bIsFolder)
{
items.SetSortIgnoreFolders(true);
pItem->m_bIsFolder = match->m_bIsFolder;
}
}
}
else
{
/* NOTE: Currently we GetPlayCounts on our items regardless of whether content is set
as if content is set, GetItemsForPaths doesn't return anything not in the content tables.
This code can be removed once the content tables are always filled */
if (!pItem->m_bIsFolder && !fetchedPlayCounts)
{
database.GetPlayCounts(items.GetPath(), items);
fetchedPlayCounts = true;
}
// preferably use some information from PVR info tag if available
if (pItem->HasPVRRecordingInfoTag())
pItem->GetPVRRecordingInfoTag()->CopyClientInfo(pItem->GetVideoInfoTag());
// set the watched overlay
if (pItem->IsVideo())
pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->m_playCount > 0);
}
}
}
void CGUIWindowVideoNav::UpdateButtons()
{
CGUIWindowVideoBase::UpdateButtons();
// Update object count
int iItems = m_vecItems->Size();
if (iItems)
{
// check for parent dir and "all" items
// should always be the first two items
for (int i = 0; i <= (iItems>=2 ? 1 : 0); i++)
{
CFileItemPtr pItem = m_vecItems->Get(i);
if (pItem->IsParentFolder()) iItems--;
if (pItem->GetPath().Left(4).Equals("/-1/")) iItems--;
}
// or the last item
if (m_vecItems->Size() > 2 &&
m_vecItems->Get(m_vecItems->Size()-1)->GetPath().Left(4).Equals("/-1/"))
iItems--;
}
CStdString items;
items.Format("%i %s", iItems, g_localizeStrings.Get(127).c_str());
SET_CONTROL_LABEL(CONTROL_LABELFILES, items);
// set the filter label
CStdString strLabel;
// "Playlists"
if (m_vecItems->GetPath().Equals("special://videoplaylists/"))
strLabel = g_localizeStrings.Get(136);
// "{Playlist Name}"
else if (m_vecItems->IsPlayList())
{
// get playlist name from path
CStdString strDummy;
URIUtils::Split(m_vecItems->GetPath(), strDummy, strLabel);
}
else if (m_vecItems->GetPath().Equals("sources://video/"))
strLabel = g_localizeStrings.Get(744);
// everything else is from a videodb:// path
else if (m_vecItems->IsVideoDb())
{
CVideoDatabaseDirectory dir;
dir.GetLabel(m_vecItems->GetPath(), strLabel);
}
else
strLabel = URIUtils::GetFileName(m_vecItems->GetPath());
SET_CONTROL_LABEL(CONTROL_FILTER, strLabel);
int watchMode = g_settings.GetWatchMode(m_vecItems->GetContent());
SET_CONTROL_LABEL(CONTROL_BTNSHOWMODE, g_localizeStrings.Get(16100 + watchMode));
SET_CONTROL_SELECTED(GetID(), CONTROL_BTNSHOWALL, watchMode != VIDEO_SHOW_ALL);
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE, g_partyModeManager.IsEnabled());
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNFLATTEN, g_settings.m_bMyVideoNavFlatten);
}
bool CGUIWindowVideoNav::GetFilteredItems(const CStdString &filter, CFileItemList &items)
{
bool listchanged = CGUIMediaWindow::GetFilteredItems(filter, items);
listchanged |= ApplyWatchedFilter(items);
return listchanged;
}
/// \brief Search for names, genres, artists, directors, and plots with search string \e strSearch in the
/// \brief video databases and return the found \e items
/// \param strSearch The search string
/// \param items Items Found
void CGUIWindowVideoNav::DoSearch(const CStdString& strSearch, CFileItemList& items)
{
CFileItemList tempItems;
CStdString strGenre = g_localizeStrings.Get(515); // Genre
CStdString strActor = g_localizeStrings.Get(20337); // Actor
CStdString strDirector = g_localizeStrings.Get(20339); // Director
CStdString strMovie = g_localizeStrings.Get(20338); // Movie
//get matching names
m_database.GetMoviesByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(20338) + "] ", items);
m_database.GetEpisodesByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(20359) + "] ", items);
m_database.GetTvShowsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(20364) + "] ", items);
m_database.GetMusicVideosByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(20391) + "] ", items);
m_database.GetMusicVideosByAlbum(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(558) + "] ", items);
// get matching genres
m_database.GetMovieGenresByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strGenre + " - " + g_localizeStrings.Get(20342) + "] ", items);
m_database.GetTvShowGenresByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strGenre + " - " + g_localizeStrings.Get(20343) + "] ", items);
m_database.GetMusicVideoGenresByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strGenre + " - " + g_localizeStrings.Get(20389) + "] ", items);
//get actors/artists
m_database.GetMovieActorsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strActor + " - " + g_localizeStrings.Get(20342) + "] ", items);
m_database.GetTvShowsActorsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strActor + " - " + g_localizeStrings.Get(20343) + "] ", items);
m_database.GetMusicVideoArtistsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strActor + " - " + g_localizeStrings.Get(20389) + "] ", items);
//directors
m_database.GetMovieDirectorsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strDirector + " - " + g_localizeStrings.Get(20342) + "] ", items);
m_database.GetTvShowsDirectorsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strDirector + " - " + g_localizeStrings.Get(20343) + "] ", items);
m_database.GetMusicVideoDirectorsByName(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strDirector + " - " + g_localizeStrings.Get(20389) + "] ", items);
//plot
m_database.GetEpisodesByPlot(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + g_localizeStrings.Get(20365) + "] ", items);
m_database.GetMoviesByPlot(strSearch, tempItems);
AppendAndClearSearchItems(tempItems, "[" + strMovie + " " + g_localizeStrings.Get(207) + "] ", items);
}
void CGUIWindowVideoNav::PlayItem(int iItem)
{
// unlike additemtoplaylist, we need to check the items here
// before calling it since the current playlist will be stopped
// and cleared!
// root is not allowed
if (m_vecItems->IsVirtualDirectoryRoot())
return;
CGUIWindowVideoBase::PlayItem(iItem);
}
void CGUIWindowVideoNav::OnInfo(CFileItem* pItem, ADDON::ScraperPtr& scraper)
{
m_database.Open(); // since we can be called from the music library without being inited
if (pItem->IsVideoDb())
scraper = m_database.GetScraperForPath(pItem->GetVideoInfoTag()->m_strPath);
else
{
CStdString strPath,strFile;
URIUtils::Split(pItem->GetPath(),strPath,strFile);
scraper = m_database.GetScraperForPath(strPath);
}
m_database.Close();
CGUIWindowVideoBase::OnInfo(pItem,scraper);
}
bool CGUIWindowVideoNav::CanDelete(const CStdString& strPath)
{
CQueryParams params;
CVideoDatabaseDirectory::GetQueryParams(strPath,params);
if (params.GetMovieId() != -1 ||
params.GetEpisodeId() != -1 ||
params.GetMVideoId() != -1 ||
(params.GetTvShowId() != -1 && params.GetSeason() <= -1
&& !CVideoDatabaseDirectory::IsAllItem(strPath)))
return true;
return false;
}
void CGUIWindowVideoNav::OnDeleteItem(CFileItemPtr pItem)
{
if (m_vecItems->IsParentFolder())
return;
if (!m_vecItems->IsVideoDb() && !pItem->IsVideoDb())
{
if (!pItem->GetPath().Equals("newsmartplaylist://video") &&
!pItem->GetPath().Equals("special://videoplaylists/") &&
!pItem->GetPath().Equals("sources://video/") &&
!pItem->GetPath().Left(9).Equals("newtag://"))
CGUIWindowVideoBase::OnDeleteItem(pItem);
}
else if (pItem->GetPath().Left(14).Equals("videodb://1/7/") &&
pItem->GetPath().size() > 14 && pItem->m_bIsFolder)
{
CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
pDialog->SetHeading(432);
CStdString strLabel;
strLabel.Format(g_localizeStrings.Get(433),pItem->GetLabel());
pDialog->SetLine(1, strLabel);
pDialog->SetLine(2, "");;
pDialog->DoModal();
if (pDialog->IsConfirmed())
{
CFileItemList items;
CDirectory::GetDirectory(pItem->GetPath(),items,"",DIR_FLAG_NO_FILE_DIRS);
for (int i=0;i<items.Size();++i)
OnDeleteItem(items[i]);
CVideoDatabaseDirectory dir;
CQueryParams params;
dir.GetQueryParams(pItem->GetPath(),params);
m_database.DeleteSet(params.GetSetId());
}
}
else if (m_vecItems->GetContent() == "tags" &&
pItem->GetPath().size() > 14 && pItem->m_bIsFolder)
{
CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
pDialog->SetHeading(432);
CStdString strLabel;
strLabel.Format(g_localizeStrings.Get(433), pItem->GetLabel());
pDialog->SetLine(1, strLabel);
pDialog->SetLine(2, "");
pDialog->DoModal();
if (pDialog->IsConfirmed())
{
CVideoDatabaseDirectory dir;
CQueryParams params;
dir.GetQueryParams(pItem->GetPath(), params);
m_database.DeleteTag(params.GetTagId(), (VIDEODB_CONTENT_TYPE)params.GetContentType());
}
}
else if (m_vecItems->GetPath().Equals(CUtil::VideoPlaylistsLocation()) ||
m_vecItems->GetPath().Equals("special://videoplaylists/"))
{
pItem->m_bIsFolder = false;
CFileUtils::DeleteItem(pItem);
}
else
{
if (!DeleteItem(pItem.get()))
return;
CStdString strDeletePath;
if (pItem->m_bIsFolder)
strDeletePath=pItem->GetVideoInfoTag()->m_strPath;
else
strDeletePath=pItem->GetVideoInfoTag()->m_strFileNameAndPath;
if (URIUtils::GetFileName(strDeletePath).Equals("VIDEO_TS.IFO"))
{
URIUtils::GetDirectory(strDeletePath.Mid(0),strDeletePath);
if (strDeletePath.Right(9).Equals("VIDEO_TS/"))
{
URIUtils::RemoveSlashAtEnd(strDeletePath);
URIUtils::GetDirectory(strDeletePath.Mid(0),strDeletePath);
}
}
if (URIUtils::HasSlashAtEnd(strDeletePath))
pItem->m_bIsFolder=true;
if (g_guiSettings.GetBool("filelists.allowfiledeletion") &&
CUtil::SupportsWriteFileOperations(strDeletePath))
{
pItem->SetPath(strDeletePath);
CGUIWindowVideoBase::OnDeleteItem(pItem);
}
}
CUtil::DeleteVideoDatabaseDirectoryCache();
}
bool CGUIWindowVideoNav::DeleteItem(CFileItem* pItem, bool bUnavailable /* = false */)
{
if (!pItem->HasVideoInfoTag() || !CanDelete(pItem->GetPath()))
return false;
VIDEODB_CONTENT_TYPE iType=VIDEODB_CONTENT_MOVIES;
if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->m_strShowTitle.IsEmpty())
iType = VIDEODB_CONTENT_TVSHOWS;
if (pItem->HasVideoInfoTag() && pItem->GetVideoInfoTag()->m_iSeason > -1 && !pItem->m_bIsFolder)
iType = VIDEODB_CONTENT_EPISODES;
if (pItem->HasVideoInfoTag() && !pItem->GetVideoInfoTag()->m_artist.empty())
iType = VIDEODB_CONTENT_MUSICVIDEOS;
// dont allow update while scanning
if (g_application.IsVideoScanning())
{
CGUIDialogOK::ShowAndGetInput(257, 0, 14057, 0);
return false;
}
CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
if (!pDialog)
return false;
if (iType == VIDEODB_CONTENT_MOVIES)
pDialog->SetHeading(432);
if (iType == VIDEODB_CONTENT_EPISODES)
pDialog->SetHeading(20362);
if (iType == VIDEODB_CONTENT_TVSHOWS)
pDialog->SetHeading(20363);
if (iType == VIDEODB_CONTENT_MUSICVIDEOS)
pDialog->SetHeading(20392);
if(bUnavailable)
{
pDialog->SetLine(0, g_localizeStrings.Get(662));
pDialog->SetLine(1, g_localizeStrings.Get(663));
pDialog->SetLine(2, "");;
pDialog->DoModal();
}
else
{
CStdString strLine;
strLine.Format(g_localizeStrings.Get(433),pItem->GetLabel());
pDialog->SetLine(0, strLine);
pDialog->SetLine(1, "");
pDialog->SetLine(2, "");;
pDialog->DoModal();
}
if (!pDialog->IsConfirmed())
return false;
CStdString path;
CVideoDatabase database;
database.Open();
database.GetFilePathById(pItem->GetVideoInfoTag()->m_iDbId, path, iType);
if (path.IsEmpty())
return false;
if (iType == VIDEODB_CONTENT_MOVIES)
database.DeleteMovie(path);
if (iType == VIDEODB_CONTENT_EPISODES)
database.DeleteEpisode(path, pItem->GetVideoInfoTag()->m_iDbId);
if (iType == VIDEODB_CONTENT_TVSHOWS)
database.DeleteTvShow(path);
if (iType == VIDEODB_CONTENT_MUSICVIDEOS)
database.DeleteMusicVideo(path);
if (iType == VIDEODB_CONTENT_TVSHOWS)
database.SetPathHash(path,"");
else
{
CStdString strDirectory;
URIUtils::GetDirectory(path,strDirectory);
database.SetPathHash(strDirectory,"");
}
return true;
}
void CGUIWindowVideoNav::OnPrepareFileItems(CFileItemList &items)
{
CGUIWindowVideoBase::OnPrepareFileItems(items);
}
void CGUIWindowVideoNav::GetContextButtons(int itemNumber, CContextButtons &buttons)
{
CFileItemPtr item;
if (itemNumber >= 0 && itemNumber < m_vecItems->Size())
item = m_vecItems->Get(itemNumber);
CGUIWindowVideoBase::GetContextButtons(itemNumber, buttons);
if (item && item->GetProperty("pluginreplacecontextitems").asBoolean())
return;
CVideoDatabaseDirectory dir;
NODE_TYPE node = dir.GetDirectoryChildType(m_vecItems->GetPath());
if (!item)
{
if (g_application.IsVideoScanning())
buttons.Add(CONTEXT_BUTTON_STOP_SCANNING, 13353);
else
buttons.Add(CONTEXT_BUTTON_UPDATE_LIBRARY, 653);
}
else if (m_vecItems->GetPath().Equals("sources://video/"))
{
// get the usual shares
CGUIDialogContextMenu::GetContextButtons("video", item, buttons);
// add scan button somewhere here
if (g_application.IsVideoScanning())
buttons.Add(CONTEXT_BUTTON_STOP_SCANNING, 13353); // Stop Scanning
if (!item->IsDVD() && item->GetPath() != "add" && !item->IsParentFolder() &&
(g_settings.GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser))
{
CVideoDatabase database;
database.Open();
ADDON::ScraperPtr info = database.GetScraperForPath(item->GetPath());
if (!g_application.IsVideoScanning())
{
if (!item->IsLiveTV() && !item->IsPlugin() && !item->IsAddonsPath() && !URIUtils::IsUPnP(item->GetPath()))
{
if (info && info->Content() != CONTENT_NONE)
buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20442);
else
buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20333);
}
}
if (info && !g_application.IsVideoScanning())
buttons.Add(CONTEXT_BUTTON_SCAN, 13349);
}
}
else
{
// are we in the playlists location?
bool inPlaylists = m_vecItems->GetPath().Equals(CUtil::VideoPlaylistsLocation()) ||
m_vecItems->GetPath().Equals("special://videoplaylists/");
if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->m_artist.empty())
{
CMusicDatabase database;
database.Open();
if (database.GetArtistByName(StringUtils::Join(item->GetVideoInfoTag()->m_artist, g_advancedSettings.m_videoItemSeparator)) > -1)
buttons.Add(CONTEXT_BUTTON_GO_TO_ARTIST, 20396);
}
if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_strAlbum.size() > 0)
{
CMusicDatabase database;
database.Open();
if (database.GetAlbumByName(item->GetVideoInfoTag()->m_strAlbum) > -1)
buttons.Add(CONTEXT_BUTTON_GO_TO_ALBUM, 20397);
}
if (item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_strAlbum.size() > 0 &&
item->GetVideoInfoTag()->m_artist.size() > 0 &&
item->GetVideoInfoTag()->m_strTitle.size() > 0)
{
CMusicDatabase database;
database.Open();
if (database.GetSongByArtistAndAlbumAndTitle(StringUtils::Join(item->GetVideoInfoTag()->m_artist, g_advancedSettings.m_videoItemSeparator),
item->GetVideoInfoTag()->m_strAlbum,
item->GetVideoInfoTag()->m_strTitle) > -1)
{
buttons.Add(CONTEXT_BUTTON_PLAY_OTHER, 20398);
}
}
if (!item->IsParentFolder())
{
ADDON::ScraperPtr info;
VIDEO::SScanSettings settings;
GetScraperForItem(item.get(), info, settings);
if (info && info->Content() == CONTENT_TVSHOWS)
buttons.Add(CONTEXT_BUTTON_INFO, item->m_bIsFolder ? 20351 : 20352);
else if (info && info->Content() == CONTENT_MUSICVIDEOS)
buttons.Add(CONTEXT_BUTTON_INFO,20393);
else if (info && info->Content() == CONTENT_MOVIES)
buttons.Add(CONTEXT_BUTTON_INFO, 13346);
// can we update the database?
if (g_settings.GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser)
{
if (node == NODE_TYPE_TITLE_TVSHOWS)
{
if (g_application.IsVideoScanning())
buttons.Add(CONTEXT_BUTTON_STOP_SCANNING, 13353);
else
buttons.Add(CONTEXT_BUTTON_UPDATE_TVSHOW, 13349);
}
if (!item->IsPlugin() && !item->IsScript() && !item->IsLiveTV() && !item->IsAddonsPath() &&
item->GetPath() != "sources://video/" && item->GetPath() != "special://videoplaylists/" &&
item->GetPath().Left(19) != "newsmartplaylist://" && item->GetPath().Left(14) != "newplaylist://" &&
item->GetPath().Left(9) != "newtag://")
{
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().Equals("OverlayWatched.png"))
buttons.Add(CONTEXT_BUTTON_MARK_UNWATCHED, 16104); //Mark as UnWatched
else
buttons.Add(CONTEXT_BUTTON_MARK_WATCHED, 16103); //Mark as Watched
}
}
if ((node == NODE_TYPE_TITLE_TVSHOWS) ||
(item->IsVideoDb() && item->HasVideoInfoTag() && !item->m_bIsFolder))
{
buttons.Add(CONTEXT_BUTTON_EDIT, 16105); //Edit Title
}
if (m_database.HasContent(VIDEODB_CONTENT_TVSHOWS) && item->HasVideoInfoTag() &&
!item->m_bIsFolder && item->GetVideoInfoTag()->m_iEpisode == -1 &&
item->GetVideoInfoTag()->m_artist.empty() && item->GetVideoInfoTag()->m_iDbId >= 0) // movie entry
{
if (m_database.IsLinkedToTvshow(item->GetVideoInfoTag()->m_iDbId))
buttons.Add(CONTEXT_BUTTON_UNLINK_MOVIE,20385);
buttons.Add(CONTEXT_BUTTON_LINK_MOVIE,20384);
}
if (node == NODE_TYPE_SEASONS && item->m_bIsFolder)
buttons.Add(CONTEXT_BUTTON_SET_SEASON_ART, 13511);
if (item->GetPath().Left(14).Equals("videodb://1/7/") && item->GetPath().size() > 14 && item->m_bIsFolder) // sets
{
buttons.Add(CONTEXT_BUTTON_EDIT, 16105);
buttons.Add(CONTEXT_BUTTON_SET_MOVIESET_ART, 13511);
buttons.Add(CONTEXT_BUTTON_DELETE, 646);
}
if (m_vecItems->GetContent() == "tags" && item->GetPath().size() > 14 && item->m_bIsFolder) // tags
{
CVideoDbUrl videoUrl;
if (videoUrl.FromString(item->GetPath()))
{
std::string mediaType = videoUrl.GetItemType();
CStdString strLabelAdd; strLabelAdd.Format(g_localizeStrings.Get(20460), GetLocalizedType(videoUrl.GetItemType()).c_str());
CStdString strLabelRemove; strLabelRemove.Format(g_localizeStrings.Get(20461), GetLocalizedType(videoUrl.GetItemType()).c_str());
buttons.Add(CONTEXT_BUTTON_TAGS_ADD_ITEMS, strLabelAdd);