Beispiel #1
0
static TQString roundNumber(const TQString &numStr, int precision)
{
  TQString tmpString = numStr;
  if (precision < 0  ||
      ! TQRegExp("^[+-]?\\d+(\\.\\d+)*(e[+-]?\\d+)?$").exactMatch(tmpString))
    return numStr;


  // Skip the sign (for now)
  bool neg = (tmpString[0] == '-');
  if (neg  ||  tmpString[0] == '+') tmpString.remove(0, 1);


  // Split off exponential part (including 'e'-symbol)
  TQString mantString = tmpString.section('e', 0, 0,
					 TQString::SectionCaseInsensitiveSeps);
  TQString expString = tmpString.section('e', 1, 1,
					TQString::SectionCaseInsensitiveSeps |
					TQString::SectionIncludeLeadingSep);
  if (expString.length() == 1) expString = TQString();


  _round(mantString, precision);

  if(neg) mantString.prepend('-');

  return mantString +  expString;
}
Beispiel #2
0
void TESession::setUserTitle( int what, const TQString &caption )
{
    // (btw: what=0 changes title and icon, what=1 only icon, what=2 only title
    if ((what == 0) || (what == 2))
       userTitle = caption;
    if ((what == 0) || (what == 1))
       iconText = caption;
    if (what == 11) {
      TQString colorString = caption.section(';',0,0);
      TQColor backColor = TQColor(colorString);
      if (backColor.isValid()){// change color via \033]11;Color\007
	if (backColor != modifiedBackground) {
	    modifiedBackground = backColor;
	    te->setDefaultBackColor(backColor);
	}
      }
    }
    if (what == 30)
       renameSession(caption);
    if (what == 31) {
       cwd=caption;
       cwd=cwd.replace( TQRegExp("^~"), TQDir::homeDirPath() );
       emit openURLRequest(cwd);
    }    
    if (what == 32) { // change icon via \033]32;Icon\007
       iconName = caption;
       te->update();
    }

    emit updateTitle(this);
}
Beispiel #3
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 #4
0
void Security::slotDataArrived(KProcIO *procIO)
{
  TQString data;
  while (procIO->readln(data, true) != -1)
  {
     switch (m_runMode)
     {
        case List:
        case ListSecret:  
          if (data.startsWith("pub") || data.startsWith("sec"))
          {
              KeyStruct key;
              if (data.startsWith("pub"))
                key.secret = false;
              else
                key.secret = true;
              TQStringList line = TQStringList::split(":", data, true);
              key.id = line[4];
              TQString shortId = key.id.right(8);
              TQString trustStr = line[1];
              key.trusted = false;
              if (trustStr == "u" || trustStr == "f")
                  key.trusted = true;
              data = line[9];
              key.mail=data.section('<', -1, -1);
              key.mail.truncate(key.mail.length() - 1);
              key.name=data.section('<',0,0);
              if (key.name.find("(")!=-1)
                  key.name=key.name.section('(',0,0);
              m_keys[shortId] = key;
          }
          break;
       case Verify:
          data = TQString(data.section("]",1,-1)).stripWhiteSpace();
          if (data.startsWith("GOODSIG"))
          {
              m_result &= SIGNED_BAD_CLEAR;
              m_result |= SIGNED_OK;
              TQString id = data.section(" ", 1 , 1).right(8);
              if (!m_keys.contains(id))
              {
                  m_result |= UNKNOWN;
              } else
              {
                 m_signatureKey = m_keys[id];
              }
          } else
          if (data.startsWith("NO_PUBKEY"))
          {
              m_result &= SIGNED_BAD_CLEAR;
              m_result |= UNKNOWN;
          } else
          if (data.startsWith("BADSIG"))
          {
              m_result |= SIGNED_BAD;
              TQString id = data.section(" ", 1 , 1).right(8);
              if (!m_keys.contains(id))
              {
                  m_result |= UNKNOWN;
              } else
              {
                 m_signatureKey = m_keys[id];
              }
          } else
          if (data.startsWith("TRUST_ULTIMATE"))
          {
            m_result &= SIGNED_BAD_CLEAR;
            m_result |= TRUSTED;
          }
          break;

       case Sign:
         if (data.find("passphrase.enter") != -1)
         {
           TQCString password;
           KeyStruct key = m_keys[m_secretKey];
           int result = KPasswordDialog::getPassword(password, i18n("<qt>Enter passphrase for key <b>0x%1</b>, belonging to<br><i>%2&lt;%3&gt;</i>:</qt>").arg(m_secretKey).arg(key.name).arg(key.mail));
           if (result == KPasswordDialog::Accepted)
           {
             procIO->writeStdin(password, true);
             password.fill(' ');
           }
           else
           {
             m_result |= BAD_PASSPHRASE;
             slotProcessExited(procIO);
             return;
           }
         } else
         if (data.find("BAD_PASSPHRASE") != -1)
         {
           m_result |= BAD_PASSPHRASE;
         }
         break;
     }
  }
}
Beispiel #5
0
static void processMetaDataOptions( const TQPtrList<FileProps> propList,
                                    TDECmdLineArgs *args )
{
// tdefile --mimetype --supportedMimetypes --listsupported --listavailable --listpreferred --listwritable --getValue "key" --setValue "key=value" --allValues --preferredValues --dialog --quiet file [file...]
// "key" may be a list of keys, separated by commas

    TQString line("-- -------------------------------------------------------");
    FileProps *props;
    TQPtrListIterator<FileProps> it( propList );
    for ( ; (props = it.current()); ++it )
    {
        TQString file = props->fileName() + " ";
        TQString fileString = line.replace( 3, file.length(), file );
        cout << TQFile::encodeName( fileString ).data() << endl;
            
        if ( args->isSet( "listsupported" ) )
        {
            cout << "=Supported Keys=" << endl;
            printList( props->supportedKeys() );
        }
        if ( args->isSet( "listpreferred" ) )
        {
            cout << "=Preferred Keys=" << endl;
            printList( props->preferredKeys() );
        }
        if ( args->isSet( "listavailable" ) )
        {
            cout << "=Available Keys=" << endl;
            TQStringList groups = props->availableGroups();
            TQStringList::ConstIterator git = groups.begin();
            for ( ; git != groups.end(); ++git )
            {
                cout << "Group: " << (*git).local8Bit().data() << endl;
                printList( props->availableKeys( *git ) );
            }
        }
//         if ( args->isSet( "listwritable" ) )
//         {
//             cout << "TODO :)" << endl;
//         }
        if ( args->isSet( "getValue" ) )
        {
            cout << "=Value=" << endl;
            TQString key = TQString::fromLocal8Bit( args->getOption("getValue"));
            TQStringList::ConstIterator git = props->groupsToUse().begin();
            for ( ; git != props->groupsToUse().end(); ++git )
                cout << props->getValue( *git, key ).local8Bit().data() << endl;
        }

        if ( args->isSet( "setValue" ) )
        {
            // separate key and value from the line "key=value"
            TQString cmd = TQString::fromLocal8Bit( args->getOption("setValue"));
            TQString key = cmd.section( '=', 0, 0 );
            TQString value = cmd.section( '=', 1 );

            // either use supplied groups or all supported groups
            // (not only the available!)
            TQStringList groups = props->userSuppliedGroups() ?
                                 props->groupsToUse() :
                                 props->supportedGroups();

            TQStringList::ConstIterator git = groups.begin();
            for ( ; git != groups.end(); ++git )
                props->setValue( *git, key, value );
        }

        if ( args->isSet( "allValues" ) )
        {
            cout << "=All Values=" << endl;
            TQStringList groups = props->availableGroups();
            TQStringList::ConstIterator group = groups.begin();
            for ( ; group != groups.end(); ++group )
                printList( props->allValues( *group ) );
        }
        if ( args->isSet( "preferredValues" ) && !args->isSet("allValues") )
        {
            cout << "=Preferred Values=" << endl;
            TQStringList groups = props->availableGroups();
            TQStringList::ConstIterator group = groups.begin();
            for ( ; group != groups.end(); ++group )
                printList( props->preferredValues( *group ) );
        }
    }

}
Beispiel #6
0
TQString KStringHandler::word( const TQString &text , uint pos )
{
    return text.section( ' ', pos, pos );
}