2017-10-29 14:47:36 +03:00
|
|
|
#include "sync.h"
|
2017-11-09 23:09:59 +03:00
|
|
|
#include <QtSql>
|
|
|
|
#include <QMultimedia>
|
|
|
|
#include <QMediaPlayer>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include "song.h"
|
|
|
|
#include "node.h"
|
2017-10-29 14:47:36 +03:00
|
|
|
|
2017-11-09 23:09:59 +03:00
|
|
|
#include "config.h"
|
2017-11-06 01:33:16 +03:00
|
|
|
|
2017-11-09 23:09:59 +03:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
#include <QDebug>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace syncLib{
|
|
|
|
|
|
|
|
Sync::Sync(){
|
|
|
|
node = new Node();
|
|
|
|
player = new QMediaPlayer(nullptr,QMediaPlayer::LowLatency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sync::initDB(){
|
|
|
|
if(db) return;
|
|
|
|
db = QSqlDatabase::addDatabase("QSQLITE");
|
|
|
|
QDir d("./" + DATABASE_NAME);
|
|
|
|
db.setDatabaseName(d.absolutePath());
|
|
|
|
if(db->open()){
|
|
|
|
qyery = new QSqlQuery(db);
|
|
|
|
QString qyer = QString("CREATE TABLE IF NOT EXISTS %0 "
|
|
|
|
"id int NOT NULL AUTO_INCREMENT,"
|
|
|
|
"name VARCHAR(100),"
|
|
|
|
"size INT NOT NULL,"
|
|
|
|
"data BLOB NOT NULL").arg(DATATABLE_NAME);
|
|
|
|
qyery->exec(qyer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sync::save(const Song &song){
|
|
|
|
QString qyer = QString("INSERT INTO %0 (name, size, data) VALUES"
|
|
|
|
"(%1,%2, :data)").arg(DATATABLE_NAME,
|
|
|
|
song.name,
|
|
|
|
QString::number(song.size));
|
|
|
|
qyery->prepare(qyer);
|
|
|
|
qyery->bindValue(":data",song.source);
|
|
|
|
|
|
|
|
return qyery->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
Sync::~Sync(){
|
|
|
|
delete node;
|
|
|
|
delete db;
|
|
|
|
delete player;
|
2017-10-29 14:47:36 +03:00
|
|
|
}
|
2017-11-09 23:09:59 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|