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; }
MANProtocol::MANProtocol(const TQCString &pool_socket, const TQCString &app_socket) : TQObject(), SlaveBase("man", pool_socket, app_socket) { assert(!_self); _self = this; const TQString common_dir = TDEGlobal::dirs()->findResourceDir( "html", "en/common/tde-common.css" ); const TQString strPath=TQString( "file:%1/en/common" ).arg( common_dir ); m_htmlPath=strPath.local8Bit(); // ### TODO encode for HTML m_cssPath=strPath.local8Bit(); // ### TODO encode for CSS section_names << "1" << "2" << "3" << "3n" << "3p" << "4" << "5" << "6" << "7" << "8" << "9" << "l" << "n"; m_manCSSFile = locate( "data", "tdeio_man/tdeio_man.css" ); }
void KMMainView::slotToolSelected(int ID) { KMTimer::self()->hold(); TQString libname = m_toollist[ID]; libname.prepend("tdeprint_tool_"); if (m_current && !m_current->device().isEmpty() && !libname.isEmpty()) { KLibFactory *factory = KLibLoader::self()->factory(libname.local8Bit()); if (factory) { TQStringList args; args << m_current->device() << m_current->printerName(); KDialogBase *dlg = static_cast<KDialogBase*>(TQT_TQWIDGET(factory->create(TQT_TQOBJECT(this), "Tool", 0, args))); if (dlg) dlg->exec(); delete dlg; } } else KMessageBox::error(this, i18n("Unable to start printer tool. Possible reasons are: " "no printer selected, the selected printer doesn't have " "any local device defined (printer port), or the tool library " "could not be found.")); KMTimer::self()->release(); }
// antlarr: KDE 4: Make it const TQString & KShred::KShred(TQString fileName) { if (fileName.isEmpty()) { kdError() << "KShred: missing file name in constructor" << endl; file = 0L; } else { file = new TQFile(); file->setName(fileName); if (!file->open(IO_ReadWrite)) { kdError() << "KShred: cannot open file '" << fileName.local8Bit().data() << "' for writing\n" << endl; file = 0L; fileSize = 0; } else fileSize = file->size(); totalBytes = 0; bytesWritten = 0; lastSignalled = 0; tbpc = 0; fspc = 0; } }
static void updatePoliciesConfig(TDEConfig *cfg) { TQStringList groups = cfg->groupList(); for (TQStringList::Iterator i = groups.begin(); i != groups.end(); ++i) { if ((*i).isEmpty() || *i == "General") { continue; } cfg->setGroup(*i); // remove it if it has expired if (!cfg->readBoolEntry("Permanent") && cfg->readDateTimeEntry("Expires") < TQDateTime::currentDateTime()) { cfg->deleteGroup(*i); continue; } TQString encodedCertStr = cfg->readEntry("Certificate"); TQCString encodedCert = encodedCertStr.local8Bit(); KSSLCertificate *newCert = KSSLCertificate::fromString(encodedCert); if (!newCert) { cfg->deleteGroup(*i); continue; } KSSLCertificateCache::KSSLCertificatePolicy policy = (KSSLCertificateCache::KSSLCertificatePolicy) cfg->readNumEntry("Policy"); bool permanent = cfg->readBoolEntry("Permanent"); TQDateTime expires = cfg->readDateTimeEntry("Expires"); TQStringList hosts = cfg->readListEntry("Hosts"); TQStringList chain = cfg->readListEntry("Chain"); cfg->deleteGroup(*i); cfg->setGroup(newCert->getMD5Digest()); cfg->writeEntry("Certificate", encodedCertStr); cfg->writeEntry("Policy", policy); cfg->writeEntry("Permanent", permanent); cfg->writeEntry("Expires", expires); cfg->writeEntry("Hosts", hosts); cfg->writeEntry("Chain", chain); delete newCert; } cfg->setGroup("General"); cfg->writeEntry("policies version", 2); cfg->sync(); }
bool KSSLD::caAdd(TQString certificate, bool ssl, bool email, bool code) { KSSLCertificate *x = KSSLCertificate::fromString(certificate.local8Bit()); if (!x) return false; TDEConfig cfg("ksslcalist", false, false); cfg.setGroup(x->getSubject()); cfg.writeEntry("x509", certificate); cfg.writeEntry("site", ssl); cfg.writeEntry("email", email); cfg.writeEntry("code", code); cfg.sync(); delete x; return true; }
bool KSSLD::caRemoveFromFile(TQString filename) { TQStringList certificates; certificates = caReadCerticatesFromFile(filename); if (certificates.isEmpty()) return false; bool ok = true; for (TQStringList::Iterator it = certificates.begin(); it != certificates.end(); ++it ) { TQString certificate = *it; KSSLCertificate *x = KSSLCertificate::fromString(certificate.local8Bit()); ok &= x && caRemove(x->getSubject()); delete x; } return ok; }
int main( int argc, char **argv ) { TDECmdLineArgs::init( argc, argv, "tdetradertest", "TDETradertest", "A TDETrader testing tool", "0.0" ); TDECmdLineArgs::addCmdLineOptions( options ); TDEApplication app( false, false ); // no GUI TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); if ( args->count() < 1 ) TDECmdLineArgs::usage(); TQString query = TQString::fromLocal8Bit( args->arg( 0 ) ); TQString genericServiceType, constraint, preference; if ( args->count() >= 2 ) genericServiceType = TQString::fromLocal8Bit( args->arg( 1 ) ); if ( args->count() >= 3 ) constraint = TQString::fromLocal8Bit( args->arg( 2 ) ); if ( args->count() == 4 ) preference = TQString::fromLocal8Bit( args->arg( 3 ) ); printf( "query is : %s\n", query.local8Bit().data() ); printf( "genericServiceType is : %s\n", genericServiceType.local8Bit().data() ); printf( "constraint is : %s\n", constraint.local8Bit().data() ); printf( "preference is : %s\n", preference.local8Bit().data() ); TDETrader::OfferList offers = TDETrader::self()->query( query, genericServiceType, constraint, preference ); printf("got %d offers.\n", offers.count()); int i = 0; TDETrader::OfferList::ConstIterator it = offers.begin(); TDETrader::OfferList::ConstIterator end = offers.end(); for (; it != end; ++it, ++i ) { printf("---- Offer %d ----\n", i); TQStringList props = (*it)->propertyNames(); TQStringList::ConstIterator propIt = props.begin(); TQStringList::ConstIterator propEnd = props.end(); for (; propIt != propEnd; ++propIt ) { TQVariant prop = (*it)->property( *propIt ); if ( !prop.isValid() ) { printf("Invalid property %s\n", (*propIt).local8Bit().data()); continue; } TQString outp = *propIt; outp += " : '"; switch ( prop.type() ) { case TQVariant::StringList: outp += prop.toStringList().join(" - "); break; case TQVariant::Bool: outp += prop.toBool() ? "TRUE" : "FALSE"; break; default: outp += prop.toString(); break; } if ( !outp.isEmpty() ) printf("%s'\n", outp.local8Bit().data()); } } }
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; }
bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) { int internal_retcode; if (!retcode) { retcode = &internal_retcode; } TQString mountpoint = mountPath(); TQString devNode = deviceNode(); if (mountpoint.isNull()) { return true; } mountpoint.replace("'", "'\\''"); TQString command; #ifdef WITH_UDISKS2 if(command.isEmpty()) { // Try to use UDISKS v2 via DBUS, if available TQString errorString; int unMountUDisks2Ret = unMountDriveUDisks2(devNode, TQString::null, &errorString); if (unMountUDisks2Ret == 0) { // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return true; } else if (unMountUDisks2Ret == -1) { if (errRet) { *errRet = errorString; } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return false; } 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; int unMountUDisksRet = unMountDriveUDisks(devNode, TQStringList(), &errorString); if (unMountUDisksRet == 0) { // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return true; } else if (unMountUDisksRet == -1) { if (errRet) { *errRet = errorString; } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return false; } 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() && !(TDEGlobal::dirs()->findExe("pumount").isEmpty())) { command = TQString("pumount '%1' 2>&1").arg(mountpoint); } if(command.isEmpty()) { if (errRet) { *errRet = i18n("No supported unmounting methods were detected on your system"); } return true; } FILE *exepipe = popen(command.local8Bit(), "r"); if (exepipe) { TQString umount_output; TQTextStream ts(exepipe, IO_ReadOnly); umount_output = ts.read(); *retcode = pclose(exepipe); if (*retcode == 0) { // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return true; } else { if (errRet) { *errRet = umount_output; } } } // Update internal mount data TDEGlobal::hardwareDevices()->processModifiedMounts(); return false; }
void EvaUserSetting::loadMsgToSql(const TQString fullName,const bool isQunMsg) { TQFile file(fullName); if(!file.open(IO_ReadOnly)) return ; TQString fullNameSql = getEvaUserDir() + "/"+SqlFileName; int result; char * errmsg = NULL; char **dbResult; int nRow, nColumn,i=0; sqlite3 *db=NULL; result=sqlite3_open(fullNameSql.data(),&db); if( result != SQLITE_OK ) return; TQString sql; sqlite3_exec( db,"begin transaction;",0,0,&errmsg); TQ_UINT32 r_buddy; TQ_UINT32 sender; TQString sNick; TQ_UINT32 receiver; TQString rNick; TQ_UINT8 type; // 0 auto reply, 1 normal TQString message; TQ_UINT32 intTime; TQDateTime time; TQ_UINT8 fontSize; TQ_UINT8 flag; // start from right. bit 0: u, bit 1: i, bit 2: b TQ_UINT8 blue; TQ_UINT8 green; TQ_UINT8 red; TQDataStream stream(&file); std::list<chatMessage>srclist; while(!stream.atEnd()){ stream>>r_buddy; stream>>sender; stream>>sNick; stream>>receiver; stream>>rNick; stream>>type; stream>>message; stream>>intTime; stream>>fontSize; stream>>flag; stream>>blue; stream>>green; stream>>red; sql.sprintf("select sender from chat where sender=%d and receiver=%d and time=%d and isQunMsg=%d ",sender,receiver,intTime,isQunMsg); result = sqlite3_get_table(db,sql.utf8().data(), &dbResult,&nRow, &nColumn, &errmsg); if( SQLITE_OK != result ) { sqlite3_exec( db,"commit transaction;",0,0,&errmsg); return; } if(nRow>0) continue; //找到重复的记录 i++; sql.sprintf("insert into chat values (%d,%d,'%s', %d,'%s',%d, '%s', %d,%d, %d, %d,%d,%d,%d)",r_buddy,sender,sNick.local8Bit().data(),receiver,rNick.local8Bit().data(),type,message.local8Bit().data(),intTime,fontSize,flag,blue,green,red,isQunMsg); sqlite3_exec( db , sql.utf8().data() , 0 , 0 , &errmsg ); } printf("load %s %i条\n",fullName.data(),i); sqlite3_exec( db,"commit transaction;",0,0,&errmsg); file.close(); TQString newfile; newfile=fullName+".old"; unlink(newfile.local8Bit().data()); rename(fullName.local8Bit().data(),newfile.local8Bit().data()); return ; }