TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsong.h
Go to the documentation of this file.
1 #ifndef MUSICSONG_H
2 #define MUSICSONG_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include "ttktime.h"
23 #include "musicstringutils.h"
24 
29 {
31 public:
32  enum class Sort
33  {
34  ByFileName,
35  BySinger,
36  ByFileSize,
37  ByAddTime,
38  ByDuration,
39  ByPlayCount
40  };
41 
45  MusicSong() noexcept;
46  explicit MusicSong(const QString &path, bool track = false) noexcept;
47  MusicSong(const QString &path, const QString &duration, const QString &name = {}, bool track = false) noexcept;
48 
52  QString title() const noexcept;
56  QString artist() const noexcept;
57 
61  inline void setAddTimeStr(const QString &t) noexcept { m_addTimeStr = t; }
65  inline QString addTimeStr() const noexcept { return m_addTimeStr; }
69  inline void setSizeStr(const QString &s) noexcept { m_sizeStr = s; }
73  inline QString sizeStr() const noexcept { return m_sizeStr; }
74 
78  inline void setName(const QString &n) noexcept { m_name = n; }
82  inline QString name() const noexcept { return m_name; }
86  inline void setPath(const QString &p) noexcept { m_path = p; }
90  inline QString path() const noexcept { return m_path; }
94  inline void setFormat(const QString &t) noexcept { m_format = t; }
98  inline QString format() const noexcept { return m_format; }
102  inline void setDuration(const QString &t) noexcept { m_duration = t; }
106  inline QString duration() const noexcept { return m_duration; }
110  inline qint64 size() const noexcept { return m_size; }
114  inline void setPlayCount(const int c) noexcept { m_playCount = c; }
118  inline int playCount() const noexcept { return m_playCount; }
122  inline void setSort(const Sort s) noexcept { m_sort = s; }
123 
124  bool operator== (const MusicSong &other) const noexcept;
125  bool operator< (const MusicSong &other) const noexcept;
126  bool operator> (const MusicSong &other) const noexcept;
127 
128 private:
130  qint64 m_size, m_addTime;
131  QString m_sizeStr, m_addTimeStr;
133  QString m_name, m_path, m_format, m_duration;
134 
135 };
137 
138 
143 {
144  int m_type;
145  Qt::SortOrder m_order;
146 
148  : m_type(-1),
149  m_order(Qt::AscendingOrder)
150  {
151 
152  }
153 };
154 
155 
157 
162 {
164  QString m_itemName;
166  MusicSongList m_songs;
168 
170  : m_itemIndex(-1),
171  m_itemWidget(nullptr)
172  {
173 
174  }
175 
176  inline bool operator<(const MusicSongItem &other) const noexcept
177  {
178  return m_itemIndex < other.m_itemIndex;
179  }
180 };
182 
183 
187 namespace TTK
188 {
192  TTK_MODULE_EXPORT bool playlistRowValid(int index);
196  TTK_MODULE_EXPORT QString trackRelatedPath(const QString &path);
197 
201  TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist);
205  TTK_MODULE_EXPORT QString generateSongTitle(const QString &name, const QString &key = TTK_DEFAULT_STR);
209  TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key = TTK_DEFAULT_STR);
213  TTK_MODULE_EXPORT MusicSongList generateSongList(const QString &path);
214 
218  TTK_MODULE_EXPORT QString generateNetworkSongTime(const QString &path);
222  TTK_MODULE_EXPORT QString generateNetworkSongPath(const QString &path);
223 
224 }
225 
226 #endif // MUSICSONG_H
bool operator==(const VolumeSettings &v1, const VolumeSettings &v2)
Definition: volume.h:38
#define TTK_MODULE_EXPORT
TTK_MODULE_EXPORT QString generateSongName(const QString &title, const QString &artist)
Definition: musicsong.cpp:112
bool operator<(const MusicSongItem &other) const noexcept
Definition: musicsong.h:176
TTK_MODULE_EXPORT QString generateSongArtist(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:128
QString sizeStr() const noexcept
Definition: musicsong.h:73
TTK_DECLARE_LIST(MusicSong)
TTK_MODULE_EXPORT bool playlistRowValid(int index)
Definition: musicsong.cpp:95
#define TTK_DEFAULT_STR
Definition: ttkglobal.h:200
void setSort(const Sort s) noexcept
Definition: musicsong.h:122
TTK_MODULE_EXPORT QString trackRelatedPath(const QString &path)
Definition: musicsong.cpp:100
QString path() const noexcept
Definition: musicsong.h:90
QString m_sizeStr
Definition: musicsong.h:131
static constexpr wchar_t key[]
TTK_MODULE_EXPORT QString generateSongTitle(const QString &name, const QString &key=TTK_DEFAULT_STR)
Definition: musicsong.cpp:117
void setName(const QString &n) noexcept
Definition: musicsong.h:78
Sort m_sort
Definition: musicsong.h:129
qint64 size() const noexcept
Definition: musicsong.h:110
TTK_MODULE_EXPORT QString generateNetworkSongPath(const QString &path)
Definition: musicsong.cpp:182
const char * name
Definition: http_parser.c:458
The namespace of the process utils.
Definition: ttkcompat.h:24
QString m_path
Definition: musicsong.h:133
MusicAbstractSongsListTableWidget * m_itemWidget
Definition: musicsong.h:167
int m_playCount
Definition: musicsong.h:132
void setFormat(const QString &t) noexcept
Definition: musicsong.h:94
void setSizeStr(const QString &s) noexcept
Definition: musicsong.h:69
TTK_MODULE_EXPORT QString generateNetworkSongTime(const QString &path)
Definition: musicsong.cpp:176
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152
The class of the music song sort tag.
Definition: musicsong.h:142
QString format() const noexcept
Definition: musicsong.h:98
QString duration() const noexcept
Definition: musicsong.h:106
QString name() const noexcept
Definition: musicsong.h:82
void setDuration(const QString &t) noexcept
Definition: musicsong.h:102
QString addTimeStr() const noexcept
Definition: musicsong.h:65
The class of the music song item.
Definition: musicsong.h:161
MusicSongList m_songs
Definition: musicsong.h:166
void setPlayCount(const int c) noexcept
Definition: musicsong.h:114
QString m_itemName
Definition: musicsong.h:164
The class of the music song info.
Definition: musicsong.h:28
void setPath(const QString &p) noexcept
Definition: musicsong.h:86
Qt::SortOrder m_order
Definition: musicsong.h:145
#define const
Definition: zconf.h:233
MusicSongSort m_sort
Definition: musicsong.h:165
constexpr bool operator<(int128_t, int128_t)
Definition: int128.h:634
int playCount() const noexcept
Definition: musicsong.h:118
qint64 m_size
Definition: musicsong.h:130
The class of the songs list abstract table widget.
TTK_MODULE_EXPORT MusicSongList generateSongList(const QString &path)
Definition: musicsong.cpp:139