diff options
author | Arno <am@disconnect.de> | 2011-05-14 08:54:07 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2011-05-14 08:54:07 +0200 |
commit | 189dbc38b5a4495553303a705e54eb1c95bc8e52 (patch) | |
tree | 288610c9ce660a5089cb3fccca439e90b1cccce5 | |
parent | 5ca7f74c5b66cb9496f8a6aa4ecbb1f687247995 (diff) | |
download | SheMov-189dbc38b5a4495553303a705e54eb1c95bc8e52.tar.gz SheMov-189dbc38b5a4495553303a705e54eb1c95bc8e52.tar.bz2 SheMov-189dbc38b5a4495553303a705e54eb1c95bc8e52.zip |
Fix adding movies with subtitles
When a movie has a subtitle, use a negative seriespart as id. I
guess this will haunt me at some point, but for now it works. Added
a sequence to the database layout for that.
-rw-r--r-- | newmoviewizard.cpp | 34 | ||||
-rw-r--r-- | seriestreemodel.cpp | 10 |
2 files changed, 30 insertions, 14 deletions
diff --git a/newmoviewizard.cpp b/newmoviewizard.cpp index 44897b4..e479a33 100644 --- a/newmoviewizard.cpp +++ b/newmoviewizard.cpp @@ -58,6 +58,7 @@ void NewMovieWizard::accept(){ //handle series QString series = field("title").toString(); + bool hasPartNo = field("hasPartNo").toBool(); series = series.toLower().trimmed(); QModelIndex seriesIdx = seriesModel->find(series); if(!seriesIdx.isValid()){ @@ -70,25 +71,24 @@ void NewMovieWizard::accept(){ } //handle seriespart - int seriesno = field("seriesNo").toInt(); - bool hasPartNo = field("hasPartNo").toBool(); - if(!hasPartNo){ - seriesno = 0; - } + QModelIndex seriesPartIdx; QString subTitle = field("subtitle").toString(); - QModelIndex seriesPartIdx = seriesModel->find(seriesno, SeriesTreeModel::SeriesPart, seriesIdx); + int seriesno = 0; + if(hasPartNo){ + seriesno = field("seriesNo").toInt(); + seriesPartIdx = seriesModel->find(seriesno, SeriesTreeModel::SeriesPart, seriesIdx); + }else{ + seriesPartIdx = seriesModel->find(subTitle, SeriesTreeModel::Subtitle, seriesIdx); + } if(seriesPartIdx.isValid()){ if(hasPartNo){ QString error = QString(tr("Already have part %1 of %2")).arg(seriesno).arg(series); QMessageBox::critical(this, tr("Error"), error); return; }else{ - QString curSubTitle = seriesPartIdx.data(SeriesTreeModel::SubtitleRole).toString(); - if(curSubTitle == subTitle){ - QString error = QString(tr("Already have a part with subtitle %1")).arg(curSubTitle); - QMessageBox::critical(this, tr("Error"), error); - return; - } + QString error = QString(tr("Already have a part with subtitle %1")).arg(seriesPartIdx.data(SeriesTreeModel::SubtitleRole).toString()); + QMessageBox::critical(this, tr("Error"), error); + return; } } @@ -96,7 +96,15 @@ void NewMovieWizard::accept(){ QMessageBox::critical(this, tr("Error"), tr("Failed to create series part!")); return; } - seriesPartIdx = seriesModel->find(seriesno, SeriesTreeModel::SeriesPart, seriesIdx); + if(hasPartNo){ + seriesPartIdx = seriesModel->find(seriesno, SeriesTreeModel::SeriesPart, seriesIdx); + }else{ + seriesPartIdx = seriesModel->find(subTitle, SeriesTreeModel::Subtitle, seriesIdx); + } + if(!seriesPartIdx.isValid()){ + QMessageBox::critical(this, tr("Error"), tr("Strange. Could not find series part! Cowardly bailing out.")); + return; + } int seriesPartId = seriesPartIdx.data(SeriesTreeModel::SeriesPartIdRole).toInt(); //handle files diff --git a/seriestreemodel.cpp b/seriestreemodel.cpp index f18ef4d..c091576 100644 --- a/seriestreemodel.cpp +++ b/seriestreemodel.cpp @@ -344,7 +344,15 @@ bool SeriesTreeModel::addSeriesPart(int seriesPart, const QModelIndex &parent, c } int seriesId = parent.data(SeriesIdRole).toInt(); mDb.transaction(); - mSeriesPartInsertQuery->bindValue(":part", seriesPart); + if(seriesPart > 0){ + mSeriesPartInsertQuery->bindValue(":part", seriesPart); + }else{ + QSqlQuery nextNegValQuery("SELECT nextval('seriesparts_iseriespart__seq')", mDb); + if(nextNegValQuery.next()){ + seriesPart = nextNegValQuery.value(0).toInt(); + mSeriesPartInsertQuery->bindValue(":part", seriesPart); + } + } mSeriesPartInsertQuery->bindValue(":id", seriesId); mSeriesPartInsertQuery->bindValue(":subtitle", subTitle.toLower()); if(mSeriesPartInsertQuery->exec()){ |