Ejemplo n.º 1
0
QString Project::locationOfObject( QObject *o )
{
    if ( !o )
	return QString::null;

    if ( MainWindow::self ) {
	QWidgetList windows = MainWindow::self->qWorkspace()->windowList();
	for ( QWidget *w = windows.first(); w; w = windows.next() ) {
	    FormWindow *fw = ::qt_cast<FormWindow*>(w);
	    SourceEditor *se = ::qt_cast<SourceEditor*>(w);
	    if ( fw ) {
		if ( fw->isFake() )
		    return objectForFakeForm( fw )->name() + QString( " [Source]" );
		else
		    return fw->name() + QString( " [Source]" );
	    } else if ( se ) {
		if ( !se->object() )
		    continue;
		if ( se->formWindow() )
		    return se->formWindow()->name() + QString( " [Source]" );
		else
		    return makeRelative( se->sourceFile()->fileName() );
	    }
	}
    }

    if ( ::qt_cast<SourceFile*>(o) ) {
	for ( QPtrListIterator<SourceFile> sources = sourceFiles();
	      sources.current(); ++sources ) {
	    SourceFile* f = sources.current();
	    if ( f == o )
		return makeRelative( f->fileName() );
	}
    }

    extern QMap<QWidget*, QString> *qwf_forms;
    if ( !qwf_forms ) {
	qWarning( "Project::locationOfObject: qwf_forms is NULL!" );
	return QString::null;
    }

    QString s = makeRelative( *qwf_forms->find( (QWidget*)o ) );
    s += " [Source]";
    return s;
}
Ejemplo n.º 2
0
	bool DatabaseImpl::rename(const boost::filesystem::path& source, const boost::filesystem::path& target)
	{
		RAISE_INVALID_ARGUMENT_IF(source.empty(), "source database name is empty");
		RAISE_INVALID_ARGUMENT_IF(target.empty(), "target database name is empty");
		RAISE_INVALID_ARGUMENT_IF(openDatabase_, "database is open");

		ManagedDatabaseFiles sourceFiles(source);
		ManagedDatabaseFiles targetFiles(target);

		// We cannot make it atomic anyway.
		const bool canRename = databaseFilesExist(sourceFiles) && ! databaseFilesExist(targetFiles);

		if (canRename) {
			boost::system::error_code bucketRenameError;
			boost::filesystem::rename(sourceFiles.bucketFile_, targetFiles.bucketFile_, bucketRenameError);
			RAISE_IO_ERROR_IF(bucketRenameError, "bucket file \"%s\" cannot be renamed to \"%s\": %s", sourceFiles.bucketFile_.string(), targetFiles.bucketFile_.string(), bucketRenameError.message());
		
			boost::system::error_code overflowRenameError;
			boost::filesystem::rename(sourceFiles.overflowFile_, targetFiles.overflowFile_, overflowRenameError);
			RAISE_IO_ERROR_IF(overflowRenameError, "overflow file \"%s\" cannot be renamed to \"%s\": %s", sourceFiles.overflowFile_.string(), targetFiles.overflowFile_.string(), overflowRenameError.message());
		}

		return canRename;
	}
