summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtAdHocCommandWindow.cpp')
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index 88aa708..5f99dba 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -1,13 +1,14 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include <Swift/QtUI/QtAdHocCommandWindow.h>
-
#include <boost/bind.hpp>
#include <QBoxLayout>
+#include <Swift/QtUI/QtAdHocCommandWindow.h>
#include <Swift/QtUI/QtFormWidget.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/Base/format.h>
#include <Swiften/Elements/Command.h>
@@ -16,5 +17,4 @@ const int FormLayoutIndex = 1;
namespace Swift {
QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) {
- someActions_ = false;
formWidget_ = NULL;
@@ -30,4 +30,11 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
label_->setTextFormat(Qt::PlainText);
layout_->addWidget(label_);
+
+ errorLabel_ = new QLabel(this);
+ errorLabel_->setText(QString("<b>%1</b>").arg(tr("Unable to complete the command because you have been disconnected")));
+ errorLabel_->setVisible(false);
+ errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken);
+ layout_->addWidget(errorLabel_);
+
QWidget* buttonsWidget = new QWidget(this);
layout_->addWidget(buttonsWidget);
@@ -49,4 +56,5 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
backButton_->setEnabled(false);
completeButton_->setEnabled(false);
+
actions_[Command::Next] = nextButton_;
actions_[Command::Prev] = backButton_;
@@ -56,5 +64,17 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
QtAdHocCommandWindow::~QtAdHocCommandWindow() {
+}
+
+void QtAdHocCommandWindow::setOnline(bool online) {
+ if (!online) {
+ nextButton_->setEnabled(false);
+ backButton_->setEnabled(false);
+ completeButton_->setEnabled(false);
+ errorLabel_->setVisible(true);
+ }
+}
+void QtAdHocCommandWindow::closeEvent(QCloseEvent*) {
+ onClosing();
}
@@ -77,14 +97,10 @@ void QtAdHocCommandWindow::handleCompleteClicked() {
void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
- if (command->getForm()) {
- setForm(command->getForm());
- } else {
- setNoForm();
- }
QString notes;
foreach (Command::Note note, command->getNotes()) {
if (!notes.isEmpty()) {
notes += "\n";
- QString qNote(note.note.c_str());
+ }
+ QString qNote(P2QSTRING(note.note));
switch (note.type) {
case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break;
@@ -93,6 +109,10 @@ void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
}
}
- }
label_->setText(notes);
+ if (command->getForm()) {
+ setForm(command->getForm());
+ } else {
+ setNoForm(notes.isEmpty());
+ }
setAvailableActions(command);
}
@@ -106,15 +126,17 @@ void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) {
void QtAdHocCommandWindow::setForm(Form::ref form) {
+ form_ = form;
delete formWidget_;
formWidget_ = new QtFormWidget(form, this);
layout_->insertWidget(FormLayoutIndex, formWidget_);
show();
- formWidget_->setEditable(someActions_);
}
-void QtAdHocCommandWindow::setNoForm() {
+void QtAdHocCommandWindow::setNoForm(bool andHide) {
+ form_.reset();
delete formWidget_;
formWidget_ = NULL;
- show();
+ resize(minimumSize());
+ setVisible(!andHide);
}
@@ -122,5 +144,4 @@ typedef std::pair<Command::Action, QPushButton*> ActionButton;
void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
- someActions_ = false;
foreach (ActionButton pair, actions_) {
OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
@@ -133,5 +154,4 @@ void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
if (state & OutgoingAdHocCommandSession::Enabled) {
pair.second->setEnabled(true);
- someActions_ = true;
}
else {
@@ -139,7 +159,4 @@ void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
}
}
- if (formWidget_) {
- formWidget_->setEditable(someActions_);
- }
}