kdeprint Library API Documentation

cupsdserversecuritypage.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 **/ 00019 00020 #include "cupsdserversecuritypage.h" 00021 00022 #include <qlineedit.h> 00023 #include <klocale.h> 00024 #include <qlayout.h> 00025 #include <qlabel.h> 00026 #include <qlistview.h> 00027 #include <qframe.h> 00028 #include <qpushbutton.h> 00029 #include <kmessagebox.h> 00030 #include <kiconloader.h> 00031 #include <kseparator.h> 00032 #include <qwhatsthis.h> 00033 00034 #include "cupsdconf.h" 00035 #include "cupsdoption.h" 00036 #include "cupslocationdialog.h" 00037 00038 CupsdServerSecurityPage::CupsdServerSecurityPage(QWidget *parent, const char *name) 00039 : CupsdPage(parent, name) 00040 { 00041 path_.append(i18n("Security")); 00042 header_ = i18n("Security Configuration"); 00043 00044 for (int i=0;i<1;i++) 00045 opt_[i] = new CupsdOption(this); 00046 00047 QVBoxLayout *main_ = new QVBoxLayout(this, 10, 10); 00048 main_->addWidget(deflabel_, 0, Qt::AlignRight|Qt::AlignVCenter); 00049 00050 QHBoxLayout *sub1_ = new QHBoxLayout(0, 0, 10); 00051 QLabel *l1 = new QLabel(i18n("System group:"), this); 00052 systemgroup_ = new QLineEdit(opt_[0]); 00053 main_->addLayout(sub1_); 00054 sub1_->addWidget(l1); 00055 sub1_->addWidget(opt_[0]); 00056 00057 KSeparator* sep = new KSeparator( KSeparator::HLine, this); 00058 sep->setFixedHeight(20); 00059 main_->addWidget(sep); 00060 00061 locations_ = new QListView(this); 00062 locations_->setFrameStyle(QFrame::WinPanel|QFrame::Sunken); 00063 locations_->setLineWidth(1); 00064 locations_->addColumn(i18n("Resource")); 00065 locations_->addColumn(i18n("Path")); 00066 locations_->setSorting(1); 00067 00068 QLabel *l2 = new QLabel(i18n("Resources:"), this); 00069 00070 QPushButton *add_ = new QPushButton(i18n("Add..."), this); 00071 connect(add_, SIGNAL(clicked()), SLOT(addClicked())); 00072 QPushButton *modify_ = new QPushButton(i18n("Modify"), this); 00073 connect(modify_, SIGNAL(clicked()), SLOT(modifyClicked())); 00074 QPushButton *remove_ = new QPushButton(i18n("Remove"), this); 00075 connect(remove_, SIGNAL(clicked()), SLOT(removeClicked())); 00076 00077 QGridLayout *sub2_ = new QGridLayout(0, 3, 3, 0, 10); 00078 main_->addLayout(sub2_); 00079 sub2_->addWidget(l2, 0, 0, Qt::AlignLeft|Qt::AlignTop); 00080 sub2_->addMultiCellWidget(locations_, 0, 2, 1, 1); 00081 sub2_->addWidget(add_, 0, 2); 00082 sub2_->addWidget(modify_, 1, 2); 00083 sub2_->addWidget(remove_, 2, 2); 00084 00085 main_->addStretch(1); 00086 00087 loclist_.setAutoDelete(true); 00088 } 00089 00090 CupsdServerSecurityPage::~CupsdServerSecurityPage() 00091 { 00092 } 00093 00094 void CupsdServerSecurityPage::updateLocations() 00095 { 00096 locations_->clear(); 00097 for (loclist_.first();loclist_.current();loclist_.next()) 00098 { 00099 QListViewItem *item = new QListViewItem(locations_, (loclist_.current()->resource_ ? loclist_.current()->resource_->text_ : i18n("<Unmatched resource>")), loclist_.current()->resourcename_); 00100 if (loclist_.current()->resource_) item->setPixmap(0, SmallIcon(CupsResource::typeToIconName(loclist_.current()->resource_->type_))); 00101 else item->setPixmap(0, SmallIcon("")); 00102 } 00103 } 00104 00105 bool CupsdServerSecurityPage::loadConfig(CupsdConf *conf, QString&) 00106 { 00107 conf_ = conf; 00108 if (!conf->systemgroup_.isNull()) 00109 { 00110 opt_[0]->setDefault(0); 00111 systemgroup_->setText(conf->systemgroup_); 00112 } 00113 loclist_.clear(); 00114 for (conf->locations_.first();conf->locations_.current();conf->locations_.next()) 00115 loclist_.append(new CupsLocation(*(conf->locations_.current()))); 00116 updateLocations(); 00117 return true; 00118 } 00119 00120 bool CupsdServerSecurityPage::saveConfig(CupsdConf *conf, QString&) 00121 { 00122 if (!opt_[0]->isDefault() && !systemgroup_->text().isNull()) conf->systemgroup_ = systemgroup_->text(); 00123 conf->locations_.clear(); 00124 for (loclist_.first();loclist_.current();loclist_.next()) 00125 conf->locations_.append(new CupsLocation(*(loclist_.current()))); 00126 return true; 00127 } 00128 00129 void CupsdServerSecurityPage::setDefaults() 00130 { 00131 systemgroup_->setText("sys"); 00132 loclist_.clear(); 00133 updateLocations(); 00134 } 00135 00136 void CupsdServerSecurityPage::addClicked() 00137 { 00138 CupsLocationDialog dlg(conf_, this); 00139 if (dlg.exec()) 00140 { 00141 CupsLocation *loc = new CupsLocation; 00142 loclist_.append(loc); 00143 dlg.saveLocation(loc); 00144 updateLocations(); 00145 } 00146 } 00147 00148 void CupsdServerSecurityPage::modifyClicked() 00149 { 00150 if (locations_->currentItem() != NULL) 00151 { 00152 for (loclist_.first();loclist_.current();loclist_.next()) 00153 if (loclist_.current()->resourcename_ == locations_->currentItem()->text(1)) break; 00154 if (!loclist_.current()) return; 00155 CupsLocation *loc = loclist_.current(); 00156 CupsLocationDialog dlg(conf_, this); 00157 dlg.loadLocation(loc); 00158 if (dlg.exec()) 00159 { 00160 dlg.saveLocation(loc); 00161 // updateLocations(); 00162 // locations_->setSelected(index, true); 00163 } 00164 } 00165 } 00166 00167 void CupsdServerSecurityPage::removeClicked() 00168 { 00169 if (!locations_->currentItem()) return; 00170 for (loclist_.first();loclist_.current();loclist_.next()) 00171 if (loclist_.current()->resourcename_ == locations_->currentItem()->text(1)) break; 00172 if (!loclist_.current()) return; 00173 if (KMessageBox::warningYesNo(this, i18n("Really remove resource \"%1\"?").arg(loclist_.current()->resourcename_)) == KMessageBox::Yes) 00174 { 00175 loclist_.remove(); 00176 delete locations_->currentItem(); 00177 // updateLocations(); 00178 // locations_->removeItem(index); 00179 } 00180 } 00181 00182 void CupsdServerSecurityPage::setInfos(CupsdConf *conf) 00183 { 00184 QWhatsThis::add(systemgroup_, conf->comments_.toolTip(SYSTEMGROUP_COMM)); 00185 QWhatsThis::add(locations_, conf->comments_.toolTip(LOCATIONS_COMM)); 00186 } 00187 #include "cupsdserversecuritypage.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Aug 30 22:55:47 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003