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); return evalRel(file->modtime);
} }
bool SizeExpressionMB::eval(FileEntry *file)
{
return evalRel((int)(file->size/(uint64_t)(1024*1024)));
}
bool SizeExpression::eval(FileEntry *file) bool SizeExpression::eval(FileEntry *file)
{ {
return evalRel(file->size); return evalRel(file->size);

View File

@ -135,13 +135,23 @@ LogicalOperator ExpressionWidget::getOperator()
return exprOpElem->getLogicalOperator(); 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* ExpressionWidget::getRsExpression()
{ {
Expression * expr = NULL; Expression * expr = NULL;
std::list<std::string> wordList; std::list<std::string> wordList;
int lowVal = 0; uint64_t lowVal = 0;
int highVal = 0; uint64_t highVal = 0;
if (isStringSearchExpression()) if (isStringSearchExpression())
{ {
@ -155,7 +165,7 @@ Expression* ExpressionWidget::getRsExpression()
highVal = exprParamElem->getIntHighValue(); highVal = exprParamElem->getIntHighValue();
if (lowVal >highVal) if (lowVal >highVal)
{ {
lowVal = lowVal^highVal; lowVal = lowVal^highVal; // csoler: wow, that is some style!
highVal = lowVal^highVal; highVal = lowVal^highVal;
lowVal = lowVal^highVal; lowVal = lowVal^highVal;
} }
@ -184,32 +194,34 @@ Expression* ExpressionWidget::getRsExpression()
break; break;
case DateSearch: case DateSearch:
if (inRangedConfig) { if (inRangedConfig) {
expr = new DateExpression(exprCondElem->getRelOperator(), expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
lowVal,
highVal);
} else { } else {
expr = new DateExpression(exprCondElem->getRelOperator(), expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
exprParamElem->getIntValue());
} }
break; break;
case PopSearch: case PopSearch:
if (inRangedConfig) { if (inRangedConfig) {
expr = new DateExpression(exprCondElem->getRelOperator(), expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
lowVal,
highVal);
} else { } else {
expr = new DateExpression(exprCondElem->getRelOperator(), expr = new DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
exprParamElem->getIntValue());
} }
break; break;
case SizeSearch: case SizeSearch:
if (inRangedConfig) { if (inRangedConfig)
expr = new SizeExpression(exprCondElem->getRelOperator(), {
lowVal, if(lowVal >= (uint64_t)(1024*1024*1024) || highVal >= (uint64_t)(1024*1024*1024))
highVal); expr = new SizeExpressionMB(exprCondElem->getRelOperator(), (int)(lowVal / (1024*1024)), (int)(highVal / (1024*1024)));
} else { else
expr = new SizeExpression(exprCondElem->getRelOperator(), expr = new SizeExpression(exprCondElem->getRelOperator(), lowVal, highVal);
exprParamElem->getIntValue()); }
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; break;
}; };

View File

@ -567,9 +567,11 @@ QString ExprParamElement::getStrSearchValue()
return lineEdit->displayText(); 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" ; QString suffix = (isToField) ? "2": "1" ;
// NOTE qFindChild necessary for MSVC 6 compatibility!! // 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)); QDateEdit * dateEdit = qFindChild<QDateEdit *> (internalframe, (fieldName + suffix));
QDateTime * time = new QDateTime(dateEdit->date()); QDateTime * time = new QDateTime(dateEdit->date());
val = time->toTime_t(); val = (uint64_t)time->toTime_t();
break; break;
} }
case SizeSearch: case SizeSearch:
{ {
QLineEdit * lineEditSize = qFindChild<QLineEdit*>(internalframe, (fieldName + suffix)); QLineEdit * lineEditSize = qFindChild<QLineEdit*>(internalframe, (fieldName + suffix));
bool ok = false; bool ok2 = false;
val = (lineEditSize->displayText()).toInt(&ok); val = (lineEditSize->displayText()).toULongLong(&ok2);
if (ok) { if (ok2)
{
QComboBox * cb = qFindChild<QComboBox*> (internalframe, (QString("unitsCb") + suffix)); QComboBox * cb = qFindChild<QComboBox*> (internalframe, (QString("unitsCb") + suffix));
QVariant data = cb->itemData(cb->currentIndex()); QVariant data = cb->itemData(cb->currentIndex());
val *= data.toInt(); val *= data.toULongLong();
} else { }
val = -1; else
} if(ok!=NULL)
*ok=false ;
break; break;
} }
case PopSearch: // not implemented case PopSearch: // not implemented
@ -612,23 +617,24 @@ int ExprParamElement::getIntValueFromField(QString fieldName, bool isToField)
case HashSearch: case HashSearch:
default: default:
// shouldn't be here...val stays at -1 // shouldn't be here...val stays at -1
val = -1; if(ok!=NULL)
*ok=false ;
} }
return val; return val;
} }
int ExprParamElement::getIntValue() uint64_t ExprParamElement::getIntValue()
{ {
return getIntValueFromField("param"); return getIntValueFromField("param");
} }
int ExprParamElement::getIntLowValue() uint64_t ExprParamElement::getIntLowValue()
{ {
return getIntValue(); return getIntValue();
} }
int ExprParamElement::getIntHighValue() uint64_t ExprParamElement::getIntHighValue()
{ {
if (!inRangedConfig) return getIntValue(); if (!inRangedConfig) return getIntValue();
return getIntValueFromField("param", true); return getIntValueFromField("param", true);

View File

@ -192,9 +192,9 @@ public:
void setRangedSearch(bool ranged = true); void setRangedSearch(bool ranged = true);
bool ignoreCase(); bool ignoreCase();
QString getStrSearchValue(); QString getStrSearchValue();
int getIntValue(); uint64_t getIntValue();
int getIntLowValue(); uint64_t getIntLowValue();
int getIntHighValue(); uint64_t getIntHighValue();
virtual QString toString(); virtual QString toString();
private: private:
@ -202,7 +202,7 @@ private:
QRegExpValidator * hexValidator; QRegExpValidator * hexValidator;
QFrame * rangeParamsFrame; QFrame * rangeParamsFrame;
bool inRangedConfig; bool inRangedConfig;
int getIntValueFromField(QString fieldName, bool isToField=false); uint64_t getIntValueFromField(QString fieldName, bool isToField=false,bool *ok = NULL);
}; };
#endif #endif