KeyboardTranslator::Entry KeyboardTranslatorReader::createEntry( const QString& condition , const QString& result ) { QString entryString("keyboard \"temporary\"\nkey "); entryString.append(condition); entryString.append(" : "); // if 'result' is the name of a command then the entry result will be that command, // otherwise the result will be treated as a string to echo when the key sequence // specified by 'condition' is pressed KeyboardTranslator::Command command; if (parseAsCommand(result,command)) entryString.append(result); else entryString.append('\"' + result + '\"'); QByteArray array = entryString.toUtf8(); KeyboardTranslator::Entry entry; QBuffer buffer(&array); buffer.open(QIODevice::ReadOnly); KeyboardTranslatorReader reader(&buffer); if ( reader.hasNextEntry() ) entry = reader.nextEntry(); return entry; }
const std::string toString( ) { std::stringstream ss; ss << "{"; int size = outputs.size(); for( int i = 0; i != size; ++i ) { Entry* e = outputs.front(); outputs.pop(); ss << entryString( e ); if( i != size-1 ) ss << ", "; delete e; } ss << "}"; return ss.str(); }
void FindWindow::FindResults(void) { // This function is called from the FinderThread function, so locking is // required when accessing any member variables. Lock(); bool canReplace = fReplaceButton->IsEnabled(); EnableReplace(false); for (int32 i = fResultList->CountItems() - 1; i >= 0; i--) { // We don't want to hog the window lock, but we also don't want // tons of context switches, either. Yielding the lock every 5 items // should give us sufficient responsiveness. if (i % 5 == 0) { Unlock(); Lock(); } BListItem *item = fResultList->RemoveItem(i); delete item; } Unlock(); ShellHelper shell; shell << "cd "; shell.AddEscapedArg(fWorkingDir); shell << "; pwd; find . -type f "; shell << "|xargs grep -n -H -s --binary-files=without-match "; // TODO check for PCRE invocation and pass in pcre flag to grep if so // TODO Ensure RE escaping also happens (E.g. open/close paran etc.) shell.AddEscapedArg(fFindBox->Text()); if (fThreadQuitFlag) return; BString out; shell.RunInPipe(out, false); if (fThreadQuitFlag) return; BObjectList<BString> resultList(20, true); TokenizeToList(out.String(), resultList); Lock(); for (int32 i = 0; i < resultList.CountItems(); i++) { // We don't want to hog the window lock, but we also don't want // tons of context switches, either. Yielding the lock every 5 items // should give us sufficient responsiveness. if (i % 5 == 0) { Unlock(); Lock(); } BString entryString(resultList.ItemAt(i)->String()); BString filename(entryString); int32 pos = filename.FindFirst(":"); if (pos < 0) continue; filename.Truncate(pos); if (filename.StartsWith("./")) filename.Remove(0,2); STRACE(2,("Truncated file name from grep: %s\n",filename.String())); BString lineString; entryString.CopyInto(lineString, pos + 1, entryString.CountChars() - pos); int32 pos2 = lineString.FindFirst(":"); BString locationString; lineString.CopyInto(locationString, pos2 + 1, lineString.CountChars() - pos2); lineString.Truncate(pos2); DPath entryPath(fWorkingDir); entryPath << filename; BString fullPath(fWorkingDir); fullPath << "/" << filename; STRACE(2,("Full path: %s\n",fullPath.String())); DPath relPath(filename); fResultList->AddItem(new GrepListItem(fullPath,filename, entryPath.GetRef(), atol(lineString.String()), locationString.String())); } EnableReplace(true); if (fResultList->CountItems() == 0) fResultList->AddItem(new BStringItem(B_TRANSLATE("No matches found"))); Unlock(); }