void ImportFilesDialogNew::DoBuildTree(const wxDataViewItem& parent, const wxDir& dir, bool initialState)
{
    wxString path;
    bool cont = dir.GetFirst(&path, "", wxDIR_DIRS);
    while (cont ) {

        wxVector<wxVariant> cols;
        cols.push_back( MakeIconText(path, PluginManager::Get()->GetStdIcons()->LoadBitmap("mime/16/folder") ) );
        cols.push_back(initialState);

        wxDir childDir( dir.GetNameWithSep() + path );
        wxDataViewItem child = m_dataviewModel->AppendItem(parent, cols, new ImportFilesDlgData( childDir.GetName(), initialState ));

        // Add dummy columns
        if ( childDir.IsOpened() && childDir.HasSubDirs() ) {
            wxVector<wxVariant> dummyCols;
            dummyCols.push_back( MakeIconText("dummy", PluginManager::Get()->GetStdIcons()->LoadBitmap("mime/16/folder") ) );
            dummyCols.push_back( false );
            m_dataviewModel->AppendItem( child, dummyCols, new ImportFilesDlgData("", false, true) );
        }
        cont = dir.GetNext(&path);
    }
}
Esempio n. 2
0
//__________________________________________________________________________________
char    ScanDirectoryForFileNames (_String& source, _List& rec, bool recurse)
{
    DIR * dirPntr = opendir (source.sData);
    if (dirPntr)
        /* source directory exists */
    {
        struct dirent * curEntry = nil;

        while (curEntry = readdir (dirPntr))
            // index thru the items
        {
            _String childDir (curEntry->d_name);
            if (childDir.sData[0] != '.') { // invisible file
                childDir = source & '/' & childDir;
                struct stat fileInfo;
                if (stat(childDir.sData, &fileInfo) == 0)
                    //if (curEntry->d_type == DT_DIR)
                {
                    if (S_ISDIR(fileInfo.st_mode))
                        // a directory
                    {
                        if (recurse) {
                            ScanDirectoryForFileNames (childDir,rec,true);
                        }
                    } else
                        //if (curEntry->d_type == DT_REG)
                        if (S_ISREG(fileInfo.st_mode)) {
                            rec && & childDir;
                        }
                }
            }
        }
        closedir (dirPntr);
    }
    return '/';
}
Esempio n. 3
0
/**
 * Implements a directory scan.
 * @param dir        The directory to scan
 * @param recursive  true for recursive scan, false otherwise
 * @return true if successful, false if the scan was aborted
 */
bool FileScanner::scan(const QDir& dir, bool recursive, bool addFiles)
{
	// Get a list of all entries in the directory.
	QFileInfoList infos = dir.entryInfoList(QDir::Files | QDir::Dirs
	                                        | QDir::NoDotAndDotDot);

	// Mark this directory as visited (if following symbolic links).
	if (followSymLinks_)
		visitedDirs_.insert(dir.absolutePath());

	// Iterate over the list.
	QFileInfoList::Iterator itr;
	for (itr = infos.begin(); itr != infos.end(); ++itr) {
		// Make sure event processing continues during a long scan.
		qApp->processEvents();
		if (stop_)
			return false;

		// Update and emit progress information.
		scanned_++;
		if ((scanned_ & 0xff) == 0) {
			if (!progressMessage_.isEmpty()) {
				QString msg = progressMessage_.arg(scanned_)
				                              .arg(fileList_.size());
				emit progress(msg);
			}
			else {
				emit progress(scanned_, fileList_.size());
			}
		}

		// Get the file's path.
		QString path = (*itr).filePath();
		if ((*itr).isDir()) {
			// Directory: scan recursively, if needed.
			if (recursive) {
				// Handle symbolic links.
				if ((*itr).isSymLink()) {
					qDebug() << __func__ << (*itr).absoluteFilePath();

					// If symbolic links are followed, make sure we do not
					// descend into an already-visited directory.
					if (!followSymLinks_
						|| visitedDirs_.contains((*itr).absoluteFilePath())) {
							continue;
					}
				}

				// Change directory.
				QDir childDir(dir);
				if (!childDir.cd((*itr).fileName()))
					continue;

				// Add a trailing "/" to directory names, so that the filter can
				// distinguish those from regular files.
				if (!path.endsWith('/'))
					path += "/";

				// Scan recursively.
				// Filter behaviour for sub-directories:
				// 1. If an inclusion rule is matched, add files.
				// 2. If an exclusion rule is matched, do not add files.
				// 3. If no rule is matched, inherit the behaviour of the
				//    current directory.
				if (!scan(childDir, true, filter_.match(path, addFiles)))
					return false;
			}
		}
		else if (addFiles) {
			// File: add to the file list if the path matches the filter.
			// The default match is set to false, so that files not matched by
			// any rule will not be added.
			if (filter_.match(path, false))
				fileList_.append(path);
		}
	}

	return true;
}