Created V0.3.x branch and moved the head into the trunk directory.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2007-11-15 03:18:48 +00:00
commit 935745a08e
1318 changed files with 348809 additions and 0 deletions

View file

@ -0,0 +1,227 @@
<ui version="4.0" >
<class>AdvancedSearchDialog</class>
<widget class="QWidget" name="AdvancedSearchDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>820</width>
<height>130</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>820</width>
<height>130</height>
</size>
</property>
<property name="sizeIncrement" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle" >
<string>RetrosShare: Advanced Search</string>
</property>
<property name="windowIcon" >
<iconset resource="../images.qrc" >:/images/advsearch_24x24.png</iconset>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="addExprButton" >
<property name="toolTip" >
<string>Add a further search criterion.</string>
</property>
<property name="text" >
<string> Add a selection criterion</string>
</property>
<property name="icon" >
<iconset resource="../images.qrc" >:/images/add_24x24.png</iconset>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" >
<size>
<width>21</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="resetButton" >
<property name="toolTip" >
<string>Reset the search criteria.</string>
</property>
<property name="text" >
<string> Reset</string>
</property>
<property name="icon" >
<iconset resource="../images.qrc" >:/images/reset.png</iconset>
</property>
<property name="iconSize" >
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>381</width>
<height>27</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cancelButton" >
<property name="toolTip" >
<string>Cancels the search.</string>
</property>
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="executeButton" >
<property name="toolTip" >
<string>Perform the advanced search.</string>
</property>
<property name="text" >
<string>Search</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="searchCriteriaBox" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>800</width>
<height>60</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="title" >
<string>Search Criteria</string>
</property>
<property name="alignment" >
<set>Qt::AlignJustify|Qt::AlignTop</set>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>0</number>
</property>
<item>
<widget class="QFrame" name="expressionsFrame" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>600</width>
<height>35</height>
</size>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc" />
</resources>
<connections>
<connection>
<sender>cancelButton</sender>
<signal>clicked()</signal>
<receiver>AdvancedSearchDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>481</x>
<y>211</y>
</hint>
<hint type="destinationlabel" >
<x>370</x>
<y>5</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -0,0 +1,154 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "advancedsearchdialog.h"
AdvancedSearchDialog::AdvancedSearchDialog(QWidget * parent) : QDialog (parent)
{
setupUi(this);
dialogLayout = this->layout();
metrics = new QFontMetrics(this->font());
// the list of expressions
expressions = new QList<ExpressionWidget*>();
// a area for holding the objects
expressionsLayout = new QVBoxLayout();
expressionsLayout->setSpacing(0);
expressionsLayout->setMargin(0);
expressionsLayout->setObjectName(QString::fromUtf8("expressionsLayout"));
expressionsFrame->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::MinimumExpanding);
expressionsFrame->setLayout(expressionsLayout);
// we now add the first expression widgets to the dialog via a vertical
// layout
reset();//addNewExpression();
connect (this->addExprButton, SIGNAL(clicked()),
this, SLOT(addNewExpression()));
connect (this->resetButton, SIGNAL(clicked()),
this, SLOT(reset()));
connect(this->executeButton, SIGNAL(clicked()),
this, SLOT(prepareSearch()));
}
void AdvancedSearchDialog::addNewExpression()
{
int sizeChange = metrics->height() + 35;
ExpressionWidget *expr;
if (expressions->size() == 0)
{
//create an initial expression
expr = new ExpressionWidget(expressionsFrame, true);
} else {
expr = new ExpressionWidget(expressionsFrame);
}
expressions->append(expr);
expressionsLayout->addWidget(expr, 1, Qt::AlignLeft);
connect(expr, SIGNAL(signalDelete(ExpressionWidget*)),
this, SLOT(deleteExpression(ExpressionWidget*)));
//expressionsLayout->invalidate();
//searchCriteriaBox->setMinimumSize(searchCriteriaBox->minimumWidth(),
// searchCriteriaBox->minimumHeight() + sizeChange);
//searchCriteriaBox->adjustSize();
expressionsFrame->adjustSize();
this->setMinimumSize(this->minimumWidth(), this->minimumHeight()+sizeChange);
this->adjustSize();
}
void AdvancedSearchDialog::deleteExpression(ExpressionWidget* expr)
{
int sizeChange = metrics->height() + 35;
expressions->removeAll(expr);
expr->hide();
expressionsLayout->removeWidget(expr);
delete expr;
expressionsLayout->invalidate();
//searchCriteriaBox->setMinimumSize(searchCriteriaBox->minimumWidth(),
// searchCriteriaBox->minimumHeight() - sizeChange);
//searchCriteriaBox->adjustSize();
expressionsFrame->adjustSize();
this->setMinimumSize(this->minimumWidth(), this->minimumHeight()-sizeChange);
this->adjustSize();
}
void AdvancedSearchDialog::reset()
{
ExpressionWidget *expr;
while (!expressions->isEmpty())
{
expr = expressions->takeLast();
deleteExpression(expr);
}
// now add a new default expressions
addNewExpression();
}
void AdvancedSearchDialog::prepareSearch()
{
emit search(getRsExpr());
}
Expression * AdvancedSearchDialog::getRsExpr()
{
Expression * wholeExpression;
// process the special case: first expression
wholeExpression = expressions->at(0)->getRsExpression();
// iterate through the items in elements and
for (int i = 1; i < expressions->size(); ++i) {
// extract the expression information and compound it with the
// first expression
wholeExpression = new CompoundExpression(expressions->at(i)->getOperator(),
wholeExpression,
expressions->at(i)->getRsExpression());
}
return wholeExpression;
}
QString AdvancedSearchDialog::getSearchAsString()
{
QString str = expressions->at(0)->toString();
// iterate through the items in elements and
for (int i = 1; i < expressions->size(); ++i) {
// extract the expression information and compound it with the
// first expression
str += QString(" ") + expressions->at(i)->toString();
}
return str;
}

