2012-02-20 21:47:14 +00:00
|
|
|
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
|
2009-04-30 15:29:03 +00:00
|
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
|
|
|
|
#include "editdictionaries.hh"
|
2023-04-17 22:51:08 +00:00
|
|
|
#include "dict/loaddictionaries.hh"
|
2023-04-22 00:43:50 +00:00
|
|
|
#include "help.hh"
|
2009-04-30 15:29:03 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
EditDictionaries::EditDictionaries( QWidget * parent,
|
|
|
|
Config::Class & cfg_,
|
2009-04-30 15:29:03 +00:00
|
|
|
vector< sptr< Dictionary::Class > > & dictionaries_,
|
2009-05-15 12:15:08 +00:00
|
|
|
Instances::Groups & groupInstances_,
|
2009-04-30 15:29:03 +00:00
|
|
|
QNetworkAccessManager & dictNetMgr_ ):
|
Dictionaries dialog: always show Maximize button
This dialog can make use of extra horizontal space when there are many
groups, extra vertical space - when there are many dictionaries. Thus
maximizing Dictionaries dialog can be useful.
Currently Dictionaries dialog features the following window buttons in
the top right corner:
* Close button under Xfce on GNU/Linux;
* Context help, Minimize, Maximize and Close buttons under KDE Plasma on
GNU/Linux;
* Help, Close buttons on Windows (according to Internet screenshots).
With this commit the top-right corner window buttons become:
* Maximize and Close buttons under Xfce on GNU/Linux;
* Minimize, Maximize and Close buttons under KDE Plasma on GNU/Linux;
* disabled Minimize button; Maximize and Close buttons on Windows
(thanks to @nonwill for checking this).
I don't think that Minimize button is useful in this dialog. But it does
no harm, so I won't go out of my way to remove it on all platforms.
Interestingly, the Minimize button won't show up under Xfce even if
Qt::WindowMinimizeButtonHint is on. It is difficult if at all possible
to remove this button under KDE Plasma. Fortunately, the Minimize button
works well in this desktop environment: minimizing hides both the dialog
and the main window, unminimizing shows both windows.
@nonwill found that this button doesn't work well on Windows: minimizing
the dialog hides it, but keeps the main window visible with its input
still blocked by the hidden dialog. Therefore it is just as well that
the Minimize button is disabled on Windows.
I couldn't find a UI element in the Dictionaries dialog that features
context help. Therefore the Context help/Help (question mark) button
must be useless. So removing it is an extra benefit of this commit.
I cannot check which window buttons are visible with this commit on
macOS, but I expect them to include Maximize, Close buttons and be
acceptable overall.
Closes #1359.
2021-06-22 08:22:02 +00:00
|
|
|
QDialog( parent, Qt::WindowSystemMenuHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint ),
|
|
|
|
cfg( cfg_ ),
|
|
|
|
dictionaries( dictionaries_ ),
|
2009-05-15 12:15:08 +00:00
|
|
|
groupInstances( groupInstances_ ),
|
2009-04-30 15:29:03 +00:00
|
|
|
dictNetMgr( dictNetMgr_ ),
|
|
|
|
origCfg( cfg ),
|
2013-04-24 14:52:04 +00:00
|
|
|
sources( this, cfg ),
|
2023-06-13 00:07:54 +00:00
|
|
|
orderAndProps( new OrderAndProps( this, cfg.dictionaryOrder, cfg.inactiveDictionaries, dictionaries ) ),
|
2023-06-23 01:25:15 +00:00
|
|
|
groups( std::make_shared< Groups >( this, dictionaries, cfg.groups, orderAndProps->getCurrentDictionaryOrder() ) ),
|
2009-04-30 15:29:03 +00:00
|
|
|
dictionariesChanged( false ),
|
|
|
|
groupsChanged( false ),
|
2023-04-17 02:23:39 +00:00
|
|
|
helpAction( this )
|
2009-04-30 15:29:03 +00:00
|
|
|
{
|
2009-05-18 18:01:50 +00:00
|
|
|
// Some groups may have contained links to non-existnent dictionaries. We
|
|
|
|
// would like to preserve them if no edits were done. To that end, we save
|
|
|
|
// the initial group readings so that if no edits were really done, we won't
|
|
|
|
// be changing groups.
|
|
|
|
origCfg.groups = groups->getGroups();
|
|
|
|
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
|
|
|
|
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
ui.setupUi( this );
|
|
|
|
|
2022-01-24 15:07:40 +00:00
|
|
|
setWindowIcon( QIcon(":/icons/dictionary.svg") );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
ui.tabs->clear();
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2022-12-05 03:28:29 +00:00
|
|
|
ui.tabs->addTab( &sources, QIcon(":/icons/sources.png"), tr( "&Sources" ) );
|
2023-06-13 00:07:54 +00:00
|
|
|
ui.tabs->addTab( orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
2022-01-24 14:23:38 +00:00
|
|
|
ui.tabs->addTab( groups.get(), QIcon(":/icons/bookcase.svg"), tr( "&Groups" ) );
|
2009-05-05 08:57:37 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( ui.buttons, &QDialogButtonBox::clicked, this, &EditDictionaries::buttonBoxClicked );
|
2011-06-13 12:30:49 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( &sources, &Sources::rescan, this, &EditDictionaries::rescanSources );
|
2012-12-20 13:25:03 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( groups.get(), &Groups::showDictionaryInfo, this, &EditDictionaries::showDictionaryInfo );
|
2014-03-01 13:11:14 +00:00
|
|
|
|
2022-12-26 02:08:17 +00:00
|
|
|
connect( orderAndProps.data(),
|
|
|
|
&OrderAndProps::showDictionaryHeadwords,
|
|
|
|
this,
|
|
|
|
&EditDictionaries::showDictionaryHeadwords );
|
2014-06-24 13:55:06 +00:00
|
|
|
|
|
|
|
helpAction.setShortcut( QKeySequence( "F1" ) );
|
|
|
|
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );
|
|
|
|
|
2023-04-22 00:43:50 +00:00
|
|
|
connect( &helpAction, &QAction::triggered, [ this ]() {
|
|
|
|
if ( ui.tabs->currentWidget() == this->groups.get() ) {
|
|
|
|
Help::openHelpWebpage( Help::section::manage_groups );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Help::openHelpWebpage( Help::section::manage_sources );
|
|
|
|
}
|
2023-04-17 02:23:39 +00:00
|
|
|
} );
|
|
|
|
connect( ui.buttons, &QDialogButtonBox::helpRequested, &helpAction, &QAction::trigger );
|
2014-06-24 13:55:06 +00:00
|
|
|
|
|
|
|
addAction( &helpAction );
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
void EditDictionaries::editGroup( unsigned id )
|
|
|
|
{
|
2022-03-03 15:27:21 +00:00
|
|
|
ui.tabs->setTabVisible( 0, false );
|
|
|
|
|
2010-05-08 14:01:59 +00:00
|
|
|
if ( id == Instances::Group::AllGroupId )
|
2022-03-03 15:27:21 +00:00
|
|
|
{
|
2010-05-08 14:01:59 +00:00
|
|
|
ui.tabs->setCurrentIndex( 1 );
|
2022-03-03 15:27:21 +00:00
|
|
|
}
|
2010-05-08 14:01:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.tabs->setCurrentIndex( 2 );
|
|
|
|
groups->editGroup( id );
|
|
|
|
}
|
|
|
|
}
|
2009-04-30 15:29:03 +00:00
|
|
|
|
2022-05-19 13:04:31 +00:00
|
|
|
void EditDictionaries::save( bool rebuildGroups )
|
2009-04-30 15:29:03 +00:00
|
|
|
{
|
|
|
|
Config::Groups newGroups = groups->getGroups();
|
2009-05-18 18:01:50 +00:00
|
|
|
Config::Group newOrder = orderAndProps->getCurrentDictionaryOrder();
|
|
|
|
Config::Group newInactive = orderAndProps->getCurrentInactiveDictionaries();
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2022-05-19 13:04:31 +00:00
|
|
|
if( isSourcesChanged() )
|
|
|
|
acceptChangedSources( rebuildGroups );
|
2009-05-15 12:39:53 +00:00
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
if ( origCfg.groups != newGroups || origCfg.dictionaryOrder != newOrder ||
|
|
|
|
origCfg.inactiveDictionaries != newInactive )
|
2009-04-30 15:29:03 +00:00
|
|
|
{
|
|
|
|
groupsChanged = true;
|
|
|
|
cfg.groups = newGroups;
|
2009-05-18 18:01:50 +00:00
|
|
|
cfg.dictionaryOrder = newOrder;
|
|
|
|
cfg.inactiveDictionaries = newInactive;
|
2009-04-30 15:29:03 +00:00
|
|
|
}
|
2011-06-13 12:30:49 +00:00
|
|
|
}
|
2009-04-30 15:29:03 +00:00
|
|
|
|
2011-06-13 12:30:49 +00:00
|
|
|
void EditDictionaries::accept()
|
|
|
|
{
|
|
|
|
save();
|
2009-04-30 15:29:03 +00:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditDictionaries::on_tabs_currentChanged( int index )
|
|
|
|
{
|
|
|
|
if ( index == -1 || !isVisible() )
|
|
|
|
return; // Sent upon the construction/destruction
|
2023-06-13 00:07:54 +00:00
|
|
|
qDebug() << ui.tabs->currentWidget()->objectName();
|
|
|
|
if ( ui.tabs->currentWidget()->objectName() == "Sources" ) {
|
2009-04-30 15:29:03 +00:00
|
|
|
// We're switching away from the Sources tab -- if its contents were
|
|
|
|
// changed, we need to either apply or reject now.
|
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
if ( isSourcesChanged() ) {
|
2009-04-30 15:29:03 +00:00
|
|
|
ui.tabs->setCurrentIndex( 0 );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
QMessageBox question( QMessageBox::Question,
|
|
|
|
tr( "Sources changed" ),
|
2009-04-30 15:29:03 +00:00
|
|
|
tr( "Some sources were changed. Would you like to accept the changes?" ),
|
2023-06-13 00:07:54 +00:00
|
|
|
QMessageBox::NoButton,
|
|
|
|
this );
|
2009-04-30 15:29:03 +00:00
|
|
|
|
|
|
|
QPushButton * accept = question.addButton( tr( "Accept" ), QMessageBox::AcceptRole );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
question.addButton( tr( "Cancel" ), QMessageBox::RejectRole );
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
question.exec();
|
|
|
|
|
|
|
|
if ( question.clickedButton() == accept )
|
|
|
|
{
|
2009-05-15 12:39:53 +00:00
|
|
|
acceptChangedSources( true );
|
2023-06-13 00:07:54 +00:00
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
ui.tabs->setCurrentIndex( index );
|
|
|
|
}
|
2023-06-13 00:07:54 +00:00
|
|
|
else {
|
2009-04-30 15:29:03 +00:00
|
|
|
// Prevent tab from switching
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-13 00:07:54 +00:00
|
|
|
else if ( lastDictionaryOrderTab ) {
|
2009-05-18 18:01:50 +00:00
|
|
|
// When switching from the dictionary order, we need to propagate any
|
|
|
|
// changes to the groups.
|
|
|
|
groups->updateDictionaryOrder( orderAndProps->getCurrentDictionaryOrder() );
|
|
|
|
}
|
2009-04-30 15:29:03 +00:00
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
lastDictionaryOrderTab = ui.tabs->currentWidget()->objectName() == "OrderAndProps";
|
2009-04-30 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 08:57:37 +00:00
|
|
|
void EditDictionaries::rescanSources()
|
|
|
|
{
|
2009-05-15 12:39:53 +00:00
|
|
|
acceptChangedSources( true );
|
2009-05-05 08:57:37 +00:00
|
|
|
}
|
|
|
|
|
2011-06-13 12:30:49 +00:00
|
|
|
void EditDictionaries::buttonBoxClicked( QAbstractButton * button )
|
|
|
|
{
|
|
|
|
if (ui.buttons->buttonRole(button) == QDialogButtonBox::ApplyRole) {
|
2022-05-19 13:04:31 +00:00
|
|
|
save( true );
|
2011-06-13 12:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-30 15:29:03 +00:00
|
|
|
bool EditDictionaries::isSourcesChanged() const
|
|
|
|
{
|
|
|
|
return sources.getPaths() != cfg.paths ||
|
|
|
|
sources.getSoundDirs() != cfg.soundDirs ||
|
|
|
|
sources.getHunspell() != cfg.hunspell ||
|
2009-05-06 14:39:08 +00:00
|
|
|
sources.getTransliteration() != cfg.transliteration ||
|
2022-12-24 14:42:40 +00:00
|
|
|
sources.getLingua() != cfg.lingua ||
|
2010-06-12 20:16:35 +00:00
|
|
|
sources.getForvo() != cfg.forvo ||
|
2009-05-16 18:04:21 +00:00
|
|
|
sources.getMediaWikis() != cfg.mediawikis ||
|
2011-05-29 05:08:37 +00:00
|
|
|
sources.getWebSites() != cfg.webSites ||
|
2014-04-30 12:55:53 +00:00
|
|
|
sources.getDictServers() != cfg.dictServers ||
|
2013-04-24 14:52:04 +00:00
|
|
|
sources.getPrograms() != cfg.programs ||
|
|
|
|
sources.getVoiceEngines() != cfg.voiceEngines;
|
2009-04-30 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2009-05-15 12:39:53 +00:00
|
|
|
void EditDictionaries::acceptChangedSources( bool rebuildGroups )
|
2009-04-30 15:29:03 +00:00
|
|
|
{
|
2009-05-05 08:57:37 +00:00
|
|
|
dictionariesChanged = true;
|
2009-05-02 21:46:43 +00:00
|
|
|
|
2009-05-15 12:39:53 +00:00
|
|
|
Config::Groups savedGroups = groups->getGroups();
|
2009-05-18 18:01:50 +00:00
|
|
|
Config::Group savedOrder = orderAndProps->getCurrentDictionaryOrder();
|
|
|
|
Config::Group savedInactive = orderAndProps->getCurrentInactiveDictionaries();
|
2009-05-15 12:39:53 +00:00
|
|
|
|
2009-05-05 08:57:37 +00:00
|
|
|
cfg.paths = sources.getPaths();
|
|
|
|
cfg.soundDirs = sources.getSoundDirs();
|
|
|
|
cfg.hunspell = sources.getHunspell();
|
2009-05-06 14:39:08 +00:00
|
|
|
cfg.transliteration = sources.getTransliteration();
|
2022-12-24 14:42:40 +00:00
|
|
|
cfg.lingua = sources.getLingua();
|
2010-06-12 20:16:35 +00:00
|
|
|
cfg.forvo = sources.getForvo();
|
2009-05-05 08:57:37 +00:00
|
|
|
cfg.mediawikis = sources.getMediaWikis();
|
2009-05-16 18:04:21 +00:00
|
|
|
cfg.webSites = sources.getWebSites();
|
2014-04-30 12:55:53 +00:00
|
|
|
cfg.dictServers = sources.getDictServers();
|
2011-05-29 05:08:37 +00:00
|
|
|
cfg.programs = sources.getPrograms();
|
2013-04-24 14:52:04 +00:00
|
|
|
cfg.voiceEngines = sources.getVoiceEngines();
|
2009-05-16 18:04:21 +00:00
|
|
|
|
2009-05-15 12:15:08 +00:00
|
|
|
groupInstances.clear(); // Those hold pointers to dictionaries, we need to
|
|
|
|
// free them.
|
2009-05-05 21:58:48 +00:00
|
|
|
ui.tabs->setUpdatesEnabled( false );
|
2022-03-18 15:12:43 +00:00
|
|
|
|
2009-05-05 21:58:48 +00:00
|
|
|
groups.reset();
|
2023-06-13 00:07:54 +00:00
|
|
|
orderAndProps.reset();
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-15 12:39:53 +00:00
|
|
|
loadDictionaries( this, true, cfg, dictionaries, dictNetMgr );
|
2022-07-08 13:47:09 +00:00
|
|
|
|
2009-05-18 18:01:50 +00:00
|
|
|
// If no changes to groups were made, update the original data
|
2009-05-23 14:19:57 +00:00
|
|
|
bool noGroupEdits = ( origCfg.groups == savedGroups );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
if ( noGroupEdits )
|
|
|
|
savedGroups = cfg.groups;
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
Instances::updateNames( savedGroups, dictionaries );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
bool noOrderEdits = ( origCfg.dictionaryOrder == savedOrder );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
if ( noOrderEdits )
|
|
|
|
savedOrder = cfg.dictionaryOrder;
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
Instances::updateNames( savedOrder, dictionaries );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
bool noInactiveEdits = ( origCfg.inactiveDictionaries == savedInactive );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
if ( noInactiveEdits )
|
|
|
|
savedInactive = cfg.inactiveDictionaries;
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
Instances::updateNames( savedInactive, dictionaries );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2023-06-13 00:07:54 +00:00
|
|
|
if ( rebuildGroups ) {
|
2022-03-18 15:12:43 +00:00
|
|
|
ui.tabs->removeTab( 1 );
|
|
|
|
ui.tabs->removeTab( 1 );
|
2023-06-13 00:07:54 +00:00
|
|
|
orderAndProps.reset( new OrderAndProps( this, savedOrder, savedInactive, dictionaries ) );
|
|
|
|
std::shared_ptr< Groups > other =
|
|
|
|
std::make_shared< Groups >( this, dictionaries, savedGroups, orderAndProps->getCurrentDictionaryOrder() );
|
|
|
|
groups.swap( other );
|
|
|
|
|
|
|
|
ui.tabs->insertTab( 1, orderAndProps.get(), QIcon( ":/icons/book.svg" ), tr( "&Dictionaries" ) );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2022-01-24 14:23:38 +00:00
|
|
|
ui.tabs->insertTab( 2, groups.get(), QIcon(":/icons/bookcase.svg"), tr( "&Groups" ) );
|
2009-05-18 18:01:50 +00:00
|
|
|
|
2009-05-23 14:19:57 +00:00
|
|
|
|
|
|
|
if ( noGroupEdits )
|
|
|
|
origCfg.groups = groups->getGroups();
|
|
|
|
|
|
|
|
if ( noOrderEdits )
|
|
|
|
origCfg.dictionaryOrder = orderAndProps->getCurrentDictionaryOrder();
|
|
|
|
|
|
|
|
if ( noInactiveEdits )
|
|
|
|
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
|
2009-05-15 12:39:53 +00:00
|
|
|
}
|
2022-03-18 15:12:43 +00:00
|
|
|
ui.tabs->setUpdatesEnabled( true );
|
|
|
|
|
2009-05-05 21:58:48 +00:00
|
|
|
}
|