Init
This commit is contained in:
+30
-48
@@ -7,78 +7,60 @@
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
cKodiLibrary::cKodiLibrary(QStatusBar* lpMainWindowStatusBar, QSqlDatabase& dbVideos) :
|
||||
m_command(command_none),
|
||||
cKodiLibrary::cKodiLibrary(QStatusBar* lpMainWindowStatusBar, const QString& szPath) :
|
||||
m_lpMainWindowStatusBar(lpMainWindowStatusBar),
|
||||
m_dbVideos(dbVideos)
|
||||
m_szPath(szPath)
|
||||
{
|
||||
}
|
||||
|
||||
void cKodiLibrary::stop()
|
||||
cKodiLibrary::~cKodiLibrary()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
while(m_command != command_none)
|
||||
msleep(100);
|
||||
|
||||
m_command = command_stop;
|
||||
}
|
||||
|
||||
void cKodiLibrary::run()
|
||||
QString cKodiLibrary::findFile(const QString& szPath, const QString& szFile)
|
||||
{
|
||||
bool bStop = false;
|
||||
QTime timer;
|
||||
timer.restart();
|
||||
QDir fileList(szPath + QDir::separator() + QString("Userdata") + QDir::separator() + QString("Database"), szFile + QString("*.*"));
|
||||
QString fileName("");
|
||||
QStringList files = fileList.entryList(QDir::Files);
|
||||
qint16 iVersion = -1;
|
||||
|
||||
for(;;)
|
||||
for(int x = 0;x < files.count();x++)
|
||||
{
|
||||
switch(m_command)
|
||||
QString tmp = files.at(x);
|
||||
tmp = tmp.left(tmp.lastIndexOf("."));
|
||||
tmp = tmp.mid(szFile.length());
|
||||
if(iVersion < tmp.toInt())
|
||||
{
|
||||
case command_none:
|
||||
break;
|
||||
case command_init:
|
||||
doInit();
|
||||
m_command = command_none;
|
||||
break;
|
||||
case command_stop:
|
||||
bStop = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
fileName = files.at(x);
|
||||
iVersion = tmp.toInt();
|
||||
}
|
||||
|
||||
if(bStop)
|
||||
break;
|
||||
msleep(10);
|
||||
}
|
||||
if(fileName.length())
|
||||
return(fileList.cleanPath(fileList.absoluteFilePath(fileName)));
|
||||
return(fileName);
|
||||
}
|
||||
|
||||
void cKodiLibrary::init()
|
||||
bool cKodiLibrary::init()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
qint32 iVideoCount;
|
||||
|
||||
while(m_command != command_none)
|
||||
msleep(100);
|
||||
m_lpMainWindowStatusBar->showMessage("Initializing ...");
|
||||
|
||||
m_command = command_init;
|
||||
}
|
||||
|
||||
bool cKodiLibrary::doInit()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
qint32 iVideoCount = 0;
|
||||
m_szAddons = findFile(m_szPath, "Addons");
|
||||
m_szADSP = findFile(m_szPath, "ADSP");
|
||||
m_szEpg = findFile(m_szPath, "Epg");
|
||||
m_szMyMusic = findFile(m_szPath, "MyMusic");
|
||||
m_szMyVideos = findFile(m_szPath, "MyVideos");
|
||||
m_szTextures = findFile(m_szPath, "Textures");
|
||||
m_szTV = findFile(m_szPath, "TV");
|
||||
m_szViewModes = findFile(m_szPath, "ViewModes");
|
||||
|
||||
m_lpMainWindowStatusBar->showMessage("Initializing Videos ...");
|
||||
|
||||
if(!m_dbVideos.open())
|
||||
return(false);
|
||||
|
||||
m_lpKodiVideoLibrary = new cKodiVideoLibrary(m_dbVideos);
|
||||
m_lpKodiVideoLibrary = new cKodiVideoLibrary(m_szMyVideos);
|
||||
if(m_lpKodiVideoLibrary->init() != -1)
|
||||
iVideoCount = m_lpKodiVideoLibrary->load();
|
||||
emit initDone(iVideoCount);
|
||||
|
||||
m_command = command_none;
|
||||
m_lpMainWindowStatusBar->showMessage("Done.", 3000);
|
||||
|
||||
return(iVideoCount != 0);
|
||||
|
||||
+14
-25
@@ -5,41 +5,30 @@
|
||||
#include "ckodivideolibrary.h"
|
||||
|
||||
#include <QStatusBar>
|
||||
#include <QThread>
|
||||
#include <QMutexLocker>
|
||||
|
||||
|
||||
class cKodiLibrary : public QThread
|
||||
class cKodiLibrary
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
cKodiLibrary(QStatusBar* lpMainWindowStatusBar, QSqlDatabase& dbVideos);
|
||||
public slots:
|
||||
void stop();
|
||||
void init();
|
||||
|
||||
signals:
|
||||
void initDone(qint32 iMovieCount);
|
||||
cKodiLibrary(QStatusBar* lpMainWindowStatusBar, const QString& szPath);
|
||||
~cKodiLibrary();
|
||||
|
||||
bool init();
|
||||
private:
|
||||
enum commands
|
||||
{
|
||||
command_none = 0,
|
||||
command_init = 1,
|
||||
command_stop = 99,
|
||||
};
|
||||
|
||||
commands m_command;
|
||||
QMutex m_mutex;
|
||||
QStatusBar* m_lpMainWindowStatusBar;
|
||||
cKodiVideoLibrary* m_lpKodiVideoLibrary;
|
||||
QString m_szPath;
|
||||
|
||||
QSqlDatabase m_dbVideos;
|
||||
QString m_szAddons;
|
||||
QString m_szADSP;
|
||||
QString m_szEpg;
|
||||
QString m_szMyMusic;
|
||||
QString m_szMyVideos;
|
||||
QString m_szTextures;
|
||||
QString m_szTV;
|
||||
QString m_szViewModes;
|
||||
|
||||
void run();
|
||||
|
||||
bool doInit();
|
||||
QString findFile(const QString& szPath, const QString& szFile);
|
||||
};
|
||||
|
||||
#endif // CKODILIBRARY_H
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
cKodiVideoLibrary::cKodiVideoLibrary(QSqlDatabase& db) :
|
||||
m_db(db),
|
||||
cKodiVideoLibrary::cKodiVideoLibrary(const QString& szFileName) :
|
||||
m_szFileName(szFileName),
|
||||
m_bConnected(false),
|
||||
m_iVersion(-1)
|
||||
{
|
||||
@@ -25,6 +25,11 @@ qint16 cKodiVideoLibrary::init()
|
||||
if(m_bConnected)
|
||||
return(m_iVersion);
|
||||
|
||||
m_db = QSqlDatabase::addDatabase("QSQLITE", "VideoLibrary");
|
||||
m_db.setDatabaseName(m_szFileName);
|
||||
if(!m_db.open())
|
||||
return(-1);
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
if(!query.exec("SELECT idVersion FROM version;"))
|
||||
{
|
||||
|
||||
+2
-1
@@ -9,7 +9,7 @@
|
||||
class cKodiVideoLibrary
|
||||
{
|
||||
public:
|
||||
cKodiVideoLibrary(QSqlDatabase& db);
|
||||
cKodiVideoLibrary(const QString& szFileName);
|
||||
~cKodiVideoLibrary();
|
||||
|
||||
qint16 init();
|
||||
@@ -18,6 +18,7 @@ public:
|
||||
qint32 load();
|
||||
private:
|
||||
QSqlDatabase m_db;
|
||||
QString m_szFileName;
|
||||
bool m_bConnected;
|
||||
qint16 m_iVersion;
|
||||
};
|
||||
|
||||
+5
-62
@@ -33,12 +33,7 @@ cMainWindow::~cMainWindow()
|
||||
delete m_lpMusicVideoWidget;
|
||||
|
||||
if(m_lpKodiLibrary)
|
||||
{
|
||||
m_lpKodiLibrary->stop();
|
||||
while(!m_lpKodiLibrary->isFinished())
|
||||
QThread::msleep(100);
|
||||
delete m_lpKodiLibrary;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
@@ -52,70 +47,18 @@ void cMainWindow::initUI()
|
||||
m_lpMusicWidget = new cMusicWidget(this);
|
||||
m_lpMusicVideoWidget = new cMusicVideosWidget(this);
|
||||
|
||||
// ui->m_lpMainTab->addTab(m_lpMovieWidget, QIcon(":/icons/Videos.ico"), "Movies");
|
||||
// ui->m_lpMainTab->addTab(m_lpTVShowWidget, QIcon(":/icons/TV Shows.ico"), "TV Shows");
|
||||
// ui->m_lpMainTab->addTab(m_lpMusicWidget, QIcon(":/icons/Musics.ico"), "Music");
|
||||
// ui->m_lpMainTab->addTab(m_lpMusicVideoWidget, QIcon(":/icons/Videos.ico"), "Music Videos");
|
||||
ui->m_lpMainTab->addTab(m_lpMovieWidget, QIcon(":/icons/empty.ico"), "Movies");
|
||||
ui->m_lpMainTab->addTab(m_lpTVShowWidget, QIcon(":/icons/empty.ico"), "TV Shows");
|
||||
ui->m_lpMainTab->addTab(m_lpMusicWidget, QIcon(":/icons/empty.ico"), "Music");
|
||||
ui->m_lpMainTab->addTab(m_lpMusicVideoWidget, QIcon(":/icons/empty.ico"), "Music Videos");
|
||||
ui->m_lpMainTab->addTab(m_lpMovieWidget, QIcon(":/icons/Videos.ico"), "Movies");
|
||||
ui->m_lpMainTab->addTab(m_lpTVShowWidget, QIcon(":/icons/TV Shows.ico"), "TV Shows");
|
||||
ui->m_lpMainTab->addTab(m_lpMusicWidget, QIcon(":/icons/Musics.ico"), "Music");
|
||||
ui->m_lpMainTab->addTab(m_lpMusicVideoWidget, QIcon(":/icons/Videos.ico"), "Music Videos");
|
||||
|
||||
ui->m_lpMainTab->setCurrentIndex(0);
|
||||
|
||||
setWindowTitle("qtKodiAdmin");
|
||||
}
|
||||
|
||||
QString cMainWindow::findFile(const QString& szPath, const QString& szFile)
|
||||
{
|
||||
QDir fileList(szPath + QDir::separator() + QString("Userdata") + QDir::separator() + QString("Database"), szFile + QString("*.*"));
|
||||
QString fileName("");
|
||||
QStringList files = fileList.entryList(QDir::Files);
|
||||
qint16 iVersion = -1;
|
||||
|
||||
for(int x = 0;x < files.count();x++)
|
||||
{
|
||||
QString tmp = files.at(x);
|
||||
tmp = tmp.left(tmp.lastIndexOf("."));
|
||||
tmp = tmp.mid(szFile.length());
|
||||
if(iVersion < tmp.toInt())
|
||||
{
|
||||
fileName = files.at(x);
|
||||
iVersion = tmp.toInt();
|
||||
}
|
||||
}
|
||||
if(fileName.length())
|
||||
return(fileList.cleanPath(fileList.absoluteFilePath(fileName)));
|
||||
return(fileName);
|
||||
}
|
||||
|
||||
void cMainWindow::initDB()
|
||||
{
|
||||
ui->m_lpStatusBar->showMessage("Initializing ...");
|
||||
|
||||
m_szPath = QDir::homePath() + QDir::separator() + QString(".kodi");
|
||||
|
||||
m_szAddons = findFile(m_szPath, "Addons");
|
||||
m_szADSP = findFile(m_szPath, "ADSP");
|
||||
m_szEpg = findFile(m_szPath, "Epg");
|
||||
m_szMyMusic = findFile(m_szPath, "MyMusic");
|
||||
m_szMyVideos = findFile(m_szPath, "MyVideos");
|
||||
m_szTextures = findFile(m_szPath, "Textures");
|
||||
m_szTV = findFile(m_szPath, "TV");
|
||||
m_szViewModes = findFile(m_szPath, "ViewModes");
|
||||
|
||||
m_dbVideos = QSqlDatabase::addDatabase("QSQLITE", "VideoLibrary");
|
||||
m_dbVideos.setDatabaseName(m_szMyVideos);
|
||||
if(!m_dbVideos.open())
|
||||
return;
|
||||
|
||||
m_lpKodiLibrary = new cKodiLibrary(ui->m_lpStatusBar, m_dbVideos);
|
||||
connect(m_lpKodiLibrary, SIGNAL(initDone(qint32)), this, SLOT(onInitDone(qint32)));
|
||||
m_lpKodiLibrary->start();
|
||||
m_lpKodiLibrary = new cKodiLibrary(ui->m_lpStatusBar, QDir::homePath() + QDir::separator() + QString(".kodi"));
|
||||
m_lpKodiLibrary->init();
|
||||
}
|
||||
|
||||
void cMainWindow::onInitDone(qint32 iMovieCount)
|
||||
{
|
||||
iMovieCount = 0;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ public:
|
||||
~cMainWindow();
|
||||
|
||||
private slots:
|
||||
void onInitDone(qint32 iMovieCount);
|
||||
|
||||
private:
|
||||
Ui::cMainWindow* ui;
|
||||
@@ -37,19 +36,6 @@ private:
|
||||
cMusicVideosWidget* m_lpMusicVideoWidget;
|
||||
cKodiLibrary* m_lpKodiLibrary;
|
||||
|
||||
QString m_szPath;
|
||||
QString m_szAddons;
|
||||
QString m_szADSP;
|
||||
QString m_szEpg;
|
||||
QString m_szMyMusic;
|
||||
QString m_szMyVideos;
|
||||
QString m_szTextures;
|
||||
QString m_szTV;
|
||||
QString m_szViewModes;
|
||||
|
||||
QSqlDatabase m_dbVideos;
|
||||
|
||||
QString findFile(const QString& szPath, const QString& szFile);
|
||||
void initUI();
|
||||
void initDB();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user