~ubuntu-branches/debian/sid/kde-baseapps/sid

« back to all changes in this revision

Viewing changes to konqueror/settings/kio/kcookiespolicyselectiondlg.cpp

  • Committer: Package Import Robot
  • Author(s): Modestas Vainius, Eshat Cakar, Pino Toscano
  • Date: 2012-06-09 22:18:08 UTC
  • mfrom: (4.2.1) (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20120609221808-h1l0ekd5qmb8nefr
Tags: 4:4.8.4-1
* New upstream release.

[ Eshat Cakar ]
* Add watch file.
* Bump kde-sc-dev-latest build dependency to version 4:4.8.4.
* Update installed files.

[ Pino Toscano ]
* Move files of the konqueror documentation from kde-baseapps-data to
  konqueror itself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright (c) 2000- Dawit Alemayehu <adawit@kde.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
// Own
 
20
#include "kcookiespolicyselectiondlg.h"
 
21
 
 
22
// Qt
 
23
#include <QtGui/QPushButton>
 
24
#include <QtGui/QWhatsThis>
 
25
#include <QtGui/QLayout>
 
26
#include <QtGui/QLabel>
 
27
#include <QtGui/QValidator>
 
28
 
 
29
// KDE
 
30
#include <klineedit.h>
 
31
#include <kcombobox.h>
 
32
#include <klocale.h>
 
33
 
 
34
class DomainNameValidator : public QValidator
 
35
{
 
36
public:
 
37
    DomainNameValidator (QObject* parent)
 
38
        :QValidator(parent)
 
39
    {
 
40
        setObjectName(QLatin1String("domainValidator"));
 
41
    }
 
42
 
 
43
    State validate (QString& input, int&) const
 
44
    {
 
45
        if (input.isEmpty() || (input == ".")) {
 
46
            return Intermediate;
 
47
        }
 
48
 
 
49
        const int length = input.length();
 
50
 
 
51
        for (int i = 0 ; i < length; i++) {
 
52
            if (!input[i].isLetterOrNumber() && input[i] != '.' && input[i] != '-') {
 
53
                return Invalid;
 
54
            }
 
55
        }
 
56
 
 
57
        return Acceptable;
 
58
    }
 
59
};
 
60
 
 
61
 
 
62
KCookiesPolicySelectionDlg::KCookiesPolicySelectionDlg (QWidget* parent, Qt::WindowFlags flags)
 
63
    : KDialog (parent, flags)
 
64
{
 
65
    mUi.setupUi(mainWidget());
 
66
    mUi.leDomain->setValidator(new DomainNameValidator (mUi.leDomain));
 
67
    mUi.cbPolicy->setMinimumWidth(mUi.cbPolicy->fontMetrics().maxWidth() * 15);
 
68
 
 
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)));
 
74
 
 
75
    mUi.leDomain->setFocus();
 
76
}
 
77
 
 
78
void KCookiesPolicySelectionDlg::setEnableHostEdit (bool state, const QString& host)
 
79
{
 
80
    if (!host.isEmpty())
 
81
        mUi.leDomain->setText (host);
 
82
 
 
83
    mUi.leDomain->setEnabled (state);
 
84
}
 
85
 
 
86
void KCookiesPolicySelectionDlg::setPolicy (int policy)
 
87
{
 
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);
 
92
    }
 
93
 
 
94
    if (!mUi.leDomain->isEnabled())
 
95
        mUi.cbPolicy->setFocus();
 
96
}
 
97
 
 
98
int KCookiesPolicySelectionDlg::advice () const
 
99
{
 
100
    return mUi.cbPolicy->currentIndex() + 1;
 
101
}
 
102
 
 
103
QString KCookiesPolicySelectionDlg::domain () const
 
104
{
 
105
    return mUi.leDomain->text();
 
106
}
 
107
 
 
108
void KCookiesPolicySelectionDlg::slotTextChanged (const QString& text)
 
109
{
 
110
    enableButtonOk (text.length() > 1);
 
111
}
 
112
 
 
113
#include "kcookiespolicyselectiondlg.moc"