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