mirror of
https://github.com/zealdocs/zeal.git
synced 2024-12-02 09:44:14 +03:00
Refactor ZealDocsetInfo
This commit is contained in:
parent
e121f38b48
commit
bceff47fc6
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user