collectionDB.h 4.8 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#ifndef COLLECTIONDB_H
#define COLLECTIONDB_H
#include <QString>
#include <QStringList>
#include <QList>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
#include <QSqlDriver>
#include <QFileInfo>
#include <QDir>
#include <QVariantMap>

#include "../utils/bae.h"

enum sourceTypes
{
    LOCAL, ONLINE, DEVICE
};

class CollectionDB : public QObject
{
    Q_OBJECT

public:
28
    explicit CollectionDB( QObject *parent = nullptr);
Camilo Higuita's avatar
Camilo Higuita committed
29 30
    ~CollectionDB() override;

31 32 33 34
    bool insert(const QString &tableName, const QVariantMap &insertData);
    bool update(const QString &tableName, const BAE::DB &updateData, const QVariantMap &where);
    bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
    bool remove();
Camilo Higuita's avatar
Camilo Higuita committed
35

Camilo Higuita's avatar
Camilo Higuita committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    bool execQuery(QSqlQuery &query) const;
    bool execQuery(const QString &queryTxt);

    /*basic public actions*/
    void prepareCollectionDB() const;
    bool check_existance(const QString &tableName, const QString &searchId, const QString &search);

    /* usefull actions */

    void insertArtwork(const BAE::DB &track);

    void addTrack(const BAE::DB &track);
    bool updateTrack(const BAE::DB &track);
    bool rateTrack(const QString &path, const int &value);
    bool moodTrack(const QString &path, const QString &value);
    bool artTrack(const QString &path, const QString &value);
    bool lyricsTrack(const BAE::DB &track, const QString &value);
    bool playedTrack(const QString &url, const int &increment = 1);

    bool wikiTrack(const BAE::DB &track, const QString &value);
    bool tagsTrack(const BAE::DB &track, const QString &value, const QString &context);
    bool albumTrack(const BAE::DB &track, const QString &value);
    bool trackTrack(const BAE::DB &track, const QString &value);

    bool wikiArtist(const BAE::DB &track, const QString &value);
    bool tagsArtist(const BAE::DB &track, const QString &value, const QString &context = "");

    bool wikiAlbum(const BAE::DB &track, QString value);
    bool tagsAlbum(const BAE::DB &track, const QString &value, const QString &context = "");

    bool addPlaylist(const QString &title);
    bool trackPlaylist(const QString &url, const QString &playlist);

    BAE::DB_LIST getDBData(const QStringList &urls);
70
    BAE::DB_LIST getDBData(const QString &queryTxt);
71
    QVariantList getDBDataQML(const QString &queryTxt);
Camilo Higuita's avatar
Camilo Higuita committed
72 73 74 75

    BAE::DB_LIST getAlbumTracks(const QString &album, const QString &artist, const BAE::KEY &orderBy = BAE::KEY::TRACK, const BAE::W &order = BAE::W::ASC);
    BAE::DB_LIST getArtistTracks(const QString &artist, const BAE::KEY &orderBy = BAE::KEY::ALBUM, const BAE::W &order = BAE::W::ASC);
    BAE::DB_LIST getBabedTracks(const BAE::KEY &orderBy = BAE::KEY::PLAYED, const BAE::W &order = BAE::W::DESC);
76
    QVariantList getSearchedTracks(const BAE::KEY &where, const QString &search);
Camilo Higuita's avatar
Camilo Higuita committed
77 78 79 80 81 82 83 84 85 86
    BAE::DB_LIST getPlaylistTracks(const QString &playlist, const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
    BAE::DB_LIST getMostPlayedTracks(const int &greaterThan = 1,const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::PLAYED, const BAE::W &order = BAE::W::DESC);
    BAE::DB_LIST getFavTracks(const int &stars = 1,const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::STARS, const BAE::W &order = BAE::W::DESC);
    BAE::DB_LIST getRecentTracks(const int &limit = 50, const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);
    BAE::DB_LIST getOnlineTracks(const BAE::KEY &orderBy = BAE::KEY::ADD_DATE, const BAE::W &order = BAE::W::DESC);


    QString getTrackArt(const QString &path);
    QStringList getTrackTags(const QString &path);
    int getTrackStars(const QString &path);
87 88
   //    QStringList getArtistTags(const QString &artist);
  //    QStringList getAlbumTags(const QString &album, const QString &artist);
Camilo Higuita's avatar
Camilo Higuita committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
    QStringList getArtistAlbums(const QString &artist);

    QStringList getPlaylists();

    bool removePlaylistTrack(const QString &url, const QString &playlist);
    bool removePlaylist(const QString &playlist);
    bool removeArtist(const QString &artist);
    bool cleanArtists();
    bool removeAlbum(const QString &album, const QString &artist);
    bool cleanAlbums();
    bool removeSource(const QString &path);
    bool removeTrack(const QString &path);
    QSqlQuery getQuery(const QString &queryTxt);
    /*useful tools*/
    sourceTypes sourceType(const QString &url);
    void openDB(const QString &name);

private:
    QString name;
    QSqlDatabase m_db;
    /*basic actions*/
110

Camilo Higuita's avatar
Camilo Higuita committed
111 112 113

public slots:
    void closeConnection();
Camilo Higuita's avatar
Camilo Higuita committed
114
    void test();
Camilo Higuita's avatar
Camilo Higuita committed
115 116 117 118 119 120 121

signals:
    void trackInserted();
    void artworkInserted(const BAE::DB &albumMap);
    void DBactionFinished();
    void albumsCleaned(const int &amount);
    void artistsCleaned(const int &amount);
Camilo Higuita's avatar
Camilo Higuita committed
122

Camilo Higuita's avatar
Camilo Higuita committed
123 124 125
};

#endif // COLLECTION_H