vvave.cpp 4.33 KB
Newer Older
Camilo higuita's avatar
fixes  
Camilo higuita committed
1 2 3
#include "vvave.h"

#include "db/collectionDB.h"
camilo higuita's avatar
camilo higuita committed
4
#include "services/local/fileloader.h"
5 6 7 8 9 10 11 12 13
#include "utils/brain.h"

#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif

#include <QtConcurrent>
#include <QFuture>

Camilo higuita's avatar
Camilo higuita committed
14 15 16 17 18 19
#ifdef STATIC_MAUIKIT
#include "fm.h"
#else
#include <MauiKit/fm.h>
#endif

20 21 22 23 24 25
/*
 * Sets upthe app default config paths
 * BrainDeamon to get collection information
 * YoutubeFetcher ?
 *
 * */
Camilo higuita's avatar
fixes  
Camilo higuita committed
26 27


camilo higuita's avatar
camilo higuita committed
28 29
vvave::vvave(QObject *parent) : QObject(parent),
    db(CollectionDB::getInstance())
Camilo higuita's avatar
fixes  
Camilo higuita committed
30
{
31 32 33 34 35 36 37
    for(const auto &path : {BAE::CachePath, BAE::YoutubeCachePath})
    {
        QDir dirPath(path);
        if (!dirPath.exists())
            dirPath.mkpath(".");
    }

38 39 40
//#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
//    if(!FMH::fileExists(BAE::NotifyDir+"/vvave.notifyrc"))
//        QFile::copy(":/assets/vvave.notifyrc", BAE::NotifyDir+"/vvave.notifyrc");
41

42
//#endif
43 44 45 46 47
}

vvave::~vvave() {}


48 49 50 51 52
void vvave::emitSignal()
{
    emit this->refreshTables(10);
}

53
//// PUBLIC SLOTS
Camilo higuita's avatar
fixes  
Camilo higuita committed
54
QVariantList vvave::sourceFolders()
55 56 57 58 59
{
    const auto sources = this->db->getDBData("select * from sources");

    QVariantList res;
    for(const auto &item : sources)
60
        res << FMH::getDirInfo(item[FMH::MODEL_KEY::URL]);
61 62
    return res;
}
Camilo higuita's avatar
fixes  
Camilo higuita committed
63

64 65 66 67 68 69 70 71
bool vvave::removeSource(const QString &source)
{
    if(!this->getSourceFolders().contains(source))
        return false;

    return this->db->removeSource(source);
}

72 73 74 75 76
QString vvave::moodColor(const int &index)
{
    if(index < BAE::MoodColors.size() && index > -1)
        return BAE::MoodColors.at(index);
    else return "";
Camilo higuita's avatar
fixes  
Camilo higuita committed
77
}
78

camilo higuita's avatar
camilo higuita committed
79 80 81 82 83
QStringList vvave::moodColors()
{
    return BAE::MoodColors;
}

Camilo higuita's avatar
fixes  
Camilo higuita committed
84
void vvave::scanDir(const QStringList &paths)
85
{
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    QFutureWatcher<uint> *watcher = new QFutureWatcher<uint>;
    connect(watcher, &QFutureWatcher<uint>::finished, [&, watcher]()
    {
        qDebug()<< "FINISHED SCANING CXOLLECTION";
        emit this->refreshTables( watcher->future().result());
        watcher->deleteLater();
    });

    const auto func = [=]() -> uint
    {
        return FLoader::getTracks(QUrl::fromStringList(paths));
    };

    QFuture<uint> t1 = QtConcurrent::run(func);
    watcher->setFuture(t1);}
101 102 103

QStringList vvave::getSourceFolders()
{
Camilo higuita's avatar
Camilo higuita committed
104 105 106 107 108 109 110 111 112
    return this->db->getSourcesFolders();
}

void vvave::openUrls(const QStringList &urls)
{
    if(urls.isEmpty()) return;

    QVariantList data;

camilo higuita's avatar
camilo higuita committed
113
    for(const auto &url : urls)
camilo higuita's avatar
camilo higuita committed
114 115 116
      {
        auto _url = QUrl::fromUserInput(url);
        if(db->check_existance(BAE::TABLEMAP[BAE::TABLE::TRACKS], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], _url.toString()))
Camilo higuita's avatar
Camilo higuita committed
117
        {
camilo higuita's avatar
camilo higuita committed
118
            data << FMH::toMap(this->db->getDBData(QStringList() << _url.toString()).first());
camilo higuita's avatar
camilo higuita committed
119
        }else
Camilo higuita's avatar
Camilo higuita committed
120
        {
121 122
            TagInfo info(_url.toLocalFile());
            if(!info.isNull())
Camilo higuita's avatar
Camilo higuita committed
123
            {
camilo higuita's avatar
camilo higuita committed
124 125 126 127 128
                const auto album = BAE::fixString(info.getAlbum());
                const auto track= info.getTrack();
                const auto title = BAE::fixString(info.getTitle()); /* to fix*/
                const auto artist = BAE::fixString(info.getArtist());
                const auto genre = info.getGenre();
camilo higuita's avatar
camilo higuita committed
129
                const auto sourceUrl = QFileInfo(_url.toLocalFile()).dir().path();
camilo higuita's avatar
camilo higuita committed
130 131
                const auto duration = info.getDuration();
                const auto year = info.getYear();
Camilo higuita's avatar
Camilo higuita committed
132 133

                data << QVariantMap({
camilo higuita's avatar
camilo higuita committed
134
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::URL], _url.toString()},
Camilo higuita's avatar
Camilo higuita committed
135 136 137 138 139 140 141 142 143 144 145 146
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::TRACK], QString::number(track)},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::TITLE], title},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::ARTIST], artist},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::DURATION],QString::number(duration)},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::GENRE], genre},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::SOURCE], sourceUrl},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::FAV],"0"},
                                        {FMH::MODEL_NAME[FMH::MODEL_KEY::RELEASEDATE], QString::number(year)}
                                    });
            }
        }
camilo higuita's avatar
camilo higuita committed
147
      }
Camilo higuita's avatar
Camilo higuita committed
148 149

    emit this->openFiles(data);
150 151
}

152 153