From 280c0256db2378c9f33775b270f211660e5bf868 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Fri, 14 Mar 2014 14:50:24 +0100 Subject: - Added IconHolder to cache items - Added FileDownloader for icon downloads --- src/sessiontreemodel.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/sessiontreemodel.cpp') diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp index d0fc79e..9bc13f6 100644 --- a/src/sessiontreemodel.cpp +++ b/src/sessiontreemodel.cpp @@ -8,10 +8,12 @@ #include "sessiontreeitem.h" #include "vsession.h" +#include "sessionsiconholder.h" SessionTreeModel::SessionTreeModel(QObject *parent) : QAbstractItemModel(parent) { root_ = new SessionTreeItem("dummy"); + iconHolder = new SessionsIconHolder(); } SessionTreeModel::~SessionTreeModel() { @@ -52,35 +54,35 @@ QVariant SessionTreeModel::data(const QModelIndex &index, int role) const { if (role == Qt::ToolTipRole) return s->description(); if (role == Qt::DecorationRole) { - // TODO: use cache for icons if (index.column() == 0) { // TODO: is this line needed? QString icon(s->icon()); if (QFileInfo(icon).isAbsolute()) { // try to load icon from file - QFile iconFile(icon); - if (iconFile.exists()) { - return QIcon(icon); + QIcon file_icon = iconHolder->getIconFromFile(icon); + if (!file_icon.name().isEmpty()) { + return file_icon; + } + + // try to load icon from url + QIcon url_icon = iconHolder->getIconFromURL(icon); + if (!url_icon.name().isEmpty()) { + return url_icon; } // fallback to os icon if (s->type() == Session::VSESSION) { const VSession* vs = (VSession*) s; if (vs->getAttribute("os", "param").toLower().startsWith("win")) { - return QIcon(":windows"); + return iconHolder->getIconFromResource("windows"); } else { - return QIcon(":linux"); + return iconHolder->getIconFromResource("linux"); } } } else { // try to load icon from QResource - if (QResource(":" + icon.toLower() + ".svg").isValid()) { - return QIcon(":" + icon.toLower() + ".svg"); - } else if (QResource(":" + icon.toLower()).isValid()) { - return QIcon(":" + icon.toLower()); - } else { - return QIcon(":none"); - } + qDebug() << icon; + return iconHolder->getIconFromResource(icon); } } } -- cgit v1.2.3-55-g7522