Show invite menu in wlm chat window immediately
[kdenetwork.git] / filesharing / advanced / nfs / nfshostdlg.cpp
blob845b0958ba438fe282ed871a13461aa03abb1e20
1 /***************************************************************************
2 nfshostdlg.cpp - description
3 -------------------
4 begin : Mon Apr 29 2002
5 copyright : (C) 2002 by Jan Sch�er
6 email : janschaefer@users.sourceforge.net
7 ***************************************************************************/
9 /***************************************************************************
10 * *
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. *
15 * *
16 ***************************************************************************/
18 #include <qcheckbox.h>
19 #include <qlayout.h>
20 #include <qlineedit.h>
21 #include <q3whatsthis.h>
22 #include <q3groupbox.h>
23 //Added by qt3to4:
24 #include <QVBoxLayout>
25 #include <klocale.h>
26 #include <kdebug.h>
27 #include <kmessagebox.h>
29 #include <assert.h>
31 #include "nfshostdlg.h"
32 #include "hostprops.h"
33 #include "nfsentry.h"
36 NFSHostDlg::NFSHostDlg(QWidget* parent, HostList* hosts, NFSEntry* entry)
37 : KDialog(parent),
38 m_hosts(hosts), m_nfsEntry(entry), m_modified(false)
40 setCaption(i18n("Host Properties"));
41 setButtons(Ok|Cancel);
42 setDefaultButton(Ok);
44 QWidget* page = new QWidget(this);
45 setMainWidget(page);
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()));
56 init();
60 NFSHostDlg::~NFSHostDlg()
64 void NFSHostDlg::init()
66 if (m_hosts->count()==1) {
67 NFSHost* host = m_hosts->first();
68 assert(host);
69 m_gui->nameEdit->setText(host->name);
70 m_gui->publicChk->setChecked(host->isPublic());
72 setHostValues(host);
74 m_gui->nameEdit->setFocus();
75 } else {
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()) {
90 setHostValues(host);
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())
112 return;
114 if (edit->text() == "FF")
115 edit->setText(value);
116 else
117 if (edit->text() != value)
118 edit->clear();
121 void NFSHostDlg::setCheckBoxValue(QCheckBox* chk, bool value) {
122 if (chk->checkState() == Qt::PartiallyChecked)
123 return;
125 if (chk->isChecked()) {
126 if (! value)
127 chk->setCheckState(Qt::PartiallyChecked);
128 } else {
129 if (value)
130 chk->setChecked(true);
135 void NFSHostDlg::slotOk()
137 if (m_hosts->count()==1) {
138 NFSHost* host = m_hosts->first();
139 if (! saveName(host))
140 return;
142 saveValues(host);
143 } else {
144 for (NFSHost* host = m_hosts->first(); host; host = m_hosts->next()) {
145 saveValues(host);
149 KDialog::accept();
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);
159 return false;
161 host->name="*";
162 } else {
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();
169 return false;
170 } else {
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();
176 return false;
179 host->name=name;
182 return true;
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())
204 return;
206 value = edit->text().toInt();
209 void NFSHostDlg::saveCheckBoxValue(bool & value, QCheckBox* chk, bool neg) {
210 if (chk->checkState() == Qt::PartiallyChecked)
211 return;
213 if (neg)
214 value = ! chk->isChecked();
215 else
216 value = chk->isChecked();
221 bool NFSHostDlg::isModified() {
222 return m_modified;
226 void NFSHostDlg::setModified()
228 m_modified = true;
231 #include "nfshostdlg.moc"