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