4
0
mirror of https://github.com/QuasarApp/SoundBand.git synced 2025-04-29 08:44:31 +00:00

199 lines
5.6 KiB
C
Raw Normal View History

2017-12-24 00:20:53 +03:00
#ifndef MYSQL_H
#define MYSQL_H
#include <QString>
2018-03-29 22:02:03 +03:00
#include "playlist.h"
2017-12-24 00:20:53 +03:00
class QSqlDatabase;
class QSqlQuery;
namespace syncLib {
class MySql
{
2017-12-24 22:04:40 +03:00
private:
QSqlDatabase *db;
QSqlQuery *qyery;
QString dataBaseName;
2018-03-25 23:01:44 +03:00
QString songDir;
2017-12-24 22:04:40 +03:00
/**
* @brief sqlErrorLog show sql error
* @param qyery
*/
2018-03-05 01:47:07 +03:00
void sqlErrorLog(const QString& qyery) const;
2017-12-24 22:04:40 +03:00
2018-03-25 23:01:44 +03:00
/**
* @brief saveToStorage save song as file into hdd
* @param url - url of song after save
* @param song - saved song
* @return true if all done
*/
bool saveToStorage(QUrl& url, const Song& song)const;
2017-12-24 00:20:53 +03:00
public:
2017-12-24 22:04:40 +03:00
MySql(const QString& databasename);
/**
* @brief initDB initialize local database of song
*/
void initDB(const QString& database = DATABASE_NAME );
2018-03-29 00:23:53 +03:00
/**
* @brief find - find song
* @param song - song header
* @param response Media Content of finded song
* @return true if song finded
*/
bool find(const SongHeader& song, QMediaContent& response);
/**
* @brief find - find song
* @param song - song header
* @param response Media Content of finded song
* @return true if song finded
*/
bool find(const QMediaContent& song, SongHeader& response);
/**
* @brief find - find song
* @param song - media Content
* @param response header of finded song
* @return true if song finded
*/
bool find(const QMediaContent& song, SongStorage &response);
2018-03-25 23:01:44 +03:00
/**
* @brief setSoundDir
* @param str
*/
void setSoundDir(const QString& str);
2018-03-29 00:23:53 +03:00
/**
* @brief findSong
* @param song
*/
bool findSong(const SongHeader &song);
2017-12-24 22:04:40 +03:00
/**
* @brief load song of database;
* @brief song -
* @brief result - the resulting value;
* @return true if everything's done
*/
2018-03-29 00:23:53 +03:00
bool load(const SongHeader &song, SongStorage &result);
2017-12-24 22:04:40 +03:00
/**
* @brief save media data into local database.
* @param song savining media data.
* @return id of song saved on local database.
*/
2018-04-02 01:03:27 +03:00
int save(const SongStorage &song);
/**
* @brief save media data into local database.
* @param song savining media data.
* @return id of song saved on local database.
*/
int save(const Song &song);
2017-12-24 22:04:40 +03:00
/**
* @brief save media file, bud from url.
*/
2017-12-24 22:04:40 +03:00
int save(const QString &url);
/**
* @brief fromDataBase return a song from local database by id.
* @param id of song saved in local database.
* @return song drom local database.
*/
Song fromDataBase(const int id);
/**
* @brief updateAvelableSongs will update the list of participants of songs.
* @param list - [out value] list of avelable song.
* @param playList - play list of songs.
2018-03-10 16:38:56 +03:00
* @param forEdit - flag for editing play list. If this flag = true then return all available songs with corect flag 'isSelect'
2017-12-24 22:04:40 +03:00
* @return true if all done
*/
2018-03-29 00:23:53 +03:00
bool updateAvailableSongs(QList<SongStorage>& list, const QString &playList = "", bool forEditing = false);
2018-01-19 15:03:07 +03:00
/**
* @brief updateAvelableSongs will update the list of participants of songs.
* @param list - [out value] list of avelable song.
* @param playList - play list of songs (string).
* @return true if all done
*/
2018-03-29 22:02:03 +03:00
bool updateAvailableSongs(PlayList& list, const QString &playList = "", bool forEditing = false);
/**
* @brief removeSong - remove song from local database.
* @param header - heder removing song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @return trye if all done.
*/
bool removeSong(const SongHeader& header);
/**
* @brief addPlayList add a new play list into database.
* @param newPlayList - a new paly list.
* @return trye if all done.
*/
2017-12-25 16:57:29 +03:00
bool addPlayList(const QString& newPlayList, const QString& desc = "");
2017-12-24 22:04:40 +03:00
/**
2017-12-25 16:57:29 +03:00
* @brief addToPlayList - add song to play list.
* @param header - header of song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @param newPlaylist
* @return true if all done.
*/
2017-12-25 16:57:29 +03:00
bool addToPlayList(const SongHeader& header, const QString& playList);
/**
* @brief addToPlayList - add song to play list.
* @param header - header of song. first : song removed by id,
* if id of head = -1 then song removed by name and size, and if song no finded this finction return false.
* @param newPlaylist
* @return true if all done.
*/
bool removeFromPlayList(const SongHeader& header, const QString& playList);
/**
* @brief removePlayList - remove play list from local database.
* @param playList - removed play list.
* @return true if all done.
*/
bool removePlayList(const QString& playList);
/**
* @brief exec - execute сustom sql file.
* @param q - sql query
* @param sqlFile - sql - file with sql code.
* @return trye if all done.
*/
2017-12-24 00:20:53 +03:00
static bool exec(QSqlQuery *q, const QString& sqlFile);
2017-12-24 22:04:40 +03:00
2017-12-25 18:40:36 +03:00
/**
* @brief getPlayLists show all created playlists.
* @param list - list of play lists.
* @return trye if all done
*/
2018-03-05 01:47:07 +03:00
bool getPlayLists(QStringList &list) const;
2017-12-25 18:40:36 +03:00
2018-01-19 16:48:22 +03:00
/**
* @brief getSongId get song id by name
* @param name - name of song
* @return true if finded song,
* bud if count of finded songs is greater than 1 return false
*/
int getSongId(const QString& name);
/**
* @brief clear - clear free space in local database
*/
2017-12-25 18:40:36 +03:00
void clear();
2017-12-24 00:20:53 +03:00
~MySql();
};
}
#endif // MYSQL_H