00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "locationdialog.h"
00021
#include "cupsdconf.h"
00022
#include "editlist.h"
00023
#include "addressdialog.h"
00024
00025
#include <qlineedit.h>
00026
#include <qcombobox.h>
00027
#include <qlayout.h>
00028
#include <qlabel.h>
00029
#include <qpushbutton.h>
00030
#include <qwhatsthis.h>
00031
00032
#include <klocale.h>
00033
#include <kiconloader.h>
00034
00035 LocationDialog::LocationDialog(
QWidget *parent,
const char *name)
00036 : KDialogBase(parent, name, true,
QString::null, Ok|Cancel, Ok, true)
00037 {
00038
QWidget *dummy =
new QWidget(
this);
00039 setMainWidget(dummy);
00040 resource_ =
new QComboBox(dummy);
00041 authtype_ =
new QComboBox(dummy);
00042 authclass_ =
new QComboBox(dummy);
00043 authname_ =
new QLineEdit(dummy);
00044 encryption_ =
new QComboBox(dummy);
00045 satisfy_ =
new QComboBox(dummy);
00046 order_ =
new QComboBox(dummy);
00047 addresses_ =
new EditList(dummy);
00048
00049 authtype_->insertItem(i18n(
"None"));
00050 authtype_->insertItem(i18n(
"Basic"));
00051 authtype_->insertItem(i18n(
"Digest"));
00052
00053 authclass_->insertItem(i18n(
"None"));
00054 authclass_->insertItem(i18n(
"User"));
00055 authclass_->insertItem(i18n(
"System"));
00056 authclass_->insertItem(i18n(
"Group"));
00057
00058 encryption_->insertItem(i18n(
"Always"));
00059 encryption_->insertItem(i18n(
"Never"));
00060 encryption_->insertItem(i18n(
"Required"));
00061 encryption_->insertItem(i18n(
"If Requested"));
00062
00063 satisfy_->insertItem(i18n(
"All"));
00064 satisfy_->insertItem(i18n(
"Any"));
00065
00066 order_->insertItem(i18n(
"Allow, Deny"));
00067 order_->insertItem(i18n(
"Deny, Allow"));
00068
00069 connect(authclass_, SIGNAL(activated(
int)), SLOT(slotClassChanged(
int)));
00070 connect(authtype_, SIGNAL(activated(
int)), SLOT(slotTypeChanged(
int)));
00071
00072
QLabel *l1 =
new QLabel(i18n(
"Resource:"), dummy);
00073
QLabel *l2 =
new QLabel(i18n(
"Authentication:"), dummy);
00074
QLabel *l3 =
new QLabel(i18n(
"Class:"), dummy);
00075
QLabel *l4 =
new QLabel(i18n(
"Names:"), dummy);
00076
QLabel *l5 =
new QLabel(i18n(
"Encryption:"), dummy);
00077
QLabel *l6 =
new QLabel(i18n(
"Satisfy:"), dummy);
00078
QLabel *l7 =
new QLabel(i18n(
"ACL order:"), dummy);
00079
QLabel *l8 =
new QLabel(i18n(
"ACL addresses:"),dummy);
00080
00081
QGridLayout *m1 =
new QGridLayout(dummy, 8, 2, 0, 5);
00082 m1->
setColStretch(1, 1);
00083 m1->
addWidget(l1, 0, 0, Qt::AlignRight);
00084 m1->
addWidget(l2, 1, 0, Qt::AlignRight);
00085 m1->
addWidget(l3, 2, 0, Qt::AlignRight);
00086 m1->
addWidget(l4, 3, 0, Qt::AlignRight);
00087 m1->
addWidget(l5, 4, 0, Qt::AlignRight);
00088 m1->
addWidget(l6, 5, 0, Qt::AlignRight);
00089 m1->
addWidget(l7, 6, 0, Qt::AlignRight);
00090 m1->
addWidget(l8, 7, 0, Qt::AlignRight|Qt::AlignTop);
00091 m1->
addWidget(resource_, 0, 1);
00092 m1->
addWidget(authtype_, 1, 1);
00093 m1->
addWidget(authclass_, 2, 1);
00094 m1->
addWidget(authname_, 3, 1);
00095 m1->
addWidget(encryption_, 4, 1);
00096 m1->
addWidget(satisfy_, 5, 1);
00097 m1->
addWidget(order_, 6, 1);
00098 m1->
addWidget(addresses_, 7, 1);
00099
00100 setCaption(i18n(
"Location"));
00101 resize(400, 100);
00102
00103 slotTypeChanged(AUTHTYPE_NONE);
00104 slotClassChanged(AUTHCLASS_ANONYMOUS);
00105 encryption_->setCurrentItem(ENCRYPT_IFREQUESTED);
00106
00107 connect(addresses_, SIGNAL(add()), SLOT(slotAdd()));
00108 connect(addresses_, SIGNAL(edit(
int)), SLOT(slotEdit(
int)));
00109 connect(addresses_, SIGNAL(defaultList()), SLOT(slotDefaultList()));
00110 }
00111
00112
void LocationDialog::setInfos(CupsdConf *conf)
00113 {
00114 conf_ = conf;
00115
00116
QPtrListIterator<CupsResource> it(conf->resources_);
00117
for (; it.current(); ++it)
00118 resource_->insertItem(SmallIcon(it.current()->typeToIconName(it.current()->type_)), it.current()->text_);
00119
00120
QWhatsThis::add(encryption_, conf_->comments_.toolTip(
"encryption"));
00121
QWhatsThis::add(order_, conf_->comments_.toolTip(
"order"));
00122
QWhatsThis::add(authclass_, conf_->comments_.toolTip(
"authclass"));
00123
QWhatsThis::add(authtype_, conf_->comments_.toolTip(
"authtype"));
00124
QWhatsThis::add(authname_, conf_->comments_.toolTip(
"authname"));
00125
QWhatsThis::add(satisfy_, conf_->comments_.toolTip(
"satisfy"));
00126
QWhatsThis::add(addresses_, conf_->comments_.toolTip(
"allowdeny"));
00127 }
00128
00129
void LocationDialog::fillLocation(CupsLocation *loc)
00130 {
00131 loc->resource_ = conf_->resources_.at(resource_->currentItem());
00132 loc->resourcename_ = loc->resource_->path_;
00133 loc->authtype_ = authtype_->currentItem();
00134 loc->authclass_ = (loc->authtype_ == AUTHTYPE_NONE ? AUTHCLASS_ANONYMOUS : authclass_->currentItem());
00135 loc->authname_ = (loc->authclass_ == AUTHCLASS_USER || loc->authclass_ == AUTHCLASS_GROUP ? authname_->text() :
QString::null);
00136 loc->encryption_ = encryption_->currentItem();
00137 loc->satisfy_ = satisfy_->currentItem();
00138 loc->order_ = order_->currentItem();
00139 loc->addresses_ = addresses_->items();
00140 }
00141
00142
void LocationDialog::setLocation(CupsLocation *loc)
00143 {
00144
int index = conf_->resources_.findRef(loc->resource_);
00145 resource_->setCurrentItem(index);
00146 authtype_->setCurrentItem(loc->authtype_);
00147 authclass_->setCurrentItem(loc->authclass_);
00148 authname_->setText(loc->authname_);
00149 encryption_->setCurrentItem(loc->encryption_);
00150 satisfy_->setCurrentItem(loc->satisfy_);
00151 order_->setCurrentItem(loc->order_);
00152 addresses_->insertItems(loc->addresses_);
00153
00154 slotTypeChanged(loc->authtype_);
00155 slotClassChanged(loc->authclass_);
00156 }
00157
00158
void LocationDialog::slotTypeChanged(
int index)
00159 {
00160 authclass_->setEnabled(index != AUTHTYPE_NONE);
00161
if (index != AUTHTYPE_NONE)
00162 slotClassChanged(authclass_->currentItem());
00163
else
00164 authname_->setEnabled(
false);
00165 }
00166
00167
void LocationDialog::slotClassChanged(
int index)
00168 {
00169 authname_->setEnabled((index == AUTHCLASS_USER || index == AUTHCLASS_GROUP));
00170 }
00171
00172
bool LocationDialog::newLocation(CupsLocation *loc,
QWidget *parent, CupsdConf *conf)
00173 {
00174 LocationDialog dlg(parent);
00175
if (conf)
00176 dlg.setInfos(conf);
00177
if (dlg.exec())
00178 {
00179 dlg.fillLocation(loc);
00180
return true;
00181 }
00182
else
00183
return false;
00184 }
00185
00186
bool LocationDialog::editLocation(CupsLocation *loc,
QWidget *parent, CupsdConf *conf)
00187 {
00188 LocationDialog dlg(parent);
00189
if (conf)
00190 dlg.setInfos(conf);
00191 dlg.setLocation(loc);
00192 dlg.resource_->setEnabled(
false);
00193
if (dlg.exec())
00194 {
00195 dlg.fillLocation(loc);
00196
return true;
00197 }
00198
else
00199
return false;
00200 }
00201
00202
void LocationDialog::slotAdd()
00203 {
00204
QString addr = AddressDialog::newAddress(
this);
00205
if (!addr.
isEmpty())
00206 addresses_->insertItem(addr);
00207 }
00208
00209
void LocationDialog::slotEdit(
int index)
00210 {
00211
QString addr = addresses_->text(index);
00212 addr = AddressDialog::editAddress(addr,
this);
00213
if (!addr.
isEmpty())
00214 addresses_->insertItem(addr);
00215 }
00216
00217
void LocationDialog::slotDefaultList()
00218 {
00219 addresses_->clear();
00220 }
00221
00222
#include "locationdialog.moc"