88 lines
3.2 KiB
C++
88 lines
3.2 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2008 by Oliver Groß *
|
|
* z.o.gross@gmx.de *
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include "cconnectiondialog.h"
|
|
#include <QDialogButtonBox>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QSpinBox>
|
|
#include <QFormLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QMessageBox>
|
|
|
|
namespace qftrans {
|
|
CConnectionDialog::CConnectionDialog(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f) {
|
|
setupUi();
|
|
}
|
|
|
|
CConnectionDialog::~CConnectionDialog() {
|
|
}
|
|
|
|
bool CConnectionDialog::execute(bool isServer) {
|
|
m_HostEdit->setEnabled(!isServer);
|
|
m_HostLabel->setEnabled(!isServer);
|
|
|
|
if (m_HostEdit->text().isEmpty())
|
|
m_HostEdit->setText("localhost");
|
|
return exec();
|
|
}
|
|
|
|
QString CConnectionDialog::host() { return m_HostEdit->text(); }
|
|
quint16 CConnectionDialog::port() { return (quint16)m_PortEdit->value(); }
|
|
|
|
inline void CConnectionDialog::setupUi() {
|
|
m_HostEdit = new QLineEdit(this);
|
|
m_HostLabel = new QLabel(tr("&Host"), this);
|
|
m_HostLabel->setBuddy(m_HostEdit);
|
|
|
|
m_PortEdit = new QSpinBox(this);
|
|
m_PortEdit->setMinimum(0);
|
|
m_PortEdit->setMaximum(65535);
|
|
m_PortEdit->setValue(8899);
|
|
m_PortLabel = new QLabel(tr("&Port"), this);
|
|
m_PortLabel->setBuddy(m_PortLabel);
|
|
|
|
QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
|
|
|
|
QFormLayout * formLayout = new QFormLayout();
|
|
formLayout->addRow(m_HostLabel, m_HostEdit);
|
|
formLayout->addRow(m_PortLabel, m_PortEdit);
|
|
|
|
QVBoxLayout * mainLayout = new QVBoxLayout();
|
|
mainLayout->addLayout(formLayout);
|
|
mainLayout->addWidget(buttonBox);
|
|
|
|
setLayout(mainLayout);
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(checkHost()));
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
}
|
|
|
|
void CConnectionDialog::checkHost() {
|
|
if (m_HostEdit->isEnabled()) {
|
|
if (m_HostEdit->text().isEmpty())
|
|
QMessageBox::warning(this, tr("Invalid host"), tr("You have to specify a host name/address."));
|
|
else
|
|
accept();
|
|
}
|
|
else
|
|
accept();
|
|
}
|
|
}
|