You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
434 lines
12 KiB
C++
434 lines
12 KiB
C++
#include <QSettings>
|
|
|
|
#include "common.h"
|
|
|
|
#include "cmainwindow.h"
|
|
#include "ui_cmainwindow.h"
|
|
|
|
#include "cmediainfo.h"
|
|
|
|
#include "cmusicviewitemdelegate.h"
|
|
|
|
#include <QStringList>
|
|
#include <QScrollBar>
|
|
|
|
#include <QTime>
|
|
|
|
|
|
void cMainWindow::addFile(const QString& szFile)
|
|
{
|
|
if(szFile.isEmpty())
|
|
return;
|
|
qDebug() << szFile;
|
|
|
|
cMediaInfo* lpMediaInfo = new cMediaInfo;
|
|
lpMediaInfo->readFromFile(szFile);
|
|
|
|
if(lpMediaInfo->isValid())
|
|
{
|
|
m_lpDB->getDB().transaction();
|
|
lpMediaInfo->writeToDB();
|
|
m_lpDB->getDB().commit();
|
|
}
|
|
|
|
delete lpMediaInfo;
|
|
}
|
|
|
|
void cMainWindow::addPath(const QString& szPath)
|
|
{
|
|
QDir Dir(szPath);
|
|
QStringList Dirs = Dir.entryList(QDir::Dirs);
|
|
QStringList Files = Dir.entryList(QDir::Files);
|
|
int z;
|
|
|
|
if(!Files.isEmpty())
|
|
{
|
|
for(z = 0;z < Files.count();z++)
|
|
addFile(szPath + QString("/") + Files.at(z));
|
|
}
|
|
|
|
Dirs.removeAll(".");
|
|
Dirs.removeAll((".."));
|
|
|
|
if(!Dirs.isEmpty())
|
|
{
|
|
for(z = 0;z < Dirs.count();z++)
|
|
addPath(szPath + QString("/") + Dirs.at(z));
|
|
}
|
|
}
|
|
|
|
cMainWindow::cMainWindow(QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::cMainWindow),
|
|
m_lpDB(0),
|
|
m_lpMusicListModel(0),
|
|
m_bProcessing(false)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
QSettings settings;
|
|
|
|
if(settings.value("application/version", QVariant(0.0)).toDouble() == 0.0)
|
|
initSettings();
|
|
|
|
m_lpDB = new cDatabase(this);
|
|
|
|
m_lpMusicListModel = new QStandardItemModel(0, 3);
|
|
ui->m_lpMusicListOriginal->setModel(m_lpMusicListModel);
|
|
ui->m_lpMusicListOriginal->setItemDelegate(new cMusicViewItemDelegate(ui->m_lpMusicListOriginal));
|
|
ui->m_lpMusicListNew->setModel(m_lpMusicListModel);
|
|
ui->m_lpMusicListNew->setItemDelegate(new cMusicViewItemDelegate(ui->m_lpMusicListNew));
|
|
|
|
connect(ui->m_lpMusicListOriginal, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequestedOriginal(QPoint)));
|
|
connect(ui->m_lpMusicListNew, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomContextMenuRequestedNew(QPoint)));
|
|
|
|
connect(ui->m_lpMusicListOriginal, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClickedOriginal(QModelIndex)));
|
|
connect(ui->m_lpMusicListNew, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onDoubleClickedNew(QModelIndex)));
|
|
|
|
connect(ui->m_lpMusicListOriginal, SIGNAL(pressed(QModelIndex)), this, SLOT(onPressedOriginal(QModelIndex)));
|
|
connect(ui->m_lpMusicListNew, SIGNAL(pressed(QModelIndex)), this, SLOT(onPressedNew(QModelIndex)));
|
|
|
|
connect(ui->m_lpMusicListOriginal, SIGNAL(expanded(QModelIndex)), this, SLOT(onExpandedOriginal(QModelIndex)));
|
|
connect(ui->m_lpMusicListNew, SIGNAL(expanded(QModelIndex)), this, SLOT(onExpandedNew(QModelIndex)));
|
|
|
|
connect(ui->m_lpMusicListOriginal, SIGNAL(collapsed(QModelIndex)), this, SLOT(onCollapsedOriginal(QModelIndex)));
|
|
connect(ui->m_lpMusicListNew, SIGNAL(collapsed(QModelIndex)), this, SLOT(onCollapsedNew(QModelIndex)));
|
|
|
|
connect(ui->m_lpMusicListOriginal->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onSelectionChangedOriginal);
|
|
connect(ui->m_lpMusicListNew->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onSelectionChangedNew);
|
|
|
|
connect(ui->m_lpMusicListOriginal->verticalScrollBar(), &QScrollBar::valueChanged, this, &cMainWindow::onScrollbarValueChangedOriginal);
|
|
connect(ui->m_lpMusicListNew->verticalScrollBar(), &QScrollBar::valueChanged, this, &cMainWindow::onScrollbarValueChangedNew);
|
|
|
|
loadDB();
|
|
displayDB();
|
|
|
|
// addPath("/data/Music");
|
|
// addPath("C:/Users/vet0572/Music");
|
|
// addPath("C:/Temp/Musik");
|
|
// addPath("C:/Users/birkeh/Music");
|
|
// addFile("C:/Users/vet0572/Music/Amy MacDonald/Life In A Beautiful Light/CD1/Amy Macdonald - Life In A Beautiful Light - 18 - Slow It Down (Singalong Instrumental Version).mp3");
|
|
}
|
|
|
|
cMainWindow::~cMainWindow()
|
|
{
|
|
delete m_lpDB;
|
|
delete ui;
|
|
}
|
|
|
|
void cMainWindow::initSettings()
|
|
{
|
|
QSettings settings;
|
|
QDir dir;
|
|
|
|
settings.setValue("application/version", QVariant(0.1));
|
|
settings.setValue("application/data", QDir::homePath()+QDir::separator()+".qtjukebox");
|
|
settings.setValue("database/type", "SQLITE");
|
|
settings.setValue("database/database", "qtjukebox.db");
|
|
|
|
dir.mkdir(settings.value("application/data").toString());
|
|
}
|
|
|
|
void cMainWindow::loadDB()
|
|
{
|
|
QSqlQuery query;
|
|
QString szOldLeadArtist = "";
|
|
QString szOldAlbum = "";
|
|
QString szAlbum;
|
|
QString szTitle;
|
|
qint16 iTrackNumber;
|
|
QString szPartOfSet;
|
|
QString szLeadArtist;
|
|
QString szBand;
|
|
QString szComposer;
|
|
QDate recordingTime;
|
|
|
|
cAlbum* lpAlbum = 0;
|
|
|
|
query.prepare("SELECT leadArtist, album, title, trackNumber, partOfSet, band, composer, recordingTime FROM file ORDER BY leadArtist, album, trackNumber;");
|
|
if(!query.exec())
|
|
{
|
|
myDebug << query.lastError().text();
|
|
return;
|
|
}
|
|
|
|
while(query.next())
|
|
{
|
|
szAlbum = query.value("album").toString();
|
|
szTitle = query.value("title").toString();
|
|
iTrackNumber = query.value("trackNumber").toInt();
|
|
szPartOfSet = query.value("partOfSet").toString();
|
|
szLeadArtist = query.value("leadArtist").toString();
|
|
szBand = query.value("band").toString();
|
|
szComposer = query.value("composer").toString();
|
|
recordingTime = query.value("recordingTime").toDate();
|
|
|
|
if(szOldLeadArtist != szLeadArtist || szOldAlbum != szAlbum)
|
|
{
|
|
szOldLeadArtist = szLeadArtist;
|
|
szOldAlbum = szAlbum;
|
|
|
|
lpAlbum = m_albumList.add(szAlbum, szLeadArtist);
|
|
}
|
|
|
|
if(lpAlbum)
|
|
lpAlbum->addTrack(szTitle, iTrackNumber, szPartOfSet, szBand, szComposer, recordingTime);
|
|
}
|
|
}
|
|
|
|
void cMainWindow::displayDB()
|
|
{
|
|
m_lpMusicListModel->clear();
|
|
|
|
QStringList header;
|
|
header << "Original" << "New";
|
|
|
|
m_lpMusicListModel->setHorizontalHeaderLabels(header);
|
|
|
|
ui->m_lpMusicListOriginal->setColumnHidden(1, true);
|
|
ui->m_lpMusicListNew->setColumnHidden(0, true);
|
|
|
|
QString szOldLeadArtist = "OldLeadArtist";
|
|
QString szOldAlbum = "OldAlbum";
|
|
QList<QStandardItem*> lpLeadArtistItem;
|
|
QList<QStandardItem*> lpAlbumItem;
|
|
|
|
for(int x = 0;x < m_albumList.count();x++)
|
|
{
|
|
cAlbum* lpAlbum = m_albumList.at(x);
|
|
|
|
if(szOldLeadArtist != lpAlbum->leadArtist())
|
|
{
|
|
|
|
szOldLeadArtist = lpAlbum->leadArtist();
|
|
szOldAlbum = "";
|
|
|
|
lpLeadArtistItem.clear();
|
|
lpLeadArtistItem.append(new QStandardItem(szOldLeadArtist));
|
|
lpLeadArtistItem.append(new QStandardItem(szOldLeadArtist));
|
|
|
|
m_lpMusicListModel->appendRow(lpLeadArtistItem);
|
|
}
|
|
|
|
if(szOldAlbum != lpAlbum->album())
|
|
{
|
|
szOldAlbum = lpAlbum->album();
|
|
|
|
lpAlbumItem.clear();
|
|
lpAlbumItem.append(new QStandardItem(szOldAlbum));
|
|
lpAlbumItem.at(0)->setData(QVariant::fromValue(lpAlbum), Qt::UserRole+MUSICLIST_ORI_ALBUM);
|
|
lpAlbumItem.append(new QStandardItem(szOldAlbum));
|
|
|
|
lpLeadArtistItem.at(0)->appendRow(lpAlbumItem);
|
|
}
|
|
|
|
cTrackList trackList = lpAlbum->trackList();
|
|
for(int y = 0;y < trackList.count();y++)
|
|
{
|
|
cTrack* lpTrack = trackList.at(y);
|
|
|
|
QList<QStandardItem*> lpTrackItem;
|
|
lpTrackItem.append(new QStandardItem(lpTrack->title()));
|
|
lpTrackItem.append(new QStandardItem(lpTrack->title()));
|
|
lpAlbumItem.at(0)->appendRow(lpTrackItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
void cMainWindow::onCustomContextMenuRequestedOriginal(const QPoint &pos)
|
|
{
|
|
onCustomContextMenuRequested(ui->m_lpMusicListOriginal, pos);
|
|
}
|
|
|
|
void cMainWindow::onDoubleClickedOriginal(const QModelIndex &index)
|
|
{
|
|
onDoubleClicked(index);
|
|
}
|
|
|
|
void cMainWindow::onPressedOriginal(const QModelIndex &index)
|
|
{
|
|
onPressed(index);
|
|
}
|
|
|
|
void cMainWindow::onExpandedOriginal(const QModelIndex &index)
|
|
{
|
|
ui->m_lpMusicListNew->expand(index);
|
|
}
|
|
|
|
void cMainWindow::onCollapsedOriginal(const QModelIndex &index)
|
|
{
|
|
ui->m_lpMusicListNew->collapse(index);
|
|
}
|
|
|
|
void cMainWindow::onSelectionChangedOriginal(const QItemSelection &selected, const QItemSelection &deselected)
|
|
{
|
|
if(m_bProcessing)
|
|
return;
|
|
|
|
m_bProcessing = true;
|
|
|
|
QItemSelectionModel* lpOriginal = ui->m_lpMusicListOriginal->selectionModel();
|
|
QItemSelectionModel* lpNew = ui->m_lpMusicListNew->selectionModel();
|
|
QModelIndexList selected1 = lpOriginal->selectedIndexes();
|
|
|
|
lpNew->clearSelection();
|
|
|
|
for(int z = 0;z < selected1.count();z++)
|
|
{
|
|
|
|
QStandardItem* lpItem = m_lpMusicListModel->itemFromIndex(selected1.at(z));
|
|
QModelIndex index = lpItem->index();
|
|
lpNew->select(index, QItemSelectionModel::Select);
|
|
}
|
|
|
|
m_bProcessing = false;
|
|
}
|
|
|
|
void cMainWindow::onScrollbarValueChangedOriginal(int value)
|
|
{
|
|
if(m_bProcessing)
|
|
return;
|
|
|
|
m_bProcessing = true;
|
|
|
|
ui->m_lpMusicListNew->verticalScrollBar()->setValue(value);
|
|
|
|
m_bProcessing = false;
|
|
}
|
|
|
|
void cMainWindow::onCustomContextMenuRequestedNew(const QPoint &pos)
|
|
{
|
|
onCustomContextMenuRequested(ui->m_lpMusicListNew, pos);
|
|
}
|
|
|
|
void cMainWindow::onDoubleClickedNew(const QModelIndex &index)
|
|
{
|
|
onDoubleClicked(index);
|
|
}
|
|
|
|
void cMainWindow::onPressedNew(const QModelIndex &index)
|
|
{
|
|
onPressed(index);
|
|
}
|
|
|
|
void cMainWindow::onExpandedNew(const QModelIndex &index)
|
|
{
|
|
ui->m_lpMusicListOriginal->expand(index);
|
|
}
|
|
|
|
void cMainWindow::onCollapsedNew(const QModelIndex &index)
|
|
{
|
|
ui->m_lpMusicListOriginal->collapse(index);
|
|
}
|
|
|
|
void cMainWindow::onSelectionChangedNew(const QItemSelection &selected, const QItemSelection &deselected)
|
|
{
|
|
if(m_bProcessing)
|
|
return;
|
|
|
|
m_bProcessing = true;
|
|
|
|
QItemSelectionModel* lpOriginal = ui->m_lpMusicListOriginal->selectionModel();
|
|
QItemSelectionModel* lpNew = ui->m_lpMusicListNew->selectionModel();
|
|
QModelIndexList selected2 = lpNew->selectedIndexes();
|
|
|
|
lpOriginal->clearSelection();
|
|
|
|
for(int z = 0;z < selected2.count();z++)
|
|
{
|
|
QStandardItem* lpItem = m_lpMusicListModel->itemFromIndex(selected2.at(z));
|
|
QModelIndex index = lpItem->index();
|
|
lpOriginal->select(index, QItemSelectionModel::Select);
|
|
}
|
|
|
|
m_bProcessing = false;
|
|
}
|
|
|
|
void cMainWindow::onScrollbarValueChangedNew(int value)
|
|
{
|
|
if(m_bProcessing)
|
|
return;
|
|
|
|
m_bProcessing = true;
|
|
|
|
ui->m_lpMusicListOriginal->verticalScrollBar()->setValue(value);
|
|
|
|
m_bProcessing = false;
|
|
}
|
|
|
|
void cMainWindow::onCustomContextMenuRequested(const QTreeView* lpTreeView, const QPoint &pos)
|
|
{
|
|
/*
|
|
QMenu* lpMenu = new QMenu(this);
|
|
|
|
lpMenu->addAction("add", this, SLOT(onActionAdd()));
|
|
|
|
lpMenu->addAction("update all", this, SLOT(onActionUpdateAll()));
|
|
lpMenu->addAction("update unfinished", this, SLOT(onActionUpdateUnfinished()));
|
|
lpMenu->addSeparator();
|
|
|
|
if(lpTreeView->selectionModel()->selectedRows().count() == 1)
|
|
{
|
|
cSerie* lpSerie = m_lpSeriesListModel->itemFromIndex(lpTreeView->selectionModel()->selectedRows().at(0))->data(Qt::UserRole).value<cSerie*>();
|
|
if(lpSerie)
|
|
{
|
|
lpMenu->addAction("update", this, SLOT(onActionUpdate()));
|
|
lpMenu->addAction("delete", this, SLOT(onActionDelete()));
|
|
lpMenu->addAction("edit", this, SLOT(onActionEdit()));
|
|
lpMenu->addSeparator();
|
|
|
|
if(!lpSerie->IMDBID().isEmpty())
|
|
lpMenu->addAction("open IMDB", this, SLOT(onActionGotoIMDB()));
|
|
|
|
if(!lpSerie->download().isEmpty())
|
|
{
|
|
lpMenu->addAction("open download link", this, SLOT(onActionGotoDownload()));
|
|
lpMenu->addAction("copy download link", this, SLOT(onActionCopyDownload()));
|
|
}
|
|
lpMenu->addAction("open all download links", this, SLOT(onActionGotoAllDownload()));
|
|
lpMenu->addAction("open all download links (open)", this, SLOT(onActionGotoAllDownloadOpen()));
|
|
lpMenu->addSeparator();
|
|
lpMenu->addAction("load images", this, SLOT(onActionLoadPictures()));
|
|
}
|
|
}
|
|
else if(lpTreeView->selectionModel()->selectedRows().count())
|
|
{
|
|
lpMenu->addAction("update selected", this, SLOT(onActionUpdate()));
|
|
lpMenu->addAction("delete selected", this, SLOT(onActionDelete()));
|
|
lpMenu->addSeparator();
|
|
lpMenu->addAction("load images", this, SLOT(onActionLoadPictures()));
|
|
}
|
|
|
|
lpMenu->addSeparator();
|
|
lpMenu->addAction("export...", this, SLOT(onActionExport()));
|
|
|
|
lpMenu->popup(lpTreeView->viewport()->mapToGlobal(pos));
|
|
*/
|
|
}
|
|
|
|
void cMainWindow::onDoubleClicked(const QModelIndex &index)
|
|
{
|
|
}
|
|
|
|
void cMainWindow::onPressed(const QModelIndex &index)
|
|
{
|
|
switch(QGuiApplication::mouseButtons())
|
|
{
|
|
/*
|
|
case Qt::MiddleButton:
|
|
if(ui->m_lpSeriesList1->selectionModel()->selectedRows().count() == 1)
|
|
{
|
|
cSerie* lpSerie = m_lpSeriesListModel->itemFromIndex(ui->m_lpSeriesList1->selectionModel()->selectedRows().at(0))->data(Qt::UserRole).value<cSerie*>();
|
|
if(lpSerie)
|
|
{
|
|
if(!lpSerie->download().isEmpty())
|
|
onActionGotoDownload();
|
|
}
|
|
}
|
|
break;
|
|
*/
|
|
default:
|
|
break;
|
|
}
|
|
}
|