Skip to content

Commit

Permalink
Merge branch 'feature/add-ignore-punctuation' into staged
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Apr 23, 2022
2 parents 67902b0 + 39c61e9 commit f6cf152
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 68 deletions.
8 changes: 6 additions & 2 deletions btreeidx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <QRegularExpression>
#include "wildcard.hh"
#include "globalbroadcaster.h"

//#define __BTREE_USE_LZO
// LZO mode is experimental and unsupported. Tests didn't show any substantial
Expand Down Expand Up @@ -853,7 +854,8 @@ void BtreeIndex::antialias( wstring const & str,
if( ignoreDiacritics )
caseFolded = Folding::applyDiacriticsOnly( caseFolded );

caseFolded = Folding::trimWhitespaceOrPunct( caseFolded );
if(GlobalBroadcaster::instance()->getPreference()->ignorePunctuation)
caseFolded = Folding::trimWhitespaceOrPunct( caseFolded );

for( unsigned x = chain.size(); x--; )
{
Expand All @@ -863,7 +865,9 @@ void BtreeIndex::antialias( wstring const & str,
if( ignoreDiacritics )
entry = Folding::applyDiacriticsOnly( entry );

entry = Folding::trimWhitespaceOrPunct( entry );
if( GlobalBroadcaster::instance()->getPreference()->ignorePunctuation )
entry = Folding::trimWhitespaceOrPunct( entry );

if ( entry != caseFolded )
chain.erase( chain.begin() + x );
else
Expand Down
7 changes: 7 additions & 0 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Preferences::Preferences():
scanPopupUnpinnedBypassWMHint( false ),
scanToMainWindow( false ),
ignoreDiacritics( false ),
ignorePunctuation( false ),
#ifdef HAVE_X11
showScanFlag( false ),
#endif
Expand Down Expand Up @@ -891,6 +892,8 @@ Class load()
c.preferences.ignoreOwnClipboardChanges = ( preferences.namedItem( "ignoreOwnClipboardChanges" ).toElement().text() == "1" );
c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" );
c.preferences.ignoreDiacritics = ( preferences.namedItem( "ignoreDiacritics" ).toElement().text() == "1" );
if( !preferences.namedItem( "ignorePunctuation" ).isNull() )
c.preferences.ignorePunctuation = ( preferences.namedItem( "ignorePunctuation" ).toElement().text() == "1" );
#ifdef HAVE_X11
c.preferences.showScanFlag= ( preferences.namedItem( "showScanFlag" ).toElement().text() == "1" );
#endif
Expand Down Expand Up @@ -1763,6 +1766,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.ignoreDiacritics ? "1":"0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "ignorePunctuation" );
opt.appendChild( dd.createTextNode( c.preferences.ignorePunctuation ? "1":"0" ) );
preferences.appendChild( opt );

#ifdef HAVE_X11
opt = dd.createElement( "showScanFlag" );
opt.appendChild( dd.createTextNode( c.preferences.showScanFlag? "1":"0" ) );
Expand Down
1 change: 1 addition & 0 deletions config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ struct Preferences
bool scanPopupUnpinnedBypassWMHint;
bool scanToMainWindow;
bool ignoreDiacritics;
bool ignorePunctuation;
#ifdef HAVE_X11
bool showScanFlag;
#endif
Expand Down
20 changes: 14 additions & 6 deletions globalbroadcaster.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#include "globalbroadcaster.h"
#include <QGlobalStatic>


Q_GLOBAL_STATIC(GlobalBroadcaster, bdcaster)
GlobalBroadcaster::GlobalBroadcaster(QObject *parent) : QObject(parent)
Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
{

}


GlobalBroadcaster* GlobalBroadcaster::instance() { return bdcaster; }
GlobalBroadcaster * GlobalBroadcaster::instance()
{
return bdcaster;
}
void GlobalBroadcaster::setPreference( Config::Preferences * p )
{
preference = p;
}
Config::Preferences * GlobalBroadcaster::getPreference()
{
return preference;
}

// namespace global
20 changes: 12 additions & 8 deletions globalbroadcaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
#define GLOBAL_GLOBALBROADCASTER_H

#include <QObject>
#include "config.hh"

struct ActiveDictIds {
struct ActiveDictIds
{
QString word;
QStringList dictIds;
}
;
};

class GlobalBroadcaster : public QObject
{
Q_OBJECT
private:
Config::Preferences * preference;

public:
GlobalBroadcaster(QObject *parent = nullptr);
static GlobalBroadcaster *instance();
void setPreference( Config::Preferences * _pre );
Config::Preferences * getPreference();
GlobalBroadcaster( QObject * parent = nullptr );
static GlobalBroadcaster * instance();
signals:
void emitDictIds(ActiveDictIds ad);

void emitDictIds( ActiveDictIds ad );
};


#endif // GLOBAL_GLOBALBROADCASTER_H
7 changes: 6 additions & 1 deletion locale/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4056,7 +4056,12 @@ from mouse-over, selection, clipboard or command line</source>
<translation>大于此大小的文章将被收起</translation>
</message>
<message>
<location filename="../preferences.ui" line="1817"/>
<location filename="../preferences.ui" line="1741"/>
<source>Ignore punctuation while searching</source>
<translation>搜索时忽略标点符号</translation>
</message>
<message>
<location filename="../preferences.ui" line="1751"/>
<source>Turn this option on to enable extra articles search via synonym lists
from Stardict, Babylon and GLS dictionaries</source>
<translation>启用该选项可以激活基于同义词列表的额外搜索功能
Expand Down
1 change: 1 addition & 0 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
QThreadPool::globalInstance()->start( new InitSSLRunnable );
#endif

GlobalBroadcaster::instance()->setPreference(&cfg.preferences);

localSchemeHandler = new LocalSchemeHandler(articleNetMgr);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", localSchemeHandler);
Expand Down
3 changes: 3 additions & 0 deletions preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):

ui.ignoreDiacritics->setChecked( p.ignoreDiacritics );

ui.ignorePunctuation->setChecked( p.ignorePunctuation );

ui.synonymSearchEnabled->setChecked( p.synonymSearchEnabled );

ui.maxDictsInContextMenu->setValue( p.maxDictionaryRefsInContextMenu );
Expand Down Expand Up @@ -424,6 +426,7 @@ Config::Preferences Preferences::getPreferences()
p.limitInputPhraseLength = ui.limitInputPhraseLength->isChecked();
p.inputPhraseLengthLimit = ui.inputPhraseLengthLimit->value();
p.ignoreDiacritics = ui.ignoreDiacritics->isChecked();
p.ignorePunctuation = ui.ignorePunctuation->isChecked();

p.synonymSearchEnabled = ui.synonymSearchEnabled->isChecked();

Expand Down
109 changes: 58 additions & 51 deletions preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1625,16 +1625,46 @@ download page.</string>
<string>Articles</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="collapseBigArticles">
<item row="1" column="0">
<widget class="QCheckBox" name="limitInputPhraseLength">
<property name="toolTip">
<string>Select this option to automatic collapse big articles</string>
<string>Turn this option on to ignore unreasonably long input text
from mouse-over, selection, clipboard or command line</string>
</property>
<property name="text">
<string>Collapse articles more than</string>
<string>Ignore input phrases longer than</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="articleSizeLimit">
<property name="toolTip">
Expand All @@ -1651,37 +1681,20 @@ download page.</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_13">
<item row="1" column="4">
<widget class="QCheckBox" name="ignoreDiacritics">
<property name="toolTip">
<string>Turn this option on to ignore diacritics while searching articles</string>
</property>
<property name="text">
<string>symbols</string>
<string>Ignore diacritics while searching</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="limitInputPhraseLength">
<property name="toolTip">
<string>Turn this option on to ignore unreasonably long input text
from mouse-over, selection, clipboard or command line</string>
</property>
<item row="0" column="2">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Ignore input phrases longer than</string>
</property>
<property name="checked">
<bool>false</bool>
<string>symbols</string>
</property>
</widget>
</item>
Expand All @@ -1701,20 +1714,13 @@ from mouse-over, selection, clipboard or command line</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>symbols</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="ignoreDiacritics">
<item row="0" column="0">
<widget class="QCheckBox" name="collapseBigArticles">
<property name="toolTip">
<string>Turn this option on to ignore diacritics while searching articles</string>
<string>Select this option to automatic collapse big articles</string>
</property>
<property name="text">
<string>Ignore diacritics while searching</string>
<string>Collapse articles more than</string>
</property>
</widget>
</item>
Expand All @@ -1728,18 +1734,19 @@ from mouse-over, selection, clipboard or command line</string>
</property>
</widget>
</item>
<item row="1" column="3">
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="2">
<widget class="QLabel" name="label_19">
<property name="text">
<string>symbols</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</widget>
</item>
<item row="2" column="4">
<widget class="QCheckBox" name="ignorePunctuation">
<property name="text">
<string>Ignore punctuation while searching</string>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
Expand Down

0 comments on commit f6cf152

Please sign in to comment.