diff options
author | Arno <arno@disconnect.de> | 2018-04-04 21:42:55 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-04-04 21:42:55 +0200 |
commit | b0768ce9758a349df68fee08cd02f39566d99ec7 (patch) | |
tree | 859780d69c61b78371057a0a56d84b6ca3f11970 | |
parent | 98c75be2b35096dd3f8a6f9f9d710a1eed0a9938 (diff) | |
download | SheMov-b0768ce9758a349df68fee08cd02f39566d99ec7.tar.gz SheMov-b0768ce9758a349df68fee08cd02f39566d99ec7.tar.bz2 SheMov-b0768ce9758a349df68fee08cd02f39566d99ec7.zip |
MoviePropertiesDialog: actually do something
Update database on accpet()
Yes, I know that some code could be shared, but I want to keep it clean.
-rw-r--r-- | moviepropertiesdialog.cpp | 106 | ||||
-rw-r--r-- | moviepropertiesdialog.h | 1 | ||||
-rw-r--r-- | moviewidget.cpp | 5 | ||||
-rw-r--r-- | moviewidget.h | 1 |
4 files changed, 113 insertions, 0 deletions
diff --git a/moviepropertiesdialog.cpp b/moviepropertiesdialog.cpp index 02bd098..2fa68c2 100644 --- a/moviepropertiesdialog.cpp +++ b/moviepropertiesdialog.cpp @@ -96,6 +96,7 @@ void MoviePropertiesDialog::setupDialog(){ viewL->addWidget(actorsGB); viewL->addWidget(genresGB); QPushButton *updatePB = new QPushButton(tr("Update!")); + connect(updatePB, &QPushButton::clicked, this, &MoviePropertiesDialog::accept); QPushButton *cancelPB = new QPushButton(tr("Cancel")); connect(cancelPB, &QPushButton::clicked, this, &MoviePropertiesDialog::reject); QHBoxLayout *buttonLayout = new QHBoxLayout; @@ -111,6 +112,7 @@ void MoviePropertiesDialog::setupDialog(){ } void MoviePropertiesDialog::init(int seriesPartsId){ + mSeriesPartsId = seriesPartsId; QSqlDatabase db = QSqlDatabase::database("treedb"); QSqlQuery genQ(db); genQ.prepare("SELECT series.tseries_name, seriesparts.tsubtitle, seriesparts.iseriespart, metadata.tcomment, metadata.sireleaseyear, metadata.tsourcemedium FROM series, seriesparts, metadata WHERE seriesparts.iseriesparts_id = :id AND seriesparts.iseries_id = series.iseries_id AND metadata.iseriespart_id = seriesparts.iseriesparts_id"); @@ -214,3 +216,107 @@ void MoviePropertiesDialog::removeItem(SmView *view){ view->model()->removeRow(selected.first().row()); } } + +void MoviePropertiesDialog::accept(){ + QSqlDatabase db = QSqlDatabase::database("treedb"); + int seriesId = -1; + if(!mSeriesNameLE->text().isEmpty()){ + QString newSeriesName = mSeriesNameLE->text().toLower(); + QSqlQuery findSnQ(db); + findSnQ.prepare("SELECT iseries_id FROM series WHERE tseries_name = :name"); + findSnQ.bindValue(":name", newSeriesName); + findSnQ.exec(); + while(findSnQ.next()){ + seriesId = findSnQ.value(0).toInt(); + } + if(seriesId == -1){ + QSqlQuery insertSnQ(db); + insertSnQ.prepare("INSERT INTO series (tseries_name) VALUES(:name)"); + insertSnQ.bindValue(":name", newSeriesName); + insertSnQ.exec(); + findSnQ.exec(); + while(findSnQ.next()){ + seriesId = findSnQ.value(0).toInt(); + } + } + } + QSqlQuery updateSpQ(db); + updateSpQ.prepare("UPDATE seriesparts SET iseries_id = :sid, tsubtitle = :sub, iseriespart = :sp WHERE iseriesparts_id = :spid"); + updateSpQ.bindValue(":sid", seriesId); + updateSpQ.bindValue(":sub", mSubtitleLE->text()); + updateSpQ.bindValue(":spid", mSeriesPartsId); + updateSpQ.bindValue(":sp", mSeriesPartLE->text().toInt()); + updateSpQ.exec(); + QString sourceMedium = "torrent"; + if(mUsenetRB->isChecked()){ + sourceMedium = "Usenet"; //for historical reasons it's not lowercased + } + QSqlQuery updateMdQ(db); + updateMdQ.prepare("UPDATE metadata SET sireleaseyear = :ry, tcomment = :c, tsourcemedium = :src WHERE iseriespart_id = :spid"); + updateMdQ.bindValue(":ry", mReleaseYearLE->text().toInt()); + updateMdQ.bindValue(":c", mCommentLE->text()); + updateMdQ.bindValue(":src", sourceMedium); + updateMdQ.bindValue(":spid", mSeriesPartsId); + updateMdQ.exec(); + QSqlQuery clearActorMapQ(db); + clearActorMapQ.prepare("DELETE FROM seriesparts_actormap WHERE iseriesparts_id = :id"); + clearActorMapQ.bindValue(":id", mSeriesPartsId); + clearActorMapQ.exec(); + QSqlQuery insertActorMapQ(db); + insertActorMapQ.prepare("INSERT INTO seriesparts_actormap (iseriesparts_id, iactors_id) VALUES(:spid, :aid)"); + for(int i = 0; i < mActorM->rowCount(); ++i){ + QString curActor = mActorM->item(i)->text(); + int actorId = -1; + QSqlQuery actorQ(db); + actorQ.prepare("SELECT iactors_id FROM actors WHERE tactorname = :name"); + actorQ.bindValue(":name", curActor); + actorQ.exec(); + while(actorQ.next()){ + actorId = actorQ.value(0).toInt(); + } + if(actorId == -1){ + QSqlQuery insertActorQ(db); + insertActorQ.prepare("INSERT INTO actors (tactorname) VALUES(:name)"); + insertActorQ.bindValue(":name", curActor); + insertActorQ.exec(); + actorQ.exec(); + while(actorQ.next()){ + actorId = actorQ.value(0).toInt(); + } + } + insertActorMapQ.bindValue(":spid", mSeriesPartsId); + insertActorMapQ.bindValue(":aid", actorId); + insertActorMapQ.exec(); + } + QSqlQuery clearGenreMapQ(db); + clearGenreMapQ.prepare("DELETE FROM seriesparts_genremap WHERE iseriesparts_id = :id"); + clearGenreMapQ.bindValue(":id", mSeriesPartsId); + clearGenreMapQ.exec(); + QSqlQuery insertGenreMapQ(db); + insertGenreMapQ.prepare("INSERT INTO seriesparts_genremap (iseriesparts_id, igenres_id) VALUES(:spid, :gid)"); + for(int i = 0; i < mGenreM->rowCount(); ++i){ + QString curGenre = mGenreM->item(i)->text(); + int genreId = -1; + QSqlQuery genreQ(db); + genreQ.prepare("SELECT igenres_id FROM genres WHERE tgenrename = :name"); + genreQ.bindValue(":name", curGenre); + genreQ.exec(); + while(genreQ.next()){ + genreId = genreQ.value(0).toInt(); + } + if(genreId == -1){ + QSqlQuery insertGenreQ(db); + insertGenreQ.prepare("INSERT INTO genres (tgenrename) VALUES(:name)"); + insertGenreQ.bindValue(":name", curGenre); + insertGenreQ.exec(); + genreQ.exec(); + while(genreQ.next()){ + genreId = genreQ.value(0).toInt(); + } + } + insertGenreMapQ.bindValue(":spid", mSeriesPartsId); + insertGenreMapQ.bindValue(":gid", genreId); + insertGenreMapQ.exec(); + } + QDialog::accept(); +} diff --git a/moviepropertiesdialog.h b/moviepropertiesdialog.h index 944b4c3..f44c35a 100644 --- a/moviepropertiesdialog.h +++ b/moviepropertiesdialog.h @@ -16,6 +16,7 @@ class MoviePropertiesDialog : public QDialog { public slots: void init(int seriesPartsId); + virtual void accept(); private: void setupDialog(); diff --git a/moviewidget.cpp b/moviewidget.cpp index d3990ca..3978c98 100644 --- a/moviewidget.cpp +++ b/moviewidget.cpp @@ -23,6 +23,7 @@ MovieWidget::MovieWidget(QWidget *parent) : QWidget(parent){ mPropDlg = new MoviePropertiesDialog(this); + connect(mPropDlg, &MoviePropertiesDialog::accepted, this, &MovieWidget::refresh); setPalette(qApp->palette()); setupWidget(); } @@ -142,6 +143,10 @@ void MovieWidget::writeSettings(){ s.setValue("mw/filter", mFilterLE->text()); } +void MovieWidget::refresh(){ + selectBy(mSelectionCB->currentText()); +} + void MovieWidget::selectBy(const QString &selection){ if(selection == "Series"){ populateBySeries(); diff --git a/moviewidget.h b/moviewidget.h index 3a6a795..f3ee593 100644 --- a/moviewidget.h +++ b/moviewidget.h @@ -21,6 +21,7 @@ class MovieWidget : public QWidget { public slots: void readSettings(); void writeSettings(); + void refresh(); private slots: void selectBy(const QString &selection); |