View file

@ -0,0 +1,57 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _AdvancedSearch_h_
#define _AdvancedSearch_h_
#include <QFontMetrics>
#include <QDialog>
#include <QList>
#include <QScrollArea>
#include <QSizePolicy>
#include "ui_AdvancedSearchDialog.h"
#include "expressionwidget.h"
#include "rsiface/rsexpr.h"
class AdvancedSearchDialog : public QDialog, public Ui::AdvancedSearchDialog
{
Q_OBJECT
public:
AdvancedSearchDialog(QWidget * parent = 0 );
Expression * getRsExpr();
QString getSearchAsString();
signals:
void search(Expression*);
private slots:
void deleteExpression(ExpressionWidget*);
void addNewExpression();
void reset();
void prepareSearch();
private:
QLayout * dialogLayout;
QVBoxLayout * expressionsLayout;
QList<ExpressionWidget*> * expressions;
QFontMetrics * metrics;
};
#endif // _AdvancedSearch_h_

View file

@ -0,0 +1,231 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "expressionwidget.h"
ExpressionWidget::ExpressionWidget(QWidget * parent, bool initial) : QWidget(parent)
{
setupUi(this);
inRangedConfig = false;
// the default search type
searchType = NameSearch;
exprLayout = this->layout();
exprOpFrame->setLayout (createLayout());
exprTermFrame->setLayout (createLayout());
exprConditionFrame->setLayout (createLayout());
exprParamFrame->setLayout (createLayout());
exprParamFrame->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Fixed);
elements = new QList<GuiExprElement*>();
exprOpElem = new ExprOpElement();
exprOpFrame->layout()->addWidget(exprOpElem);
elements->append(exprOpElem);
exprTermElem = new ExprTermsElement();
exprTermFrame->layout()->addWidget(exprTermElem);
elements->append(exprTermElem);
connect (exprTermElem, SIGNAL(currentIndexChanged(int)),
this, SLOT (adjustExprForTermType(int)));
exprCondElem = new ExprConditionElement(searchType);
exprConditionFrame->layout()->addWidget(exprCondElem);
elements->append(exprCondElem);
connect (exprCondElem, SIGNAL (currentIndexChanged(int)),
this, SLOT (adjustExprForConditionType(int)));
exprParamElem= new ExprParamElement(searchType);
exprParamFrame->layout()->addWidget(exprParamElem);
elements->append(exprParamElem);
// set up the default search: a search on name
adjustExprForTermType(searchType);
isFirst = initial;
deleteExprButton ->setVisible(!isFirst);
exprOpElem ->setVisible(!isFirst);
exprTermFrame ->show();
exprConditionFrame ->show();
exprParamFrame ->show();
// connect the delete button signal
connect (deleteExprButton, SIGNAL (clicked()),
this, SLOT(deleteExpression()));
this->show();
}
QLayout * ExpressionWidget::createLayout(QWidget * parent)
{
QHBoxLayout * hboxLayout;
if (parent == 0)
{
hboxLayout = new QHBoxLayout();
} else {
hboxLayout = new QHBoxLayout(parent);
}
hboxLayout->setSpacing(0);
hboxLayout->setMargin(0);
return hboxLayout;
}
bool ExpressionWidget::isStringSearchExpression()
{
return (searchType == NameSearch || searchType == PathSearch
|| searchType == ExtSearch || searchType == HashSearch);
}
void ExpressionWidget::adjustExprForTermType(int index)
{
ExprSearchType type = (*GuiExprElement::TermsIndexMap)[index];
searchType = type;
// now adjust the relevant elements
// the condition combobox
exprCondElem->adjustForSearchType(type);
// the parameter expression: can be a date, 1-2 edit fields
// or a size with units etc
exprParamElem->adjustForSearchType(type);
exprParamFrame->adjustSize();
exprLayout->invalidate();
this->adjustSize();
}
void ExpressionWidget::adjustExprForConditionType(int newCondition)
{
// we adjust the appearance for a ranged selection
inRangedConfig = (newCondition == GuiExprElement::RANGE_INDEX);
exprParamElem->setRangedSearch(inRangedConfig);
exprParamFrame->layout()->invalidate();
exprParamFrame->adjustSize();
}
void ExpressionWidget::deleteExpression()
{
this->hide();
emit signalDelete(this);
}
LogicalOperator ExpressionWidget::getOperator()
{
return exprOpElem->getLogicalOperator();
}
Expression* ExpressionWidget::getRsExpression()
{
Expression * expr;
std::list<std::string> wordList;
int lowVal = 0;
int highVal = 0;
if (isStringSearchExpression())
{
QString txt = exprParamElem->getStrSearchValue();
QStringList words = txt.split(" ", QString::SkipEmptyParts);
for (int i = 0; i < words.size(); ++i)
wordList.push_back(words.at(i).toStdString());
} else if (inRangedConfig){
// correct for reversed ranges to be nice to the user
lowVal = exprParamElem->getIntLowValue();
highVal = exprParamElem->getIntHighValue();
if (lowVal >highVal)
{
lowVal = lowVal^highVal;
highVal = lowVal^highVal;
lowVal = lowVal^highVal;
}
}
switch (searchType)
{
case NameSearch:
expr = new NameExpression(exprCondElem->getStringOperator(),
wordList,
exprParamElem->ignoreCase());
break;
case PathSearch:
expr = new PathExpression(exprCondElem->getStringOperator(),
wordList,
exprParamElem->ignoreCase());
break;
case ExtSearch:
expr = new ExtExpression(exprCondElem->getStringOperator(),
wordList,
exprParamElem->ignoreCase());
break;
case HashSearch:
expr = new HashExpression(exprCondElem->getStringOperator(),
wordList);
break;
case DateSearch:
if (inRangedConfig) {
expr = new DateExpression(exprCondElem->getRelOperator(),
lowVal,
highVal);
} else {
expr = new DateExpression(exprCondElem->getRelOperator(),
exprParamElem->getIntValue());
}
break;
case PopSearch:
if (inRangedConfig) {
expr = new DateExpression(exprCondElem->getRelOperator(),
lowVal,
highVal);
} else {
expr = new DateExpression(exprCondElem->getRelOperator(),
exprParamElem->getIntValue());
}
break;
case SizeSearch:
if (inRangedConfig) {
expr = new SizeExpression(exprCondElem->getRelOperator(),
lowVal,
highVal);
} else {
expr = new SizeExpression(exprCondElem->getRelOperator(),
exprParamElem->getIntValue());
}
break;
};
return expr;
}
QString ExpressionWidget::toString()
{
QString str = "";
if (!isFirst)
{
str += exprOpElem->toString() + " ";
}
str += exprTermElem->toString() + " ";
str += exprCondElem->toString() + " ";
str += exprParamElem->toString();
return str;
}

