Commit eaebb485 authored by Camilo Higuita's avatar Camilo Higuita

singleton helper and work on the console

parent feb13216
......@@ -368,7 +368,8 @@ HEADERS += \
java/notificationclient.h \
db/conthread.h \
services/web/babeit.h \
utils/babeconsole.h
utils/babeconsole.h \
utils/singleton.h
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
......
This diff is collapsed.
......@@ -4,6 +4,7 @@
#include "db/conthread.h"
#include "settings/BabeSettings.h"
#include "pulpo/pulpo.h"
#include "../utils/babeconsole.h"
#include <QPalette>
#include <QWidget>
......@@ -30,11 +31,13 @@ using namespace BAE;
Babe::Babe(QObject *parent) : CollectionDB(parent)
{
Babe::debug("CONSTRUCTING ABE INTERFACE");
bDebug::Instance()->msg("CONSTRUCTING ABE INTERFACE");
this->settings = new BabeSettings(this);
this->thread = new ConThread;
connect(bDebug::Instance(), SIGNAL(debug(QString)), this, SLOT(debug(QString)));
connect(settings, &BabeSettings::refreshTables, [this](QVariantMap tables)
{
emit this->refreshTables(tables);
......@@ -107,7 +110,7 @@ void Babe::trackPlaylist(const QStringList &urls, const QString &playlist)
data << map;
}
debug("Adding "+QString::number(urls.size())+" tracks to playlist : "+playlist);
bDebug::Instance()->msg("Adding "+QString::number(urls.size())+" tracks to playlist : "+playlist);
this->thread->start(BAE::TABLEMAP[TABLE::TRACKS_PLAYLISTS], data);
}
......@@ -179,7 +182,7 @@ QString Babe::albumArt(const QString &album, const QString &artist)
void Babe::fetchTrackLyrics(DB &song)
{
Pulpo pulpo;
pulpo.registerServices({SERVICES::LyricWikia, SERVICES::Genius});
pulpo.registerServices({SERVICES::LyricWikia});
pulpo.setOntology(PULPO::ONTOLOGY::TRACK);
pulpo.setInfo(PULPO::INFO::LYRICS);
......@@ -190,7 +193,7 @@ void Babe::fetchTrackLyrics(DB &song)
auto lyrics = res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::LYRICS][PULPO::CONTEXT::LYRIC].toString();
lyricsTrack(track, lyrics);
debug("Downloaded the lyrics for "+song[KEY::TITLE]+" "+song[KEY::ARTIST]);
bDebug::Instance()->msg("Downloaded the lyrics for "+song[KEY::TITLE]+" "+song[KEY::ARTIST]);
emit this->trackLyricsReady(lyrics, song[KEY::URL]);
}
});
......@@ -499,8 +502,7 @@ QString Babe::homeDir()
#if defined(Q_OS_ANDROID)
QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
// debug("HOMEDIR FROM ADNROID"+ mediaPath.toString());
// bDebug::Instance()->msg("HOMEDIR FROM ADNROID"+ mediaPath.toString());
if(BAE::fileExists("/mnt/extSdCard"))
return "/mnt/sdcard";
......@@ -532,7 +534,7 @@ QString Babe::sdDir()
// env->ExceptionClear();
// }
// qDebug()<<"TESTED SDPATH"<<QProcessEnvironment::systemEnvironment().value("EXTERNAL_SDCARD_STORAGE",dataAbsPath);
// qbDebug::Instance()->msg()<<"TESTED SDPATH"<<QProcessEnvironment::systemEnvironment().value("EXTERNAL_SDCARD_STORAGE",dataAbsPath);
if(BAE::fileExists("/mnt/extSdCard"))
return "/mnt/extSdCard";
else if(BAE::fileExists("/mnt/ext_sdcard"))
......@@ -551,7 +553,7 @@ QVariantList Babe::getDirs(const QString &pathUrl)
if(path.startsWith("file://"))
path.replace("file://", "");
//debug("Get directories for path: "+path);
bDebug::Instance()->msg("Get directories for path: "+path);
QVariantList paths;
if (QFileInfo(path).isDir())
......@@ -688,7 +690,6 @@ QVariantList Babe::searchFor(const QStringList &queries)
void Babe::debug(const QString &msg)
{
emit this->message(msg);
qDebug()<<msg;
}
......
......@@ -10,7 +10,6 @@
class Notify;
#endif
class BabeConsole;
class CollectionDB;
class Pulpo;
class BabeSettings;
......@@ -110,6 +109,7 @@ public:
Q_INVOKABLE QString loadCover(const QString &url);
Q_INVOKABLE QVariantList searchFor(const QStringList &queries);
public slots:
void debug(const QString &msg);
private:
......@@ -133,4 +133,5 @@ signals:
void message(QString msg);
};
#endif // BABE_H
......@@ -19,7 +19,7 @@
#include "youtube.h"
#include "../../pulpo/pulpo.h"
#include "../../db/collectionDB.h"
#include "../../utils/babeconsole.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif
......@@ -53,7 +53,7 @@ void YouTube::fetch(const QString &json)
auto playlist = data.value("playlist").toString().trimmed();
auto page = data.value("page").toString().replace('"',"").trimmed();
qDebug()<< id << title << artist;
bDebug::Instance()->msg("Fetching from Youtube: "+id+" "+title+" "+artist);
DB infoMap;
infoMap.insert(KEY::TITLE, title);
......@@ -85,7 +85,7 @@ void YouTube::fetch(const QString &json)
auto command = ydl;
command = command.replace("$$$",infoMap[KEY::ID])+" "+infoMap[KEY::ID];
qDebug()<<command;
bDebug::Instance()->msg(command);
process->start(command);
}
}
......@@ -101,8 +101,9 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
ids.removeAll(doneId);
track.insert(KEY::URL,file);
bDebug::Instance()->msg("Finished collection track with youtube-dl");
qDebug()<<track[KEY::ID]<<track[KEY::TITLE]<<track[KEY::ARTIST]<<track[KEY::PLAYLIST]<<track[KEY::URL];
// qDebug()<<track[KEY::ID]<<track[KEY::TITLE]<<track[KEY::ARTIST]<<track[KEY::PLAYLIST]<<track[KEY::URL];
/*here get metadata*/
TagInfo tag;
......@@ -117,7 +118,7 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
tag.setAlbum(track[KEY::ALBUM]);
tag.setComment(track[KEY::URL]);
qDebug()<<"trying tocollect metadata of downloaded track";
bDebug::Instance()->msg("Trying to collect metadata of downloaded track");
Pulpo pulpo;
pulpo.registerServices({PULPO::SERVICES::LastFm, PULPO::SERVICES::Spotify});
pulpo.setOntology(PULPO::ONTOLOGY::TRACK);
......@@ -126,20 +127,19 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
QEventLoop loop;
QTimer timer;
connect(&timer, &QTimer::timeout,&loop,&QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.setSingleShot(true);
timer.setInterval(1000);
connect(&pulpo, &Pulpo::infoReady, [&loop](const BAE::DB &track, const PULPO::RESPONSE &res)
{
qDebug()<<"SETTING YOUTUBE DOWNLOAD TRACK METADATA";
bDebug::Instance()->msg("Setting collected track metadata");
if(!res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::METADATA].isEmpty())
{
qDebug()<<res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::METADATA][PULPO::CONTEXT::ALBUM_TITLE].toString();
qDebug()<<res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::METADATA][PULPO::CONTEXT::TRACK_NUMBER].toString();
bDebug::Instance()->msg(res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::METADATA][PULPO::CONTEXT::ALBUM_TITLE].toString());
bDebug::Instance()->msg(res[PULPO::ONTOLOGY::TRACK][PULPO::INFO::METADATA][PULPO::CONTEXT::TRACK_NUMBER].toString());
qDebug()<<track[KEY::URL];
TagInfo tag;
tag.feed(track[KEY::URL]);
......@@ -160,10 +160,10 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
loop.exec();
timer.stop();
qDebug()<<"process finished totally for"<< state << doneId << exitStatus;
bDebug::Instance()->msg("Process finished totally for "+QString(state)+" "+doneId+" "+QString(exitStatus));
qDebug()<<"need to delete the id=" << doneId;
qDebug()<<"ids left to process: " << this->ids;
bDebug::Instance()->msg("Need to delete the id "+ doneId);
bDebug::Instance()->msg("Ids left to process: " + this->ids.join(","));
}
}
......@@ -178,8 +178,6 @@ void YouTube::processFinished_totally(const int &state,const DB &info,const QPro
auto duration = tag.getDuration();
auto year = tag.getYear();
qDebug()<<"FILE LOADER:"<< title << album << artist <<file;
BAE::DB trackMap =
{
{BAE::KEY::URL,file},
......
......@@ -22,6 +22,7 @@
#include "../utils/brain.h"
#include "../services/local/socket.h"
#include "../services/web/youtube.h"
#include "../utils/babeconsole.h"
BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
{
......@@ -42,11 +43,11 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
if(!BAE::fileExists(notifyDir+"/Babe.notifyrc"))
{
qDebug()<<"The Knotify file does not exists, going to create it";
bDebug::Instance()->msg("The Knotify file does not exists, going to create it");
QFile knotify(":/assets/Babe.notifyrc");
if(knotify.copy(notifyDir+"/Babe.notifyrc"))
qDebug()<<"the knotify file got copied";
bDebug::Instance()->msg("the knotify file got copied");
}
#endif
......@@ -79,7 +80,7 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
connect(this->babeSocket, &Socket::connected, [this](const int &index)
{
auto playlists = this->connection->getPlaylists();
qDebug()<<"Sending playlists to socket"<<playlists;
bDebug::Instance()->msg("Sending playlists to socket: "+playlists.join(", "));
this->babeSocket->sendMessageTo(index, playlists.join(","));
});
......@@ -111,7 +112,7 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
// this->startBrainz(true, BAE::SEG::ONEHALF);
qDebug()<<"Finished inserting into DB";
bDebug::Instance()->msg("Finished inserting into DB");
}else
{
this->dirs.clear();
......@@ -162,7 +163,7 @@ void BabeSettings::refreshCollectionPaths()
void BabeSettings::addToWatcher(QStringList paths)
{
qDebug()<<"duplicated paths in watcher removd: "<<paths.removeDuplicates();
bDebug::Instance()->msg("Removed duplicated paths in watcher: "+paths.removeDuplicates());
if(!paths.isEmpty()) watcher->addPaths(paths);
}
......@@ -198,7 +199,7 @@ void BabeSettings::collectionWatcher()
void BabeSettings::handleDirectoryChanged(const QString &dir)
{
qDebug()<<"directory changed:"<<dir;
bDebug::Instance()->msg("directory changed:"+dir);
auto wait = new QTimer(this);
wait->setSingleShot(true);
......@@ -216,7 +217,7 @@ void BabeSettings::handleDirectoryChanged(const QString &dir)
void BabeSettings::checkCollectionBrainz(const bool &state)
{
qDebug()<<"BRAINZ STATE<<"<<state;
bDebug::Instance()->msg("BRAINZ STATE<<"+state);
this->startBrainz(state, BAE::SEG::THREE);
}
......
......@@ -5,7 +5,7 @@ function playTrack(track)
{
if(track)
{
root.currentTrack = track
currentTrack = track
if(bae.fileExists(currentTrack.url))
{
......@@ -15,16 +15,15 @@ function playTrack(track)
var artwork = currentTrack.artwork
// root.mainPlaylist.list.currentItem.playingIndicator = true
root.currentArtwork = artwork && artwork.length>0 && artwork !== "NONE" ? artwork : bae.loadCover(currentTrack.url)
currentArtwork = artwork && artwork.length>0 && artwork !== "NONE" ? artwork : bae.loadCover(currentTrack.url)
root.currentBabe = bae.trackBabe(currentTrack.url)
currentBabe = bae.trackBabe(currentTrack.url)
root.progressBar.enabled = true
progressBar.enabled = true
if(!root.isMobile)
if(!isMobile)
{
root.title = currentTrack.title + " - " +currentTrack.artist
title = currentTrack.title + " - " +currentTrack.artist
if(!root.active)
bae.notifySong(currentTrack.url)
......
......@@ -8,7 +8,8 @@ BabeConsole::BabeConsole(QObject *parent) : QObject(parent)
void BabeConsole::msg(const QString &msg)
{
emit debug(msg);
// emit debug(msg);
bDebug::Instance()->debug(msg);
qDebug()<<msg;
}
......@@ -2,15 +2,14 @@
#define BABECONSOLE_H
#include <QObject>
#include <iostream>
#include "singleton.h"
using namespace std;
class BabeConsole : public QObject
{
Q_OBJECT
public:
explicit BabeConsole(QObject *parent = nullptr);
void msg(const QString &msg);
static void msg(const QString &msg);
signals:
void debug(QString msg);
......@@ -18,6 +17,6 @@ signals:
public slots:
};
typedef Singleton<BabeConsole> bDebug;
#endif // BABECONSOLE_H
#ifndef SINGLETON_H
#define SINGLETON_H
#include <assert.h>
template <class T>
class Singleton
{
public:
static T* Instance()
{
if(!m_Instance) m_Instance = new T;
assert(m_Instance != nullptr);
return m_Instance;
}
protected:
Singleton();
~Singleton();
private:
Singleton(Singleton const&);
Singleton& operator = (Singleton const&);
static T* m_Instance;
};
template <class T> T* Singleton<T>::m_Instance = nullptr;
#endif // SINGLETON_H
......@@ -17,7 +17,7 @@ Page
Rectangle
{
visible: logginDialog.visible
visible: logginDialog.visible && !isMobile
anchors.fill: parent
z: -999
color: darkColor
......
......@@ -12,8 +12,8 @@ BabePopup
padding: contentMargins*3
maxHeight: loginLayout.implicitHeight+64
maxWidth: loginLayout.implicitWidth+64
// closePolicy: Popup.NoAutoClose
// modal: false
// closePolicy: Popup.NoAutoClose
ScrollView
{
......
......@@ -18,6 +18,12 @@ BabePopup
onMessage: consoletext.append(">> "+msg+"\n");
}
background: Rectangle
{
color: darkDarkColor
border.color: "#111"
}
ColumnLayout
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment