Commit 9233ef61 authored by Camilo higuita's avatar Camilo higuita

masive clean up

parent d99b7e7a
#include "babe.h"
#include "db/collectionDB.h"
#include "db/conthread.h"
//#include "db/conthread.h"
#include "settings/BabeSettings.h"
#include "pulpo/pulpo.h"
......@@ -34,7 +34,7 @@ Babe::Babe(QObject *parent) : QObject(parent)
this->settings = new BabeSettings(this);
/*use another thread for the db to perfom heavy dutty actions*/
this->thread = new ConThread;
// this->thread = new ConThread;
this->pulpo = new Pulpo(this);
this->db = CollectionDB::getInstance();
......@@ -70,7 +70,7 @@ Babe::Babe(QObject *parent) : QObject(parent)
});
/*The local streaming connection still unfinished*/
connect(&link, &Linking::parseAsk, this, &Babe::linkDecoder);
// connect(&link, &Linking::parseAsk, this, &Babe::linkDecoder);
// connect(&link, &Linking::bytesFrame, [this](QByteArray array)
// {
// this->player.appendBuffe(array);
......@@ -102,7 +102,6 @@ Babe::Babe(QObject *parent) : QObject(parent)
Babe::~Babe()
{
delete this->thread;
}
......@@ -134,25 +133,25 @@ QVariantList Babe::getList(const QStringList &urls)
return Babe::transformData(this->db->getDBData(urls));
}
void Babe::set(const QString &table, const QVariantList &wheres)
{
this->thread->start(table, wheres);
}
//void Babe::set(const QString &table, const QVariantList &wheres)
//{
// this->thread->start(table, wheres);
//}
void Babe::trackPlaylist(const QStringList &urls, const QString &playlist)
{
QVariantList data;
for(auto url : urls)
{
QVariantMap map {{FMH::MODEL_NAME[FMH::MODEL_KEY::PLAYLIST],playlist},
{FMH::MODEL_NAME[FMH::MODEL_KEY::URL],url},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE],QDateTime::currentDateTime()}};
//void Babe::trackPlaylist(const QStringList &urls, const QString &playlist)
//{
// QVariantList data;
// for(auto url : urls)
// {
// QVariantMap map {{FMH::MODEL_NAME[FMH::MODEL_KEY::PLAYLIST],playlist},
// {FMH::MODEL_NAME[FMH::MODEL_KEY::URL],url},
// {FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE],QDateTime::currentDateTime()}};
data << map;
}
// data << map;
// }
this->thread->start(BAE::TABLEMAP[TABLE::TRACKS_PLAYLISTS], data);
}
// this->thread->start(BAE::TABLEMAP[TABLE::TRACKS_PLAYLISTS], data);
//}
void Babe::trackLyrics(const QString &url)
{
......@@ -168,17 +167,6 @@ void Babe::trackLyrics(const QString &url)
this->fetchTrackLyrics(track.first());
}
bool Babe::trackBabe(const QString &path)
{
auto babe = this->db->getDBData(QString("SELECT %1 FROM %2 WHERE %3 = \"%4\"").arg(FMH::MODEL_NAME[FMH::MODEL_KEY::FAV],
TABLEMAP[TABLE::TRACKS],
FMH::MODEL_NAME[FMH::MODEL_KEY::URL],path));
if(!babe.isEmpty())
return babe.first()[FMH::MODEL_KEY::FAV].toInt();
return false;
}
QString Babe::artistArt(const QString &artist)
{
......@@ -233,60 +221,60 @@ void Babe::fetchTrackLyrics(FMH::MODEL &song)
qDebug()<<"DONE FETCHING LYRICS";
}
void Babe::linkDecoder(QString json)
{
//void Babe::linkDecoder(QString json)
//{
qDebug()<<"DECODING LINKER MSG"<<json;
auto ask = link.decode(json);
// qDebug()<<"DECODING LINKER MSG"<<json;
// auto ask = link.decode(json);
auto code = ask[BAE::SLANG[BAE::W::CODE]].toInt();
auto msg = ask[BAE::SLANG[BAE::W::MSG]].toString();
// auto code = ask[BAE::SLANG[BAE::W::CODE]].toInt();
// auto msg = ask[BAE::SLANG[BAE::W::MSG]].toString();
switch(static_cast<LINK::CODE>(code))
{
case LINK::CODE::CONNECTED :
{
this->link.deviceName = msg;
emit this->link.serverConReady(msg);
break;
}
case LINK::CODE::QUERY :
case LINK::CODE::FILTER :
case LINK::CODE::PLAYLISTS :
{
auto res = this->db->getDBDataQML(msg);
link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::SEARCHFOR :
{
// auto res = this->searchFor(msg.split(","));
// switch(static_cast<LINK::CODE>(code))
// {
// case LINK::CODE::CONNECTED :
// {
// this->link.deviceName = msg;
// emit this->link.serverConReady(msg);
// break;
// }
// case LINK::CODE::QUERY :
// case LINK::CODE::FILTER :
// case LINK::CODE::PLAYLISTS :
// {
// auto res = this->db->getDBDataQML(msg);
// link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::PLAY :
{
QFile file(msg); // sound dir
file.open(QIODevice::ReadOnly);
QByteArray arr = file.readAll();
qDebug()<<"Preparing track array"<<msg<<arr.size();
link.sendArrayToClient(arr);
break;
}
case LINK::CODE::COLLECT :
{
// auto devices = getDevices();
// qDebug()<<"DEVICES:"<< devices;
// if(!devices.isEmpty())
// sendToDevice(devices.first().toMap().value("name").toString(),
// devices.first().toMap().value("id").toString(), msg);
break;
// break;
// }
// case LINK::CODE::SEARCHFOR :
// {
//// auto res = this->searchFor(msg.split(","));
//// link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
// break;
// }
// case LINK::CODE::PLAY :
// {
// QFile file(msg); // sound dir
// file.open(QIODevice::ReadOnly);
// QByteArray arr = file.readAll();
// qDebug()<<"Preparing track array"<<msg<<arr.size();
// link.sendArrayToClient(arr);
// break;
// }
// case LINK::CODE::COLLECT :
// {
// // auto devices = getDevices();
// // qDebug()<<"DEVICES:"<< devices;
// // if(!devices.isEmpty())
// // sendToDevice(devices.first().toMap().value("name").toString(),
// // devices.first().toMap().value("id").toString(), msg);
// break;
}
default: break;
// }
// default: break;
}
}
// }
//}
QString Babe::albumWiki(const QString &album, const QString &artist)
{
......@@ -359,7 +347,7 @@ void Babe::brainz(const bool &on)
bool Babe::brainzState()
{
return loadSetting("AUTO", "BRAINZ", false).toBool();
return FM::loadSettings("AUTO", "BRAINZ", false).toBool();
}
void Babe::refreshCollection()
......@@ -372,16 +360,6 @@ void Babe::getYoutubeTrack(const QString &message)
this->settings->fetchYoutubeTrack(message);
}
QVariant Babe::loadSetting(const QString &key, const QString &group, const QVariant &defaultValue)
{
return BAE::loadSettings(key, group, defaultValue);
}
void Babe::saveSetting(const QString &key, const QVariant &value, const QString &group)
{
BAE::saveSettings(key, value, group);
}
void Babe::savePlaylist(const QStringList &list)
{
FM::saveSettings("LASTPLAYLIST", list, "PLAYLIST");
......@@ -402,15 +380,10 @@ int Babe::lastPlaylistPos()
return BAE::loadSettings("PLAYLIST_POS","MAINWINDOW",QVariant(0)).toInt();
}
bool Babe::fileExists(const QString &url)
{
return BAE::fileExists(url);
}
void Babe::showFolder(const QStringList &urls)
{
{
for(auto url : urls)
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(url).dir().absolutePath()));
FM::openUrl(QUrl::fromLocalFile(QFileInfo(url).dir().absolutePath()).toString());
}
QString Babe::babeColor()
......@@ -468,16 +441,6 @@ QString Babe::moodColor(const int &pos)
else return "";
}
QString Babe::homeDir()
{
return BAE::HomePath;
}
QString Babe::musicDir()
{
return BAE::MusicPath;
}
QStringList Babe::defaultSources()
{
return BAE::defaultSources;
......@@ -549,11 +512,11 @@ QVariantList Babe::transformData(const FMH::MODEL_LIST &dbList)
{
QVariantList res;
// for(FMH::MODEL data : dbList)
// {
// FMH::MODEL copy = data;
// res << FM::toMap(copy);
// }
for(FMH::MODEL data : dbList)
{
FMH::MODEL copy = data;
res << FM::toMap(copy);
}
return res;
}
......
......@@ -5,7 +5,7 @@
#include <QVariantList>
#include "utils/bae.h"
#include "db/collectionDB.h"
#include "services/local/linking.h"
//#include "services/local/linking.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
class Notify;
......@@ -29,7 +29,7 @@ public:
~Babe();
BabeSettings *settings;
Linking link;
// Linking link;
// Q_INVOKABLE void runPy();
......@@ -37,16 +37,17 @@ public:
Q_INVOKABLE QVariantList get(const QString &queryTxt);
Q_INVOKABLE QVariantList getList(const QStringList &urls);
Q_INVOKABLE void set(const QString &table, const QVariantList &wheres);
// Q_INVOKABLE void set(const QString &table, const QVariantList &wheres);
// Q_INVOKABLE void trackPlaylist(const QStringList &urls, const QString &playlist);
Q_INVOKABLE void trackPlaylist(const QStringList &urls, const QString &playlist);
/***MOVE ALL THIS TO A INFO MODEL ***/
Q_INVOKABLE void trackLyrics(const QString &url);
Q_INVOKABLE bool trackBabe(const QString &path);
Q_INVOKABLE QString artistArt(const QString &artist);
Q_INVOKABLE QString albumArt(const QString &album, const QString &artist);
Q_INVOKABLE QString artistWiki(const QString &artist);
Q_INVOKABLE QString albumWiki(const QString &album, const QString &artist);
Q_INVOKABLE QString loadCover(const QString &url);
/**************************************/
Q_INVOKABLE QVariantList getFolders();
Q_INVOKABLE QStringList getSourceFolders();
......@@ -59,16 +60,12 @@ public:
Q_INVOKABLE void getYoutubeTrack(const QString &message);
/* STATIC METHODS */
Q_INVOKABLE static void saveSetting(const QString &key, const QVariant &value, const QString &group);
Q_INVOKABLE static QVariant loadSetting(const QString &key, const QString &group, const QVariant &defaultValue);
Q_INVOKABLE static void savePlaylist(const QStringList &list);
Q_INVOKABLE static QStringList lastPlaylist();
Q_INVOKABLE static void savePlaylistPos(const int &pos);
Q_INVOKABLE static int lastPlaylistPos();
Q_INVOKABLE static bool fileExists(const QString &url);
Q_INVOKABLE static void showFolder(const QStringList &urls);
/*COLORS*/
......@@ -78,15 +75,8 @@ public:
Q_INVOKABLE void openUrls(const QStringList &urls);
Q_INVOKABLE static QString moodColor(const int &pos);
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static QString musicDir();
Q_INVOKABLE static QStringList defaultSources();
/*USEFUL*/
Q_INVOKABLE QString loadCover(const QString &url);
/*KDE*/
Q_INVOKABLE void notify(const QString &title, const QString &body);
Q_INVOKABLE void notifySong(const QString &url);
......@@ -95,7 +85,7 @@ public slots:
private:
Pulpo *pulpo;
ConThread *thread;
// ConThread *thread;
CollectionDB *db;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
......@@ -107,7 +97,7 @@ private:
static QVariantList transformData(const FMH::MODEL_LIST &dbList);
void fetchTrackLyrics(FMH::MODEL &song);
void linkDecoder(QString json);
// void linkDecoder(QString json);
signals:
void refreshTables(int size);
......
......@@ -29,14 +29,14 @@
#include "utils/bae.h"
#include "services/web/youtube.h"
#include "services/web/Spotify/spotify.h"
#include "services/local/linking.h"
//#include "services/web/Spotify/spotify.h"
//#include "services/local/linking.h"
#include "services/local/player.h"
#include "models/tracks/tracksmodel.h"
#include "models/albums/albumsmodel.h"
#include "models/playlists/playlistsmodel.h"
#include "models/cloud/cloud.h"
//#include "models/cloud/cloud.h"
#include "models/baselist.h"
#include "models/basemodel.h"
......@@ -65,19 +65,9 @@ int main(int argc, char *argv[])
const QCommandLineOption versionOption = parser.addVersionOption();
parser.process(app);
// bool version = parser.isSet(versionOption);
// if(version)
// {
// printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
// qPrintable(QCoreApplication::applicationVersion()));
// return 0;
// }
const QStringList args = parser.positionalArguments();
QStringList urls;
if(!args.isEmpty())
urls = args;
......@@ -85,7 +75,7 @@ int main(int argc, char *argv[])
/* Services */
YouTube youtube;
Spotify spotify;
// Spotify spotify;
QFontDatabase::addApplicationFont(":/assets/materialdesignicons-webfont.ttf");
......@@ -102,8 +92,8 @@ int main(int argc, char *argv[])
auto context = engine.rootContext();
context->setContextProperty("bae", &bae);
context->setContextProperty("youtube", &youtube);
context->setContextProperty("spotify", &spotify);
context->setContextProperty("link", &bae.link);
// context->setContextProperty("spotify", &spotify);
// context->setContextProperty("link", &bae.link);
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
......@@ -111,17 +101,17 @@ int main(int argc, char *argv[])
qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
qmlRegisterType<PlaylistsModel>("PlaylistsList", 1, 0, "Playlists");
qmlRegisterType<AlbumsModel>("AlbumsList", 1, 0, "Albums");
qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
// qmlRegisterType<Cloud>("CloudList", 1, 0, "CloudList");
qmlRegisterType<Player>("Player", 1, 0, "Player");
qmlRegisterUncreatableMetaObject(
LINK::staticMetaObject, // static meta object
"Link.Codes", // import statement (can be any string)
1, 0, // major and minor version of the import
"LINK", // name in QML (does not have to match C++ name)
"Error: only enums" // error in case someone tries to create a MyNamespace object
);
// qmlRegisterUncreatableMetaObject(
// LINK::staticMetaObject, // static meta object
// "Link.Codes", // import statement (can be any string)
// 1, 0, // major and minor version of the import
// "LINK", // name in QML (does not have to match C++ name)
// "Error: only enums" // error in case someone tries to create a MyNamespace object
// );
#ifdef STATIC_KIRIGAMI
KirigamiPlugin::getInstance().registerTypes();
......
......@@ -609,7 +609,7 @@ Maui.ApplicationWindow
globalDrawer: Maui.GlobalDrawer
{
id: _drawer
width: Kirigami.Units.gridUnit * 14
width: Kirigami.Units.gridUnit * 17
modal: !root.isWide
handleVisible: false
......@@ -700,8 +700,9 @@ Maui.ApplicationWindow
query = query.arg(artist)
mainPlaylist.list.clear()
mainPlaylist.list.sortBy = Tracks.NONE
mainPlaylist.list.query = query
Player.playAll()
Player.playAll()
}
onPlayAll:
......@@ -750,8 +751,10 @@ Maui.ApplicationWindow
onAlbumCoverPressedAndHold:
{
var query = Q.GET.artistTracks_.arg(artist)
var map = bae.get(query)
Player.playAll(map)
mainPlaylist.list.clear()
mainPlaylist.list.sortBy = Tracks.NONE
mainPlaylist.list.query = query
Player.playAll()
}
onPlayAll:
......@@ -803,9 +806,11 @@ Maui.ApplicationWindow
}
onPlaySync:
{
var tracks = bae.get(Q.GET.playlistTracks_.arg(playlist))
Player.playAll(tracks)
{
var query = playlistsView.playlistQuery
mainPlaylist.list.appendQuery(query)
Player.playAll()
root.sync = true
root.syncPlaylist = playlist
root.infoMsg = qsTr("Syncing to ") + playlist
......@@ -842,7 +847,10 @@ Maui.ApplicationWindow
query = query.arg(searchView.searchTable.model.get(
index).artist)
Player.playAll(bae.get(query))
mainPlaylist.list.clear()
mainPlaylist.list.sortBy = Tracks.NONE
mainPlaylist.list.query = query
Player.playAll()
}
}
}
......@@ -908,7 +916,7 @@ Maui.ApplicationWindow
id: _selectionBar
property alias listView: _selectionBar.selectionList
Layout.fillWidth: true
Layout.margins: space.huge
Layout.margins: space.big
Layout.topMargin: space.small
Layout.bottomMargin: space.big
onIconClicked: _contextMenu.popup()
......@@ -996,7 +1004,11 @@ Maui.ApplicationWindow
}
onSkipTrack: Player.nextTrack()
onBabeIt: Player.babeTrack()
onBabeIt: if (!mainlistEmpty)
{
mainPlaylist.list.fav(currentTrackIndex, !(mainPlaylist.list.get(currentTrackIndex).fav == "1"))
currentBabe = mainPlaylist.list.get(currentTrackIndex).fav == "1"
}
onOpenFiles: Player.playAll(tracks)
}
......
......@@ -127,29 +127,29 @@ FMH::MODEL_LIST PlaylistsModel::defaultPlaylists()
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Tags"},
{FMH::MODEL_KEY::ICON, "tag"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Relationships"},
{FMH::MODEL_KEY::ICON, "view-media-similarartists"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Popular"},
{FMH::MODEL_KEY::ICON, "view-media-chart"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
},
{
{FMH::MODEL_KEY::PLAYLIST, "Genres"},
{FMH::MODEL_KEY::ICON, "view-media-genre"},
{FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
}
// {
// {FMH::MODEL_KEY::PLAYLIST, "Tags"},
// {FMH::MODEL_KEY::ICON, "tag"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Relationships"},
// {FMH::MODEL_KEY::ICON, "view-media-similarartists"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Popular"},
// {FMH::MODEL_KEY::ICON, "view-media-chart"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// },
// {
// {FMH::MODEL_KEY::PLAYLIST, "Genres"},
// {FMH::MODEL_KEY::ICON, "view-media-genre"},
// {FMH::MODEL_KEY::ADDDATE,QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate)}
// }
};
}
......
......@@ -156,7 +156,7 @@ Page
editable: true
onValueChanged:
{
bae.saveSetting("YOUTUBELIMIT", value, "BABE")
Maui.FM.saveSettings("YOUTUBELIMIT", value, "BABE")
}
}
......
......@@ -113,53 +113,3 @@ function addToSelection(item)
item.path= item.url
selectionBar.append(item)
}
function queueIt(paths)
{
var data = bae.getList(paths)
Player.queueTracks(data)
}
function rateIt(paths, rate)
{
for(var i in paths)
{
var url = paths[i]
if(bae.rateTrack(url, rate))
if(paths.length === 1)
return rate
}
}
function moodIt(paths, color)
{
if(paths.length > 0)
for(var i in paths)
bae.colorTagTrack(paths[i], color)
}
function isFav(url)
{
var data = bae.get(Q.GET.tracksWhere_.arg("t.url = %1").arg(url))
if(data.lenght > 0)
return data[0].babe === 1 ? true : false
}
function faveIt(paths)
{
if(paths.length > 0)
{
for(var i in paths)
{
var url = paths[i]
var value = bae.trackBabe(url) ? false : true
if(bae.babeTrack(url, value))
if(paths.length === 1)
return value
}
}
}
Qt.include("Icons.js")
.import org.kde.mauikit 1.0 as Maui
function playTrack(index)
{
......@@ -9,7 +8,7 @@ function playTrack(index)
if(typeof(currentTrack) === "undefined") return
if(bae.fileExists(currentTrack.url))
if(Maui.FM.fileExists(currentTrack.url))
{
player.url = currentTrack.url;
player.playing = true
......@@ -19,7 +18,7 @@ function playTrack(index)
currentTrack.artwork = currentArtwork
currentBabe = bae.trackBabe(currentTrack.url)
// currentBabe = bae.trackBabe(currentTrack.url)
progressBar.enabled = true
......@@ -153,7 +152,7 @@ function appendTrack(track)
if(sync === true)
{
infoMsgAnim()
addToPlaylist([track.url], syncPlaylist)
// addToPlaylist([track.url], syncPlaylist)
}
}
......@@ -236,18 +235,3 @@ function playAll()
mainPlaylist.listView.positionViewAtBeginning()
playAt(0)
}
function babeTrack(url, value)
{
bae.babeTrack(url, value)
}
function addToPlaylist(urls, playlist)
{
if(urls.length > 0)
{
bae.trackPlaylist(urls, playlist)
bae.notify(playlist, urls.length + " tracks added to the playlist:\n"+urls.join("\n"))
}
}
......@@ -44,8 +44,7 @@ Maui.Dialog
onPressAndHold:
{
playlistsList.currentIndex = index
Player.addToPlaylist(tracks, playlistsList.model.get(playlistsList.currentIndex).playlist)
close()
insert()
}
}
}
......@@ -66,7 +65,6 @@ Maui.Dialog
addPlaylist()
playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
clear()
close()
}
}
......@@ -85,6 +83,12 @@ Maui.Dialog
if(newPlaylistField.text.length)
addPlaylist()
insert()
}
function insert()
{
playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
close()
}
......
......@@ -90,9 +90,8 @@ SwipeDelegate
iconColor: model.fav === "1" ? babeColor : textColor
onClicked:
{
model.fav = model.fav === "1" ? "0" : "1"
bae.babeTrack(url, model.fav)
{
list.fav(index, !(list.get(index).fav == "1"))
swipe.close()
}
}
......
......@@ -136,6 +136,7 @@ BabeGrid
quickPlayVisible: true
focus: true
list.sortBy: Tracks.TRACK
headBar.plegable: false
holder.emoji: "qrc:/assets/ElectricPlug.png"
......@@ -186,15 +187,6 @@ BabeGrid
}
function populate(query)
{
var map = bae.get(query)
if(map.length > 0)