summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-01-19 17:23:23 +0100
committerSimon Rettberg2016-01-19 17:23:23 +0100
commit5177db6d63e48e7ff6ee9ffcef2dee9d77b80075 (patch)
tree2b45af855d00dac72f009d77390cd1a5d74d8e0e
parentFix filter logic (diff)
downloadvmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.tar.gz
vmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.tar.xz
vmchooser2-5177db6d63e48e7ff6ee9ffcef2dee9d77b80075.zip
Re-introduce tree structure: Allow server-defined sections
-rw-r--r--src/dialog.cpp1
-rw-r--r--src/session.h1
-rw-r--r--src/sessiontreemodel.cpp48
-rw-r--r--src/vsession.h7
-rw-r--r--src/xsession.h4
5 files changed, 46 insertions, 15 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index fdf3d78..1d497d2 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -481,6 +481,7 @@ void Dialog::setListModel(QAbstractItemModel *model) {
old = ui->treeView->model();
}
ui->treeView->setModel(model);
+ ui->treeView->expandAll();
if (old != NULL) {
old->deleteLater();
}
diff --git a/src/session.h b/src/session.h
index 515bd2d..8e41120 100644
--- a/src/session.h
+++ b/src/session.h
@@ -17,6 +17,7 @@ class Session {
virtual QIcon icon() const = 0;
virtual bool run() const = 0;
virtual int type() const = 0;
+ virtual QString section() const = 0;
virtual bool operator<(const Session& s) const = 0;
diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp
index cf4f2cf..69c7302 100644
--- a/src/sessiontreemodel.cpp
+++ b/src/sessiontreemodel.cpp
@@ -125,8 +125,27 @@ QModelIndex SessionTreeModel::parent(const QModelIndex &index) const {
}
void SessionTreeModel::addItems(const QList<Session*>& sessions) {
+ SessionTreeItem* parentItem;
+
foreach (Session* s, sessions) {
- root_->appendChild(new SessionTreeItem(s, root_));
+ bool sectionExists = false;
+ QString section(s->section());
+
+ for (int i = 0; i < root_->childCount(); ++i) {
+ SessionTreeItem* item = root_->child(i);
+ if (item->text() == section) {
+ parentItem = item;
+ sectionExists = true;
+ break;
+ }
+ }
+
+ if (!sectionExists) {
+ parentItem = new SessionTreeItem(section, root_);
+ root_->appendChild(parentItem);
+ }
+
+ parentItem->appendChild(new SessionTreeItem(s, parentItem));
}
}
@@ -143,32 +162,31 @@ void SessionTreeModel::removeItem(const QString& name) {
}
}
+static void lookDeeper(QList<Session*>& result, QList<QString>& items, SessionTreeItem* root) {
+ for (int i = 0; i < root->childCount(); ++i) {
+ SessionTreeItem* item = root->child(i);
+ if (item->session() != NULL && item->session()->containsKeywords(items)) {
+ result.append(const_cast<Session*>(item->session()));
+ }
+ lookDeeper(result, items, item);
+ }
+}
+
QList<Session*> SessionTreeModel::lookForItem(const QString& label) {
QList<Session*> result;
+ QList<QString> items;
if (label.startsWith("\"")) {
QString searchTerm = label;
searchTerm.remove(0, 1);
if (label.endsWith("\"")) {
searchTerm.chop(1);
}
- QList<QString> items;
items.append(searchTerm);
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->session() != NULL && item->session()->containsKeywords(items)) {
- result.append(const_cast<Session*>(item->session()));
- }
- }
} else {
- QList<QString> items = label.split(" ", QString::SkipEmptyParts);
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->session() != NULL && item->session()->containsKeywords(items)) {
- result.append(const_cast<Session*>(item->session()));
- }
- }
+ items = label.split(" ", QString::SkipEmptyParts);
}
+ lookDeeper(result, items, root_);
return result;
diff --git a/src/vsession.h b/src/vsession.h
index 22f3a94..34c7457 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -39,6 +39,13 @@ class VSession : public Session {
return getAttribute("os");
}
+ QString section() const {
+ QString attr = getAttribute("section");
+ if (!attr.isEmpty())
+ return attr;
+ return QObject::tr("Priority: ").append(QString::number(priority()));
+ }
+
QString getAttribute(const QString& nodeName,
const QString& attribute = "param") const;
QList<QString> keywords() const;
diff --git a/src/xsession.h b/src/xsession.h
index 75deffc..10b3b0b 100644
--- a/src/xsession.h
+++ b/src/xsession.h
@@ -19,6 +19,10 @@ class XSession : public Session {
bool isValid() const;
int priority() const;
+ QString section() const {
+ return QObject::tr("X-Sessions");
+ }
+
QString shortDescription() const {
return this->name_;
}