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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "policydlg.h"
23 #include <QtGui/QPushButton>
24 #include <QtGui/QWhatsThis>
25 #include <QtGui/QLayout>
26 #include <QtGui/QLabel>
27 #include <QtGui/QValidator>
30 #include <klineedit.h>
31 #include <kcombobox.h>
34 class DomainLineValidator
: public QValidator
37 DomainLineValidator(QObject
*parent
)
40 setObjectName("domainValidator");
43 State
validate(QString
&input
, int &) const
45 if (input
.isEmpty() || (input
== "."))
48 int length
= input
.length();
50 for(int i
= 0 ; i
< length
; i
++)
52 if (!input
[i
].isLetterOrNumber() && input
[i
] != '.' && input
[i
] != '-')
61 PolicyDlg::PolicyDlg (const QString
& caption
, QWidget
*parent
,
65 setObjectName( name
);
67 setCaption( caption
);
68 setButtons( Ok
|Cancel
);
69 showButtonSeparator( true );
71 m_dlgUI
= new PolicyDlgUI (this);
72 setMainWidget(m_dlgUI
);
74 m_dlgUI
->leDomain
->setValidator(new DomainLineValidator(m_dlgUI
->leDomain
));
75 m_dlgUI
->cbPolicy
->setMinimumWidth( m_dlgUI
->cbPolicy
->fontMetrics().maxWidth() * 25 );
77 enableButtonOk( false );
78 connect(m_dlgUI
->leDomain
, SIGNAL(textChanged(const QString
&)),
79 SLOT(slotTextChanged(const QString
&)));
81 setFixedSize (sizeHint());
82 m_dlgUI
->leDomain
->setFocus ();
85 void PolicyDlg::setEnableHostEdit( bool state
, const QString
& host
)
87 if ( !host
.isEmpty() )
88 m_dlgUI
->leDomain
->setText( host
);
89 m_dlgUI
->leDomain
->setEnabled( state
);
92 void PolicyDlg::setPolicy (int policy
)
94 if ( policy
> -1 && policy
<= static_cast<int>(m_dlgUI
->cbPolicy
->count()) )
95 m_dlgUI
->cbPolicy
->setCurrentIndex(policy
-1);
97 if ( !m_dlgUI
->leDomain
->isEnabled() )
98 m_dlgUI
->cbPolicy
->setFocus();
101 int PolicyDlg::advice () const
103 return m_dlgUI
->cbPolicy
->currentIndex() + 1;
106 QString
PolicyDlg::domain () const
108 return m_dlgUI
->leDomain
->text();
111 void PolicyDlg::slotTextChanged( const QString
& text
)
113 enableButtonOk( text
.length() > 1 );
115 #include "policydlg.moc"