/
GUIWindowVideoNav.cpp
1137 lines (1006 loc) · 40.9 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) 2016-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "GUIWindowVideoNav.h"
#include "FileItem.h"
#include "FileItemList.h"
#include "GUIPassword.h"
#include "PartyModeManager.h"
#include "ServiceBroker.h"
#include "Util.h"
#include "dialogs/GUIDialogMediaSource.h"
#include "dialogs/GUIDialogYesNo.h"
#include "filesystem/Directory.h"
#include "filesystem/VideoDatabaseDirectory.h"
#include "filesystem/VideoDatabaseFile.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIKeyboardFactory.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "input/actions/Action.h"
#include "input/actions/ActionIDs.h"
#include "messaging/ApplicationMessenger.h"
#include "messaging/helpers/DialogOKHelper.h"
#include "music/MusicDatabase.h"
#include "profiles/ProfileManager.h"
#include "settings/AdvancedSettings.h"
#include "settings/MediaSettings.h"
#include "settings/MediaSourceSettings.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/FileUtils.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
#include "utils/log.h"
#include "video/VideoDbUrl.h"
#include "video/VideoFileItemClassify.h"
#include "video/VideoInfoScanner.h"
#include "video/VideoLibraryQueue.h"
#include "video/dialogs/GUIDialogVideoInfo.h"
#include "view/GUIViewState.h"
#include <utility>
using namespace XFILE;
using namespace VIDEODATABASEDIRECTORY;
using namespace KODI;
using namespace KODI::MESSAGING;
#define CONTROL_BTNVIEWASICONS 2
#define CONTROL_BTNSORTBY 3
#define CONTROL_BTNSORTASC 4
#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_LABELEMPTY 18
#define CONTROL_UPDATE_LIBRARY 20
CGUIWindowVideoNav::CGUIWindowVideoNav(void)
: CGUIWindowVideoBase(WINDOW_VIDEO_NAV, "MyVideoNav.xml")
{
m_thumbLoader.SetObserver(this);
}
CGUIWindowVideoNav::~CGUIWindowVideoNav(void) = default;
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->HasVideoInfoTag())
{
CVideoLibraryQueue::GetInstance().MarkAsWatched(pItem, pItem->GetVideoInfoTag()->GetPlayCount() == 0);
return true;
}
}
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", CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYVIDEOS_FLATTEN));
if (message.GetNumStringParams() && StringUtils::EqualsNoCase(message.GetStringParam(0), "Files") &&
CMediaSourceSettings::GetInstance().GetSources("video")->empty())
{
message.SetStringParam("");
}
if (!CGUIWindowVideoBase::OnMessage(message))
return false;
if (message.GetStringParam(0) != "")
{
CURL url(message.GetStringParam(0));
int i = 0;
for (; i < m_vecItems->Size(); i++)
{
CFileItemPtr pItem = m_vecItems->Get(i);
// skip ".."
if (pItem->IsParentFolder())
continue;
if (URIUtils::PathEquals(pItem->GetPath(), message.GetStringParam(0), true, true))
{
m_viewControl.SetSelectedItem(i);
i = -1;
if (url.GetOption("showinfo") == "true")
{
OnItemInfo(*pItem);
}
break;
}
}
if (i >= m_vecItems->Size())
{
SelectFirstUnwatched();
if (url.GetOption("showinfo") == "true")
{
// We are here if the item is filtered out in the nav window
const std::string& path = message.GetStringParam(0);
CFileItem item(path, URIUtils::HasSlashAtEnd(path));
if (VIDEO::IsVideoDb(item))
{
*(item.GetVideoInfoTag()) = XFILE::CVideoDatabaseFile::GetVideoTag(CURL(item.GetPath()));
if (!item.GetVideoInfoTag()->IsEmpty())
{
item.SetPath(item.GetVideoInfoTag()->m_strFileNameAndPath);
OnItemInfo(item);
}
}
}
}
}
else
{
// This needs to be done again, because the initialization of CGUIWindow overwrites it with default values
// Mostly affects cases where GUIWindowVideoNav is constructed and we're already in a show, e.g. entering from the homescreen
SelectFirstUnwatched();
}
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)
m_guiState->SetPlaylistDirectory("playlistvideo://");
return true;
}
UpdateButtons();
}
if (iControl == CONTROL_BTNSEARCH)
{
OnSearch();
}
else if (iControl == CONTROL_BTNSHOWMODE)
{
CMediaSettings::GetInstance().CycleWatchedMode(m_vecItems->GetContent());
CServiceBroker::GetSettingsComponent()->GetSettings()->Save();
OnFilterItems(GetProperty("filter").asString());
UpdateButtons();
return true;
}
else if (iControl == CONTROL_BTNSHOWALL)
{
if (CMediaSettings::GetInstance().GetWatchedMode(m_vecItems->GetContent()) == WatchedModeAll)
CMediaSettings::GetInstance().SetWatchedMode(m_vecItems->GetContent(), WatchedModeUnwatched);
else
CMediaSettings::GetInstance().SetWatchedMode(m_vecItems->GetContent(), WatchedModeAll);
CServiceBroker::GetSettingsComponent()->GetSettings()->Save();
OnFilterItems(GetProperty("filter").asString());
UpdateButtons();
return true;
}
else if (iControl == CONTROL_UPDATE_LIBRARY)
{
if (!CVideoLibraryQueue::GetInstance().IsScanningLibrary())
OnScan("");
else
CVideoLibraryQueue::GetInstance().StopLibraryScanning();
return true;
}
}
break;
// update the display
case GUI_MSG_REFRESH_THUMBS:
Refresh();
break;
}
return CGUIWindowVideoBase::OnMessage(message);
}
SelectFirstUnwatchedItem CGUIWindowVideoNav::GetSettingSelectFirstUnwatchedItem()
{
if (VIDEO::IsVideoDb(*m_vecItems))
{
NODE_TYPE nodeType = CVideoDatabaseDirectory::GetDirectoryChildType(m_vecItems->GetPath());
if (nodeType == NODE_TYPE_SEASONS || nodeType == NODE_TYPE_EPISODES)
{
int iValue = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOLIBRARY_TVSHOWSSELECTFIRSTUNWATCHEDITEM);
if (iValue >= SelectFirstUnwatchedItem::NEVER && iValue <= SelectFirstUnwatchedItem::ALWAYS)
return (SelectFirstUnwatchedItem)iValue;
}
}
return SelectFirstUnwatchedItem::NEVER;
}
IncludeAllSeasonsAndSpecials CGUIWindowVideoNav::GetSettingIncludeAllSeasonsAndSpecials()
{
int iValue = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOLIBRARY_TVSHOWSINCLUDEALLSEASONSANDSPECIALS);
if (iValue >= IncludeAllSeasonsAndSpecials::NEITHER && iValue <= IncludeAllSeasonsAndSpecials::SPECIALS)
return (IncludeAllSeasonsAndSpecials)iValue;
return IncludeAllSeasonsAndSpecials::NEITHER;
}
int CGUIWindowVideoNav::GetFirstUnwatchedItemIndex(bool includeAllSeasons, bool includeSpecials)
{
int iIndex = 0;
int iUnwatchedSeason = INT_MAX;
int iUnwatchedEpisode = INT_MAX;
NODE_TYPE nodeType = CVideoDatabaseDirectory::GetDirectoryChildType(m_vecItems->GetPath());
// Run through the list of items and find the first unwatched season/episode
for (int i = 0; i < m_vecItems->Size(); ++i)
{
CFileItemPtr pItem = m_vecItems->Get(i);
if (pItem->IsParentFolder() || !pItem->HasVideoInfoTag())
continue;
CVideoInfoTag *pTag = pItem->GetVideoInfoTag();
if ((!includeAllSeasons && pTag->m_iSeason < 0) || (!includeSpecials && pTag->m_iSeason == 0))
continue;
// Use the special sort values if they're available
int iSeason = pTag->m_iSpecialSortSeason >= 0 ? pTag->m_iSpecialSortSeason : pTag->m_iSeason;
int iEpisode = pTag->m_iSpecialSortEpisode >= 0 ? pTag->m_iSpecialSortEpisode : pTag->m_iEpisode;
if (nodeType == NODE_TYPE::NODE_TYPE_SEASONS)
{
// Is the season unwatched, and is its season number lower than the currently identified
// first unwatched season
if (pTag->GetPlayCount() == 0 && iSeason < iUnwatchedSeason)
{
iUnwatchedSeason = iSeason;
iIndex = i;
}
}
if (nodeType == NODE_TYPE::NODE_TYPE_EPISODES)
{
// Is the episode unwatched, and is its season number lower
// or is its episode number lower within the current season
if (pTag->GetPlayCount() == 0 && (iSeason < iUnwatchedSeason || (iSeason == iUnwatchedSeason && iEpisode < iUnwatchedEpisode)))
{
iUnwatchedSeason = iSeason;
iUnwatchedEpisode = iEpisode;
iIndex = i;
}
}
}
return iIndex;
}
bool CGUIWindowVideoNav::Update(const std::string &strDirectory, bool updateFilterPath /* = true */)
{
if (!CGUIWindowVideoBase::Update(strDirectory, updateFilterPath))
return false;
SelectFirstUnwatched();
return true;
}
void CGUIWindowVideoNav::SelectFirstUnwatched() {
// Check if we should select the first unwatched item
SelectFirstUnwatchedItem selectFirstUnwatched = GetSettingSelectFirstUnwatchedItem();
if (selectFirstUnwatched != SelectFirstUnwatchedItem::NEVER)
{
bool bIsItemSelected = (m_viewControl.GetSelectedItem() > 0);
if (selectFirstUnwatched == SelectFirstUnwatchedItem::ALWAYS ||
(selectFirstUnwatched == SelectFirstUnwatchedItem::ON_FIRST_ENTRY && !bIsItemSelected))
{
IncludeAllSeasonsAndSpecials incAllSeasonsSpecials = GetSettingIncludeAllSeasonsAndSpecials();
bool bIncludeAllSeasons = (incAllSeasonsSpecials == IncludeAllSeasonsAndSpecials::BOTH || incAllSeasonsSpecials == IncludeAllSeasonsAndSpecials::ALL_SEASONS);
bool bIncludeSpecials = (incAllSeasonsSpecials == IncludeAllSeasonsAndSpecials::BOTH || incAllSeasonsSpecials == IncludeAllSeasonsAndSpecials::SPECIALS);
int iIndex = GetFirstUnwatchedItemIndex(bIncludeAllSeasons, bIncludeSpecials);
m_viewControl.SetSelectedItem(iIndex);
}
}
}
bool CGUIWindowVideoNav::GetDirectory(const std::string &strDirectory, CFileItemList &items)
{
if (m_thumbLoader.IsLoading())
m_thumbLoader.StopThread();
items.ClearArt();
items.ClearProperties();
bool bResult = CGUIWindowVideoBase::GetDirectory(strDirectory, items);
if (bResult)
{
if (VIDEO::IsVideoDb(items))
{
XFILE::CVideoDatabaseDirectory dir;
CQueryParams params;
dir.GetQueryParams(items.GetPath(),params);
VIDEODATABASEDIRECTORY::NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath());
int iFlatten = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_VIDEOLIBRARY_FLATTENTVSHOWS);
int itemsSize = items.GetObjectCount();
int firstIndex = items.Size() - itemsSize;
// perform the flattening logic for tvshows with a single (unwatched) season (+ optional special season)
if (node == NODE_TYPE_SEASONS && !items.IsEmpty())
{
// check if the last item is the "All seasons" item which should be ignored for flattening
if (!items[items.Size() - 1]->HasVideoInfoTag() || items[items.Size() - 1]->GetVideoInfoTag()->m_iSeason < 0)
itemsSize -= 1;
bool bFlatten = (itemsSize == 1 && iFlatten == 1) || iFlatten == 2 || // flatten if one one season or if always flatten is enabled
(itemsSize == 2 && iFlatten == 1 && // flatten if one season + specials
(items[firstIndex]->GetVideoInfoTag()->m_iSeason == 0 || items[firstIndex + 1]->GetVideoInfoTag()->m_iSeason == 0));
if (iFlatten > 0 && !bFlatten && (WatchedMode)CMediaSettings::GetInstance().GetWatchedMode("tvshows") == WatchedModeUnwatched)
{
int count = 0;
for(int i = 0; i < items.Size(); i++)
{
const CFileItemPtr item = items.Get(i);
if (item->GetProperty("unwatchedepisodes").asInteger() != 0 && item->GetVideoInfoTag()->m_iSeason > 0)
count++;
}
bFlatten = (count < 2); // flatten if there is only 1 unwatched season (not counting specials)
}
if (bFlatten)
{ // flatten if one season or flatten always
items.Clear();
CVideoDbUrl videoUrl;
if (!videoUrl.FromString(items.GetPath()))
return false;
videoUrl.AppendPath("-2/");
return GetDirectory(videoUrl.ToString(), items);
}
}
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());
std::map<std::string, std::string> art;
if (m_database.GetArtForItem(details.m_iDbId, details.m_type, art))
{
items.AppendArt(art, details.m_type);
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);
items.SetProperty("showtitle", details.m_strShowTitle);
// the container folder thumb is the parent (i.e. season or show)
if (itemsSize && (node == NODE_TYPE_EPISODES || node == NODE_TYPE_RECENTLY_ADDED_EPISODES))
{
int seasonID = -1;
int seasonParam = params.GetSeason();
// grab all season art when flatten always
if (seasonParam == -2 && iFlatten == 2)
seasonParam = -1;
if (seasonParam >= -1)
seasonID = m_database.GetSeasonId(details.m_iDbId, seasonParam);
else
seasonID = items[firstIndex]->GetVideoInfoTag()->m_iIdSeason;
CGUIListItem::ArtMap seasonArt;
if (seasonID > -1 && m_database.GetArtForItem(seasonID, MediaTypeSeason, seasonArt))
{
items.AppendArt(seasonArt, MediaTypeSeason);
// 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 if (node == NODE_TYPE_TITLE_MOVIES ||
node == NODE_TYPE_RECENTLY_ADDED_MOVIES)
{
if (params.GetSetId() > 0)
{
CGUIListItem::ArtMap setArt;
if (m_database.GetArtForItem(params.GetSetId(), MediaTypeVideoCollection, setArt))
{
items.AppendArt(setArt, MediaTypeVideoCollection);
items.SetArtFallback("fanart", "set.fanart");
if (items.HasArt("set.poster"))
items.SetArtFallback("thumb", "set.poster");
}
}
}
}
else if (URIUtils::PathEquals(items.GetPath(), "special://videoplaylists/"))
items.SetContent("playlists");
else if (!items.IsVirtualDirectoryRoot())
{ // load info from the database
std::string label;
if (items.GetLabel().empty() && m_rootDir.IsSource(items.GetPath(), CMediaSourceSettings::GetInstance().GetSources("video"), &label))
items.SetLabel(label);
if (!items.IsSourcesPath() && !items.IsLibraryFolder())
LoadVideoInfo(items, m_database);
}
CVideoDbUrl videoUrl;
if (videoUrl.FromString(items.GetPath()))
{
if (items.GetContent() == "tags" && !items.Contains("newtag://" + videoUrl.GetType()))
{
const auto newTag{std::make_shared<CFileItem>("newtag://" + videoUrl.GetType(), false)};
newTag->SetLabel(g_localizeStrings.Get(20462));
newTag->SetLabelPreformatted(true);
newTag->SetSpecialSort(SortSpecialOnTop);
items.Add(newTag);
}
}
}
return bResult;
}
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 (StringUtils::StartsWith(pItem->GetPath(), "/-1/")) iItems--;
}
// or the last item
if (m_vecItems->Size() > 2 &&
StringUtils::StartsWith(m_vecItems->Get(m_vecItems->Size()-1)->GetPath(), "/-1/"))
iItems--;
}
std::string items = StringUtils::Format("{} {}", iItems, g_localizeStrings.Get(127));
SET_CONTROL_LABEL(CONTROL_LABELFILES, items);
// set the filter label
std::string strLabel;
// "Playlists"
if (m_vecItems->IsPath("special://videoplaylists/"))
strLabel = g_localizeStrings.Get(136);
// "{Playlist Name}"
else if (m_vecItems->IsPlayList())
{
// get playlist name from path
std::string strDummy;
URIUtils::Split(m_vecItems->GetPath(), strDummy, strLabel);
}
else if (m_vecItems->IsPath("sources://video/"))
strLabel = g_localizeStrings.Get(744);
// everything else is from a videodb:// path
else if (VIDEO::IsVideoDb(*m_vecItems))
{
CVideoDatabaseDirectory dir;
dir.GetLabel(m_vecItems->GetPath(), strLabel);
}
else
strLabel = URIUtils::GetFileName(m_vecItems->GetPath());
SET_CONTROL_LABEL(CONTROL_FILTER, strLabel);
int watchMode = CMediaSettings::GetInstance().GetWatchedMode(m_vecItems->GetContent());
SET_CONTROL_LABEL(CONTROL_BTNSHOWMODE, g_localizeStrings.Get(16100 + watchMode));
SET_CONTROL_SELECTED(GetID(), CONTROL_BTNSHOWALL, watchMode != WatchedModeAll);
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE, g_partyModeManager.IsEnabled());
CONTROL_ENABLE_ON_CONDITION(CONTROL_UPDATE_LIBRARY, !m_vecItems->IsAddonsPath() && !m_vecItems->IsPlugin() && !m_vecItems->IsScript());
}
bool CGUIWindowVideoNav::GetFilteredItems(const std::string &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 std::string& strSearch, CFileItemList& items)
{
CFileItemList tempItems;
struct Entry
{
int id;
std::function<void()> func;
int prefix = 0;
};
const auto entries = std::array{
Entry{20338,
[&strSearch, &tempItems, this]() { m_database.GetMoviesByName(strSearch, tempItems); }},
Entry{20359, [&strSearch, &tempItems,
this]() { m_database.GetEpisodesByName(strSearch, tempItems); }},
Entry{20364, [&strSearch, &tempItems,
this]() { m_database.GetTvShowsByName(strSearch, tempItems); }},
Entry{20391, [&strSearch, &tempItems,
this]() { m_database.GetMusicVideosByName(strSearch, tempItems); }},
Entry{558, [&strSearch, &tempItems,
this]() { m_database.GetMusicVideosByAlbum(strSearch, tempItems); }},
Entry{20342,
[&strSearch, &tempItems, this]() {
m_database.GetMovieGenresByName(strSearch, tempItems);
},
515},
Entry{20343,
[&strSearch, &tempItems, this]() {
m_database.GetTvShowGenresByName(strSearch, tempItems);
},
515},
Entry{20389,
[&strSearch, &tempItems, this]() {
m_database.GetMusicVideoGenresByName(strSearch, tempItems);
},
515},
Entry{20342,
[&strSearch, &tempItems, this]() {
m_database.GetMovieActorsByName(strSearch, tempItems);
},
20337},
Entry{20343,
[&strSearch, &tempItems, this]() {
m_database.GetTvShowsActorsByName(strSearch, tempItems);
},
20337},
Entry{20389,
[&strSearch, &tempItems, this]() {
m_database.GetMusicVideoArtistsByName(strSearch, tempItems);
},
20337},
Entry{20342,
[&strSearch, &tempItems, this]() {
m_database.GetMovieDirectorsByName(strSearch, tempItems);
},
20339},
Entry{20343,
[&strSearch, &tempItems, this]() {
m_database.GetTvShowsDirectorsByName(strSearch, tempItems);
},
20339},
Entry{20389,
[&strSearch, &tempItems, this]() {
m_database.GetMusicVideoDirectorsByName(strSearch, tempItems);
},
20339},
Entry{20365, [&strSearch, &tempItems,
this]() { m_database.GetEpisodesByPlot(strSearch, tempItems); }},
Entry{20323,
[&strSearch, &tempItems, this]() { m_database.GetMoviesByPlot(strSearch, tempItems); }},
};
std::for_each(entries.begin(), entries.end(), [this, &items, &tempItems](const auto& entry) {
entry.func();
std::string msg;
if (entry.prefix > 0)
{
msg = fmt::format("[{} - {}] ", g_localizeStrings.Get(entry.prefix),
g_localizeStrings.Get(entry.id));
}
else
msg = fmt::format("[{}] ", g_localizeStrings.Get(entry.id));
this->AppendAndClearSearchItems(tempItems, msg, items);
});
}
void CGUIWindowVideoNav::OnDeleteItem(const CFileItemPtr& pItem)
{
if (m_vecItems->IsParentFolder())
return;
if (!VIDEO::IsVideoDb(*m_vecItems) && !VIDEO::IsVideoDb(*pItem))
{
if (!pItem->IsPath("newsmartplaylist://video") && !pItem->IsPath("special://videoplaylists/") &&
!pItem->IsPath("sources://video/") && !URIUtils::IsProtocol(pItem->GetPath(), "newtag"))
CGUIWindowVideoBase::OnDeleteItem(pItem);
}
else if (StringUtils::StartsWithNoCase(pItem->GetPath(), "videodb://movies/sets/") &&
pItem->GetPath().size() > 22 && pItem->m_bIsFolder)
{
CGUIDialogYesNo* pDialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogYesNo>(WINDOW_DIALOG_YES_NO);
if (!pDialog)
return;
pDialog->SetHeading(CVariant{432});
std::string strLabel = StringUtils::Format(
g_localizeStrings.Get(pItem->HasVideoVersions() ? 40021 : 433), pItem->GetLabel());
pDialog->SetLine(1, CVariant{std::move(strLabel)});
pDialog->SetLine(2, CVariant{""});
pDialog->Open();
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->IsPath(CUtil::VideoPlaylistsLocation()) ||
m_vecItems->IsPath("special://videoplaylists/"))
{
pItem->m_bIsFolder = false;
CGUIComponent *gui = CServiceBroker::GetGUI();
if (gui && gui->ConfirmDelete(pItem->GetPath()))
CFileUtils::DeleteItem(pItem);
}
else
{
if (!CGUIDialogVideoInfo::DeleteVideoItem(pItem))
return;
}
int itemNumber = m_viewControl.GetSelectedItem();
int select = itemNumber >= m_vecItems->Size()-1 ? itemNumber-1 : itemNumber;
m_viewControl.SetSelectedItem(select);
CUtil::DeleteVideoDatabaseDirectoryCache();
}
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);
CVideoDatabaseDirectory dir;
NODE_TYPE node = dir.GetDirectoryChildType(m_vecItems->GetPath());
const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
if (!item)
{
// nothing to do here
}
else if (m_vecItems->IsPath("sources://video/"))
{
// get the usual shares
CGUIDialogContextMenu::GetContextButtons("video", item, buttons);
if (!item->IsDVD() && item->GetPath() != "add" && !item->IsParentFolder() &&
(profileManager->GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser))
{
CVideoDatabase database;
database.Open();
ADDON::ScraperPtr info = database.GetScraperForPath(item->GetPath());
if (!item->IsLiveTV() && !item->IsAddonsPath() && !URIUtils::IsUPnP(item->GetPath()))
{
if (info && info->Content() != CONTENT_NONE)
{
buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20442);
buttons.Add(CONTEXT_BUTTON_SCAN, 13349);
}
else
buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20333);
}
}
}
else
{
// are we in the playlists location?
bool inPlaylists = m_vecItems->IsPath(CUtil::VideoPlaylistsLocation()) ||
m_vecItems->IsPath("special://videoplaylists/");
if (item->HasVideoInfoTag() && item->HasProperty("artist_musicid"))
buttons.Add(CONTEXT_BUTTON_GO_TO_ARTIST, 20396);
if (item->HasVideoInfoTag() && item->HasProperty("album_musicid"))
buttons.Add(CONTEXT_BUTTON_GO_TO_ALBUM, 20397);
if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->m_strAlbum.empty() &&
!item->GetVideoInfoTag()->m_artist.empty() &&
!item->GetVideoInfoTag()->m_strTitle.empty())
{
CMusicDatabase database;
database.Open();
if (database.GetSongByArtistAndAlbumAndTitle(StringUtils::Join(item->GetVideoInfoTag()->m_artist, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->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);
// can we update the database?
if (profileManager->GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser)
{
if (!CVideoLibraryQueue::GetInstance().IsScanningLibrary() && VIDEO::IsVideoDb(*item) &&
item->HasVideoInfoTag() &&
(item->GetVideoInfoTag()->m_type == MediaTypeMovie || // movies
item->GetVideoInfoTag()->m_type == MediaTypeTvShow || // tvshows
item->GetVideoInfoTag()->m_type == MediaTypeSeason || // seasons
item->GetVideoInfoTag()->m_type == MediaTypeEpisode || // episodes
item->GetVideoInfoTag()->m_type == MediaTypeMusicVideo || // musicvideos
item->GetVideoInfoTag()->m_type == "tag" || // tags
item->GetVideoInfoTag()->m_type == MediaTypeVideoCollection)) // sets
{
buttons.Add(CONTEXT_BUTTON_EDIT, 16106);
}
if (node == NODE_TYPE_TITLE_TVSHOWS)
{
buttons.Add(CONTEXT_BUTTON_SCAN, 13349);
}
if (node == NODE_TYPE_ACTOR && !dir.IsAllItem(item->GetPath()) && item->m_bIsFolder)
{
if (StringUtils::StartsWithNoCase(m_vecItems->GetPath(), "videodb://musicvideos")) // mvids
buttons.Add(CONTEXT_BUTTON_SET_ARTIST_THUMB, 13359);
else
buttons.Add(CONTEXT_BUTTON_SET_ACTOR_THUMB, 20403);
}
}
if (!VIDEO::IsVideoDb(*m_vecItems) && !m_vecItems->IsVirtualDirectoryRoot())
{ // non-video db items, file operations are allowed
if ((CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_FILELISTS_ALLOWFILEDELETION) &&
CUtil::SupportsWriteFileOperations(item->GetPath())) ||
(inPlaylists && URIUtils::GetFileName(item->GetPath()) != "PartyMode-Video.xsp"
&& (item->IsPlayList() || item->IsSmartPlayList())))
{
buttons.Add(CONTEXT_BUTTON_DELETE, 117);
buttons.Add(CONTEXT_BUTTON_RENAME, 118);
}
// add "Set/Change content" to folders
if (item->m_bIsFolder && !VIDEO::IsVideoDb(*item) && !item->IsPlayList() &&
!item->IsSmartPlayList() && !item->IsLibraryFolder() && !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 && info->Content() != CONTENT_NONE)
buttons.Add(CONTEXT_BUTTON_SCAN, 13349);
}
}
if ((!item->HasVideoInfoTag() || item->GetVideoInfoTag()->m_iDbId == -1) && info && info->Content() != CONTENT_NONE)
buttons.Add(CONTEXT_BUTTON_SCAN_TO_LIBRARY, 21845);
}
}
}
bool CGUIWindowVideoNav::OnPopupMenu(int iItem)
{
if (iItem >= 0 && iItem < m_vecItems->Size())
{
const auto item = m_vecItems->Get(iItem);
item->SetProperty("CheckAutoPlayNextItem", true);
}
return CGUIWindowVideoBase::OnPopupMenu(iItem);
}
bool CGUIWindowVideoNav::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
CFileItemPtr item;
if (itemNumber >= 0 && itemNumber < m_vecItems->Size())
item = m_vecItems->Get(itemNumber);
if (CGUIDialogContextMenu::OnContextButton("video", item, button))
{
if (button == CONTEXT_BUTTON_REMOVE_SOURCE && !item->IsLiveTV()
&&!item->IsRSS() && !URIUtils::IsUPnP(item->GetPath()))
{
// if the source has been properly removed, remove the cached source list because the list has changed
if (OnUnAssignContent(item->GetPath(), 20375, 20340))
m_vecItems->RemoveDiscCache(GetID());
}
Refresh();
return true;
}
switch (button)
{
case CONTEXT_BUTTON_EDIT:
{
const CONTEXT_BUTTON ret{
static_cast<CONTEXT_BUTTON>(CGUIDialogVideoInfo::ManageVideoItem(item))};
if (ret != CONTEXT_BUTTON_CANCELLED)
{
Refresh(true);
if (ret == CONTEXT_BUTTON_DELETE)
{
int select = itemNumber >= m_vecItems->Size()-1 ? itemNumber-1:itemNumber;
m_viewControl.SetSelectedItem(select);
}
}
return true;
}
case CONTEXT_BUTTON_SET_ACTOR_THUMB:
case CONTEXT_BUTTON_SET_ARTIST_THUMB:
{
std::string type = MediaTypeSeason;
if (button == CONTEXT_BUTTON_SET_ACTOR_THUMB)
type = "actor";
else if (button == CONTEXT_BUTTON_SET_ARTIST_THUMB)
type = MediaTypeArtist;
bool result = CGUIDialogVideoInfo::ManageVideoItemArtwork(m_vecItems->Get(itemNumber), type);
Refresh();
return result;
}
case CONTEXT_BUTTON_GO_TO_ARTIST:
{
std::string strPath;
strPath = StringUtils::Format("musicdb://artists/{}/",
item->GetProperty("artist_musicid").asInteger());
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_NAV, strPath);
return true;
}
case CONTEXT_BUTTON_GO_TO_ALBUM:
{
std::string strPath;
strPath = StringUtils::Format("musicdb://albums/{}/",
item->GetProperty("album_musicid").asInteger());
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_NAV, strPath);
return true;
}
case CONTEXT_BUTTON_PLAY_OTHER:
{
CMusicDatabase database;
database.Open();
CSong song;
if (database.GetSong(database.GetSongByArtistAndAlbumAndTitle(StringUtils::Join(m_vecItems->Get(itemNumber)->GetVideoInfoTag()->m_artist, CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_videoItemSeparator),m_vecItems->Get(itemNumber)->GetVideoInfoTag()->m_strAlbum,
m_vecItems->Get(itemNumber)->GetVideoInfoTag()->m_strTitle),
song))
{
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MEDIA_PLAY, 0, 0,
static_cast<void*>(new CFileItem(song)));
}
return true;
}
case CONTEXT_BUTTON_SCAN_TO_LIBRARY:
CGUIDialogVideoInfo::ShowFor(*item);
return true;
default:
break;
}
return CGUIWindowVideoBase::OnContextButton(itemNumber, button);
}
bool CGUIWindowVideoNav::OnAddMediaSource()
{
return CGUIDialogMediaSource::ShowAndAddMediaSource("video");
}
bool CGUIWindowVideoNav::OnClick(int iItem, const std::string &player)
{
CFileItemPtr item = m_vecItems->Get(iItem);
if (StringUtils::StartsWithNoCase(item->GetPath(), "newtag://"))
{
// dont allow update while scanning
if (CVideoLibraryQueue::GetInstance().IsScanningLibrary())
{
HELPERS::ShowOKDialogText(CVariant{257}, CVariant{14057});
return true;
}
//Get the new title
std::string strTag;
if (!CGUIKeyboardFactory::ShowAndGetInput(strTag, CVariant{g_localizeStrings.Get(20462)}, false))
return true;
CVideoDatabase videodb;
if (!videodb.Open())
return true;
// get the media type and convert from plural to singular (by removing the trailing "s")
std::string mediaType = item->GetPath().substr(9);
mediaType.pop_back();
std::string localizedType = CGUIDialogVideoInfo::GetLocalizedVideoType(mediaType);
if (localizedType.empty())
return true;
if (!videodb.GetSingleValue("tag", "tag.tag_id", videodb.PrepareSQL("tag.name = '%s' AND tag.tag_id IN (SELECT tag_link.tag_id FROM tag_link WHERE tag_link.media_type = '%s')", strTag.c_str(), mediaType.c_str())).empty())
{
std::string strError = StringUtils::Format(g_localizeStrings.Get(20463), strTag);
HELPERS::ShowOKDialogText(CVariant{20462}, CVariant{std::move(strError)});