Exemplo n.º 1
0
void TreeKeyIdx::setText(const char *ikey) {
	char *buf = 0;
	stdstr(&buf, ikey);
	SWBuf leaf = strtok(buf, "/");
	leaf.trim();
	root();
	while ((leaf.size()) && (!popError())) {
		bool ok, inChild = false;
		error = KEYERR_OUTOFBOUNDS;
		for (ok = firstChild(); ok; ok = nextSibling()) {
			inChild = true;
			if (leaf == getLocalName()) {
				error = 0;
				break;
			}
		}
		leaf = strtok(0, "/");
		leaf.trim();
		if (!ok) {
		    	if (inChild) {	// if we didn't find a matching child node, default to first child
				parent();
				firstChild();
			}
			error = KEYERR_OUTOFBOUNDS;
		}
	}
	if (leaf.size())
		error = KEYERR_OUTOFBOUNDS;
	delete [] buf;
	unsnappedKeyText = ikey;
	positionChanged();
}
Exemplo n.º 2
0
void ListKey::decrement(int step) {
	if (step < 0) {
		increment(step*-1);
		return;
	}
	popError();		// clear error
	for(; step && !popError(); step--) {
		if (arraypos > -1 && arraycnt) {
			if (array[arraypos]->isBoundSet())
				(*(array[arraypos]))--;
			if ((array[arraypos]->popError()) || (!array[arraypos]->isBoundSet())) {
				setToElement(arraypos-1, BOTTOM);
			}
			else SWKey::setText((const char *)(*array[arraypos]));
		}
		else error = KEYERR_OUTOFBOUNDS;
	}
}
Exemplo n.º 3
0
/** Sets the key of this instance */
bool CSwordLDKey::setKey(const char *newKey) {
    Q_ASSERT(newKey);

    if (newKey) {
        SWKey::operator = (newKey); //set the key
        m_module->module()->setKey(this);
        m_module->snap();
    }

    return !popError();
}
Exemplo n.º 4
0
void TreeKeyIdx::setPosition(SW_POSITION p) {
	switch (p) {
	case POS_TOP:
		root();
		break;
	case POS_BOTTOM:
		error = getTreeNodeFromIdxOffset(idxfd->seek(-4, SEEK_END), &currentNode);
		break;
	} 
	positionChanged();
	popError();	// clear error from normalize
}
Exemplo n.º 5
0
  /*
   * Return a species thermo manager to handle the parameterizations
   * specified in a CTML phase specification.
   */
  SpeciesThermo* SpeciesThermoFactory::newSpeciesThermo(std::vector<XML_Node*> & spDataNodeList) const {
    int inasa = 0, ishomate = 0, isimple = 0, iother = 0;
    try {
      getSpeciesThermoTypes(spDataNodeList, inasa, ishomate, isimple, iother);
    } catch (UnknownSpeciesThermoModel) {
      iother = 1;
      popError();
    }
    if (iother) {
      //writelog("returning new GeneralSpeciesThermo");
      return new GeneralSpeciesThermo();
    }
    return newSpeciesThermo(NASA*inasa
			    + SHOMATE*ishomate + SIMPLE*isimple);
  }
