summaryrefslogtreecommitdiffstats
path: root/fbreader/src/external
diff options
context:
space:
mode:
Diffstat (limited to 'fbreader/src/external')
-rw-r--r--fbreader/src/external/ProgramCollection.cpp188
-rw-r--r--fbreader/src/external/ProgramCollection.h90
2 files changed, 0 insertions, 278 deletions
diff --git a/fbreader/src/external/ProgramCollection.cpp b/fbreader/src/external/ProgramCollection.cpp
deleted file mode 100644
index 9599d90..0000000
--- a/fbreader/src/external/ProgramCollection.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
- *
- * 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 <algorithm>
-
-#include <ZLibrary.h>
-#include <ZLFile.h>
-#include <ZLXMLReader.h>
-#include <ZLResource.h>
-
-#include "ProgramCollection.h"
-#include "../options/FBCategoryKey.h"
-
-class ProgramCollectionBuilder : public ZLXMLReader {
-
-public:
- ProgramCollectionBuilder(ProgramCollectionMap &collectionMap);
- ~ProgramCollectionBuilder();
-
-private:
- void startElementHandler(const char *tag, const char **attributes);
- void endElementHandler(const char *tag);
-
-private:
- ProgramCollectionMap &myCollectionMap;
- shared_ptr<ProgramCollection> myCurrentCollection;
- shared_ptr<Program> myCurrentProgram;
-};
-
-static const std::string SECTION = "section";
-static const std::string PROGRAM = "program";
-static const std::string ACTION = "action";
-static const std::string OPTION = "option";
-
-ProgramCollectionBuilder::ProgramCollectionBuilder(ProgramCollectionMap &collectionMap) : myCollectionMap(collectionMap) {
-}
-
-ProgramCollectionBuilder::~ProgramCollectionBuilder() {
-}
-
-void ProgramCollectionBuilder::startElementHandler(const char *tag, const char **attributes) {
- if (SECTION == tag) {
- const char *name = attributeValue(attributes, "name");
- if (name != 0) {
- myCurrentCollection = myCollectionMap.myMap[name];
- if (myCurrentCollection.isNull()) {
- myCurrentCollection = new ProgramCollection(name);
- myCollectionMap.myMap[name] = myCurrentCollection;
- }
- }
- } else if (!myCurrentCollection.isNull() && (PROGRAM == tag)) {
- const char *name = attributeValue(attributes, "name");
- const char *protocol = attributeValue(attributes, "protocol");
- const char *testFile = attributeValue(attributes, "testFile");
- if ((name != 0) && (protocol != 0)) {
- shared_ptr<ZLMessageOutputChannel> channel =
- ZLCommunicationManager::Instance().createMessageOutputChannel(protocol, (testFile != 0) ? testFile : "");
- if (!channel.isNull()) {
- std::string sName = name;
- if (!sName.empty()) {
- if (sName[0] == '%') {
- sName = ZLResource::resource("external")[sName.substr(1)].value();
- }
- myCurrentProgram = new Program(sName, channel);
- myCurrentCollection->myNames.push_back(sName);
- myCurrentCollection->myPrograms[sName] = myCurrentProgram;
- }
- }
- }
- } else if (!myCurrentProgram.isNull() && (ACTION == tag)) {
- const char *name = attributeValue(attributes, "name");
- if (name != 0) {
- static const std::string NAME = "name";
- ZLCommunicationManager::Data &data = myCurrentProgram->myCommandData[name];
- for (const char **it = attributes; (*it != 0) && (*(it + 1) != 0); it += 2) {
- if (NAME != *it) {
- data[*it] = *(it + 1);
- }
- }
- }
- } else if (!myCurrentProgram.isNull() && (OPTION == tag)) {
- const char *name = attributeValue(attributes, "name");
- if (name != 0) {
- const char *defaultValue = attributeValue(attributes, "defaultValue");
- const std::string sName = name;
- const std::string sDefaultValue = (defaultValue != 0) ? defaultValue : std::string();
- myCurrentProgram->myOptions.push_back(Program::OptionDescription(sName, sDefaultValue));
- myCurrentProgram->myDefaultValues[sName] = sDefaultValue;
- }
- }
-}
-
-void ProgramCollectionBuilder::endElementHandler(const char *tag) {
- if (SECTION == tag) {
- if (!myCurrentCollection.isNull()) {
- const std::vector<std::string> &names = myCurrentCollection->names();
- ZLStringOption &nameOption = myCurrentCollection->CurrentNameOption;
- if (!names.empty() && (std::find(names.begin(), names.end(), nameOption.value()) == names.end())) {
- nameOption.setValue(names.front());
- }
- }
- myCurrentCollection = 0;
- myCurrentProgram = 0;
- } else if (PROGRAM == tag) {
- myCurrentProgram = 0;
- }
-}
-
-ProgramCollectionMap::ProgramCollectionMap() {
- ProgramCollectionBuilder builder(*this);
- builder.readDocument(ZLFile(ZLibrary::DefaultFilesPathPrefix() + "external.xml"));
-}
-
-shared_ptr<ProgramCollection> ProgramCollectionMap::collection(const std::string &name) const {
- std::map<std::string,shared_ptr<ProgramCollection> >::const_iterator it = myMap.find(name);
- return (it != myMap.end()) ? it->second : 0;
-}
-
-ProgramCollection::ProgramCollection(const std::string &name) :
- EnableCollectionOption(ZLCategoryKey::CONFIG, name, "Enabled", true),
- CurrentNameOption(ZLCategoryKey::CONFIG, name, "Name", "") {
-}
-
-const std::vector<std::string> &ProgramCollection::names() const {
- return myNames;
-}
-
-shared_ptr<Program> ProgramCollection::program(const std::string &name) const {
- std::map<std::string,shared_ptr<Program> >::const_iterator it = myPrograms.find(name);
- return (it != myPrograms.end()) ? it->second : 0;
-}
-
-shared_ptr<Program> ProgramCollection::currentProgram() const {
- if (!EnableCollectionOption.value()) {
- return 0;
- }
- return program(CurrentNameOption.value());
-}
-
-Program::Program(const std::string &name, shared_ptr<ZLMessageOutputChannel> channel) : myName(name), myChannel(channel) {
-}
-
-void Program::run(const std::string &command, const std::string &parameter) const {
- if (!myChannel.isNull()) {
- std::map<std::string,ZLCommunicationManager::Data>::const_iterator it = myCommandData.find(command);
- if (it != myCommandData.end()) {
- ZLCommunicationManager::Data data = it->second;
- for (ZLCommunicationManager::Data::iterator jt = data.begin(); jt != data.end(); ++jt) {
- if (!jt->second.empty() && jt->second[0] == '%') {
- const std::string optionName = jt->second.substr(1);
- std::map<std::string,std::string>::const_iterator st = myDefaultValues.find(optionName);
- jt->second = ZLStringOption(
- FBCategoryKey::EXTERNAL,
- myName,
- optionName,
- (st != myDefaultValues.end()) ? st->second : "").value();
- }
- }
- shared_ptr<ZLMessageSender> sender = myChannel->createSender(data);
- if (!sender.isNull()) {
- sender->sendStringMessage(parameter);
- }
- }
- }
-}
-
-const std::vector<Program::OptionDescription> &Program::options() const {
- return myOptions;
-}
-
-Program::OptionDescription::OptionDescription(const std::string &name, const std::string &defaultValue) : OptionName(name), DefaultValue(defaultValue) {
-}
diff --git a/fbreader/src/external/ProgramCollection.h b/fbreader/src/external/ProgramCollection.h
deleted file mode 100644
index a8aa3ec..0000000
--- a/fbreader/src/external/ProgramCollection.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
- *
- * 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.
- */
-
-#ifndef __PROGRAMCOLLECTION_H__
-#define __PROGRAMCOLLECTION_H__
-
-#include <string>
-#include <map>
-#include <vector>
-
-#include <shared_ptr.h>
-#include <ZLMessage.h>
-#include <ZLOptions.h>
-
-class Program {
-
-private:
- Program(const std::string &name, shared_ptr<ZLMessageOutputChannel> channel);
-
-public:
- void run(const std::string &command, const std::string &parameter) const;
-
-public:
- struct OptionDescription {
- OptionDescription(const std::string &name, const std::string &defaultValue);
- std::string OptionName;
- std::string DefaultValue;
- };
- const std::vector<OptionDescription> &options() const;
-
-private:
- const std::string myName;
- shared_ptr<ZLMessageOutputChannel> myChannel;
- std::map<std::string,ZLCommunicationManager::Data> myCommandData;
- std::vector<OptionDescription> myOptions;
- std::map<std::string,std::string> myDefaultValues;
-
-friend class ProgramCollection;
-friend class ProgramCollectionBuilder;
-};
-
-class ProgramCollection {
-
-public:
- mutable ZLBooleanOption EnableCollectionOption;
- mutable ZLStringOption CurrentNameOption;
-
-public:
- ProgramCollection(const std::string &name);
-
- const std::vector<std::string> &names() const;
- shared_ptr<Program> currentProgram() const;
- shared_ptr<Program> program(const std::string &name) const;
-
-private:
- std::vector<std::string> myNames;
- std::map<std::string,shared_ptr<Program> > myPrograms;
-
-friend class ProgramCollectionBuilder;
-};
-
-class ProgramCollectionMap {
-
-public:
- ProgramCollectionMap();
- shared_ptr<ProgramCollection> collection(const std::string &name) const;
-
-private:
- std::map<std::string,shared_ptr<ProgramCollection> > myMap;
-
-friend class ProgramCollectionBuilder;
-};
-
-#endif /* __PROGRAMCOLLECTION_H__ */