MythTV  master
videoscan.h
Go to the documentation of this file.
1 #ifndef VIDEO_SCANNER_H
2 #define VIDEO_SCANNER_H
3 
4 #include <map>
5 #include <set>
6 #include <utility>
7 #include <vector>
8 
9 // Qt headers
10 #include <QObject> // for moc
11 #include <QStringList>
12 #include <QEvent>
13 #include <QCoreApplication>
14 
15 // MythTV headers
16 #include "libmythbase/mthread.h"
19 
21 
22 class META_PUBLIC VideoScanner : public QObject
23 {
24  Q_OBJECT
25 
26  public:
27  VideoScanner();
28  ~VideoScanner() override;
29 
30  void doScan(const QStringList &dirs);
31  void doScanAll(void);
32 
33  signals:
34  void finished(bool);
35 
36  public slots:
37  void finishedScan();
38 
39  private:
40  class VideoScannerThread *m_scanThread {nullptr};
41  bool m_cancel {false};
42 };
43 
44 class META_PUBLIC VideoScanChanges : public QEvent
45 {
46  public:
47  VideoScanChanges(QList<int> adds, QList<int> movs,
48  QList<int>dels) : QEvent(kEventType),
49  m_additions(std::move(adds)), m_moved(std::move(movs)),
50  m_deleted(std::move(dels)) {}
51  ~VideoScanChanges() override = default;
52 
53  QList<int> m_additions; // newly added intids
54  QList<int> m_moved; // intids moved to new filename
55  QList<int> m_deleted; // orphaned/deleted intids
56 
57  static const Type kEventType;
58 };
59 
61 {
62  Q_DECLARE_TR_FUNCTIONS(VideoScannerThread);
63 
64  public:
65  explicit VideoScannerThread(QObject *parent);
66  ~VideoScannerThread() override;
67 
68  void run() override; // MThread
69  void SetDirs(QStringList dirs);
70  void SetHosts(const QStringList &hosts);
71  void SetProgressDialog(MythUIProgressDialog *dialog) { m_dialog = dialog; };
72  QStringList GetOfflineSGHosts(void) { return m_offlineSGHosts; };
73  bool getDataChanged() const { return m_dbDataChanged; };
74 
75  void ResetCounts() { m_addList.clear(); m_movList.clear(); m_delList.clear(); };
76 
77  private:
78 
79  struct CheckStruct
80  {
81  bool check {false};
82  QString host;
83  };
84 
85  using PurgeList = std::vector<std::pair<int, QString> >;
86  using FileCheckList = std::map<QString, CheckStruct>;
87 
88  void removeOrphans(unsigned int id, const QString &filename);
89 
90  void verifyFiles(FileCheckList &files, PurgeList &remove);
91  bool updateDB(const FileCheckList &add, const PurgeList &remove);
92  bool buildFileList(const QString &directory,
93  const QStringList &imageExtensions,
94  FileCheckList &filelist) const;
95 
96  void SendProgressEvent(uint progress, uint total = 0,
97  QString messsage = QString());
98 
99  QObject *m_parent {nullptr};
100 
101  bool m_listUnknown {false};
102  bool m_removeAll {false};
103  bool m_keepAll {false};
104  bool m_hasGUI {false};
105  QStringList m_directories;
106  QStringList m_liveSGHosts;
107  QStringList m_offlineSGHosts;
108 
109  VideoMetadataListManager *m_dbMetadata {nullptr};
110  MythUIProgressDialog *m_dialog {nullptr};
111 
112  QList<int> m_addList; // newly added intids
113  QList<int> m_movList; // intids moved to new filename
114  QList<int> m_delList; // orphaned/deleted intids
115  bool m_dbDataChanged {false};
116 };
117 
118 #endif
VideoScanChanges::m_deleted
QList< int > m_deleted
Definition: videoscan.h:55
VideoMetadataListManager
Definition: videometadatalistmanager.h:10
progress
bool progress
Definition: mythcommflag.cpp:69
VideoScannerThread::GetOfflineSGHosts
QStringList GetOfflineSGHosts(void)
Definition: videoscan.h:72
mythmetaexp.h
VideoScannerThread::m_movList
QList< int > m_movList
Definition: videoscan.h:113
mythprogressdialog.h
VideoScannerThread::ResetCounts
void ResetCounts()
Definition: videoscan.h:75
VideoScannerThread
Definition: videoscan.h:60
MythUIProgressDialog
Definition: mythprogressdialog.h:59
VideoScannerThread::m_addList
QList< int > m_addList
Definition: videoscan.h:112
VideoScannerThread::m_liveSGHosts
QStringList m_liveSGHosts
Definition: videoscan.h:106
VideoScanChanges::kEventType
static const Type kEventType
Definition: videoscan.h:57
uint
unsigned int uint
Definition: compat.h:81
MThread::run
virtual void run(void)
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mthread.cpp:315
VideoScannerThread::CheckStruct::host
QString host
Definition: videoscan.h:82
VideoScannerThread::m_delList
QList< int > m_delList
Definition: videoscan.h:114
VideoScannerThread::SetProgressDialog
void SetProgressDialog(MythUIProgressDialog *dialog)
Definition: videoscan.h:71
VideoScannerThread::CheckStruct
Definition: videoscan.h:79
VideoScanChanges::m_moved
QList< int > m_moved
Definition: videoscan.h:54
std
Definition: mythchrono.h:23
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
VideoScanChanges::VideoScanChanges
VideoScanChanges(QList< int > adds, QList< int > movs, QList< int >dels)
Definition: videoscan.h:47
mthread.h
VideoScanChanges
Definition: videoscan.h:44
VideoScanner
Definition: videoscan.h:22
VideoScannerThread::m_offlineSGHosts
QStringList m_offlineSGHosts
Definition: videoscan.h:107
VideoScannerThread::FileCheckList
std::map< QString, CheckStruct > FileCheckList
Definition: videoscan.h:86
build_compdb.filename
filename
Definition: build_compdb.py:21
VideoScannerThread::m_directories
QStringList m_directories
Definition: videoscan.h:105
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
VideoScannerThread::getDataChanged
bool getDataChanged() const
Definition: videoscan.h:73
VideoScannerThread::PurgeList
std::vector< std::pair< int, QString > > PurgeList
Definition: videoscan.h:85
VideoScanChanges::m_additions
QList< int > m_additions
Definition: videoscan.h:53