void QtFileIconView::readDir( const QDir &dir )
{
    if ( !dir.isReadable() )
        return;

    if ( isRoot( dir.absPath() ) )
        emit disableUp();
    else
        emit enableUp();

    clear();

    emit directoryChanged( dir.absPath() );

    const QFileInfoList *filist = dir.entryInfoList( QDir::DefaultFilter, QDir::DirsFirst | QDir::Name );

    emit startReadDir( filist->count() );

    QFileInfoListIterator it( *filist );
    QFileInfo *fi;
    bool allowRename = FALSE, allowRenameSet = FALSE;
    while ( ( fi = it.current() ) != 0 ) {
        ++it;
        if ( fi && fi->fileName() == ".." && ( fi->dirPath() == "/" || fi->dirPath().isEmpty() ) )
            continue;
        emit readNextDir();
        QtFileIconViewItem *item = new QtFileIconViewItem( this, new QFileInfo( *fi ) );
        if ( fi->isDir() )
            item->setKey( QString( "000000%1" ).arg( fi->fileName() ) );
        else
            item->setKey( fi->fileName() );
        if ( !allowRenameSet ) {
            if ( !QFileInfo( fi->absFilePath() ).isWritable() ||
                    item->text() == "." || item->text() == ".." )
                allowRename = FALSE;
            else
                allowRename = TRUE;
            if ( item->text() == "." || item->text() == ".." )
                allowRenameSet = FALSE;
            else
                allowRenameSet = TRUE;
        }
        item->setRenameEnabled( allowRename );
    }

    if ( !QFileInfo( dir.absPath() ).isWritable() )
        emit disableMkdir();
    else
        emit enableMkdir();

    emit readDirDone();
}
示例#2
0
文件: kscope.cpp 项目: VicHao/kkscope
/**
 * Parses the command line, after it was stripped of its KDE options.
 * The command line may contain one of the following options:
 * 1. A project file (named cscope.proj)
 * 2. A Cscope cross-reference database
 * 3. A list of source files
 * @param	pArgs	Command line arguments
 */
