TQString TDEStorageDevice::mountPath() { // See if this device node is mounted // This requires parsing /proc/mounts, looking for deviceNode() // The Device Mapper throws a monkey wrench into this // It likes to advertise mounts as /dev/mapper/<something>, // where <something> is listed in <system path>/dm/name // First, ensure that all device information (mainly holders/slaves) is accurate TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TQString dmnodename = systemPath(); dmnodename.append("/dm/name"); TQFile namefile( dmnodename ); TQString dmaltname; if ( namefile.open( IO_ReadOnly ) ) { TQTextStream stream( &namefile ); dmaltname = stream.readLine(); namefile.close(); } if (!dmaltname.isNull()) { dmaltname.prepend("/dev/mapper/"); } TQStringList lines; TQFile file( "/proc/mounts" ); if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); TQString line; while ( !stream.atEnd() ) { line = stream.readLine(); TQStringList mountInfo = TQStringList::split(" ", line, true); TQString testNode = *mountInfo.at(0); // Check for match if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) { TQString ret = *mountInfo.at(1); ret.replace("\\040", " "); return ret; } lines += line; } file.close(); } // While this device is not directly mounted, it could concievably be mounted via the Device Mapper // If so, try to retrieve the mount path... TQStringList slaveDeviceList = holdingDevices(); for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) { // Try to locate this device path in the TDE device tree TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit); if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice); return sdevice->mountPath(); } } return TQString::null; }
TQString TDEStorageDevice::determineFileSystemType(TQString path) { TQStringList mountTable; TQString prevPath = path; dev_t prevDev = 0; int pos; struct stat directory_info; if (path.startsWith("/")) { stat(path.local8Bit(), &directory_info); prevDev = directory_info.st_dev; // Walk the directory tree up to the root, checking for any change in st_dev // If a change is found, the previous value of path is the mount point itself while (path != "/") { pos = path.findRev("/", -1, TRUE); if (pos < 0) { break; } path = path.mid(0, pos); if (path == "") { path = "/"; } stat(path.local8Bit(), &directory_info); if (directory_info.st_dev != prevDev) { break; } prevPath = path; prevDev = directory_info.st_dev; } } // Read in mount table mountTable.clear(); TQFile file( "/proc/mounts" ); if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); while ( !stream.atEnd() ) { mountTable.append(stream.readLine()); } file.close(); } // Parse mount table TQStringList::Iterator it; for ( it = mountTable.begin(); it != mountTable.end(); ++it ) { TQStringList mountInfo = TQStringList::split(" ", (*it), true); if ((*mountInfo.at(1)) == prevPath) { return (*mountInfo.at(2)); } } // Unknown file system type return TQString::null; }
TQString KStringHandler::word( const TQString &text , const char *range ) { // Format in: START:END // Note index starts a 0 (zero) // // 0: first word to end // 1:3 second to fourth words TQStringList list = TQStringList::split( " ", text , true ); TQString tmp = ""; TQString r = range; if ( text.isEmpty() ) return tmp; uint pos = 0, cnt = list.count(); parsePythonRange( range, pos, cnt ); // // Extract words // int wordsToExtract = cnt-pos+1; TQStringList::Iterator it = list.at( pos); while ( (it != list.end()) && (wordsToExtract-- > 0)) { tmp += *it; tmp += " "; it++; } return tmp.stripWhiteSpace(); }
TQString KStringHandler::remrange( const TQString &text , const char *range ) { // Format in: START:END // Note index starts a 0 (zero) // // 0: first word to end // 1:3 second to fourth words TQStringList list = TQStringList::split( " ", text , true ); TQString tmp = ""; TQString r = range; if ( text.isEmpty() ) return tmp; uint pos = 0, cnt = list.count(); parsePythonRange( range, pos, cnt ); // // Remove that range of words // int wordsToDelete = cnt-pos+1; TQStringList::Iterator it = list.at( pos); while ( (it != list.end()) && (wordsToDelete-- > 0)) it = list.remove( it ); return list.join( " " ); }
TQString KStringHandler::remword( const TQString &text , uint pos ) { TQString tmp = ""; if ( text.isEmpty() ) return tmp; // Split words and add into list TQStringList list = TQStringList::split( " ", text, true ); if ( pos < list.count() ) list.remove( list.at( pos ) ); // Rejoin return list.join( " " ); }
// // Insertion and removal routines // TQString KStringHandler::insword( const TQString &text , const TQString &word , uint pos ) { if ( text.isEmpty() ) return word; if ( word.isEmpty() ) return text; // Split words and add into list TQStringList list = TQStringList::split( " ", text, true ); if ( pos >= list.count() ) list.append( word ); else list.insert( list.at(pos) , word ); // Rejoin return list.join( " " ); }
TQString TQtRegExpConverter::toString( TextRangeRegExp* regexp, bool /*markSelection*/ ) { TQString txt; bool foundCarrot = false; bool foundDash = false; bool foundParenthesis = false; // Now print the rest of the single characters, but keep "^" as the very // last element of the characters. TQStringList chars = regexp->chars(); for (unsigned int i = 0; i< chars.count(); i++) { if ( *chars.at(i) == TQChar( ']' ) ) { foundParenthesis = true; } else if ( *chars.at(i) == TQChar( '-' ) ) { foundDash = true; } else if ( *chars.at(i) == TQChar( '^' ) ) { foundCarrot = true; } else { txt.append( *chars.at(i) ); } } // Now insert the ranges. TQPtrList<StringPair> ranges = regexp->range(); for ( TQPtrListIterator<StringPair> it(ranges); *it; ++it ) { txt.append((*it)->first()+ TQString::fromLatin1("-")+ (*it)->second()); } // Ok, its time to build each part of the regexp, here comes the rule: // if a ']' is one of the characters, then it must be the first one in the // list (after then opening '[' and eventually negation '^') // Next if a '-' is one of the characters, then it must come // finally if '^' is one of the characters, then it must not be the first // one! TQString res = TQString::fromLatin1("["); if ( regexp->negate() ) res.append(TQString::fromLatin1("^")); // a ']' must be the first character in teh range. if ( foundParenthesis ) { res.append(TQString::fromLatin1("]")); } // a '-' must be the first character ( only coming after a ']') if ( foundDash ) { res.append(TQString::fromLatin1("-")); } res += txt; // Insert \s,\S,\d,\D,\w, and \W if ( regexp->digit() ) res += TQString::fromLocal8Bit("\\d"); if ( regexp->nonDigit() ) res += TQString::fromLocal8Bit("\\D"); if ( regexp->space() ) res += TQString::fromLocal8Bit("\\s"); if ( regexp->nonSpace() ) res += TQString::fromLocal8Bit("\\S"); if ( regexp->wordChar() ) res += TQString::fromLocal8Bit("\\w"); if ( regexp->nonWordChar() ) res += TQString::fromLocal8Bit("\\W"); if ( foundCarrot ) { res.append( TQChar( '^' ) ); } res.append(TQString::fromLatin1("]")); return res; }