2008-03-06 23:23:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Patrick Ohly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY, TITLE, NONINFRINGEMENT 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., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "FilterConfigNode.h"
|
2008-03-20 22:59:59 +01:00
|
|
|
#include "EvolutionSyncClient.h"
|
2008-03-06 23:23:13 +01:00
|
|
|
|
|
|
|
FilterConfigNode::FilterConfigNode(const boost::shared_ptr<ConfigNode> &node,
|
2008-03-18 22:45:34 +01:00
|
|
|
const ConfigFilter &filter) :
|
2008-03-24 22:42:47 +01:00
|
|
|
m_filter(filter),
|
2008-03-06 23:23:13 +01:00
|
|
|
m_node(node),
|
2008-03-24 22:42:47 +01:00
|
|
|
m_readOnlyNode(node)
|
2008-03-20 22:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterConfigNode::FilterConfigNode(const boost::shared_ptr<const ConfigNode> &node,
|
|
|
|
const ConfigFilter &filter) :
|
2008-03-24 22:42:47 +01:00
|
|
|
m_filter(filter),
|
|
|
|
m_readOnlyNode(node)
|
2008-03-06 23:23:13 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterConfigNode::addFilter(const string &property,
|
|
|
|
const string &value)
|
|
|
|
{
|
2008-07-06 22:26:23 +02:00
|
|
|
m_filter[property] = value;
|
2008-03-06 23:23:13 +01:00
|
|
|
}
|
|
|
|
|
2008-03-18 22:45:34 +01:00
|
|
|
void FilterConfigNode::setFilter(const ConfigFilter &filter)
|
2008-03-06 23:23:13 +01:00
|
|
|
{
|
|
|
|
m_filter = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
string FilterConfigNode::readProperty(const string &property) const
|
|
|
|
{
|
2008-03-18 22:45:34 +01:00
|
|
|
ConfigFilter::const_iterator it = m_filter.find(property);
|
2008-03-06 23:23:13 +01:00
|
|
|
|
|
|
|
if (it != m_filter.end()) {
|
|
|
|
return it->second;
|
|
|
|
} else {
|
2008-03-20 22:59:59 +01:00
|
|
|
return m_readOnlyNode->readProperty(property);
|
2008-03-06 23:23:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterConfigNode::setProperty(const string &property,
|
|
|
|
const string &value,
|
2008-03-30 23:50:51 +02:00
|
|
|
const string &comment,
|
|
|
|
const string *defValue)
|
2008-03-06 23:23:13 +01:00
|
|
|
{
|
2008-03-18 22:45:34 +01:00
|
|
|
ConfigFilter::iterator it = m_filter.find(property);
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-20 22:59:59 +01:00
|
|
|
if (!m_node.get()) {
|
|
|
|
EvolutionSyncClient::throwError(getName() + ": read-only, setting properties not allowed");
|
|
|
|
}
|
|
|
|
|
2008-03-06 23:23:13 +01:00
|
|
|
if (it != m_filter.end()) {
|
|
|
|
m_filter.erase(it);
|
|
|
|
}
|
2008-03-30 23:50:51 +02:00
|
|
|
m_node->setProperty(property, value, comment, defValue);
|
2008-03-06 23:23:13 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 21:54:02 +02:00
|
|
|
void FilterConfigNode::readProperties(map<string, string> &props) const
|
2008-03-06 23:23:13 +01:00
|
|
|
{
|
2008-04-10 21:54:02 +02:00
|
|
|
m_readOnlyNode->readProperties(props);
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-20 22:59:59 +01:00
|
|
|
for(ConfigFilter::const_iterator it = m_filter.begin();
|
2008-03-06 23:23:13 +01:00
|
|
|
it != m_filter.end();
|
|
|
|
it++) {
|
2008-04-10 21:54:02 +02:00
|
|
|
props.insert(*it);
|
2008-03-06 23:23:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterConfigNode::removeProperty(const string &property)
|
|
|
|
{
|
2008-03-18 22:45:34 +01:00
|
|
|
ConfigFilter::iterator it = m_filter.find(property);
|
2008-03-06 23:23:13 +01:00
|
|
|
|
2008-03-20 22:59:59 +01:00
|
|
|
if (!m_node.get()) {
|
|
|
|
EvolutionSyncClient::throwError(getName() + ": read-only, removing properties not allowed");
|
|
|
|
}
|
|
|
|
|
2008-03-06 23:23:13 +01:00
|
|
|
if (it != m_filter.end()) {
|
|
|
|
m_filter.erase(it);
|
|
|
|
}
|
|
|
|
m_node->removeProperty(property);
|
|
|
|
}
|
2008-03-20 22:59:59 +01:00
|
|
|
|
|
|
|
void FilterConfigNode::flush()
|
|
|
|
{
|
|
|
|
if (!m_node.get()) {
|
2008-04-10 22:08:34 +02:00
|
|
|
EvolutionSyncClient::throwError(getName() + ": read-only, flushing not allowed");
|
2008-03-20 22:59:59 +01:00
|
|
|
}
|
|
|
|
m_node->flush();
|
|
|
|
}
|