From 17b259df9cb6b28779d4881b2b6c805ee2e48eea Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 7 Jun 2024 23:30:05 +0900 Subject: Rename to tde-ebook-reader Signed-off-by: Michele Calgaro --- reader/src/optionsDialog/IntegrationTab.cpp | 159 ++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 reader/src/optionsDialog/IntegrationTab.cpp (limited to 'reader/src/optionsDialog/IntegrationTab.cpp') diff --git a/reader/src/optionsDialog/IntegrationTab.cpp b/reader/src/optionsDialog/IntegrationTab.cpp new file mode 100644 index 0000000..ca3ebf0 --- /dev/null +++ b/reader/src/optionsDialog/IntegrationTab.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2004-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +#include +#include +#include + +#include +#include + +#include "AbstractOptionsDialog.h" + +#include "../options/FBCategoryKey.h" +#include "../external/ProgramCollection.h" + + +class ProgramChoiceEntry : public ZLComboOptionEntry { + +public: + ProgramChoiceEntry(const ProgramCollection &collection); + +private: + const std::vector &values() const; + void onAccept(const std::string &value); + void onValueSelected(int index); + +public: + const std::string &initialValue() const; + void addDependentEntry(const std::string &name, ZLOptionEntry *dependentEntry); + void updateDependentEntries(bool visible); + +private: + const ProgramCollection &myCollection; + std::string myValue; + std::map myDependentEntries; +}; + +class EnableIntegrationEntry : public ZLToggleBooleanOptionEntry { + +public: + EnableIntegrationEntry(ZLBooleanOption &option); + void setProgramChoiceEntry(ProgramChoiceEntry *programChoiceEntry); + void onStateChanged(bool state); + +private: + ProgramChoiceEntry *myProgramChoiceEntry; +}; + +ProgramChoiceEntry::ProgramChoiceEntry(const ProgramCollection &collection) : myCollection(collection) { + myValue = initialValue(); +} + +const std::string &ProgramChoiceEntry::initialValue() const { + return myCollection.CurrentNameOption.value(); +} + +const std::vector &ProgramChoiceEntry::values() const { + return myCollection.names(); +} + +void ProgramChoiceEntry::onAccept(const std::string &value) { + myCollection.CurrentNameOption.setValue(value); +} + +void ProgramChoiceEntry::addDependentEntry(const std::string &name, ZLOptionEntry *dependentEntry) { + myDependentEntries[dependentEntry] = name; +} + +void ProgramChoiceEntry::onValueSelected(int index) { + myValue = values()[index]; + updateDependentEntries(true); +} + +void ProgramChoiceEntry::updateDependentEntries(bool visible) { + for (std::map::const_iterator it = myDependentEntries.begin(); it != myDependentEntries.end(); ++it) { + it->first->setVisible(visible && (it->second == myValue)); + } +} + +EnableIntegrationEntry::EnableIntegrationEntry(ZLBooleanOption &option) : ZLToggleBooleanOptionEntry(option), myProgramChoiceEntry(0) { +} + +void EnableIntegrationEntry::setProgramChoiceEntry(ProgramChoiceEntry *programChoiceEntry) { + addDependentEntry(programChoiceEntry); + myProgramChoiceEntry = programChoiceEntry; +} + +void EnableIntegrationEntry::onStateChanged(bool state) { + ZLToggleBooleanOptionEntry::onStateChanged(state); + if (myProgramChoiceEntry != 0) { + myProgramChoiceEntry->updateDependentEntries(state); + } +} + +void AbstractOptionsDialog::createIntegrationTab(shared_ptr collection, const ZLResourceKey &key, std::vector > &additionalOptions) { + if (!collection.isNull()) { + const std::vector &programNames = collection->names(); + if (!programNames.empty()) { + ZLDialogContent &tab = myDialog->createTab(key); + std::string optionName; + if (programNames.size() == 1) { + optionName = ZLStringUtil::printf(tab.value(ZLResourceKey("enableIntegration")), programNames[0]); + } else { + optionName = tab.value(ZLResourceKey("defaultText")); + } + EnableIntegrationEntry *enableIntegrationEntry = + new EnableIntegrationEntry(collection->EnableCollectionOption); + tab.addOption(optionName, "", enableIntegrationEntry); + + ProgramChoiceEntry *programChoiceEntry = 0; + if (programNames.size() > 1) { + programChoiceEntry = new ProgramChoiceEntry(*collection); + tab.addOption(ZLResourceKey("choice"), programChoiceEntry); + enableIntegrationEntry->setProgramChoiceEntry(programChoiceEntry); + } + + for (std::vector::const_iterator it = programNames.begin(); it != programNames.end(); ++it) { + const std::vector &options = collection->program(*it)->options(); + for (std::vector::const_iterator jt = options.begin(); jt != options.end(); ++jt) { + ZLStringOption *parameterOption = new ZLStringOption(FBCategoryKey::EXTERNAL, *it, jt->OptionName, jt->DefaultValue); + storeTemporaryOption(parameterOption); + ZLOptionEntry *parameterEntry = new ZLSimpleStringOptionEntry(*parameterOption); + if (programChoiceEntry != 0) { + programChoiceEntry->addDependentEntry(*it, parameterEntry); + } else { + enableIntegrationEntry->addDependentEntry(parameterEntry); + } + tab.addOption(ZLResourceKey(jt->OptionName), parameterEntry); + } + } + for (std::vector >::const_iterator it = additionalOptions.begin(); it != additionalOptions.end(); ++it) { + enableIntegrationEntry->addDependentEntry(it->second); + tab.addOption(it->first, it->second); + } + enableIntegrationEntry->onStateChanged(enableIntegrationEntry->initialState()); + return; + } + } + + for (std::vector >::const_iterator it = additionalOptions.begin(); it != additionalOptions.end(); ++it) { + delete it->second; + } +} -- cgit v1.2.3