Source Code (Use browser search to find items of interest.)

Class Index

kppp'AccountWidget (./kdenetwork/kppp/accounts.h:44)

class AccountWidget : public KGroupBox {
  Q_OBJECT
public:
  AccountWidget( QWidget *parent=0, const char *name=0 );
  ~AccountWidget() {}

private slots:
  void editaccount();
  void editaccount(int);
  void copyaccount();
  void newaccount();
  void deleteaccount();
  void slotListBoxSelect(int);
  void resetClicked();
  void viewLogClicked();

private:
  int doTab();

signals:
  void resetaccounts();
  void resetCosts(const QString &);
  void resetVolume(const QString &);

private:
  QString prettyPrintVolume(unsigned int);

  QTabDialog *tabWindow;
  DialWidget *dial_w;
  AccountingSelector *acct;
  IPWidget *ip_w;
  DNSWidget *dns_w;
  GatewayWidget *gateway_w;
  ScriptWidget *script_w;

  QPushButton *reset;
  QPushButton *log;
  QLabel *costlabel;
  QLineEdit *costedit;
  QLabel *vollabel;
  QLineEdit *voledit;

  QListBox *accountlist_l;
  QPushButton *edit_b;
  QPushButton *copy_b;
  QPushButton *new_b;
  QPushButton *delete_b;
};



kppp'AccountWidget::AccountWidget() (./kdenetwork/kppp/accounts.cpp:49)

AccountWidget::AccountWidget( QWidget *parent, const char *name )
  : KGroupBox( i18n("Account Setup"), parent, name )
{
  int min = 0;
  QVBoxLayout *l1 = new QVBoxLayout(peer(), 10, 10);

  // add a hbox
  QHBoxLayout *l11 = new QHBoxLayout;
  l1->addLayout(l11);
    
  accountlist_l = new QListBox(peer());
  accountlist_l->setMinimumSize(160, 128);
  connect(accountlist_l, SIGNAL(highlighted(int)),
	  this, SLOT(slotListBoxSelect(int)));
  connect(accountlist_l, SIGNAL(selected(int)),
	  this, SLOT(editaccount()));
  l11->addWidget(accountlist_l, 10);

  QVBoxLayout *l111 = new QVBoxLayout;
  l11->addLayout(l111, 1);  
  edit_b = new QPushButton(i18n("Edit..."), peer());
  connect(edit_b, SIGNAL(clicked()), SLOT(editaccount()));
  QWhatsThis::add(edit_b, i18n("Allows you to modify the selected account"));

  min = edit_b->sizeHint().width();
  min = QMAX(70,min);
  edit_b->setMinimumWidth(min);

  l111->addWidget(edit_b);

  new_b = new QPushButton(i18n("New..."), peer());
  connect(new_b, SIGNAL(clicked()), SLOT(newaccount()));
  l111->addWidget(new_b);
  QWhatsThis::add(new_b, i18n("Create a new dialup connection\n"
  			      "to the internet"));

  copy_b = new QPushButton(i18n("Copy"), peer());
  connect(copy_b, SIGNAL(clicked()), SLOT(copyaccount()));
  l111->addWidget(copy_b);
  QWhatsThis::add(copy_b, 
		  i18n("Makes a copy of the selected account. All\n"
		       "settings of the selected account are copied\n"
		       "to a new account, that you can modify to fit your\n"
		       "needs"));

  delete_b = new QPushButton(i18n("Delete"), peer());
  connect(delete_b, SIGNAL(clicked()), SLOT(deleteaccount()));
  l111->addWidget(delete_b);
  QWhatsThis::add(delete_b, 
		  i18n("Deletes the selected account\n\n<red><b>Use with care!"));

  QHBoxLayout *l12 = new QHBoxLayout;
  l1->addStretch(1);
  l1->addLayout(l12);

  QVBoxLayout *l121 = new QVBoxLayout;
  l12->addLayout(l121);
  l121->addStretch(1);
  costlabel = new QLabel(i18n("Phone Costs:"), peer());
  costlabel->setEnabled(FALSE);
  l121->addWidget(costlabel);

  costedit = new QLineEdit(peer());
  costedit->setFocusPolicy(QWidget::NoFocus);
  costedit->setFixedHeight(costedit->sizeHint().height());
  costedit->setEnabled(FALSE);
  l121->addWidget(costedit);
  l121->addStretch(1);
  QString tmp = i18n("This shows the accumulated phone costs\n"
		     "for the selected account.\n"
		     "\n"
		     "<b>Important</b>: If you have more than one \n"
		     "account - beware, this is <b>NOT</b> the sum \n"
		     "of the phone costs of all your accounts!");
  QWhatsThis::add(costlabel, tmp);
  QWhatsThis::add(costedit, tmp);

  vollabel = new QLabel(i18n("Volume:"), peer());
  vollabel->setEnabled(FALSE);
  l121->addWidget(vollabel);

  voledit = new QLineEdit(peer(),"voledit");
  voledit->setFocusPolicy(QWidget::NoFocus);
  voledit->setFixedHeight(voledit->sizeHint().height());
  voledit->setEnabled(FALSE);
  l121->addWidget(voledit);
  tmp = i18n("This shows the number of bytes transferred\n"
	     "for the selected account (not for all of your\n"
	     "accounts. You can select what to display in\n"
	     "the accounting dialog.\n"
	     "\n"
	     "<link #volaccounting>More on volume accounting</link>");

  QWhatsThis::add(vollabel,tmp);
  QWhatsThis::add(voledit, tmp);

  QVBoxLayout *l122 = new QVBoxLayout;
  l12->addStretch(1);
  l12->addLayout(l122);
  
  l122->addStretch(1);
  reset = new QPushButton(i18n("Reset..."), peer());
  reset->setEnabled(FALSE);
  connect(reset, SIGNAL(clicked()),
	  this, SLOT(resetClicked()));
  l122->addWidget(reset);

  log = new QPushButton(i18n("View Logs"), peer());
  connect(log, SIGNAL(clicked()),
	  this, SLOT(viewLogClicked()));
  l122->addWidget(log);
  l122->addStretch(1);

  //load up account list from gppdata to the list box
  if(gpppdata.count() > 0) {
    for(int i=0; i <= gpppdata.count()-1; i++) {
      gpppdata.setAccountbyIndex(i);
      accountlist_l->insertItem(gpppdata.accname());
    }
  }

  slotListBoxSelect(accountlist_l->currentItem());

  l1->activate();
}