View file

@ -0,0 +1,93 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _ExpressionWidget_h_
#define _ExpressionWidget_h_
#include <iostream>
#include <QWidget>
#include <QLabel>
#include "rsiface/rsexpr.h"
#include "guiexprelement.h"
#include "ui_expressionwidget.h"
/**
Represents an Advanced Search GUI Expression object which acts as a container
for a series of GuiExprElement objects. The structure of the expression can
change dynamically, dependant on user choices made while assembling an expression.
The default appearance is simply a search on name.
*/
class ExpressionWidget : public QWidget, public Ui::ExpressionWidget
{
Q_OBJECT
public:
ExpressionWidget( QWidget * parent = 0, bool initial=false );
/** delivers the expression represented by this widget
the operator to join this expression with any previous
expressions is provided by the getOperator method */
Expression* getRsExpression();
/** supplies the operator to be used when joining this expression
to the whole query */
LogicalOperator getOperator();
QString toString();
signals:
/** associates an expression object with the delete event */
void signalDelete(ExpressionWidget*);
private slots:
/** emits the signalDelete signal with a pointer to this object
for use by listeners */
void deleteExpression();
/** dynbamically changes the structure of the expression based on
the terms combobox changes */
void adjustExprForTermType(int);
/** dynamically adjusts the expression dependant on the choices
made in the condition combobox e.g. inRange and equals
have different parameter fields */
void adjustExprForConditionType(int);
private:
QLayout * createLayout(QWidget* parent = 0);
bool isStringSearchExpression();
QList <GuiExprElement *> * elements;
QLayout * exprLayout;
ExprOpElement * exprOpElem;
ExprTermsElement * exprTermElem;
ExprConditionElement * exprCondElem;
ExprParamElement* exprParamElem;
bool inRangedConfig;
bool isFirst;
ExprSearchType searchType;
};
#endif // _ExpressionWidget_h_

View file