Exemplo n.º 6
0
SpeciesThermo* SpeciesThermoFactory::newSpeciesThermo(std::vector<XML_Node*> & spDataNodeList) const
{
    warn_deprecated("SpeciesThermoFactory::newSpeciesThermo",
        "To be removed after Cantera 2.2. Use class GeneralSpeciesThermo directly.");
    int inasa = 0, ishomate = 0, isimple = 0, iother = 0;
    try {
        getSpeciesThermoTypes(spDataNodeList, inasa, ishomate, isimple, iother);
    } catch (UnknownSpeciesThermoModel) {
        iother = 1;
        popError();
    }
    if (iother) {
        return new GeneralSpeciesThermo();
    }
    return newSpeciesThermo(NASA*inasa
                            + SHOMATE*ishomate + SIMPLE*isimple);
}
Exemplo n.º 7
0
  // Chose the variable pressure standard state manager 
  // and the reference standard state manager
  VPSSMgr* 
  VPSSMgrFactory::newVPSSMgr(VPStandardStateTP *vp_ptr, 
			     XML_Node* phaseNode_ptr,
			     std::vector<XML_Node*> & spDataNodeList) {

    std::string ssManager="";
    std::string vpssManager="";
    VPSSMgr *vpss = 0;

    // First look for any explicit instructions within the XML Database
    // for the standard state manager and the variable pressure 
    // standard state manager
    if (phaseNode_ptr) {
      if (phaseNode_ptr->hasChild("thermo")) {
	const XML_Node& thermoNode = phaseNode_ptr->child("thermo");
	if (thermoNode.hasChild("standardStateManager")) {
	  const XML_Node& ssNode = thermoNode.child("standardStateManager");
	  ssManager = ssNode["model"];
	}
	if (thermoNode.hasChild("variablePressureStandardStateManager")) {
	  const XML_Node& vpssNode = thermoNode.child("variablePressureStandardStateManager");
	  vpssManager = vpssNode["model"];
	}
      }
    }

    // first get the reference state handler. If we have explicit instructions,
    // use them to spawn the object.
    SpeciesThermo *spth = 0;
    if (ssManager != "") {
      spth = newSpeciesThermoMgr(ssManager);
    } else {
      spth = newSpeciesThermoMgr(spDataNodeList);
    }
    vp_ptr->setSpeciesThermo(spth);

    // Next, if we have specific directions, use them to get the VPSSSMgr object
    // and return immediately
    if (vpssManager != "") {
      VPSSMgr_enumType type = VPSSMgr_StringConversion(vpssManager);
      vpss = newVPSSMgr(type, vp_ptr);
      return vpss;
    }

 
    // If it comes back as general, then there may be some unknown 
    // parameterizations to the SpeciesThermo factory routine.
    bool haveSomeUnknowns = true;
    GeneralSpeciesThermo *ttmp = dynamic_cast<GeneralSpeciesThermo *>(spth);
    if (ttmp == 0) {
      haveSomeUnknowns = false;
    }
 
    // Handle special cases based on the VPStandardState types
    if (vp_ptr->eosType() == cVPSS_IdealGas) {
      vpss = new VPSSMgr_IdealGas(vp_ptr, spth);
      return vpss;
    } else if (vp_ptr->eosType() == cVPSS_ConstVol) {
      vpss = new VPSSMgr_ConstVol(vp_ptr, spth);
      return vpss;
    }


    int inasaIG = 0, inasaCV = 0, ishomateIG = 0, ishomateCV = 0,
      isimpleIG = 0, isimpleCV = 0, 
      iwater = 0, itpx = 0, iother = 0;
    int ihptx = 0;
  
    try {
      getVPSSMgrTypes(spDataNodeList, inasaIG, inasaCV, ishomateIG, ishomateCV,
		      isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
    } catch (UnknownSpeciesThermoModel) {
      iother = 1;
      popError();
    }
    
    if (iwater == 1) {
      if (ihptx == 0) {
	if (inasaIG ||  ishomateIG || isimpleIG) {
	  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
	} else {
	  vpss = new VPSSMgr_Water_ConstVol(vp_ptr, spth);
	}
      } else {
	if (inasaIG ||  ishomateIG || isimpleIG) {
	  throw CanteraError("newVPSSMgr", "Ideal gas with liquid water");
	} else if (inasaCV || ishomateCV ||  isimpleCV) {
	  vpss = new VPSSMgr_General(vp_ptr, spth);
	} else {
	  vpss = new VPSSMgr_Water_HKFT(vp_ptr, spth);
	}
      }
    }
    if (vpss == 0) {
      if (inasaCV || ishomateCV || isimpleCV) {
	if (!inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
	  vpss = new VPSSMgr_ConstVol(vp_ptr, spth);
	}
      }
    }
    if (vpss == 0) {
      vpss = new VPSSMgr_General(vp_ptr, spth);
    }
    return vpss;
  }
Exemplo n.º 8
0
//-----------------------------------------------------------------------------
bool KMAcctPop::authenticate(DwPopClient& client)
{
  QString passwd;
  const char* msg=0;
  KMPasswdDialog* dlg;
  bool opened = FALSE;
  int replyCode;

  if(mPasswd.isEmpty() || mLogin.isEmpty())
    msg = i18n("Please set Password and Username");

  passwd = decryptStr(mPasswd);
  passwd.detach();

  while (1)
  {
    if (msg)
    {
      dlg = new KMPasswdDialog(NULL, NULL, this, msg,
			       mLogin, passwd);
      if (!dlg->exec()) return FALSE;
      delete dlg;
      msg = 0;
    }

    // Some POP servers close the connection upon failed
    // user/password. So we close the connection here to
    // be sure that everything below runs as we expect it.
    if (opened)
    {
      client.Quit();
      client.Close();
    }
      
    // Open connection to server
    if (client.Open(mHost,mPort) != '+')
      return popError("OPEN", client);
    opened = TRUE;
    app->processEvents();

    // Send user name
    replyCode = client.User((const char*)mLogin);
    if (replyCode == '-')
    {
      msg = i18n("Incorrect Username");
      continue;
    }
    else if (replyCode != '+')
      return popError("USER", client);
    app->processEvents();

    // Send password
    passwd = decryptStr(mPasswd);
    passwd.detach();
    replyCode = client.Pass((const char*)passwd);
    if (replyCode == '-')
    {
      msg = i18n("Incorrect Password");
      continue;
    }
    else if (replyCode != '+')
      return popError("PASS", client);

    // Ok, we are done
    break;
  }

  return TRUE;
}
Exemplo n.º 9
0
//-----------------------------------------------------------------------------
bool KMAcctPop::doProcessNewMail(KMIOStatus *wid)
{
  DwPopClient client;
  QString passwd;
  QString response, status;
  int num, size;	// number of all msgs / size of all msgs
  int id, i;		// id of message to read
  int tmout;
  int dummy;
  char dummyStr[32];
  //int replyCode; // ReplyCode need from User & Passwd call.
  KMMessage* msg;
  gotMsgs = FALSE;
  bool doFetchMsg;
  bool addedOk;   //Flag if msg was delivered succesfully
  
  wid->prepareTransmission(host(), KMIOStatus::RETRIEVE);

  // is everything specified ?
  app->processEvents();

  if (mHost.isEmpty() || mPort<=0)
  {
    warning(i18n("Please specify Host, Port  and\n"
		 "destination folder in the settings\n"
		 "and try again."));
    return FALSE;
  }

  client.SetReceiveTimeout(20);

  // Handle connect, user, and password.
  if (!authenticate(client)) return FALSE;

  if (client.Stat() != '+') return popError("STAT", client);
  response = client.SingleLineResponse().c_str();
  sscanf(response.data(), "%3s %d %d", dummyStr, &num, &size);

//#warning "*** If client.Last() cannot be found then install the latest kdesupport"
  if (!mRetrieveAll && client.Last() == '+')
  {
    response = client.SingleLineResponse().c_str();
    sscanf(response.data(), "%3s %d", dummyStr, &id);
    id++;
  }
  else id = 1;

  // workaround but still is no good. If msgs are too big in size
  // we will get a timeout.
  client.SetReceiveTimeout(40);

  addedOk = true;
  
  // do while there are mesages to take and last msg wass added succesfully
  while (id <= num && addedOk)
  {
    client.SetReceiveTimeout(40);

    if(wid->abortRequested()) {
      client.Quit();
      return gotMsgs;
    }
    wid->updateProgressBar(id, num);
    app->processEvents();
    if (client.List(id) != '+')
      return popError("LIST", client);
    response = client.SingleLineResponse().c_str();
    sscanf(response.data(), "%3s %d %d", dummyStr, &dummy, &size);

    doFetchMsg = TRUE;
    if (size > 4500 && !mRetrieveAll)
    {
      // If the message is large it is cheaper to first load
      // the header to check the status of the message.
      // We will have to load the entire message with the RETR
      // command below, so we will not fetch the header for
      // small messages.
      if (client.Top(id,1) != '+')
	return popError("TOP", client);
      response = client.MultiLineResponse().c_str();
      i = response.find("\nStatus:");
      if (i<0) i = response.find("\rStatus:");
      if (i>=0)
      {
	status = response.mid(i+8,32).stripWhiteSpace();
	if (strnicmp(status,"RO",2)==0 ||
	    strnicmp(status,"OR",2)==0)
	{
	  doFetchMsg=FALSE;
	  debug("message %d is old -- no need to download it", id);
	}
      }
    }

    if (doFetchMsg)
    {
      // set timeout depending on size
      tmout = size >> 8;
      if (tmout < 30) tmout = 30;
      client.SetReceiveTimeout(tmout);

      if (client.Retr(id) != '+')
	return popError("RETR", client);
      response = client.MultiLineResponse().c_str();

      msg = new KMMessage;
      msg->fromString(response,TRUE);
      if (mRetrieveAll || msg->status()!=KMMsgStatusOld)
	addedOk = processNewMsg(msg); //added ok? Error displayed if not.
      else delete msg;
    }

    // If we should delete from server _and_ we added ok then delete it
    if(!mLeaveOnServer && addedOk)
    {
      if(client.Dele(id) != '+')
	return popError("DELE",client);
      else 
	std::cout << client.SingleLineResponse().c_str();
    }

    gotMsgs = TRUE;
    id++;
  }
  wid->transmissionCompleted();
  client.Quit();
  return gotMsgs;
}