void KScope::parseCmdLine(KCmdLineArgs* pArgs)
{
	QString sArg;
	QFileInfo fi;
	int i;

	// Loop over all arguments
	for (i = 0; i < pArgs->count(); i++) {
		// Verify the argument is a file or directory name
		sArg = pArgs->arg(i);
		fi.setFile(sArg);
		if (!fi.exists())
			continue;
			
		// Handle the current argument
		if (fi.isFile()) {
			if (fi.fileName() == "cscope.proj") {
				// Open a project file
				openProject(fi.dirPath(true));
				return;
			} else if (openCscopeOut(sArg)) {
				// Opened the file as a cross-reference database
				return;
			} else {
				// Assume this is a source file
				slotShowEditor(sArg, 0);
			}
		} else if (fi.isDir()) {
			// Treat the given path as a project directory
			openProject(fi.absFilePath());
			return;
		}
	}
}
示例#3
0
void VASettingsDialog::slotBrowse ()
{
  QString s = QFileDialog::getOpenFileName (
     lastDir.isEmpty () ? QString (".") : lastDir,
     tr("PNG files")+" (*.png);;"+
     tr("Any file")+" (*)",
     this, 0, tr("Enter an Icon File Name"));

  if (!s.isEmpty ()) {
    QFileInfo Info (s);
    lastDir = Info.dirPath (true);  // remember last directory
    IconEdit->setText (s);
    IconButt->setPixmap (QPixmap (s));
  }
}
示例#4
0
void EvaGlobal::initialize()
{
	dirPath = KGlobal::dirs()->findResource("data", QString::fromLatin1("eva/servers"));
// 	QStringList dirs = KGlobal::dirs()->findDirs("data", QString::fromLatin1("eva"));
// 	for(uint i=0; i<dirs.size(); i++){
// 		//printf("dir %i:%s\n", i, dirs[i].ascii());
// 		//dirPath = dirs[0];
// 		break;
// 	}
	if(dirPath == QString::null){
		QFileInfo fi;
		fi.setFile(QString(getenv("_")));
		dirPath = fi.dirPath(true);
	}else
		dirPath = dirPath.left(dirPath.length() - strlen("/servers"));

	//printf("found data path: %s\n", dirPath.ascii());
	initImage();
	initSound();
	initEvaSetting();
	initServers();
}
示例#5
0
QStringList Q3FileDialog::winGetOpenFileNames(const QString &filter,
        QString* initialDirectory,
        QWidget *parent,
        const char* /*name*/,
        const QString& caption,
        QString* selectedFilter)
{
    QStringList result;
    QFileInfo fi;
    QDir dir;
    QString isel;

    if (initialDirectory && initialDirectory->left(5) == QLatin1String("file:"))
        initialDirectory->remove(0, 5);
    fi = QFileInfo(*initialDirectory);

    if (initialDirectory && !fi.isDir()) {
        *initialDirectory = fi.dirPath(true);
        isel = fi.fileName();
    }

    if (!fi.exists())
        *initialDirectory = QDir::homeDirPath();

    QString title = caption;
    if (title.isNull())
        title = tr("Open ");

    DWORD selFilIdx = 0;

    int idx = 0;
    if (selectedFilter && !selectedFilter->isEmpty()) {
        QStringList filterLst = makeFiltersList(filter);
        idx = filterLst.findIndex(*selectedFilter);
    }

    if (parent) {
        QEvent e(QEvent::WindowBlocked);
        QApplication::sendEvent(parent, &e);
        QApplicationPrivate::enterModal(parent);
    }

    OPENFILENAME* ofn = makeOFN(parent, isel,
                                *initialDirectory, title,
                                winFilter(filter), ExistingFiles);
    if (idx)
        ofn->nFilterIndex = idx + 1;
    if (GetOpenFileName(ofn)) {
        QString fileOrDir = QString::fromWCharArray(ofn->lpstrFile);
        selFilIdx = ofn->nFilterIndex;
        int offset = fileOrDir.length() + 1;
        if (ofn->lpstrFile[offset] == 0) {
            // Only one file selected; has full path
            fi.setFile(fileOrDir);
            QString res = fi.absFilePath();
            if (!res.isEmpty())
                result.append(res);
        }
        else {
            // Several files selected; first string is path
            dir.setPath(fileOrDir);
            QString f;
            while (!(f = QString::fromWCharArray(ofn->lpstrFile + offset)).isEmpty()) {
                fi.setFile(dir, f);
                QString res = fi.absFilePath();
                if (!res.isEmpty())
                    result.append(res);
                offset += f.length() + 1;
            }
        }
    }
    cleanUpOFN(&ofn);

    if (parent) {
        QApplicationPrivate::leaveModal(parent);
        QEvent e(QEvent::WindowUnblocked);
        QApplication::sendEvent(parent, &e);
    }

    if (!result.isEmpty()) {
        *initialDirectory = fi.dirPath();    // only save the path if there is a result
        if (selectedFilter)
            *selectedFilter = selFilter(filter, selFilIdx);
    }
    return result;
}
示例#6
0
int readDir(QFileInfo *fi,
            FileNameList *fnList,
            FileNameDict *fnDict,
            StringDict  *exclDict,
            QStrList *patList,
            QStrList *exclPatList,
            StringList *resultList,
            StringDict *resultDict,
            bool errorIfNotExist,
            bool recursive,
            QDict<void> *killDict,
            QDict<void> *paths
           )
{
  QCString dirName = fi->absFilePath().utf8();
  if (paths && paths->find(dirName)==0)
  {
    paths->insert(dirName,(void*)0x8);
  }
  if (fi->isSymLink())
  {
  }
  QDir dir(dirName);
  dir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
  int totalSize=0;
  //printf("killDict=%p count=%d\n",killDict,killDict->count());
  
  const QFileInfoList *list = dir.entryInfoList();
  if (list)
  {
    QFileInfoListIterator it( *list );
    QFileInfo *cfi;

    while ((cfi=it.current()))
    {
      if (exclDict==0 || exclDict->find(cfi->absFilePath().utf8())==0) 
      { // file should not be excluded
        //printf("killDict->find(%s)\n",cfi->absFilePath().data());
        if (!cfi->exists() || !cfi->isReadable())
        {
          if (errorIfNotExist)
          {
          }
        }
        else if (cfi->isFile() && 
            (patList==0 || patternMatch(*cfi,patList)) && 
            !patternMatch(*cfi,exclPatList) &&
            (killDict==0 || killDict->find(cfi->absFilePath().utf8())==0)
            )
        {
          totalSize+=cfi->size()+cfi->absFilePath().length()+4;
          QCString name=cfi->fileName().utf8();
          //printf("New file %s\n",name.data());
          if (fnDict)
          {
            FileDef  *fd=new FileDef(cfi->dirPath().utf8()+"/",name);
            FileName *fn=0;
            if (!name.isEmpty() && (fn=(*fnDict)[name]))
            {
              fn->append(fd);
            }
            else
            {
              fn = new FileName(cfi->absFilePath().utf8(),name);
              fn->append(fd);
              if (fnList) fnList->inSort(fn);
              fnDict->insert(name,fn);
            }
          }
          QCString *rs=0;
          if (resultList || resultDict)
          {
            rs=new QCString(cfi->absFilePath().utf8());
          }
          if (resultList) resultList->append(rs);
          if (resultDict) resultDict->insert(cfi->absFilePath().utf8(),rs);
          if (killDict) killDict->insert(cfi->absFilePath().utf8(),(void *)0x8);
        }
        else if (recursive &&
            cfi->isDir() && 
            !patternMatch(*cfi,exclPatList) &&
            cfi->fileName().at(0)!='.') // skip "." ".." and ".dir"
        {
          cfi->setFile(cfi->absFilePath());
          totalSize+=readDir(cfi,fnList,fnDict,exclDict,
              patList,exclPatList,resultList,resultDict,errorIfNotExist,
              recursive,killDict,paths);
        }
      }
      ++it;
    }
  }
  return totalSize;
}
示例#7
0
void OFileViewFileListView::reread( bool all ) {
    m_view->clear();

    if (selector()->showClose() )
        m_btnClose->show();
    else
        m_btnClose->hide();

    if (selector()->showNew() )
        m_btnNew->show();
    else
        m_btnNew->hide();

    m_mimes = selector()->currentMimeType();
    m_all = all;

    QDir dir( m_currentDir );
    if (!dir.exists() )
        return;

    dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
    int filter;
    if (m_all )
        filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
    else
        filter = QDir::Files | QDir::Dirs | QDir::All;
    dir.setFilter( filter );

    // now go through all files
    const QFileInfoList *list = dir.entryInfoList();
    if (!list) {
        cdUP();
        return;
    }
    QFileInfoListIterator it( *list );
    QFileInfo *fi;
    while( (fi=it.current() ) ) {
        if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) {
            ++it;
            continue;
        }

        /*
         * It is a symlink we try to resolve it now but don't let us attack by DOS
         *
         */
        if( fi->isSymLink() ) {
            QString file = fi->dirPath( true ) + "/" + fi->readLink();
            for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
                QFileInfo info( file );
                if( !info.exists() ) {
                    addSymlink( fi, TRUE );
                    break;
                } else if( info.isDir() ) {
                    addDir( fi, TRUE );
                    break;
                } else if( info.isFile() ) {
                    addFile( fi, TRUE );
                    break;
                } else if( info.isSymLink() ) {
                    file = info.dirPath(true ) + "/" + info.readLink() ;
                    break;
                } else if( i == 4) { // couldn't resolve symlink add it as symlink
                    addSymlink( fi );
                }
            } // off for loop for symlink resolving
        } else if( fi->isDir() )
            addDir(  fi );
        else if( fi->isFile() )
            addFile( fi );

        ++it;
    } // of while loop
    m_view->sort();

}