void KValueColTextExport::print( TQString &T ) const { int p = 0; int pEnd = NoOfBytesPerLine; // correct boundaries if( PrintLine == CoordRange.start().line() ) p = CoordRange.start().pos(); if( PrintLine == CoordRange.end().line() ) pEnd = CoordRange.end().pos()+1; TQString E; E.setLength( ByteCodec->encodingWidth() ); // draw individual chars uint e = 0; for( ; p<pEnd; ++p, ++PrintData ) { // get next position uint t = Pos[p]; // clear spacing T.append( whiteSpace(t-e) ); ByteCodec->encode( E, 0, *PrintData ); T.append( E ); e = t + ByteCodec->encodingWidth(); } T.append( whiteSpace(NoOfCharsPerLine-e) ); ++PrintLine; }
unsigned long long TDEStorageDevice::deviceSize() { TQString bsnodename = systemPath(); bsnodename.append("/queue/physical_block_size"); TQFile bsfile( bsnodename ); TQString blocksize; if ( bsfile.open( IO_ReadOnly ) ) { TQTextStream stream( &bsfile ); blocksize = stream.readLine(); bsfile.close(); } else { // Drat, I can't get a guaranteed block size. Assume a block size of 512, as everything I have read indicates that /sys/block/<dev>/size is given in terms of a 512 byte block... blocksize = "512"; } TQString dsnodename = systemPath(); dsnodename.append("/size"); TQFile dsfile( dsnodename ); TQString devicesize; if ( dsfile.open( IO_ReadOnly ) ) { TQTextStream stream( &dsfile ); devicesize = stream.readLine(); dsfile.close(); } return ((unsigned long long)blocksize.toULong()*(unsigned long long)devicesize.toULong()); }
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 TokenizerString::toString() const { TQString result; if (!m_pushedChar1.isNull()) { result.append(m_pushedChar1); if (!m_pushedChar2.isNull()) result.append(m_pushedChar2); } m_currentString.appendTo(result); if (m_composite) { TQValueListConstIterator<TokenizerSubstring> i = m_substrings.begin(); TQValueListConstIterator<TokenizerSubstring> e = m_substrings.end(); for (; i != e; ++i) (*i).appendTo(result); } return result; }
// Cut off if more digits in fractional part than 'precision' static void _round(TQString &str, int precision) { int decimalSymbolPos = str.find('.'); if (decimalSymbolPos == -1) if (precision == 0) return; else if (precision > 0) // add dot if missing (and needed) { str.append('.'); decimalSymbolPos = str.length() - 1; } // fill up with more than enough zeroes (in case fractional part too short) str.append(TQString().fill('0', precision)); // Now decide whether to round up or down char last_char = str[decimalSymbolPos + precision + 1].latin1(); switch (last_char) { case '0': case '1': case '2': case '3': case '4': // nothing to do, rounding down break; case '5': case '6': case '7': case '8': case '9': // rounding up _inc_by_one(str, decimalSymbolPos + precision); break; default: break; } decimalSymbolPos = str.find('.'); str.truncate(decimalSymbolPos + precision + 1); // if precision == 0 delete also '.' if (precision == 0) str = str.section('.', 0, 0); }
PrintcapEntry* LprHandler::createEntry(KMPrinter *prt) { // this default handler only supports local parallel and remote lpd URIs KURL uri ( prt->device() ); TQString prot = uri.protocol(); if (!prot.isEmpty() && prot != "parallel" && prot != "file" && prot != "lpd" && prot != "socket") { manager()->setErrorMsg(i18n("Unsupported backend: %1.").arg(prot)); return NULL; } PrintcapEntry *entry = new PrintcapEntry; entry->comment = "# Default handler"; if (prot == "lpd") { entry->addField("rm", Field::String, uri.host()); TQString rp = uri.path(); if (rp[0] == '/') rp = rp.mid(1); entry->addField("rp", Field::String, rp); // force this entry to null (otherwise it seems it's redirected // to /dev/lp0 by default) entry->addField("lp", Field::String, TQString::null); } else if ( prot == "socket" ) { TQString lp = uri.host(); if ( uri.port() == 0 ) lp.append( "%9100" ); else lp.append( "%" ).append( TQString::number( uri.port() ) ); entry->addField("lp", Field::String, lp); } else { entry->addField("lp", Field::String, uri.path()); } return entry; }
bool KRlprPrinterImpl::setupCommand(TQString& cmd, KPrinter *printer) { // retrieve the KMPrinter object, to get host and queue name KMPrinter *rpr = KMFactory::self()->manager()->findPrinter(printer->printerName()); if (!rpr) return false; QString host(rpr->option("host")), queue(rpr->option("queue")); if (!host.isEmpty() && !queue.isEmpty()) { QString exestr = TDEStandardDirs::findExe("rlpr"); if (exestr.isEmpty()) { printer->setErrorMessage(i18n("The <b>%1</b> executable could not be found in your path. Check your installation.").arg("rlpr")); return false; } cmd = TQString::fromLatin1("%1 -H %2 -P %3 -\\#%4").arg(exestr).arg(quote(host)).arg(quote(queue)).arg(printer->numCopies()); // proxy settings TDEConfig *conf = KMFactory::self()->printConfig(); conf->setGroup("RLPR"); QString host = conf->readEntry("ProxyHost",TQString::null), port = conf->readEntry("ProxyPort",TQString::null); if (!host.isEmpty()) { cmd.append(" -X ").append(quote(host)); if (!port.isEmpty()) cmd.append(" --port=").append(port); } return true; } else { printer->setErrorMessage(i18n("The printer is incompletely defined. Try to reinstall it.")); return false; } }
void TDECompletion::extractStringsFromNode( const TDECompTreeNode *node, const TQString& beginning, TDECompletionMatchesWrapper *matches, bool addWeight ) const { if ( !node || !matches ) return; // kDebug() << "Beginning: " << beginning << endl; const TDECompTreeChildren *list = node->children(); TQString string; TQString w; // loop thru all children for ( TDECompTreeNode *cur = list->begin(); cur ; cur = cur->next) { string = beginning; node = cur; if ( !node->isNull() ) string += *node; while ( node && node->childrenCount() == 1 ) { node = node->firstChild(); if ( node->isNull() ) break; string += *node; } if ( node && node->isNull() ) { // we found a leaf if ( addWeight ) { // add ":num" to the string to store the weighting string += ':'; w.setNum( node->weight() ); string.append( w ); } matches->append( node->weight(), string ); } // recursively find all other strings. if ( node && node->childrenCount() > 1 ) extractStringsFromNode( node, string, matches, addWeight ); } }
TQString ApsHandler::printOptions(KPrinter *printer) { TQString optstr; TQMap<TQString,TQString> opts = printer->options(); for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it) { if (it.key().startsWith("kde-") || it.key().startsWith("_kde-") || it.key().startsWith( "app-" )) continue; optstr.append((*it)).append(":"); } if (!optstr.isEmpty()) { optstr = optstr.left(optstr.length()-1); if (LprSettings::self()->mode() == LprSettings::LPR) optstr.prepend("-C '").append("'"); else optstr.prepend("-Z '").append("'"); } return optstr; }
void KMWEnd::initPrinter(KMPrinter *p) { TQString txt; TQString s(TQString::fromLatin1("<li><u>%1</u>: %2</li>")); int ID = p->option("kde-backend").toInt(); // general information txt.append(TQString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("General"))); txt.append(s.arg(i18n("Type")).arg(p->option("kde-backend-description"))); txt.append(s.arg(i18n("Name")).arg(p->name())); txt.append(s.arg(i18n("Location")).arg(p->location())); txt.append(s.arg(i18n("Description")).arg(p->description())); txt.append("</ul><br>"); if (ID == KMWizard::Class) { // class members txt.append(TQString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Members"))); TQStringList m(p->members()); TQString s1(TQString::fromLatin1("<li>%1</li>")); for (TQStringList::ConstIterator it=m.begin(); it!=m.end(); ++it) txt.append(s1.arg(*it)); txt.append("</ul><br>"); } else { // backend information txt.append(TQString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Backend"))); KURL url ( p->device() ); switch (ID) { case KMWizard::Local: txt.append(s.arg(i18n("Device")).arg(url.path())); break; case KMWizard::TCP: txt.append(s.arg(i18n("Printer IP")).arg(url.host())); txt.append(s.arg(i18n("Port")).arg(url.port())); break; case KMWizard::LPD: txt.append(s.arg(i18n("Host")).arg(url.host())); txt.append(s.arg(i18n("Queue")).arg(url.path().right(url.path().length()-1))); break; case KMWizard::File: txt.append(s.arg(i18n("File")).arg(url.path())); break; case KMWizard::IPP: txt.append(s.arg(i18n("Host")).arg(url.host())); txt.append(s.arg(i18n("Port")).arg(url.port())); txt.append(s.arg(i18n("Printer")).arg(url.path().right(url.path().length()-1))); if (url.hasUser()) txt.append(s.arg(i18n("Account")).arg(url.user())); break; default: // double decoding in case the printer name contains chars like '#' that are // not decoded by "prettyURL". txt.append(s.arg(i18n("URI")).arg(KURL( p->device()).prettyURL())); break; } txt.append("</ul><br>"); if (p->option("kde-driver") == "raw" || p->driver()) { // driver information txt.append(TQString::fromLatin1("<b>%1</b><ul type=circle>").arg(i18n("Driver"))); if (p->option("kde-driver") == "raw") txt.append(s.arg(i18n("Type")).arg(i18n("Raw printer"))); else { txt.append(s.arg(i18n("Type")).arg((p->dbEntry() ? i18n("DB driver") : i18n("External driver")))); txt.append(s.arg(i18n("Manufacturer")).arg(p->manufacturer())); txt.append(s.arg(i18n("Model")).arg(p->model())); txt.append(s.arg(i18n("Description")).arg(p->driverInfo())); } txt.append("</ul><br>"); } } m_view->setText(txt); }
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) { int internal_retcode; if (!retcode) { retcode = &internal_retcode; } TQString ret = mountPath(); if (!ret.isNull()) { return ret; } // Create dummy password file KTempFile passwordFile(TQString::null, "tmp", 0600); passwordFile.setAutoDelete(true); TQFile* pwFile = passwordFile.file(); if (!pwFile) { return TQString::null; } pwFile->writeBlock(passphrase.ascii(), passphrase.length()); pwFile->flush(); TQString optionString; if (mountOptions["ro"] == "true") { optionString.append(" -r"); } if (mountOptions["atime"] != "true") { optionString.append(" -A"); } if (mountOptions["utf8"] == "true") { optionString.append(" -c utf8"); } if (mountOptions["sync"] == "true") { optionString.append(" -s"); } if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); } if (mountOptions.contains("locale")) { optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); } TQString passFileName = passwordFile.name(); TQString devNode = deviceNode(); passFileName.replace("'", "'\\''"); devNode.replace("'", "'\\''"); mediaName.replace("'", "'\\''"); TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); FILE *exepipe = popen(command.local8Bit(), "r"); if (exepipe) { TQString mount_output; TQTextStream ts(exepipe, IO_ReadOnly); mount_output = ts.read(); *retcode = pclose(exepipe); if (errRet) { *errRet = mount_output; } } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; }
TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet, int* retcode) { int internal_retcode; if (!retcode) { retcode = &internal_retcode; } TQString ret = mountPath(); // Device is already mounted if (!ret.isNull()) { return ret; } TQString command; TQString devNode = deviceNode(); devNode.replace("'", "'\\''"); mediaName.replace("'", "'\\''"); #if defined(WITH_UDISKS2) || defined(WITH_UDISKS) // Prepare filesystem options for mount TQStringList udisksOptions; TQString optionString; if (mountOptions["ro"] == "true") { udisksOptions.append("ro"); } if (mountOptions["atime"] != "true") { udisksOptions.append("noatime"); } if (mountOptions["sync"] == "true") { udisksOptions.append("sync"); } if( (mountOptions["filesystem"] == "fat") || (mountOptions["filesystem"] == "vfat") || (mountOptions["filesystem"] == "msdos") || (mountOptions["filesystem"] == "umsdos") ) { if (mountOptions.contains("shortname")) { udisksOptions.append(TQString("shortname=%1").arg(mountOptions["shortname"])); } } if( (mountOptions["filesystem"] == "jfs")) { if (mountOptions["utf8"] == "true") { // udisks/udisks2 for now does not support option iocharset= for jfs // udisksOptions.append("iocharset=utf8"); } } if( (mountOptions["filesystem"] == "ntfs-3g") ) { if (mountOptions.contains("locale")) { udisksOptions.append(TQString("locale=%1").arg(mountOptions["locale"])); } } if( (mountOptions["filesystem"] == "ext3") || (mountOptions["filesystem"] == "ext4") ) { if (mountOptions.contains("journaling")) { // udisks/udisks2 for now does not support option data= for ext3/ext4 // udisksOptions.append(TQString("data=%1").arg(mountOptions["journaling"])); } } for (TQStringList::Iterator it = udisksOptions.begin(); it != udisksOptions.end(); ++it) { optionString.append(","); optionString.append(*it); } if (!optionString.isEmpty()) { optionString.remove(0, 1); } #endif // defined(WITH_UDISKS2) || defined(WITH_UDISKS) #ifdef WITH_UDISKS2 if(command.isEmpty()) { // Try to use UDISKS v2 via DBUS, if available TQString errorString; TQString fileSystemType; if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { fileSystemType = mountOptions["filesystem"]; } int uDisks2Ret = mountDriveUDisks2(devNode, fileSystemType, optionString, &errorString); if (uDisks2Ret == 0) { // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; } else if (uDisks2Ret == -1) { if (errRet) { *errRet = errorString; } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; } else { // The UDISKS v2 DBUS service was either not available or was unusable; try another method... command = TQString::null; } } #endif // WITH_UDISKS2 #ifdef WITH_UDISKS if(command.isEmpty()) { // Try to use UDISKS v1 via DBUS, if available TQString errorString; TQString fileSystemType; if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { fileSystemType = mountOptions["filesystem"]; } int uDisksRet = mountDriveUDisks(devNode, fileSystemType, udisksOptions, &errorString); if (uDisksRet == 0) { // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; } else if (uDisksRet == -1) { if (errRet) { *errRet = errorString; } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; } else { // The UDISKS v1 DBUS service was either not available or was unusable; try another method... command = TQString::null; } } #endif // WITH_UDISKS if(command.isEmpty()) { // Use 'pmount' command, if available TQString pmountProg = TDEGlobal::dirs()->findExe("pmount"); if (!pmountProg.isEmpty()) { // Create dummy password file KTempFile passwordFile(TQString::null, "tmp", 0600); passwordFile.setAutoDelete(true); TQString optionString; if (mountOptions["ro"] == "true") { optionString.append(" -r"); } if (mountOptions["atime"] != "true") { optionString.append(" -A"); } if (mountOptions["utf8"] == "true") { optionString.append(" -c utf8"); } if (mountOptions["sync"] == "true") { optionString.append(" -s"); } if (mountOptions.contains("filesystem") && !mountOptions["filesystem"].isEmpty()) { optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); } if (mountOptions.contains("locale")) { optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); } TQString passFileName = passwordFile.name(); passFileName.replace("'", "'\\''"); command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); } } if(command.isEmpty()) { if (errRet) { *errRet = i18n("No supported mounting methods were detected on your system"); } return ret; } FILE *exepipe = popen(command.local8Bit(), "r"); if (exepipe) { TQString mount_output; TQTextStream ts(exepipe, IO_ReadOnly); mount_output = ts.read(); *retcode = pclose(exepipe); if (errRet) { *errRet = mount_output; } } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); ret = mountPath(); return ret; }
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; }
void KBorderColTextExport::print( TQString &T ) const { T.append( " | " ); }