summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dialog.cpp12
-rw-r--r--src/session.h2
-rw-r--r--src/sessiontreemodel.cpp28
-rw-r--r--src/vsession.cpp18
-rw-r--r--src/vsession.h1
-rw-r--r--src/xsession.cpp4
-rw-r--r--src/xsession.h2
7 files changed, 60 insertions, 7 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index fc9a435..2a50c11 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -34,6 +34,7 @@ Dialog::Dialog(QWidget *parent)
activeTab = 0;
ui->tabButtonLocal->setChecked(true);
+ ui->filterEdit->setEnabled(false);
setListModel(model_[0]);
@@ -415,12 +416,15 @@ void Dialog::onTabButtonChanged(int tab) {
if (tab == 0) {
ui->tabButtonMyClasses->setChecked(false);
ui->tabButtonAllClasses->setChecked(false);
+ ui->filterEdit->setEnabled(false);
} else if (tab == 1) {
ui->tabButtonLocal->setChecked(false);
ui->tabButtonAllClasses->setChecked(false);
+ ui->filterEdit->setEnabled(true);
} else {
ui->tabButtonLocal->setChecked(false);
ui->tabButtonMyClasses->setChecked(false);
+ ui->filterEdit->setEnabled(true);
}
// load the new list
@@ -443,13 +447,15 @@ void Dialog::on_filterEdit_textChanged() {
}
setListModel(newModel);
+
+ // reconnect the treeModel
+ QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
+ this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
+
if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) {
ui->treeView->selectionModel()->clearSelection();
ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
}
- // reconnect the treeModel
- QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
- this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
}
void Dialog::setListModel(QAbstractItemModel *model) {
diff --git a/src/session.h b/src/session.h
index f3d4b4b..e1af027 100644
--- a/src/session.h
+++ b/src/session.h
@@ -22,5 +22,7 @@ class Session {
const static int XSESSION = 0;
const static int VSESSION = 1;
+ virtual bool containsKeywords(const QList<QString>& keywords) const = 0;
+
};
#endif /*VMCHOOSER_SESSION_H_*/
diff --git a/src/sessiontreemodel.cpp b/src/sessiontreemodel.cpp
index 2078aaa..722850e 100644
--- a/src/sessiontreemodel.cpp
+++ b/src/sessiontreemodel.cpp
@@ -172,13 +172,33 @@ void SessionTreeModel::removeItem(const QString& name) {
QList<Session*> SessionTreeModel::lookForItem(const QString& label) {
QList<Session*> result;
- for (int i = 0; i < root_->childCount(); ++i) {
- SessionTreeItem* item = root_->child(i);
- if (item->session()->shortDescription().contains(label, Qt::CaseInsensitive)) {
- result.append(const_cast<Session*>(item->session()));
+ 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()->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()->containsKeywords(items)) {
+ result.append(const_cast<Session*>(item->session()));
+ }
}
}
+
return result;
+
}
void SessionTreeModel::updateView() {
diff --git a/src/vsession.cpp b/src/vsession.cpp
index ba7a478..e8e301e 100644
--- a/src/vsession.cpp
+++ b/src/vsession.cpp
@@ -82,6 +82,24 @@ void VSession::readKeywords() {
}
}
+bool VSession::containsKeywords(const QList<QString>& keywords) const {
+ for (int j = 0; j < keywords.length(); ++j) {
+ bool keywordFlag = true;
+ if (!this->shortDescription().contains(keywords[j], Qt::CaseInsensitive)
+ && !this->description().contains(keywords[j], Qt::CaseInsensitive)
+ && !this->getAttribute("creator", "param").contains(keywords[j], Qt::CaseInsensitive)) {
+ keywordFlag = false;
+ for (int i = 0; i < this->keywords().length(); ++i) {
+ if (this->keywords()[i].contains(keywords[j], Qt::CaseInsensitive)) {
+ keywordFlag = true;
+ }
+ }
+ if (!keywordFlag) return false;
+ }
+ }
+ return true;
+}
+
QString VSession::getNodeText(const QString& nodeName) const {
return this->doc_.namedItem(nodeName).toText().data();
}
diff --git a/src/vsession.h b/src/vsession.h
index 50a51f7..9cb7a69 100644
--- a/src/vsession.h
+++ b/src/vsession.h
@@ -42,6 +42,7 @@ class VSession : public Session {
QString getAttribute(const QString& nodeName,
const QString& attribute = "param") const;
QList<QString> keywords() const;
+ bool containsKeywords(const QList<QString>& keywords) const;
QString getNodeText(const QString& nodeName) const;
void addNodeWithAttribute(const QString& nodeName,
diff --git a/src/xsession.cpp b/src/xsession.cpp
index f4cc3d9..3cd0e7e 100644
--- a/src/xsession.cpp
+++ b/src/xsession.cpp
@@ -147,3 +147,7 @@ bool XSession::operator<(const Session& other) const {
}
return false;
}
+
+bool XSession::containsKeywords(const QList<QString>&) const {
+ return true;
+}
diff --git a/src/xsession.h b/src/xsession.h
index 1d36d64..4140c38 100644
--- a/src/xsession.h
+++ b/src/xsession.h
@@ -37,6 +37,8 @@ class XSession : public Session {
static QList<Session*> readSessions(const QString& path);
+ bool containsKeywords(const QList<QString>& keywords) const;
+
private:
QString name_;
QString exec_;