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
217
218
219
220
221
222
223
224
225
226
227
|
/***************************************************************************
* Copyright (C) 2004 by Christoph Thielecke *
* crissi99@gmx.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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "profilenetworkrouteoptions.h"
#include <tqcheckbox.h>
#include <klineedit.h>
#include <klistview.h>
#include <tqpushbutton.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
#include <kcombobox.h>
#include <tqstring.h>
#include <klocale.h>
#include <iostream>
#include "addnetworkroutedialog.h"
#include "widgetnotifyhelper.h"
ProfileNetworkRouteOptions::ProfileNetworkRouteOptions(TQWidget *parent): ProfileNetworkRouteOptionsBase(parent)
{
WidgetNotifyHelper h;
h.setupChangedAction(this);
dialogModified=false;
checkList();
}
ProfileNetworkRouteOptions::~ProfileNetworkRouteOptions()
{
}
void ProfileNetworkRouteOptions::additionalNetworkRoutesToggled(bool)
{
if (UseExtraNetworkRoutesCheckbox->isChecked())
{
NetworkListView->setEnabled(TRUE);
AddRoutePushButton->setEnabled(TRUE);
checkList();
}
else
{
NetworkListView->setEnabled(FALSE);
DeleteNetworkRoutePushButton->setEnabled(FALSE);
AddRoutePushButton->setEnabled(FALSE);
}
}
void ProfileNetworkRouteOptions::delNetworkRouteClicked()
{
if ( NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 )
{
TQListViewItem *item = NetworkListView->currentItem();
TQString Network = item->text(0);
TQString Netmask = item->text(1);
int result = KMessageBox::questionYesNo ( this, i18n( "Do you really want to delete the network \"%1/%2\"?" ).tqarg( Network ).tqarg(Netmask), i18n( "Delete?" ) );
//LogOutput->append( "Result: "+ TQString().setNum(result) ) ;
if ( result == 3) // Yes
{
NetworkListView->removeItem(item);
}
checkList();
}
}
void ProfileNetworkRouteOptions::addNetworkRouteClicked()
{
AddNetworkRouteDialog dlg(this, i18n("Add Network Route..."));
dlg.main->InterfaceComboBox->insertItem("default"); // interface where default route points
//FIXME
dlg.main->InterfaceComboBox->insertItem("eth0");
dlg.main->InterfaceComboBox->insertItem("eth1");
dlg.main->InterfaceComboBox->insertItem("eth2");
dlg.main->InterfaceComboBox->insertItem("ipsec0");
dlg.main->InterfaceComboBox->insertItem("tun0");
dlg.main->InterfaceComboBox->insertItem("ppp0");
if (dlg.exec())
{
TQString gateway = dlg.getGateway();
TQString interface = dlg.getInterface();
if (!dlg.getUseGateway())
gateway="-";
if (!dlg.getUseInterface())
interface="-";
NetworkListView->insertItem( new TQListViewItem(NetworkListView, dlg.getNetwork(),dlg.getNetmask(), gateway,interface));
if (dlg.dialogModified == true)
dialogModified=true;
}
checkList();
}
void ProfileNetworkRouteOptions::editNetworkRouteClicked()
{
if ( NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 )
{
AddNetworkRouteDialog dlg(this, i18n("Edit Network Route..."));
TQString Network=NetworkListView->currentItem()->text(0);
TQString Netmask=NetworkListView->currentItem()->text(1);
TQString Gateway=NetworkListView->currentItem()->text(2);
TQString Interface=NetworkListView->currentItem()->text(3);
dlg.main->InterfaceComboBox->insertItem("default"); // interface where default route points
//FIXME
dlg.main->InterfaceComboBox->insertItem("eth0");
dlg.main->InterfaceComboBox->insertItem("eth1");
dlg.main->InterfaceComboBox->insertItem("eth2");
dlg.main->InterfaceComboBox->insertItem("ipsec0");
dlg.main->InterfaceComboBox->insertItem("tun0");
dlg.main->InterfaceComboBox->insertItem("tun1");
dlg.main->InterfaceComboBox->insertItem("tun2");
dlg.main->InterfaceComboBox->insertItem("tap0");
dlg.main->InterfaceComboBox->insertItem("tap1");
dlg.main->InterfaceComboBox->insertItem("tap2");
dlg.main->InterfaceComboBox->insertItem("ppp0");
dlg.main->RemoteNetAddrLineEdit->setText(Network);
dlg.main->RemoteNetMaskComboBox->setCurrentItem(Netmask);
if (!Gateway.isEmpty() && Gateway != "-")
{
dlg.main->RemoteGatewayAddrLineEdit->setText(Gateway);
dlg.main->UseGatewayCheckBox->setChecked(true);
}
else
dlg.main->UseGatewayCheckBox->setChecked(false);
if (!Interface.isEmpty() && Interface!="-")
{
dlg.main->InterfaceComboBox->setCurrentText(Interface);
dlg.main->UseInterfaceCheckBox->setChecked(true);
}
else
dlg.main->UseInterfaceCheckBox->setChecked(false);
if (dlg.exec())
{
TQString gateway = dlg.getGateway();
TQString interface = dlg.getInterface();
if (!dlg.getUseGateway())
gateway="-";
if (!dlg.getUseInterface())
interface="-";
NetworkListView->takeItem(NetworkListView->currentItem());
NetworkListView->insertItem( new TQListViewItem(NetworkListView, dlg.getNetwork(),dlg.getNetmask(), gateway,interface));
// NetworkListView->currentItem()->text(0) = dlg.getNetwork();
// NetworkListView->currentItem()->text(1) = dlg.getNetmask();
// NetworkListView->currentItem()->text(2) = gateway;
// NetworkListView->currentItem()->text(3) = interface;
}
checkList();
}
}
void ProfileNetworkRouteOptions::checkList()
{
if (NetworkListView->childCount() > 0 && NetworkListView->currentItem()!= 0 )
{
EditRoutePushButton->setEnabled(true);
DeleteNetworkRoutePushButton->setEnabled(true);
}
else
{
EditRoutePushButton->setEnabled(false);
DeleteNetworkRoutePushButton->setEnabled(false);
}
}
void ProfileNetworkRouteOptions::contextMenuRequested ( TQListViewItem * item, const TQPoint &pos, int )
{
ContextMenu = new TQPopupMenu ( 0 );
if (item != 0)
{
ContextMenu->insertItem(i18n("&Edit..."));
ContextMenu->insertItem(i18n("&Delete..."));
}
ContextMenu->insertItem(i18n("&Add..."));
connect ( ContextMenu, TQT_SIGNAL ( activated ( int ) ), this, TQT_SLOT ( doContextMenuAction ( int ) ) );
ContextMenu->show();
ContextMenu->setGeometry(pos.x(),pos.y(), ContextMenu->width(),ContextMenu->height());
}
void ProfileNetworkRouteOptions::doContextMenuAction ( int action)
{
TQString itemtext = ContextMenu->text ( action );
// std::cout << "action: " << itemtext << std::endl;
if (itemtext == i18n("&Edit..."))
editNetworkRouteClicked();
if (itemtext == i18n("&Delete..."))
delNetworkRouteClicked();
if (itemtext == i18n("&Add..."))
addNetworkRouteClicked();
}
void ProfileNetworkRouteOptions::dialogChanged()
{
// std::cout << "ProfileNetworkRouteOptions::dialogChanged()" << std::endl;
dialogModified=true;
}
|