Diffstat (limited to 'noncore/settings/networksettings/ppp/accounts.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/accounts.cpp | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/noncore/settings/networksettings/ppp/accounts.cpp b/noncore/settings/networksettings/ppp/accounts.cpp index f704c84..7760d5e 100644 --- a/noncore/settings/networksettings/ppp/accounts.cpp +++ b/noncore/settings/networksettings/ppp/accounts.cpp | |||
@@ -28,33 +28,35 @@ | |||
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | #include <qtabdialog.h> | 31 | #include <qtabdialog.h> |
32 | #include <qwhatsthis.h> | 32 | #include <qwhatsthis.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | 34 | ||
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #include <qbuttongroup.h> | 36 | #include <qbuttongroup.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <qvgroupbox.h> | 38 | #include <qvgroupbox.h> |
39 | 39 | ||
40 | #include "pppdata.h" | ||
41 | #include "accounts.h" | 40 | #include "accounts.h" |
41 | #include "authwidget.h" | ||
42 | #include "pppdata.h" | ||
42 | #include "edit.h" | 43 | #include "edit.h" |
43 | 44 | ||
44 | void parseargs(char* buf, char** args); | 45 | void parseargs(char* buf, char** args); |
45 | 46 | ||
46 | AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name ) | 47 | AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name ) |
47 | : QWidget( parent, name ), _pppdata(pd) | 48 | : QWidget( parent, name )//, _pppdata(pd) |
48 | { | 49 | { |
50 | _pppdata = pd; | ||
49 | QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); | 51 | QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10); |
50 | accountlist_l = new QListBox(this); | 52 | accountlist_l = new QListBox(this); |
51 | 53 | ||
52 | connect(accountlist_l, SIGNAL(highlighted(int)), | 54 | connect(accountlist_l, SIGNAL(highlighted(int)), |
53 | this, SLOT(slotListBoxSelect(int))); | 55 | this, SLOT(slotListBoxSelect(int))); |
54 | connect(accountlist_l, SIGNAL(selected(int)), | 56 | connect(accountlist_l, SIGNAL(selected(int)), |
55 | this, SLOT(editaccount())); | 57 | this, SLOT(editaccount())); |
56 | l1->addWidget(accountlist_l, 10); | 58 | l1->addWidget(accountlist_l, 10); |
57 | 59 | ||
58 | edit_b = new QPushButton(tr("&Edit..."), this); | 60 | edit_b = new QPushButton(tr("&Edit..."), this); |
59 | connect(edit_b, SIGNAL(clicked()), SLOT(editaccount())); | 61 | connect(edit_b, SIGNAL(clicked()), SLOT(editaccount())); |
60 | QWhatsThis::add(edit_b, tr("Allows you to modify the selected account")); | 62 | QWhatsThis::add(edit_b, tr("Allows you to modify the selected account")); |
@@ -77,86 +79,56 @@ AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name ) | |||
77 | 79 | ||
78 | delete_b = new QPushButton(tr("De&lete"), this); | 80 | delete_b = new QPushButton(tr("De&lete"), this); |
79 | connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount())); | 81 | connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount())); |
80 | l1->addWidget(delete_b); | 82 | l1->addWidget(delete_b); |
81 | QWhatsThis::add(delete_b, | 83 | QWhatsThis::add(delete_b, |
82 | tr("<p>Deletes the selected account\n\n" | 84 | tr("<p>Deletes the selected account\n\n" |
83 | "<font color=\"red\"><b>Use with care!</b></font>")); | 85 | "<font color=\"red\"><b>Use with care!</b></font>")); |
84 | 86 | ||
85 | QHBoxLayout *l12 = new QHBoxLayout; | 87 | QHBoxLayout *l12 = new QHBoxLayout; |
86 | l1->addStretch(1); | 88 | l1->addStretch(1); |
87 | l1->addLayout(l12); | 89 | l1->addLayout(l12); |
88 | 90 | ||
91 | int currAccId = _pppdata->currentAccountID(); | ||
92 | qDebug("currentAccountID %i", currAccId); | ||
93 | |||
89 | //load up account list from gppdata to the list box | 94 | //load up account list from gppdata to the list box |
90 | if(_pppdata->count() > 0) { | 95 | if(_pppdata->count() > 0) { |
91 | for(int i=0; i <= _pppdata->count()-1; i++) { | 96 | for(int i=0; i <= _pppdata->count()-1; i++) { |
92 | _pppdata->setAccountbyIndex(i); | 97 | _pppdata->setAccountbyIndex(i); |
93 | accountlist_l->insertItem(_pppdata->accname()); | 98 | accountlist_l->insertItem(_pppdata->accname()); |
94 | } | 99 | } |
95 | } | 100 | } |
96 | 101 | _pppdata->setAccountbyIndex( currAccId ); | |
97 | 102 | ||
98 | qDebug("setting listview index to %i",_pppdata->currentAccountID() ); | 103 | qDebug("setting listview index to %i",_pppdata->currentAccountID() ); |
99 | accountlist_l->setCurrentItem( _pppdata->currentAccountID() ); | 104 | accountlist_l->setCurrentItem( _pppdata->currentAccountID() ); |
100 | slotListBoxSelect( _pppdata->currentAccountID()); | 105 | slotListBoxSelect( _pppdata->currentAccountID()); |
101 | 106 | ||
102 | l1->activate(); | 107 | l1->activate(); |
103 | } | 108 | } |
104 | 109 | ||
105 | 110 | ||
106 | 111 | ||
107 | void AccountWidget::slotListBoxSelect(int idx) { | 112 | void AccountWidget::slotListBoxSelect(int idx) { |
108 | delete_b->setEnabled((bool)(idx != -1)); | 113 | delete_b->setEnabled((bool)(idx != -1)); |
109 | edit_b->setEnabled((bool)(idx != -1)); | 114 | edit_b->setEnabled((bool)(idx != -1)); |
110 | copy_b->setEnabled((bool)(idx != -1)); | 115 | copy_b->setEnabled((bool)(idx != -1)); |
111 | if(idx!=-1) { | 116 | if(idx!=-1) { |
112 | qDebug("setting account to %i", idx); | 117 | qDebug("setting account to %i", idx); |
113 | QString account = _pppdata->accname(); | 118 | QString account = _pppdata->accname(); |
114 | _pppdata->setAccountbyIndex(accountlist_l->currentItem()); | 119 | _pppdata->setAccountbyIndex(accountlist_l->currentItem()); |
115 | // _pppdata->setAccount(account); | ||
116 | } | 120 | } |
117 | } | 121 | } |
118 | 122 | ||
119 | |||
120 | // void AccountWidget::viewLogClicked(){ | ||
121 | |||
122 | // QApplication::flushX(); | ||
123 | // if(fork() == 0) { | ||
124 | // setgid(getgid()); | ||
125 | // setuid(getuid()); | ||
126 | // system("kppplogview -kppp"); | ||
127 | // _exit(0); | ||
128 | // } | ||
129 | // } | ||
130 | |||
131 | |||
132 | // void AccountWidget::resetClicked(){ | ||
133 | // if(accountlist_l->currentItem() == -1) | ||
134 | // return; | ||
135 | |||
136 | // // QueryReset dlg(this); | ||
137 | // // int what = dlg.exec(); | ||
138 | |||
139 | // // if(what && QueryReset::COSTS) { | ||
140 | // // emit resetCosts(accountlist_l->text(accountlist_l->currentItem())); | ||
141 | // // costedit->setText("0"); | ||
142 | // // } | ||
143 | |||
144 | // // if(what && QueryReset::VOLUME) { | ||
145 | // // emit resetVolume(accountlist_l->text(accountlist_l->currentItem())); | ||
146 | // // voledit->setText(prettyPrintVolume(0)); | ||
147 | // // } | ||
148 | // } | ||
149 | |||
150 | |||
151 | void AccountWidget::editaccount() { | 123 | void AccountWidget::editaccount() { |
152 | _pppdata->setAccount(accountlist_l->text(accountlist_l->currentItem())); | 124 | _pppdata->setAccount(accountlist_l->text(accountlist_l->currentItem())); |
153 | 125 | ||
154 | int result = doTab(); | 126 | int result = doTab(); |
155 | 127 | ||
156 | if(result == QDialog::Accepted) { | 128 | if(result == QDialog::Accepted) { |
157 | accountlist_l->changeItem(_pppdata->accname(),accountlist_l->currentItem()); | 129 | accountlist_l->changeItem(_pppdata->accname(),accountlist_l->currentItem()); |
158 | // emit resetaccounts(); | 130 | // emit resetaccounts(); |
159 | _pppdata->save(); | 131 | _pppdata->save(); |
160 | } | 132 | } |
161 | } | 133 | } |
162 | 134 | ||
@@ -240,64 +212,63 @@ int AccountWidget::doTab(){ | |||
240 | isnewaccount = true; | 212 | isnewaccount = true; |
241 | } else { | 213 | } else { |
242 | QString tit = tr("Edit Account: "); | 214 | QString tit = tr("Edit Account: "); |
243 | tit += _pppdata->accname(); | 215 | tit += _pppdata->accname(); |
244 | dlg->setCaption(tit); | 216 | dlg->setCaption(tit); |
245 | isnewaccount = false; | 217 | isnewaccount = false; |
246 | } | 218 | } |
247 | 219 | ||
248 | // // DIAL WIDGET | 220 | // // DIAL WIDGET |
249 | dial_w = new DialWidget( _pppdata, tabWindow, isnewaccount, "Dial Setup"); | 221 | dial_w = new DialWidget( _pppdata, tabWindow, isnewaccount, "Dial Setup"); |
250 | tabWindow->addTab( dial_w, tr("Dial") ); | 222 | tabWindow->addTab( dial_w, tr("Dial") ); |
251 | 223 | ||
224 | // // AUTH WIDGET | ||
225 | auth_w = new AuthWidget( _pppdata, tabWindow, isnewaccount, tr("Edit Login Script")); | ||
226 | tabWindow->addTab( auth_w, tr("Authentication") ); | ||
227 | |||
252 | // // IP WIDGET | 228 | // // IP WIDGET |
253 | ip_w = new IPWidget( _pppdata, tabWindow, isnewaccount, tr("IP Setup")); | 229 | ip_w = new IPWidget( _pppdata, tabWindow, isnewaccount, tr("IP Setup")); |
254 | tabWindow->addTab( ip_w, tr("IP") ); | 230 | tabWindow->addTab( ip_w, tr("IP") ); |
255 | 231 | ||
256 | // // GATEWAY WIDGET | 232 | // // GATEWAY WIDGET |
257 | gateway_w = new GatewayWidget( _pppdata, tabWindow, isnewaccount, tr("Gateway Setup")); | 233 | gateway_w = new GatewayWidget( _pppdata, tabWindow, isnewaccount, tr("Gateway Setup")); |
258 | tabWindow->addTab( gateway_w, tr("Gateway") ); | 234 | tabWindow->addTab( gateway_w, tr("Gateway") ); |
259 | 235 | ||
260 | // // DNS WIDGET | 236 | // // DNS WIDGET |
261 | dns_w = new DNSWidget( _pppdata, tabWindow, isnewaccount, tr("DNS Servers") ); | 237 | dns_w = new DNSWidget( _pppdata, tabWindow, isnewaccount, tr("DNS Servers") ); |
262 | tabWindow->addTab( dns_w, tr("DNS") ); | 238 | tabWindow->addTab( dns_w, tr("DNS") ); |
263 | 239 | ||
264 | // // SCRIPT WIDGET | ||
265 | script_w = new ScriptWidget( _pppdata, tabWindow, isnewaccount, tr("Edit Login Script")); | ||
266 | tabWindow->addTab( script_w, tr("Login Script") ); | ||
267 | |||
268 | // // EXECUTE WIDGET | 240 | // // EXECUTE WIDGET |
269 | ExecWidget *exec_w = new ExecWidget( _pppdata, tabWindow, isnewaccount, tr("Execute Programs")); | 241 | ExecWidget *exec_w = new ExecWidget( _pppdata, tabWindow, isnewaccount, tr("Execute Programs")); |
270 | tabWindow->addTab( exec_w, tr("Execute") ); | 242 | tabWindow->addTab( exec_w, tr("Execute") ); |
271 | 243 | ||
272 | int result = 0; | 244 | int result = 0; |
273 | bool ok = false; | 245 | bool ok = false; |
274 | 246 | ||
275 | while (!ok){ | 247 | while (!ok){ |
276 | // dlg->showMinimized(); | 248 | // dlg->showMinimized(); |
277 | result = dlg->exec(); | 249 | result = dlg->exec(); |
278 | ok = true; | 250 | ok = true; |
279 | 251 | ||
280 | if(result == QDialog::Accepted) { | 252 | if(result == QDialog::Accepted) { |
281 | if (!script_w->check()){ | 253 | if (!auth_w->check()){ |
282 | QMessageBox::critical(this, "error", tr("<qt>Login script has unbalanced loop Start/End<qt>")); | ||
283 | ok = false; | 254 | ok = false; |
284 | } else if(!dial_w->save()) { | 255 | } else if(!dial_w->save()) { |
285 | QMessageBox::critical(this, "error", tr( "You must enter a unique account name")); | 256 | QMessageBox::critical(this, "error", tr( "You must enter a unique account name")); |
286 | ok = false; | 257 | ok = false; |
287 | }else{ | 258 | }else{ |
288 | ip_w->save(); | 259 | ip_w->save(); |
289 | dns_w->save(); | 260 | dns_w->save(); |
290 | gateway_w->save(); | 261 | gateway_w->save(); |
291 | script_w->save(); | 262 | auth_w->save(); |
292 | exec_w->save(); | 263 | exec_w->save(); |
293 | } | 264 | } |
294 | } | 265 | } |
295 | } | 266 | } |
296 | 267 | ||
297 | delete dlg; | 268 | delete dlg; |
298 | 269 | ||
299 | return result; | 270 | return result; |
300 | } | 271 | } |
301 | 272 | ||
302 | 273 | ||
303 | QString AccountWidget::prettyPrintVolume(unsigned int n) { | 274 | QString AccountWidget::prettyPrintVolume(unsigned int n) { |