QStringList Config::findLanguageFiles() { QDir dir(programPath); QStringList fileNames; QStringList langs; fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name); QDir resDir(":/lang"); fileNames += resDir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name); QRegExp exp("^rbutil_(.*)\\.qm"); for(int i = 0; i < fileNames.size(); i++) { QString a = fileNames.at(i); a.replace(exp, "\\1"); langs.append(a); } langs.sort(); qDebug() << "[Config] available lang files:" << langs; return langs; }
qint32 NoteTable::duplicateNote(qint32 oldLid) { ConfigStore cs; qint32 newLid = cs.incrementLidCounter(); QSqlQuery query; QString tempTableName = "notecopy" + QString::number(oldLid); query.exec("drop temporary table " +tempTableName); query.prepare("create temporary table " +tempTableName +" as select * from datastore where lid=:oldLid"); query.bindValue(":oldLid", oldLid); query.exec(); query.prepare("Update " +tempTableName +" set lid=:newLid"); query.bindValue(":newLid", newLid); query.exec(); query.exec("insert into datastore select lid, key, data from " +tempTableName); query.exec("drop " +tempTableName); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newLid); query.bindValue(":key", NOTE_UPDATE_SEQUENCE_NUMBER); query.exec(); Note n; get(n, newLid, false,false); updateNoteList(newLid, n, true); setDirty(newLid, true); // Update all the resources ResourceTable resTable; QList<qint32> lids; resTable.getResourceList(lids, oldLid); for (int i=0; i<lids.size(); i++) { qint32 newResLid = cs.incrementLidCounter(); query.prepare("create temporary table " +tempTableName +" as select * from datastore where lid=:oldLid"); query.bindValue(":oldLid", lids[i]); query.exec(); query.prepare("Update " +tempTableName +" set lid=:newLid"); query.bindValue(":newLid", newResLid); query.exec(); query.exec("insert into datastore select lid, key, data from " +tempTableName); query.exec("drop " +tempTableName); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newResLid); query.bindValue(":key", RESOURCE_UPDATE_SEQUENCE_NUMBER); query.exec(); query.prepare("update datastore set data=:data where lid=:lid and key=:key"); query.bindValue(":data", 0); query.bindValue(":lid", newResLid); query.bindValue(":key", RESOURCE_NOTE_LID); query.exec(); QStringList filter; QDir resDir(global.fileManager.getDbaDirPath()); filter << QString::number(lids[i])+".*"; QStringList files = resDir.entryList(filter); for (int j=0; j<files.size(); j++) { QFile file(global.fileManager.getDbaDirPath()+files[j]); int pos = files[j].indexOf("."); QString type = files[j].mid(pos); file.open(QIODevice::ReadOnly); file.copy(global.fileManager.getDbaDirPath()+ QString::number(newResLid) +type); file.close(); } } return newLid; }