20 #include "locationdialog.h"
21 #include "cupsdconf.h"
23 #include "addressdialog.h"
25 #include <tqlineedit.h>
26 #include <tqcombobox.h>
29 #include <tqpushbutton.h>
30 #include <tqwhatsthis.h>
32 #include <tdelocale.h>
33 #include <kiconloader.h>
35 LocationDialog::LocationDialog(TQWidget *parent,
const char *name)
36 : KDialogBase(parent, name, true, TQString::null, Ok|Cancel, Ok, true)
38 TQWidget *dummy =
new TQWidget(
this);
40 resource_ =
new TQComboBox(dummy);
41 authtype_ =
new TQComboBox(dummy);
42 authclass_ =
new TQComboBox(dummy);
43 authname_ =
new TQLineEdit(dummy);
44 encryption_ =
new TQComboBox(dummy);
45 satisfy_ =
new TQComboBox(dummy);
46 order_ =
new TQComboBox(dummy);
47 addresses_ =
new EditList(dummy);
49 authtype_->insertItem(i18n(
"None"));
50 authtype_->insertItem(i18n(
"Basic"));
51 authtype_->insertItem(i18n(
"Digest"));
53 authclass_->insertItem(i18n(
"None"));
54 authclass_->insertItem(i18n(
"User"));
55 authclass_->insertItem(i18n(
"System"));
56 authclass_->insertItem(i18n(
"Group"));
58 encryption_->insertItem(i18n(
"Always"));
59 encryption_->insertItem(i18n(
"Never"));
60 encryption_->insertItem(i18n(
"Required"));
61 encryption_->insertItem(i18n(
"If Requested"));
63 satisfy_->insertItem(i18n(
"All"));
64 satisfy_->insertItem(i18n(
"Any"));
66 order_->insertItem(i18n(
"Allow, Deny"));
67 order_->insertItem(i18n(
"Deny, Allow"));
69 connect(authclass_, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotClassChanged(
int)));
70 connect(authtype_, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotTypeChanged(
int)));
72 TQLabel *l1 =
new TQLabel(i18n(
"Resource:"), dummy);
73 TQLabel *l2 =
new TQLabel(i18n(
"Authentication:"), dummy);
74 TQLabel *l3 =
new TQLabel(i18n(
"Class:"), dummy);
75 TQLabel *l4 =
new TQLabel(i18n(
"Names:"), dummy);
76 TQLabel *l5 =
new TQLabel(i18n(
"Encryption:"), dummy);
77 TQLabel *l6 =
new TQLabel(i18n(
"Satisfy:"), dummy);
78 TQLabel *l7 =
new TQLabel(i18n(
"ACL order:"), dummy);
79 TQLabel *l8 =
new TQLabel(i18n(
"ACL addresses:"),dummy);
81 TQGridLayout *m1 =
new TQGridLayout(dummy, 8, 2, 0, 5);
82 m1->setColStretch(1, 1);
83 m1->addWidget(l1, 0, 0, TQt::AlignRight);
84 m1->addWidget(l2, 1, 0, TQt::AlignRight);
85 m1->addWidget(l3, 2, 0, TQt::AlignRight);
86 m1->addWidget(l4, 3, 0, TQt::AlignRight);
87 m1->addWidget(l5, 4, 0, TQt::AlignRight);
88 m1->addWidget(l6, 5, 0, TQt::AlignRight);
89 m1->addWidget(l7, 6, 0, TQt::AlignRight);
90 m1->addWidget(l8, 7, 0, TQt::AlignRight|TQt::AlignTop);
91 m1->addWidget(resource_, 0, 1);
92 m1->addWidget(authtype_, 1, 1);
93 m1->addWidget(authclass_, 2, 1);
94 m1->addWidget(authname_, 3, 1);
95 m1->addWidget(encryption_, 4, 1);
96 m1->addWidget(satisfy_, 5, 1);
97 m1->addWidget(order_, 6, 1);
98 m1->addWidget(addresses_, 7, 1);
100 setCaption(i18n(
"Location"));
103 slotTypeChanged(AUTHTYPE_NONE);
104 slotClassChanged(AUTHCLASS_ANONYMOUS);
105 encryption_->setCurrentItem(ENCRYPT_IFREQUESTED);
107 connect(addresses_, TQ_SIGNAL(add()), TQ_SLOT(slotAdd()));
108 connect(addresses_, TQ_SIGNAL(edit(
int)), TQ_SLOT(slotEdit(
int)));
109 connect(addresses_, TQ_SIGNAL(defaultList()), TQ_SLOT(slotDefaultList()));
112 void LocationDialog::setInfos(CupsdConf *conf)
116 TQPtrListIterator<CupsResource> it(conf->resources_);
117 for (; it.current(); ++it)
118 resource_->insertItem(SmallIcon(it.current()->typeToIconName(it.current()->type_)), it.current()->text_);
120 TQWhatsThis::add(encryption_, conf_->comments_.toolTip(
"encryption"));
121 TQWhatsThis::add(order_, conf_->comments_.toolTip(
"order"));
122 TQWhatsThis::add(authclass_, conf_->comments_.toolTip(
"authclass"));
123 TQWhatsThis::add(authtype_, conf_->comments_.toolTip(
"authtype"));
124 TQWhatsThis::add(authname_, conf_->comments_.toolTip(
"authname"));
125 TQWhatsThis::add(satisfy_, conf_->comments_.toolTip(
"satisfy"));
126 TQWhatsThis::add(addresses_, conf_->comments_.toolTip(
"allowdeny"));
129 void LocationDialog::fillLocation(CupsLocation *loc)
131 loc->resource_ = conf_->resources_.at(resource_->currentItem());
132 loc->resourcename_ = loc->resource_->path_;
133 loc->authtype_ = authtype_->currentItem();
134 loc->authclass_ = (loc->authtype_ == AUTHTYPE_NONE ? AUTHCLASS_ANONYMOUS : authclass_->currentItem());
135 loc->authname_ = (loc->authclass_ == AUTHCLASS_USER || loc->authclass_ == AUTHCLASS_GROUP ? authname_->text() : TQString::null);
136 loc->encryption_ = encryption_->currentItem();
137 loc->satisfy_ = satisfy_->currentItem();
138 loc->order_ = order_->currentItem();
139 loc->addresses_ = addresses_->items();
142 void LocationDialog::setLocation(CupsLocation *loc)
144 int index = conf_->resources_.findRef(loc->resource_);
145 resource_->setCurrentItem(index);
146 authtype_->setCurrentItem(loc->authtype_);
147 authclass_->setCurrentItem(loc->authclass_);
148 authname_->setText(loc->authname_);
149 encryption_->setCurrentItem(loc->encryption_);
150 satisfy_->setCurrentItem(loc->satisfy_);
151 order_->setCurrentItem(loc->order_);
152 addresses_->insertItems(loc->addresses_);
154 slotTypeChanged(loc->authtype_);
155 slotClassChanged(loc->authclass_);
158 void LocationDialog::slotTypeChanged(
int index)
160 authclass_->setEnabled(index != AUTHTYPE_NONE);
161 if (index != AUTHTYPE_NONE)
162 slotClassChanged(authclass_->currentItem());
164 authname_->setEnabled(
false);
167 void LocationDialog::slotClassChanged(
int index)
169 authname_->setEnabled((index == AUTHCLASS_USER || index == AUTHCLASS_GROUP));
172 bool LocationDialog::newLocation(CupsLocation *loc, TQWidget *parent, CupsdConf *conf)
174 LocationDialog dlg(parent);
179 dlg.fillLocation(loc);
186 bool LocationDialog::editLocation(CupsLocation *loc, TQWidget *parent, CupsdConf *conf)
188 LocationDialog dlg(parent);
191 dlg.setLocation(loc);
192 dlg.resource_->setEnabled(
false);
195 dlg.fillLocation(loc);
202 void LocationDialog::slotAdd()
204 TQString addr = AddressDialog::newAddress(
this);
206 addresses_->insertItem(addr);
209 void LocationDialog::slotEdit(
int index)
211 TQString addr = addresses_->text(index);
212 addr = AddressDialog::editAddress(addr,
this);
214 addresses_->insertItem(addr);
217 void LocationDialog::slotDefaultList()
222 #include "locationdialog.moc"