diff options
author | Jan Darmochwal | 2010-10-02 18:50:09 +0200 |
---|---|---|
committer | Jan Darmochwal | 2010-10-02 18:50:09 +0200 |
commit | 6117049617df720fb744a90773a3580b3450b005 (patch) | |
tree | c3b605ab7a7c2e9fd9d14572e8c0e69432d6ac76 /src/model.cpp | |
parent | fixed bad copy & paste in CMakeLists.txt (diff) | |
download | vmchooser-6117049617df720fb744a90773a3580b3450b005.tar.gz vmchooser-6117049617df720fb744a90773a3580b3450b005.tar.xz vmchooser-6117049617df720fb744a90773a3580b3450b005.zip |
Qt port is almost complete (at least it compiles)
Major change:
* struct DataEntry has become class Session with sub-classes XSession and VSession
* functions from addInfo.cpp, addPrinters.cpp, addScanners.cpp, readLinSess.cpp, readXmlDir.cpp, runImage.cpp have been moved to XSession and VSession
Several minor changes:
* new files globals.h and globals.cpp for global variables (replaces constants.h and paths.h)
* replaced (all) libxml2, (much) std:: and (most) boost:: stuff by Qt stuff
Things left to do:
* remove tons of debug printfs
* show error messages on errors
* tidy up anyoption stuff in main()
* highlight session run previously
* readGroupXml stuff
* tree view (with "X Sessions" and "Virtual Sessions" sections) instead of list view for session selection
Diffstat (limited to 'src/model.cpp')
-rw-r--r-- | src/model.cpp | 66 |
1 files changed, 15 insertions, 51 deletions
diff --git a/src/model.cpp b/src/model.cpp index 75bd58b..672f91e 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -2,11 +2,11 @@ #include <QIcon> #include <QPixmap> -Model::Model(std::vector<DataEntry> e, QObject *parent) +Model::Model(QList<Session*> e, QObject *parent) : QAbstractListModel(parent), - rc(e.size()), entries(e) + rowCount_(e.size()), entries_(e) { - printf("model with %d entries created\n", this->entries.size()); + printf("model with %d entries created\n", this->entries_.size()); } Model::~Model() @@ -15,7 +15,7 @@ Model::~Model() int Model::rowCount(const QModelIndex &parent) const { - return (parent.isValid() && parent.column() != 0) ? 0 : rc; + return (parent.isValid() && parent.column() != 0) ? 0 : rowCount_; } QVariant Model::data(const QModelIndex &index, int role) const @@ -24,59 +24,23 @@ QVariant Model::data(const QModelIndex &index, int role) const if (!index.isValid()) return QVariant(); if (role == Qt::DisplayRole) - return QString::fromStdString(this->entries.at(index.row()).short_description); + return this->entries_.at(index.row())->shortDescription(); if (role == Qt::ToolTipRole) - return QString::fromStdString(this->entries.at(index.row()).description); + return this->entries_.at(index.row())->description(); if (role == Qt::DecorationRole) { - // TODO: use additional function (with cache) for icons + // TODO: use cache for icons if (index.column() == 0) { - const DataEntry& e(this->entries.at(index.row())); + const Session* 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"); + QString icon(e->icon()); - 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"); + if (QFileInfo(icon).isAbsolute()) { + // try to load icon from file + return QIcon(icon); + } else { + // try to load icon from QResource + return QIcon(":" + icon.toLower()); } - - //return QIcon(":/img/linux.xpm"); - return iconProvider.icon(QFileIconProvider::File); } } return QVariant(); |