From 7c5b0e7ee1bb48672d69deccd2288372de481e34 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 15 Sep 2015 18:00:35 +0200 Subject: Make default icon determination smarter --- src/sessiontreemodel.cpp | 58 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'src/sessiontreemodel.cpp') diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp index 2d151ed..775d8d0 100644 --- a/src/sessiontreemodel.cpp +++ b/src/sessiontreemodel.cpp @@ -57,32 +57,52 @@ QVariant SessionTreeModel::data(const QModelIndex &index, int role) const { if (index.column() == 0) { // TODO: is this line needed? QString icon(s->icon()); - // check if attribute is a valid url: - if (icon.startsWith("http://")) { - // try to load icon from url - QIcon url_icon = iconHolder->getIcon(QUrl(icon)); - if (!url_icon.isNull()) { - return url_icon; - } + if (icon.isEmpty()) { + // Nothing... + } else if (icon.startsWith("http://")) { + // try to load icon from url + QIcon url_icon = iconHolder->getIcon(QUrl(icon)); + if (!url_icon.isNull()) { + return url_icon; + } } else if (QFileInfo(icon).isAbsolute()) { // try to load icon from file return QIcon(icon); } else { // try to load icon from QResource - QIcon res_icon = iconHolder->getIcon(icon); - if (!res_icon.isNull()) { - return res_icon; - } + QIcon res_icon = iconHolder->getIcon(icon); + if (!res_icon.isNull()) { + return res_icon; + } } // fallback to os icon - if (s->type() == Session::VSESSION) { - const VSession* vs = (VSession*) s; - if (vs->getAttribute("os", "param").toLower().startsWith("win")) { - return iconHolder->getIcon("windows"); - } else { - return iconHolder->getIcon("linux"); - } - } + if (s->type() == Session::VSESSION) { + const VSession* vs = (VSession*) s; + QString os(vs->getAttribute("os", "param").toLower()); + if (!os.isEmpty()) { + QIcon osi = iconHolder->getIcon(os); + if (!osi.isNull()) + return osi; + if (os == "dos") + return iconHolder->getIcon("dos"); + if (os.startsWith("windows7")) + return iconHolder->getIcon("win7"); + if (os.startsWith("win31")) + return iconHolder->getIcon("win311"); + if (os.startsWith("debian")) + return iconHolder->getIcon("debian"); + if (os.startsWith("ubuntu")) + return iconHolder->getIcon("ubuntu"); + if (os.startsWith("win")) + return iconHolder->getIcon("windows"); + if (os.contains("linux")) + return iconHolder->getIcon("linux"); + } + if (vs->imgtype() == VMWARE) + return iconHolder->getIcon("vmware"); + if (vs->imgtype() == VBOX) + return iconHolder->getIcon("virtualbox"); + } } } } else if (role == Qt::DisplayRole) { -- cgit v1.2.3-55-g7522