From e04a688f1beedf9ea0627f8b98dfd4528c925c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20P=C3=A5lsson?= Date: Mon, 3 Mar 2014 16:18:05 +0100 Subject: Improved input history --- browser/browserview.h | 9 +++++++-- browser/userinput.cpp | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/browser/browserview.h b/browser/browserview.h index 509d762..17e0fde 100644 --- a/browser/browserview.h +++ b/browser/browserview.h @@ -42,6 +42,10 @@ public slots: emit onScroll ((uint)x,(uint)y); } void setCurrentFocus (const QWebElement &elem) { + // Check whether this element was already selected + if (elem == m_elem) + return; + if (elem.tagName().compare("INPUT", Qt::CaseInsensitive) == 0){ emit onInputText (elem.attribute("name"), elem.attribute("value"), elem.attribute("type", "0").toInt(), @@ -69,8 +73,9 @@ public slots: qDebug() << "Options:" << options.size(); emit onSelect(elem.attribute("name", ""), options, true); } + m_elem = elem; } - const QWebElement *currentFocus () { return m_elem; } + const QWebElement currentFocus () { return m_elem; } signals: void onInputText(QString name, QString value, int type, int maxlength, @@ -79,7 +84,7 @@ signals: void onSelect(const QString &, const conn::brw::SelectableOptionList &, bool); private: - QWebElement *m_elem; + QWebElement m_elem; }; class BrowserView : public QGraphicsView diff --git a/browser/userinput.cpp b/browser/userinput.cpp index 978a9a1..33f8f0d 100644 --- a/browser/userinput.cpp +++ b/browser/userinput.cpp @@ -26,14 +26,29 @@ conn::brw::ERROR_IDS userinput::inputText(conn::brw::DIALOG_RESULT a_eResult, co emit setOutputWebview(message().path()); - if(a_eResult == conn::brw::DR_OK) - emit inputText(a_strInputValue); + if(a_eResult == conn::brw::DR_OK) { + emit inputText(a_strInputValue); + + struct inputStruct is; + is.name = m_currentInput.name; + is.type = m_currentInput.type; + is.value = a_strInputValue; + bool shouldAdd = true; + + for (int i = 0; i < m_inputHistory->size(); i++) { + if (m_inputHistory->at(i).value.compare(is.value) == 0 && + m_inputHistory->at(i).type == is.type && + m_inputHistory->at(i).name == is.name) { + shouldAdd = false; + break; + } + } + + qDebug() << "Should add " << is.value << "?" << shouldAdd; - struct inputStruct is; - is.name = m_currentInput.name; - is.type = m_currentInput.type; - is.value = a_strInputValue; - m_inputHistory->append(is); + if (shouldAdd) + m_inputHistory->append(is); + } return conn::brw::EID_NO_ERROR; } @@ -89,10 +104,13 @@ conn::brw::ERROR_IDS userinput::getPrevEnteredValues (const QString &a_strInputN { Q_UNUSED(a_strInputValue); for (int i = 0; i < m_inputHistory->size(); i++){ - struct inputStruct s = m_inputHistory->at(0); + struct inputStruct s = m_inputHistory->at(i); qDebug() << s.value; - if (s.type == a_i32InputType && - s.name.compare(a_strInputName) == 0) { + if (s.type == a_i32InputType && + s.name.compare(a_strInputName) == 0 && + s.value.contains(a_strInputValue, + Qt::CaseInsensitive)) + { a_oInputVariants.append(s.value); } } -- cgit v1.2.1