2
* Copyright (c) 2000- Dawit Alemayehu <adawit@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
#include <qpushbutton.h>
20
#include <qwhatsthis.h>
23
#include <qvalidator.h>
25
#include <klineedit.h>
26
#include <kcombobox.h>
29
#include "policydlg.h"
30
#include "policydlg_ui.h"
33
class DomainLineValidator : public QValidator
36
DomainLineValidator(QObject *parent)
37
:QValidator(parent, "domainValidator")
41
State validate(QString &input, int &) const
43
if (input.isEmpty() || (input == "."))
46
int length = input.length();
48
for(int i = 0 ; i < length; i++)
50
if (!input[i].isLetterOrNumber() && input[i] != '.' && input[i] != '-')
59
PolicyDlg::PolicyDlg (const QString& caption, QWidget *parent,
61
: KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, true)
63
m_dlgUI = new PolicyDlgUI (this);
64
setMainWidget(m_dlgUI);
66
m_dlgUI->leDomain->setValidator(new DomainLineValidator(m_dlgUI->leDomain));
67
m_dlgUI->cbPolicy->setMinimumWidth( m_dlgUI->cbPolicy->fontMetrics().width('W') * 25 );
69
enableButtonOK( false );
70
connect(m_dlgUI->leDomain, SIGNAL(textChanged(const QString&)),
71
SLOT(slotTextChanged(const QString&)));
73
setFixedSize (sizeHint());
74
m_dlgUI->leDomain->setFocus ();
77
void PolicyDlg::setEnableHostEdit( bool state, const QString& host )
79
if ( !host.isEmpty() )
80
m_dlgUI->leDomain->setText( host );
81
m_dlgUI->leDomain->setEnabled( state );
84
void PolicyDlg::setPolicy (int policy)
86
if ( policy > -1 && policy <= static_cast<int>(m_dlgUI->cbPolicy->count()) )
87
m_dlgUI->cbPolicy->setCurrentItem(policy-1);
89
if ( !m_dlgUI->leDomain->isEnabled() )
90
m_dlgUI->cbPolicy->setFocus();
93
int PolicyDlg::advice () const
95
return m_dlgUI->cbPolicy->currentItem() + 1;
98
QString PolicyDlg::domain () const
100
return m_dlgUI->leDomain->text();
103
void PolicyDlg::slotTextChanged( const QString& text )
105
enableButtonOK( text.length() > 1 );
107
#include "policydlg.moc"