summaryrefslogtreecommitdiffstats
path: root/filesharing/advanced/nfs/nfsdialog.cpp
blob: 9636b5cbc02943b61ab4c3e8e4d3b5210405ee21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
  Copyright (c) 2004 Jan Schaefer <j_schaef@informatik.uni-kl.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/


#include <tqradiobutton.h>
#include <tqpushbutton.h>
#include <tqgroupbox.h>
#include <tqlineedit.h>
#include <tqbuttongroup.h>
#include <tqlayout.h>

#include <kdebug.h>
#include <tdemessagebox.h>
#include <tdefiledialog.h>
#include <tdelocale.h>
#include <tdelistview.h>
#include <tdeaccel.h>

#include "nfsdialog.h"
#include "nfsentry.h"
#include "nfshostdlg.h"
#include "nfsfile.h"
#include "nfsdialoggui.h"

NFSDialog::NFSDialog(TQWidget * parent, NFSEntry* entry)
 : KDialogBase(Plain, i18n("NFS Options"), Ok|Cancel, Ok, parent), 
   m_nfsEntry(entry),
   m_modified(false)
{
  if (m_nfsEntry) 
      m_workEntry = m_nfsEntry->copy();
  else
      kdWarning() << "NFSDialog::NFSDialog: entry is null!" << endl;
            
  initGUI();
  initSlots();
  initListView();
}

NFSDialog::~NFSDialog()
{
  delete m_workEntry;
}

void NFSDialog::initGUI() {
  TQWidget* page = plainPage();
  m_gui = new NFSDialogGUI(page);

  TQVBoxLayout *layout = new TQVBoxLayout( page );
  layout->addWidget( m_gui );
  
  TDEAccel* accel = new TDEAccel( m_gui->listView );
  accel->insert( "Delete", TQt::Key_Delete, this, TQT_SLOT(slotRemoveHost()));
}

void NFSDialog::initSlots()
{
  connect( m_gui->removeHostBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT( slotRemoveHost()));
  connect( m_gui->addHostBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT( slotAddHost()));
  connect( m_gui->modifyHostBtn, TQT_SIGNAL(clicked()), this, TQT_SLOT( slotModifyHost()));
  connect( m_gui->listView, TQT_SIGNAL(doubleClicked(TQListViewItem*)), 
           this, TQT_SLOT( slotModifyHost()));

}

void NFSDialog::initListView()
{
  if (m_workEntry) {
    HostIterator it = m_workEntry->getHosts();

    NFSHost* host;
    while ( (host = it.current()) != 0 ) {
       ++it;
       createItemFromHost(host);
    }
  }
}

TQListViewItem* NFSDialog::createItemFromHost(NFSHost* host)
{
  if (!host) 
    return 0;

  TQListViewItem* item = new TQListViewItem(m_gui->listView);
  updateItem(item, host);
  return item;
}

void NFSDialog::updateItem(TQListViewItem* item, NFSHost* host)
{
  item->setText(0,host->name);
  item->setText(1,host->paramString());
}

void NFSDialog::slotAddHost()
{
  NFSHost *host = new NFSHost();

  // Set some secure parameters
  //host->allSquash=true;
  host->readonly=true;

  HostList hostList;
  hostList.append(host);
  
  NFSHostDlg *dlg = new NFSHostDlg(this, &hostList, m_workEntry);
  dlg->exec();

  
  if (dlg->result()==TQDialog::Accepted) {
    m_workEntry->addHost(host);
    createItemFromHost(host);
    setModified();
  } else {
    delete host;
  }

  delete dlg;
}

void NFSDialog::slotOk() {
  if (m_modified) {
    m_nfsEntry->copyFrom(m_workEntry);
  }    
  KDialogBase::slotOk();
}

void NFSDialog::slotRemoveHost()
{
  TQPtrList<TQListViewItem> items = m_gui->listView->selectedItems();
  if (items.count()==0)
      return;
  
  TQListViewItem *item;
  for ( item = items.first(); item; item = items.next() ) {
    TQString name = item->text(0);
    m_gui->listView->takeItem(item);
    
    NFSHost* host = m_workEntry->getHostByName(name);
    if (host) {
      m_workEntry->removeHost(host);
    } else {
      kdWarning() << "NFSDialog::slotRemoveHost: no host " 
                  << name << " << found!" << endl;
    }
      
  }
    
  m_gui->modifyHostBtn->setDisabled(true);
  m_gui->removeHostBtn->setDisabled(true);
  setModified();
}

void NFSDialog::slotModifyHost()
{
  TQPtrList<TQListViewItem> items = m_gui->listView->selectedItems();
  if (items.count()==0)
      return;
  
  HostList hostList;
  
  TQListViewItem *item;
  for ( item = items.first(); item; item = items.next() ) {
  
    NFSHost* host = m_workEntry->getHostByName(item->text(0));
    if (host)
      hostList.append(host);
    else
      kdWarning() << "NFSDialog::slogModifyHost: host " 
                  << item->text(0) << " is null!" << endl;     
  }
  
  NFSHostDlg *dlg = new NFSHostDlg(this, &hostList, m_workEntry);
  if (dlg->exec() == TQDialog::Accepted &&
      dlg->isModified()) 
  {      
      setModified();
  }
        
  delete dlg;

  NFSHost* host = hostList.first();
  for ( item = items.first(); item; item = items.next() ) {
      if (item && host)
          updateItem( item,host);
      host = hostList.next();
  }
}

void NFSDialog::setModified()
{
  m_modified = true;
}

bool NFSDialog::modified() {
  return m_modified;
}

#include "nfsdialog.moc"