📄 krquery.cpp
字号:
if( buf[ k ] == 0 || buf[ k ] == '\n' ) { if( k != start ) { QString line = QTextCodec::codecForLocale()->toUnicode( buf + start, k - start ); if( !line.isEmpty() ) list << line; } start = k + 1; } k++; } if( start != k ) { QString line = QTextCodec::codecForLocale()->toUnicode( buf + start, k - start ); if( !line.isEmpty() ) list << line; } for( unsigned int i=0; i != list.count(); i++ ) { QString line = list[ i ]; int ndx = 0; if ( line.isNull() ) return false; if ( containWholeWord ) { while ( ( ndx = line.find( contain, ndx, containCaseSensetive ) ) != -1 ) { QChar before = line.at( ndx - 1 ); QChar after = line.at( ndx + contain.length() ); if ( !before.isLetterOrNumber() && !after.isLetterOrNumber() && after != '_' && before != '_' ) { lastSuccessfulGrep = line; fixFoundTextForDisplay(lastSuccessfulGrep, ndx, contain.length()); return true; } ndx++; } } else if ( (ndx = line.find( contain, 0, containCaseSensetive )) != -1 ) { lastSuccessfulGrep = line; fixFoundTextForDisplay(lastSuccessfulGrep, ndx, contain.length()); return true; } } return false;}bool KRQuery::containsContent( QString file ) const{ QFile qf( file ); if( !qf.open( IO_ReadOnly ) ) return false; char buffer[ 1440 ]; // 2k buffer while ( !qf.atEnd() ) { int bytes = qf.readBlock( buffer, sizeof( buffer ) ); if( bytes <= 0 ) break; receivedBytes += bytes; if( checkBuffer( buffer, bytes ) ) return true; if( checkTimer() ) { bool stopped = false; emit ((KRQuery *)this)->processEvents( stopped ); if( stopped ) return false; } } if( checkBuffer( buffer, 0 ) ) return true; lastSuccessfulGrep = QString::null; // nothing was found return false;}bool KRQuery::containsContent( KURL url ) const{ KIO::TransferJob *contentReader = KIO::get( url, false, false ); connect(contentReader, SIGNAL(data(KIO::Job *, const QByteArray &)), this, SLOT(containsContentData(KIO::Job *, const QByteArray &))); connect(contentReader, SIGNAL( result( KIO::Job* ) ), this, SLOT(containsContentFinished( KIO::Job* ) ) ); busy = true; containsContentResult = false; bool stopped = false; while( busy && !stopped ) { checkTimer(); emit ((KRQuery *)this)->processEvents( stopped ); } if( busy ) { contentReader->kill(); busy = false; } return containsContentResult;}void KRQuery::containsContentData(KIO::Job *job, const QByteArray &array) { receivedBytes += array.size(); if( checkBuffer( array.data(), array.size() ) ) { containsContentResult = true; containsContentFinished( job ); job->kill(); return; } checkTimer();}void KRQuery::containsContentFinished( KIO::Job * ) { busy = false;}bool KRQuery::checkTimer() const { if( timer.elapsed() >= STATUS_SEND_DELAY ) { int pcnt = (int)(100.*(double)receivedBytes/(double)totalBytes + .5); QString message = i18n( "Searching content of '%1' (%2%)" ) .arg( fileName ).arg( pcnt ); timer.start(); emit ((KRQuery *)this)->status( message ); return true; } return false;}QStringList KRQuery::split( QString str ){ QStringList list; unsigned splitNdx = 0; unsigned startNdx = 0; bool quotation = false; while( splitNdx < str.length() ) { if( str[ splitNdx ] == '"' ) quotation = !quotation; if( !quotation && str[ splitNdx ] == ' ') { QString section = str.mid( startNdx, splitNdx - startNdx ); startNdx = splitNdx+1; if( section.startsWith( "\"" ) && section.endsWith( "\"" ) && section.length() >=2 ) section = section.mid( 1, section.length()-2 ); if( !section.isEmpty() ) list.append( section ); } splitNdx++; } if( startNdx < splitNdx ) { QString section = str.mid( startNdx, splitNdx - startNdx ); if( section.startsWith( "\"" ) && section.endsWith( "\"" ) && section.length() >=2 ) section = section.mid( 1, section.length()-2 ); if( !section.isEmpty() ) list.append( section ); } return list;}void KRQuery::setNameFilter( const QString &text, bool cs ){ bNull = false; matchesCaseSensitive = cs; origFilter = text; QString matchText = text; QString excludeText; unsigned excludeNdx = 0; bool quotationMark = 0; while( excludeNdx < matchText.length() ) { if( matchText[ excludeNdx ] == '"' ) quotationMark = !quotationMark; if( !quotationMark ) { if( matchText[ excludeNdx ] == '|' ) break; } excludeNdx++; } if( excludeNdx < matchText.length() ) { excludeText = matchText.mid( excludeNdx + 1 ).stripWhiteSpace(); matchText.truncate( excludeNdx ); matchText = matchText.stripWhiteSpace(); if( matchText.isEmpty() ) matchText = "*"; } unsigned i; matches = split( matchText ); includedDirs.clear(); for( i=0; i < matches.count(); ) { if( matches[ i ].endsWith( "/" ) ) { includedDirs.push_back( matches[ i ].left( matches[ i ].length() - 1 ) ); matches.remove( matches.at( i ) ); continue; } if( !matches[ i ].contains( "*" ) && !matches[ i ].contains( "?" ) ) matches[ i ] = "*" + matches[ i ] + "*"; i++; } excludes = split( excludeText ); excludedDirs.clear(); for( i=0; i < excludes.count(); ) { if( excludes[ i ].endsWith( "/" ) ) { excludedDirs.push_back( excludes[ i ].left( excludes[ i ].length() - 1 ) ); excludes.remove( excludes.at( i ) ); continue; } if( !excludes[ i ].contains( "*" ) && !excludes[ i ].contains( "?" ) ) excludes[ i ] = "*" + excludes[ i ] + "*"; i++; }}void KRQuery::setContent( const QString &content, bool cs, bool wholeWord, bool remoteSearch ){ bNull = false; contain = content; containCaseSensetive = cs; containWholeWord = wholeWord; containOnRemote = remoteSearch;}void KRQuery::setMinimumFileSize( KIO::filesize_t minimumSize ){ bNull = false; minSize = minimumSize;}void KRQuery::setMaximumFileSize( KIO::filesize_t maximumSize ){ bNull = false; maxSize = maximumSize;}void KRQuery::setNewerThan( time_t time ){ bNull = false; newerThen = time;}void KRQuery::setOlderThan( time_t time ){ bNull = false; olderThen = time;}void KRQuery::setOwner( const QString &ownerIn ){ bNull = false; owner = ownerIn;}void KRQuery::setGroup( const QString &groupIn ){ bNull = false; group = groupIn;}void KRQuery::setPermissions( const QString &permIn ){ bNull = false; perm = permIn;}void KRQuery::setMimeType( const QString &typeIn, QStringList customList ){ bNull = false; type = typeIn; customType = customList;}bool KRQuery::isExcluded( const KURL &url ){ for ( unsigned int i = 0; i < whereNotToSearch.count(); ++i ) if( whereNotToSearch [ i ].isParentOf( url ) || url.equals( whereNotToSearch [ i ], true ) ) return true; if( !matchDirName( url.fileName() ) ) return true; return false;}void KRQuery::setSearchInDirs( const KURL::List &urls ) { whereToSearch.clear(); for( unsigned int i = 0; i < urls.count(); ++i ) { QString url = urls[ i ].url(); KURL completed = vfs::fromPathOrURL( KURLCompletion::replacedPath( url, true, true ) ); whereToSearch.append( completed ); }}void KRQuery::setDontSearchInDirs( const KURL::List &urls ) { whereNotToSearch.clear(); for( unsigned int i = 0; i < urls.count(); ++i ) { QString url = urls[ i ].url(); KURL completed = vfs::fromPathOrURL( KURLCompletion::replacedPath( url, true, true ) ); whereNotToSearch.append( completed ); }}#include "krquery.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -