.
This commit is contained in:
+336
-11
@@ -1,10 +1,17 @@
|
||||
#include <QSettings>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include "cmainwindow.h"
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
#include "cmediainfo.h"
|
||||
|
||||
#include "cmusicviewitemdelegate.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <QTime>
|
||||
|
||||
|
||||
@@ -49,8 +56,13 @@ void cMainWindow::addPath(const QString& szPath)
|
||||
|
||||
cMainWindow::cMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::cMainWindow)
|
||||
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)
|
||||
@@ -58,20 +70,39 @@ cMainWindow::cMainWindow(QWidget *parent) :
|
||||
|
||||
m_lpDB = new cDatabase(this);
|
||||
|
||||
QTime t;
|
||||
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)));
|
||||
|
||||
// bool bRet;
|
||||
// bRet = lpDatabase->getDB().transaction();
|
||||
t.start();
|
||||
addPath("C:/Users/vet0572/Music");
|
||||
qDebug() << t.elapsed();
|
||||
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("C:/Users/vet0572/Music");
|
||||
// addPath("C:/Users/birkeh/Music");
|
||||
// bRet = lpDatabase->getDB().commit();
|
||||
|
||||
// addFile("C:/Users/vet0572/Music/Amy MacDonald/Under Stars (Deluxe)/01 - Dream On.mp3");
|
||||
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
cMainWindow::~cMainWindow()
|
||||
@@ -92,3 +123,297 @@ void cMainWindow::initSettings()
|
||||
|
||||
dir.mkdir(settings.value("application/data").toString());
|
||||
}
|
||||
|
||||
void cMainWindow::loadDB()
|
||||
{
|
||||
QSqlQuery query;
|
||||
QString szOldLeadArtist = "";
|
||||
QString szOldAlbum = "";
|
||||
QString szAlbum;
|
||||
QString szTitle;
|
||||
qint16 iTrackNumber;
|
||||
qint16 iPartOfSet;
|
||||
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();
|
||||
iPartOfSet = query.value("partOfSet").toInt();
|
||||
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;
|
||||
|
||||
cAlbum* lpAlbum = m_albumList.add(szAlbum, szLeadArtist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = "";
|
||||
QString szOldAlbum = "";
|
||||
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);
|
||||
}
|
||||
|
||||
QList<QStandardItem*> lpTrackItem;
|
||||
lpTrackItem.append(new QStandardItem("track 1"));
|
||||
lpTrackItem.append(new QStandardItem("track 1"));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user