Beispiel #1
0
  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;
}
Beispiel #2
0
void KJSProxyImpl::applyUserAgent()
{
  assert( m_script );
  TQString host = m_frame->m_part->url().isLocalFile() ? "localhost" : m_frame->m_part->url().host();
  TQString userAgent = KProtocolManager::userAgentForHost(host);
  if (userAgent.find(TQString::fromLatin1("Microsoft")) >= 0 ||
      userAgent.find(TQString::fromLatin1("MSIE")) >= 0)
  {
    m_script->setCompatMode(Interpreter::IECompat);
#ifdef KJS_VERBOSE
    kdDebug() << "Setting IE compat mode" << endl;
#endif
  }
  else
    // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
    if (userAgent.find(TQString::fromLatin1("Mozilla")) >= 0 &&
        userAgent.find(TQString::fromLatin1("compatible")) == -1 &&
        userAgent.find(TQString::fromLatin1("TDEHTML")) == -1)
    {
      m_script->setCompatMode(Interpreter::NetscapeCompat);
#ifdef KJS_VERBOSE
      kdDebug() << "Setting NS compat mode" << endl;
#endif
    }
}
Beispiel #3
0
// 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;
}
Beispiel #4
0
bool GetInfo_Sound (TQListView *lbox)
{
	lbox->setSorting(false);

	if (!GetDmesgInfo(lbox, "audio", NULL))
		new TQListViewItem(lbox, i18n("No audio devices found."));

	// append information for each audio devices found
	TQListViewItem *lvitem = lbox->firstChild();
	for(; lvitem; lvitem = lvitem->nextSibling()) {
		TQString s;
		int pos, len;
		const char *start;
		char *dev;

		s = lvitem->text(0);
		// The autoconf message is in form 'audio0 at auvia0: ...'
		if (s.find("audio") == 0 && (pos = s.find(" at ")) > 0) {
			pos += 4;	// skip " at "
			start = s.ascii() + pos;
			len = (int) strcspn(start, ":\n\t ");
			dev = (char *) malloc(1 + len + 1);
			sprintf(dev, "^%.*s", len, start);	/* safe */

			GetDmesgInfo(lbox, dev, NULL);

			free(dev);
		}
	}

	return true;
}
Beispiel #5
0
void TarArch::slotListingDone(TDEProcess *_kp)
{
    const TQString list = getLastShellOutput();
    FileListView *flv = m_gui->fileList();
    if (flv!=NULL && flv->totalFiles()>0)
    {
        const TQString firstfile = ((FileLVI *) flv->firstChild())->fileName();
        if (list.find(TQRegExp(TQString("\\s\\./%1[/\\n]").arg(firstfile)))>=0)
        {
            m_dotslash = true;
            kdDebug(1601) << k_funcinfo << "archive has dot-slash" << endl;
        }
        else
        {
            if (list.find(TQRegExp(TQString("\\s%1[/\\n]").arg(firstfile)))>=0)
            {
                // archive doesn't have dot-slash
                m_dotslash = false;
            }
            else
            {
                kdDebug(1601) << k_funcinfo << "cannot match '" << firstfile << "' in listing!" << endl;
            }
        }
    }

    delete _kp;
    _kp = m_currentProcess = NULL;
}
Beispiel #6
0
// 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;
}
Beispiel #7
0
void KXmlCommandAdvancedDlg::slotCommandChanged(const TQString& cmd)
{
	m_inputfile->parentWidget()->setEnabled(cmd.find("%filterinput") != -1);
	m_outputfile->parentWidget()->setEnabled(cmd.find("%filteroutput") != -1);
	m_view->setEnabled(cmd.find("%filterargs") != -1);
	m_name->parentWidget()->setEnabled(m_view->isEnabled());
	slotSelectionChanged((m_view->isEnabled() ? m_view->currentItem() : 0));
	m_view->setOpen(m_view->firstChild(), m_view->isEnabled());
}
Beispiel #8
0
void CpuView::updateView()
{
  if (m_cpus.isEmpty())
    return;

  CpuList::Iterator it;
  for (it = m_cpus.begin(); it != m_cpus.end(); ++it) {
    Cpu &current = (*it);
    CpuData cpuData;
    updateCpu(cpuData, current.number());

    TQString text = current.format();
    current.setData(cpuData);
    cpuData -= current.oldData();
    int cpuDiff = 0;
    int total = cpuData.sys + cpuData.user + cpuData.nice + cpuData.idle;

//    kdDebug(2003) << "name = " << cpuData.name << endl;
//    kdDebug(2003) << "user = "******"nice = " << cpuData.nice << endl;
//    kdDebug(2003) << "sys = " << cpuData.sys << endl;
//    kdDebug(2003) << "idle = " << cpuData.idle << endl;
    
    if (!m_firstTime) {
      if (text.find("%T") != -1)
        cpuDiff = cpuData.sys + cpuData.user + cpuData.nice;
      else if (text.find("%t") != -1)
        cpuDiff = cpuData.sys + cpuData.user;
      else if (text.find("%s") != -1)
        cpuDiff = cpuData.sys;
      else if (text.find("%u") != -1)
        cpuDiff = cpuData.user;
      else if (text.find("%n") != -1)
        cpuDiff = cpuData.nice;

      cpuDiff *= 100;
	  
	  if ( total > 0 )
		  cpuDiff /= total;

      if (cpuDiff > 100)
        cpuDiff = 100;
    }

    current.chart()->setText(i18n("%1%").arg(cpuDiff));
    current.chart()->setValue(cpuDiff, 0);
    current.label()->setValue(cpuDiff);
  }

  m_firstTime = false;
}
Beispiel #9
0
/* 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;
}
Beispiel #10
0
void LDAPProtocol::LDAPEntry2UDSEntry( const TQString &dn, UDSEntry &entry, 
  const LDAPUrl &usrc, bool dir )
{
  UDSAtom atom;
  
  int pos;
  entry.clear();
  atom.m_uds = UDS_NAME;
  atom.m_long = 0;
  TQString name = dn;
  if ( (pos = name.find(",")) > 0 )
    name = name.left( pos );
  if ( (pos = name.find("=")) > 0 )
    name.remove( 0, pos+1 );
  name.replace(' ', "_");
  if ( !dir ) name += ".ldif";
  atom.m_str = name;
  entry.append( atom );

  // the file type
  atom.m_uds = UDS_FILE_TYPE;
  atom.m_str = "";
  atom.m_long = dir ? S_IFDIR : S_IFREG;
  entry.append( atom );
  
  // the mimetype
  if (!dir) {
    atom.m_uds = UDS_MIME_TYPE;
    atom.m_long = 0;
    atom.m_str = "text/plain";
    entry.append( atom );
  }

  atom.m_uds = UDS_ACCESS;
  atom.m_long = dir ? 0500 : 0400;
  entry.append( atom );

  // the url
  atom.m_uds = UDS_URL;
  atom.m_long = 0;
  LDAPUrl url;
  url=usrc;

  url.setPath("/"+dn);
  url.setScope( dir ? LDAPUrl::One : LDAPUrl::Base );
  atom.m_str = url.prettyURL();
  entry.append( atom );
}
Beispiel #11
0
static
bool parseUrl(const TQString& _url, TQString &title, TQString &section)
{
    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;
}
Beispiel #12
0
void KTextBrowser::setSource( const TQString& name )
{
  if( name.isNull() )
  {
    return;
  }

  if( name.find('@') > -1 )
  {
    if( !mNotifyClick )
    {
      kapp->invokeMailer( KURL( name ) );
    }
    else
    {
      emit mailClick( TQString::null, name );
    }
  }
  else
  {
    if( !mNotifyClick )
    {
      kapp->invokeBrowser( name );
    }
    else
    {
      emit urlClick( name );
    }
  }
}
Beispiel #13
0
void KwikDisk::toggleMount(int item)
{
   kdDebug() << k_funcinfo << endl;

   DiskEntry *disk = m_diskList.at(item);
   if( disk == 0 )
   {
      return;
   }

   int val = disk->toggleMount();
   if( val != 0 )
   {
      KMessageBox::error(this, disk->lastSysError());
   }
   else if( (m_options.openFileManager() == true) && (disk->mounted() == true ) )
   {
      kdDebug() << "opening filemanager" << endl;
      if( m_options.fileManager().isEmpty() == false )
      {
         TQString cmd = m_options.fileManager();
         int pos = cmd.find("%m");
         if( pos > 0 )
         {
            cmd = cmd.replace( pos, 2, TDEProcess::quote(disk->mountPoint()) ) + " &";
         }
         else
         {
            cmd += " " + TDEProcess::quote(disk->mountPoint()) +" &";
         }
         system( TQFile::encodeName(cmd) );
      }
   }
   m_dirty = TRUE;
}
Beispiel #14
0
TQString KfindWindow::reducedDir(const TQString& fullDir)
{
   if (fullDir.find(m_baseDir)==0)
   {
      TQString tmp=fullDir.mid(m_baseDir.length());
      return tmp;
   };
   return fullDir;
}
Beispiel #15
0
// 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);
}
Beispiel #16
0
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;
}
Beispiel #17
0
void KSim::Sysinfo::clockUptimeUpdate()
{
  TQString time;
  static bool updateDate = true;

  if (m_timeLabel) {
    TQTime now = TQTime::currentTime();
    time = TDEGlobal::locale()->formatTime(now, true);
    if ( now == TQTime(0, 0) )
      updateDate = true;

    m_timeLabel->setText(time);
  }

  // only update the date when necessary
  if (m_dateLabel) {
    if (updateDate) {
      m_dateLabel->setText(TDEGlobal::locale()->formatDate(TQDate::currentDate()));
      updateDate = false;
    }
  }
  else {
    updateDate = true;
  }

  if (m_uptimeLabel) {
    TQString uptime = m_config->uptimeFormat();
    ++m_totalUptime;
    long uptimeDays, uptimeHours, uptimeMins, uptimeSecs;

    uptimeHours = m_totalUptime / 3600;
    uptimeDays = uptimeHours / 24;
    uptimeMins = (m_totalUptime - uptimeHours * 3600) / 60;
    uptimeSecs = m_totalUptime % 60;

    TQString days;
    TQString hours;
    TQString minutes;
    TQString seconds;

    // found days so we have to modify hours
    if (uptime.find(TQRegExp("%d" ), 0) >= 0)
      uptimeHours -= (uptimeDays * 24);

    days.sprintf("%02li", uptimeDays);
    hours.sprintf("%02li", uptimeHours);
    minutes.sprintf("%02li", uptimeMins);
    seconds.sprintf("%02li", uptimeSecs);

    uptime.replace(TQRegExp("%d"), days);
    uptime.replace(TQRegExp("%h"), hours);
    uptime.replace(TQRegExp("%m"), minutes);
    uptime.replace(TQRegExp("%s"), seconds);
    m_uptimeLabel->setText(uptime);
  }
}
Beispiel #18
0
// this is used to find out which devices are currently
// on system
static bool GetDmesgInfo(TQListView *lBox, const char *filter,
	void func(TQListView *, TQString s))
{
        TQFile *dmesg = new TQFile("/var/run/dmesg.boot");
	bool usepipe = false;
	FILE *pipe = NULL;
	TQTextStream *t;
	bool seencpu = false;
	TQString s;
	bool found = false;

	if (dmesg->exists() && dmesg->open(IO_ReadOnly)) {
		t = new TQTextStream(dmesg);
	}
	else {
		delete dmesg;
		pipe = popen("/sbin/dmesg", "r");
		if (!pipe) return false;
		usepipe = true;
		t = new TQTextStream(pipe, IO_ReadOnly);
	}

	TQListViewItem *olditem = NULL;
	while(!(s = t->readLine().local8Bit()).isEmpty()) {
		if (!seencpu) {
			if (s.contains("cpu"))
				seencpu = true;
			else
				continue;
		}
		if (s.contains("boot device") ||
			s.contains("WARNING: old BSD partition ID!"))
			break;

		if (!filter
		    || (filter[0] == '^' && s.find(&filter[1]) == 0)
		    || (filter[0] != '^' && s.contains(filter))) {
			if (func)
				func(lBox, s);
			else
				olditem = new TQListViewItem(lBox, olditem, s);
			found = true;
		}
	}

	delete t;
	if (pipe)
		pclose(pipe);
	else {
		dmesg->close();
		delete dmesg;
	}

	return found;
}
Beispiel #19
0
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("&lt;", "<").replace("&gt;", ">")+"</qt>");
		}
		if (entry)
			insertEntry(entry);
	}
}
Beispiel #20
0
void KSim::Sysinfo::sysUpdate()
{
  const System &system = System::self();
  m_totalUptime = system.uptime();

  if (m_memLabel) {
    TQString memory = m_config->memoryFormat();
    unsigned long total = system.totalRam();
    unsigned long free = system.freeRam();
  unsigned long shared = system.sharedRam();
  unsigned long buffer = system.bufferRam();
  unsigned long cache = system.cacheRam();
  unsigned long used = system.usedRam();
  unsigned long allFree = free + buffer + cache;
  bool all = memory.find( "%F" ) != -1;

  memory.replace(TQRegExp("%s"), TQString::number(System::bytesToMegs(shared)));
  memory.replace(TQRegExp("%b"), TQString::number(System::bytesToMegs(buffer)));
  memory.replace(TQRegExp("%c"), TQString::number(System::bytesToMegs(cache)));
  memory.replace(TQRegExp("%u"), TQString::number(System::bytesToMegs(used)));
  memory.replace(TQRegExp("%t"), TQString::number(System::bytesToMegs(total)));
  memory.replace(TQRegExp("%f"), TQString::number(System::bytesToMegs(free)));
  memory.replace(TQRegExp("%F"), TQString::number(System::bytesToMegs(allFree)));
    kdDebug(2003) << memory << endl;
    m_memLabel->setText("Memory");
    TQToolTip::add(m_memLabel, memory );

    if ( !all )
      m_memLabel->setValue( System::bytesToMegs( total ) - System::bytesToMegs( free ) );
    else
      m_memLabel->setValue( System::bytesToMegs( total ) - System::bytesToMegs( allFree ) );
  }

  if (m_swapLabel) {
    TQString swap = m_config->swapFormat();
    unsigned long total = system.totalSwap();
    unsigned long free = system.freeSwap();
    unsigned long swapUsed = system.usedSwap();
    swap.replace(TQRegExp("%u"), TQString::number(System::bytesToMegs(swapUsed)));
    swap.replace(TQRegExp("%t"), TQString::number(System::bytesToMegs(total)));
    swap.replace(TQRegExp("%f"), TQString::number(System::bytesToMegs(free)));
    m_swapLabel->setText("Swap");
    TQToolTip::add(m_swapLabel, swap);
    m_swapLabel->setValue(System::bytesToMegs(total) - System::bytesToMegs(free));
  }

//  if (m_config->showProcs()) {
//    m_procsLabel->setText(i18n("Procs: %1").arg(sysInfo.procs));
//  }
}
Beispiel #21
0
void
AddIRQLine(TQListView *lBox, TQString s)
{
	int pos, irqnum;
	char numstr[3];

	pos = s.find(" irq ");
	irqnum = (pos < 0) ? 0 : atoi(&s.ascii()[pos+5]);
	if (irqnum)
		snprintf(numstr, 3, "%02d", irqnum);
	else {
		// this should never happen
		strcpy(numstr, "??");
	}

	new TQListViewItem(lBox, numstr, s);
}
Beispiel #22
0
void KMWLocal::initialize()
{
	TQStringList	list = KMFactory::self()->manager()->detectLocalPrinters();
	if (list.isEmpty() || (list.count() % 4) != 0)
	{
		KMessageBox::error(this, i18n("Unable to detect local ports."));
		return;
	}
	TQListViewItem	*last[4] = {0, 0, 0, 0};
	for (TQStringList::Iterator it=list.begin(); it!=list.end(); ++it)
	{
		TQString cl = *it;
		++it;

		TQString	uri = *it;
		int p = uri.find( ':' );
		TQString	desc = *(++it), prot = ( p != -1 ? uri.left( p ) : TQString::null );
		TQString	printer = *(++it);
		int	index(-1);
		if (desc.isEmpty())
			desc = uri;
		if (prot == "parallel" || prot == "file")
			index = 0;
		else if (prot == "serial")
			index = 1;
		else if (prot == "usb")
			index = 2;
		else if (cl == "direct")
			index = 3;
		else
			continue;
		last[index] = new TQListViewItem(m_parents[index], last[index], desc, uri);
		last[index]->setPixmap(0, SmallIcon("blockdevice"));
		m_parents[index]->setOpen(true);
		m_uris << uri;
		if (!printer.isEmpty())
		{
			TQListViewItem	*pItem = new TQListViewItem(last[index], printer);
			last[index]->setOpen(true);
			pItem->setPixmap(0, SmallIcon("tdeprint_printer"));
		}
	}
	m_initialized = true;
}
Beispiel #23
0
void ConfFilters::load()
{
	TQFile	f(locate("data","tdeprintfax/faxfilters"));
	if (f.exists() && f.open(IO_ReadOnly))
	{
		TQTextStream	t(&f);
		TQString		line;
		int		p(-1);
		TQListViewItem	*item(0);
		while (!t.eof())
		{
			line = t.readLine().stripWhiteSpace();
			if ((p=line.find(TQRegExp("\\s"))) != -1)
			{
				TQString	mime(line.left(p)), cmd(line.right(line.length()-p-1).stripWhiteSpace());
				if (!mime.isEmpty() && !cmd.isEmpty())
					item = new TQListViewItem(m_filters, item, mime, cmd);
			}
		}
	}
}
Beispiel #24
0
TQStringList TDECompletion::substringCompletion( const TQString& string ) const
{
    // get all items in the tree, possibly in sorted order
    bool sorted = (myOrder == Weighted);
    TDECompletionMatchesWrapper allItems( sorted );
    extractStringsFromNode( myTreeRoot, TQString::null, &allItems, false );

    TQStringList list = allItems.list();

    // subStringMatches is invoked manually, via a shortcut, so we should
    // beep here, if necessary.
    if ( list.isEmpty() ) {
        doBeep( NoMatch );
        return list;
    }

    if ( string.isEmpty() ) { // shortcut
        postProcessMatches( &list );
        return list;
    }

    TQStringList matches;
    TQStringList::ConstIterator it = list.begin();

    for( ; it != list.end(); ++it ) {
        TQString item = *it;
        if ( item.find( string, 0, false ) != -1 ) { // always case insensitive
            matches.append( item );
        }
    }

    postProcessMatches( &matches );

    if ( matches.isEmpty() )
        doBeep( NoMatch );

    return matches;
}
Beispiel #25
0
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;
}
Beispiel #26
0
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;
	}
    }
}
Beispiel #27
0
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 );
}
Beispiel #28
0
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;
}
Beispiel #29
0
// RETURN: <0      => error
//         =0      => no error, no update
//         >0      => no error, update happened
//
int KPCMCIACard::refresh() {
//////////////////////////////////////////////
///////////// LINUX ONLY
///////////////////////////////////////////////
#ifdef __linux__
struct timeval tv;
cs_status_t status;
fd_set rfds;
int rc;
event_t event;
struct stat sb;
config_info_t cfg;
KPCMCIACard oldValues(*this);
int updated = 0;
oldValues._fd = -1;

#define CHECK_CHANGED(x, y) do { if (x.y != y) updated = 1; } while(0)

    /**
     *   Get any events on the pcmcia device
     */
