int XJudgerMain::getDir(string dir, int &count){ struct direct *file = NULL; DIR *pdir = opendir(dir.c_str()); dir = tDir(dir); if (pdir){ while ((file = readdir(pdir)) != NULL){ if (strcmp(file -> d_name, ".") == 0) continue; if (strcmp(file -> d_name, "..") == 0) continue; if (checkDir(dir + file -> d_name)){ QTreeWidgetItem *item; if (MainViewScore -> topLevelItemCount() <= count) item = new QTreeWidgetItem(MainViewScore); else item = MainViewScore -> topLevelItem(count); item -> setData(0, 0, file -> d_name); item -> setData(3, 0, (dir + file -> d_name).c_str()); PersonInfo info(dir + file -> d_name); char strout[30]; snprintf(strout, 30, "%5.0lf", info.Score); item -> setData(1, 0, strout); snprintf(strout, 30, "%.3lf s", info.ACTime); item -> setData(2, 0, strout); item -> setIcon(0, QIcon(":/Icons/User.png")); count ++; } getDir(dir + file -> d_name, count); } } closedir(pdir); return 0; }
bool seg:: extendBy ( const vec3& pt ) { // TODO: This only handles cases where the point is along the "positive" direction // of travel. If it were along the "negative", we should move pos and extend length. // vec3 ptDir = pt - pos; vec3 ptDir ( pt ); ptDir -= pos; ptDir.normalize (); vec3 tDir ( dir ); tDir.normalize (); if ( ! tDir.equal ( ptDir ) ) { return false; } length = pt.dist ( pos ); return true; }
int seg:: contains ( const seg& segIn ) const { // TODO: Remove direction vector normalization?? User's responsibility??? vec3 tDir ( segIn.dir ); tDir.normalize (); // vec3 endPt = segIn.pos + tDir * segIn.length; vec3 endPt ( tDir ); endPt *= segIn.length; endPt += segIn.pos; int c1 = contains ( segIn.pos ); int c2 = contains ( endPt ); if ( c1 ) { if ( c2 ) return containsResult::AllIn; return containsResult::SomeIn; } if ( c2 ) return containsResult::SomeIn; // OPTIMIZE: Expensive... if ( segIn.contains ( pos ) ) return containsResult::SomeIn; vec3 endPos = pos + dir * length; if ( segIn.contains ( endPos ) ) return containsResult::SomeIn; return containsResult::NoneIn; }
void ProjectSelectionPage::validateData() { KUrl url = ui->locationUrl->url(); if( !url.isLocalFile() || url.isEmpty() ) { ui->locationValidLabel->setText( i18n("Invalid location") ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); emit invalid(); return; } if( appName().isEmpty() ) { ui->locationValidLabel->setText( i18n("Empty project name") ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); emit invalid(); return; } if( appName() == "." || appName() == "..") { ui->locationValidLabel->setText( i18n("Invalid project name") ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); emit invalid(); return; } QDir tDir(url.toLocalFile( KUrl::RemoveTrailingSlash )); while (!tDir.exists() && !tDir.isRoot()) tDir.setPath( pathUp( tDir.absolutePath() )); if (tDir.exists()) { QFileInfo tFileInfo(tDir.absolutePath()); if (!tFileInfo.isWritable() || !tFileInfo.isExecutable()) { ui->locationValidLabel->setText( i18n("Unable to create subdirectories, " "missing permissions on: %1", tDir.absolutePath()) ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); emit invalid(); return; } } QStandardItem* item = m_templatesModel->itemFromIndex( ui->templateView->currentIndex() ); if( item && !item->hasChildren() ) { ui->locationValidLabel->setText( QString(" ") ); setForeground(ui->locationValidLabel, KColorScheme::NormalText); emit valid(); } else { ui->locationValidLabel->setText( i18n("Invalid project template, please choose a leaf item") ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); emit invalid(); return; } // Check for non-empty target directory. Not an error, but need to display a warning. url.addPath( encodedAppName() ); QFileInfo fi( url.toLocalFile( KUrl::RemoveTrailingSlash ) ); if( fi.exists() && fi.isDir() ) { if( !QDir( fi.absoluteFilePath()).entryList( QDir::NoDotAndDotDot | QDir::AllEntries ).isEmpty() ) { ui->locationValidLabel->setText( i18n("Path already exists and contains files") ); setForeground(ui->locationValidLabel, KColorScheme::NegativeText); } } }