bool ModelManager::storeActiveModel(const QDateTime& changedTime, qint32 sampleRate, const QByteArray& container) { KConfig config( KStandardDirs::locateLocal("appdata", "model/activemodelrc"), KConfig::SimpleConfig ); KConfigGroup cGroup(&config, ""); cGroup.writeEntry("Date", changedTime); config.sync(); SpeechModelManagementConfiguration::setModelSampleRate(sampleRate); QFile containerFile(KStandardDirs::locateLocal("appdata", "model/active.sbm")); if (!containerFile.open(QIODevice::WriteOnly)) return false; containerFile.write(container); containerFile.close(); bool success = false; QDateTime creationDate; QString name; ModelMetadata *data = metaDataFromBuffer(container); if (data) { success = updateBlacklistedTranscriptions(data); creationDate = data->dateTime(); name = data->name(); delete data; } emit activeModelStored(creationDate, name); return success; }
bool ModelManager::storeBaseModel(const QDateTime& changedTime, int baseModelType, const QByteArray& container) { KConfig config( KStandardDirs::locateLocal("appdata", "model/modelsrcrc"), KConfig::SimpleConfig ); KConfigGroup cGroup(&config, ""); cGroup.writeEntry("BaseModelDate", changedTime); cGroup.writeEntry("BaseModelType", baseModelType); config.sync(); QString repoPath = KStandardDirs::locateLocal("appdata", "model/base/srv" + changedTime.toString(Qt::ISODate) + ".sbm"); //store both as selected base model and in the local repository foreach (const QString& path, QStringList() << KStandardDirs::locateLocal("appdata", "model/basemodel.sbm") << repoPath) { QFile containerFile(path); if (!containerFile.open(QIODevice::WriteOnly)) return false; containerFile.write(container); containerFile.close(); } setBaseModel(repoPath, baseModelType); QDateTime creationDate; QString name; ModelMetadata *data = metaDataFromBuffer(container); if (data) { name = data->name(); creationDate = data->dateTime(); delete data; } announceBaseModel(name, baseModelType, creationDate); return true; }