tv.tv_sec = 0;  tv.tv_usec = 0;
     FD_ZERO(&rfds);
     FD_SET(_fd, &rfds);
     rc = select(_fd+1, &rfds, NULL, NULL, &tv);
     if (rc > 0) {
        rc = read(_fd, (void *)&event, 4);
        if (rc == 4) {
	   int thisEvent = -1;  // thisEvent is the index of event in event_tag
           for (unsigned int j = 0; j < NTAGS; j++) {
              if (event_tag[j].event == event) {
                 thisEvent = j;
                 break;
              }
              if (thisEvent < 0) return -1;
           }
        } else {
           return -1;
        }
     } else return updated;

     if (event == CS_EVENT_EJECTION_REQUEST) {
        _interrupt = -1;
        _ports = "";
        _device = "";
        _module = "";
        _type = "";
        _iotype = 0;
        _inttype = 0;
        _cfgbase = 0;
        _cardname = i18n("Empty slot.");
        _vcc = _vpp = _vpp2 = 0;
        return updated;
     }

     /**
      *   Read in the stab file.
      */
     if (!stat(_stabPath.latin1(), &sb) && sb.st_mtime >= _last) {
        TQFile f(_stabPath.latin1());

        if (f.open(IO_ReadOnly)) {
          TQTextStream ts(&f);
          bool foundit = false;
          TQString _thisreg = "^Socket %1: ";
          TQRegExp thisreg ( _thisreg.arg(_num) );

          if (flock(f.handle(), LOCK_SH)) return updated;

          _last = sb.st_mtime;

          // find the card
          while(!foundit) {
            TQString s;
            if (ts.eof()) break;
            s = ts.readLine();
            if (s.contains(thisreg)) {
               _cardname = s.right(s.length() - s.find(':') - 1);
               _cardname = _cardname.stripWhiteSpace();
               foundit = true;
               CHECK_CHANGED(oldValues, _cardname);
            }
          }

          // read it in
          if (foundit && !ts.eof()) {  // FIXME: ts.eof() is a bad error!!
            TQString s = ts.readLine();
            int end;
            s.simplifyWhiteSpace();

            end = s.find(TQRegExp("[ \r\t\n]"));
            s = s.remove(0, end+1);

            end = s.find(TQRegExp("[ \r\t\n]"));
            _type = s;
            _type.truncate(end);
            s = s.remove(0, end+1);

            end = s.find(TQRegExp("[ \r\t\n]"));
            _module = s;
            _module.truncate(end);
            s = s.remove(0, end+1);

            end = s.find(TQRegExp("[ \r\t\n]"));
            s = s.remove(0, end+1);

            end = s.find(TQRegExp("[ \r\t\n]"));
            _device = s;
            _device.truncate(end);
            s = s.remove(0, end+1);
            CHECK_CHANGED(oldValues, _type);
            CHECK_CHANGED(oldValues, _module);
            CHECK_CHANGED(oldValues, _device);
          }

          flock(f.handle(), LOCK_UN);
          f.close();
        } else return -1;
     } else return updated;


     /**
      *   Get the card's status and configuration information
      */
     status.Function = 0;
     ioctl(_fd, DS_GET_STATUS, &status);
     memset(&cfg, 0, sizeof(cfg));
     ioctl(_fd, DS_GET_CONFIGURATION_INFO, &cfg);
     // status is looked up in the table at the top
     if (cfg.Attributes & CONF_VALID_CLIENT) {
        if (cfg.AssignedIRQ == 0)
          _interrupt = -1;
        else _interrupt = cfg.AssignedIRQ;

        if (cfg.NumPorts1 > 0) {
           int stop = cfg.BasePort1 + cfg.NumPorts1;
           if (cfg.NumPorts2 > 0) {
              if (stop == cfg.BasePort2) {
                 _ports.sprintf("%#x-%#x", cfg.BasePort1, stop+cfg.NumPorts2-1);
              } else {
                 _ports.sprintf("%#x-%#x, %#x-%#x", cfg.BasePort1, stop-1,
                               cfg.BasePort2, cfg.BasePort2+cfg.NumPorts2-1);
              }
           } else {
              _ports.sprintf("%#x-%#x", cfg.BasePort1, stop-1);
           }
        }
        CHECK_CHANGED(oldValues, _ports);
        CHECK_CHANGED(oldValues, _interrupt);
     }

     _vcc = cfg.Vcc;
     _vpp = cfg.Vpp1;
     _vpp2 = cfg.Vpp2;
     CHECK_CHANGED(oldValues, _vcc);
     CHECK_CHANGED(oldValues, _vpp);
     CHECK_CHANGED(oldValues, _vpp2);
     _inttype = cfg.IntType;
     CHECK_CHANGED(oldValues, _inttype);
     _iotype = cfg.IOAddrLines;
     CHECK_CHANGED(oldValues, _iotype);
     _cfgbase = cfg.ConfigBase;
     CHECK_CHANGED(oldValues, _cfgbase);

     if (status.CardState & CS_EVENT_CARD_DETECT)
        _status |= CARD_STATUS_PRESENT;
     if (status.CardState & CS_EVENT_CARD_REMOVAL)
        _status &= ~CARD_STATUS_PRESENT;
     if (event & CS_EVENT_CARD_REMOVAL)
        _status &= ~CARD_STATUS_PRESENT;

     if (!(status.CardState & CS_EVENT_PM_SUSPEND)) {
        if (status.CardState & CS_EVENT_READY_CHANGE) {
           _status |= CARD_STATUS_READY;
           _status &= ~(CARD_STATUS_BUSY|CARD_STATUS_SUSPEND);
        } else {
           _status |= CARD_STATUS_BUSY;
           _status &= ~(CARD_STATUS_READY|CARD_STATUS_SUSPEND);
        }
     } else if (status.CardState & CS_EVENT_PM_SUSPEND) {
        _status |= CARD_STATUS_SUSPEND;
        _status &= ~(CARD_STATUS_READY|CARD_STATUS_BUSY);
     }

     CHECK_CHANGED(oldValues, _status);

