+ if (parent.isValid())
+ return false; // This is a flat model
+ if (rowCount() < row)
+ row = rowCount() + 1;
+ int supId = -1;
+ QSqlQuery q;
+ q.exec(QString("SELECT setup.id, "
+ // The following is to get the correct order:
+ "platform.name || ' ' || mediatype.name AS SetupName "
+ "FROM setup "
+ "INNER JOIN platform ON setup.platformid=platform.id "
+ "INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
+ "ORDER BY SetupName "
+ "LIMIT 1"));
+ if (q.first()) {
+ supId = q.value(0).toInt();
+ qDebug() << "Got id " << supId << " for default setup.";
+ }
+ else {
+ throw EmuFrontException(tr("No setups yet available for file path configuration!"));
+ }
+ q.prepare(QString("INSERT INTO filepath "
+ "(id, name, filetypeid, setupid, lastscanned) "
+ "VALUES (NULL, '', :filetype, :setupid, :lastscanned )"));
+ beginInsertRows(QModelIndex(), row, row + count - 1);
+ for(int i = 0; i < count; ++i) {
+ q.bindValue(":filetype", EmuFrontFile::FileType_MediaImage);
+ q.bindValue(":setupid", supId);
+ q.bindValue(":lastscanned", 0);
+ if (!q.exec()) {
+ throw EmuFrontException(tr("Failed creating new filepath row: %1").
+ arg(q.lastError().text()));
+ }
+ }
+ endInsertRows();
+ refresh();
+ return true;