Refactor ZealDocsetInfo

This commit is contained in:
Oleg Shparber 2014-11-15 23:26:00 -08:00
parent e121f38b48
commit bceff47fc6
2 changed files with 13 additions and 22 deletions

View File

@ -1,46 +1,40 @@
#include "zealdocsetinfo.h"
#include <QDomDocument>
ZealDocsetInfo::ZealDocsetInfo()
: ZealDocsetInfo("")
{
}
#include <QFile>
ZealDocsetInfo::ZealDocsetInfo(const QString filePath)
: indexPath(""), family(""), keyword("")
{
if (QFile(filePath).exists()) {
if (QFile(filePath).exists())
readDocset(filePath);
}
}
bool ZealDocsetInfo::readDocset(const QString filePath)
{
QFile file(filePath);
QDomDocument infoplist("infoplist");
if (!file.open(QIODevice::ReadOnly)) {
if (!file.open(QIODevice::ReadOnly))
return false;
}
if (!infoplist.setContent(&file)) {
file.close();
return false;
}
auto keys = infoplist.elementsByTagName("key");
for(int i = 0; i < keys.count(); ++i) {
for (int i = 0; i < keys.count(); ++i) {
auto key = keys.at(i);
if (key.firstChild().nodeValue() == "dashIndexFilePath") {
if (key.firstChild().nodeValue() == "dashIndexFilePath")
indexPath = key.nextSibling().firstChild().nodeValue();
} else if (key.firstChild().nodeValue() == "DashDocSetKeyword") {
else if (key.firstChild().nodeValue() == "DashDocSetKeyword")
keyword = key.nextSibling().firstChild().nodeValue();
} else if (key.firstChild().nodeValue() == "DashDocSetFamily") {
else if (key.firstChild().nodeValue() == "DashDocSetFamily")
family = key.nextSibling().firstChild().nodeValue();
} else if (key.firstChild().nodeValue() == "CFBundleName") {
else if (key.firstChild().nodeValue() == "CFBundleName")
bundleName = key.nextSibling().firstChild().nodeValue();
} else if (key.firstChild().nodeValue() == "CFBundleIdentifier") {
else if (key.firstChild().nodeValue() == "CFBundleIdentifier")
bundleIdentifier = key.nextSibling().firstChild().nodeValue();
}
}
return true;
}

View File

@ -1,14 +1,11 @@
#ifndef ZEALDOCSETINFO_H
#define ZEALDOCSETINFO_H
#include "stdlib.h"
#include <QFile>
#include <QString>
struct ZealDocsetInfo
{
public:
ZealDocsetInfo();
ZealDocsetInfo(const QString filePath);
explicit ZealDocsetInfo(const QString filePath = QString());
bool readDocset(const QString filePath);
QString indexPath;