TQStringList KStringHandler::perlSplit(const TQChar & sep, const TQString & s, uint max) { bool ignoreMax = 0 == max; TQStringList l; int searchStart = 0; int tokenStart = s.find(sep, searchStart); while (-1 != tokenStart && (ignoreMax || l.count() < max - 1)) { if (!s.mid(searchStart, tokenStart - searchStart).isEmpty()) l << s.mid(searchStart, tokenStart - searchStart); searchStart = tokenStart + 1; tokenStart = s.find(sep, searchStart); } if (!s.mid(searchStart, s.length() - searchStart).isEmpty()) l << s.mid(searchStart, s.length() - searchStart); return l; }
TQStringList KStringHandler::perlSplit(const TQRegExp & sep, const TQString & s, uint max) { bool ignoreMax = 0 == max; TQStringList l; int searchStart = 0; int tokenStart = sep.search(s, searchStart); int len = sep.matchedLength(); while (-1 != tokenStart && (ignoreMax || l.count() < max - 1)) { if (!s.mid(searchStart, tokenStart - searchStart).isEmpty()) l << s.mid(searchStart, tokenStart - searchStart); searchStart = tokenStart + len; tokenStart = sep.search(s, searchStart); len = sep.matchedLength(); } if (!s.mid(searchStart, s.length() - searchStart).isEmpty()) l << s.mid(searchStart, s.length() - searchStart); return l; }
// Helper method. Parses a trash URL with the URL scheme defined in makeURL. // The trash:/ URL itself isn't parsed here, must be caught by the caller before hand. bool TrashImpl::parseURL( const KURL& url, int& trashId, TQString& fileId, TQString& relativePath ) { if ( url.protocol() != "trash" ) return false; const TQString path = url.path(); int start = 0; if ( path[0] == '/' ) // always true I hope start = 1; int slashPos = path.find( '-', 0 ); // don't match leading slash if ( slashPos <= 0 ) return false; bool ok = false; trashId = path.mid( start, slashPos - start ).toInt( &ok ); Q_ASSERT( ok ); if ( !ok ) return false; start = slashPos + 1; slashPos = path.find( '/', start ); if ( slashPos <= 0 ) { fileId = path.mid( start ); relativePath = TQString::null; return true; } fileId = path.mid( start, slashPos - start ); relativePath = path.mid( slashPos + 1 ); return true; }
// check $oldlayouts and $nonlatin groups for XFree 4.3 and later OldLayouts* X11Helper::loadOldLayouts(const TQString& rulesFile) { static const char* oldLayoutsTag = "! $oldlayouts"; static const char* nonLatinLayoutsTag = "! $nonlatin"; TQStringList m_oldLayouts; TQStringList m_nonLatinLayouts; TQFile f(rulesFile); if (f.open(IO_ReadOnly)) { TQTextStream ts(&f); TQString line; while (!ts.eof()) { line = ts.readLine().simplifyWhiteSpace(); if( line.find(oldLayoutsTag) == 0 ) { line = line.mid(strlen(oldLayoutsTag)); line = line.mid(line.find('=')+1).simplifyWhiteSpace(); while( !ts.eof() && line.endsWith("\\") ) line = line.left(line.length()-1) + ts.readLine(); line = line.simplifyWhiteSpace(); m_oldLayouts = TQStringList::split(TQRegExp("\\s"), line); // kdDebug() << "oldlayouts " << m_oldLayouts.join("|") << endl; if( !m_nonLatinLayouts.empty() ) break; } else if( line.find(nonLatinLayoutsTag) == 0 ) { line = line.mid(strlen(nonLatinLayoutsTag)+1).simplifyWhiteSpace(); line = line.mid(line.find('=')+1).simplifyWhiteSpace(); while( !ts.eof() && line.endsWith("\\") ) line = line.left(line.length()-1) + ts.readLine(); line = line.simplifyWhiteSpace(); m_nonLatinLayouts = TQStringList::split(TQRegExp("\\s"), line); // kdDebug() << "nonlatin " << m_nonLatinLayouts.join("|") << endl; if( !m_oldLayouts.empty() ) break; } } f.close(); } OldLayouts* oldLayoutsStruct = new OldLayouts(); oldLayoutsStruct->oldLayouts = m_oldLayouts; oldLayoutsStruct->nonLatinLayouts = m_nonLatinLayouts; return oldLayoutsStruct; }
static bool parseUrl(const TQString& _url, TQString &title, TQString §ion) { section = TQString::null; TQString url = _url; if (url.at(0) == '/') { if (TDEStandardDirs::exists(url)) { title = url; return true; } else { // If the directory does not exist, then it is perhaps a normal man page kdDebug(7107) << url << " does not exist" << endl; } } while (url.at(0) == '/') url.remove(0,1); title = url; int pos = url.find('('); if (pos < 0) return true; title = title.left(pos); section = url.mid(pos+1); section = section.left(section.length()-1); return true; }
void TDECompletion::extractStringsFromNodeCI( const TDECompTreeNode *node, const TQString& beginning, const TQString& restString, TDECompletionMatchesWrapper *matches ) const { if ( restString.isEmpty() ) { extractStringsFromNode( node, beginning, matches, false /*noweight*/ ); return; } TQChar ch1 = restString.at(0); TQString newRest = restString.mid(1); TDECompTreeNode *child1, *child2; child1 = node->find( ch1 ); // the correct match if ( child1 ) extractStringsFromNodeCI( child1, beginning + *child1, newRest, matches ); // append the case insensitive matches, if available if ( ch1.isLetter() ) { // find out if we have to lower or upper it. Is there a better way? TQChar ch2 = ch1.lower(); if ( ch1 == ch2 ) ch2 = ch1.upper(); if ( ch1 != ch2 ) { child2 = node->find( ch2 ); if ( child2 ) extractStringsFromNodeCI( child2, beginning + *child2, newRest, matches ); } } }
void CityList::readCityList(const TQString &fname) { TQFile f(fname); if (f.open(IO_ReadOnly)) { TQTextStream is(&f); TQString line; TQStringList tags; TQRegExp coord("[+-]\\d+[+-]\\d+"); TQRegExp name("[^\\s]+/[^\\s]+"); int pos; while (!is.eof()) { line = is.readLine().stripWhiteSpace(); if (line.isEmpty() || line.left(1) == "#") continue; TQString c, n; pos = coord.search(line, 0); if (pos >= 0) c = line.mid(pos, coord.matchedLength()); pos = name.search(line, pos); if (pos > 0) n = line.mid(pos, name.matchedLength()).stripWhiteSpace(); if (!c.isEmpty() && !n.isEmpty()) { double la, lo; pos = c.find("+", 1); if (pos < 0) pos = c.find("-", 1); if (pos > 0) { la = coordinate(c.left(pos)); lo = coordinate(c.mid(pos)); _cities.append(new City(n.latin1(), la, lo)); } } } f.close(); } }
TQString KfindWindow::reducedDir(const TQString& fullDir) { if (fullDir.find(m_baseDir)==0) { TQString tmp=fullDir.mid(m_baseDir.length()); return tmp; }; return fullDir; }
bool LprHandler::completePrinter(KMPrinter *prt, PrintcapEntry *entry, bool) { prt->setDescription(i18n("Unknown (unrecognized entry)")); TQString val = entry->field("lp"); KURL uri; if (!val.isEmpty() && val != "/dev/null") { int p = val.find('@'); if (p != -1) { prt->setLocation(i18n("Remote queue (%1) on %2").arg(val.left(p)).arg(val.mid(p+1))); uri.setProtocol("lpd"); uri.setHost(val.mid(p+1)); uri.setPath("/" + val.left(p)); } else if ((p = val.find('%')) != -1) { prt->setLocation(i18n("Network printer (%1)").arg("socket")); uri.setProtocol("socket"); uri.setHost(val.left(p)); uri.setPort(val.mid(p+1).toInt()); } else { prt->setLocation(i18n("Local printer on %1").arg(val)); uri.setProtocol("parallel"); uri.setPath(val); } } else if (!(val = entry->field("rp")).isEmpty()) { TQString rm = entry->has("rm") ? entry->field("rm") : LprSettings::self()->defaultRemoteHost(); prt->setLocation(i18n("Remote queue (%1) on %2").arg(val).arg(rm)); uri.setProtocol("lpd"); uri.setHost(rm); uri.setPath("/" + val); } else prt->setLocation(i18n("Unknown (unrecognized entry)")); prt->setDevice(uri.url()); return true; }
static TQString extractName(TQString path) { int i = path.findRev('/'); if (i >= 0) path = path.mid(i+1); i = path.findRev('.'); if (i >= 0) path = path.left(i); return path; }
void EvaQunMemberPicker::slotClicked(TQListViewItem *item) { if(!item) return; TQCheckListItem *chkItem = dynamic_cast<TQCheckListItem *>(item); if(!chkItem) return; unsigned int id; TQString txt; TQString strID; bool ok; TQString nick; TQPixmap face; TQCheckListItem *child = dynamic_cast<TQCheckListItem *>(chkItem->firstChild()); if(!child){ txt = chkItem->text(0); int index = txt.findRev("("); nick = txt.left( index ); strID = txt.mid(index+1, txt.length() - index - 1 - 1); id = strID.toUInt(&ok); if(!ok) return; face = *(chkItem->pixmap(0)); emit memberClicked(id, chkItem->isOn()); } while(child){ child->setOn(chkItem->isOn()); txt = child->text(0); int index = txt.findRev("("); nick = txt.left( index ); strID = txt.mid(index+1, txt.length() - index - 1 - 1); id = strID.toUInt(&ok); if(!ok) return; face = *(child->pixmap(0)); emit memberClicked(id, child->isOn()); child = dynamic_cast<TQCheckListItem *>(child->nextSibling()); } }
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 TrashImpl::makeRelativePath( const TQString& topdir, const TQString& path ) { const TQString realPath = TDEStandardDirs::realFilePath( path ); // topdir ends with '/' if ( realPath.startsWith( topdir ) ) { const TQString rel = realPath.mid( topdir.length() ); Q_ASSERT( rel[0] != '/' ); return rel; } else { // shouldn't happen... kdWarning() << "Couldn't make relative path for " << realPath << " (" << path << "), with topdir=" << topdir << endl; return realPath; } }
KXSConfigDialog::KXSConfigDialog(const TQString &filename, const TQString &name) : KDialogBase(Plain, name, Ok| Cancel, Ok, 0, 0, false), mFilename(filename), mPreviewProc(0), mKilled(true) { int slash = filename.findRev('/'); if (slash >= 0) mConfigFile = filename.mid(slash+1); else mConfigFile = filename; mExeName = mConfigFile; mConfigFile += "rc"; }
void KMDriverDB::loadDbFile() { // first clear everything m_entries.clear(); m_pnpentries.clear(); TQFile f(dbFile()); if (f.exists() && f.open(IO_ReadOnly)) { TQTextStream t(&f); TQString line; TQStringList words; KMDBEntry *entry(0); while (!t.eof()) { line = t.readLine().stripWhiteSpace(); if (line.isEmpty()) continue; int p = line.find('='); if (p == -1) continue; words.clear(); words << line.left(p) << line.mid(p+1); if (words[0] == "FILE") { if (entry) insertEntry(entry); entry = new KMDBEntry; entry->file = words[1]; } else if (words[0] == "MANUFACTURER" && entry) entry->manufacturer = words[1].upper(); else if (words[0] == "MODEL" && entry) entry->model = words[1]; else if (words[0] == "MODELNAME" && entry) entry->modelname = words[1]; else if (words[0] == "PNPMANUFACTURER" && entry) entry->pnpmanufacturer = words[1].upper(); else if (words[0] == "PNPMODEL" && entry) entry->pnpmodel = words[1]; else if (words[0] == "DESCRIPTION" && entry) entry->description = words[1]; else if (words[0] == "RECOMMANDED" && entry && words[1].lower() == "yes") entry->recommended = true; else if (words[0] == "DRIVERCOMMENT" && entry) entry->drivercomment = ("<qt>"+words[1].replace("<", "<").replace(">", ">")+"</qt>"); } if (entry) insertEntry(entry); } }
TQMap<TQString,TQString> ApsHandler::loadVarFile(const TQString& filename) { TQMap<TQString,TQString> opts; TQFile f(filename); if (f.open(IO_ReadOnly)) { TQTextStream t(&f); TQString line; int p(-1); while (!t.atEnd()) { line = t.readLine().stripWhiteSpace(); if (line.isEmpty() || line[0] == '#' || (p = line.find('=')) == -1) continue; TQString variable = line.left(p).stripWhiteSpace(); TQString value = line.mid(p+1).stripWhiteSpace(); if (!value.isEmpty() && value[0] == '\'') value = value.mid(1, value.length()-2); opts[variable] = value; } } return opts; }
TQString AddresseeItem::key( int column, bool ) const { if (column == Email) { TQString value = text(Email); TQRegExp emailRe("<\\S*>"); int match = emailRe.search(value); if (match > -1) value = value.mid(match + 1, emailRe.matchedLength() - 2); return value.lower(); } return text(column).lower(); }
/* pretty simple algorithm - reads the layout file and tries to find "xkb_symbols" also checks whether previous line contains "hidden" to skip it */ TQStringList* X11Helper::getVariants(const TQString& layout, const TQString& x11Dir, bool oldLayouts) { TQStringList* result = new TQStringList(); TQString file = x11Dir + "xkb/symbols/"; // workaround for XFree 4.3 new directory for one-group layouts if( TQDir(file+"pc").exists() && !oldLayouts ) file += "pc/"; file += layout; // kdDebug() << "reading variants from " << file << endl; TQFile f(file); if (f.open(IO_ReadOnly)) { TQTextStream ts(&f); TQString line; TQString prev_line; while (!ts.eof()) { prev_line = line; line = ts.readLine().simplifyWhiteSpace(); if (line[0] == '#' || line.left(2) == "//" || line.isEmpty()) continue; int pos = line.find("xkb_symbols"); if (pos < 0) continue; if( prev_line.find("hidden") >=0 ) continue; pos = line.find('"', pos) + 1; int pos2 = line.find('"', pos); if( pos < 0 || pos2 < 0 ) continue; result->append(line.mid(pos, pos2-pos)); // kdDebug() << "adding variant " << line.mid(pos, pos2-pos) << endl; } f.close(); } return result; }
void MANProtocol::parseWhatIs( TQMap<TQString, TQString> &i, TQTextStream &t, const TQString &mark ) { TQRegExp re( mark ); TQString l; while ( !t.atEnd() ) { l = t.readLine(); int pos = re.search( l ); if (pos != -1) { TQString names = l.left(pos); TQString descr = l.mid(pos + re.matchedLength()); while ((pos = names.find(",")) != -1) { i[names.left(pos++)] = descr; while (names[pos] == ' ') pos++; names = names.mid(pos); } i[names] = descr; } } }
double coordinate(TQString c) { int neg; int d=0, m=0, s=0; neg = c.left(1) == "-"; c.remove(0,1); switch (c.length()) { case 4: d = c.left(2).toInt(); m = c.mid(2).toInt(); break; case 5: d = c.left(3).toInt(); m = c.mid(3).toInt(); break; case 6: d = c.left(2).toInt(); m = c.mid(2,2).toInt(); s = c.right(2).toInt(); break; case 7: d = c.left(3).toInt(); m = c.mid(3,2).toInt(); s = c.right(2).toInt(); break; default: break; } if (neg) return - (d + m/60.0 + s/3600.0); else return d + m/60.0 + s/3600.0; }
void TDMAppearanceWidget::loadLanguageList(KLanguageButton *combo) { TQStringList langlist = TDEGlobal::dirs()->findAllResources("locale", TQString::fromLatin1("*/entry.desktop")); langlist.sort(); for ( TQStringList::ConstIterator it = langlist.begin(); it != langlist.end(); ++it ) { TQString fpath = (*it).left((*it).length() - 14); int index = fpath.findRev('/'); TQString nid = fpath.mid(index + 1); KSimpleConfig entry(*it); entry.setGroup(TQString::fromLatin1("KCM Locale")); TQString name = entry.readEntry(TQString::fromLatin1("Name"), i18n("without name")); combo->insertLanguage(nid, name, TQString::fromLatin1("l10n/"), TQString::null); } }
void ShortcutsModule::createActionsSequence() { TDEAccelActions& actions = m_actionsSequence; for( uint i = 0; i < actions.count(); i++ ) { TQString sConfigKey = actions[i].name(); //kdDebug(125) << "sConfigKey: " << sConfigKey << endl; int iLastSpace = sConfigKey.findRev( ' ' ); bool bIsNum = false; if( iLastSpace >= 0 ) sConfigKey.mid( iLastSpace+1 ).toInt( &bIsNum ); //kdDebug(125) << "sConfigKey: " << sConfigKey // << " bIsNum: " << bIsNum << endl; if( !bIsNum && !sConfigKey.contains( ':' ) ) { actions[i].setConfigurable( false ); actions[i].setName( TQString::null ); } } }
void KMMainView::slotChangePrinterState() { TQString opname = TQT_TQOBJECT_CONST(sender())->name(); if (m_current && opname.startsWith("printer_")) { opname = opname.mid(8); KMTimer::self()->hold(); bool result(false); if (opname == "enable") result = m_manager->enablePrinter(m_current, true); else if (opname == "disable") result = m_manager->enablePrinter(m_current, false); else if (opname == "start") result = m_manager->startPrinter(m_current, true); else if (opname == "stop") result = m_manager->startPrinter(m_current, false); if (!result) showErrorMsg(i18n("Unable to modify the state of printer %1.").arg(m_current->printerName())); KMTimer::self()->release(result); } }
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; }
void EvaChatView::slotLinkClicked( const KURL & url, const KParts::URLArgs &/*args*/) { TQString cmd = url.url(); TQString strSession = cmd.mid(13,cmd.length() - 13); bool ok; unsigned int session = strSession.toUInt(&ok); if(ok) { if(cmd.startsWith(protocolAccept) ) { emit fileTransferAcceptRequest(session); return; } if(cmd.startsWith(protocolSaveAs) ) { emit fileTransferSaveAsRequest(session); return; } if(cmd.startsWith(protocolCancel) ) { emit fileTransferCancelRequest(session); return; } if(cmd.startsWith(protocolResume) ) { emit fileTransferResume(session, true); return; } if(cmd.startsWith(protocolNewOne) ) { emit fileTransferResume(session, false); return; } } TQStringList args; if(url.isLocalFile()) { args<<"exec"<< TQString::fromLocal8Bit(url.path().ascii()); } else { args<<"exec" <<cmd; } kapp->tdeinitExec("kfmclient",args); }
bool KStringHandler::matchFileName( const TQString& filename, const TQString& pattern ) { int len = filename.length(); int pattern_len = pattern.length(); if (!pattern_len) return false; // Patterns like "Makefile*" if ( pattern[ pattern_len - 1 ] == (QChar)'*' && len + 1 >= pattern_len ) { if ( pattern[ 0 ] == (QChar)'*' ) { return filename.find(pattern.mid(1, pattern_len - 2)) != -1; } const TQChar *c1 = pattern.unicode(); const TQChar *c2 = filename.unicode(); int cnt = 1; while ( cnt < pattern_len && *c1++ == *c2++ ) ++cnt; return cnt == pattern_len; } // Patterns like "*~", "*.extension" if ( pattern[ 0 ] == (QChar)'*' && len + 1 >= pattern_len ) { const TQChar *c1 = pattern.unicode() + pattern_len - 1; const TQChar *c2 = filename.unicode() + len - 1; int cnt = 1; while ( cnt < pattern_len && *c1-- == *c2-- ) ++cnt; return cnt == pattern_len; } // Patterns like "Makefile" return ( filename == pattern ); }
void TDECompletion::addWeightedItem( const TQString& item ) { if ( myOrder != Weighted ) { addItem( item, 0 ); return; } uint len = item.length(); uint weight = 0; // find out the weighting of this item (appended to the string as ":num") int index = item.findRev(':'); if ( index > 0 ) { bool ok; weight = item.mid( index + 1 ).toUInt( &ok ); if ( !ok ) weight = 0; len = index; // only insert until the ':' } addItem( item.left( len ), weight ); return; }
TQString KURIFilterData::iconName() { if( m_bChanged ) { m_customIconPixmap = TQPixmap(); switch ( m_iType ) { case KURIFilterData::LOCAL_FILE: case KURIFilterData::LOCAL_DIR: case KURIFilterData::NET_PROTOCOL: { m_strIconName = KMimeType::iconForURL( m_pURI ); break; } case KURIFilterData::EXECUTABLE: { TQString exeName = m_pURI.url(); exeName = exeName.mid( exeName.findRev( '/' ) + 1 ); // strip path if given KService::Ptr service = KService::serviceByDesktopName( exeName ); #ifndef HAVE_ELFICON // Try to find an icon with the same name as the binary (useful for non-tde apps) // FIXME: We should only do this if the binary is in the system path somewhere, // otherwise TDE could end up showing system icons for user binaries if (service && service->icon() != TQString::fromLatin1( "unknown" )) { m_strIconName = service->icon(); } else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) { m_strIconName = exeName; } else { // use default m_strIconName = TQString::fromLatin1("exec"); } #else // HAVE_ELFICON // Try to find an icon with the same name as the binary (useful for non-tde apps) // FIXME: We should only do this if the binary is in the system path somewhere, // otherwise TDE could end up showing system icons for user binaries if (service && service->icon() != TQString::fromLatin1( "unknown" )) { m_strIconName = service->icon(); } else if ( !TDEGlobal::iconLoader()->loadIcon( exeName, TDEIcon::NoGroup, 16, TDEIcon::DefaultState, 0, true ).isNull() ) { m_strIconName = exeName; } else { // use default m_strIconName = TQString::fromLatin1("exec"); } // Try to load from elf file (if supported) // Check for an embedded icon unsigned int icon_size; libr_icon *icon = NULL; libr_file *handle = NULL; libr_access_t access = LIBR_READ; char libr_can_continue = 1; if((handle = libr_open(const_cast<char*>(m_pURI.path().ascii()), access)) == NULL) { kdWarning() << "failed to open file" << m_pURI.path() << endl; libr_can_continue = 0; } if (libr_can_continue == 1) { icon_size = 32; // FIXME: Is this a reasonable size request for all possible usages of kurifilter? icon = libr_icon_geticon_bysize(handle, icon_size); if (libr_can_continue == 1) { // See if the embedded icon name matches any icon file names already on the system // If it does, use the system icon instead of the embedded one int iconresnamefound = 0; iconentry *entry = NULL; iconlist icons; if(!get_iconlist(handle, &icons)) { // Failed to obtain a list of ELF icons kdWarning() << "failed to obtain ELF icon: " << libr_errmsg() << endl; // See if there is a system icon we can use TQString sysIconName = elf_get_resource(handle, ".metadata_sysicon"); if (!sysIconName.isEmpty()) { if (TDEGlobal::iconLoader()->iconPath(sysIconName.ascii(), 0, true) != "") { m_strIconName = sysIconName; } } libr_close(handle); libr_can_continue = 0; } else { while((entry = get_nexticon(&icons, entry)) != NULL) { if(icon == NULL) { // Try loading this icon as fallback icon = libr_icon_geticon_byname(handle, entry->name); } if (TDEGlobal::iconLoader()->iconPath(entry->name, 0, true) != "") { iconresnamefound = 1; m_strIconName = entry->name; break; } } } if (libr_can_continue == 1) { if ((iconresnamefound == 0) && (icon)) { // Extract the embedded icon size_t icon_data_length; char* icondata = libr_icon_malloc(icon, &icon_data_length); m_customIconPixmap.loadFromData(static_cast<uchar*>(static_cast<void*>(icondata)), icon_data_length); // EVIL CAST if (icon_size != 0) { TQImage ip = m_customIconPixmap.convertToImage(); ip = ip.smoothScale(icon_size, icon_size); m_customIconPixmap.convertFromImage(ip); } free(icondata); libr_icon_close(icon); } libr_close(handle); } } } #endif // HAVE_ELFICON break; } case KURIFilterData::HELP: { m_strIconName = TQString::fromLatin1("khelpcenter"); break; } case KURIFilterData::SHELL: { m_strIconName = TQString::fromLatin1("konsole"); break; } case KURIFilterData::ERROR: case KURIFilterData::BLOCKED: { m_strIconName = TQString::fromLatin1("error"); break; } default: m_strIconName = TQString::null; break; } m_bChanged = false; } return m_strIconName; }
/** @brief Try to get country code from layout name in xkb before xorg 6.9.0 */ TQString LayoutIcon::getCountryFromLayoutName(const TQString& layoutName) { TQString flag; if( X11Helper::areLayoutsClean() ) { // >= Xorg 6.9.0 if( layoutName == "mkd" ) flag = "mk"; else if( layoutName == "srp" ) { TQString csFlagFile = locate("locale", flagTemplate.arg("cs")); flag = csFlagFile.isEmpty() ? "yu" : "cs"; } else if( layoutName.endsWith("/jp") ) flag = "jp"; else if( layoutName == "trq" || layoutName == "trf" || layoutName == "tralt" ) flag = "tr"; else if( layoutName.length() > 2 ) flag = ""; else flag = layoutName; } else { if( layoutName == "ar" ) // Arabic - not argentina ; else if( layoutName == "sr" || layoutName == "cs") // Serbian language - Yugoslavia flag = "yu"; else if( layoutName == "bs" ) // Bosnian language - Bosnia flag = "ba"; else if( layoutName == "la" ) // Latin America ; else if( layoutName == "lo" ) // Lao flag = "la"; else if( layoutName == "pl2" ) // Poland flag = "pl"; else if( layoutName == "iu" ) // Inuktitut - Canada flag = "ca"; else if( layoutName == "syr" ) // Syriac flag = "sy"; else if( layoutName == "dz" ) // Dzongka/Tibetian - Buthan flag = "bt"; else if( layoutName == "ogham" ) // Ogham - Ireland flag = "ie"; else if( layoutName == "ge_la" || layoutName == "ge_ru" ) flag = "ge"; else if( layoutName == "el" ) flag = "gr"; else if( layoutName.endsWith("/jp") ) flag = "jp"; else if( layoutName == "ml" || layoutName == "dev" || layoutName == "gur" || layoutName == "guj" || layoutName == "kan" || layoutName == "ori" || layoutName == "tel" || layoutName == "tml" || layoutName == "ben" ) // some Indian languages flag = "in"; else { int sepPos = layoutName.find(TQRegExp("[-_]")); TQString leftCode = layoutName.mid(0, sepPos); TQString rightCode; if( sepPos != -1 ) rightCode = layoutName.mid(sepPos+1); // kdDebug() << "layout name breakup: " << leftCode << ":" << rightCode << endl; if( rightCode.length() == 2 && TQRegExp("[A-Z][A-Z]").exactMatch(rightCode) ) { flag = rightCode.lower(); } else { flag = leftCode.length() == 2 ? leftCode : ""; } } } return flag; }
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; }