Make sure we can restore the entire folder hierarchy when opening a project

parent 5ef3da9a
...@@ -1013,7 +1013,8 @@ void Bin::slotLoadFolders(QMap<QString,QString> foldersData) ...@@ -1013,7 +1013,8 @@ void Bin::slotLoadFolders(QMap<QString,QString> foldersData)
// Folder parent is saved in folderId, separated by a dot. for example "1.3" means parent folder id is "1" and new folder id is "3". // Folder parent is saved in folderId, separated by a dot. for example "1.3" means parent folder id is "1" and new folder id is "3".
ProjectFolder *parentFolder = m_rootFolder; ProjectFolder *parentFolder = m_rootFolder;
QStringList folderIds = foldersData.keys(); QStringList folderIds = foldersData.keys();
QStringList secondProcess; int maxIterations = folderIds.count() * folderIds.count();
int iterations = 0;
while(!folderIds.isEmpty()) { while(!folderIds.isEmpty()) {
//for (int i = 0; i < folderIds.count(); i++) { //for (int i = 0; i < folderIds.count(); i++) {
QString id = folderIds.takeFirst(); QString id = folderIds.takeFirst();
...@@ -1028,14 +1029,15 @@ void Bin::slotLoadFolders(QMap<QString,QString> foldersData) ...@@ -1028,14 +1029,15 @@ void Bin::slotLoadFolders(QMap<QString,QString> foldersData)
// parent folder not yet created, create unnamed placeholder // parent folder not yet created, create unnamed placeholder
parentFolder = new ProjectFolder(parentId, QString(), parentFolder); parentFolder = new ProjectFolder(parentId, QString(), parentFolder);
} else if (parentFolder == NULL) { } else if (parentFolder == NULL) {
// folder without parent detected, create standard one // Parent folder not yet created in hierarchy
if (secondProcess.contains(id)) { if (iterations > maxIterations) {
// Orphaned folder // Give up, place folder in root
parentFolder = new ProjectFolder(parentId, i18n("Folder"), m_rootFolder); parentFolder = new ProjectFolder(parentId, i18n("Folder"), m_rootFolder);
} }
else { else {
// Try to process again at end of queue
folderIds.append(id); folderIds.append(id);
secondProcess << id; iterations ++;
continue; continue;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment