Beispiel #1
0
static ParseNode f_internalDcop(Parser* parser, const ParameterList& params)
{
  SpecialFunction function = SpecialInformation::functionObject("DCOP", params[0].toString());
  int functionId = SpecialInformation::function(Group::DCOP, params[0].toString());
  if (functionId == -1)
    return f_executeSlot(parser, params);
    //return ParseNode::error("unknown function");
  else if ((uint)function.minArg() > params.count() - 1)
    return ParseNode::error("too few parameters");
  else if ((uint)function.maxArg() < params.count() - 1)
    return ParseNode::error("too many parameters");
  KommanderWidget* widget = parser->currentWidget();
  if (widget)
    widget = widget->widgetByName(params[1].toString());
  if (!widget)
    return ParseNode::error("unknown widget");
  QStringList args;
  ParameterList::ConstIterator it = params.begin(); 
  ++it;   // skip function
  ++it;   // skip widget
  while (it != params.end())
  {
    args += (*it).toString(); 
    ++it;
  }
  return widget->handleDCOP(functionId, args);
}
Beispiel #2
0
static ParseNode f_stringArgs(Parser*, const ParameterList& params)
{
  if (params.count() == 2)
    return params[0].toString().arg(params[1].toString());
  else if (params.count() == 3)
    return params[0].toString().arg(params[1].toString()).arg(params[2].toString());
  else 
    return params[0].toString().arg(params[1].toString()).arg(params[2].toString()).arg(params[3].toString());
}
Beispiel #3
0
static ParseNode f_echo(Parser*, const ParameterList& params)
{
  for (uint i=0; i<params.count(); i++)
    std::cout << params[i].toString();
  fflush(stdout);
  return ParseNode();
}
Beispiel #4
0
void display::sFillList(ParameterList pParams, bool forceSetParams)
{
  emit fillListBefore();
  if (forceSetParams || !pParams.count())
  {
    if (!setParams(pParams))
      return;
  }
  int itemid = _data->_list->id();
  bool ok = true;
  QString errorString;
  MetaSQLQuery mql = MQLUtil::mqlLoad(_data->metasqlGroup, _data->metasqlName, errorString, &ok);
  if(!ok)
  {
    systemError(this, errorString, __FILE__, __LINE__);
    return;
  }
  XSqlQuery xq = mql.toQuery(pParams);
  _data->_list->populate(xq, itemid, _data->_useAltId);
  if (xq.lastError().type() != QSqlError::NoError)
  {
    systemError(this, xq.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  emit fillListAfter();
}
Beispiel #5
0
/******************* Debug function ********************************/
static ParseNode f_debug(Parser*, const ParameterList& params)
{
  for (uint i=0; i<params.count(); i++)
    std::cerr << params[i].toString();
  std::cerr << "\n";
  fflush(stderr);
  return ParseNode();
}
Beispiel #6
0
bool deliverEmail::submitReport(QWidget* parent, const QString reportName, const QString fileName, const QString from, const QString to, const QString cc, const QString subject, const QString body, const bool emailHTML, ParameterList &rptParams)
{
    if (to.isEmpty())
        return false;

    q.prepare( "SELECT submitReportToBatch( :reportname, :fromEmail, :emailAddress, :ccAddress, :subject,"
               "                            :emailBody, :fileName, CURRENT_TIMESTAMP, :emailHTML) AS batch_id;" );
    q.bindValue(":reportname", reportName);
    q.bindValue(":fileName", fileName);
    q.bindValue(":fromEmail", from);
    q.bindValue(":emailAddress", to);
    q.bindValue(":ccAddress", cc);
    q.bindValue(":subject", subject);
    q.bindValue(":emailBody", body);
    q.bindValue(":emailHTML", emailHTML);
    q.exec();
    if (q.first())
    {
        int batch_id = q.value("batch_id").toInt();
        int counter;

        q.prepare( "INSERT INTO batchparam "
                   "( batchparam_batch_id, batchparam_order,"
                   "  batchparam_name, batchparam_value ) "
                   "VALUES "
                   "( :batchparam_batch_id, :batchparam_order,"
                   "  :batchparam_name, :batchparam_value );" );
        q.bindValue(":batchparam_batch_id", batch_id);

        for (counter = 0; counter < rptParams.count(); counter++)
        {
            q.bindValue(":batchparam_order", counter+1);
            q.bindValue(":batchparam_name", rptParams.name(counter));
            q.bindValue(":batchparam_value", rptParams.value(counter));
            q.exec();
            if (q.lastError().type() != QSqlError::NoError)
            {
                systemError(parent, q.lastError().databaseText(), __FILE__, __LINE__);
                return false;
            }
        }

        q.bindValue(":batchparam_batch_id", batch_id);
        q.bindValue(":batchparam_order", counter+2);
        q.bindValue(":batchparam_name", "title");
        q.bindValue(":batchparam_value", "Emailed Customer Copy");
        q.exec();
        if (q.lastError().type() != QSqlError::NoError)
        {
            systemError(parent, q.lastError().databaseText(), __FILE__, __LINE__);
            return false;
        }
    }

    return true;
}
Beispiel #7
0
// ParameterList Conversion functions
QScriptValue ParameterListtoScriptValue(QScriptEngine *engine, const ParameterList &params)
{
  QScriptValue obj = engine->newObject();
  for(int i = 0; i < params.count(); i++)
  {
    obj.setProperty(params.name(i), ScriptToolbox::variantToScriptValue(engine, params.value(i)));
  }

  return obj;
}
Beispiel #8
0
static ParseNode f_dcop(Parser*, const ParameterList& params)
{
  QCString appId = params[0].toString().latin1();
  QCString object = params[1].toString().latin1();
  QString function = params[2].toString().section('(', 0, 0);
  QStringList items = QStringList::split(",", params[2].toString().section('(', 1, 1).section(')', 0, 0));
  QByteArray byteData;
  QDataStream byteDataStream(byteData, IO_WriteOnly);

  if (items.count() != params.count() - 3)
  {
     qDebug("Wrong number of parameters");
     return ParseNode();
  }
  int i = 3;
  for (QStringList::Iterator it = items.begin(); it != items.end(); ++it)
  {
    *it = (*it).stripWhiteSpace();
    if (*it == "int")
      byteDataStream << params[i++].toInt();
    else if (*it == "long")
      byteDataStream << params[i++].toInt();
    else if (*it == "float")
      byteDataStream << params[i++].toDouble();
    else if (*it == "double")
      byteDataStream << params[i++].toDouble();
    else if (*it == "bool")
      byteDataStream << (bool)params[i++].toInt();
    else if (*it == "QStringList")
      if (params[i].toString().find('\n') != -1)
        byteDataStream << QStringList::split("\n", params[i++].toString(), true);
      else
        byteDataStream << QStringList::split("\\n", params[i++].toString(), true);
    else 
      byteDataStream << params[i++].toString();
  }
  function.append(QString("(%1)").arg(items.join(",")));
  QCString replyType, byteReply;
  DCOPClient* cl = KApplication::dcopClient();
  if (!cl || !cl->call(appId, object, function.latin1(),
       byteData, replyType, byteReply))
  {
    qDebug("DCOP failure");
    return ParseNode();
  }
  QDataStream byteReplyStream(byteReply, IO_ReadOnly);
  if (replyType == "QString")
  {
    QString text;
    byteReplyStream >> text;
    return text;
  }
Beispiel #9
0
static ParseNode f_fileAppend(Parser*, const ParameterList& params)
{
  QString fname = params[0].toString();
  if (fname.isEmpty())
    return 0;
  QFile file(fname);
  if (!file.open(IO_WriteOnly | IO_Append))
    return 0;
  QTextStream text(&file);
  for (uint i=1; i<params.count(); i++)
    text << params[i].toString();
  return 1;
}
Beispiel #10
0
void dspInventoryHistoryByParameterList::sPrint()
{
  ParameterList params;
  setParams(params);
  if (!params.count())
    return;

  orReport report("InventoryHistory", params);
  if (report.isValid())
    report.print();
  else
    report.reportError(this);
}
Beispiel #11
0
void dspInventoryHistoryByParameterList::sFillList()
{
  _invhist->clear();

  ParameterList params;
  setParams(params);
  if (!params.count())
    return;
  MetaSQLQuery mql = mqlLoad("inventoryHistory", "detail");
  q = mql.toQuery(params);

  if (q.first())
  {
    _invhist->populate(q, true);
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Beispiel #12
0
static ParseNode f_stringFindRev(Parser*, const ParameterList& params)
{
  return params[0].toString().findRev(params[1].toString(), 
    params.count() == 3 ? params[2].toInt() : params[0].toString().length());
}
Beispiel #13
0
static ParseNode f_stringSection(Parser*, const ParameterList& params)
{
  return params[0].toString().section(params[1].toString(), params[2].toInt(), 
    params.count() == 4 ? params[3].toInt() : params[2].toInt());
}
Beispiel #14
0
void displayPrivate::print(ParameterList pParams, bool showPreview, bool forceSetParams)
{
  int numCopies = 1;
  ParameterList params = pParams;

  if (forceSetParams || !params.count())
  {
    if(!_parent->setParams(params))
      return;
  }
  params.append("isReport", true);

  XSqlQuery report;
  report.prepare("SELECT report_grade, report_source "
                 "  FROM report "
                 " WHERE (report_name=:report_name)"
                 " ORDER BY report_grade DESC LIMIT 1");
  report.bindValue(":report_name", reportName);
  report.exec();
  QDomDocument _doc;
  if (report.first())
  {
    QString errorMessage;
    int     errorLine;

    if (!_doc.setContent(report.value("report_source").toString(), &errorMessage, &errorLine))
    {
      QMessageBox::critical(_parent, ::display::tr("Error Parsing Report"),
        ::display::tr("There was an error Parsing the report definition. %1 %2").arg(errorMessage).arg(errorLine));
      return;
    }
  }
  else
  {
    QMessageBox::critical(_parent, ::display::tr("Report Not Found"),
      ::display::tr("The report %1 does not exist.").arg(reportName));
    return;
  }

  ORPreRender pre;
  pre.setDom(_doc);
  pre.setParamList(params);
  ORODocument * doc = pre.generate();

  if(doc)
  {
    ReportPrinter printer(QPrinter::HighResolution);
    printer.setNumCopies( numCopies );

    ORPrintRender render;
    render.setupPrinter(doc, &printer);

    if(showPreview)
    {
      QPrinter * tPrinter = &printer;
      QPrinter pdfPrinter(QPrinter::HighResolution);
      if(!printer.isValid())
      {
        render.setupPrinter(doc, &pdfPrinter);
        pdfPrinter.setOutputFormat(QPrinter::PdfFormat);
        tPrinter = &pdfPrinter;
      }
      PreviewDialog preview (doc, tPrinter, _parent);
      if (preview.exec() == QDialog::Rejected)
        return;
    }

    QPrintDialog pd(&printer);
    pd.setMinMax(1, doc->pages());
    if(pd.exec() == QDialog::Accepted)
    {
      render.render(doc, &printer);
    }
    delete doc;
  }
}
Beispiel #15
0
        virtual QString toString(MetaSQLInfo * mif, const ParameterList & params, int * nBreaks = 0, bool * isContinue = 0) {
            //qDebug("MetaSQLBlock::toString()");
            QString results = QString::null;

            MetaSQLOutput * output = 0;
            bool b = false, myContinue = false, found;
            int myBreaks = 0;
            int i = 0, n = 0, ii = 0;
            QList<QVariant> list;
            QVariant v, t;
            ParameterList pList;
            QString str;
            switch(_block) {
                case BlockIf:
                case BlockElseIf:
                    //qDebug("  BlockIf/BlockEleseIf");
                    b = _if_func->toVariant(params, nBreaks, isContinue).toBool();
                    if(_if_not) b = !b;
                    if(b) {
                        //qDebug("    Expression evaluated TRUE");
                        for(i = 0; i < _items.size(); i++)
                        {
                            output = _items.at(i);
                            results += output->toString(mif, params, nBreaks, isContinue);
                            if(nBreaks && *nBreaks) break;
                        }
                    } else if(_alt) {
                        //qDebug("    Expression evaluated FALSE");
                        results = _alt->toString(mif, params, nBreaks, isContinue);
                    }
                    break;

                case BlockForEach:
                    //qDebug("  BlockForEach");

                    // HERE
                    v = params.value(_loopVar, &found);
                    if(found) {
                        list = v.toList();
                        for(i = 0; i < list.count(); i++) {
                            str = _loopVar + "__FOREACH_POS__";

                            // create a new params list with our special var added in 
                            pList.clear();
                            pList.append(str, i);
                            for(n = 0; n < params.count(); n++) {
                                if(params.name(n) != str) {
                                    pList.append(params.name(n), params.value(n));
                                }
                            }

                            myBreaks = 0;
                            myContinue = false;

                            // execute the block
                            for(ii = 0; ii < _items.size(); ii++)
                            {
                                output = _items.at(ii);
                                results += output->toString(mif, pList, &myBreaks, &myContinue);
                                if(myBreaks) break;
                            }

                            if(myBreaks > 0) {
                                myBreaks--;
                                if(myBreaks > 0 || !myContinue) {
                                    if(nBreaks) *nBreaks = myBreaks;
                                    if(isContinue) *isContinue = myContinue;
                                    break;
                                }
                            }
                        }
                    }



                    break;

                case BlockElse:
                case BlockGeneric:
                    //qDebug("  BlockElse/BlockGeneric");
                    for(i = 0; i < _items.size(); i++)
                    {
                        output = _items.at(i);
                        results += output->toString(mif, params, nBreaks, isContinue);
                        if(nBreaks && *nBreaks) break;
                    }
                    break;

                default:
                    qDebug("Encountered unknown Block type %d.", _block);
            };

            return results;
        }
Beispiel #16
0
        virtual QVariant toVariant(const ParameterList & params, int * nBreaks = 0, bool * isContinue = 0) {
            //qDebug("MetaSQLFunction::toVariant()");
            QVariant val;
            if(_valid) {
                bool found;
                QString str;
                QRegExp re;
                QVariant t;
                int i = 0;
                switch(_func) {
                    case FunctionValue:
                    case FunctionLiteral:
                        //qDebug("  FunctionValue");
                        str = _params[0];
                        val = params.value(str);
                        if(val.type() == QVariant::List || val.type() == QVariant::StringList) {
                            str += "__FOREACH_POS__";
                            t = params.value(str, &found);
                            if(found) {
                                val = (val.toList())[t.toInt()];
                            } else {
                                // we are not in a loop or the loop we are in is not for
                                // this list so just return the first value in the list
                                val = val.toList().first();
                            }
                        }
                        break;
                    case FunctionExists:
                        //qDebug("  FunctionExists");
                        params.value(_params[0], &found);
                        val = ( found ? _trueVariant : _falseVariant );
                        break;
                    case FunctionReExists:
                        //qDebug("  FunctionReExists");
                        //qDebug("    Pattern: %s", (const char*)_params[0]);
                        re.setPattern(_params[0]);
                        for(i = 0; i < params.count(); i++) {
                            if(re.search(params.name(i)) != -1) {
                                val = _trueVariant;
                                break;
                            }
                        }
                        break;
                    case FunctionIsFirst:
                    case FunctionIsLast:
                        //qDebug("  FunctionIsFirst/FunctionIsLast");
                        val = _falseVariant;
                        str = _params[0];
                        t = params.value(str, &found);
                        if(found) {
                            if(t.type() == QVariant::List || t.type() == QVariant::StringList) {
                                str += "__FOREACH_POS__";
                                QVariant t2 = params.value(str, &found);
                                int pos = 0;
                                if(found)
                                    pos = t2.toInt();

                                QList<QVariant> l = t.toList();
                                if(l.size() > 0) {
                                    if((_func == FunctionIsFirst) && (pos == 0)) val = _trueVariant;
                                    else if((_func == FunctionIsLast) && ((pos + 1) == l.size())) val = _trueVariant;
                                }
                            } else {
                                val = _trueVariant;
                            }
                        }
                        break;
                    case FunctionContinue:
                    case FunctionBreak:
                        //qDebug("  FunctionContinue/FunctionBreak");
                        if(nBreaks && isContinue) {
                            *nBreaks = _nBreaks;
                            *isContinue = (_func == FunctionContinue);
                        }
                        break;
                    default:
                        (*_parent->_logger) << "MetaSQLFunction::toVariant() encountered unknown Function Type " << (int)_func << "!" << endl; 
                        // how did we get here?
                };
            }
            return val;
        }
Beispiel #17
0
orQuery::orQuery( const QString &qstrPName, const QString &qstrSQL,
                  ParameterList qstrlstParams, bool doexec, QSqlDatabase pDb )
{
  QString qstrParsedSQL(qstrSQL);
  QString qstrParam;
  int     intParamNum;
  int     intStartIndex = 0;

  qryQuery = 0;
  _database = pDb;

  //  Initialize some privates
  qstrName  = qstrPName;

  QRegExp rexp("<\\?.*\\?>");
  if(rexp.indexIn(qstrParsedSQL) == -1)
  {
    // Parse through the passed SQL populating the parameters
    QRegExp re("(?:%(\\d+))|(?:\\$\"([^\"]*)\")");
    while ((intStartIndex = re.indexIn(qstrParsedSQL,intStartIndex)) != -1)
    {
      QString val = " ";

      QString match = re.cap(0);
      if(match[0] == '$')
      {
        QString n = re.cap(2).toLower();
        val = qstrlstParams.value(n).toString();
        if(val.isNull())
        {
          // add this to the list of missing parameters
          if(!missingParamList.contains(n))
            missingParamList.append(n);
        }
      }
      else if(match[0] == '%')
      {
        //  Grab the parameter number
        intParamNum = re.cap(1).toInt();

        //  Replace the parameter hold with the specified paramemter
        //  Verify the parameter index
        if (intParamNum <= (int)qstrlstParams.count())
          val = qstrlstParams.value(intParamNum - 1).toString();
        else
        {
          // add this to the list of missing parameters
          QString s = QString("%%1").arg(intParamNum);
          if(!missingParamList.contains(s)) missingParamList.append(s);
        }
      }
      else
      {
        // ?!?!? How did we get here.
        qDebug("Match did not start with $ or %%...");
      }

      QString qstrWork = qstrParsedSQL.left(intStartIndex)
                       + val
                       + qstrParsedSQL.right(qstrParsedSQL.length() - intStartIndex - re.matchedLength());
      intStartIndex += val.length();
      qstrParsedSQL = qstrWork;
    }

    qstrQuery = qstrParsedSQL;

    if(doexec)
      execute();
  }
  else
  {
    qstrQuery = qstrParsedSQL;
    MetaSQLQuery mql(qstrParsedSQL);
    qryQuery = new XSqlQuery(mql.toQuery(qstrlstParams, _database, doexec));
    if (doexec)
      qryQuery->first();
    // TODO: actually look for missing parameters?
  }
}
Beispiel #18
0
bool Function::isValid(const ParameterList& params) const
{
  return params.count() >= minArgs() && params.count() <= maxArgs();
}
Beispiel #19
0
static ParseNode f_stringMid(Parser*, const ParameterList& params)
{
  return params[0].toString().mid(params[1].toInt(), params.count() == 3 ? params[2].toInt() : 0xffffffff);
}