From 2a91c3df1b86e881d0c0ac09d350404b3667b3c9 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Fri, 7 Sep 2012 22:57:25 +0200
Subject: Find <input> elements correctly after accepting MUC invites.

Resolves: #1129

License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php

diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 433ade4..efd00e4 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -365,18 +365,18 @@ void QtChatView::resetView() {
 	connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
 }
 
-QWebElement findDivElementWithID(QWebElement document, QString id) {
-	QWebElementCollection divs = document.findAll("div");
-	foreach(QWebElement div, divs) {
-		if (div.attribute("id") == id) {
-			return div;
+QWebElement findElementWithID(QWebElement document, QString elementName, QString id) {
+	QWebElementCollection elements = document.findAll(elementName);
+	foreach(QWebElement element, elements) {
+		if (element.attribute("id") == id) {
+			return element;
 		}
 	}
 	return QWebElement();
 }
 
 void QtChatView::setFileTransferProgress(QString id, const int percentageDone) {
-	QWebElement ftElement = findDivElementWithID(document_, id);
+	QWebElement ftElement = findElementWithID(document_, "div", id);
 	if (ftElement.isNull()) {
 		SWIFT_LOG(debug) << "Tried to access FT UI via invalid id!" << std::endl;
 		return;
@@ -389,7 +389,7 @@ void QtChatView::setFileTransferProgress(QString id, const int percentageDone) {
 }
 
 void QtChatView::setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /* msg */) {
-	QWebElement ftElement = findDivElementWithID(document_, id);
+	QWebElement ftElement = findElementWithID(document_, "div", id);
 	if (ftElement.isNull()) {
 		SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
 		return;
@@ -445,8 +445,8 @@ void QtChatView::setWhiteboardSessionStatus(QString id, const ChatWindow::Whiteb
 }
 
 void QtChatView::setMUCInvitationJoined(QString id) {
-	QWebElement divElement = findDivElementWithID(document_, id);
-	QWebElement buttonElement = divElement.findFirst("input#mucinvite");
+	QWebElement divElement = findElementWithID(document_, "div", id);
+	QWebElement buttonElement = findElementWithID(divElement, "input", "mucinvite");
 	if (!buttonElement.isNull()) {
 		buttonElement.setAttribute("value", tr("Return to room"));
 	}
-- 
cgit v0.10.2-6-g49f6