- if (!entries.isEmpty()) {
- QString name = QFile(entries.last()).fileName();
- index = name.section('_', 1, 1).section('.', 0, 0).toInt();
+ if (m_index->stamp(indexType) != date) {
+ m_index->setStamp(indexType, date);
+ }
+ else {
+ index = m_index->counter(indexType);
+ }
+
+ if (index == 0) {
+ QStringList filters(QString("*%1_*").arg(date));
+ QStringList entries = dir.entryList(filters, QDir::Files, QDir::Name);
+ if (!entries.isEmpty()) {
+ QString name = QFile(entries.last()).fileName();
+ index = name.section('_', 1, 1).section('.', 0, 0).toInt();
+ }
+ }
+
+ while (index < INT_MAX) {
+ ++index;
+
+ QString name = QString("%1%2_%3.%4")
+ .arg(path).arg(date).arg(QString().sprintf("%03i", index)).arg(suffix);
+
+ if (!QFile(name).exists()) {
+ m_index->setCounter(indexType, index);
+ return name;
+ }
+
+ }
+
+ qmlInfo(this) << "Failed to guess a file name";
+
+ return QString();
+}
+
+QString FileNaming::canonicalPath(const QString& path) {
+ if (!QDir::root().mkpath(path)) {
+ qmlInfo(this) << "Failed to create path" << path;
+ return QString();
+ }
+
+ QString newPath = QFileInfo(path).canonicalFilePath();
+
+ if (newPath.isEmpty()) {
+ return newPath;
+ }
+
+ if (!newPath.endsWith(QDir::separator())) {
+ newPath.append(QDir::separator());