diff --git a/src/article_maker.cc b/src/article_maker.cc index eab66e6c..9558ac41 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -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 ); diff --git a/src/config.hh b/src/config.hh index 1a5feaac..bc4c960d 100644 --- a/src/config.hh +++ b/src/config.hh @@ -18,6 +18,13 @@ #include #include +/// 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 { diff --git a/src/fulltextsearch.cc b/src/fulltextsearch.cc index 5f14613d..edfb815f 100644 --- a/src/fulltextsearch.cc +++ b/src/fulltextsearch.cc @@ -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 { diff --git a/src/instances.hh b/src/instances.hh index 56a87d28..6718ac0a 100644 --- a/src/instances.hh +++ b/src/instances.hh @@ -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 > diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 722fde5a..cf03b557 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -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() ) { diff --git a/src/ui/editdictionaries.cc b/src/ui/editdictionaries.cc index ceeac7f2..40d37a5a 100644 --- a/src/ui/editdictionaries.cc +++ b/src/ui/editdictionaries.cc @@ -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 { diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 4c60632a..b5de33bb 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -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 ); } diff --git a/src/ui/mainwindow.hh b/src/ui/mainwindow.hh index 007f8cfb..1cc0e145 100644 --- a/src/ui/mainwindow.hh +++ b/src/ui/mainwindow.hh @@ -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(); diff --git a/src/ui/scanpopup.cc b/src/ui/scanpopup.cc index a5d61d82..27328193 100644 --- a/src/ui/scanpopup.cc +++ b/src/ui/scanpopup.cc @@ -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 {