add min/max size entries to adv search + convert size display to decimal (instead of 1024-based)

This commit is contained in:
Jean-Francois Dockes 2012-03-07 17:52:32 +01:00
parent 7ddbbb1ee8
commit 420157d998
4 changed files with 76 additions and 6 deletions

View File

@ -145,6 +145,46 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line2">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelminsize">
<property name="toolTip">
<string>Minimum size. You can use k/K,m/M,g/G as multipliers</string>
</property>
<property name="text">
<string>Min. Size</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="minSizeLE"/>
</item>
<item>
<widget class="QLabel" name="labelmaxsize">
<property name="toolTip">
<string>Maximum size. You can use k/K,m/M,g/G as multipliers</string>
</property>
<property name="text">
<string>Max. Size</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="maxSizeLE"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line4">
<property name="frameShape">

View File

@ -300,6 +300,30 @@ void AdvSearch::saveFileTypes()
rwSettings(true);
}
size_t AdvSearch::stringToSize(QString qsize)
{
size_t size = size_t(-1);
qsize.replace(QRegExp("[\\s]+"), "");
if (!qsize.isEmpty()) {
string csize((const char*)qsize.toAscii());
char *cp;
size = strtoll(csize.c_str(), &cp, 10);
if (*cp != 0) {
switch (*cp) {
case 'k': case 'K': size *= 1E3;break;
case 'm': case 'M': size *= 1E6;break;
case 'g': case 'G': size *= 1E9;break;
case 't': case 'T': size *= 1E12;break;
default:
QMessageBox::warning(0, "Recoll",
tr("Bad multiplier suffix in size filter"));
size = size_t(-1);
}
}
}
return size;
}
using namespace Rcl;
void AdvSearch::runSearch()
{
@ -343,6 +367,11 @@ void AdvSearch::runSearch()
}
}
size_t size = stringToSize(minSizeLE->text());
sdata->setMinSize(size);
size = stringToSize(maxSizeLE->text());
sdata->setMaxSize(size);
if (!subtreeCMB->currentText().isEmpty()) {
QString current = subtreeCMB->currentText();
sdata->setTopdir((const char*)subtreeCMB->currentText().toUtf8(),

View File

@ -68,6 +68,7 @@ private:
bool m_ignByCats;
void saveCnf();
void fillFileTypes();
size_t stringToSize(QString);
};

View File

@ -594,17 +594,17 @@ string displayableBytes(off_t size)
char sizebuf[50];
const char *unit;
if (size < 1024) {
if (size < 1000) {
unit = " B ";
} else if (size < 1024*1024) {
} else if (size < 1E6) {
unit = " KB ";
size /= 1024;
} else if (size < 1024*1024*1024) {
size /= 1000;
} else if (size < 1E9) {
unit = " MB ";
size /= (1024*1024);
size /= (1E6);
} else {
unit = " GB ";
size /= (1024*1024*1024);
size /= (1E9);
}
sprintf(sizebuf, OFFTPC "%s", size, unit);