implemented a backward compatible fix for bug when searching (advanced) with max size larger than 2Gb

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4094 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-03-15 23:12:46 +00:00
parent 9e2be4b5be
commit 794ab4aa06
4 changed files with 61 additions and 38 deletions

View File

@ -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);

View File

@ -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<std::string> 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;
};

View File

@ -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<QDateEdit *> (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<QLineEdit*>(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<QComboBox*> (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);

View File

@ -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