~ubuntu-branches/ubuntu/warty/kdebase/warty

« back to all changes in this revision

Viewing changes to kcontrol/kio/policydlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-16 04:51:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040916045145-9vr63kith3k1cpza
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
17
 */
 
18
 
 
19
#include <qpushbutton.h>
 
20
#include <qwhatsthis.h>
 
21
#include <qlayout.h>
 
22
#include <qlabel.h>
 
23
#include <qvalidator.h>
 
24
 
 
25
#include <klineedit.h>
 
26
#include <kcombobox.h>
 
27
#include <klocale.h>
 
28
 
 
29
#include "policydlg.h"
 
30
#include "policydlg_ui.h"
 
31
 
 
32
 
 
33
class DomainLineValidator : public QValidator
 
34
{
 
35
public:
 
36
  DomainLineValidator(QObject *parent)
 
37
  :QValidator(parent, "domainValidator")
 
38
  {
 
39
  }
 
40
 
 
41
  State validate(QString &input, int &) const
 
42
  {
 
43
    if (input.isEmpty() || (input == "."))
 
44
      return Intermediate;
 
45
 
 
46
    int length = input.length();
 
47
 
 
48
    for(int i = 0 ; i < length; i++)
 
49
    {
 
50
      if (!input[i].isLetterOrNumber() && input[i] != '.' && input[i] != '-')
 
51
        return Invalid;
 
52
    }
 
53
 
 
54
    return Acceptable;
 
55
  }
 
56
};
 
57
 
 
58
 
 
59
PolicyDlg::PolicyDlg (const QString& caption, QWidget *parent,
 
60
    const char *name)
 
61
    : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, true)
 
62
{
 
63
  m_dlgUI = new PolicyDlgUI (this);
 
64
  setMainWidget(m_dlgUI);
 
65
 
 
66
  m_dlgUI->leDomain->setValidator(new DomainLineValidator(m_dlgUI->leDomain));
 
67
  m_dlgUI->cbPolicy->setMinimumWidth( m_dlgUI->cbPolicy->fontMetrics().width('W') * 25 );
 
68
  
 
69
  enableButtonOK( false );
 
70
  connect(m_dlgUI->leDomain, SIGNAL(textChanged(const QString&)),
 
71
    SLOT(slotTextChanged(const QString&)));
 
72
 
 
73
  setFixedSize (sizeHint());
 
74
  m_dlgUI->leDomain->setFocus ();
 
75
}
 
76
 
 
77
void PolicyDlg::setEnableHostEdit( bool state, const QString& host )
 
78
{
 
79
  if ( !host.isEmpty() )
 
80
    m_dlgUI->leDomain->setText( host );
 
81
  m_dlgUI->leDomain->setEnabled( state );
 
82
}
 
83
 
 
84
void PolicyDlg::setPolicy (int policy)
 
85
{
 
86
  if ( policy > -1 && policy <= static_cast<int>(m_dlgUI->cbPolicy->count()) )
 
87
    m_dlgUI->cbPolicy->setCurrentItem(policy-1);
 
88
 
 
89
  if ( !m_dlgUI->leDomain->isEnabled() )
 
90
    m_dlgUI->cbPolicy->setFocus();
 
91
}
 
92
 
 
93
int PolicyDlg::advice () const
 
94
{
 
95
  return m_dlgUI->cbPolicy->currentItem() + 1;
 
96
}
 
97
 
 
98
QString PolicyDlg::domain () const
 
99
{
 
100
  return m_dlgUI->leDomain->text();
 
101
}
 
102
 
 
103
void PolicyDlg::slotTextChanged( const QString& text )
 
104
{
 
105
  enableButtonOK( text.length() > 1 );
 
106
}
 
107
#include "policydlg.moc"