2 * Copyright (C) < 2002 to whoever created and edited this file before
3 * Copyright (C) 2002 Leo Savernik <l.savernik@aon.at>
4 * Generalizing the policy dialog
12 #include <QtGui/QLayout>
13 #include <QtGui/QLabel>
14 #include <QtGui/QComboBox>
15 #include <QtGui/QPushButton>
19 #include <kmessagebox.h>
24 PolicyDialog::PolicyDialog( Policies
*policies
, QWidget
*parent
, const char *name
)
28 setObjectName( name
);
30 setButtons( Ok
|Cancel
);
31 showButtonSeparator( true );
33 QFrame
*main
= new QFrame( this );
34 setMainWidget( main
);
36 insertIdx
= 1; // index where to insert additional panels
37 topl
= new QVBoxLayout(main
);
39 topl
->setSpacing(spacingHint());
41 QGridLayout
*grid
= new QGridLayout();
42 topl
->addLayout( grid
);
43 grid
->setColumnStretch(1, 1);
45 QLabel
*l
= new QLabel(i18n("&Host or domain name:"), main
);
46 grid
->addWidget(l
, 0, 0);
48 le_domain
= new QLineEdit(main
);
49 l
->setBuddy( le_domain
);
50 grid
->addWidget(le_domain
, 0, 1);
51 connect( le_domain
,SIGNAL(textChanged( const QString
& )),
52 SLOT(slotTextChanged( const QString
&)));
54 le_domain
->setWhatsThis( i18n("Enter the name of a host (like www.kde.org) "
55 "or a domain, starting with a dot (like .kde.org or .org)") );
57 l_feature_policy
= new QLabel(main
);
58 grid
->addWidget(l_feature_policy
, 1, 0);
60 cb_feature_policy
= new QComboBox(main
);
61 l_feature_policy
->setBuddy( cb_feature_policy
);
62 policy_values
<< i18n("Use Global") << i18n("Accept") << i18n("Reject");
63 cb_feature_policy
->addItems(policy_values
);
64 grid
->addWidget(cb_feature_policy
, 1, 1);
66 le_domain
->setFocus();
68 enableButtonOk(!le_domain
->text().isEmpty());
71 PolicyDialog::FeatureEnabledPolicy
PolicyDialog::featureEnabledPolicy() const {
72 return (FeatureEnabledPolicy
)cb_feature_policy
->currentIndex();
75 void PolicyDialog::slotTextChanged( const QString
&text
)
77 enableButtonOk(!text
.isEmpty());
80 void PolicyDialog::setDisableEdit( bool state
, const QString
& text
)
82 le_domain
->setText( text
);
84 le_domain
->setEnabled( state
);
87 cb_feature_policy
->setFocus();
90 void PolicyDialog::refresh() {
91 FeatureEnabledPolicy pol
;
93 if (policies
->isFeatureEnabledPolicyInherited())
95 else if (policies
->isFeatureEnabled())
99 cb_feature_policy
->setCurrentIndex(pol
);
102 void PolicyDialog::setFeatureEnabledLabel(const QString
&text
) {
103 l_feature_policy
->setText(text
);
106 void PolicyDialog::setFeatureEnabledWhatsThis(const QString
&text
) {
107 cb_feature_policy
->setWhatsThis(text
);
110 void PolicyDialog::addPolicyPanel(QWidget
*panel
) {
111 topl
->insertWidget(insertIdx
++,panel
);
114 QString
PolicyDialog::featureEnabledPolicyText() const {
115 int pol
= cb_feature_policy
->currentIndex();
116 if (pol
>= 0 && pol
< 3) // Keep in sync with FeatureEnabledPolicy
117 return policy_values
[pol
];
122 void PolicyDialog::accept()
124 if( le_domain
->text().isEmpty() )
126 KMessageBox::information( 0, i18n("You must first enter a domain name.") );
130 FeatureEnabledPolicy pol
= (FeatureEnabledPolicy
)
131 cb_feature_policy
->currentIndex();
132 if (pol
== InheritGlobal
) {
133 policies
->inheritFeatureEnabledPolicy();
134 } else if (pol
== Reject
) {
135 policies
->setFeatureEnabled(false);
137 policies
->setFeatureEnabled(true);
142 #include "policydlg.moc"