void KBuildSycoca::processGnomeVfs() { TQString file = locate("app-reg", "gnome-vfs.applications"); if (file.isEmpty()) { // kdDebug(7021) << "gnome-vfs.applications not found." << endl; return; } TQString app; char line[1024*64]; FILE *f = fopen(TQFile::encodeName(file), "r"); while (!feof(f)) { if (!fgets(line, sizeof(line)-1, f)) { break; } if (line[0] != '\t') { app = TQString::fromLatin1(line); app.truncate(app.length()-1); } else if (strncmp(line+1, "mime_types=", 11) == 0) { TQString mimetypes = TQString::fromLatin1(line+12); mimetypes.truncate(mimetypes.length()-1); mimetypes.replace(TQRegExp("\\*"), "all"); KService *s = g_bsf->findServiceByName(app); if (!s) continue; TQStringList &serviceTypes = s->accessServiceTypes(); if (serviceTypes.count() <= 1) { serviceTypes += TQStringList::split(',', mimetypes); // kdDebug(7021) << "Adding gnome mimetypes for '" << app << "'.\n"; // kdDebug(7021) << "ServiceTypes=" << s->serviceTypes().join(":") << endl; } } } fclose( f ); }
/** * Test if a directory exists, create otherwise * @param _name full path of the directory * @return errorcode, or 0 if the dir was created or existed already * Warning, don't use return value like a bool */ int TrashImpl::testDir( const TQString &_name ) const { DIR *dp = opendir( TQFile::encodeName(_name) ); if ( dp == NULL ) { TQString name = _name; if ( name.endsWith( "/" ) ) name.truncate( name.length() - 1 ); TQCString path = TQFile::encodeName(name); bool ok = ::mkdir( path, S_IRWXU ) == 0; if ( !ok && errno == EEXIST ) { #if 0 // this would require to use SlaveBase's method to ask the question //int ret = KMessageBox::warningYesNo( 0, i18n("%1 is a file, but TDE needs it to be a directory. Move it to %2.orig and create directory?").arg(name).arg(name) ); //if ( ret == KMessageBox::Yes ) { #endif if ( ::rename( path, path + ".orig" ) == 0 ) { ok = ::mkdir( path, S_IRWXU ) == 0; } else { // foo.orig existed already. How likely is that? ok = false; } if ( !ok ) { return TDEIO::ERR_DIR_ALREADY_EXIST; } #if 0 //} else { // return 0; //} #endif } if ( !ok ) { //KMessageBox::sorry( 0, i18n( "Couldn't create directory %1. Check for permissions." ).arg( name ) ); kdWarning() << "could not create " << name << endl; return TDEIO::ERR_COULD_NOT_MKDIR; } else { kdDebug() << name << " created." << endl; } } else // exists already { closedir( dp ); } return 0; // success }
// 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); }
TrashImpl::TrashedFileInfoList TrashImpl::list() { // Here we scan for trash directories unconditionally. This allows // noticing plugged-in [e.g. removeable] devices, or new mounts etc. scanTrashDirectories(); TrashedFileInfoList lst; // For each known trash directory... TrashDirMap::const_iterator it = m_trashDirectories.begin(); for ( ; it != m_trashDirectories.end() ; ++it ) { const int trashId = it.key(); TQString infoPath = it.data(); infoPath += "/info"; // Code taken from tdeio_file TQStrList entryNames = listDir( infoPath ); //char path_buffer[PATH_MAX]; //getcwd(path_buffer, PATH_MAX - 1); //if ( chdir( infoPathEnc ) ) // continue; TQStrListIterator entryIt( entryNames ); for (; entryIt.current(); ++entryIt) { TQString fileName = TQFile::decodeName( *entryIt ); if ( fileName == "." || fileName == ".." ) continue; if ( !fileName.endsWith( ".trashinfo" ) ) { kdWarning() << "Invalid info file found in " << infoPath << " : " << fileName << endl; continue; } fileName.truncate( fileName.length() - 10 ); TrashedFileInfo info; if ( infoForFile( trashId, fileName, info ) ) lst << info; } } return lst; }
TQStringList readAreaList() { TQStringList lst; lst.append( "0 (generic)" ); TQString confAreasFile = locate( "config", "kdebug.areas" ); TQFile file( confAreasFile ); if (!file.open(IO_ReadOnly)) { kdWarning() << "Couldn't open " << confAreasFile << endl; file.close(); } else { TQString data; TQTextStream *ts = new TQTextStream(&file); ts->setEncoding( TQTextStream::Latin1 ); while (!ts->eof()) { data = ts->readLine().simplifyWhiteSpace(); int pos = data.find("#"); if ( pos != -1 ) data.truncate( pos ); if (data.isEmpty()) continue; lst.append( data ); } delete ts; file.close(); } return lst; }
bool tdeio_isoProtocol::checkNewFile( TQString fullPath, TQString & path, int startsec ) { kdDebug() << "tdeio_isoProtocol::checkNewFile " << fullPath << " startsec: " << startsec << endl; // Are we already looking at that file ? if ( m_isoFile && startsec == m_isoFile->startSec() && m_isoFile->fileName() == fullPath.left(m_isoFile->fileName().length()) ) { // Has it changed ? struct stat statbuf; if ( ::stat( TQFile::encodeName( m_isoFile->fileName() ), &statbuf ) == 0 ) { if ( m_mtime == statbuf.st_mtime ) { path = fullPath.mid( m_isoFile->fileName().length() ); kdDebug() << "tdeio_isoProtocol::checkNewFile returning " << path << endl; return true; } } } kdDebug() << "Need to open a new file" << endl; // Close previous file if ( m_isoFile ) { m_isoFile->close(); delete m_isoFile; m_isoFile = 0L; } // Find where the iso file is in the full path int pos = 0; TQString isoFile; path = TQString::null; int len = fullPath.length(); if ( len != 0 && fullPath[ len - 1 ] != '/' ) fullPath += '/'; kdDebug() << "the full path is " << fullPath << endl; while ( (pos=fullPath.find( '/', pos+1 )) != -1 ) { TQString tryPath = fullPath.left( pos ); kdDebug() << fullPath << " trying " << tryPath << endl; KDE_struct_stat statbuf; if ( KDE_lstat( TQFile::encodeName(tryPath), &statbuf ) == 0 && !S_ISDIR(statbuf.st_mode) ) { isoFile = tryPath; m_mtime = statbuf.st_mtime; m_mode = statbuf.st_mode; path = fullPath.mid( pos + 1 ); kdDebug() << "fullPath=" << fullPath << " path=" << path << endl; len = path.length(); if ( len > 1 ) { if ( path[ len - 1 ] == '/' ) path.truncate( len - 1 ); } else path = TQString::fromLatin1("/"); kdDebug() << "Found. isoFile=" << isoFile << " path=" << path << endl; break; } } if ( isoFile.isEmpty() ) { kdDebug() << "tdeio_isoProtocol::checkNewFile: not found" << endl; return false; } // Open new file kdDebug() << "Opening KIso on " << isoFile << endl; m_isoFile = new KIso( isoFile ); m_isoFile->setStartSec(startsec); if ( !m_isoFile->open( IO_ReadOnly ) ) { kdDebug() << "Opening " << isoFile << " failed." << endl; delete m_isoFile; m_isoFile = 0L; return false; } return true; }
/* we just simplify the process. if we use KParts::BrowserExtension, we have to do lots extra work, adding so much classes. so just hack like following. grab useful code from TDEHTMLPopupGUIClient(tdehtml_ext.cpp), and change a little bit to fit our needs */ void EvaChatView::slotPopupMenu( const TQString & _url, const TQPoint & point ) { menu->clear(); bool isImage = false; bool hasSelection = TDEHTMLPart::hasSelection(); KURL url = KURL(_url); if(d) delete d; d = new MenuPrivateData; d->m_url = url; DOM::Element e = nodeUnderMouse(); if ( !e.isNull() && (e.elementId() == ID_IMG) ) { DOM::HTMLImageElement ie = static_cast<DOM::HTMLImageElement>(e); TQString src = ie.src().string(); d->m_imageURL = KURL(src); d->m_suggestedFilename = src.right(src.length() - src.findRev("/") -1); isImage=true; } TDEAction *action = 0L; if(hasSelection) { //action = new TDEAction( i18n( "&Copy Text" ), TDEShortcut("Ctrl+C"), this, SLOT( copy() ), // actionCollection(), "copy" ); //action = KStdAction::copy( browserExtension(), SLOT(copy()), actionCollection(), "copy"); //action->setText(i18n("&Copy Text")); //action->setEnabled(true); copyAction->plug(menu); // search text TQString selectedText = TDEHTMLPart::selectedText(); if ( selectedText.length()>18 ) { selectedText.truncate(15); selectedText+="..."; } #ifdef HAS_KONTQUEROR // Fill search provider entries TDEConfig config("kuriikwsfilterrc"); config.setGroup("General"); const TQString defaultEngine = config.readEntry("DefaultSearchEngine", "google"); const char keywordDelimiter = config.readNumEntry("KeywordDelimiter", ':'); // default search provider KService::Ptr service = KService::serviceByDesktopPath(TQString("searchproviders/%1.desktop").arg(defaultEngine)); // search provider icon TQPixmap icon; KURIFilterData data; TQStringList list; const TQString defaultSearchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; data.setData( defaultSearchProviderPrefix + TQString("some keyword") ); list << "kurisearchfilter" << "kuriikwsfilter"; TQString name; if ( KURIFilter::self()->filterURI(data, list) ) { TQString iconPath = locate("cache", KMimeType::favIconForURL(data.uri()) + ".png"); if ( iconPath.isEmpty() ) icon = SmallIcon("edit-find"); else icon = TQPixmap( iconPath ); name = service->name(); } else { icon = SmallIcon("google"); name = "Google"; } action = new TDEAction( i18n( "Search '%1' at %2" ).arg( selectedText ).arg( name ), icon, 0, this, SLOT( searchProvider() ), actionCollection(), "searchProvider" ); action->plug(menu); // favorite search providers TQStringList favoriteEngines; favoriteEngines = config.readListEntry("FavoriteSearchEngines"); // for KDE 3.2 API compatibility if(favoriteEngines.isEmpty()) favoriteEngines << "google" << "google_groups" << "google_news" << "webster" << "dmoz" << "wikipedia"; if ( !favoriteEngines.isEmpty()) { TDEActionMenu* providerList = new TDEActionMenu( i18n( "Search '%1' At" ).arg( selectedText ), actionCollection(), "searchProviderList" ); bool hasSubMenus = false; TQStringList::ConstIterator it = favoriteEngines.begin(); for ( ; it != favoriteEngines.end(); ++it ) { if (*it==defaultEngine) continue; service = KService::serviceByDesktopPath(TQString("searchproviders/%1.desktop").arg(*it)); if (!service) continue; const TQString searchProviderPrefix = *(service->property("Keys").toStringList().begin()) + keywordDelimiter; data.setData( searchProviderPrefix + "some keyword" ); if ( KURIFilter::self()->filterURI(data, list) ) { TQString iconPath = locate("cache", KMimeType::favIconForURL(data.uri()) + ".png"); if ( iconPath.isEmpty() ) icon = SmallIcon("edit-find"); else icon = TQPixmap( iconPath ); name = service->name(); providerList->insert( new TDEAction( name, icon, 0, this, SLOT( searchProvider() ), actionCollection(), TQString( "searchProvider" + searchProviderPrefix ).latin1() ) ); hasSubMenus = true; } } if(hasSubMenus) providerList->plug(menu); } #endif // HAS_KONTQUEROR if ( selectedText.contains("://") && KURL(selectedText).isValid() ) { action = new TDEAction( i18n( "Open '%1'" ).arg( selectedText ), "window_new", 0, this, SLOT( openSelection() ), actionCollection(), "openSelection" ); action->plug(menu); } } if ( !url.isEmpty() ) { if (url.protocol() == "mailto") { action = new TDEAction( i18n( "Copy Email Address" ), 0, this, SLOT( slotCopyLinkLocation() ), actionCollection(), "copylinklocation" ); action->plug(menu); } else { action = new TDEAction( i18n( "Copy &Link Address" ), 0, this, SLOT( slotCopyLinkLocation() ), actionCollection(), "copylinklocation" ); action->plug(menu); } } if (isImage) { #ifndef QT_NO_MIMECLIPBOARD action = (new TDEAction( i18n( "Copy Image" ), 0, this, SLOT( slotCopyImage() ), actionCollection(), "copyimage" )); action->plug(menu); #endif action = new TDEAction( i18n( "Save Image As..." ), 0, this, SLOT( slotSaveImageAs() ), actionCollection(), "saveimageas" ); action->plug(menu); action = new TDEAction( i18n( "Save As Custom Smiley"), 0, this, SLOT( slotSaveAsCustomSmiley() ), actionCollection(), "saveascustomsmiley" ); action->plug(menu); } if(menu->count()) menu->popup(point); }
bool TrashImpl::createInfo( const TQString& origPath, int& trashId, TQString& fileId ) { kdDebug() << k_funcinfo << origPath << endl; // Check source const TQCString origPath_c( TQFile::encodeName( origPath ) ); KDE_struct_stat buff_src; if ( KDE_lstat( origPath_c.data(), &buff_src ) == -1 ) { if ( errno == EACCES ) error( TDEIO::ERR_ACCESS_DENIED, origPath ); else error( TDEIO::ERR_DOES_NOT_EXIST, origPath ); return false; } // Choose destination trash trashId = findTrashDirectory( origPath ); if ( trashId < 0 ) { kdWarning() << "OUCH - internal error, TrashImpl::findTrashDirectory returned " << trashId << endl; return false; // ### error() needed? } kdDebug() << k_funcinfo << "trashing to " << trashId << endl; // Grab original filename KURL url; url.setPath( origPath ); const TQString origFileName = url.fileName(); // Make destination file in info/ url.setPath( infoPath( trashId, origFileName ) ); // we first try with origFileName KURL baseDirectory; baseDirectory.setPath( url.directory() ); // Here we need to use O_EXCL to avoid race conditions with other tdeioslave processes int fd = 0; do { kdDebug() << k_funcinfo << "trying to create " << url.path() << endl; fd = ::open( TQFile::encodeName( url.path() ), O_WRONLY | O_CREAT | O_EXCL, 0600 ); if ( fd < 0 ) { if ( errno == EEXIST ) { url.setFileName( TDEIO::RenameDlg::suggestName( baseDirectory, url.fileName() ) ); // and try again on the next iteration } else { error( TDEIO::ERR_COULD_NOT_WRITE, url.path() ); return false; } } } while ( fd < 0 ); const TQString infoPath = url.path(); fileId = url.fileName(); Q_ASSERT( fileId.endsWith( ".trashinfo" ) ); fileId.truncate( fileId.length() - 10 ); // remove .trashinfo from fileId FILE* file = ::fdopen( fd, "w" ); if ( !file ) { // can't see how this would happen error( TDEIO::ERR_COULD_NOT_WRITE, infoPath ); return false; } // Contents of the info file. We could use KSimpleConfig, but that would // mean closing and reopening fd, i.e. opening a race condition... TQCString info = "[Trash Info]\n"; info += "Path="; // Escape filenames according to the way they are encoded on the filesystem // All this to basically get back to the raw 8-bit representation of the filename... if ( trashId == 0 ) // home trash: absolute path info += KURL::encode_string( origPath, m_mibEnum ).latin1(); else info += KURL::encode_string( makeRelativePath( topDirectoryPath( trashId ), origPath ), m_mibEnum ).latin1(); info += "\n"; info += "DeletionDate="; info += TQDateTime::currentDateTime().toString( Qt::ISODate ).latin1(); info += "\n"; size_t sz = info.size() - 1; // avoid trailing 0 from QCString size_t written = ::fwrite(info.data(), 1, sz, file); if ( written != sz ) { ::fclose( file ); TQFile::remove( infoPath ); error( TDEIO::ERR_DISK_FULL, infoPath ); return false; } ::fclose( file ); kdDebug() << k_funcinfo << "info file created in trashId=" << trashId << " : " << fileId << endl; return true; }
bool SevenZipArch::processLine( const TQCString& _line ) { TQString line; TQString columns[ 11 ]; unsigned int pos = 0; int strpos, len; TQTextCodec *codec = TQTextCodec::codecForLocale(); line = codec->toUnicode( _line ); columns[ 0 ] = line.right( line.length() - m_nameColumnPos); line.truncate( m_nameColumnPos ); // Go through our columns, try to pick out data, return silently on failure for ( TQPtrListIterator <ArchColumns>col( m_archCols ); col.current(); ++col ) { ArchColumns *curCol = *col; strpos = curCol->pattern.search( line, pos ); len = curCol->pattern.matchedLength(); if ( ( strpos == -1 ) || ( len > curCol->maxLength ) ) { if ( curCol->optional ) continue; // More? else { kdDebug(1601) << "processLine failed to match critical column" << endl; return false; } } pos = strpos + len; columns[ curCol->colRef ] = line.mid( strpos, len ); } // Separated directories pass if(columns[4].length() && columns[4][0] == 'D') return true; if ( m_dateCol >= 0 ) { TQString year = ( m_repairYear >= 0 ) ? ArkUtils::fixYear( columns[ m_repairYear ].ascii()) : columns[ m_fixYear ]; TQString month = ( m_repairMonth >= 0 ) ? TQString( "%1" ) .arg( ArkUtils::getMonth( columns[ m_repairMonth ].ascii() ) ) : columns[ m_fixMonth ]; TQString timestamp = TQString::fromLatin1( "%1-%2-%3 %4" ) .arg( year ) .arg( month ) .arg( columns[ m_fixDay ] ) .arg( columns[ m_fixTime ] ); columns[ m_dateCol ] = timestamp; } TQStringList list; for ( int i = 0; i < m_numCols; ++i ) { list.append( columns[ i ] ); } m_gui->fileList()->addItem( list ); // send the entry to the GUI return true; }