kppp'AccountWidget::slotListBoxSelect() (./kdenetwork/kppp/accounts.cpp:177)

void AccountWidget::slotListBoxSelect(int idx) {
  delete_b->setEnabled((bool)(idx != -1));
  edit_b->setEnabled((bool)(idx != -1));
  copy_b->setEnabled((bool)(idx != -1));
  if(idx!=-1) {
    QString account = gpppdata.accname();
    gpppdata.setAccountbyIndex(accountlist_l->currentItem());
    reset->setEnabled(TRUE);
    costlabel->setEnabled(TRUE);
    costedit->setEnabled(TRUE);
    costedit->setText(AccountingBase::getCosts(accountlist_l->text(accountlist_l->currentItem())));

    vollabel->setEnabled(TRUE);
    voledit->setEnabled(TRUE);
    int bytes = gpppdata.totalBytes();
    voledit->setText(prettyPrintVolume(bytes));
    gpppdata.setAccount(account);
 } else{
    reset->setEnabled(FALSE);
    costlabel->setEnabled(FALSE);
    costedit->setText("");
    costedit->setEnabled(FALSE);
    vollabel->setEnabled(FALSE);
    voledit->setText("");
    voledit->setEnabled(FALSE);
  }
}



kppp'AccountWidget::viewLogClicked() (./kdenetwork/kppp/accounts.cpp:206)

void AccountWidget::viewLogClicked(){

    QApplication::flushX();
    if(fork() == 0) {
      setgid(getgid());
      setuid(getuid());
      system("kppplogview -kppp");
      exit(0);
    }
}



kppp'AccountWidget::resetClicked() (./kdenetwork/kppp/accounts.cpp:218)

void AccountWidget::resetClicked(){
  if(accountlist_l->currentItem() == -1)
    return;

  QueryReset dlg(this);
  int what = dlg.exec();

  if(what && QueryReset::COSTS) {
    emit resetCosts(accountlist_l->text(accountlist_l->currentItem()));
    costedit->setText("0");
  }
  
  if(what && QueryReset::VOLUME) {
    emit resetVolume(accountlist_l->text(accountlist_l->currentItem()));
    voledit->setText(prettyPrintVolume(0));
  }
}



kppp'AccountWidget::editaccount() (./kdenetwork/kppp/accounts.cpp:237)

void AccountWidget::editaccount(int) {
  editaccount();
}



kppp'AccountWidget::editaccount() (./kdenetwork/kppp/accounts.cpp:242)

void AccountWidget::editaccount() {
  gpppdata.setAccount(accountlist_l->text(accountlist_l->currentItem()));

  int result = doTab();

  if(result == QDialog::Accepted) {
    accountlist_l->changeItem(gpppdata.accname(),accountlist_l->currentItem());
    emit resetaccounts();
    gpppdata.save();
  }
}



kppp'AccountWidget::newaccount() (./kdenetwork/kppp/accounts.cpp:255)

void AccountWidget::newaccount() {
  if(accountlist_l->count() == MAX_ACCOUNTS) {   
      KMessageBox::sorry(this, i18n("Maximum number of accounts reached."));
    return;
  }

  int result;
  int query = QMessageBox::information(this,
				   i18n("Create a new account..."),
   i18n("Do you want to use the wizard to create the new account or the\n"
	"standard, dialog-based setup?\n\n"
	"The wizard is easier and sufficient in most cases. If you need\n"
	"very special settings, you might want to try the standard,\n"
		"dialog-based setup.\n"), i18n("Wizard"), i18n("Dialog setup"), i18n("Cancel"));

  switch(query) {
  case 0: 
    {
      if (gpppdata.newaccount() == -1) 
	return;
      ProviderDB pdb(this);
      result = pdb.exec();
      break;
    }
  case 1:
    if (gpppdata.newaccount() == -1) 
      return;
    result = doTab();
    break;
  default:
    return;
  }

  if(result == QDialog::Accepted) {
    accountlist_l->insertItem(gpppdata.accname());
    emit resetaccounts();
    gpppdata.save();
  } else
    gpppdata.deleteAccount();  
}



