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 "kcookiespolicyselectiondlg.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 DomainNameValidator : public QValidator
37
DomainNameValidator (QObject* parent)
40
setObjectName(QLatin1String("domainValidator"));
43
State validate (QString& input, int&) const
45
if (input.isEmpty() || (input == ".")) {
49
const int length = input.length();
51
for (int i = 0 ; i < length; i++) {
52
if (!input[i].isLetterOrNumber() && input[i] != '.' && input[i] != '-') {
62
KCookiesPolicySelectionDlg::KCookiesPolicySelectionDlg (QWidget* parent, Qt::WindowFlags flags)
63
: KDialog (parent, flags)
65
mUi.setupUi(mainWidget());
66
mUi.leDomain->setValidator(new DomainNameValidator (mUi.leDomain));
67
mUi.cbPolicy->setMinimumWidth(mUi.cbPolicy->fontMetrics().maxWidth() * 15);
69
enableButtonOk(false);
70
connect(mUi.leDomain, SIGNAL(textEdited(QString)),
71
SLOT(slotTextChanged(QString)));
72
connect(mUi.cbPolicy, SIGNAL(currentIndexChanged(QString)),
73
SLOT(slotTextChanged(QString)));
75
mUi.leDomain->setFocus();
78
void KCookiesPolicySelectionDlg::setEnableHostEdit (bool state, const QString& host)
81
mUi.leDomain->setText (host);
83
mUi.leDomain->setEnabled (state);
86
void KCookiesPolicySelectionDlg::setPolicy (int policy)
88
if (policy > -1 && policy <= static_cast<int> (mUi.cbPolicy->count())) {
89
const bool blocked = mUi.cbPolicy->blockSignals(true);
90
mUi.cbPolicy->setCurrentIndex (policy - 1);
91
mUi.cbPolicy->blockSignals(blocked);
94
if (!mUi.leDomain->isEnabled())
95
mUi.cbPolicy->setFocus();
98
int KCookiesPolicySelectionDlg::advice () const
100
return mUi.cbPolicy->currentIndex() + 1;
103
QString KCookiesPolicySelectionDlg::domain () const
105
return mUi.leDomain->text();
108
void KCookiesPolicySelectionDlg::slotTextChanged (const QString& text)
110
enableButtonOk (text.length() > 1);
113
#include "kcookiespolicyselectiondlg.moc"