2018-07-20 19:48:29 +02:00
/*******************************************************************************
* gui / advsearch / advancedsearchdialog . cpp *
* *
* LibResAPI : API for local socket server *
* *
* Copyright ( C ) RetroShare Team < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-11-15 03:18:48 +00:00
2018-07-22 00:02:06 +02:00
# include "advancedsearchdialog.h"
2021-04-09 11:54:57 +02:00
2021-02-14 19:38:36 +01:00
# include "gui/common/FilesDefs.h"
2018-07-22 00:02:06 +02:00
2021-04-09 11:54:57 +02:00
# include <QGridLayout>
2007-11-15 03:18:48 +00:00
AdvancedSearchDialog : : AdvancedSearchDialog ( QWidget * parent ) : QDialog ( parent )
{
2021-04-09 11:54:57 +02:00
setupUi ( this ) ;
QFontMetrics metrics = QFontMetrics ( this - > font ( ) ) ;
searchCriteriaBox_VL - > setContentsMargins ( 2 , metrics . height ( ) / 2 , 2 , 2 ) ;
addExprButton - > setIconSize ( QSize ( metrics . height ( ) , metrics . height ( ) ) * 1.5 ) ;
resetButton - > setIconSize ( QSize ( metrics . height ( ) , metrics . height ( ) ) * 1.5 ) ;
// Save current default size as minimum to only add expresssions size to it.
this - > adjustSize ( ) ;
this - > setMinimumSize ( this - > size ( ) ) ;
// the list of expressions
expressions = new QList < ExpressionWidget * > ( ) ;
// we now add the first expression widgets to the dialog
reset ( ) ; //addNewExpression();
connect ( addExprButton , SIGNAL ( clicked ( ) )
, this , SLOT ( addNewExpression ( ) ) ) ;
connect ( resetButton , SIGNAL ( clicked ( ) )
, this , SLOT ( reset ( ) ) ) ;
connect ( searchButton , SIGNAL ( clicked ( ) )
, this , SLOT ( prepareSearch ( ) ) ) ;
2007-11-15 03:18:48 +00:00
}
void AdvancedSearchDialog : : addNewExpression ( )
{
2021-04-09 11:54:57 +02:00
ExpressionWidget * expr = new ExpressionWidget ( searchCriteriaBox , ( expressions - > size ( ) = = 0 ) ) ;
expressions - > append ( expr ) ;
2007-11-15 03:18:48 +00:00
2021-04-09 11:54:57 +02:00
searchCriteriaBox_VL - > addWidget ( expr ) ;
searchCriteriaBox_VL - > setAlignment ( Qt : : AlignTop ) ;
expr - > adjustSize ( ) ;
if ( searchCriteriaBox - > minimumWidth ( ) < expr - > minimumWidth ( ) )
searchCriteriaBox - > setMinimumWidth ( expr - > minimumWidth ( ) ) ;
QSize exprHeight = QSize ( 0 , expr - > height ( ) ) ;
connect ( expr , SIGNAL ( signalDelete ( ExpressionWidget * ) )
, this , SLOT ( deleteExpression ( ExpressionWidget * ) ) ) ;
this - > setMinimumSize ( this - > minimumSize ( ) + exprHeight ) ;
int marg = gradFrame_GL - > contentsMargins ( ) . left ( ) + gradFrame_GL - > contentsMargins ( ) . right ( ) ;
marg + = this - > contentsMargins ( ) . left ( ) + this - > contentsMargins ( ) . right ( ) ;
if ( this - > minimumWidth ( ) < ( searchCriteriaBox - > minimumWidth ( ) + marg ) )
this - > setMinimumWidth ( searchCriteriaBox - > minimumWidth ( ) + marg ) ;
2007-11-15 03:18:48 +00:00
}
void AdvancedSearchDialog : : deleteExpression ( ExpressionWidget * expr )
{
2021-04-09 11:54:57 +02:00
QSize exprHeight = QSize ( 0 , expr - > height ( ) ) ;
expressions - > removeAll ( expr ) ;
expr - > hide ( ) ;
searchCriteriaBox_VL - > removeWidget ( expr ) ;
delete expr ;
this - > setMinimumSize ( this - > minimumSize ( ) - exprHeight ) ;
this - > resize ( this - > size ( ) - exprHeight ) ;
2007-11-15 03:18:48 +00:00
}
void AdvancedSearchDialog : : reset ( )
{
while ( ! expressions - > isEmpty ( ) )
2021-04-09 11:54:57 +02:00
deleteExpression ( expressions - > takeLast ( ) ) ;
2007-11-15 03:18:48 +00:00
// now add a new default expressions
addNewExpression ( ) ;
}
void AdvancedSearchDialog : : prepareSearch ( )
{
emit search ( getRsExpr ( ) ) ;
}
2016-09-13 12:05:22 +02:00
RsRegularExpression : : Expression * AdvancedSearchDialog : : getRsExpr ( )
2007-11-15 03:18:48 +00:00
{
2016-09-13 12:05:22 +02:00
RsRegularExpression : : Expression * wholeExpression ;
2007-11-15 03:18:48 +00:00
// process the special case: first expression
wholeExpression = expressions - > at ( 0 ) - > getRsExpression ( ) ;
// iterate through the items in elements and
Fic Gcc warnings:
/libretroshare/src/file_sharing/p3filelists.cc:-1: In static member
function ‘static bool p3FileDatabase::convertPointerToEntryIndex(const
void*, p3FileDatabase::EntryIndex&, uint32_t&)’:
/libretroshare/src/file_sharing/p3filelists.cc:624: warning:
dereferencing type-punned pointer will break strict-aliasing rules [-
Wstrict-aliasing]
e = EntryIndex( *reinterpret_cast<uint32_t*>(&p) &
ENTRY_INDEX_BIT_MASK ) ;
/home/phenom/GIT/RetroShare/trunk/libretroshare/src/file_sharing/
p3filelists.cc:625: warning: dereferencing type-punned pointer will
break strict-aliasing rules [-Wstrict-aliasing]
friend_index = (*reinterpret_cast<uint32_t*>(&p)) >>
NB_ENTRY_INDEX_BITS ;
/libretroshare/src/gxstrans/p3gxstransitems.h:29: In file included from
../../../trunk/libretroshare/src/gxstrans/p3gxstransitems.h:29:0,
/libretroshare/src/gxstrans/p3gxstransitems.cc:19: from ../../../trunk/
libretroshare/src/gxstrans/p3gxstransitems.cc:19:
/libretroshare/src/gxstrans/p3gxstransitems.cc:-1: In member function
‘virtual void
OutgoingRecord_deprecated::serial_process(RsGenericSerializer::SerializeJob,
RsGenericSerializer::SerializeContext&)’:
/libretroshare/src/serialiser/rstypeserializer.h:61: warning:
dereferencing type-punned pointer will break strict-aliasing rules [-
Wstrict-aliasing]
RsTypeSerializer::serial_process<T>(j, ctx, reinterpret_cast<T&>(I),
#I);\
/libretroshare/src/gxstrans/p3gxstransitems.cc:51: in expansion of macro
‘RS_REGISTER_SERIAL_MEMBER_TYPED’
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
/libretroshare/src/gxstrans/p3gxstransitems.cc:-1: In member function
‘virtual void
OutgoingRecord::serial_process(RsGenericSerializer::SerializeJob,
RsGenericSerializer::SerializeContext&)’:
/libretroshare/src/serialiser/rstypeserializer.h:61: warning:
dereferencing type-punned pointer will break strict-aliasing rules [-
Wstrict-aliasing]
RsTypeSerializer::serial_process<T>(j, ctx, reinterpret_cast<T&>(I),
#I);\
/libretroshare/src/gxstrans/p3gxstransitems.cc:65: in expansion of macro
‘RS_REGISTER_SERIAL_MEMBER_TYPED’
RS_REGISTER_SERIAL_MEMBER_TYPED(clientService, uint16_t);
/retroshare-gui/src/gui/common/RsBanListToolButton.cpp:-1: In member
function ‘void RsBanListToolButton::applyIp()’:
/retroshare-gui/src/gui/common/RsBanListToolButton.cpp:163: warning:
‘list_type’ may be used uninitialized in this function [-Wmaybe-
uninitialized]
changed = rsBanList->removeIpRange(addr, masked_bytes, list_type);
2017-07-28 20:00:29 +02:00
# warning Phenom (2017-07-21): I don t know if it is a real memLeak for wholeExpression. If not remove this warning and add a comment how it is deleted.
2017-07-21 15:19:17 +02:00
// cppcheck-suppress memleak
2007-11-15 03:18:48 +00:00
for ( int i = 1 ; i < expressions - > size ( ) ; + + i ) {
// extract the expression information and compound it with the
// first expression
2016-09-13 12:05:22 +02:00
wholeExpression = new RsRegularExpression : : CompoundExpression ( expressions - > at ( i ) - > getOperator ( ) ,
2007-11-15 03:18:48 +00:00
wholeExpression ,
expressions - > at ( i ) - > getRsExpression ( ) ) ;
2021-04-09 11:54:57 +02:00
}
2007-11-15 03:18:48 +00:00
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 ( ) ;
2021-04-09 11:54:57 +02:00
}
2007-11-15 03:18:48 +00:00
return str ;
}