kppp'AccountWidget::copyaccount() (./kdenetwork/kppp/accounts.cpp:297)

void AccountWidget::copyaccount() {
  if(accountlist_l->count() == MAX_ACCOUNTS) {
    KMessageBox::sorry(this, i18n("Maximum number of accounts reached."));
    return;
  }

  if(accountlist_l->currentItem()<0) {
    KMessageBox::sorry(this, i18n("No account selected."));
    return;
  }

  gpppdata.copyaccount(accountlist_l->currentItem());

  accountlist_l->insertItem(gpppdata.accname());
  emit resetaccounts();
  gpppdata.save();
}



kppp'AccountWidget::deleteaccount() (./kdenetwork/kppp/accounts.cpp:316)

void AccountWidget::deleteaccount() {

  QString s = i18n("Are you sure you want to delete\nthe account \"%1\"?")
    .arg(accountlist_l->text(accountlist_l->currentItem()));

  if(KMessageBox::warningYesNo(this, s, i18n("Confirm")) != KMessageBox::Yes)
    return;

  if(gpppdata.deleteAccount(accountlist_l->text(accountlist_l->currentItem())))
    accountlist_l->removeItem(accountlist_l->currentItem());

  emit resetaccounts();
  gpppdata.save();

  slotListBoxSelect(accountlist_l->currentItem());

}



kppp'AccountWidget::doTab() (./kdenetwork/kppp/accounts.cpp:335)

int AccountWidget::doTab(){
  tabWindow = new QTabDialog(0,0,TRUE);
  KWM::setMiniIcon(tabWindow->winId(), kapp->miniIcon());
  bool isnewaccount;
 
  if(gpppdata.accname().isEmpty()) {
    tabWindow->setCaption(i18n("New Account"));
    isnewaccount = true;
  } else {
    QString tit = i18n("Edit Account: ");
    tit += gpppdata.accname();
    tabWindow->setCaption(tit);
    isnewaccount = false;
  }

  tabWindow->resize( 360, 400 );
  tabWindow->setOKButton(i18n("OK"));
  tabWindow->setCancelButton(i18n("Cancel"));

  dial_w = new DialWidget(tabWindow, isnewaccount);
  ExecWidget *exec_w = new ExecWidget(tabWindow, isnewaccount);
  ip_w = new IPWidget(tabWindow, isnewaccount);
  dns_w = new DNSWidget(tabWindow, isnewaccount);
  gateway_w = new GatewayWidget(tabWindow, isnewaccount);
  script_w = new ScriptWidget(tabWindow, isnewaccount);
  acct = new AccountingSelector(tabWindow, isnewaccount);

  tabWindow->addTab(dial_w, i18n("Dial"));
  tabWindow->addTab(ip_w, i18n("IP"));
  tabWindow->addTab(gateway_w, i18n("Gateway"));
  tabWindow->addTab(dns_w, i18n("DNS"));
  tabWindow->addTab(script_w, i18n("Login Script"));
  tabWindow->addTab(exec_w, i18n("Execute"));
  tabWindow->addTab(acct, i18n("Accounting"));

  int result = 0;
  bool ok = false;
  while (!ok){

    result = tabWindow->exec();
    ok = true;

    if(result == QDialog::Accepted) {
      if (script_w->check()) {
          if(dial_w->save()) {
		ip_w->save();
		dns_w->save();
		gateway_w->save();
		script_w->save();
		exec_w->save();
		acct->save();
         } else {
	     KMessageBox::error(this, i18n( "You must enter an unique\n"
					    "account name"));
		ok = false;
	 }
      } else {
	      KMessageBox::error(this, i18n("Login script has unbalanced "
					    "loop Start/End"));
	      ok = false;
      }
    }
  }

 delete tabWindow;
 return result;
}



kppp'AccountWidget::prettyPrintVolume() (./kdenetwork/kppp/accounts.cpp:404)

QString AccountWidget::prettyPrintVolume(unsigned int n) {
  int idx = 0;
  const QString quant[] = {i18n("Byte"), i18n("KB"), 
		   i18n("MB"), i18n("GB"), QString::null};

  float n1 = n;
  while(n >= 1024 && quant[idx] != QString::null) {
    idx++;
    n /= 1024;
  }

  int i = idx;
  while(i--)
    n1 = n1 / 1024.0;

  QString s;
  if(idx==0)
    s.sprintf("%0.0f ", n1);
  else
    s.sprintf("%0.1f ", n1);
  s += quant[idx];
  return s;
}


/////////////////////////////////////////////////////////////////////////////
//
// Queries the user what to reset: costs, volume or both
//
/////////////////////////////////////////////////////////////////////////////