mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
opt: move special GroupIDs to a seperate enum (#1900)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
* opt: move groupid to a seperate namespace * opt: move groupid to a seperate namespace * Update src/config.hh Co-authored-by: shenleban tongying <shenlebantongying@gmail.com> --------- Co-authored-by: shenleban tongying <shenlebantongying@gmail.com>
This commit is contained in:
parent
c8b6a6b6c5
commit
d4cc838652
|
@ -315,7 +315,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const &
|
|||
true );
|
||||
}
|
||||
|
||||
if ( groupId == Instances::Group::HelpGroupId ) {
|
||||
if ( groupId == GroupId::HelpGroupId ) {
|
||||
if ( word == tr( "Welcome!" ) ) {
|
||||
string welcome = makeWelcomeHtml();
|
||||
sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true );
|
||||
|
|
|
@ -18,6 +18,13 @@
|
|||
#include <optional>
|
||||
#include <QThread>
|
||||
|
||||
/// Special group IDs
|
||||
enum GroupId : unsigned {
|
||||
AllGroupId = UINT_MAX - 1, /// The 'All' group
|
||||
HelpGroupId = UINT_MAX, /// The fictitious 'Help' group
|
||||
NoGroupId = 0, /// Invalid value, used to specify that no group id is specified at all.
|
||||
};
|
||||
|
||||
/// GoldenDict's configuration
|
||||
namespace Config {
|
||||
|
||||
|
|
|
@ -494,7 +494,7 @@ void FullTextSearchDialog::updateDictionaries()
|
|||
Config::Group const * grp = cfg.getGroup( group );
|
||||
Config::MutedDictionaries const * mutedDicts;
|
||||
|
||||
if ( group == Instances::Group::AllGroupId ) {
|
||||
if ( group == GroupId::AllGroupId ) {
|
||||
mutedDicts = &cfg.mutedDictionaries;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -45,17 +45,6 @@ struct Group
|
|||
|
||||
/// Remove id's if not presented in group dictionaries
|
||||
void checkMutedDictionaries( Config::MutedDictionaries * mutedDictionaries ) const;
|
||||
|
||||
// Some constants
|
||||
|
||||
/// The id of the 'All' group
|
||||
static const unsigned AllGroupId = UINT_MAX - 1;
|
||||
|
||||
/// The id of the fictious 'Help' group
|
||||
static const unsigned HelpGroupId = UINT_MAX;
|
||||
|
||||
/// Invalid value, used to specify that no group id is specified at all.
|
||||
static const unsigned NoGroupId = 0;
|
||||
};
|
||||
|
||||
struct Groups: public vector< Group >
|
||||
|
|
|
@ -798,7 +798,7 @@ QStringList ArticleView::getMutedDictionaries( unsigned group )
|
|||
// Find muted dictionaries for current group
|
||||
Config::Group const * grp = cfg.getGroup( group );
|
||||
Config::MutedDictionaries const * mutedDictionaries;
|
||||
if ( group == Instances::Group::AllGroupId ) {
|
||||
if ( group == GroupId::AllGroupId ) {
|
||||
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
||||
}
|
||||
else {
|
||||
|
@ -1766,7 +1766,7 @@ void ArticleView::pasteTriggered()
|
|||
|
||||
if ( !word.isEmpty() ) {
|
||||
unsigned groupId = getGroup( webview->url() );
|
||||
if ( groupId == 0 || groupId == Instances::Group::HelpGroupId ) {
|
||||
if ( groupId == 0 || groupId == GroupId::HelpGroupId ) {
|
||||
// We couldn't figure out the group out of the URL,
|
||||
// so let's try the currently selected group.
|
||||
groupId = currentGroupId;
|
||||
|
@ -1918,7 +1918,7 @@ void ArticleView::doubleClicked( QPoint pos )
|
|||
QUrl const & ref = webview->url();
|
||||
|
||||
auto groupId = getGroup( ref );
|
||||
if ( groupId == 0 || groupId == Instances::Group::HelpGroupId ) {
|
||||
if ( groupId == 0 || groupId == GroupId::HelpGroupId ) {
|
||||
groupId = currentGroupId;
|
||||
}
|
||||
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
|
||||
|
@ -2062,7 +2062,7 @@ void ArticleView::setActiveDictIds( const ActiveDictIds & ad )
|
|||
{
|
||||
auto groupId = ad.groupId;
|
||||
if ( groupId == 0 ) {
|
||||
groupId = Instances::Group::AllGroupId;
|
||||
groupId = GroupId::AllGroupId;
|
||||
}
|
||||
if ( ( ad.word == currentWord && groupId == getCurrentGroup() ) || historyMode ) {
|
||||
// ignore all other signals.
|
||||
|
@ -2077,7 +2077,7 @@ void ArticleView::dictionaryClear( const ActiveDictIds & ad )
|
|||
{
|
||||
auto groupId = ad.groupId;
|
||||
if ( groupId == 0 ) {
|
||||
groupId = Instances::Group::AllGroupId;
|
||||
groupId = GroupId::AllGroupId;
|
||||
}
|
||||
// ignore all other signals.
|
||||
if ( ad.word == currentWord && groupId == getCurrentGroup() ) {
|
||||
|
|
|
@ -74,7 +74,7 @@ void EditDictionaries::editGroup( unsigned id )
|
|||
{
|
||||
ui.tabs->setTabVisible( 0, false );
|
||||
|
||||
if ( id == Instances::Group::AllGroupId ) {
|
||||
if ( id == GroupId::AllGroupId ) {
|
||||
ui.tabs->setCurrentIndex( 1 );
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -553,7 +553,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
// Dictionary bar
|
||||
|
||||
Instances::Group const * igrp = groupInstances.findGroup( cfg.lastMainGroupId );
|
||||
if ( cfg.lastMainGroupId == Instances::Group::AllGroupId ) {
|
||||
if ( cfg.lastMainGroupId == GroupId::AllGroupId ) {
|
||||
if ( igrp ) {
|
||||
igrp->checkMutedDictionaries( &cfg.mutedDictionaries );
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
addNewTab();
|
||||
ArticleView * view = getCurrentArticleView();
|
||||
history.enableAdd( false );
|
||||
view->showDefinition( tr( "Welcome!" ), Instances::Group::HelpGroupId );
|
||||
view->showDefinition( tr( "Welcome!" ), GroupId::HelpGroupId );
|
||||
history.enableAdd( cfg.preferences.storeHistory );
|
||||
|
||||
// restore should be called after all UI initialized but not necessarily after show()
|
||||
|
@ -1640,7 +1640,7 @@ void MainWindow::updateGroupList( bool reload )
|
|||
dictionaries );
|
||||
|
||||
g.name = tr( "All" );
|
||||
g.id = Instances::Group::AllGroupId;
|
||||
g.id = GroupId::AllGroupId;
|
||||
g.icon = "folder.png";
|
||||
|
||||
groupInstances.push_back( g );
|
||||
|
@ -1685,7 +1685,7 @@ void MainWindow::updateDictionaryBar()
|
|||
|
||||
dictionaryBar.setMutedDictionaries( nullptr );
|
||||
if ( grp ) { // Should always be !0, but check as a safeguard
|
||||
if ( currentId == Instances::Group::AllGroupId ) {
|
||||
if ( currentId == GroupId::AllGroupId ) {
|
||||
dictionaryBar.setMutedDictionaries( &cfg.mutedDictionaries );
|
||||
}
|
||||
else {
|
||||
|
@ -2205,7 +2205,7 @@ void MainWindow::editDictionaries( unsigned editDictionaryGroup )
|
|||
|
||||
connect( &dicts, &EditDictionaries::showDictionaryHeadwords, this, &MainWindow::showDictionaryHeadwords );
|
||||
|
||||
if ( editDictionaryGroup != Instances::Group::NoGroupId ) {
|
||||
if ( editDictionaryGroup != GroupId::NoGroupId ) {
|
||||
dicts.editGroup( editDictionaryGroup );
|
||||
}
|
||||
|
||||
|
@ -2219,7 +2219,7 @@ void MainWindow::editDictionaries( unsigned editDictionaryGroup )
|
|||
// Set muted dictionaries from old groups
|
||||
for ( auto & group : newCfg.groups ) {
|
||||
unsigned id = group.id;
|
||||
if ( id != Instances::Group::NoGroupId ) {
|
||||
if ( id != GroupId::NoGroupId ) {
|
||||
Config::Group const * grp = cfg.getGroup( id );
|
||||
if ( grp ) {
|
||||
group.mutedDictionaries = grp->mutedDictionaries;
|
||||
|
@ -2373,7 +2373,7 @@ void MainWindow::currentGroupChanged( int )
|
|||
unsigned grg_id = groupList->getCurrentGroup();
|
||||
cfg.lastMainGroupId = grg_id;
|
||||
Instances::Group const * igrp = groupInstances.findGroup( grg_id );
|
||||
if ( grg_id == Instances::Group::AllGroupId ) {
|
||||
if ( grg_id == GroupId::AllGroupId ) {
|
||||
if ( igrp ) {
|
||||
igrp->checkMutedDictionaries( &cfg.mutedDictionaries );
|
||||
}
|
||||
|
|
|
@ -345,7 +345,7 @@ private slots:
|
|||
|
||||
/// If editDictionaryGroup is specified, the dialog positions on that group
|
||||
/// initially.
|
||||
void editDictionaries( unsigned editDictionaryGroup = Instances::Group::NoGroupId );
|
||||
void editDictionaries( unsigned editDictionaryGroup = GroupId::NoGroupId );
|
||||
/// Edits current group when triggered from the dictionary bar.
|
||||
void editCurrentGroup();
|
||||
void editPreferences();
|
||||
|
|
|
@ -140,7 +140,7 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
dictionaryBar.setFloatable( false );
|
||||
|
||||
Instances::Group const * igrp = groups.findGroup( cfg.lastPopupGroupId );
|
||||
if ( cfg.lastPopupGroupId == Instances::Group::AllGroupId ) {
|
||||
if ( cfg.lastPopupGroupId == GroupId::AllGroupId ) {
|
||||
if ( igrp ) {
|
||||
igrp->checkMutedDictionaries( &cfg.popupMutedDictionaries );
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ void ScanPopup::currentGroupChanged( int )
|
|||
{
|
||||
cfg.lastPopupGroupId = ui.groupList->getCurrentGroup();
|
||||
Instances::Group const * igrp = groups.findGroup( cfg.lastPopupGroupId );
|
||||
if ( cfg.lastPopupGroupId == Instances::Group::AllGroupId ) {
|
||||
if ( cfg.lastPopupGroupId == GroupId::AllGroupId ) {
|
||||
if ( igrp ) {
|
||||
igrp->checkMutedDictionaries( &cfg.popupMutedDictionaries );
|
||||
}
|
||||
|
@ -1086,7 +1086,7 @@ void ScanPopup::updateDictionaryBar()
|
|||
dictionaryBar.setDictionaries( grp->dictionaries );
|
||||
}
|
||||
|
||||
if ( currentId == Instances::Group::AllGroupId ) {
|
||||
if ( currentId == GroupId::AllGroupId ) {
|
||||
dictionaryBar.setMutedDictionaries( &cfg.popupMutedDictionaries );
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue