Initial Commit. The packaging still does not work properly.
[confmgr] / xmlutil.h
diff --git a/xmlutil.h b/xmlutil.h
new file mode 100644 (file)
index 0000000..f51518e
--- /dev/null
+++ b/xmlutil.h
@@ -0,0 +1,79 @@
+#ifndef XMLUTIL_H\r
+#define XMLUTIL_H\r
+\r
+#include <QObject>\r
+#include <QtXml/QDomElement>\r
+#include "profile.h"\r
+\r
+#define NO_OF_PROFILE_ATTR "NoOfProfiles"\r
+#define PROFILE_TAG "Profiles"\r
+#define PROFILE_ELEM_TAG "Profile"\r
+#define NAME_ATTR "Name"\r
+#define NO_OF_STEPS_ATTR "NoOfSteps"\r
+#define STEP_TAG "Step"\r
+#define VALUE_ATTR "Value"\r
+#define DELAY_ATTR "Delay"\r
+\r
+class Xmlutil : public QObject\r
+{\r
+    Q_OBJECT\r
+public:\r
+    explicit Xmlutil(QObject *parent = 0);\r
+\r
+    static QDomElement addElement(QDomDocument &doc, QDomNode &node,\r
+                           const QString &tag,\r
+                           const QString &value = QString::null);\r
+\r
+    static QString generateProfileXML(const Profile &profile, int *error = 0,\r
+                                      QDomDocument *doc = 0, QDomElement *elem = 0);\r
+    // returns non-zero on error\r
+    static int degenerateProfileXML(const QString xmlString, Profile &profile,\r
+                                    QDomElement *pElem = 0);\r
+\r
+//    QDomElement removeElement\r
+signals:\r
+\r
+public slots:\r
+\r
+};\r
+\r
+/*\r
+    QDomDocument doc("mydocument");\r
+    QFile file(argv[1]);\r
+    if (!file.open(QIODevice::ReadOnly))\r
+        return -1;\r
+    if (!doc.setContent(&file)) {\r
+        file.close();\r
+        return -1;\r
+    }\r
+    file.close();\r
+\r
+// print out the element names of all elements that are direct children\r
+// of the outermost element.\r
+    QDomElement docElem = doc.namedItem("Profiles").toElement();\r
+    qDebug() << "Main Tag: " << docElem.attribute("NoOfProfiles") << endl;\r
+\r
+    QDomNode n = docElem.firstChild();\r
+    while(!n.isNull()) {\r
+        QDomElement e = n.toElement(); // try to convert the node to an element.\r
+        if(!e.isNull()) {\r
+            qDebug() << "Name" << qPrintable(e.tagName()) << e.attribute("Name") << endl; // the node really is an element.\r
+            qDebug() << "NoOfSteps" << qPrintable(e.tagName()) << e.attribute("NoOfSteps") << endl; // the node really is an element.\r
+        }\r
+        QDomNode node = n.firstChild();\r
+        for(int i = 0; i < e.attribute("NoOfSteps").toInt(); i++)\r
+        {\r
+            QDomElement elem = node.toElement();\r
+            if(!elem.isNull())\r
+            {\r
+                qDebug() << "Value" << qPrintable(elem.tagName()) << elem.attribute("Value") << endl; // the node really is an element.\r
+                qDebug() << "Delay" << qPrintable(elem.tagName()) << elem.attribute("Delay") << endl; // the node really is an element.\r
+            }\r
+            node = node.nextSibling();\r
+        }\r
+        n = n.nextSibling();\r
+    }\r
+\r
+ */\r
+\r
+#endif // XMLUTIL_H\r