[rkward-cvs] rkward/rkward/misc rkmenulist.cpp,1.1,1.2 rkmenulist.h,1.1,1.2 xmlhelper.cpp,1.1,1.2 xmlhelper.h,1.1,1.2
Thomas Friedrichsmeier
tfry at users.sourceforge.net
Fri Sep 9 13:02:59 UTC 2005
- Previous message: [rkward-cvs] rkward/rkward/plugins Makefile.am,1.9,1.10 standard_plugins.pluginmap,1.1,1.2
- Next message: [rkward-cvs] rkward/rkward rkglobals.cpp,1.6,1.7 rkglobals.h,1.5,1.6 rkward.cpp,1.84,1.85 rkward.h,1.36,1.37
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/rkward/rkward/rkward/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12794/rkward/misc
Modified Files:
rkmenulist.cpp rkmenulist.h xmlhelper.cpp xmlhelper.h
Log Message:
Changed the way plugin-handles and corresponding menu-entries are created. Added some first building blocks for component infrastructure. Some polishing still needed.
Index: xmlhelper.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/xmlhelper.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** xmlhelper.cpp 8 May 2005 16:55:44 -0000 1.1
--- xmlhelper.cpp 9 Sep 2005 13:02:57 -0000 1.2
***************
*** 29,40 ****
--- 29,45 ----
XMLHelper::XMLHelper () {
+ RK_TRACE (XML);
+
highest_error = 0;
}
XMLHelper::~XMLHelper () {
+ RK_TRACE (XML);
}
//static
XMLHelper *XMLHelper::getStaticHelper () {
+ RK_TRACE (XML);
+
if (!static_xml_helper) {
static_xml_helper = new XMLHelper ();
***************
*** 44,47 ****
--- 49,54 ----
QDomElement XMLHelper::openXMLFile (const QString &filename, int debug_level) {
+ RK_TRACE (XML);
+
int error_line, error_column;
QString error_message;
***************
*** 61,72 ****
}
! QDomNodeList XMLHelper::getChildElements (const QDomElement &parent, const QString &name, int debug_level) {
! QString convert;
if (!parent.isNull()) {
! if (name != "") {
! return (parent.elementsByTagName (name));
! } else {
! return (parent.childNodes ());
}
} else {
--- 68,86 ----
}
! XMLChildList XMLHelper::getChildElements (const QDomElement &parent, const QString &name, int debug_level) {
! RK_TRACE (XML);
!
! XMLChildList list;
if (!parent.isNull()) {
! QDomNode n = parent.firstChild ();
! while (!n.isNull ()) {
! QDomElement e = n.toElement ();
! if (!e.isNull ()) {
! if ((name == "") || (e.tagName () == name)) {
! list.append (e);
! }
! }
! n = n.nextSibling ();
}
} else {
***************
*** 74,82 ****
}
- QDomNodeList list;
return (list);
}
QString XMLHelper::getStringAttribute (const QDomElement &element, const QString &name, const QString &def, int debug_level) {
if (!element.hasAttribute (name)) {
displayError (&element, i18n ("'%1'-attribute not given. Assuming '%2'").arg (name).arg (def), debug_level);
--- 88,110 ----
}
return (list);
}
+ QDomElement XMLHelper::getChildElement (const QDomElement &parent, const QString &name, int debug_level) {
+ RK_TRACE (XML);
+
+ XMLChildList list = getChildElements (parent, name, debug_level);
+ if (list.count () != 1) {
+ displayError (&parent, i18n ("Expected exactly one element '%1' but found %2").arg (name).arg (QString::number (list.count ())), debug_level);
+ QDomElement dummy;
+ return dummy;
+ }
+
+ return list.first ();
+ }
+
QString XMLHelper::getStringAttribute (const QDomElement &element, const QString &name, const QString &def, int debug_level) {
+ RK_TRACE (XML);
+
if (!element.hasAttribute (name)) {
displayError (&element, i18n ("'%1'-attribute not given. Assuming '%2'").arg (name).arg (def), debug_level);
***************
*** 87,91 ****
--- 115,154 ----
}
+ int XMLHelper::getMultiChoiceAttribute (const QDomElement &element, const QString &name, const QString &values, int def, int debug_level) {
+ RK_TRACE (XML);
+
+ QStringList value_list = QStringList::split (';', values);
+
+ QString plain_value = getStringAttribute (element, name, value_list[def], debug_level);
+
+ int index;
+ if ((index = value_list.findIndex (plain_value)) >= 0) {
+ return (index);
+ } else {
+ displayError (&element, i18n ("Illegal attribute value. Allowed values are one of '%1', only.").arg (values), debug_level, DL_ERROR);
+ return def;
+ }
+ }
+
+ int XMLHelper::getIntAttribute (const QDomElement &element, const QString &name, int def, int debug_level) {
+ RK_TRACE (XML);
+
+ QString res = getStringAttribute (element, name, QString::number (def), debug_level);
+
+ bool valid_number;
+ int ret = res.toInt (&valid_number);
+
+ if (!valid_number) {
+ displayError (&element, i18n ("Illegal attribute value. Only integer numbers are allowed."), debug_level, DL_ERROR);
+ return def;
+ }
+
+ return ret;
+ }
+
+
bool XMLHelper::getBoolAttribute (const QDomElement &element, const QString &name, bool def, int debug_level) {
+ RK_TRACE (XML);
+
QString defstring, res;
if (def) defstring = "true";
***************
*** 101,104 ****
--- 164,169 ----
void XMLHelper::displayError (const QDomNode *in_node, const QString &message, int debug_level, int message_level) {
+ RK_TRACE (XML);
+
if (message_level < debug_level) message_level = debug_level;
if (highest_error < debug_level) highest_error = debug_level;
***************
*** 109,116 ****
QStringList list;
! QDomNode node_copy = *in_node;
! while (!((node_copy.isDocument ()) || (node_copy.isNull ()))) {
! list.prepend (node_copy.nodeName ());
! node_copy = node_copy.parentNode ();
}
--- 174,183 ----
QStringList list;
! if (in_node) {
! QDomNode node_copy = *in_node;
! while (!((node_copy.isNull ()) || (node_copy.isDocument ()))) {
! list.prepend (node_copy.nodeName ());
! node_copy = node_copy.parentNode ();
! }
}
Index: rkmenulist.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenulist.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkmenulist.h 27 Aug 2004 10:17:35 -0000 1.1
--- rkmenulist.h 9 Sep 2005 13:02:57 -0000 1.2
***************
*** 30,34 ****
@author Thomas Friedrichsmeier
*/
! class RKMenuList{
public:
RKMenuList (QMenuBar *menubar);
--- 30,34 ----
@author Thomas Friedrichsmeier
*/
! class RKMenuList {
public:
RKMenuList (QMenuBar *menubar);
***************
*** 40,43 ****
--- 40,45 ----
/** like registerMenu, except that a new QPopupMenu is created with the given label. */
RKMenu *createMenu (const QString &id, const QString &label, int index);
+ /** clears all menus created via RKMenuList */
+ void clear ();
private:
typedef QMap<QString, RKMenu*> MenuMap;
Index: xmlhelper.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/xmlhelper.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** xmlhelper.h 8 May 2005 16:55:44 -0000 1.1
--- xmlhelper.h 9 Sep 2005 13:02:57 -0000 1.2
***************
*** 20,23 ****
--- 20,27 ----
#include <qdom.h>
+ #include <qvaluelist.h>
+
+ /** a helper type used to pass a list of direct child elements of a node */
+ typedef QValueList<QDomElement> XMLChildList;
/** This class contains some convenience functions for parsing XML files (DOM). Usually you will use a static instance of this class (getStaticHelper ()), which will be created early in rkward initialization. The error-logs will be reset every time you open a new XML-file using openXMLFile (). This is fine as long as you are parsing files one by one instead of mixing several files. In the latter case you will want to create additional instances of XMLHelper (it's quite possible, this mechanism will be changed, but I want to get going before considering all implications ;-)).
***************
*** 27,30 ****
--- 31,36 ----
Warning/Error messages will always be printed using the standard debugging framework (shown according to user settings).
+ TODO: Probably it's not really clever to use the debugging-framework for showing error-messages in XML-file parsing. Anyway, the only function to adjust in order to change this would be displayError ().
+
@author Thomas Friedrichsmeier
*/
***************
*** 43,54 ****
QDomElement openXMLFile (const QString &filename, int debug_level);
! /** returns all child elements with a given tag-name of the given parent
@param parent the element whose children to return
@param name the tag-name to look for (if none given, will return all children)
@param debug_level level of debug message to generate in case of failure
@returns a list of child elements (you'll have to call toElement () on the list items), in the order of occurence in the XML file */
! QDomNodeList getChildElements (const QDomElement &parent, const QString &name, int debug_level);
! /** returns the value of a string attribute
@param element the element whose attributes to search
@param name the name of the attribute to read
--- 49,67 ----
QDomElement openXMLFile (const QString &filename, int debug_level);
! /** returns all (direct) child elements with a given tag-name of the given parent
@param parent the element whose children to return
@param name the tag-name to look for (if none given, will return all children)
@param debug_level level of debug message to generate in case of failure
@returns a list of child elements (you'll have to call toElement () on the list items), in the order of occurence in the XML file */
! XMLChildList getChildElements (const QDomElement &parent, const QString &name, int debug_level);
! /** like getChildElements, but tries to retrieve exactly one element. Throws an error, if no such element, or more than one such element was found.
! @param parent the element whose children to search
! @param name the tag-name to look for
! @param debug_level level of debug message to generate in case of failure
! @returns the element found */
! QDomElement getChildElement (const QDomElement &parent, const QString &name, int debug_level);
!
! /** returns the value of a string attribute (Note: most get...Attribute functions use this function internally)
@param element the element whose attributes to search
@param name the name of the attribute to read
***************
*** 58,61 ****
--- 71,91 ----
QString getStringAttribute (const QDomElement &element, const QString &name, const QString &def, int debug_level);
+ /** checks whether the given attribute is one of the allowed string values and returns the number of the value in the list (or the default)
+ @param element the element whose attributes to search
+ @param name the name of the attribute to read
+ @param values a list of allowed values given as a QString separated by ';', e.g. "menu;entry" allows the values "menu" (returns 0) or "entry" (returns 1)
+ @param def default value to return if no such attribute is given or does not hold a legal value
+ @param debug_level level of debug message to generate in case of failure (i.e. no such attribute was found) Note that if the given attribute is found, but is not a valid value, an error-message will be shown regardless of this setting, but highestError () will still use debug_level)
+ @returns the index of the value of the given attribute or the given default (see parameter values) */
+ int getMultiChoiceAttribute (const QDomElement &element, const QString &name, const QString &values, int def, int debug_level);
+
+ /** returns the value of an integer attribute
+ @param element the element whose attributes to search
+ @param name the name of the attribute to read
+ @param def default value to return if no such attribute is given
+ @param debug_level level of debug message to generate in case of failure (i.e. no such attribute was found, or attribute was not an integer. Note that if the given attribute is found, but is not a valid integer, an error-message will be shown regardless of this setting, but highestError () will still use debug_level)
+ @returns the value of the given attribute or the given default */
+ int getIntAttribute (const QDomElement &element, const QString &name, int def, int debug_level);
+
/** returns the value of a boolean attribute ("true" or "false")
@param element the element whose attributes to search
Index: rkmenulist.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkmenulist.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rkmenulist.cpp 27 Aug 2004 10:17:35 -0000 1.1
--- rkmenulist.cpp 9 Sep 2005 13:02:57 -0000 1.2
***************
*** 31,34 ****
--- 31,39 ----
RKMenuList::~RKMenuList () {
RK_TRACE (MISC);
+ clear ();
+ }
+
+ void RKMenuList::clear () {
+ RK_TRACE (MISC);
for (MenuMap::iterator it = menu_map.begin (); it != menu_map.end (); ++it) {
delete it.data ();
- Previous message: [rkward-cvs] rkward/rkward/plugins Makefile.am,1.9,1.10 standard_plugins.pluginmap,1.1,1.2
- Next message: [rkward-cvs] rkward/rkward rkglobals.cpp,1.6,1.7 rkglobals.h,1.5,1.6 rkward.cpp,1.84,1.85 rkward.h,1.36,1.37
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the rkward-tracker
mailing list