mirror of
https://github.com/QuasarApp/SoundBand.git
synced 2025-05-09 05:29:34 +00:00
added support sql files.
This commit is contained in:
parent
3f1a5aba12
commit
0d0f83eca0
@ -34,7 +34,8 @@ SOURCES += \
|
||||
servermodel.cpp \
|
||||
songmodel.cpp \
|
||||
../sync/player.cpp \
|
||||
../sync/chronotime.cpp
|
||||
../sync/chronotime.cpp \
|
||||
../sync/mysql.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@ -48,7 +49,8 @@ HEADERS += \
|
||||
servermodel.h \
|
||||
songmodel.h \
|
||||
../sync/player.h \
|
||||
../sync/chronotime.h
|
||||
../sync/chronotime.h \
|
||||
../sync/mysql.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
41
sync/mysql.cpp
Normal file
41
sync/mysql.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "mysql.h"
|
||||
#include <QSqlQuery>
|
||||
#include <QtSql>
|
||||
|
||||
namespace syncLib{
|
||||
|
||||
MySql::MySql()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MySql::exec(QSqlQuery *sq,const QString& sqlFile){
|
||||
QFile f(sqlFile);
|
||||
bool result=true;
|
||||
if(f.open(QIODevice::ReadOnly)){
|
||||
QString temp,delimiter=";";
|
||||
QTextStream stream(&f);
|
||||
stream.setCodec("UTF8");
|
||||
while(!stream.atEnd()){
|
||||
temp+=stream.readLine();
|
||||
if(temp.lastIndexOf("delimiter",-1,Qt::CaseInsensitive)>-1){
|
||||
temp.remove("delimiter",Qt::CaseInsensitive);
|
||||
int last=temp.indexOf(QRegularExpression("[^ \f\n\r\t\v]"))+1;
|
||||
int begin=temp.lastIndexOf(QRegularExpression("[^ \f\n\r\t\v]"));
|
||||
delimiter=temp.mid(begin,last-begin);
|
||||
temp="";
|
||||
}else{
|
||||
if(temp.lastIndexOf(delimiter)>-1){
|
||||
temp.remove(delimiter);
|
||||
(result=result&&sq->exec(temp));
|
||||
temp="";
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
20
sync/mysql.h
Normal file
20
sync/mysql.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef MYSQL_H
|
||||
#define MYSQL_H
|
||||
#include <QString>
|
||||
|
||||
|
||||
class QSqlDatabase;
|
||||
class QSqlQuery;
|
||||
|
||||
namespace syncLib {
|
||||
|
||||
|
||||
class MySql
|
||||
{
|
||||
public:
|
||||
MySql();
|
||||
static bool exec(QSqlQuery *q, const QString& sqlFile);
|
||||
~MySql();
|
||||
};
|
||||
}
|
||||
#endif // MYSQL_H
|
@ -17,13 +17,11 @@ Sync::Sync(const QString address, int port, const QString &datadir):
|
||||
db(nullptr),
|
||||
player(nullptr),
|
||||
qyery(nullptr),
|
||||
buffer(nullptr),
|
||||
curentSong(nullptr)
|
||||
{
|
||||
node = new Node(address , this->port = port);
|
||||
|
||||
player = new Player(BUFFER_NAME,nullptr,QMediaPlayer::LowLatency);
|
||||
buffer = new QBuffer;
|
||||
if(!player->isAvailable()){
|
||||
throw MediaException();
|
||||
}
|
||||
@ -260,7 +258,6 @@ void Sync::pause(bool state){
|
||||
}
|
||||
|
||||
void Sync::stop(){
|
||||
buffer->close();
|
||||
player->stop();
|
||||
}
|
||||
|
||||
|
@ -5,12 +5,9 @@
|
||||
#include "LocalScanner.h"
|
||||
#include <chrono>
|
||||
#include "config.h"
|
||||
|
||||
#include "mysql.h"
|
||||
#include "player.h"
|
||||
|
||||
class QSqlDatabase;
|
||||
class QSqlQuery;
|
||||
class QBuffer;
|
||||
namespace syncLib {
|
||||
|
||||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> Clock;
|
||||
@ -28,7 +25,6 @@ private:
|
||||
Node *node;
|
||||
QSqlDatabase *db;
|
||||
Player *player;
|
||||
QBuffer *buffer;
|
||||
QList<SongHeader> playList;
|
||||
SongHeader * curentSong;
|
||||
QSqlQuery *qyery;
|
||||
|
@ -30,7 +30,9 @@ SOURCES += \
|
||||
node.cpp \
|
||||
player.cpp \
|
||||
song.cpp \
|
||||
sync.cpp
|
||||
sync.cpp \
|
||||
mysql.cpp
|
||||
|
||||
|
||||
|
||||
HEADERS += \
|
||||
@ -42,7 +44,9 @@ HEADERS += \
|
||||
node.h \
|
||||
player.h \
|
||||
song.h \
|
||||
sync.h
|
||||
sync.h \
|
||||
mysql.h
|
||||
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
@ -14,7 +14,8 @@ SOURCES += \
|
||||
../node.cpp \
|
||||
../player.cpp \
|
||||
../song.cpp \
|
||||
../sync.cpp
|
||||
../sync.cpp \
|
||||
../mysql.cpp
|
||||
|
||||
|
||||
RESOURCES += \
|
||||
@ -29,6 +30,7 @@ HEADERS += \
|
||||
../node.h \
|
||||
../player.h \
|
||||
../song.h \
|
||||
../sync.h
|
||||
../sync.h \
|
||||
../mysql.h
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user