@ -0,0 +1,172 @@
<ui version="4.0" >
<class>ExpressionWidget</class>
<widget class="QWidget" name="ExpressionWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>800</width>
<height>30</height>
</size>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>55</height>
</size>
</property>
<property name="windowTitle" >
<string>Expression Widget</string>
</property>
<property name="toolTip" >
<string/>
</property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QFrame" name="exprOpFrame" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>90</width>
<height>30</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="exprTermFrame" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>100</width>
<height>30</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="exprConditionFrame" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>180</width>
<height>30</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="exprParamFrame" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>350</width>
<height>30</height>
</size>
</property>
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteExprButton" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="toolTip" >
<string>Delete this expression</string>
</property>
<property name="text" >
<string/>
</property>
<property name="icon" >
<iconset resource="../images.qrc" >:/images/delete.png</iconset>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc" />
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,637 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "guiexprelement.h"
#define STR_FIELDS_MIN_WIDTH 200
#define SIZE_FIELDS_MIN_WIDTH 80
#define DATE_FIELDS_MIN_WIDTH 100
#define FIELDS_MIN_HEIGHT 30
#define LOGICAL_OP_CB_WIDTH 70
#define STD_CB_WIDTH 90
#define CONDITION_CB_WIDTH 170
const QString GuiExprElement::AND = QObject::tr("and");
const QString GuiExprElement::OR = QObject::tr("and / or");
const QString GuiExprElement::XOR = QObject::tr("or"); // exclusive or
const QString GuiExprElement::NAME = QObject::tr("Name");
const QString GuiExprElement::PATH = QObject::tr("Path");
const QString GuiExprElement::EXT = QObject::tr("Extension");
const QString GuiExprElement::HASH = QObject::tr("Hash");
//const QString GuiExprElement::KEYWORDS= QObject::tr("Keywords");
//const QString GuiExprElement::COMMENTS= QObject::tr("Comments");
//const QString GuiExprElement::META = QObject::tr("Meta");
const QString GuiExprElement::DATE = QObject::tr("Date");
const QString GuiExprElement::SIZE = QObject::tr("Size");
const QString GuiExprElement::POP = QObject::tr("Popularity");
const QString GuiExprElement::CONTAINS= QObject::tr("contains");
const QString GuiExprElement::CONTALL = QObject::tr("contains all");
const QString GuiExprElement::IS = QObject::tr("is");
const QString GuiExprElement::LT = QObject::tr("less than");
const QString GuiExprElement::LTE = QObject::tr("less than or equal");
const QString GuiExprElement::EQUAL = QObject::tr("equals");
const QString GuiExprElement::GTE = QObject::tr("greater than or equal");
const QString GuiExprElement::GT = QObject::tr("greater than");
const QString GuiExprElement::RANGE = QObject::tr("is in range");
const int GuiExprElement::AND_INDEX = 0;
const int GuiExprElement::OR_INDEX = 1;
const int GuiExprElement::XOR_INDEX = 2;
const int GuiExprElement::NAME_INDEX = 0;
const int GuiExprElement::PATH_INDEX = 1;
const int GuiExprElement::EXT_INDEX = 2;
const int GuiExprElement::HASH_INDEX = 3;
/*const int GuiExprElement::KEYWORDS_INDEX = ???;
const int GuiExprElement::COMMENTS_INDEX = ???;
const int GuiExprElement::META_INDEX = ???;*/
const int GuiExprElement::DATE_INDEX = 4;
const int GuiExprElement::SIZE_INDEX = 5;
const int GuiExprElement::POP_INDEX = 6;
const int GuiExprElement::CONTAINS_INDEX = 0;
const int GuiExprElement::CONTALL_INDEX = 1;
const int GuiExprElement::IS_INDEX = 2;
const int GuiExprElement::LT_INDEX = 0;
const int GuiExprElement::LTE_INDEX = 1;
const int GuiExprElement::EQUAL_INDEX = 2;
const int GuiExprElement::GTE_INDEX = 3;
const int GuiExprElement::GT_INDEX = 4;
const int GuiExprElement::RANGE_INDEX = 5;
QStringList * GuiExprElement::exprOpsList = new QStringList();
QStringList * GuiExprElement::searchTermsOptionsList = new QStringList();
QStringList * GuiExprElement::stringOptionsList = new QStringList();
QStringList * GuiExprElement::relOptionsList = new QStringList();
QMap<int, ExprSearchType> * GuiExprElement::TermsIndexMap = new QMap<int, ExprSearchType>();
QMap<int, LogicalOperator> * GuiExprElement::logicalOpIndexMap = new QMap<int, LogicalOperator>();
QMap<int, StringOperator> * GuiExprElement::strConditionIndexMap = new QMap<int, StringOperator>();
QMap<int, RelOperator> * GuiExprElement::relConditionIndexMap = new QMap<int, RelOperator>();
QMap<int, QString> * GuiExprElement::logicalOpStrMap = new QMap<int, QString>();
QMap<int, QString> * GuiExprElement::termsStrMap = new QMap<int, QString>();
QMap<int, QString> * GuiExprElement::strConditionStrMap = new QMap<int, QString>();
QMap<int, QString> * GuiExprElement::relConditionStrMap = new QMap<int, QString>();
bool GuiExprElement::initialised = false;
GuiExprElement::GuiExprElement(QWidget * parent)
: QWidget(parent)
{
if (!GuiExprElement::initialised)
{
initialiseOptionsLists();
}
searchType = NameSearch;
}
void GuiExprElement::initialiseOptionsLists()
{
exprOpsList->append(AND);
exprOpsList->append(OR);
exprOpsList->append(XOR);
GuiExprElement::searchTermsOptionsList->append(NAME);
GuiExprElement::searchTermsOptionsList->append(PATH);
GuiExprElement::searchTermsOptionsList->append(EXT);
GuiExprElement::searchTermsOptionsList->append(HASH);
//GuiExprElement::searchTermsOptionsList->append(KEYWORDS);
//GuiExprElement::searchTermsOptionsList->append(COMMENTS);
//GuiExprElement::searchTermsOptionsList->append(META);
GuiExprElement::searchTermsOptionsList->append(DATE);
GuiExprElement::searchTermsOptionsList->append(SIZE);
// GuiExprElement::searchTermsOptionsList->append(POP);
GuiExprElement::stringOptionsList->append(CONTAINS);
GuiExprElement::stringOptionsList->append(CONTALL);
GuiExprElement::stringOptionsList->append(IS);
GuiExprElement::relOptionsList->append(LT);
GuiExprElement::relOptionsList->append(LTE);
GuiExprElement::relOptionsList->append(EQUAL);
GuiExprElement::relOptionsList->append(GTE);
GuiExprElement::relOptionsList->append(GT);
GuiExprElement::relOptionsList->append(RANGE);
// now the maps
(*GuiExprElement::logicalOpIndexMap)[GuiExprElement::AND_INDEX] = AndOp;
(*GuiExprElement::logicalOpIndexMap)[GuiExprElement::OR_INDEX] = OrOp;
(*GuiExprElement::logicalOpIndexMap)[GuiExprElement::XOR_INDEX] = XorOp;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::NAME_INDEX] = NameSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::PATH_INDEX] = PathSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::EXT_INDEX] = ExtSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::HASH_INDEX] = HashSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::DATE_INDEX] = DateSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::SIZE_INDEX] = SizeSearch;
(*GuiExprElement::TermsIndexMap)[GuiExprElement::POP_INDEX] = PopSearch;
(*GuiExprElement::strConditionIndexMap)[GuiExprElement::CONTAINS_INDEX] = ContainsAnyStrings;
(*GuiExprElement::strConditionIndexMap)[GuiExprElement::CONTALL_INDEX] = ContainsAllStrings;
(*GuiExprElement::strConditionIndexMap)[GuiExprElement::IS_INDEX] = EqualsString;
/* W A R N I N G !!!!
the cb elements correspond to their inverse rel op counterparts in rsexpr.h due to the nature of
the implementation.there
For example consider "size greater than 100kb" selected in the GUI.
The rsexpr.cc impl returns true if the CONDITION specified is greater than the file size passed as argument
as rsexpr iterates through the files. So, the user wants files that are greater than 100kb but the impl returns
files where the condition is greater than the file size i.e. files whose size is less than or equal to the condition
Therefore we invert the mapping of rel conditions here to match the behaviour of the impl.
*/
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::LT_INDEX] = GreaterEquals;
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::LTE_INDEX] = Greater;
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::EQUAL_INDEX] = Equals;
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::GTE_INDEX] = Smaller;
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::GT_INDEX] = SmallerEquals;
(*GuiExprElement::relConditionIndexMap)[GuiExprElement::RANGE_INDEX] = InRange;
// the string to index map
(*GuiExprElement::termsStrMap)[GuiExprElement::NAME_INDEX] = GuiExprElement::NAME;
(*GuiExprElement::termsStrMap)[GuiExprElement::PATH_INDEX] = GuiExprElement::PATH;
(*GuiExprElement::termsStrMap)[GuiExprElement::EXT_INDEX] = GuiExprElement::EXT;
(*GuiExprElement::termsStrMap)[GuiExprElement::HASH_INDEX] = GuiExprElement::HASH;
(*GuiExprElement::termsStrMap)[GuiExprElement::DATE_INDEX] = GuiExprElement::DATE;
(*GuiExprElement::termsStrMap)[GuiExprElement::SIZE_INDEX] = GuiExprElement::SIZE;
(*GuiExprElement::termsStrMap)[GuiExprElement::POP_INDEX] = GuiExprElement::POP;
(*GuiExprElement::logicalOpStrMap)[GuiExprElement::AND_INDEX] = GuiExprElement::AND;
(*GuiExprElement::logicalOpStrMap)[GuiExprElement::XOR_INDEX] = GuiExprElement::XOR;
(*GuiExprElement::logicalOpStrMap)[GuiExprElement::OR_INDEX] = GuiExprElement::OR;
(*GuiExprElement::strConditionStrMap)[GuiExprElement::CONTAINS_INDEX] = GuiExprElement::CONTAINS;
(*GuiExprElement::strConditionStrMap)[GuiExprElement::CONTALL_INDEX] = GuiExprElement::CONTALL;
(*GuiExprElement::strConditionStrMap)[GuiExprElement::IS_INDEX] = GuiExprElement::IS;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::LT_INDEX] = GuiExprElement::LT;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::LTE_INDEX] = GuiExprElement::LTE;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::EQUAL_INDEX] = GuiExprElement::EQUAL;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::GTE_INDEX] = GuiExprElement::GTE;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::GT_INDEX] = GuiExprElement::GT;
(*GuiExprElement::relConditionStrMap)[GuiExprElement::RANGE_INDEX] = GuiExprElement::RANGE;
GuiExprElement::initialised = true;
}
QStringList* GuiExprElement::getConditionOptions(ExprSearchType t)
{
QStringList * list = new QStringList();
switch (t) {
case NameSearch:
case PathSearch:
case ExtSearch:
case HashSearch:
list = GuiExprElement::stringOptionsList;
break;
case DateSearch:
case PopSearch:
case SizeSearch:
default:
list = GuiExprElement::relOptionsList;
}
return list;
}
QHBoxLayout * GuiExprElement::createLayout(QWidget * parent)
{
QHBoxLayout * hboxLayout;
if (parent == 0)
{
hboxLayout = new QHBoxLayout();
} else {
hboxLayout = new QHBoxLayout(parent);
}
hboxLayout->setMargin(0);
hboxLayout->setSpacing(0);
return hboxLayout;
}
bool GuiExprElement::isStringSearchExpression()
{
return (searchType == NameSearch || searchType == PathSearch
|| searchType == ExtSearch || searchType == HashSearch);
}
/* ********************************************************************/
/* *********** L O G I C A L O P E L E M E N T ******************/
/* ********************************************************************/
ExprOpElement::ExprOpElement(QWidget * parent)
: GuiExprElement(parent)
{
internalframe = new QFrame(this);
internalframe->setLayout(createLayout());
cb = new QComboBox(this);
cb->setMinimumSize(LOGICAL_OP_CB_WIDTH, FIELDS_MIN_HEIGHT);
cb->addItems(*(GuiExprElement::exprOpsList));
internalframe->layout()->addWidget(cb);
}
QString ExprOpElement::toString()
{
return (*GuiExprElement::logicalOpStrMap)[cb->currentIndex()];
}
LogicalOperator ExprOpElement::getLogicalOperator()
{
return (*GuiExprElement::logicalOpIndexMap)[cb->currentIndex()];
}
/* **********************************************************/
/* *********** T E R M S E L E M E N T ******************/
/* **********************************************************/
ExprTermsElement::ExprTermsElement(QWidget * parent)
: GuiExprElement(parent)
{
internalframe = new QFrame(this);
internalframe->setLayout(createLayout());
cb = new QComboBox(this);
cb->setMinimumSize(STD_CB_WIDTH, FIELDS_MIN_HEIGHT);
connect (cb, SIGNAL(currentIndexChanged(int)),
this, SIGNAL(currentIndexChanged(int)));
cb->addItems(*(GuiExprElement::searchTermsOptionsList));
internalframe->layout()->addWidget(cb);
}
QString ExprTermsElement::toString()
{
return (*GuiExprElement::termsStrMap)[cb->currentIndex()];
}
/* ******************************************************************/
/* *********** C O N D I T I O N E L E M E N T ******************/
/* ******************************************************************/
ExprConditionElement::ExprConditionElement(ExprSearchType type, QWidget * parent)
: GuiExprElement(parent)
{
internalframe = new QFrame(this);
internalframe->setLayout(createLayout());
cb = new QComboBox(this);
cb->setMinimumSize(CONDITION_CB_WIDTH, FIELDS_MIN_HEIGHT);
connect (cb, SIGNAL(currentIndexChanged(int)),
this, SIGNAL(currentIndexChanged(int)));
cb->addItems(*(getConditionOptions(type)));
internalframe->layout()->addWidget(cb);
}
QString ExprConditionElement::toString()
{
QString str = "";
if (isStringSearchExpression())
{
str = (*GuiExprElement::strConditionStrMap)[cb->currentIndex()];
} else {
str = (*GuiExprElement::relConditionStrMap)[cb->currentIndex()];
}
return str;
}
RelOperator ExprConditionElement::getRelOperator()
{
return (*GuiExprElement::relConditionIndexMap)[cb->currentIndex()];
}
StringOperator ExprConditionElement::getStringOperator()
{
return (*GuiExprElement::strConditionIndexMap)[cb->currentIndex()];
}
void ExprConditionElement::adjustForSearchType(ExprSearchType type)
{
cb->clear();
cb->addItems(*(getConditionOptions(type)));
searchType = type;
}
/* **********************************************************/
/* *********** P A R A M E L E M E N T ******************/
/* **********************************************************/
ExprParamElement::ExprParamElement(ExprSearchType type, QWidget * parent)
: GuiExprElement(parent)
{
internalframe = new QFrame(this);
internalframe->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
internalframe->setLayout(createLayout());
inRangedConfig = false;
searchType = type;
adjustForSearchType(type);
}
QString ExprParamElement::toString()
{
QString str = "";
if (isStringSearchExpression())
{
str = QString("\"") + getStrSearchValue() + QString("\"");
// we don't bother with case if hash search
if (searchType != HashSearch) {
str += (ignoreCase() ? QString(" (ignore case)")
: QString(" (case sensitive)"));
}
} else
{
if (searchType == DateSearch) {
QDateEdit * dateEdit = qFindChild<QDateEdit *> (internalframe, "param1");
str = dateEdit->text();
if (inRangedConfig)
{
str += QString(" ") + tr("to") + QString(" ");
dateEdit = qFindChild<QDateEdit *> (internalframe, "param2");
str += dateEdit->text();
}
} else if (searchType == SizeSearch)
{
QLineEdit * lineEditSize = qFindChild<QLineEdit*>(internalframe, "param1");
str = ("" == lineEditSize->text()) ? "0"
: lineEditSize->text();
QComboBox * cb = qFindChild<QComboBox*> (internalframe, "unitsCb1");
str += QString(" ") + cb->itemText(cb->currentIndex());
if (inRangedConfig)
{
str += QString(" ") + tr("to") + QString(" ");
lineEditSize = qFindChild<QLineEdit*>(internalframe, "param2");
str += ("" == lineEditSize->text()) ? "0"
: lineEditSize->text();
cb = qFindChild<QComboBox*> (internalframe, "unitsCb2");
str += QString(" ") + cb->itemText(cb->currentIndex());
}
}
}
return str;
}
void ExprParamElement::adjustForSearchType(ExprSearchType type)
{
// record which search type is active
searchType = type;
QRegExp regExp("0|[1-9][0-9]*");
numValidator = new QRegExpValidator(regExp, this);
QRegExp hexRegExp("[A-Fa-f0-9]*");
hexValidator = new QRegExpValidator(hexRegExp, this);
// remove all elements
QList<QWidget*> children = qFindChildren<QWidget*>(internalframe);
QWidget* child;
QLayout * lay_out = internalframe->layout();
while (!children.isEmpty())
{
child = children.takeLast();
child->hide();
lay_out->removeWidget(child);
delete child;
}
delete lay_out;
QHBoxLayout* hbox = createLayout();
internalframe->setLayout(hbox);
internalframe->setMinimumSize(320,30);
if (isStringSearchExpression())
{
// set up for default of a simple input field
QLineEdit* lineEdit = new QLineEdit(internalframe);
lineEdit->setMinimumSize(STR_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
lineEdit->setObjectName("param1");
hbox->addWidget(lineEdit);
hbox->addSpacing(9);
QCheckBox* icCb = new QCheckBox(tr("ignore case"), internalframe);
icCb->setObjectName("ignoreCaseCB");
icCb->setCheckState(Qt::Checked);
// hex search specifics: hidden case sensitivity and hex validator
if (searchType == HashSearch) {
icCb->hide();
lineEdit->setValidator(hexValidator);
}
hbox->addWidget(icCb);
hbox->addStretch();
} else if (searchType == DateSearch)
{
QDateEdit * dateEdit = new QDateEdit(QDate::currentDate(), internalframe);
dateEdit->setMinimumSize(DATE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
dateEdit->setDisplayFormat(tr("dd.MM.yyyy"));
dateEdit->setObjectName("param1");
dateEdit->setMinimumDate(QDate(1970, 1, 1));
dateEdit->setMaximumDate(QDate(2099, 12,31));
hbox->addWidget(dateEdit, Qt::AlignLeft);
hbox->addStretch();
} else if (searchType == SizeSearch)
{
QLineEdit * lineEdit = new QLineEdit(internalframe);
lineEdit->setMinimumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
lineEdit->setMaximumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
lineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
lineEdit->setObjectName("param1");
lineEdit->setValidator(numValidator);
hbox->addWidget(lineEdit, Qt::AlignLeft);
QComboBox * cb = new QComboBox(internalframe);
cb->setObjectName("unitsCb1");
cb-> addItem(tr("KB"), QVariant(1024));
cb->addItem(tr("MB"), QVariant(1048576));
cb->addItem(tr("GB"), QVariant(1073741824));
hbox->addSpacing(9);
internalframe->layout()->addWidget(cb);
hbox->addStretch();
}
/* POP Search not implemented
else if (searchType == PopSearch)
{
QLineEdit * lineEdit = new QLineEdit(elem);
lineEdit->setObjectName("param1");
lineEdit->setValidator(numValidator);
elem->layout()->addWidget(lineEdit);
}*/
hbox->invalidate();
internalframe->adjustSize();
internalframe->show();
this->adjustSize();
}
void ExprParamElement::setRangedSearch(bool ranged)
{
if (inRangedConfig == ranged) return; // nothing to do here
inRangedConfig = ranged;
QHBoxLayout* hbox = (dynamic_cast<QHBoxLayout*>(internalframe->layout()));
// add additional or remove extra input fields depending on whether
// ranged search or not
if (inRangedConfig)
{
QLabel * toLbl = new QLabel(tr("to"));
toLbl->setMinimumSize(10, FIELDS_MIN_HEIGHT);
toLbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
if (searchType == DateSearch) {
internalframe->setMinimumSize(250,30);
QDateEdit * dateEdit = new QDateEdit(QDate::currentDate(), internalframe);
dateEdit->setMinimumSize(DATE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
dateEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
dateEdit->setObjectName("param2");
dateEdit->setDisplayFormat(tr("dd.MM.yyyy"));
dateEdit->setMinimumDate(QDate(1970, 1, 1));
dateEdit->setMaximumDate(QDate(2099, 12,31));
hbox->addSpacing(9);
hbox->addWidget(toLbl, Qt::AlignLeft);
hbox->addSpacing(9);
hbox->addWidget(dateEdit, Qt::AlignLeft);
hbox->addStretch();
} else if (searchType == SizeSearch) {
internalframe->setMinimumSize(340,30);
QLineEdit * lineEdit = new QLineEdit(internalframe);
lineEdit->setMinimumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
lineEdit->setMaximumSize(SIZE_FIELDS_MIN_WIDTH, FIELDS_MIN_HEIGHT);
lineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
lineEdit->setObjectName("param2");
lineEdit->setValidator(numValidator);
QComboBox * cb = new QComboBox(internalframe);
cb->setObjectName("unitsCb2");
cb-> addItem(tr("KB"), QVariant(1024));
cb->addItem(tr("MB"), QVariant(1048576));
cb->addItem(tr("GB"), QVariant(1073741824));
hbox->addSpacing(9);
hbox->addWidget(toLbl, Qt::AlignLeft);
hbox->addSpacing(9);
hbox->addWidget(lineEdit, Qt::AlignLeft);
hbox->addSpacing(9);
hbox->addWidget(cb);
hbox->addStretch();
}
// else if (searchType == PopSearch)
// {
// elem->layout()->addWidget(new QLabel(tr("to")), Qt::AlignCenter);
// QLineEdit * lineEdit = new QLineEdit(elem);
// lineEdit->setObjectName("param2");
// lineEdit->setValidator(numValidator);
// elem->layout()->addWidget(slineEdit);
// }
hbox->invalidate();
internalframe->adjustSize();
internalframe->show();
this->adjustSize();
} else {
adjustForSearchType(searchType);
}
}
bool ExprParamElement::ignoreCase()
{
return (isStringSearchExpression()
&& (qFindChild<QCheckBox*>(internalframe, "ignoreCaseCB"))
->checkState()==Qt::Checked);
}
QString ExprParamElement::getStrSearchValue()
{
if (!isStringSearchExpression()) return "";
QLineEdit * lineEdit = qFindChild<QLineEdit*>(internalframe, "param1");
return lineEdit->displayText();
}
int ExprParamElement::getIntValueFromField(QString fieldName, bool isToField)
{
int val = -1;
QString suffix = (isToField) ? "2": "1" ;
// NOTE qFindChild necessary for MSVC 6 compatibility!!
switch (searchType)
{
case DateSearch:
{
QDateEdit * dateEdit = qFindChild<QDateEdit *> (internalframe, (fieldName + suffix));
QDateTime * time = new QDateTime(dateEdit->date());
val = time->toTime_t();
break;
}
case SizeSearch:
{
QLineEdit * lineEditSize = qFindChild<QLineEdit*>(internalframe, (fieldName + suffix));
bool ok = false;
val = (lineEditSize->displayText()).toInt(&ok);
if (ok) {
QComboBox * cb = qFindChild<QComboBox*> (internalframe, (QString("unitsCb") + suffix));
QVariant data = cb->itemData(cb->currentIndex());
val *= data.toInt();
} else {
val = -1;
}
break;
}
case PopSearch: // not implemented
/* {
QLineEdit * lineEditPop = qFindChild<QLineEdit*>(elem, (fieldName + suffix));
bool ok = false;
val = (lineEditPop->displayText()).toInt(&ok);
if (!ok) {
val = -1;
}
break;
}*/
case NameSearch:
case PathSearch:
case ExtSearch:
case HashSearch:
default:
// shouldn't be here...val stays at -1
val = -1;
}
return val;
}
int ExprParamElement::getIntValue()
{
return getIntValueFromField("param");
}
int ExprParamElement::getIntLowValue()
{
return getIntValue();
}
int ExprParamElement::getIntHighValue()
{
if (!inRangedConfig) return getIntValue();
return getIntValueFromField("param", true);
}

View file

@ -0,0 +1,234 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006, 2007 The RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef _GuiExprElement_h_
#define _GuiExprElement_h_
#include <QWidget>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QComboBox>
#include <QCheckBox>
#include <QVariant>
#include <QLineEdit>
#include <QDateEdit>
#include <QLabel>
#include <QRegExp>
#include <QRegExpValidator>
#include <QHBoxLayout>
#include <QMap>
#include <iostream>
#include "rsiface/rsexpr.h"
enum ExprSearchType
{
NameSearch,
PathSearch,
ExtSearch,
HashSearch,
DateSearch,
SizeSearch,
PopSearch
};
class GuiExprElement: public QWidget
{
Q_OBJECT
public:
GuiExprElement(QWidget * parent = 0);
virtual void adjustForSearchType(ExprSearchType) {}
virtual ~GuiExprElement(){}
virtual void set(int){}
virtual void set(QObject*){}
bool isStringSearchExpression();
/* translatable option strings for the comboboxes */
static const QString AND ;
static const QString XOR ;
static const QString OR ;
static const QString NAME ;
static const QString PATH ;
static const QString EXT ;
static const QString HASH ;
static const QString KEYWORDS;
static const QString COMMENTS;
static const QString META ;
static const QString DATE ;
static const QString SIZE ;
static const QString POP ;
static const QString CONTAINS;
static const QString CONTALL ;
static const QString IS ;
static const QString LT ;
static const QString LTE ;
static const QString EQUAL ;
static const QString GTE ;
static const QString GT ;
static const QString RANGE ;
/* indices for possible cb options */
static const int AND_INDEX;
static const int XOR_INDEX;
static const int OR_INDEX;
static const int NAME_INDEX;
static const int PATH_INDEX;
static const int EXT_INDEX;
static const int HASH_INDEX;
static const int KEYWORDS_INDEX;
static const int COMMENTS_INDEX;
static const int META_INDEX;
static const int DATE_INDEX;
static const int SIZE_INDEX;
static const int POP_INDEX;
static const int CONTAINS_INDEX;
static const int CONTALL_INDEX;
static const int IS_INDEX;
static const int LT_INDEX;
static const int LTE_INDEX;
static const int EQUAL_INDEX;
static const int GTE_INDEX;
static const int GT_INDEX;
static const int RANGE_INDEX;
static QMap<int, ExprSearchType> * TermsIndexMap;
virtual QString toString(){return QString("");}
protected:
/** prepare the option lists for use */
void initialiseOptionsLists();
/** provides the appropriate options list for the
condition combobox */
QStringList* getConditionOptions(ExprSearchType t);
QHBoxLayout* createLayout(QWidget* parent = 0);
QFrame * internalframe;
ExprSearchType searchType;
static bool initialised;
static QStringList * exprOpsList;
static QStringList * searchTermsOptionsList;
static QStringList * stringOptionsList;
static QStringList * relOptionsList;
// provides a mapping of condition operators to RSExpr reloperators
static QMap<int, LogicalOperator> * logicalOpIndexMap;
static QMap<int, StringOperator> * strConditionIndexMap;
static QMap<int, RelOperator> * relConditionIndexMap;
// provides a mapping of indexes to translatable strings
static QMap<int, QString> * logicalOpStrMap;
static QMap<int, QString> * termsStrMap;
static QMap<int, QString> * strConditionStrMap;
static QMap<int, QString> * relConditionStrMap;
};
/** the Expression operator combobox element */
class ExprOpElement : public GuiExprElement
{
Q_OBJECT
public:
ExprOpElement(QWidget * parent = 0);
LogicalOperator getLogicalOperator();
QString toString();
private:
QComboBox * cb;
};
/** the Terms combobox element */
class ExprTermsElement : public GuiExprElement
{
Q_OBJECT
public:
ExprTermsElement(QWidget * parent = 0);
int getTermsIndex();
RelOperator getRelOperator();
StringOperator getStringOperator();
void set(int i) {cb->setCurrentIndex(i);}
QString toString();
signals:
void currentIndexChanged(int);
private:
QComboBox * cb;
};
/** the Conditions combobox element */
class ExprConditionElement : public GuiExprElement
{
Q_OBJECT
public:
ExprConditionElement(ExprSearchType, QWidget * parent = 0);
RelOperator getRelOperator();
StringOperator getStringOperator();
void adjustForSearchType(ExprSearchType);
void set(int i) {cb->setCurrentIndex(i);}
QString toString();
signals:
void currentIndexChanged(int);
private:
QComboBox * cb;
};
/** the Parameter element */
class ExprParamElement : public GuiExprElement
{
Q_OBJECT
public:
ExprParamElement(ExprSearchType, QWidget * parent = 0);
QVariant* getRSExprValue();
void adjustForSearchType(ExprSearchType);
void setRangedSearch(bool ranged = true);
bool ignoreCase();
QString getStrSearchValue();
int getIntValue();
int getIntLowValue();
int getIntHighValue();
virtual QString toString();
private:
QRegExpValidator * numValidator;
QRegExpValidator * hexValidator;
QFrame * rangeParamsFrame;
bool inRangedConfig;
int getIntValueFromField(QString fieldName, bool isToField=false);
};
#endif