MythTV  master
lyricsdata.h
Go to the documentation of this file.
1 #ifndef LYRICSDATA_H_
2 #define LYRICSDATA_H_
3 
4 // C/C++
5 #include <cstdint>
6 
7 // qt
8 #include <QObject>
9 
10 // mythtv
11 #include "mythmetaexp.h"
12 #include "mythcorecontext.h"
13 #include "musicmetadata.h"
14 
15 class LyricsData;
16 
18 {
19  public:
20  LyricsLine() = default;
21  LyricsLine(int time, const QString &lyric) :
22  m_time(time), m_lyric(lyric) { }
23 
24  int m_time {0};
25  QString m_lyric;
26 
27  QString toString(bool syncronized)
28  {
29  if (syncronized)
30  return formatTime() + m_lyric;
31 
32  return m_lyric;
33  }
34 
35  private:
36  QString formatTime(void)
37  {
38  QString res;
39  int minutes = m_time / (1000 * 60);
40  int seconds = m_time % (1000 * 60) / 1000;
41  int hundredths = (m_time % 1000) / 10;
42 
43  res.sprintf("[%02d:%02d.%02d]", minutes, seconds, hundredths);
44  return res;
45  }
46 };
47 
48 class META_PUBLIC LyricsData : public QObject
49 {
50  Q_OBJECT
51 
52  public:
53  LyricsData();
54  explicit LyricsData(MusicMetadata *parent)
55  : m_parent(parent) {}
56  LyricsData(MusicMetadata *parent, const QString &grabber, const QString &artist,
57  const QString &album, const QString &title, bool syncronized)
58  : m_parent(parent), m_grabber(grabber), m_artist(artist),
59  m_album(album), m_title(title), m_syncronized(syncronized) {}
60  ~LyricsData();
61 
62  QString grabber(void) { return m_grabber; }
63  void setGrabber(const QString &grabber) { m_grabber = grabber; }
64 
65  QString artist(void) { return m_artist; }
66  void setArtist(const QString &artist) { m_artist = artist; }
67 
68  QString album(void) { return m_album; }
69  void setAlbum(const QString &album) { m_album = album; }
70 
71  QString title(void) { return m_title; }
72  void setTitle(const QString &title) { m_title = title; }
73 
74  QMap<int, LyricsLine*>* lyrics(void) { return &m_lyricsMap; }
75  void setLyrics(const QStringList &lyrics);
76 
77  bool syncronized(void) { return m_syncronized; }
78  void setSyncronized(bool syncronized ) { m_syncronized = syncronized; }
79 
80  bool changed(void) { return m_changed; }
81  void setChanged(bool changed) { m_changed = changed; }
82 
83  enum Status
84  {
85  STATUS_NOTLOADED = 0, // not looked for any lyrics yet
86  STATUS_SEARCHING, // search is taking place
87  STATUS_FOUND, // search completed and some lyrics have been found
88  STATUS_NOTFOUND // search completed but no lyrics have been found
89  };
90 
91  Status getStatus(void) { return m_status; }
92 
93  void clear(void);
94  void clearLyrics(void);
95  void findLyrics(const QString &grabber);
96  void save(void);
97 
98  void customEvent(QEvent *event) override; // QObject
99 
100  signals:
101  void statusChanged(LyricsData::Status status, const QString &message);
102 
103  private:
104  void loadLyrics(const QString &xmlData);
105  QString createLyricsXML(void);
106 
107  QMap<int, LyricsLine*> m_lyricsMap;
108 
109  MusicMetadata *m_parent {nullptr};
110 
111  Status m_status {STATUS_NOTLOADED};
112 
113  QString m_grabber;
114  QString m_artist;
115  QString m_album;
116  QString m_title;
117  bool m_syncronized {false};
118  bool m_changed {false};
119 };
120 
122 
123 #endif
void setGrabber(const QString &grabber)
Definition: lyricsdata.h:63
QString m_album
Definition: lyricsdata.h:115
QString title(void)
Definition: lyricsdata.h:71
QMap< int, LyricsLine * > m_lyricsMap
Definition: lyricsdata.h:107
void setChanged(bool changed)
Definition: lyricsdata.h:81
QString artist(void)
Definition: lyricsdata.h:65
void setTitle(const QString &title)
Definition: lyricsdata.h:72
LyricsData(MusicMetadata *parent)
Definition: lyricsdata.h:54
QString grabber(void)
Definition: lyricsdata.h:62
Q_DECLARE_METATYPE(GrabberScript *)
QString toString(bool syncronized)
Definition: lyricsdata.h:27
QString m_title
Definition: lyricsdata.h:116
QString album(void)
Definition: lyricsdata.h:68
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:830
#define META_PUBLIC
Definition: mythmetaexp.h:9
Status getStatus(void)
Definition: lyricsdata.h:91
LyricsData(MusicMetadata *parent, const QString &grabber, const QString &artist, const QString &album, const QString &title, bool syncronized)
Definition: lyricsdata.h:56
bool syncronized(void)
Definition: lyricsdata.h:77
QString m_grabber
Definition: lyricsdata.h:113
void setArtist(const QString &artist)
Definition: lyricsdata.h:66
LyricsLine(int time, const QString &lyric)
Definition: lyricsdata.h:21
void setAlbum(const QString &album)
Definition: lyricsdata.h:69
QMap< int, LyricsLine * > * lyrics(void)
Definition: lyricsdata.h:74
bool changed(void)
Definition: lyricsdata.h:80
QString formatTime(void)
Definition: lyricsdata.h:36
QString m_artist
Definition: lyricsdata.h:114
void setSyncronized(bool syncronized)
Definition: lyricsdata.h:78
QString m_lyric
Definition: lyricsdata.h:25