Add generic DataPath::icon() method.

This commit is contained in:
Felix Geyer 2012-05-02 23:48:17 +02:00
parent 000be1e5be
commit 539ea5bd44
2 changed files with 16 additions and 5 deletions

View File

@ -29,18 +29,28 @@ QString DataPath::path(const QString& name)
QIcon DataPath::applicationIcon()
{
QIcon icon = QIcon::fromTheme("keepassx");
return icon("apps", "keepassx");
}
QIcon DataPath::icon(const QString& category, const QString& name)
{
QIcon icon = QIcon::fromTheme(name);
#if defined(QT_DEBUG) || defined(Q_WS_MAC) || defined(Q_WS_WIN)
if (icon.isNull()) {
QStringList pngSizes;
pngSizes << "16" << "24" << "32" << "48" << "64" << "128";
QString filename;
Q_FOREACH (const QString& size, pngSizes) {
icon.addFile(QString("%1/icons/application/%2x%2/apps/keepassx.png").arg(m_basePath, size));
filename = QString("%1/icons/application/%2x%2/%3/%4.png").arg(m_basePath, size, category, name);
if (QFile::exists(filename)) {
icon.addFile(filename);
}
}
filename = QString("%1/icons/application/scalable/%3/%4.svgz").arg(m_basePath, category, name);
if (QFile::exists(filename)) {
icon.addFile(filename);
}
icon.addFile(QString("%1/icons/application/scalable/apps/keepassx.svgz").arg(m_basePath));
}
#endif
return icon;
}

View File

@ -26,6 +26,7 @@ class DataPath
public:
QString path(const QString& name);
QIcon applicationIcon();
QIcon icon(const QString& category, const QString& name);
private:
DataPath();