Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use UUIDs instead of counting #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/basketfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QtCore/QTextStream>
#include <QtGui/QGraphicsView>
#include <QtXml/QDomElement>
#include <QUuid>

#include <KDE/KLocale>
#include <KDE/KMessageBox>
Expand All @@ -44,13 +45,12 @@ QString BasketFactory::newFolderName()
QString fullPath;
QDir dir;

for (int i = 1; ; ++i) {
folderName = "basket" + QString::number(i) + "/";
do {
QString id = QUuid::createUuid().toString().remove(QRegExp("[{}]")); // QTBUG-885
folderName = "basket-" + id + "/";
fullPath = Global::basketsFolder() + folderName;
dir = QDir(fullPath);
if (! dir.exists()) // OK : The folder do not yet exists :
break; // We've found one !
}
} while (dir.exists()); // Should run only once

return folderName;
}
Expand Down
16 changes: 7 additions & 9 deletions src/notefactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QtGui/QTextDocument> //For Qt::mightBeRichText(...)
#include <QtGui/QBitmap> //For createHeuristicMask
#include <QtCore/qnamespace.h>
#include <QUuid>

#include <KDE/KUrl>
#include <KDE/KMimeType>
Expand Down Expand Up @@ -864,20 +865,17 @@ QString NoteFactory::fileNameForNewNote(BasketScene *parent, const QString &want
// (extension willn't be used for that case)
QString NoteFactory::createFileForNewNote(BasketScene *parent, const QString &extension, const QString &wantedName)
{
static int nb = 1;

QString fileName;
QString fullName;

if (wantedName.isEmpty()) { // TODO: fileNameForNewNote(parent, "note1."+extension);
QDir dir;
for (/*int nb = 1*/; ; ++nb) { // TODO: FIXME: If overflow ???
fileName = "note" + QString::number(nb)/*.rightJustified(5, '0')*/ + "." + extension;
QDir file;
do {
QString id = QUuid::createUuid().toString().remove(QRegExp("[{}]")); // QTBUG-885
fileName = "note-" + id + "." + extension;
fullName = parent->fullPath() + fileName;
dir = QDir(fullName);
if (! dir.exists(fullName))
break;
}
file = QDir(fullName);
} while (file.exists(fullName)); // should run only once
} else {
fileName = fileNameForNewNote(parent, wantedName);
fullName = parent->fullPath() + fileName;
Expand Down