From 4a1f206b0f8d4926b3a61cc8d7aad217761e52f6 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Thu, 26 Apr 2012 16:39:33 +0100
Subject: Size AdHoc dialogs by the first form received.

Resolves: #954

diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index f8a3cd6..b148560 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2012 Kevin Smith
  * Licensed under the GNU General Public License v3.
  * See Documentation/Licenses/GPLv3.txt for more information.
  */
@@ -11,6 +11,8 @@
 #include <Swift/QtUI/QtFormWidget.h>
 #include <Swiften/Elements/Command.h>
 
+const int FormLayoutIndex = 1;
+
 namespace Swift {
 QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) {
 
@@ -21,17 +23,14 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
 	command->onError.connect(boost::bind(&QtAdHocCommandWindow::handleError, this, _1));
 	command->start();
 
-	QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
-	layout->setContentsMargins(0,0,0,0);
-	layout->setSpacing(2);
+	layout_ = new QBoxLayout(QBoxLayout::TopToBottom, this);
+	layout_->setContentsMargins(0,0,0,0);
+	layout_->setSpacing(2);
 	label_ = new QLabel(this);
 	label_->setTextFormat(Qt::PlainText);
-	layout->addWidget(label_);
-	QWidget* formContainer = new QWidget(this);
-	layout->addWidget(formContainer);
-	formLayout_ = new QBoxLayout(QBoxLayout::TopToBottom, formContainer);
+	layout_->addWidget(label_);
 	QWidget* buttonsWidget = new QWidget(this);
-	layout->addWidget(buttonsWidget);
+	layout_->addWidget(buttonsWidget);
 
 	QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget);
 	cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget);
@@ -53,7 +52,6 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
 	actions_[Command::Prev] = backButton_;
 	actions_[Command::Complete] = completeButton_;
 	actions_[Command::Cancel] = cancelButton_;
-	show();
 }
 
 QtAdHocCommandWindow::~QtAdHocCommandWindow() {
@@ -109,11 +107,13 @@ void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) {
 void QtAdHocCommandWindow::setForm(Form::ref form) {
 	delete formWidget_;
 	formWidget_ = new QtFormWidget(form, this);
-	formLayout_->addWidget(formWidget_);
+	layout_->insertWidget(FormLayoutIndex, formWidget_);
+	show();
 }
 
 void QtAdHocCommandWindow::setNoForm() {
 	delete formWidget_;
+	show();
 }
 
 typedef std::pair<Command::Action, QPushButton*> ActionButton;
diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h
index adeb3e6..42e3b1c 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.h
+++ b/Swift/QtUI/QtAdHocCommandWindow.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2012 Kevin Smith
  * Licensed under the GNU General Public License v3.
  * See Documentation/Licenses/GPLv3.txt for more information.
  */
@@ -36,7 +36,6 @@ namespace Swift {
 		private:
 			boost::shared_ptr<OutgoingAdHocCommandSession> command_;
 			QtFormWidget* formWidget_;
-			QBoxLayout* formLayout_;
 			Form::ref form_;
 			QLabel* label_;
 			QPushButton* backButton_;
@@ -44,5 +43,6 @@ namespace Swift {
 			QPushButton* completeButton_;
 			QPushButton* cancelButton_;
 			std::map<Command::Action, QPushButton*> actions_;
+			QBoxLayout* layout_;
 	};
 }
-- 
cgit v0.10.2-6-g49f6