-
Notifications
You must be signed in to change notification settings - Fork 345
/
videodlg.cpp
3766 lines (3155 loc) · 109 KB
/
videodlg.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
#include <set>
#include <map>
#include <QApplication>
#include <QTimer>
#include <QList>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QUrl>
#include "mythcontext.h"
#include "compat.h"
#include "mythdirs.h"
#include "mythuihelper.h"
#include "mythprogressdialog.h"
#include "mythuitext.h"
#include "mythuibutton.h"
#include "mythuibuttonlist.h"
#include "mythuibuttontree.h"
#include "mythuiimage.h"
#include "mythuistatetype.h"
#include "mythuimetadataresults.h"
#include "mythdialogbox.h"
#include "mythgenerictree.h"
#include "mythsystem.h"
#include "remotefile.h"
#include "remoteutil.h"
#include "storagegroup.h"
#include "videoscan.h"
#include "globals.h"
#include "videometadatalistmanager.h"
#include "parentalcontrols.h"
#include "videoutils.h"
#include "dbaccess.h"
#include "dirscan.h"
#include "metadatafactory.h"
#include "videofilter.h"
#include "editvideometadata.h"
#include "videopopups.h"
#include "videolist.h"
#include "videoplayercommand.h"
#include "videodlg.h"
#include "videofileassoc.h"
#include "videoplayersettings.h"
#include "videometadatasettings.h"
namespace
{
bool IsValidDialogType(int num)
{
for (int i = 1; i <= VideoDialog::dtLast - 1; i <<= 1)
if (num == i) return true;
return false;
}
class ParentalLevelNotifyContainer : public QObject
{
Q_OBJECT
signals:
void SigLevelChanged();
public:
ParentalLevelNotifyContainer(QObject *lparent = 0) :
QObject(lparent), m_level(ParentalLevel::plNone)
{
connect(&m_levelCheck,
SIGNAL(SigResultReady(bool, ParentalLevel::Level)),
SLOT(OnResultReady(bool, ParentalLevel::Level)));
}
const ParentalLevel &GetLevel() const { return m_level; }
void SetLevel(ParentalLevel level)
{
m_levelCheck.Check(m_level.GetLevel(), level.GetLevel());
}
private slots:
void OnResultReady(bool passwordValid, ParentalLevel::Level newLevel)
{
ParentalLevel lastLevel = m_level;
if (passwordValid)
{
m_level = newLevel;
}
if (m_level.GetLevel() == ParentalLevel::plNone)
{
m_level = ParentalLevel(ParentalLevel::plLowest);
}
if (lastLevel != m_level)
{
emit SigLevelChanged();
}
}
private:
ParentalLevel m_level;
ParentalLevelChangeChecker m_levelCheck;
};
MythGenericTree *GetNodePtrFromButton(MythUIButtonListItem *item)
{
if (item)
return item->GetData().value<MythGenericTree *>();
return 0;
}
VideoMetadata *GetMetadataPtrFromNode(MythGenericTree *node)
{
if (node)
return node->GetData().value<TreeNodeData>().GetMetadata();
return 0;
}
bool GetLocalVideoImage(const QString &video_uid, const QString &filename,
const QStringList &in_dirs, QString &image,
QString title, int season,
const QString host, QString sgroup,
int episode = 0, bool isScreenshot = false)
{
QStringList search_dirs(in_dirs);
QFileInfo qfi(filename);
search_dirs += qfi.absolutePath();
if (title.contains("/"))
title.replace("/", "-");
const QString base_name = qfi.completeBaseName();
QList<QByteArray> image_types = QImageReader::supportedImageFormats();
typedef std::set<QString> image_type_list;
image_type_list image_exts;
QString suffix;
if (sgroup == "Coverart")
suffix = "coverart";
if (sgroup == "Fanart")
suffix = "fanart";
if (sgroup == "Screenshots")
suffix = "screenshot";
if (sgroup == "Banners")
suffix = "banner";
for (QList<QByteArray>::const_iterator it = image_types.begin();
it != image_types.end(); ++it)
{
image_exts.insert(QString(*it).toLower());
}
if (!host.isEmpty())
{
QStringList hostFiles;
RemoteGetFileList(host, "", &hostFiles, sgroup, true);
const QString hntm("%2.%3");
for (image_type_list::const_iterator ext = image_exts.begin();
ext != image_exts.end(); ++ext)
{
QStringList sfn;
if (episode > 0 || season > 0)
{
if (isScreenshot)
sfn += hntm.arg(QString("%1 Season %2x%3_%4")
.arg(title).arg(QString::number(season))
.arg(QString::number(episode))
.arg(suffix))
.arg(*ext);
else
sfn += hntm.arg(QString("%1 Season %2_%3")
.arg(title).arg(QString::number(season))
.arg(suffix))
.arg(*ext);
}
else
{
sfn += hntm.arg(base_name + "_%1").arg(suffix).arg(*ext);
sfn += hntm.arg(video_uid + "_%1").arg(suffix).arg(*ext);
}
for (QStringList::const_iterator i = sfn.begin();
i != sfn.end(); ++i)
{
if (hostFiles.contains(*i))
{
image = *i;
return true;
}
}
}
}
const QString fntm("%1/%2.%3");
for (QStringList::const_iterator dir = search_dirs.begin();
dir != search_dirs.end(); ++dir)
{
if (!(*dir).length()) continue;
for (image_type_list::const_iterator ext = image_exts.begin();
ext != image_exts.end(); ++ext)
{
QStringList sfn;
if (season > 0 || episode > 0)
{
if (isScreenshot)
sfn += fntm.arg(*dir).arg(QString("%1 Season %2x%3_%4")
.arg(title).arg(QString::number(season))
.arg(QString::number(episode))
.arg(suffix))
.arg(*ext);
else if (!isScreenshot)
sfn += fntm.arg(*dir).arg(QString("%1 Season %2_%3")
.arg(title).arg(QString::number(season))
.arg(suffix))
.arg(*ext);
}
if (!isScreenshot)
{
sfn += fntm.arg(*dir).arg(QString(base_name + "_%1")
.arg(suffix)).arg(*ext);
sfn += fntm.arg(*dir).arg(QString(video_uid + "_%1")
.arg(suffix)).arg(*ext);
}
for (QStringList::const_iterator i = sfn.begin();
i != sfn.end(); ++i)
{
if (QFile::exists(*i))
{
image = *i;
return true;
}
}
}
}
return false;
}
void PlayVideo(const QString &filename,
const VideoMetadataListManager &video_list, bool useAltPlayer = false)
{
const int WATCHED_WATERMARK = 10000; // Less than this and the chain of
// videos will not be followed when
// playing.
VideoMetadataListManager::VideoMetadataPtr item = video_list.byFilename(filename);
if (!item) return;
QTime playing_time;
do
{
playing_time.start();
if (useAltPlayer)
VideoPlayerCommand::AltPlayerFor(item.get()).Play();
else
VideoPlayerCommand::PlayerFor(item.get()).Play();
if (item->GetChildID() > 0 && video_list.byID(item->GetChildID()))
item = video_list.byID(item->GetChildID());
else
break;
}
while (item && playing_time.elapsed() > WATCHED_WATERMARK);
}
class FanartLoader: public QObject
{
Q_OBJECT
public:
FanartLoader() : itemsPast(0)
{
connect(&m_fanartTimer, SIGNAL(timeout()), SLOT(fanartLoad()));
}
~FanartLoader()
{
m_fanartTimer.stop();
m_fanartTimer.disconnect(this);
}
void LoadImage(const QString &filename, MythUIImage *image)
{
bool wasActive = m_fanartTimer.isActive();
if (filename.isEmpty())
{
if (wasActive)
m_fanartTimer.stop();
image->Reset();
itemsPast++;
}
else
{
QMutexLocker locker(&m_fanartLock);
m_fanart = image;
if (filename != m_fanart->GetFilename())
{
if (wasActive)
m_fanartTimer.stop();
if (itemsPast > 2)
m_fanart->Reset();
m_fanart->SetFilename(filename);
m_fanartTimer.setSingleShot(true);
m_fanartTimer.start(300);
if (wasActive)
itemsPast++;
else
itemsPast = 0;
}
else
itemsPast = 0;
}
}
protected slots:
void fanartLoad(void)
{
QMutexLocker locker(&m_fanartLock);
m_fanart->Load();
}
private:
int itemsPast;
QMutex m_fanartLock;
MythUIImage *m_fanart;
QTimer m_fanartTimer;
};
FanartLoader fanartLoader;
struct CopyMetadataDestination
{
virtual void handleText(const QString &name, const QString &value) = 0;
virtual void handleState(const QString &name, const QString &value) = 0;
virtual void handleImage(const QString &name,
const QString &filename) = 0;
};
class ScreenCopyDest : public CopyMetadataDestination
{
public:
ScreenCopyDest(MythScreenType *screen) : m_screen(screen) {}
void handleText(const QString &name, const QString &value)
{
CheckedSet(m_screen, name, value);
}
void handleState(const QString &name, const QString &value)
{
handleText(name, value);
}
void handleImage(const QString &name, const QString &filename)
{
MythUIImage *image = NULL;
UIUtilW::Assign(m_screen, image, name);
if (image)
{
if (name != "fanart")
{
if (!filename.isEmpty())
{
image->SetFilename(filename);
image->Load();
}
else
image->Reset();
}
else
{
fanartLoader.LoadImage(filename, image);
}
}
}
private:
MythScreenType *m_screen;
};
class MythUIButtonListItemCopyDest : public CopyMetadataDestination
{
public:
MythUIButtonListItemCopyDest(MythUIButtonListItem *item) :
m_item(item) {}
void handleText(const QString &name, const QString &value)
{
m_item->SetText(value, name);
}
void handleState(const QString &name, const QString &value)
{
m_item->DisplayState(value, name);
}
void handleImage(const QString &name, const QString &filename)
{
(void) name;
(void) filename;
}
private:
MythUIButtonListItem *m_item;
};
void CopyMetadataToUI(const VideoMetadata *metadata,
CopyMetadataDestination &dest)
{
typedef std::map<QString, QString> valuelist;
valuelist tmp;
if (metadata)
{
QString coverfile;
if ((metadata->IsHostSet()
&& !metadata->GetCoverFile().startsWith("/"))
&& !metadata->GetCoverFile().isEmpty()
&& !IsDefaultCoverFile(metadata->GetCoverFile()))
{
coverfile = generate_file_url("Coverart", metadata->GetHost(),
metadata->GetCoverFile());
}
else
{
coverfile = metadata->GetCoverFile();
}
if (!IsDefaultCoverFile(coverfile))
tmp["coverart"] = coverfile;
tmp["coverfile"] = coverfile;
QString screenshotfile;
if (metadata->IsHostSet() && !metadata->GetScreenshot().startsWith("/")
&& !metadata->GetScreenshot().isEmpty())
{
screenshotfile = generate_file_url("Screenshots",
metadata->GetHost(), metadata->GetScreenshot());
}
else
{
screenshotfile = metadata->GetScreenshot();
}
if (!IsDefaultScreenshot(screenshotfile))
tmp["screenshot"] = screenshotfile;
tmp["screenshotfile"] = screenshotfile;
QString bannerfile;
if (metadata->IsHostSet() && !metadata->GetBanner().startsWith("/")
&& !metadata->GetBanner().isEmpty())
{
bannerfile = generate_file_url("Banners", metadata->GetHost(),
metadata->GetBanner());
}
else
{
bannerfile = metadata->GetBanner();
}
if (!IsDefaultBanner(bannerfile))
tmp["banner"] = bannerfile;
tmp["bannerfile"] = bannerfile;
QString fanartfile;
if (metadata->IsHostSet() && !metadata->GetFanart().startsWith("/")
&& !metadata->GetFanart().isEmpty())
{
fanartfile = generate_file_url("Fanart", metadata->GetHost(),
metadata->GetFanart());
}
else
{
fanartfile = metadata->GetFanart();
}
if (!IsDefaultFanart(fanartfile))
tmp["fanart"] = fanartfile;
tmp["fanartfile"] = fanartfile;
tmp["trailerstate"] = TrailerToState(metadata->GetTrailer());
tmp["studiostate"] = metadata->GetStudio();
tmp["userratingstate"] =
QString::number((int)(metadata->GetUserRating()));
tmp["watchedstate"] = WatchedToState(metadata->GetWatched());
tmp["videolevel"] = ParentalLevelToState(metadata->GetShowLevel());
}
struct helper
{
helper(valuelist &values, CopyMetadataDestination &d) :
m_vallist(values), m_dest(d) {}
void handleImage(const QString &name)
{
m_dest.handleImage(name, m_vallist[name]);
}
void handleState(const QString &name)
{
m_dest.handleState(name, m_vallist[name]);
}
private:
valuelist &m_vallist;
CopyMetadataDestination &m_dest;
};
helper h(tmp, dest);
h.handleImage("coverart");
h.handleImage("screenshot");
h.handleImage("banner");
h.handleImage("fanart");
h.handleState("trailerstate");
h.handleState("userratingstate");
h.handleState("watchedstate");
h.handleState("videolevel");
}
}
class ItemDetailPopup : public MythScreenType
{
Q_OBJECT
public:
static bool Exists()
{
// TODO: Add ability to theme loader to do this a better way.
return LoadWindowFromXML("video-ui.xml", WINDOW_NAME, NULL);
}
public:
ItemDetailPopup(MythScreenStack *lparent, VideoMetadata *metadata,
const VideoMetadataListManager &listManager) :
MythScreenType(lparent, WINDOW_NAME), m_metadata(metadata),
m_listManager(listManager), m_playButton(NULL), m_doneButton(NULL)
{
}
bool Create()
{
if (!LoadWindowFromXML("video-ui.xml", WINDOW_NAME, this))
return false;
UIUtilW::Assign(this, m_playButton, "play_button");
UIUtilW::Assign(this, m_doneButton, "done_button");
if (m_playButton)
connect(m_playButton, SIGNAL(Clicked()), SLOT(OnPlay()));
if (m_doneButton)
connect(m_doneButton, SIGNAL(Clicked()), SLOT(OnDone()));
BuildFocusList();
if (m_playButton || m_doneButton)
SetFocusWidget(m_playButton ? m_playButton : m_doneButton);
MetadataMap metadataMap;
m_metadata->toMap(metadataMap);
SetTextFromMap(metadataMap);
ScreenCopyDest dest(this);
CopyMetadataToUI(m_metadata, dest);
return true;
}
private slots:
void OnPlay()
{
PlayVideo(m_metadata->GetFilename(), m_listManager);
}
void OnDone()
{
// TODO: Close() can do horrible things, this will pop
// our screen, delete us, and return here.
Close();
}
private:
bool OnKeyAction(const QStringList &actions)
{
bool handled = false;
for (QStringList::const_iterator key = actions.begin();
key != actions.end(); ++key)
{
handled = true;
if (*key == "SELECT" || *key == "PLAYBACK")
OnPlay();
else
handled = false;
}
return handled;
}
protected:
bool keyPressEvent(QKeyEvent *levent)
{
if (!MythScreenType::keyPressEvent(levent))
{
QStringList actions;
bool handled = GetMythMainWindow()->TranslateKeyPress("Video",
levent, actions);
if (!handled && !OnKeyAction(actions))
{
handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend",
levent, actions);
OnKeyAction(actions);
}
}
return true;
}
private:
static const char * const WINDOW_NAME;
VideoMetadata *m_metadata;
const VideoMetadataListManager &m_listManager;
MythUIButton *m_playButton;
MythUIButton *m_doneButton;
};
const char * const ItemDetailPopup::WINDOW_NAME = "itemdetailpopup";
class VideoDialogPrivate
{
private:
typedef std::list<std::pair<QString, ParentalLevel::Level> >
parental_level_map;
struct rating_to_pl_less :
public std::binary_function<parental_level_map::value_type,
parental_level_map::value_type, bool>
{
bool operator()(const parental_level_map::value_type &lhs,
const parental_level_map::value_type &rhs) const
{
return lhs.first.length() < rhs.first.length();
}
};
typedef VideoDialog::VideoListPtr VideoListPtr;
public:
VideoDialogPrivate(VideoListPtr videoList, VideoDialog::DialogType type,
VideoDialog::BrowseType browse) :
m_switchingLayout(false), m_firstLoadPass(true),
m_rememberPosition(false), m_videoList(videoList), m_rootNode(0),
m_currentNode(0), m_treeLoaded(false), m_isFlatList(false),
m_type(type), m_browse(browse), m_scanner(0)
{
if (gCoreContext->GetNumSetting("mythvideo.ParentalLevelFromRating", 0))
{
for (ParentalLevel sl(ParentalLevel::plLowest);
sl.GetLevel() <= ParentalLevel::plHigh && sl.good(); ++sl)
{
QString ratingstring =
gCoreContext->GetSetting(QString("mythvideo.AutoR2PL%1")
.arg(sl.GetLevel()));
QStringList ratings =
ratingstring.split(':', QString::SkipEmptyParts);
for (QStringList::const_iterator p = ratings.begin();
p != ratings.end(); ++p)
{
m_rating_to_pl.push_back(
parental_level_map::value_type(*p, sl.GetLevel()));
}
}
m_rating_to_pl.sort(std::not2(rating_to_pl_less()));
}
m_rememberPosition =
gCoreContext->GetNumSetting("mythvideo.VideoTreeRemember", 0);
m_isFileBrowser = gCoreContext->GetNumSetting("VideoDialogNoDB", 0);
m_groupType = gCoreContext->GetNumSetting("mythvideo.db_group_type", 0);
m_altPlayerEnabled =
gCoreContext->GetNumSetting("mythvideo.EnableAlternatePlayer");
m_autoMeta = gCoreContext->GetNumSetting("mythvideo.AutoMetaDataScan", 1);
m_artDir = gCoreContext->GetSetting("VideoArtworkDir");
m_sshotDir = gCoreContext->GetSetting("mythvideo.screenshotDir");
m_fanDir = gCoreContext->GetSetting("mythvideo.fanartDir");
m_banDir = gCoreContext->GetSetting("mythvideo.bannerDir");
}
~VideoDialogPrivate()
{
delete m_scanner;
if (m_rememberPosition && m_lastTreeNodePath.length())
{
gCoreContext->SaveSetting("mythvideo.VideoTreeLastActive",
m_lastTreeNodePath);
}
}
void AutomaticParentalAdjustment(VideoMetadata *metadata)
{
if (metadata && !m_rating_to_pl.empty())
{
QString rating = metadata->GetRating();
for (parental_level_map::const_iterator p = m_rating_to_pl.begin();
!rating.isEmpty() && p != m_rating_to_pl.end(); ++p)
{
if (rating.indexOf(p->first) != -1)
{
metadata->SetShowLevel(p->second);
break;
}
}
}
}
void DelayVideoListDestruction(VideoListPtr videoList)
{
m_savedPtr = new VideoListDeathDelay(videoList);
}
public:
ParentalLevelNotifyContainer m_parentalLevel;
bool m_switchingLayout;
static VideoDialog::VideoListDeathDelayPtr m_savedPtr;
bool m_firstLoadPass;
bool m_rememberPosition;
VideoListPtr m_videoList;
MythGenericTree *m_rootNode;
MythGenericTree *m_currentNode;
bool m_treeLoaded;
bool m_isFileBrowser;
int m_groupType;
bool m_isFlatList;
bool m_altPlayerEnabled;
VideoDialog::DialogType m_type;
VideoDialog::BrowseType m_browse;
bool m_autoMeta;
QString m_artDir;
QString m_sshotDir;
QString m_fanDir;
QString m_banDir;
VideoScanner *m_scanner;
QString m_lastTreeNodePath;
private:
parental_level_map m_rating_to_pl;
};
VideoDialog::VideoListDeathDelayPtr VideoDialogPrivate::m_savedPtr;
class VideoListDeathDelayPrivate
{
public:
VideoListDeathDelayPrivate(VideoDialog::VideoListPtr toSave) :
m_savedList(toSave)
{
}
VideoDialog::VideoListPtr GetSaved()
{
return m_savedList;
}
private:
VideoDialog::VideoListPtr m_savedList;
};
VideoListDeathDelay::VideoListDeathDelay(VideoDialog::VideoListPtr toSave) :
QObject(qApp)
{
m_d = new VideoListDeathDelayPrivate(toSave);
QTimer::singleShot(3000, this, SLOT(OnTimeUp()));
}
VideoListDeathDelay::~VideoListDeathDelay()
{
delete m_d;
}
VideoDialog::VideoListPtr VideoListDeathDelay::GetSaved()
{
return m_d->GetSaved();
}
void VideoListDeathDelay::OnTimeUp()
{
deleteLater();
}
VideoDialog::VideoListDeathDelayPtr &VideoDialog::GetSavedVideoList()
{
return VideoDialogPrivate::m_savedPtr;
}
VideoDialog::VideoDialog(MythScreenStack *lparent, QString lname,
VideoListPtr video_list, DialogType type, BrowseType browse) :
MythScreenType(lparent, lname), m_menuPopup(0), m_busyPopup(0),
m_videoButtonList(0), m_videoButtonTree(0), m_titleText(0),
m_novideoText(0), m_positionText(0), m_crumbText(0), m_coverImage(0),
m_screenshot(0), m_banner(0), m_fanart(0), m_trailerState(0),
m_parentalLevelState(0), m_watchedState(0), m_studioState(0)
{
m_metadataFactory = new MetadataFactory(this);
m_d = new VideoDialogPrivate(video_list, type, browse);
m_popupStack = GetMythMainWindow()->GetStack("popup stack");
m_mainStack = GetMythMainWindow()->GetMainStack();
m_d->m_videoList->setCurrentVideoFilter(VideoFilterSettings(true,
lname));
m_d->m_parentalLevel.SetLevel(ParentalLevel(gCoreContext->
GetNumSetting("VideoDefaultParentalLevel",
ParentalLevel::plLowest)));
StorageGroup::ClearGroupToUseCache();
}
VideoDialog::~VideoDialog()
{
if (!m_d->m_switchingLayout)
m_d->DelayVideoListDestruction(m_d->m_videoList);
SavePosition();
delete m_d;
}
void VideoDialog::SavePosition(void)
{
m_d->m_lastTreeNodePath = "";
if (m_d->m_type == DLG_TREE)
{
MythGenericTree *node = m_videoButtonTree->GetCurrentNode();
if (node)
m_d->m_lastTreeNodePath = node->getRouteByString().join("\n");
}
else if (m_d->m_type == DLG_BROWSER || m_d->m_type == DLG_GALLERY)
{
MythUIButtonListItem *item = m_videoButtonList->GetItemCurrent();
if (item)
{
MythGenericTree *node = GetNodePtrFromButton(item);
if (node)
m_d->m_lastTreeNodePath = node->getRouteByString().join("\n");
}
}
gCoreContext->SaveSetting("mythvideo.VideoTreeLastActive", m_d->m_lastTreeNodePath);
}
bool VideoDialog::Create()
{
if (m_d->m_type == DLG_DEFAULT)
{
m_d->m_type = static_cast<DialogType>(
gCoreContext->GetNumSetting("Default MythVideo View", DLG_GALLERY));
m_d->m_browse = static_cast<BrowseType>(
gCoreContext->GetNumSetting("mythvideo.db_group_type", BRS_FOLDER));
}
if (!IsValidDialogType(m_d->m_type))
{
m_d->m_type = DLG_GALLERY;
}
QString windowName = "videogallery";
int flatlistDefault = 0;
switch (m_d->m_type)
{
case DLG_BROWSER:
windowName = "browser";
flatlistDefault = 1;
break;
case DLG_GALLERY:
windowName = "gallery";
break;
case DLG_TREE:
windowName = "tree";
break;
case DLG_MANAGER:
m_d->m_isFlatList =
gCoreContext->GetNumSetting("mythvideo.db_folder_view", 1);
windowName = "manager";
flatlistDefault = 1;
break;
case DLG_DEFAULT:
default:
break;
}
switch (m_d->m_browse)
{
case BRS_GENRE:
m_d->m_groupType = BRS_GENRE;
break;
case BRS_CATEGORY:
m_d->m_groupType = BRS_CATEGORY;
break;
case BRS_YEAR:
m_d->m_groupType = BRS_YEAR;
break;
case BRS_DIRECTOR:
m_d->m_groupType = BRS_DIRECTOR;
break;
case BRS_STUDIO:
m_d->m_groupType = BRS_STUDIO;
break;
case BRS_CAST:
m_d->m_groupType = BRS_CAST;
break;
case BRS_USERRATING:
m_d->m_groupType = BRS_USERRATING;
break;
case BRS_INSERTDATE:
m_d->m_groupType = BRS_INSERTDATE;
break;
case BRS_TVMOVIE:
m_d->m_groupType = BRS_TVMOVIE;
break;
case BRS_FOLDER:
default:
m_d->m_groupType = BRS_FOLDER;
break;
}
m_d->m_isFlatList =
gCoreContext->GetNumSetting(QString("mythvideo.folder_view_%1")
.arg(m_d->m_type), flatlistDefault);
if (!LoadWindowFromXML("video-ui.xml", windowName, this))
return false;
bool err = false;
if (m_d->m_type == DLG_TREE)
UIUtilE::Assign(this, m_videoButtonTree, "videos", &err);
else
UIUtilE::Assign(this, m_videoButtonList, "videos", &err);
UIUtilW::Assign(this, m_titleText, "title");
UIUtilW::Assign(this, m_novideoText, "novideos");
UIUtilW::Assign(this, m_positionText, "position");
UIUtilW::Assign(this, m_crumbText, "breadcrumbs");
UIUtilW::Assign(this, m_coverImage, "coverart");
UIUtilW::Assign(this, m_screenshot, "screenshot");
UIUtilW::Assign(this, m_banner, "banner");
UIUtilW::Assign(this, m_fanart, "fanart");
UIUtilW::Assign(this, m_trailerState, "trailerstate");
UIUtilW::Assign(this, m_parentalLevelState, "parentallevel");
UIUtilW::Assign(this, m_watchedState, "watchedstate");
UIUtilW::Assign(this, m_studioState, "studiostate");
if (err)