diff --git a/libretroshare/src/dbase/rsexpr.cc b/libretroshare/src/dbase/rsexpr.cc index ac819209d..39859795c 100644 --- a/libretroshare/src/dbase/rsexpr.cc +++ b/libretroshare/src/dbase/rsexpr.cc @@ -48,6 +48,11 @@ bool DateExpression::eval(FileEntry *file) return evalRel(file->modtime); } +bool SizeExpressionMB::eval(FileEntry *file) +{ + return evalRel((int)(file->size/(uint64_t)(1024*1024))); +} + bool SizeExpression::eval(FileEntry *file) { return evalRel(file->size); diff --git a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp index 87996da56..dfca2c2f5 100644 --- a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp +++ b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp @@ -135,13 +135,23 @@ LogicalOperator ExpressionWidget::getOperator() return exprOpElem->getLogicalOperator(); } +static int checkedConversion(uint64_t s) +{ + if(s > 0x7fffffff) + { + std::cerr << "Error: bad convertion from uint64_t s=" << s << " into int" << std::endl; + return 0 ; + } + return (int)s ; +} + Expression* ExpressionWidget::getRsExpression() { Expression * expr = NULL; std::list wordList; - int lowVal = 0; - int highVal = 0; + uint64_t lowVal = 0; + uint64_t highVal = 0; if (isStringSearchExpression()) { @@ -155,7 +165,7 @@ Expression* ExpressionWidget::getRsExpression() highVal = exprParamElem->getIntHighValue(); if (lowVal >highVal) { - lowVal = lowVal^highVal; + lowVal = lowVal^highVal; // csoler: wow, that is some style! highVal = lowVal^highVal; lowVal = lowVal^highVal; } @@ -184,32 +194,34 @@ Expression* ExpressionWidget::getRsExpression() break; case DateSearch: if (inRangedConfig) { - expr = new DateExpression(exprCondElem->getRelOperator(), - lowVal, - highVal); + expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); } else { - expr = new DateExpression(exprCondElem->getRelOperator(), - exprParamElem->getIntValue()); + expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); } break; case PopSearch: if (inRangedConfig) { - expr = new DateExpression(exprCondElem->getRelOperator(), - lowVal, - highVal); + expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal)); } else { - expr = new DateExpression(exprCondElem->getRelOperator(), - exprParamElem->getIntValue()); + expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue())); } break; case SizeSearch: - if (inRangedConfig) { - expr = new SizeExpression(exprCondElem->getRelOperator(), - lowVal, - highVal); - } else { - expr = new SizeExpression(exprCondElem->getRelOperator(), - exprParamElem->getIntValue()); + if (inRangedConfig) + { + if(lowVal >= (uint64_t)(1024*1024*1024) || highVal >= (uint64_t)(1024*1024*1024)) + expr = new SizeExpressionMB(exprCondElem->getRelOperator(), (int)(lowVal / (1024*1024)), (int)(highVal / (1024*1024))); + else + expr = new SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal); + } + else + { + uint64_t s = exprParamElem->getIntValue() ; + + if(s >= (uint64_t)(1024*1024*1024)) + expr = new SizeExpressionMB(exprCondElem->getRelOperator(), (int)(s/(1024*1024))) ; + else + expr = new SizeExpression(exprCondElem->getRelOperator(), (int)s) ; } break; }; diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp index 47e286ae4..98bcc9742 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.cpp +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.cpp @@ -567,9 +567,11 @@ QString ExprParamElement::getStrSearchValue() return lineEdit->displayText(); } -int ExprParamElement::getIntValueFromField(QString fieldName, bool isToField) +uint64_t ExprParamElement::getIntValueFromField(QString fieldName, bool isToField,bool *ok) { - int val = -1; + uint64_t val = 0; + if(ok!=NULL) + *ok=true ; QString suffix = (isToField) ? "2": "1" ; // NOTE qFindChild necessary for MSVC 6 compatibility!! @@ -579,21 +581,24 @@ int ExprParamElement::getIntValueFromField(QString fieldName, bool isToField) { QDateEdit * dateEdit = qFindChild (internalframe, (fieldName + suffix)); QDateTime * time = new QDateTime(dateEdit->date()); - val = time->toTime_t(); + val = (uint64_t)time->toTime_t(); break; } case SizeSearch: { QLineEdit * lineEditSize = qFindChild(internalframe, (fieldName + suffix)); - bool ok = false; - val = (lineEditSize->displayText()).toInt(&ok); - if (ok) { + bool ok2 = false; + val = (lineEditSize->displayText()).toULongLong(&ok2); + if (ok2) + { QComboBox * cb = qFindChild (internalframe, (QString("unitsCb") + suffix)); QVariant data = cb->itemData(cb->currentIndex()); - val *= data.toInt(); - } else { - val = -1; - } + val *= data.toULongLong(); + } + else + if(ok!=NULL) + *ok=false ; + break; } case PopSearch: // not implemented @@ -612,23 +617,24 @@ int ExprParamElement::getIntValueFromField(QString fieldName, bool isToField) case HashSearch: default: // shouldn't be here...val stays at -1 - val = -1; + if(ok!=NULL) + *ok=false ; } return val; } -int ExprParamElement::getIntValue() +uint64_t ExprParamElement::getIntValue() { return getIntValueFromField("param"); } -int ExprParamElement::getIntLowValue() +uint64_t ExprParamElement::getIntLowValue() { return getIntValue(); } -int ExprParamElement::getIntHighValue() +uint64_t ExprParamElement::getIntHighValue() { if (!inRangedConfig) return getIntValue(); return getIntValueFromField("param", true); diff --git a/retroshare-gui/src/gui/advsearch/guiexprelement.h b/retroshare-gui/src/gui/advsearch/guiexprelement.h index 739931bac..1cdcf1f2a 100644 --- a/retroshare-gui/src/gui/advsearch/guiexprelement.h +++ b/retroshare-gui/src/gui/advsearch/guiexprelement.h @@ -192,9 +192,9 @@ public: void setRangedSearch(bool ranged = true); bool ignoreCase(); QString getStrSearchValue(); - int getIntValue(); - int getIntLowValue(); - int getIntHighValue(); + uint64_t getIntValue(); + uint64_t getIntLowValue(); + uint64_t getIntHighValue(); virtual QString toString(); private: @@ -202,7 +202,7 @@ private: QRegExpValidator * hexValidator; QFrame * rangeParamsFrame; bool inRangedConfig; - int getIntValueFromField(QString fieldName, bool isToField=false); + uint64_t getIntValueFromField(QString fieldName, bool isToField=false,bool *ok = NULL); }; #endif