diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.cpp | 45 | ||||
-rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.h | 15 |
2 files changed, 39 insertions, 21 deletions
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp index a6bce65..ef397f4 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.cpp +++ b/Swift/QtUI/QtAdHocCommandWindow.cpp @@ -1,20 +1,24 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file 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> +#include <Swift/QtUI/QtFormWidget.h> +#include <Swift/QtUI/QtSwiftUtil.h> + const int FormLayoutIndex = 1; namespace Swift { QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) { formWidget_ = NULL; @@ -33,28 +37,31 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman 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); + dialogButtons_ = new QDialogButtonBox(this); + layout_->addWidget(dialogButtons_); - QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget); - cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget); - buttonsLayout->addWidget(cancelButton_); + dialogButtons_->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); + okButton_ = dialogButtons_->button(QDialogButtonBox::Ok); + connect(okButton_, SIGNAL(clicked()), this, SLOT(close())); + cancelButton_ = dialogButtons_->button(QDialogButtonBox::Cancel); connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); - backButton_ = new QPushButton(tr("Back"), buttonsWidget); - buttonsLayout->addWidget(backButton_); - connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); - nextButton_ = new QPushButton(tr("Next"), buttonsWidget); - buttonsLayout->addWidget(nextButton_); - connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); - completeButton_ = new QPushButton(tr("Complete"), buttonsWidget); - buttonsLayout->addWidget(completeButton_); + // Buttons appear next to the Ok button, right of Cancel with YesRole + completeButton_ = dialogButtons_->addButton(tr("Complete"), QDialogButtonBox::YesRole); connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); + nextButton_ = dialogButtons_->addButton(tr("Next"), QDialogButtonBox::YesRole); + connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); + backButton_ = dialogButtons_->addButton(tr("Back"), QDialogButtonBox::YesRole); + connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); + + okButton_->setEnabled(false); + okButton_->hide(); + nextButton_->setEnabled(false); backButton_->setEnabled(false); completeButton_->setEnabled(false); actions_[Command::Next] = nextButton_; actions_[Command::Prev] = backButton_; @@ -140,15 +147,19 @@ void QtAdHocCommandWindow::setNoForm(bool andHide) { setVisible(!andHide); } typedef std::pair<Command::Action, QPushButton*> ActionButton; void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { + okButton_->show(); + okButton_->setEnabled(true); foreach (ActionButton pair, actions_) { OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); if (state & OutgoingAdHocCommandSession::Present) { + okButton_->hide(); + okButton_->setEnabled(false); pair.second->show(); } else { pair.second->hide(); } if (state & OutgoingAdHocCommandSession::Enabled) { diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h index 231a51c..c8d493c 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.h +++ b/Swift/QtUI/QtAdHocCommandWindow.h @@ -1,51 +1,58 @@ /* - * Copyright (c) 2010-2012 Isode Limited. + * Copyright (c) 2010-2015 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <QWidget> -#include <QPushButton> +#include <QDialogButtonBox> #include <QLabel> +#include <QPushButton> +#include <QWidget> -#include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> +#include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> + class QBoxLayout; namespace Swift { class QtFormWidget; class QtAdHocCommandWindow : public QWidget, public AdHocCommandWindow { Q_OBJECT public: QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); virtual ~QtAdHocCommandWindow(); virtual void setOnline(bool online); + private: void closeEvent(QCloseEvent* event); void handleNextStageReceived(Command::ref command); void handleError(ErrorPayload::ref error); void setForm(Form::ref); void setNoForm(bool andHide); void setAvailableActions(Command::ref commandResult); + private slots: void handleCancelClicked(); void handlePrevClicked(); void handleNextClicked(); void handleCompleteClicked(); + private: boost::shared_ptr<OutgoingAdHocCommandSession> command_; QtFormWidget* formWidget_; Form::ref form_; QLabel* label_; QLabel* errorLabel_; QPushButton* backButton_; QPushButton* nextButton_; QPushButton* completeButton_; QPushButton* cancelButton_; + QPushButton* okButton_; std::map<Command::Action, QPushButton*> actions_; + QDialogButtonBox* dialogButtons_; QBoxLayout* layout_; }; } |