MythTV  master
importmusic.h
Go to the documentation of this file.
1 #ifndef IMPORTMUSIC_H_
2 #define IMPORTMUSIC_H_
3 
4 #include <iostream>
5 #include <utility>
6 #include <vector>
7 using namespace std;
8 
9 #include <QStringList>
10 
11 #include <mythscreentype.h>
12 #include <mthread.h>
13 
14 class MusicMetadata;
15 class ImportMusicDialog;
16 
17 class MythUIText;
18 class MythUITextEdit;
19 class MythUIImage;
20 class MythUIButton;
21 class MythUIButtonList;
22 class MythUICheckBox;
23 class MythDialogBox;
24 
25 struct TrackInfo
26 {
28  bool isNewTune;
30 };
31 
33 {
34  public:
35  explicit FileScannerThread(ImportMusicDialog *parent);
36  void run() override; // MThread
37 
38  private:
39  ImportMusicDialog *m_parent {nullptr};
40 };
41 
42 class FileCopyThread: public MThread
43 {
44  public:
45  FileCopyThread(QString src, QString dst)
46  : MThread("FileCopy"), m_srcFile(std::move(src)),
47  m_dstFile(std::move(dst)) {}
48  void run() override; // MThread
49 
50  bool GetResult(void) { return m_result; }
51 
52  private:
53  QString m_srcFile;
54  QString m_dstFile;
55  bool m_result {false};
56 };
57 
59 {
60 
61  Q_OBJECT
62 
63  public:
64  explicit ImportMusicDialog(MythScreenStack *parent);
65  ~ImportMusicDialog() override;
66 
67  bool Create(void) override; // MythScreenType
68  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
69  void customEvent(QEvent *event) override; // MythUIType
70 
71  bool somethingWasImported() { return m_somethingWasImported; }
72  void doScan(void);
73  void doFileCopy(const QString &src, const QString &dst);
74 
75  public slots:
76  void addAllNewPressed(void);
77  void playPressed(void);
78  void addPressed(void);
79  void nextNewPressed(void);
80  void locationPressed(void);
81  void coverArtPressed(void);
82 
83  void nextPressed(void);
84  void prevPressed(void);
85  void showEditMetadataDialog(void);
86  void startScan(void);
87  void doExit(bool ok);
88 
89  // popup menu
90  void ShowMenu(void) override; // MythScreenType
91  void saveDefaults(void);
92  void setCompilation(void);
93  void setCompilationArtist(void);
94  void setArtist(void);
95  void setAlbum(void);
96  void setYear(void);
97  void setTrack(void);
98  void setGenre(void);
99  void setRating(void);
100  void setTitleWordCaps(void);
101  void setTitleInitialCap(void);
102  void metadataChanged(void);
103  void chooseBackend(void);
104  void setSaveHost(const QString& host);
105 
106  signals:
107  void importFinished(void);
108 
109  private:
110  void fillWidgets();
111  void scanDirectory(QString &directory, vector<TrackInfo*> *tracks);
112  void showImportCoverArtDialog();
113  static bool copyFile(const QString &src, const QString &dst);
114 
116  bool m_somethingWasImported {false};
117  vector<TrackInfo*> *m_tracks {nullptr};
118  QStringList m_sourceFiles;
119  int m_currentTrack {0};
120  MusicMetadata *m_playingMetaData {nullptr};
121 
122  // GUI stuff
123  MythUITextEdit *m_locationEdit {nullptr};
124  MythUIButton *m_locationButton {nullptr};
125  MythUIButton *m_scanButton {nullptr};
126  MythUIButton *m_coverartButton {nullptr};
127 
128  MythUIText *m_filenameText {nullptr};
129  MythUIText *m_compartistText {nullptr};
130  MythUIText *m_artistText {nullptr};
131  MythUIText *m_albumText {nullptr};
132  MythUIText *m_titleText {nullptr};
133  MythUIText *m_genreText {nullptr};
134  MythUIText *m_yearText {nullptr};
135  MythUIText *m_trackText {nullptr};
136 
137  MythUIButton *m_nextButton {nullptr};
138  MythUIButton *m_prevButton {nullptr};
139 
140  MythUIText *m_currentText {nullptr};
141  MythUIText *m_statusText {nullptr};
142 
143  MythUIButton *m_playButton {nullptr};
144  MythUIButton *m_addButton {nullptr};
145  MythUIButton *m_addallnewButton {nullptr};
146  MythUIButton *m_nextnewButton {nullptr};
147 
148  MythUICheckBox *m_compilationCheck {nullptr};
149 
150  // default metadata values
151  bool m_defaultCompilation {false};
154  QString m_defaultAlbum;
155  QString m_defaultGenre;
156  int m_defaultYear {0};
157  int m_defaultRating {0};
158  bool m_haveDefaults {false};
159 };
160 
162 
164 {
165 
166  Q_OBJECT
167 
168  public:
169 
170  ImportCoverArtDialog(MythScreenStack *parent, QString sourceDir,
171  MusicMetadata *metadata, QString storageDir)
172  : MythScreenType(parent, "import_coverart"),
173  m_sourceDir(std::move(sourceDir)),
174  m_musicStorageDir(std::move(storageDir)),
175  m_metadata(metadata) {}
176  ~ImportCoverArtDialog() override = default;
177 
178  bool Create(void) override; // MythScreenType
179  bool keyPressEvent(QKeyEvent *event) override; // MythScreenType
180 
181  public slots:
182  void copyPressed(void);
183  void prevPressed(void);
184  void nextPressed(void);
185  void selectorChanged(void);
186 
187  private:
188  void scanDirectory(void);
189  void updateStatus(void);
190  void updateTypeSelector(void);
191 
192  QStringList m_filelist;
193  QString m_sourceDir;
195  MusicMetadata *m_metadata {nullptr};
196  int m_currentFile {0};
197  QString m_saveFilename;
198 
199  //
200  // GUI stuff
201  //
202  MythUIText *m_filenameText {nullptr};
203  MythUIText *m_currentText {nullptr};
204  MythUIText *m_statusText {nullptr};
205  MythUIText *m_destinationText {nullptr};
206 
207  MythUIImage *m_coverartImage {nullptr};
208  MythUIButtonList *m_typeList {nullptr};
209 
210  MythUIButton *m_nextButton {nullptr};
211  MythUIButton *m_prevButton {nullptr};
212  MythUIButton *m_copyButton {nullptr};
213  MythUIButton *m_exitButton {nullptr};
214 };
215 
216 #endif
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
ImportCoverArtDialog(MythScreenStack *parent, QString sourceDir, MusicMetadata *metadata, QString storageDir)
Definition: importmusic.h:170
unsigned int slots[4]
Definition: element.c:38
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
A checkbox widget supporting three check states - on,off,half and two conditions - selected and unsel...
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
Basic menu dialog, message and a list of options.
QString m_defaultAlbum
Definition: importmusic.h:154
FileCopyThread(QString src, QString dst)
Definition: importmusic.h:45
bool isNewTune
Definition: importmusic.h:28
QString m_dstFile
Definition: importmusic.h:54
QStringList m_sourceFiles
Definition: importmusic.h:118
A text entry and edit widget.
QString m_defaultGenre
Definition: importmusic.h:155
bool GetResult(void)
Definition: importmusic.h:50
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
QString m_musicStorageDir
Definition: importmusic.h:115
A single button widget.
Definition: mythuibutton.h:21
bool metadataHasChanged
Definition: importmusic.h:29
QString m_defaultArtist
Definition: importmusic.h:153
bool somethingWasImported()
Definition: importmusic.h:71
QStringList m_filelist
Definition: importmusic.h:192
QString m_srcFile
Definition: importmusic.h:53
QString m_defaultCompArtist
Definition: importmusic.h:152
MusicMetadata * metadata
Definition: importmusic.h:27
Screen in which all other widgets are contained and rendered.