diff --git a/data/Quirks.xml b/data/Quirks.xml
new file mode 100644
index 0000000..2884fe6
--- /dev/null
+++ b/data/Quirks.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Blahblah
+
+
diff --git a/devicedb-lib/devicedb.cpp b/devicedb-lib/devicedb.cpp
index c41e29e..9934077 100644
--- a/devicedb-lib/devicedb.cpp
+++ b/devicedb-lib/devicedb.cpp
@@ -17,7 +17,7 @@
#include
#include "devicedb.hpp"
-
+#include "devicequirks.h"
#include "ui_devicedb.h"
DeviceDB::DeviceDB(QWidget *parent) :
@@ -27,6 +27,7 @@ DeviceDB::DeviceDB(QWidget *parent) :
m_Path("config/")
{
ui->setupUi(this);
+ qDebug() << DeviceQuirks::GetInstance().isReady();
this->ui->saveBtn->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
this->ui->saveBtn->button(QDialogButtonBox::Save)->setEnabled(false);
deviceTree = new DeviceDBXMLReader(this);
diff --git a/devicedb-lib/devicequirks.cpp b/devicedb-lib/devicequirks.cpp
index dd36d52..bec4a24 100644
--- a/devicedb-lib/devicequirks.cpp
+++ b/devicedb-lib/devicequirks.cpp
@@ -1,6 +1,118 @@
#include "devicequirks.h"
+#include
+#include
+#include
+#include
+
+
+bool parseNumberList(QString str, QList &list) {
+ size_t pos = 0;
+ size_t start = 0;
+ bool parsing = true;
+ while( parsing )
+ {
+ std::string ccStr;
+
+ pos = str.toStdString().find_first_of( ",", start );
+ if( std::string::npos == pos )
+ {
+ ccStr = str.toStdString().substr( start );
+ parsing = false;
+ }
+ else
+ {
+ ccStr = str.toStdString().substr( start, pos-start );
+ start = pos + 1;
+ }
+ QString result = QString::fromStdString(ccStr);
+ list.push_back(result.toInt());
+ }
+ return true;
+}
DeviceQuirks::DeviceQuirks(QObject *parent) : QObject(parent)
{
+ QString errorStr;
+ int errorLine;
+ int errorColumn;
+ qDebug() << QDir(".").absolutePath();
+ QFile mfxml("Quirks.xml");
+ if (!mfxml.open(QFile::ReadOnly | QFile::Text)) {
+ QMessageBox::warning(nullptr, tr("QXmlStream Quirks"),
+ tr("Cannot read file %1:\n%2.")
+ .arg(mfxml.fileName())
+ .arg(mfxml.errorString()));
+ this->setReady(false);
+ return;
+ }
+ if (!domDocument.setContent(&mfxml, false,&errorStr, &errorLine, &errorColumn)) {
+ QMessageBox::information(nullptr, tr("Quirks Database"), tr("Parse Error at line %1, column %2:\n%3")
+ .arg(errorLine)
+ .arg(errorColumn)
+ .arg(errorStr));
+ return;
+ }
+
+ QDomElement root = domDocument.documentElement();
+ if (root.tagName() != "QuirkData") {
+ QMessageBox::information(nullptr, tr("Quirks Database"),
+ tr("The file is not an Quirk file."));
+ return;
+ }
+
+ QDomElement child = root.firstChildElement("Quirk");
+ while (!child.isNull()) {
+ QString name = child.attribute("name");
+ QuirksEntry *entry = new QuirksEntry();
+ if (child.hasAttribute("CommandClass"))
+ parseNumberList(child.attribute("CommandClass"), entry->CommandClasses);
+ if (child.hasChildNodes()) {
+ QDomNode options = child.firstChild();
+ while (!options.isNull()) {
+ if (options.nodeName().toUpper() == "OPTION")
+ entry->options.push_back(options.toElement().attribute("name"));
+ else if (options.nodeName().toUpper() == "HELP")
+ entry->Help = options.firstChild().toText().data();
+ options = options.nextSibling();
+ }
+ }
+ this->m_quirks.insert(name, entry);
+ child = child.nextSiblingElement();
+ }
+
+ mfxml.close();
+ this->setReady(true);
+ this->dump();
}
+
+DeviceQuirks &DeviceQuirks::GetInstance() {
+ static DeviceQuirks instance;
+ return instance;
+}
+
+void DeviceQuirks::setReady(bool ready) {
+ this->m_Ready = ready;
+}
+bool DeviceQuirks::isReady() const {
+ return this->m_Ready;
+}
+
+void DeviceQuirks::dump() {
+ QHash::iterator it;
+ for (it = this->m_quirks.begin(); it != this->m_quirks.end(); ++it) {
+ qDebug() << it.key();
+ qDebug() << "\tOptions:";
+ for (int i = 0; i < it.value()->options.count(); ++i)
+ qDebug() << "\t\t" << it.value()->options.at(i);
+ qDebug() << "\tCommandClasses:";
+ for (int i = 0; i < it.value()->CommandClasses.count(); ++i)
+ qDebug() << "\t\t" << it.value()->CommandClasses.at(i);
+ qDebug() << "\tHelp:";
+ qDebug() << "\t\t" << it.value()->Help;
+ }
+}
+
+
+
+
diff --git a/devicedb-lib/devicequirks.h b/devicedb-lib/devicequirks.h
index da8c4df..7ae1df2 100644
--- a/devicedb-lib/devicequirks.h
+++ b/devicedb-lib/devicequirks.h
@@ -2,16 +2,33 @@
#define DEVICEQUIRKS_H
#include
+#include
+#include
class DeviceQuirks : public QObject
{
Q_OBJECT
public:
- explicit DeviceQuirks(QObject *parent = 0);
+ static DeviceQuirks &GetInstance();
+ bool isReady() const;
+ void dump();
+private:
+ struct QuirksEntry {
+ QList options;
+ QList CommandClasses;
+ QString Help;
+ };
+ explicit DeviceQuirks(QObject *parent = 0);
+ void setReady(bool ready);
signals:
public slots:
+
+private:
+ QDomDocument domDocument;
+ bool m_Ready;
+ QHash m_quirks;
};
-#endif // DEVICEQUIRKS_H
\ No newline at end of file
+#endif // DEVICEQUIRKS_H
diff --git a/ozwadmin-main/mainwindow.ui b/ozwadmin-main/mainwindow.ui
index 0fb65e9..c6fa062 100644
--- a/ozwadmin-main/mainwindow.ui
+++ b/ozwadmin-main/mainwindow.ui
@@ -44,8 +44,8 @@
0
0
- 605
- 516
+ 573
+ 468
@@ -289,8 +289,8 @@
0
0
- 605
- 461
+ 573
+ 428
@@ -610,8 +610,8 @@
0
0
- 618
- 303
+ 588
+ 276
@@ -625,8 +625,8 @@
0
0
- 600
- 217
+ 564
+ 184
@@ -643,8 +643,8 @@
0
0
- 600
- 183
+ 102
+ 102
@@ -679,8 +679,8 @@
0
0
- 618
- 303
+ 588
+ 276
@@ -717,8 +717,8 @@
0
0
- 618
- 303
+ 588
+ 276
@@ -757,7 +757,7 @@
0
0
660
- 28
+ 22