Skip to content

Commit

Permalink
Improve docset icon search logic (fixes #251, #264)
Browse files Browse the repository at this point in the history
Decreases file I/O, since icons are kept in Docset now.
  • Loading branch information
trollixx committed Jan 30, 2015
1 parent dde2141 commit 04b5dee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/registry/docset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Docset::Docset(const QString &path) :

prefix = info.bundleName.isEmpty() ? m_name : info.bundleName;

findIcon();

m_isValid = true;
}

Expand Down Expand Up @@ -85,25 +87,33 @@ QString Docset::documentPath() const

QIcon Docset::icon() const
{
const QDir dir(documentPath());
return m_icon;
}

void Docset::findIcon()
{
m_icon = QIcon(QDir(m_path).absoluteFilePath(QStringLiteral("icon.png")));
if (!m_icon.availableSizes().isEmpty())
return;

QIcon icon(dir.absoluteFilePath("favicon.ico"));

if (icon.availableSizes().isEmpty())
icon = QIcon(dir.absoluteFilePath("icon.png"));
m_icon = QIcon(QDir(documentPath()).absoluteFilePath(QStringLiteral("favicon.ico")));
if (!m_icon.availableSizes().isEmpty())
return;

if (icon.availableSizes().isEmpty()) {
QString bundleName = info.bundleName;
bundleName.replace(" ", "_");
QString bundleName = info.bundleName;
bundleName.replace(" ", "_");
m_icon = QIcon(QString("icons:%1.png").arg(bundleName));
if (!m_icon.availableSizes().isEmpty())
return;

icon = QIcon(QString("icons:%1.png").arg(bundleName));
// Fallback to identifier and docset file name.
m_icon = QIcon(QString("icons:%1.png").arg(info.bundleIdentifier));
if (!m_icon.availableSizes().isEmpty())
return;

// Fallback to identifier and docset file name.
if (icon.availableSizes().isEmpty())
icon = QIcon(QString("icons:%1.png").arg(info.bundleIdentifier));
if (icon.availableSizes().isEmpty())
icon = QIcon(QString("icons:%1.png").arg(m_name));
}
return icon;
m_icon = QIcon(QString("icons:%1.png").arg(m_name));
if (!m_icon.availableSizes().isEmpty())
return;
}

3 changes: 3 additions & 0 deletions src/registry/docset.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ class Docset
DocsetInfo info;

private:
void findIcon();

bool m_isValid = false;

QString m_name;
QString m_path;
QIcon m_icon;
};

} // namespace Zeal
Expand Down

0 comments on commit 04b5dee

Please sign in to comment.