summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2016-11-11 04:53:00 +0100
committerArno <arno@disconnect.de>2016-11-11 04:53:00 +0100
commitf686dd4c13215bb02e456456e512daed076028a7 (patch)
treeb9095c6d037856e610e189f87acaeebbbfbee2e9
parentce0d37ac854cb7102f0476e837b252cb0c127876 (diff)
downloadSheMov-f686dd4c13215bb02e456456e512daed076028a7.tar.gz
SheMov-f686dd4c13215bb02e456456e512daed076028a7.tar.bz2
SheMov-f686dd4c13215bb02e456456e512daed076028a7.zip
Energize!
Fill the random file view with movies.
-rw-r--r--randomtab.cpp170
-rw-r--r--randomtab.h8
2 files changed, 172 insertions, 6 deletions
diff --git a/randomtab.cpp b/randomtab.cpp
index 52f612b..036e482 100644
--- a/randomtab.cpp
+++ b/randomtab.cpp
@@ -17,26 +17,32 @@
#include <QSplitter>
#include <QStandardItemModel>
#include <QStandardItem>
+#include <QModelIndex>
#include <QTreeView>
#include <QSortFilterProxyModel>
#include <QSqlQuery>
#include <QDateTime>
#include <QFont>
+#include <QStringList>
+#include <QSettings>
+#include <QDirIterator>
+
+#include <algorithm>
+#include <random>
#include "randomtab.h"
+#include "helper.h"
RandomTab::RandomTab(QWidget *parent) : QWidget(parent) {
mDb = QSqlDatabase::database("treedb");
- mGenreModel = new QStandardItemModel(this);
- mActorModel = new QStandardItemModel(this);
-
- // setupModels is logging, so...
mLog = new QTextEdit;
mLog->setFont(QFont("courier new", -1 , QFont::Bold));
-
+ mGenreModel = new QStandardItemModel(this);
+ mActorModel = new QStandardItemModel(this);
setupModels();
setupGui();
clearAll();
+ mValidDvds = validDvdNos();
}
void RandomTab::setupGui(){
@@ -56,6 +62,7 @@ void RandomTab::setupGui(){
mGenre2->setModel(mGenreModel);
mGenre3 = new QComboBox;
mGenre3->setModel(mGenreModel);
+ mGenreBoxes << mGenre1 << mGenre2 << mGenre3;
QVBoxLayout *genreL = new QVBoxLayout;
genreL->addWidget(mGenre1);
genreL->addWidget(mGenre2);
@@ -69,6 +76,7 @@ void RandomTab::setupGui(){
mActor2->setModel(mActorModel);
mActor3 = new QComboBox;
mActor3->setModel(mActorModel);
+ mActorBoxes << mActor1 << mActor2 << mActor3;
QVBoxLayout *actorL = new QVBoxLayout;
actorL->addWidget(mActor1);
actorL->addWidget(mActor2);
@@ -98,6 +106,8 @@ void RandomTab::setupGui(){
leftWidget->setLayout(lwL);
mFileView = new QTreeView;
+ mFileView->setAlternatingRowColors(true);
+ mFileView->setRootIsDecorated(false);
mFileModel = new QStandardItemModel;
mFileProxy = new QSortFilterProxyModel;
mFileProxy->setSourceModel(mFileModel);
@@ -123,6 +133,24 @@ void RandomTab::setupGui(){
setLayout(mainLayout);
}
+QStringList RandomTab::validDvdNos(){
+ QStringList retval;
+ QSettings s;
+ QString usbDir = s.value("paths/usb").toString();
+ logMessage(QString(tr("Traversing %1")).arg(usbDir));
+ QDirIterator it(usbDir);
+ while(it.hasNext()){
+ it.next();
+ QString next = it.fileName();
+ if(next.startsWith("DVD_")){
+ QString no = QString(next.right(3));
+ retval << no;
+ }
+ }
+ logMessage(QString(tr("Found %1 valid Dirs: (%2)")).arg(QString::number(retval.count())).arg(retval.join(',')));
+ return retval;
+}
+
void RandomTab::setupModels(){
// Genres
mGenreModel->clear();
@@ -162,6 +190,7 @@ void RandomTab::setupModels(){
}
void RandomTab::clearAll(){
+ logMessage(tr("Clearing Selection!"));
mGenre1->setCurrentIndex(0);
mGenre2->setCurrentIndex(0);
mGenre3->setCurrentIndex(0);
@@ -176,7 +205,138 @@ void RandomTab::refreshComboboxes(){
}
void RandomTab::select(){
+ logMessage(tr("Selecting..."));
+
+ // Genres
+ QStringList genreIds;
+ foreach(QComboBox *c, mGenreBoxes){
+ int curId = c->currentData(IdRole).toInt();
+ if(curId != -1){
+ genreIds << QString::number(curId);
+ }
+ }
+ QVector<int> gIds;
+ QString gids = genreIds.join(',');
+ logMessage(QString(tr("Genres: (%1)")).arg(gids));
+ QString genreQString = QString("SELECT ifiles_id FROM files WHERE iseriespart_id IN (SELECT distinct(iseriesparts_id) FROM seriesparts_genremap WHERE igenres_id IN (%1)) AND sifiletype = 1 AND (idvd = -1 OR idvd IN (%2))").arg(gids).arg(mValidDvds.join(','));
+ logMessage(genreQString);
+ QSqlQuery gQ(genreQString, mDb);
+ while(gQ.next()){
+ gIds << gQ.value(0).toInt();
+ }
+ logMessage(QString(tr("Selected %1 Genre files")).arg(QString::number(gIds.count())));
+ // Actors
+ QStringList actorIds;
+ foreach(QComboBox *c, mActorBoxes){
+ int curId = c->currentData(IdRole).toInt();
+ if(curId != -1){
+ actorIds << QString::number(curId);
+ }
+ }
+ QVector<int> aIds;
+ QString aids = actorIds.join(',');
+ logMessage(QString(tr("Actors: (%1)")).arg(aids));
+ QString actorQString = QString("SELECT ifiles_id FROM files WHERE iseriespart_id IN (SELECT distinct(iseriesparts_id) FROM seriesparts_actormap WHERE iactors_id IN (%1)) AND sifiletype = 1 AND (idvd = -1 OR idvd IN (%2))").arg(aids).arg(mValidDvds.join(','));
+ logMessage(actorQString);
+ QSqlQuery aQ(actorQString, mDb);
+ while(aQ.next()){
+ aIds << aQ.value(0).toInt();
+ }
+ logMessage(QString(tr("Selected %1 Actor files")).arg(QString::number(aIds.count())));
+
+ // Join!
+ QVector<int> finalIds;
+ if(!aIds.isEmpty() && !gIds.isEmpty()){
+ logMessage(tr("Intersecting..."));
+ std::sort(aIds.begin(), aIds.end());
+ std::sort(gIds.begin(), gIds.end());
+ QVector<int> intersection;
+ std::set_intersection(aIds.begin(), aIds.end(), gIds.begin(), gIds.end(), std::back_inserter(intersection));
+ logMessage(QString(tr("Joined to %1 ids")).arg(QString::number(intersection.count())));
+ finalIds = intersection;
+ }else if(aIds.count() > 0){
+ logMessage(tr("Using Actors"));
+ finalIds = aIds;
+ }else if(gIds.count() > 0){
+ logMessage(tr("Using Genres"));
+ finalIds = gIds;
+ }
+
+ std::random_device rd;
+ std::mt19937 g(rd());
+ std::shuffle(finalIds.begin(), finalIds.end(), g);
+
+ QSqlQuery randomFilesQ(mDb);
+ randomFilesQ.prepare("SELECT tfilename, bisize, iduration, cmd5sum, idvd FROM files WHERE ifiles_id = :id");
+ QSqlQuery otherQ(mDb);
+ otherQ.prepare("SELECT iseriespart, tsubtitle, tseries_name FROM seriesparts, series, files WHERE files.ifiles_id = :fid AND files.iseriespart_id = seriesparts.iseriesparts_id AND seriesparts.iseries_id = series.iseries_id");
+
+ int selCount = mNumber->text().toInt();
+ int count = selCount;
+ if(finalIds.count() < selCount){
+ count = finalIds.count();;
+ }
+ logMessage(QString(tr("Count is %1 out of %2")).arg(QString::number(count)).arg(QString::number(finalIds.count())));
+
+ mFileModel->clear();
+ mFileModel->setHorizontalHeaderLabels(QStringList() << tr("Filename") << tr("Size (MB)") << tr("Dur.") << tr("MD5") << tr("LOC") << tr("Full Path"));
+ QLocale l;
+ QStandardItem *fRootItem = mFileModel->invisibleRootItem();
+
+ logMessage(tr("Filling View..."));
+ for(int i = 0; i < count; ++i){
+ QList<QStandardItem*> fData;
+ randomFilesQ.bindValue(":id", finalIds.at(i));
+ randomFilesQ.exec();
+ while(randomFilesQ.next()){
+ for(int i = 0; i < ColumnCount; ++i){
+ QStandardItem *item = new QStandardItem;
+ item->setFont(QFont("courier new", -1, QFont::Bold));
+ fData << item;
+ }
+ fData[0]->setText(randomFilesQ.value(0).toString());
+ fData[0]->setIcon(QIcon(":/huge_bra.png"));
+ fData[1]->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ qint64 dbSize = randomFilesQ.value(1).toLongLong();
+ float mbSize = dbSize / 1024.0 / 1024.0;
+ QString sizeStr = QString("%1").arg(mbSize, 0, 'f', 2);
+ fData[1]->setText(sizeStr);
+ fData[1]->setData(dbSize, SizeRole);
+ qint64 durSecs = randomFilesQ.value(2).toLongLong();
+ Helper::Duration dur(durSecs);
+ fData[2]->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ fData[2]->setText(dur.toString());
+ fData[2]->setData(durSecs, DurationRole);
+ fData[3]->setText(randomFilesQ.value(3).toString());
+ fData[4]->setText(l.toString(randomFilesQ.value(4).toInt()));
+ int dvdno = randomFilesQ.value(4).toInt();
+ if(dvdno == -1){
+ fData[4]->setText(tr("ARC"));
+ }else{
+ fData[4]->setText(tr("USB"));
+ }
+ QString fullPath;
+ if(randomFilesQ.value(4).toInt() < 0){
+ fullPath = Helper::createArchivePath(randomFilesQ.value(0).toString(), randomFilesQ.value(3).toString());
+ }else{
+ otherQ.bindValue(":fid", finalIds.at(i));
+ otherQ.exec();
+ while(otherQ.next()){
+ int seriesPart = otherQ.value(0).toInt();
+ QString subTitle = otherQ.value(1).toString();
+ QString seriesName = otherQ.value(2).toString();
+ fullPath = Helper::createUSBPath(randomFilesQ.value(0).toString(), seriesName, subTitle, randomFilesQ.value(4).toInt(), seriesPart);
+ }
+ }
+ fData[5]->setText(fullPath);
+ }
+ fRootItem->appendRow(fData);
+ }
+ logMessage(tr("Filling View -> Done!"));
+ for(int i = ColumnCount - 1; i >= 0; --i){
+ mFileView->resizeColumnToContents(i);
+ }
}
void RandomTab::logMessage(const QString &msg){
diff --git a/randomtab.h b/randomtab.h
index ccec1d6..12d98c2 100644
--- a/randomtab.h
+++ b/randomtab.h
@@ -10,6 +10,7 @@
#include <QWidget>
#include <QSqlDatabase>
+#include <QVector>
class QComboBox;
class QPushButton;
@@ -22,7 +23,8 @@ class QTextEdit;
class RandomTab : public QWidget {
Q_OBJECT
public:
- enum CustomRoles { IdRole = Qt::UserRole + 1 };
+ enum CustomRoles { IdRole = Qt::UserRole + 1, SizeRole = Qt::UserRole + 2, DurationRole = Qt::UserRole + 3, DvdNoRole = Qt::UserRole + 4 };
+ enum { ColumnCount = 6 };
explicit RandomTab(QWidget *parent = 0);
public slots:
@@ -34,12 +36,15 @@ class RandomTab : public QWidget {
private:
void setupGui();
+ QStringList validDvdNos();
QComboBox *mGenre1;
QComboBox *mGenre2;
QComboBox *mGenre3;
+ QVector<QComboBox*> mGenreBoxes;
QComboBox *mActor1;
QComboBox *mActor2;
QComboBox *mActor3;
+ QVector<QComboBox*> mActorBoxes;
QLineEdit *mNumber;
QPushButton *mSelect;
QPushButton *mClear;
@@ -51,6 +56,7 @@ class RandomTab : public QWidget {
QStandardItemModel *mActorModel;
QSortFilterProxyModel *mFileProxy;
QSqlDatabase mDb;
+ QStringList mValidDvds;
};
#endif // RANDOMTAB_H