1 /***************************************************************************
2 nfshostdlg.cpp - description
4 begin : Mon Apr 29 2002
5 copyright : (C) 2002 by Jan Sch�er
6 email : janschaefer@users.sourceforge.net
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <qcheckbox.h>
20 #include <qlineedit.h>
21 #include <q3whatsthis.h>
22 #include <q3groupbox.h>
24 #include <QVBoxLayout>
27 #include <kmessagebox.h>
31 #include "nfshostdlg.h"
32 #include "hostprops.h"
36 NFSHostDlg::NFSHostDlg(QWidget
* parent
, HostList
* hosts
, NFSEntry
* entry
)
38 m_hosts(hosts
), m_nfsEntry(entry
), m_modified(false)
40 setCaption(i18n("Host Properties"));
41 setButtons(Ok
|Cancel
);
44 QWidget
* page
= new QWidget(this);
47 m_gui
= new HostProps(page
);
49 QVBoxLayout
*layout
= new QVBoxLayout( page
);
50 layout
->setSpacing( 6 );
51 layout
->setMargin( 0 );
52 layout
->addWidget( m_gui
);
54 connect( m_gui
, SIGNAL(modified()), this, SLOT(setModified()));
55 connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
60 NFSHostDlg::~NFSHostDlg()
64 void NFSHostDlg::init()
66 if (m_hosts
->count()==1) {
67 NFSHost
* host
= m_hosts
->first();
69 m_gui
->nameEdit
->setText(host
->name
);
70 m_gui
->publicChk
->setChecked(host
->isPublic());
74 m_gui
->nameEdit
->setFocus();
76 m_gui
->nameEdit
->setDisabled(true);
77 m_gui
->publicChk
->setDisabled(true);
79 m_gui
->readOnlyChk
->setTristate();
80 m_gui
->allSquashChk
->setTristate();
81 m_gui
->rootSquashChk
->setTristate();
82 m_gui
->hideChk
->setTristate();
83 m_gui
->secureChk
->setTristate();
84 m_gui
->secureLocksChk
->setTristate();
85 m_gui
->subtreeChk
->setTristate();
86 m_gui
->syncChk
->setTristate();
87 m_gui
->wdelayChk
->setTristate();
89 for (NFSHost
* host
= m_hosts
->first(); host
; host
= m_hosts
->next()) {
95 void NFSHostDlg::setHostValues(NFSHost
* host
) {
96 setCheckBoxValue(m_gui
->readOnlyChk
, ! host
->readonly
);
97 setCheckBoxValue(m_gui
->allSquashChk
, host
->allSquash
);
98 setCheckBoxValue(m_gui
->rootSquashChk
, ! host
->rootSquash
);
99 setCheckBoxValue(m_gui
->hideChk
, ! host
->hide
);
100 setCheckBoxValue(m_gui
->secureChk
, ! host
->secure
);
101 setCheckBoxValue(m_gui
->secureLocksChk
, ! host
->secureLocks
);
102 setCheckBoxValue(m_gui
->subtreeChk
, ! host
->subtreeCheck
);
103 setCheckBoxValue(m_gui
->syncChk
, host
->sync
);
104 setCheckBoxValue(m_gui
->wdelayChk
, ! host
->wdelay
);
106 setEditValue(m_gui
->anonuidEdit
,QString::number(host
->anonuid
));
107 setEditValue(m_gui
->anongidEdit
,QString::number(host
->anongid
));
110 void NFSHostDlg::setEditValue(QLineEdit
* edit
, const QString
& value
) {
111 if (edit
->text().isEmpty())
114 if (edit
->text() == "FF")
115 edit
->setText(value
);
117 if (edit
->text() != value
)
121 void NFSHostDlg::setCheckBoxValue(QCheckBox
* chk
, bool value
) {
122 if (chk
->checkState() == Qt::PartiallyChecked
)
125 if (chk
->isChecked()) {
127 chk
->setCheckState(Qt::PartiallyChecked
);
130 chk
->setChecked(true);
135 void NFSHostDlg::slotOk()
137 if (m_hosts
->count()==1) {
138 NFSHost
* host
= m_hosts
->first();
139 if (! saveName(host
))
144 for (NFSHost
* host
= m_hosts
->first(); host
; host
= m_hosts
->next()) {
152 bool NFSHostDlg::saveName(NFSHost
* host
) {
153 if (m_gui
->publicChk
->isChecked()) {
154 NFSHost
* publicHost
= m_nfsEntry
->getPublicHost();
155 if (publicHost
&& publicHost
!= host
) {
156 KMessageBox::sorry(this,i18n("There already exists a public entry."),
157 i18n("Host Already Exists"));
158 m_gui
->publicChk
->setChecked(false);
163 QString name
= m_gui
->nameEdit
->text().trimmed();
164 if (name
.isEmpty()) {
165 KMessageBox::sorry(this,
166 i18n("Please enter a hostname or an IP address."),
167 i18n("No Hostname/IP-Address"));
168 m_gui
->nameEdit
->setFocus();
171 NFSHost
* host2
= m_nfsEntry
->getHostByName(name
);
172 if (host2
&& host2
!= host
) {
173 KMessageBox::sorry(this,i18n("The host '%1' already exists.", name
),
174 i18n("Host Already Exists"));
175 m_gui
->nameEdit
->setFocus();
186 void NFSHostDlg::saveValues(NFSHost
* host
) {
188 saveCheckBoxValue(host
->readonly
,m_gui
->readOnlyChk
,true);
189 saveCheckBoxValue(host
->allSquash
,m_gui
->allSquashChk
,false);
190 saveCheckBoxValue(host
->rootSquash
,m_gui
->rootSquashChk
,true);
191 saveCheckBoxValue(host
->hide
,m_gui
->hideChk
,true);
192 saveCheckBoxValue(host
->secure
,m_gui
->secureChk
,true);
193 saveCheckBoxValue(host
->secureLocks
,m_gui
->secureLocksChk
,true);
194 saveCheckBoxValue(host
->subtreeCheck
,m_gui
->subtreeChk
,true);
195 saveCheckBoxValue(host
->sync
,m_gui
->syncChk
,false);
196 saveCheckBoxValue(host
->wdelay
,m_gui
->wdelayChk
,true);
198 saveEditValue(host
->anonuid
,m_gui
->anonuidEdit
);
199 saveEditValue(host
->anongid
,m_gui
->anongidEdit
);
202 void NFSHostDlg::saveEditValue(int & value
, QLineEdit
* edit
) {
203 if ( edit
->text().isEmpty())
206 value
= edit
->text().toInt();
209 void NFSHostDlg::saveCheckBoxValue(bool & value
, QCheckBox
* chk
, bool neg
) {
210 if (chk
->checkState() == Qt::PartiallyChecked
)
214 value
= ! chk
->isChecked();
216 value
= chk
->isChecked();
221 bool NFSHostDlg::isModified() {
226 void NFSHostDlg::setModified()
231 #include "nfshostdlg.moc"