MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / generateChatFileName

Method generateChatFileName

ChatView/ChatHistoryStore.cpp:190–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190QString ChatHistoryStore::generateChatFileName(const QString &shortMessage, const QString &dir) const
191{
192 static const QRegularExpression saitizeSymbols = QRegularExpression("[\\/:*?\"<>|\\s]");
193 static const QRegularExpression underSymbols = QRegularExpression("_+");
194
195 QStringList parts;
196 QString sanitizedMessage = shortMessage;
197 sanitizedMessage.replace(saitizeSymbols, "_");
198 sanitizedMessage.replace(underSymbols, "_");
199 sanitizedMessage = sanitizedMessage.trimmed();
200
201 if (!sanitizedMessage.isEmpty()) {
202 if (sanitizedMessage.startsWith('_')) {
203 sanitizedMessage.remove(0, 1);
204 }
205 if (sanitizedMessage.endsWith('_')) {
206 sanitizedMessage.chop(1);
207 }
208
209 QString fullPath = QDir(dir).filePath(sanitizedMessage);
210 QFileInfo fileInfo(fullPath);
211 if (!fileInfo.exists() && QFileInfo(fileInfo.path()).isWritable()) {
212 parts << sanitizedMessage;
213 }
214 }
215
216 parts << QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm");
217
218 QString fileName = parts.join("_");
219 QString fullPath = QDir(dir).filePath(fileName);
220 QFileInfo finalCheck(fullPath);
221
222 if (fileName.isEmpty() || finalCheck.exists() || !QFileInfo(finalCheck.path()).isWritable()) {
223 fileName = QString("chat_%1").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm"));
224 }
225
226 return fileName;
227}
228
229} // namespace QodeAssist::Chat

Callers

nothing calls this directly

Calls 3

isEmptyMethod · 0.45
filePathMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected