make config option "show-hidden notification icons" persistent

svn path=/trunk/; revision=8898
This commit is contained in:
Martin Fuchs 2004-03-28 12:00:46 +00:00
parent 6d1dae4a75
commit bbc679d779
5 changed files with 199 additions and 50 deletions

View file

@ -3,7 +3,7 @@
<tr> <tr>
<td><address style="align: right;"><small> <td><address style="align: right;"><small>
ROS Explorer Source Code Documentation ROS Explorer Source Code Documentation
<br>generated on 27.03.2004 by <a href="http://www.doxygen.org/index.html"> <br>generated on 28.03.2004 by <a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0> <img src="doxygen.png" alt="doxygen" align="middle" border=0>
</small></address> </small></address>
</td> </td>

View file

@ -20,6 +20,7 @@
</taskbar> </taskbar>
<notify-icons> <notify-icons>
<option show-hidden="FALSE"/>
<icon name="Volume Control" text="Volume" show="show"/> <icon name="Volume Control" text="Volume" show="show"/>
</notify-icons> </notify-icons>

View file

@ -195,6 +195,8 @@ void NotifyArea::read_config()
if (pos.go_down("explorer-cfg")) { if (pos.go_down("explorer-cfg")) {
if (pos.go_down("notify-icons")) { if (pos.go_down("notify-icons")) {
_show_hidden = XMLBool(pos, "option", "show-hidden");
XMLChildrenFilter icons(pos, "icon"); XMLChildrenFilter icons(pos, "icon");
for(XMLChildrenFilter::iterator it=icons.begin(); it!=icons.end(); ++it) { for(XMLChildrenFilter::iterator it=icons.begin(); it!=icons.end(); ++it) {
@ -227,13 +229,14 @@ void NotifyArea::read_config()
void NotifyArea::write_config() void NotifyArea::write_config()
{ {
// write notification icon settings to XML configuration // write notification icon settings to XML configuration file
XMLPos pos(&g_Globals._cfg); XMLPos pos(&g_Globals._cfg);
///@todo pos.create("\\explorer-cfg\\startmenu");
pos.create("explorer-cfg"); pos.create("explorer-cfg");
pos.create("notify-icons"); pos.create("notify-icons");
XMLBoolRef(pos, "option", "show-hidden") = _show_hidden;
for(NotifyIconCfgList::iterator it=_cfg.begin(); it!=_cfg.end(); ++it) { for(NotifyIconCfgList::iterator it=_cfg.begin(); it!=_cfg.end(); ++it) {
NotifyIconConfig& cfg = *it; NotifyIconConfig& cfg = *it;

View file

@ -133,14 +133,33 @@ std::string XMLString(LPCTSTR s)
} }
/// write node with children tree to output stream /// write node with children tree to output stream using original white space
std::ostream& XMLNode::write_worker(std::ostream& out, WRITE_MODE mode, int indent) void XMLNode::write_worker(std::ostream& out, WRITE_MODE mode, int indent) const
{ {
bool format = mode==FORMAT_PRETTY; out << '<' << XMLString(*this);
if (format) for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
for(int i=indent; i--; ) out << ' ' << XMLString(it->first) << "=\"" << XMLString(it->second) << "\"";
out << XML_INDENT_SPACE;
if (!_children.empty() || !_content.empty()) {
out << '>' << _content;
for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
(*it)->write_worker(out, mode, indent+1);
out << "</" << XMLString(*this) << '>';
} else
out << "/>";
out << _trailing;
}
/// pretty print node with children tree to output stream
void XMLNode::pretty_write_worker(std::ostream& out, WRITE_MODE mode, int indent) const
{
for(int i=indent; i--; )
out << XML_INDENT_SPACE;
out << '<' << XMLString(*this); out << '<' << XMLString(*this);
@ -148,36 +167,23 @@ std::ostream& XMLNode::write_worker(std::ostream& out, WRITE_MODE mode, int inde
out << ' ' << XMLString(it->first) << "=\"" << XMLString(it->second) << "\""; out << ' ' << XMLString(it->first) << "=\"" << XMLString(it->second) << "\"";
if (!_children.empty() || !_content.empty()) { if (!_children.empty() || !_content.empty()) {
out << '>'; out << ">\n";
if (format)
out << '\n';
else
out << _content;
for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
(*it)->write_worker(out, mode, indent+1); (*it)->pretty_write_worker(out, mode, indent+1);
if (format) for(int i=indent; i--; )
for(int i=indent; i--; ) out << XML_INDENT_SPACE;
out << XML_INDENT_SPACE;
out << "</" << XMLString(*this) << '>'; out << "</" << XMLString(*this) << ">\n";
} else { } else
out << "/>"; out << "/>\n";
}
if (format)
out << '\n';
else
out << _trailing;
return out;
} }
/// write node with children tree to output stream using smart formating /// write node with children tree to output stream using smart formating
std::ostream& XMLNode::smart_write_worker(std::ostream& out, int indent, bool& next_format) bool XMLNode::smart_write_worker(std::ostream& out, int indent, bool next_format) const
{ {
bool format_pre, format_mid, format_post; bool format_pre, format_mid, format_post;
@ -208,7 +214,7 @@ std::ostream& XMLNode::smart_write_worker(std::ostream& out, int indent, bool& n
next_format = (*it)->_content.empty() && (*it)->_trailing.empty(); next_format = (*it)->_content.empty() && (*it)->_trailing.empty();
for(; it!=_children.end(); ++it) for(; it!=_children.end(); ++it)
(*it)->smart_write_worker(out, indent+1, next_format); next_format = (*it)->smart_write_worker(out, indent+1, next_format);
} }
if (next_format) if (next_format)
@ -216,18 +222,15 @@ std::ostream& XMLNode::smart_write_worker(std::ostream& out, int indent, bool& n
out << XML_INDENT_SPACE; out << XML_INDENT_SPACE;
out << "</" << XMLString(*this) << '>'; out << "</" << XMLString(*this) << '>';
} else { } else
out << "/>"; out << "/>";
}
if (format_post) if (format_post)
out << '\n'; out << '\n';
else else
out << _trailing; out << _trailing;
next_format = format_post; return format_post;
return out;
} }

View file

@ -289,15 +289,22 @@ struct XMLNode : public String
}; };
/// write node with children tree to output stream /// write node with children tree to output stream
std::ostream& write(std::ostream& out, WRITE_MODE mode=FORMAT_SMART, int indent=0) std::ostream& write(std::ostream& out, WRITE_MODE mode=FORMAT_SMART, int indent=0) const
{ {
if (mode) { switch(mode) {
return write_worker(out, mode, indent); case FORMAT_PRETTY:
} else { // FORMAT_SMART pretty_write_worker(out, mode, indent);
bool next_format = _content.empty() && _trailing.empty(); break;
return smart_write_worker(out, indent, next_format); case FORMAT_ORIGINAL:
write_worker(out, mode, indent);
break;
default: // FORMAT_SMART
smart_write_worker(out, indent, _content.empty() && _trailing.empty());
} }
return out;
} }
protected: protected:
@ -352,8 +359,9 @@ protected:
_children.back()->_trailing.append(s, l); _children.back()->_trailing.append(s, l);
} }
std::ostream& write_worker(std::ostream& out, WRITE_MODE mode, int indent); void write_worker(std::ostream& out, WRITE_MODE mode, int indent) const;
std::ostream& smart_write_worker(std::ostream& out, int indent, bool& next_format); void pretty_write_worker(std::ostream& out, WRITE_MODE mode, int indent) const;
bool smart_write_worker(std::ostream& out, int indent, bool next_format) const;
}; };
@ -520,6 +528,9 @@ struct XMLPos
return false; return false;
} }
/// move X-Path like to position in XML tree
bool go(const char* path);
/// create node if not already existing and move to it /// create node if not already existing and move to it
void create(const String& name) void create(const String& name)
{ {
@ -545,7 +556,27 @@ struct XMLPos
} }
} }
bool go(const char* path); String& value(const String& name, const String& attr_name)
{
XMLNode* node = _cur->find_first(name);
if (!node) {
node = new XMLNode(name);
_cur->add_child(node);
}
return (*node)[attr_name];
}
String value(const String& name, const String& attr_name) const
{
XMLNode* node = _cur->find_first(name);
if (node)
return (*node)[attr_name];
else
return "";
}
protected: protected:
XMLNode* _root; XMLNode* _root;
@ -561,6 +592,117 @@ protected:
}; };
struct XMLBool
{
XMLBool(bool value)
: _value(value)
{
}
XMLBool(LPCTSTR value)
{
_value = !_tcsicmp(value, TEXT("TRUE"));
}
XMLBool(XMLPos& pos, const String& name, const String& attr_name)
{
_value = !_tcsicmp(pos.value(name, attr_name), TEXT("TRUE"));
}
operator bool() const
{
return _value;
}
operator LPCTSTR() const
{
return _value? TEXT("TRUE"): TEXT("FALSE");
}
protected:
bool _value;
private:
void operator=(const XMLBool&); // disallow assignment operations
};
struct XMLBoolRef
{
XMLBoolRef(XMLPos& pos, const String& name, const String& attr_name)
: _ref(pos.value(name, attr_name))
{
}
XMLBoolRef& operator=(bool value)
{
_ref.assign(value? TEXT("TRUE"): TEXT("FALSE"));
return *this;
}
protected:
String& _ref;
};
struct XMLNumber
{
XMLNumber(int value)
: _value(value)
{
}
XMLNumber(LPCTSTR value)
{
_value = _ttoi(value);
}
XMLNumber(XMLPos& pos, const String& name, const String& attr_name)
{
_value = _ttoi(pos.value(name, attr_name));
}
operator int() const
{
return _value;
}
operator String() const
{
TCHAR buffer[32];
_stprintf(buffer, TEXT("%d"), _value);
return buffer;
}
protected:
int _value;
private:
void operator=(const XMLBool&); // disallow assignment operations
};
struct XMLNumberRef
{
XMLNumberRef(XMLPos& pos, const String& name, const String& attr_name)
: _ref(pos.value(name, attr_name))
{
}
XMLNumberRef& operator=(int value)
{
TCHAR buffer[32];
_stprintf(buffer, TEXT("%d"), value);
_ref.assign(buffer);
return *this;
}
protected:
String& _ref;
};
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable: 4355) #pragma warning(disable: 4355)
#endif #endif
@ -672,7 +814,7 @@ struct XMLDoc : public XMLNode
/// write XML stream preserving previous white space and comments /// write XML stream preserving previous white space and comments
std::ostream& write(std::ostream& out, WRITE_MODE mode=FORMAT_SMART, std::ostream& write(std::ostream& out, WRITE_MODE mode=FORMAT_SMART,
const std::string& xml_version="1.0", const std::string& encoding="UTF-8") const std::string& xml_version="1.0", const std::string& encoding="UTF-8") const
{ {
out << "<?xml version=\"" << xml_version << "\" encoding=\"" << encoding << "\"?>\n"; out << "<?xml version=\"" << xml_version << "\" encoding=\"" << encoding << "\"?>\n";
@ -683,20 +825,20 @@ struct XMLDoc : public XMLNode
} }
/// write XML stream with formating /// write XML stream with formating
std::ostream& write_formating(std::ostream& out) std::ostream& write_formating(std::ostream& out) const
{ {
return write(out, FORMAT_PRETTY); return write(out, FORMAT_PRETTY);
} }
void write(const std::string& path, WRITE_MODE mode=FORMAT_SMART, void write(const std::string& path, WRITE_MODE mode=FORMAT_SMART,
const std::string& xml_version="1.0", const std::string& encoding="UTF-8") const std::string& xml_version="1.0", const std::string& encoding="UTF-8") const
{ {
std::ofstream out(path.c_str()); std::ofstream out(path.c_str());
write(out, mode, xml_version, encoding); write(out, mode, xml_version, encoding);
} }
void write_formating(const std::string& path) void write_formating(const std::string& path) const
{ {
std::ofstream out(path.c_str()); std::ofstream out(path.c_str());