void FileSystemScanner::testIfFolderIsAddable(QDir* dir, bool recursive) const throw(EngineException*)
{
    tracer->sinvoked(__func__) << dir->absPath() << ", recursive: " << recursive << "..." << endl;

    // test if the given folder is already added
    Folder* folder;
    for (folder = m_engine->sourceDirs()->first(); folder; folder = m_engine->sourceDirs()->next() ) {

        if (*(folder->dir()) == *dir) {
            QString detailMsg = QString(i18n("The folder you have chosen is already added to KPhotoBook.\n"
                    "Folder: %1")).arg(folder->dir()->absPath());
            throw new EngineException(
                    i18n("You cannot add the same folder more than once to KPhotoBook."),
                    detailMsg
            );
        }

        QString folderPath = folder->dir()->absPath();
        QString newFolderPath = dir->absPath();

        if (folder->recursive()) {
            // test if the new folder is a subfolder of the current sourceFolder
            if (newFolderPath.startsWith(folderPath)) {
                QString detailMsg = QString(i18n("The folder you have chosen is a subfolder of a recursively added folder.\n"
                        "Folder: %1\nNew folder: %2")).arg(folderPath).arg(newFolderPath);
                throw new EngineException(
                        i18n("You cannot add a folder which is a subfolder of an already recursively added folder because"
                        "the chosen folder is already added implicitely."),
                        detailMsg
                 );
            }
        }

        if (recursive) {
            // test if the current folder is a subfolder of the new folder
            if (folderPath.startsWith(newFolderPath)) {
                QString detailMsg = QString(i18n("The folder you have chosen to add recursively is the parentfolder of at least "
                        "one already added folders.\nFolder: %1\nNew folder: %2")).arg(folderPath).arg(newFolderPath);
                throw new EngineException(
                        i18n("You cannot add the parentfolder of an already added folder recursively."),
                        detailMsg
                 );
            }
        }
    }

    tracer->debug(__func__, "ended");
}
void FileSystemScanner::rescanFolders(QPtrList<Folder>* folders, bool forceEXIF, bool fast)
{
    Folder* folder = 0;
    for (folder = folders->first(); folder; folder = folders->next()) {
        QString currentFolderPath = folder->dir()->absPath();

        tracer->sdebug(__func__) << "rescanning folder: " << folder->id() << ": " << currentFolderPath << endl;

        if (folder->dir()->exists()) {

            folder->setFound(true);

            if (!fast) {
                rescanFolder(folder, forceEXIF);
                if (m_cancel) {
                    return;
                }
            }

            if (folder->children() && folder->children()->count()) {
                rescanFolders(folder->children(), forceEXIF, fast);
            }

            // scan the filesystem for new folders
            if (!fast && folder->recursive()) {
                delete m_loopDetectionHelper;
                m_loopDetectionHelper = new QPtrList<QString>;
                m_loopDetectionHelper->setAutoDelete(true);
                m_loopDetectionHelper->append(new QString(folder->dir()->canonicalPath()));

                addFolders(folder);
            }
        } else {
            folder->setFound(false);

            tracer->sdebug(__func__) << "folder: " << folder->id() << ": '" << currentFolderPath << "' not found" << endl;
            emit(progress_folderNotFound(currentFolderPath));
        }
    }
}