You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cconnectiondialog.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /***************************************************************************
  2. * Copyright (C) 2008 by Oliver Groß *
  3. * z.o.gross@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include "cconnectiondialog.h"
  21. #include <QDialogButtonBox>
  22. #include <QLabel>
  23. #include <QLineEdit>
  24. #include <QSpinBox>
  25. #include <QFormLayout>
  26. #include <QVBoxLayout>
  27. #include <QMessageBox>
  28. namespace qftrans {
  29. CConnectionDialog::CConnectionDialog(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f) {
  30. setupUi();
  31. }
  32. CConnectionDialog::~CConnectionDialog() {
  33. }
  34. bool CConnectionDialog::execute(bool isServer) {
  35. m_HostEdit->setEnabled(!isServer);
  36. m_HostLabel->setEnabled(!isServer);
  37. if (m_HostEdit->text().isEmpty())
  38. m_HostEdit->setText("localhost");
  39. return exec();
  40. }
  41. QString CConnectionDialog::host() { return m_HostEdit->text(); }
  42. quint16 CConnectionDialog::port() { return (quint16)m_PortEdit->value(); }
  43. inline void CConnectionDialog::setupUi() {
  44. m_HostEdit = new QLineEdit(this);
  45. m_HostLabel = new QLabel(tr("&Host"), this);
  46. m_HostLabel->setBuddy(m_HostEdit);
  47. m_PortEdit = new QSpinBox(this);
  48. m_PortEdit->setMinimum(0);
  49. m_PortEdit->setMaximum(65535);
  50. m_PortEdit->setValue(8899);
  51. m_PortLabel = new QLabel(tr("&Port"), this);
  52. m_PortLabel->setBuddy(m_PortLabel);
  53. QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
  54. QFormLayout * formLayout = new QFormLayout();
  55. formLayout->addRow(m_HostLabel, m_HostEdit);
  56. formLayout->addRow(m_PortLabel, m_PortEdit);
  57. QVBoxLayout * mainLayout = new QVBoxLayout();
  58. mainLayout->addLayout(formLayout);
  59. mainLayout->addWidget(buttonBox);
  60. setLayout(mainLayout);
  61. connect(buttonBox, SIGNAL(accepted()), this, SLOT(checkHost()));
  62. connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  63. }
  64. void CConnectionDialog::checkHost() {
  65. if (m_HostEdit->isEnabled()) {
  66. if (m_HostEdit->text().isEmpty())
  67. QMessageBox::warning(this, tr("Invalid host"), tr("You have to specify a host name/address."));
  68. else
  69. accept();
  70. }
  71. else
  72. accept();
  73. }
  74. }