00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "cupsdserverpage.h"
00021 #include "cupsdconf.h"
00022
00023 #include <QtGui/QLineEdit>
00024 #include <QtGui/QLabel>
00025 #include <QtGui/QCheckBox>
00026 #include <QtGui/QComboBox>
00027 #include <QtGui/QLayout>
00028
00029 #include <klocale.h>
00030
00031 int findComboItem(QComboBox *cb, const QString& str)
00032 {
00033 for (int i = 0; i < cb->count(); i++)
00034 if (cb->itemText(i) == str)
00035 return i;
00036 return (-1);
00037 }
00038
00039 CupsdServerPage::CupsdServerPage(QWidget *parent)
00040 : CupsdPage(parent)
00041 {
00042 setPageLabel(i18n("Server"));
00043 setHeader(i18n("Server Settings"));
00044 setPixmap("network-server");
00045
00046 servername_ = new QLineEdit(this);
00047 serveradmin_ = new QLineEdit(this);
00048 otherclassname_ = new QLineEdit(this);
00049 language_ = new QLineEdit(this);
00050 printcap_ = new QLineEdit(this);
00051 classification_ = new QComboBox(this);
00052 charset_ = new QComboBox(this);
00053 printcapformat_ = new QComboBox(this);
00054 classoverride_ = new QCheckBox(i18n("Allow overrides"), this);
00055
00056 classification_->addItem(i18n("None"));
00057 classification_->addItem(i18n("Classified"));
00058 classification_->addItem(i18n("Confidential"));
00059 classification_->addItem(i18n("Secret"));
00060 classification_->addItem(i18n("Top Secret"));
00061 classification_->addItem(i18n("Unclassified"));
00062 classification_->addItem(i18n("Other"));
00063
00064 charset_->addItem("UTF-8");
00065 charset_->addItem("ISO-8859-1");
00066 charset_->addItem("ISO-8859-2");
00067 charset_->addItem("ISO-8859-3");
00068 charset_->addItem("ISO-8859-4");
00069 charset_->addItem("ISO-8859-5");
00070 charset_->addItem("ISO-8859-6");
00071 charset_->addItem("ISO-8859-7");
00072 charset_->addItem("ISO-8859-8");
00073 charset_->addItem("ISO-8859-9");
00074 charset_->addItem("ISO-8859-10");
00075 charset_->addItem("ISO-8859-13");
00076 charset_->addItem("ISO-8859-14");
00077 charset_->addItem("ISO-8859-15");
00078
00079 printcapformat_->addItem("BSD");
00080 printcapformat_->addItem("SOLARIS");
00081
00082 QLabel *l1 = new QLabel(i18n("Server name:"), this);
00083 QLabel *l2 = new QLabel(i18n("Server administrator:"), this);
00084 QLabel *l3 = new QLabel(i18n("Classification:"), this);
00085 QLabel *l4 = new QLabel(i18n("Default character set:"), this);
00086 QLabel *l5 = new QLabel(i18n("Default language:"), this);
00087 QLabel *l6 = new QLabel(i18n("Printcap file:"), this);
00088 QLabel *l7 = new QLabel(i18n("Printcap format:"), this);
00089
00090 connect(classification_, SIGNAL(activated(int)), SLOT(classChanged(int)));
00091 classification_->setCurrentIndex(0);
00092 charset_->setCurrentIndex(0);
00093 printcapformat_->setCurrentIndex(0);
00094 classChanged(0);
00095
00096 QGridLayout *m1 = new QGridLayout(this);
00097 m1->setMargin(10);
00098 m1->setSpacing(7);
00099 m1->setRowStretch(8, 1);
00100 m1->setColumnStretch(1, 1);
00101 m1->addWidget(l1, 0, 0, Qt::AlignRight);
00102 m1->addWidget(l2, 1, 0, Qt::AlignRight);
00103 m1->addWidget(l3, 2, 0, Qt::AlignRight);
00104 m1->addWidget(l4, 4, 0, Qt::AlignRight);
00105 m1->addWidget(l5, 5, 0, Qt::AlignRight);
00106 m1->addWidget(l6, 6, 0, Qt::AlignRight);
00107 m1->addWidget(l7, 7, 0, Qt::AlignRight);
00108 m1->addWidget(servername_, 0, 1);
00109 m1->addWidget(serveradmin_, 1, 1);
00110 m1->addWidget(charset_, 4, 1);
00111 m1->addWidget(language_, 5, 1);
00112 m1->addWidget(printcap_, 6, 1);
00113 m1->addWidget(printcapformat_, 7, 1);
00114 QHBoxLayout *m2 = new QHBoxLayout();
00115 m2->setMargin(0);
00116 m2->setSpacing(5);
00117 m1->addLayout(m2, 2, 1);
00118 m2->addWidget(classification_);
00119 m2->addWidget(otherclassname_);
00120 QWidget *w = new QWidget(this);
00121 w->setFixedWidth(20);
00122 QHBoxLayout *m3 = new QHBoxLayout();
00123 m3->setMargin(0);
00124 m3->setSpacing(0);
00125 m1->addLayout(m3, 3, 1);
00126 m3->addWidget(w);
00127 m3->addWidget(classoverride_);
00128 }
00129
00130 bool CupsdServerPage::loadConfig(CupsdConf *conf, QString&)
00131 {
00132 conf_ = conf;
00133 servername_->setText(conf_->servername_);
00134 serveradmin_->setText(conf_->serveradmin_);
00135 classification_->setCurrentIndex(conf_->classification_);
00136 classChanged(conf_->classification_);
00137 if (conf->classification_ != CLASS_NONE)
00138 classoverride_->setChecked(conf_->classoverride_);
00139 if (conf->classification_ == CLASS_OTHER)
00140 otherclassname_->setText(conf_->otherclassname_);
00141 int index = findComboItem(charset_, conf_->charset_.toUpper());
00142 if (index != -1)
00143 charset_->setCurrentIndex(index);
00144 language_->setText(conf_->language_);
00145 printcap_->setText(conf_->printcap_);
00146 printcapformat_->setCurrentIndex(conf_->printcapformat_);
00147
00148 return true;
00149 }
00150
00151 bool CupsdServerPage::saveConfig(CupsdConf *conf, QString&)
00152 {
00153 conf->servername_ = servername_->text();
00154 conf->serveradmin_ = serveradmin_->text();
00155 conf->classification_ = classification_->currentIndex();
00156 if (conf->classification_ != CLASS_NONE)
00157 conf->classoverride_ = classoverride_->isChecked();
00158 if (conf->classification_ == CLASS_OTHER)
00159 conf->otherclassname_ = otherclassname_->text();
00160 conf->charset_ = charset_->currentText();
00161 conf->language_ = language_->text();
00162 conf->printcap_ = printcap_->text();
00163 conf->printcapformat_ = printcapformat_->currentIndex();
00164
00165 return true;
00166 }
00167
00168 void CupsdServerPage::setInfos(CupsdConf *conf)
00169 {
00170 servername_->setWhatsThis(conf->comments_.toolTip("servername"));
00171 serveradmin_->setWhatsThis(conf->comments_.toolTip("serveradmin"));
00172 classification_->setWhatsThis(conf->comments_.toolTip("classification"));
00173 classoverride_->setWhatsThis(conf->comments_.toolTip("classifyoverride"));
00174 charset_->setWhatsThis(conf->comments_.toolTip("defaultcharset"));
00175 language_->setWhatsThis(conf->comments_.toolTip("defaultlanguage"));
00176 printcap_->setWhatsThis(conf->comments_.toolTip("printcap"));
00177 printcapformat_->setWhatsThis(conf->comments_.toolTip("printcapformat"));
00178 }
00179
00180 void CupsdServerPage::classChanged(int index)
00181 {
00182 classoverride_->setEnabled(index != 0);
00183 otherclassname_->setEnabled(index == CLASS_OTHER);
00184 }
00185
00186 #include "cupsdserverpage.moc"