int SamplePool::ImportSample(Path &path) { if (count_==MAX_PIG_SAMPLES) return -1 ; // construct target path std::string dpath="samples:" ; dpath+=path.GetName() ; Path dstPath(dpath.c_str()) ; // Opens files I_File *fin=FileSystem::GetInstance()->Open(path.GetPath().c_str(),"r") ; if (!fin) { Trace::Error("Failed to open input file %s",path.GetPath().c_str()) ; return -1; } ; fin->Seek(0,SEEK_END) ; long size=fin->Tell() ; fin->Seek(0,SEEK_SET) ; I_File *fout=FileSystem::GetInstance()->Open(dstPath.GetPath().c_str(),"w") ; if (!fout) { fin->Close() ; delete (fin) ; return -1 ; } ; // copy file to current project char buffer[IMPORT_CHUNK_SIZE] ; while (size>0) { int count=(size>IMPORT_CHUNK_SIZE)?IMPORT_CHUNK_SIZE:size ; fin->Read(buffer,1,count) ; fout->Write(buffer,1,count) ; size-=count ; } ; fin->Close() ; fout->Close() ; delete(fin) ; delete(fout) ; // now load the sample bool status=loadSample(dstPath.GetPath().c_str()) ; SetChanged() ; SamplePoolEvent ev ; ev.index_=count_-1 ; ev.type_=SPET_INSERT ; NotifyObservers(&ev) ; return status?(count_-1):-1 ; };
// SetDirectory status_t UncachedDirIterator::SetDirectory(Directory* directory) { // unset old if (fDirHandle) { closedir(fDirHandle); fDirHandle = NULL; } fDirectory = NULL; // set new if (directory) { // get the directory path Path path; status_t error = directory->GetPath(&path); if (error != B_OK) return error; // open the directory error = FDManager::OpenDir(path.GetPath(), fDirHandle); if (error != B_OK) return error; fDirectory = directory; fNodeRef = directory->GetNodeRef(); } return B_OK; }
/** \brief Invoked * Handles when an icon within the view is invoked. If it is a directory * it should, the current directory should move into it. If it is a file * it should be opened if possible and otherwise it should be downloaded. * * \todo Should attempt to dowload and open the remote file if it's not a directory? * \todo What should be the default action when the file type is unknown? */ void RemoteIconView::Invoked( uint nIcon, IconData* pcData ) { // DEBUG( "RemoteIconView::Invoked on icon %i (%s)\n", nIcon, GetIconString( nIcon, 0 ).c_str() ); RemoteIconData* pcRData = (RemoteIconData*)pcData; if( pcRData->m_cNode.IsDir() ) { Path cPath = m_zPath; cPath.Append( pcRData->m_cNode.m_zName ); DEBUG( "RemoteView: Changing to %s\n", cPath.GetPath().c_str() ); if( m_pcDirChangedMsg ) { Message cTmp = *m_pcDirChangedMsg; cTmp.AddString( "file/path", cPath.GetPath() ); Invoke( &cTmp ); } SetPath( cPath.GetPath() ); } }
bool FieldView::DrawPath(const Path& path){ //get dots container from givven path Path::Dots dots = path.GetPath(); const size_t size = dots.size(); if(dots.empty()) //if container with dots coordinats is empty, then exit return false; window = get_window(); //get pointer to parent window if(window){ //if pointer to window is not NULL... cr = window->create_cairo_context(); if(cr){ //and if pointer to context is not NULL... allocation = get_allocation(); cr->save(); cr->rectangle(0, 0, allocation.get_width(), allocation.get_height()); cr->clip(); //choose color switch(path.GetColor()){ case RED: cr->set_source_rgb(1.0, 0.0, 0.0); break; case BLUE: cr->set_source_rgb(0.0, 0.0, 1.0); break; default: return false; } cr->set_line_width((ctrl->GetPrefs()->line_width) * 2); //move to start point cr->move_to((dots[0].GetX()+1) * CELL_SIZE * sx, (dots[0].GetY() + 1) * CELL_SIZE * sy); //here we will just move from one point to another while there is at least one of them for(size_t i = 1; i < size; i++) //we add 1 because field has some kind of "dead zone" on its sides cr->line_to((dots[i].GetX() + 1) * CELL_SIZE * sx, (dots[i].GetY() + 1) * CELL_SIZE * sy); cr->stroke(); dots.clear(); return true; } } return false; }
// Open status_t AttrDirIterator::Open(Node* node) { if (!node) return B_BAD_VALUE; // get a path Path path; status_t error = node->GetPath(&path); if (error != B_OK) return error; // open the attribute directory error = FDManager::OpenAttrDir(path.GetPath(), fDir); if (error != B_OK) return errno; fNodeRef = node->GetNodeRef(); return B_OK; }
//================================================================================= // I wonder if we should overwrite the cache entry in the case that // a cache entry for the given path already exists. bool Context::TreeCacheAdd( const Path& path, const Node* root ) { if( !treeCacheMap ) treeCacheMap = new TreeCacheMap(); std::string key; if( !path.GetPath( key, true ) ) return false; TreeCacheMap::iterator iter = treeCacheMap->find( key ); if( iter != treeCacheMap->end() ) return false; Node::CopyParameters copyParameters; Node* clone = root->Clone( *this, copyParameters ); if( !clone ) return false; ( *treeCacheMap )[ key ] = clone; return true; }
// Open status_t FileHandle::Open(Node* node, int openMode) { if (!node) return B_BAD_VALUE; openMode &= O_RWMASK | O_TRUNC | O_APPEND; // get a path Path path; status_t error = node->GetPath(&path); if (error != B_OK) return error; // open the file error = FDManager::Open(path.GetPath(), openMode | O_NOTRAVERSE, 0, fFD); if (error != B_OK) return error; fNodeRef = node->GetNodeRef(); return B_OK; }
Path::Path(const Path& o) { SetPath(o.GetPath()); }