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