Ejemplo n.º 3
0
BOOL CDiskObject::EnumDirectories( const CString& sourceDirectory, CStringArray& directories )
/* ============================================================
	Function :		CDiskObject::EnumDirectories
	Description :	Enumerates all directories in directory 
					"sourceDirectory", and adds them to the 
					"CStringArray" "directories". Each entry will
					be a fully qualified name
	Access :		Public

	Return :		BOOL						-	"TRUE" if OK. 
													"GetErrorMessage" 
													will contain errors
	Parameters :	CString sourceDirectory		-	start directory
					CStringArray& directories	-	"CStringArray" to be 
													filled with the 
													directory names.

	Usage :			Call to get a list of directories in a 
					directory tree.

   ============================================================*/
{
	ClearError( );

	CString source( sourceDirectory );
	QualifyPath( source );
	CString sourceFiles( source + _T( "*.*" ) );
	BOOL result = TRUE;
	WIN32_FIND_DATA ff;

	HANDLE findhandle = FindFirstFile( sourceFiles, &ff );
	if( findhandle != INVALID_HANDLE_VALUE)
	{

		BOOL res = TRUE;
		while( res)
		{
			// We only want directories
			if( ( ff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) && _tcscmp( ff.cFileName, _T( "." ) ) && _tcscmp( ff.cFileName, _T( ".." ) ) )
			{
				directories.Add( ff.cFileName );
				Trigger( ff.cFileName );
			}

			if( res )
				res = FindNextFile( findhandle, &ff );
			else
				result = FALSE;
		}

		FindClose( findhandle );
	}
	else
	{
		// Set error message
		SetSystemErrorMessage( ::GetLastError( ), sourceFiles );
		result = FALSE;
	}

	return result;
}
Ejemplo n.º 4
0
BOOL CDiskObject::EnumFilesInDirectoryWithFilter( const CString& strFilter,const CString& sourceDirectory, CStringArray& files, int mode )
/* ============================================================
	Function :		CDiskObject::EnumFilesInDirectoryWithFilter
	Description :	Enumerates all files matching "strFilter" in 
					the directory "sourceDirectory", and adds 
					them to the "CStringArray" "files". Will not 
					add subdirectories.
	Access :		Public
					
	Return :		BOOL					-	"TRUE" if OK. 
												"GetErrorMessage" 
												will contain errors
	Parameters :	CString strFilter		-	the file name filter
					CString sourceDirectory	-	source directory
					CStringArray& files		-	output array
					
	Usage :			Call to get a filtered list of files from 
					a directory.

   ============================================================*/
{

	ClearError( );
	CString source( sourceDirectory );
	QualifyPath( source );
	CString sourceFiles( source + strFilter );
	BOOL result = TRUE;
	WIN32_FIND_DATA ff;

	HANDLE findhandle = FindFirstFile( sourceFiles, &ff );
	if( findhandle != INVALID_HANDLE_VALUE )
	{
		BOOL res = TRUE;
		while( res )
		{
			// We only want files
			if( !( ff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
			{
				BOOL    added = FALSE;
				CString file;
				file = ff.cFileName;

				if( mode == EF_FULLY_QUALIFIED )
					file = sourceDirectory + file;


				if ( !added )
				{
					files.Add( file );
				}

				Trigger( file );
			}

			res = FindNextFile( findhandle, &ff );
		}

		FindClose( findhandle );
	}
	else
	{
		// Set error message
		SetSystemErrorMessage( ::GetLastError( ), sourceFiles );
		result = FALSE;
	}

	return result;

}
Ejemplo n.º 5
0
void Bootstrap::run(RProp& model) const
{
    int numberOfBoards = numberOfFilesIn(sourceDirectory);

    if(!numberOfBoards)
    {
        printf("No files in %s\n", sourceDirectory);

        return;
    }

    int startingSize = STARTING_LABELS < numberOfBoards ?
          STARTING_LABELS
        : numberOfBoards;

    std::vector<const char*> toMove;
    std::vector<const char*> toRemove;

    DirectoryIterator itt(sourceDirectory);
    DirectoryIterator end = DirectoryIterator::end();

    for(int i = 0; i < startingSize; ++i)
    {
        if(manuallyLabelBoard(*itt))
        {
            toMove.push_back(*itt);
        }
        else
        {
            toRemove.push_back(*itt);
        }

        ++itt;
    }

    handleTouchedFiles(toMove, toRemove, sourceDirectory, destinationDirectory);

    while(numberOfFilesIn(sourceDirectory) > 0)
    {
        DirectoryIterator genItt(destinationDirectory);

        model.train(genItt, labelDirectory);

        bool changed = false;

        toMove.clear();
        toRemove.clear();

        DirectoryIterator sourceFiles(sourceDirectory);

        for( ; sourceFiles != end; ++sourceFiles)
        {
            if(automaticallyLabelBoard(model, *sourceFiles))
            {
                toMove.push_back(*sourceFiles);

                changed = true;
            }
        }

        if(!changed)
        {
            numberOfBoards = numberOfFilesIn(sourceDirectory);

            int stepSize = LABEL_STEP > numberOfBoards ?
                  numberOfBoards
                : LABEL_STEP;

            DirectoryIterator boardFiles(sourceDirectory);

            for(int i = 0; i < stepSize; ++i)
            {
                if(manuallyLabelBoard(*boardFiles))
                {
                    toMove.push_back(*boardFiles);
                }
                else
                {
                    toRemove.push_back(*boardFiles);
                }

                ++boardFiles;
            }
        }

        handleTouchedFiles(toMove, toRemove, sourceDirectory, destinationDirectory);
    }
}