summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/accounts.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/accounts.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/accounts.cpp158
1 files changed, 62 insertions, 96 deletions
diff --git a/noncore/settings/networksettings/ppp/accounts.cpp b/noncore/settings/networksettings/ppp/accounts.cpp
index fa1c43b..28d8732 100644
--- a/noncore/settings/networksettings/ppp/accounts.cpp
+++ b/noncore/settings/networksettings/ppp/accounts.cpp
@@ -44,102 +44,66 @@
44 44
45void parseargs(char* buf, char** args); 45void parseargs(char* buf, char** args);
46 46
47AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name ) 47
48 : QWidget( parent, name )//, _pppdata(pd) 48AccountWidget::AccountWidget( PPPData *pd, QWidget *parent, const char *name, WFlags f )
49 : ChooserWidget( pd, parent, name, f )
49{ 50{
50 _pppdata = pd;
51 QVBoxLayout *l1 = new QVBoxLayout(this, 10, 10);
52 accountlist_l = new QListBox(this);
53
54 connect(accountlist_l, SIGNAL(highlighted(int)),
55 this, SLOT(slotListBoxSelect(int)));
56 connect(accountlist_l, SIGNAL(selected(int)),
57 this, SLOT(editaccount()));
58 l1->addWidget(accountlist_l, 10);
59
60 edit_b = new QPushButton(tr("&Edit..."), this);
61 connect(edit_b, SIGNAL(clicked()), SLOT(editaccount()));
62 QWhatsThis::add(edit_b, tr("Allows you to modify the selected account"));
63 l1->addWidget(edit_b);
64 51
65 new_b = new QPushButton(tr("&New..."), this); 52 QWhatsThis::add(edit_b, tr("Allows you to modify the selected account"));
66 connect(new_b, SIGNAL(clicked()), SLOT(newaccount()));
67 l1->addWidget(new_b);
68 QWhatsThis::add(new_b, tr("Create a new dialup connection\n" 53 QWhatsThis::add(new_b, tr("Create a new dialup connection\n"
69 "to the Internet")); 54 "to the Internet"));
70
71 copy_b = new QPushButton(tr("Co&py"), this);
72 connect(copy_b, SIGNAL(clicked()), SLOT(copyaccount()));
73 l1->addWidget(copy_b);
74 QWhatsThis::add(copy_b, 55 QWhatsThis::add(copy_b,
75 tr("Makes a copy of the selected account. All\n" 56 tr("Makes a copy of the selected account. All\n"
76 "settings of the selected account are copied\n" 57 "settings of the selected account are copied\n"
77 "to a new account, that you can modify to fit your\n" 58 "to a new account, that you can modify to fit your\n"
78 "needs")); 59 "needs"));
79
80 delete_b = new QPushButton(tr("De&lete"), this);
81 connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount()));
82 l1->addWidget(delete_b);
83 QWhatsThis::add(delete_b, 60 QWhatsThis::add(delete_b,
84 tr("<p>Deletes the selected account\n\n" 61 tr("<p>Deletes the selected account\n\n"
85 "<font color=\"red\"><b>Use with care!</b></font>")); 62 "<font color=\"red\"><b>Use with care!</b></font>"));
86 63
87 QHBoxLayout *l12 = new QHBoxLayout;
88 l1->addStretch(1);
89 l1->addLayout(l12);
90 64
91 int currAccId = _pppdata->currentAccountID();
92 qDebug("currentAccountID %i", currAccId);
93 65
94 //load up account list from gppdata to the list box 66 copy_b->setEnabled( false ); //FIXME
95 if(_pppdata->count() > 0) { 67 // delete_b->setEnabled( false ); //FIXME
96 for(int i=0; i <= _pppdata->count()-1; i++) {
97 _pppdata->setAccountbyIndex(i);
98 accountlist_l->insertItem(_pppdata->accname());
99 }
100 }
101 _pppdata->setAccountbyIndex( currAccId );
102 68
103 qDebug("setting listview index to %i",_pppdata->currentAccountID() ); 69 listListbox->insertStringList(_pppdata->getAccountList());
104 accountlist_l->setCurrentItem( _pppdata->currentAccountID() );
105 slotListBoxSelect( _pppdata->currentAccountID() );
106 70
107 l1->activate(); 71 for (uint i = 0; i < listListbox->count(); i++){
72 if ( listListbox->text(i) == _pppdata->accname() )
73 listListbox->setCurrentItem( i );
74 }
108} 75}
109 76
110 77
111 78
112void AccountWidget::slotListBoxSelect(int idx) { 79void AccountWidget::slotListBoxSelect(int idx) {
113 delete_b->setEnabled((bool)(idx != -1)); 80 bool ok = _pppdata->setAccount( listListbox->text(idx) );
114 edit_b->setEnabled((bool)(idx != -1)); 81 ok = (bool)(idx != -1);
115 copy_b->setEnabled((bool)(idx != -1)); 82 delete_b->setEnabled(ok);
116 if(idx!=-1) { 83 edit_b->setEnabled(ok);
117 qDebug("setting account to %i", idx); 84//FIXME copy_b->setEnabled(ok);
118 QString account = _pppdata->accname();
119 _pppdata->setAccountbyIndex(accountlist_l->currentItem());
120 }
121} 85}
122 86
123void AccountWidget::editaccount() { 87void AccountWidget::edit() {
124 _pppdata->setAccount(accountlist_l->text(accountlist_l->currentItem())); 88 _pppdata->setAccount(listListbox->text(listListbox->currentItem()));
125 89
126 int result = doTab(); 90 int result = doTab();
127 91
128 if(result == QDialog::Accepted) { 92 if(result == QDialog::Accepted) {
129 accountlist_l->changeItem(_pppdata->accname(),accountlist_l->currentItem()); 93 listListbox->changeItem(_pppdata->accname(),listListbox->currentItem());
130// emit resetaccounts(); 94// emit resetaccounts();
131 _pppdata->save(); 95 _pppdata->save();
132 } 96 }
133} 97}
134 98
135 99
136void AccountWidget::newaccount() { 100void AccountWidget::create() {
137 101
138 if(accountlist_l->count() == MAX_ACCOUNTS) { 102// if(listListbox->count() == MAX_ACCOUNTS) {
139 QMessageBox::information(this, "sorry", 103// QMessageBox::information(this, "sorry",
140 tr("Maximum number of accounts reached.")); 104// tr("Maximum number of accounts reached."));
141 return; 105// return;
142 } 106// }
143 107
144 int result; 108 int result;
145 if (_pppdata->newaccount() == -1){ 109 if (_pppdata->newaccount() == -1){
@@ -149,8 +113,8 @@ void AccountWidget::newaccount() {
149 result = doTab(); 113 result = doTab();
150 114
151 if(result == QDialog::Accepted) { 115 if(result == QDialog::Accepted) {
152 accountlist_l->insertItem(_pppdata->accname()); 116 listListbox->insertItem(_pppdata->accname());
153 accountlist_l->setSelected(accountlist_l->findItem(_pppdata->accname()),true); 117 listListbox->setSelected(listListbox->findItem(_pppdata->accname()),true);
154 118
155 _pppdata->save(); 119 _pppdata->save();
156 } else 120 } else
@@ -158,53 +122,55 @@ void AccountWidget::newaccount() {
158} 122}
159 123
160 124
161void AccountWidget::copyaccount() { 125void AccountWidget::copy() {
162 if(accountlist_l->count() == MAX_ACCOUNTS) { 126// if(listListbox->count() == MAX_ACCOUNTS) {
163 QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached.")); 127// QMessageBox::information(this, "sorry", tr("Maximum number of accounts reached."));
164 return; 128// return;
165 } 129// }
166 130
167 if(accountlist_l->currentItem()<0) { 131 if(listListbox->currentItem()<0) {
168 QMessageBox::information(this, "sorry", tr("No account selected.")); 132 QMessageBox::information(this, "sorry", tr("No account selected."));
169 return; 133 return;
170 } 134 }
171 135
172 _pppdata->copyaccount(accountlist_l->currentItem()); 136 _pppdata->copyaccount(listListbox->currentText());
173 137
174 accountlist_l->insertItem(_pppdata->accname()); 138 listListbox->insertItem(_pppdata->accname());
175// emit resetaccounts(); 139// emit resetaccounts();
176 _pppdata->save(); 140 _pppdata->save();
177} 141}
178 142
179 143
180void AccountWidget::deleteaccount() { 144void AccountWidget::remove() {
181 145
182 QString s = tr("Are you sure you want to delete\nthe account \"%1\"?") 146 QString s = tr("Are you sure you want to delete\nthe account \"%1\"?")
183 .arg(accountlist_l->text(accountlist_l->currentItem())); 147 .arg(listListbox->text(listListbox->currentItem()));
184 148
185 if(QMessageBox::warning(this,tr("Confirm"),s, 149 if(QMessageBox::warning(this,tr("Confirm"),s,
186 QMessageBox::Yes,QMessageBox::No 150 QMessageBox::Yes,QMessageBox::No
187 ) != QMessageBox::Yes) 151 ) != QMessageBox::Yes)
188 return; 152 return;
189 153
190 if(_pppdata->deleteAccount(accountlist_l->text(accountlist_l->currentItem()))) 154 if(_pppdata->deleteAccount(listListbox->text(listListbox->currentItem())))
191 accountlist_l->removeItem(accountlist_l->currentItem()); 155 listListbox->removeItem(listListbox->currentItem());
192 156
193 emit resetaccounts();
194 _pppdata->save();
195 157
196 slotListBoxSelect(accountlist_l->currentItem()); 158// emit resetaccounts();
159// _pppdata->save();
160
161
162 slotListBoxSelect(listListbox->currentItem());
197 163
198} 164}
199 165
200 166
201int AccountWidget::doTab(){ 167int AccountWidget::doTab(){
202 QDialog *dlg = new QDialog( 0, "newAccount", true ); 168 QDialog *dlg = new QDialog( 0, "newAccount", true, Qt::WStyle_ContextHelp );
203 QVBoxLayout *layout = new QVBoxLayout( dlg ); 169 QVBoxLayout *layout = new QVBoxLayout( dlg );
204 layout->setSpacing( 0 ); 170 layout->setSpacing( 0 );
205 layout->setMargin( 1 ); 171 layout->setMargin( 1 );
206 172
207 tabWindow = new QTabWidget( dlg, "tabWindow" ); 173 QTabWidget *tabWindow = new QTabWidget( dlg, "tabWindow" );
208 layout->addWidget( tabWindow ); 174 layout->addWidget( tabWindow );
209 175
210 bool isnewaccount; 176 bool isnewaccount;
@@ -273,25 +239,25 @@ int AccountWidget::doTab(){
273} 239}
274 240
275 241
276QString AccountWidget::prettyPrintVolume(unsigned int n) { 242// QString AccountWidget::prettyPrintVolume(unsigned int n) {
277 int idx = 0; 243// int idx = 0;
278 const QString quant[] = {tr("Byte"), tr("KB"), 244// const QString quant[] = {tr("Byte"), tr("KB"),
279 tr("MB"), tr("GB"), QString::null}; 245 // tr("MB"), tr("GB"), QString::null};
280 246
281 float n1 = n; 247// float n1 = n;
282 while(n >= 1024 && quant[idx] != QString::null) { 248// while(n >= 1024 && quant[idx] != QString::null) {
283 idx++; 249// idx++;
284 n /= 1024; 250// n /= 1024;
285 } 251// }
286 252
287 int i = idx; 253// int i = idx;
288 while(i--) 254// while(i--)
289 n1 = n1 / 1024.0; 255// n1 = n1 / 1024.0;
290 256
291 QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); 257// QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 );
292 s += " " + quant[idx]; 258// s += " " + quant[idx];
293 return s; 259// return s;
294} 260// }
295 261
296 262
297///////////////////////////////////////////////////////////////////////////// 263/////////////////////////////////////////////////////////////////////////////