return updated;
#else
return 0;
#endif
}
Beispiel #30
0
void ExtensionManager::migrateMenubar()
{
    // lame, lame, lame.
    // the menubar applet was just plunked into kicker and not much
    // thought was put into how it should be used. great idea, but no
    // integration. >:-(
    // so now we have to check to see if we HAVE another extension that
    // will have a menubar in it, and if so, abort creating one of our
    // own.
    //
    // the reason i didn't do this as a tdeconfig_update script is that
    // most people don't use this feature, so no reason to penalize
    // everyone, and moreover the user may added this to their main
    // panel, meaning kickerrc itself would have to be vastly modified
    // with lots of complications. not work it IMHO.

    TDEConfig* config = TDEGlobal::config();
    config->setGroup("General");

    if (config->readBoolEntry("CheckedForMenubar", false))
    {
        return;
    }

    if (!locate("config", "kicker_menubarpanelrc").isEmpty())
    {
        // don't overwrite/override something that's already there
        return;
    }

    TQStringList elist = config->readListEntry("Extensions2");
    TQStringList::iterator itEnd = elist.end();
    for (TQStringList::iterator it = elist.begin(); it !=  elist.end(); ++it)
    {
        TQString extensionId(*it);

        if (extensionId.find("Extension") == -1)
        {
            continue;
        }

        // is there a config group for this extension?
        if (!config->hasGroup(extensionId))
        {
            continue;
        }

        config->setGroup(extensionId);
        TQString extension = config->readPathEntry("ConfigFile");
        TDEConfig extensionConfig(locate("config", extension));
        extensionConfig.setGroup("General");

        if (extensionConfig.hasKey("Applets2"))
        {
            TQStringList containers = extensionConfig.readListEntry("Applets2");
            TQStringList::iterator cit = containers.begin();
            TQStringList::iterator citEnd = containers.end();
            for (; cit != citEnd; ++cit)
            {
                TQString appletId(*cit);

                // is there a config group for this applet?
                if (!extensionConfig.hasGroup(appletId))
                {
                    continue;
                }

                TDEConfigGroup group(&extensionConfig, appletId.latin1());
                TQString appletType = appletId.left(appletId.findRev('_'));

                if (appletType == "Applet")
                {
                    TQString appletFile = group.readPathEntry("DesktopFile");
                    if (appletFile.find("menuapplet.desktop") != -1)
                    {
                        TQString menubarConfig = locate("config", extension);
                        TDEIO::NetAccess::copy(menubarConfig,
                                             locateLocal("config",
                                             "kicker_menubarpanelrc"), 0);
                        elist.remove(it);
                        config->setGroup("General");
                        config->writeEntry("Extensions2", elist);
                        config->writeEntry("CheckedForMenubar", true);
                        config->sync();
                        return;
                    }
                }
            }
        }
    }

    config->setGroup("General");
    config->writeEntry("CheckedForMenubar", true);
}