Commit 3109147f authored by camilo higuita's avatar camilo higuita

a long needed clean up

parent 9482fadc
......@@ -21,9 +21,7 @@ set(CMAKE_AUTORCC ON)
add_executable(vvave
qml.qrc
main.cpp
# babe.cpp
vvave.cpp
# pulpo/services/geniusService.cpp
# pulpo/services/deezerService.cpp
pulpo/services/lastfmService.cpp
......@@ -38,17 +36,11 @@ add_executable(vvave
services/local/youtubedl.cpp
# services/local/linking.cpp
services/local/socket.cpp
# services/web/babeit.cpp
services/web/youtube.cpp
# services/web/Spotify/spotify.cpp
db/collectionDB.cpp
# settings/BabeSettings.cpp
# settings/fileloader.cpp
# utils/brain.cpp
# utils/babeconsole.cpp
models/tracks/tracksmodel.cpp
models/basemodel.cpp
models/baselist.cpp
models/playlists/playlistsmodel.cpp
models/albums/albumsmodel.cpp
# models/cloud/cloud.cpp
......@@ -68,7 +60,7 @@ if (ANDROID)
target_link_libraries(vvave MauiKit Qt5::AndroidExtras Qt5::WebView Qt5::Xml OpenSSL::SSL)
add_dependencies(vvave taglib)
kde_source_files_enable_exceptions(vvave babe.cpp)
kde_source_files_enable_exceptions(vvave)
else()
find_package(Taglib REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS WebEngine)
......
This diff is collapsed.
#ifndef BABE_H
#define BABE_H
#include <QObject>
#include <QVariantList>
#include "utils/bae.h"
#include "db/collectionDB.h"
//#include "services/local/linking.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
class Notify;
#elif defined (Q_OS_ANDROID)
//class NotificationClient;
#endif
class CollectionDB;
class Pulpo;
class BabeSettings;
class ConThread;
using namespace BAE;
class Babe : public QObject
{
Q_OBJECT
public:
explicit Babe(QObject *parent = nullptr);
~Babe();
BabeSettings *settings;
// Linking link;
// Q_INVOKABLE void runPy();
/* DATABASE INTERFACES */
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 trackPlaylist(const QStringList &urls, const QString &playlist);
/***MOVE ALL THIS TO A INFO MODEL ***/
Q_INVOKABLE void trackLyrics(const QString &url);
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 void loadCover(const QString &url);
/**************************************/
Q_INVOKABLE QVariantList getFolders();
Q_INVOKABLE QStringList getSourceFolders();
/* SETTINGS */
Q_INVOKABLE void scanDir(const QString &url);
Q_INVOKABLE void brainz(const bool &on);
Q_INVOKABLE bool brainzState();
Q_INVOKABLE void refreshCollection();
Q_INVOKABLE void getYoutubeTrack(const QString &message);
/* STATIC METHODS */
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 void showFolder(const QStringList &urls);
/*COLORS*/
Q_INVOKABLE static QString babeColor();
/*UTILS*/
Q_INVOKABLE void openUrls(const QStringList &urls);
Q_INVOKABLE static QString moodColor(const int &pos);
Q_INVOKABLE static QStringList defaultSources();
/*KDE*/
Q_INVOKABLE void notify(const QString &title, const QString &body);
Q_INVOKABLE void notifySong(const QString &url);
public slots:
private:
// ConThread *thread;
CollectionDB *db;
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
Notify *nof;
#elif defined (Q_OS_ANDROID)
// NotificationClient *nof;
#endif
void fetchCoverArt(FMH::MODEL &song);
static QVariantList transformData(const FMH::MODEL_LIST &dbList);
void fetchTrackLyrics(FMH::MODEL &song);
// void linkDecoder(QString json);
signals:
void refreshTables(int size);
void refreshTracks();
void refreshAlbums();
void refreshArtists();
void trackLyricsReady(QString lyrics, QString url);
void skipTrack();
void babeIt();
void message(QString msg);
void openFiles(QVariantList tracks);
void coverReady(const QString &path);
};
#endif // BABE_H
#include "conthread.h"
#include <QMap>
#include <QList>
#include "collectionDB.h"
ConThread::ConThread() : QObject(nullptr)
{
this->db = CollectionDB::getInstance();
this->moveToThread(&t);
this->t.start();
}
ConThread::~ConThread()
{
this->stop();
}
void ConThread::start(QString table, QVariantList wheres)
{
if(!this->go) this->go = true;
this->queue.append({{QString ("TABLE"), table}, {QString ("WHERES"), wheres}});
if(this->queue.size() > 1) return;
if(this->go)
{
qDebug()<<"RUNNIGN QUERY ON CONTHREAD"<<this->queue.first()["TABLE"].toString();
QMetaObject::invokeMethod(this, "set", Q_ARG(QString, this->queue.first()["TABLE"].toString()), Q_ARG(QVariantList, this->queue.first()["WHERES"].toList()));
}else return;
}
void ConThread::stop()
{
this->go = false;
this->t.quit();
this->t.wait();
}
void ConThread::pause()
{
this->go = false;
}
bool ConThread::isRunning()
{
return this->go;
}
void ConThread::setInterval(const uint &interval)
{
this->interval = interval;
}
void ConThread::get(QString query)
{
auto data = this->db->getDBDataQML(query);
emit this->dataReady(data);
}
void ConThread::set(QString tableName, QVariantList wheres)
{
for(auto variant : wheres)
{
this->db->insert(tableName, QVariantMap(variant.toMap()));
this->t.msleep(this->interval);
}
this->queue.removeFirst();
emit this->finished();
if(!this->queue.isEmpty())
this->set(this->queue.first()["TABLE"].toString(), this->queue.first()["WHERES"].toList());
}
#ifndef CONTHREAD_H
#define CONTHREAD_H
#include <QObject>
#include <QThread>
#include <QVariant>
class CollectionDB;
class ConThread : public QObject
{
Q_OBJECT
public:
explicit ConThread();
~ConThread();
void start(QString table, QVariantList wheres);
void stop();
void pause();
bool isRunning();
void setInterval(const uint &interval);
void get(QString query);
private:
QThread t;
CollectionDB *db;
uint interval = 0;
bool go = false;
QList<QMap<QString, QVariant>> queue;
signals:
void finished();
void dataReady(QVariantList);
public slots:
void set(QString tableName, QVariantList wheres);
};
#endif // CONTHREAD_H
#include "kdeconnect.h"
#include "../utils/babeconsole.h"
#include <QProcess>
KdeConnect::KdeConnect(QObject *parent) : QObject(parent)
{
}
QVariantList KdeConnect::getDevices()
{
QVariantList devices;
bDebug::Instance()->msg("Getting the kdeconnect devices avaliable");
QProcess process;
process.start("kdeconnect-cli -a");
process.waitForFinished();
// auto output = process->readAllStandardOutput();
process.setReadChannel(QProcess::StandardOutput);
while (process.canReadLine())
{
QString line = QString::fromLocal8Bit(process.readLine());
if(line.contains("(paired and reachable)"))
{
QVariantMap _devices;
QStringList items = line.split(" ");
auto key = QString(items.at(2));
auto name = QString(items.at(1)).replace(":","");
bDebug::Instance()->msg("Founded devices: "+key+" : "+name);
_devices.insert("key", key);
_devices.insert("name", name);
devices.append(_devices);
}
}
return devices;
}
bool KdeConnect::sendToDevice(const QString &device, const QString &id, const QString &url)
{
QString deviceName = device;
QString deviceKey = id;
bDebug::Instance()->msg("Trying to send "+url + " to : "+ deviceName);
auto process = new QProcess();
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus)
{
bDebug::Instance()->msg("ProcessFinished_totally"+exitCode+exitStatus);
// BabeWindow::nof->notify("Song sent to " + deviceName,title +" by "+ artist);
// process->deleteLater();
});
bDebug::Instance()->msg("kdeconnect-cli -d " +deviceKey+ " --share " + url);
process->start("kdeconnect-cli -d " +deviceKey+ " --share " +"\""+ url+"\"");
return true;
}
#ifndef KDECONNECT_H
#define KDECONNECT_H
#include <QObject>
#include <QMap>
#include <QString>
#include <QVariantList>
class KdeConnect : public QObject
{
Q_OBJECT
public:
explicit KdeConnect(QObject *parent = nullptr);
static QVariantList getDevices();
static bool sendToDevice(const QString &device, const QString &id, const QString &url);
signals:
public slots:
};
#endif // KDECONNECT_H
......@@ -38,8 +38,6 @@
#include "models/albums/albumsmodel.h"
#include "models/playlists/playlistsmodel.h"
//#include "models/cloud/cloud.h"
#include "models/baselist.h"
#include "models/basemodel.h"
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
......@@ -58,13 +56,15 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#endif
app.setApplicationName(BAE::App);
app.setApplicationVersion(BAE::Version);
app.setApplicationName(BAE::appName);
app.setApplicationVersion(BAE::version);
app.setApplicationDisplayName(BAE::displayName);
app.setOrganizationName(BAE::orgName);
app.setOrganizationDomain(BAE::orgDomain);
app.setWindowIcon(QIcon("qrc:/assets/vvave.png"));
app.setDesktopFileName(BAE::App);
QCommandLineParser parser;
parser.setApplicationDescription(BAE::Description);
parser.setApplicationDescription(BAE::description);
const QCommandLineOption versionOption = parser.addVersionOption();
parser.process(app);
......@@ -96,12 +96,7 @@ int main(int argc, char *argv[])
auto context = engine.rootContext();
context->setContextProperty("vvave", &vvave);
context->setContextProperty("youtube", &youtube);
// context->setContextProperty("spotify", &spotify);
// context->setContextProperty("link", &bae.link);
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterType<BaseModel>("BaseModel", 1, 0, "BaseModel");
qmlRegisterType<TracksModel>("TracksList", 1, 0, "Tracks");
qmlRegisterType<PlaylistsModel>("PlaylistsList", 1, 0, "Playlists");
qmlRegisterType<AlbumsModel>("AlbumsList", 1, 0, "Albums");
......@@ -109,14 +104,6 @@ int main(int argc, char *argv[])
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
// );
#ifdef STATIC_KIRIGAMI
KirigamiPlugin::getInstance().registerTypes();
#endif
......@@ -128,11 +115,7 @@ int main(int argc, char *argv[])
#ifdef Q_OS_ANDROID
QtWebView::initialize();
#else
// if(QQuickStyle::availableStyles().contains("nomad"))
// QQuickStyle::setStyle("nomad");
if(!BAE::isMobile())
QtWebEngine::initialize();
QtWebEngine::initialize();
#endif
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
......@@ -34,7 +34,6 @@ import Player 1.0
import AlbumsList 1.0
import TracksList 1.0
import BaseModel 1.0
import TracksList 1.0
Maui.ApplicationWindow
......@@ -237,6 +236,11 @@ Maui.ApplicationWindow
width: root.width
spacing: 0
Kirigami.Separator
{
Layout.fillWidth: true
}
Slider
{
id: progressBar
......@@ -266,7 +270,7 @@ Maui.ApplicationWindow
{
width: progressBar.visualPosition * parent.width
height: progressBar.height
color: babeColor
color: Kirigami.Theme.highlightColor
}
}
......@@ -278,15 +282,11 @@ Maui.ApplicationWindow
implicitWidth: progressBar.pressed ? Maui.Style.iconSizes.medium : 0
implicitHeight: progressBar.pressed ? Maui.Style.iconSizes.medium : 0
radius: progressBar.pressed ? Maui.Style.iconSizes.medium : 0
color: babeColor
color: Kirigami.Theme.highlightColor
}
}
// Kirigami.Separator
// {
// Layout.fillWidth: true
//// color: borderColor
// }
Maui.ToolBar
{
......@@ -967,44 +967,11 @@ Maui.ApplicationWindow
Layout.bottomMargin: Maui.Style.space.big
onIconClicked: _contextMenu.popup()
onExitClicked: clear()
// Kirigami.Theme.backgroundColor: "#212121"
// model: BaseModel
// {
// list: _selectionBarModelList
// }
// Tracks
// {
// id: _selectionBarModelList
// }
SelectionBarMenu
{
id: _contextMenu
}
// function append(item)
// {
// _selectionBar.append(item)
//// if(selectedPaths.indexOf(item.path) < 0)
//// {
//// selectedItems.push(item)
//// selectedPaths.push(item.path)
//// // for(var i = 0; i < selectionList.count ; i++ )
//// // if(selectionList.model.get(i).path === item.path)
//// // {
//// // selectionList.model.remove(i)
//// // return
//// // }
//// selectionList.model.list.append(item)
//// selectionList.positionViewAtEnd()
//// }
// }
}
}
......
......@@ -3,7 +3,7 @@
#include "utils/brain.h"
#include <QtConcurrent>
AlbumsModel::AlbumsModel(QObject *parent) : BaseList(parent),
AlbumsModel::AlbumsModel(QObject *parent) : MauiList(parent),
db(CollectionDB::getInstance())
{
connect(this, &AlbumsModel::queryChanged, this, &AlbumsModel::setList);
......
......@@ -2,17 +2,22 @@
#define ALBUMSMODEL_H
#include <QObject>
#include "models/baselist.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#include "mauilist.h"
#else
#include <MauiKit/fmh.h>
#include <MauiKit/mauilist.h>
#endif
class CollectionDB;
class AlbumsModel : public BaseList
class AlbumsModel : public MauiList
{
Q_OBJECT
Q_PROPERTY(AlbumsModel::QUERY query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(AlbumsModel::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
enum SORTBY : uint_fast8_t
{
ADDDATE = FMH::MODEL_KEY::ADDDATE,
......@@ -57,7 +62,7 @@ signals:
void sortByChanged();
public slots:
QVariantMap get(const int &index) const override;
QVariantMap get(const int &index) const;
void append(const QVariantMap &item);
void append(const QVariantMap &item, const int &at);
void refresh();
......
#include "baselist.h"
BaseList::BaseList(QObject *parent) : QObject(parent)
{
}
#ifndef BASELIST_H
#define BASELIST_H
#ifdef STATIC_MAUIKIT
#include "fm.h"
#include "fmh.h"
#else
#include <MauiKit/fm.h>
#include <MauiKit/fmh.h>
#endif
class BaseList : public QObject
{
Q_OBJECT
public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual FMH::MODEL_LIST items() const {return FMH::MODEL_LIST({{}});}
protected:
signals:
void preItemAppended();
void postItemAppended();
void preItemAppendedAt(int index);
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
virtual QVariantMap get(const int &index) const
{
Q_UNUSED(index);
return QVariantMap();
}
virtual bool update(const int &index, const QVariant &value, const int &role)
{
Q_UNUSED(index);
Q_UNUSED(value);
Q_UNUSED(role);
return false;
}
virtual bool update(const QVariantMap &data, const int &index)
{
Q_UNUSED(index);
Q_UNUSED(data);
return false;
}
virtual bool update(const FMH::MODEL &data)
{
Q_UNUSED(data);
return false;
}
virtual bool insert(const QVariantMap &map)
{
Q_UNUSED(map);
return false;
}
virtual bool remove(const int &index)
{
Q_UNUSED(index);
return false;
}
virtual void clear(){}
};
#endif // BASELIST_H
#include "basemodel.h"
#include "baselist.h"
BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int BaseModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant BaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mList)
return QVariant();
return mList->items().at(index.row())[static_cast<FMH::MODEL_KEY>(role)];
}
bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mList)
return false;
if (mList->update(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
BaseList *BaseModel::getList() const
{
return this->mList;
}
void BaseModel::setList(BaseList *value)
{
beginResetModel();
if(mList)
mList->disconnect(this);
mList = value;
if(mList)
{
connect(this->mList, &BaseList::preItemAppended, this, [=]()
{
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemAppended, this, [=]()
{
endInsertRows();
});
connect(this->mList, &BaseList::preItemAppendedAt, this, [=](int index)
{
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::preItemRemoved, this, [=](int index)
{
beginRemoveRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemRemoved, this, [=]()
{
endRemoveRows();
});