diff options
Diffstat (limited to 'vmchooser2/model.cpp')
-rw-r--r-- | vmchooser2/model.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/vmchooser2/model.cpp b/vmchooser2/model.cpp new file mode 100644 index 0000000..75bd58b --- /dev/null +++ b/vmchooser2/model.cpp @@ -0,0 +1,83 @@ +#include "model.h" +#include <QIcon> +#include <QPixmap> + +Model::Model(std::vector<DataEntry> e, QObject *parent) + : QAbstractListModel(parent), + rc(e.size()), entries(e) +{ + printf("model with %d entries created\n", this->entries.size()); +} + +Model::~Model() +{ +} + +int Model::rowCount(const QModelIndex &parent) const +{ + return (parent.isValid() && parent.column() != 0) ? 0 : rc; +} + +QVariant Model::data(const QModelIndex &index, int role) const +{ + printf("request for model row %d role %d\n", index.row(), role); + if (!index.isValid()) + return QVariant(); + if (role == Qt::DisplayRole) + return QString::fromStdString(this->entries.at(index.row()).short_description); + if (role == Qt::ToolTipRole) + return QString::fromStdString(this->entries.at(index.row()).description); + if (role == Qt::DecorationRole) { + // TODO: use additional function (with cache) for icons + if (index.column() == 0) { + const DataEntry& e(this->entries.at(index.row())); + + if(e.imgtype == VMWARE) { + if(e.os.find("win") != string::npos || e.os.find("Win") != string::npos) + return QIcon(e.locked ? ":xp_locked" : ":xp"); + + if(e.icon.find("gentoo") != string::npos || e.icon.find("Gentoo") != string::npos ) + return QIcon(":gentoo"); + + if(e.icon.find("suse") != string::npos || e.icon.find("Suse") != string::npos ) + return QIcon(":suse"); + + if(e.icon.find("ubuntu") != string::npos || e.icon.find("Ubuntu") != string::npos ) + return QIcon(":ubuntu"); + + + if(e.os.find("linux") != string::npos) + return QIcon(":linux"); + + if(e.icon.find("bsd") != string::npos + || e.icon.find("BSD") != string::npos + || e.icon.find("Bsd") != string::npos) + return QIcon(":bsd"); + + if(e.icon.find("mac") != string::npos + || e.icon.find("Mac") != string::npos + || e.icon.find("apple") != string::npos) + return QIcon(":macos"); + + return QIcon(":vmware"); + } + + if(e.imgtype == LINUX) { + if(e.short_description.find("KDE")!= string::npos) + return QIcon(":kde"); + + if(e.short_description.find("GNOME")!= string::npos) + return QIcon(":gnome"); + + if(e.short_description.find("Xfce")!= string::npos) + return QIcon(":xfce"); + + return QIcon(":linux"); + } + + //return QIcon(":/img/linux.xpm"); + return iconProvider.icon(QFileIconProvider::File); + } + } + return QVariant(); +} |