Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pppdargs.cpp

Go to the documentation of this file.
00001 /*
00002  *            kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: pppdargs.cpp,v 1.7 2004/03/02 12:21:30 alwin Exp $
00005  *
00006  *            Copyright (C) 1997 Bernd Johannes Wuebben
00007  *                   wuebben@math.cornell.edu
00008  *
00009  * based on EzPPP:
00010  * Copyright (C) 1997  Jay Painter
00011  *
00012  *
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Library General Public
00015  * License as published by the Free Software Foundation; either
00016  * version 2 of the License, or (at your option) any later version.
00017  *
00018  * This library is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  * Library General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU Library General Public
00024  * License along with this program; if not, write to the Free
00025  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00026  */
00027 
00028 #include <qlayout.h>
00029 #include <qbuttongroup.h>
00030 #include <qapplication.h>
00031 #include "pppdargs.h"
00032 #include "pppdata.h"
00033 
00034 
00035 PPPdArguments::PPPdArguments( PPPData *pd, QWidget *parent, const char *name)
00036     : QDialog(parent, name, TRUE), _pppdata(pd)
00037 {
00038   setCaption(tr("Customize pppd Arguments"));
00039 //  KWin::setIcons(winId(), kapp->icon(), kapp->miniIcon());
00040   QVBoxLayout *l = new QVBoxLayout(this, 10, 10);
00041   QHBoxLayout *tl = new QHBoxLayout(10);
00042   l->addLayout(tl);
00043   QVBoxLayout *l1 = new QVBoxLayout();
00044   QVBoxLayout *l2 = new QVBoxLayout();
00045   tl->addLayout(l1, 1);
00046   tl->addLayout(l2, 0);
00047 
00048   QHBoxLayout *l11 = new QHBoxLayout(10);
00049   l1->addLayout(l11);
00050 
00051   argument_label = new QLabel(tr("Argument:"), this);
00052   l11->addWidget(argument_label);
00053 
00054   argument = new QLineEdit(this);
00055   connect(argument, SIGNAL(returnPressed()),
00056           SLOT(addbutton()));
00057   l11->addWidget(argument);
00058   connect(argument, SIGNAL(textChanged(const QString&)),
00059           this, SLOT(textChanged(const QString&)));
00060 
00061   arguments = new QListBox(this);
00062   arguments->setMinimumSize(1, fontMetrics().lineSpacing()*10);
00063   connect(arguments, SIGNAL(highlighted(int)),
00064           this, SLOT(itemSelected(int)));
00065   l1->addWidget(arguments, 1);
00066 
00067   add = new QPushButton(tr("Add"), this);
00068   connect(add, SIGNAL(clicked()), SLOT(addbutton()));
00069   l2->addWidget(add);
00070   l2->addStretch(1);
00071 
00072   remove = new QPushButton(tr("Remove"), this);
00073   connect(remove, SIGNAL(clicked()), SLOT(removebutton()));
00074   l2->addWidget(remove);
00075 
00076   defaults = new QPushButton(tr("Defaults"), this);
00077   connect(defaults, SIGNAL(clicked()), SLOT(defaultsbutton()));
00078   l2->addWidget(defaults);
00079 
00080   l->addSpacing(5);
00081 
00082 
00083   //load info from gpppdata
00084   init();
00085 
00086   add->setEnabled(false);
00087   remove->setEnabled(false);
00088   argument->setFocus();
00089 }
00090 
00091 
00092 void PPPdArguments::addbutton() {
00093   if(!argument->text().isEmpty() && arguments->count() < MAX_PPPD_ARGUMENTS) {
00094     arguments->insertItem(argument->text());
00095     argument->setText("");
00096   }
00097 }
00098 
00099 
00100 void PPPdArguments::removebutton() {
00101   if(arguments->currentItem() >= 0)
00102     arguments->removeItem(arguments->currentItem());
00103 }
00104 
00105 
00106 void PPPdArguments::defaultsbutton() {
00107   // all of this is a hack
00108   // save current list
00109   QStringList arglist(_pppdata->pppdArgument());
00110 
00111   // get defaults
00112   _pppdata->setpppdArgumentDefaults();
00113   init();
00114 
00115   // restore old list
00116   _pppdata->setpppdArgument(arglist);
00117 }
00118 
00119 
00120 void PPPdArguments::accept() {
00121   QStringList arglist;
00122   for(uint i=0; i < arguments->count(); i++)
00123     arglist.append(arguments->text(i));
00124   _pppdata->setpppdArgument(arglist);
00125 
00126   QDialog::accept();
00127 }
00128 
00129 
00130 void PPPdArguments::init() {
00131   while(arguments->count())
00132     arguments->removeItem(0);
00133 
00134   QStringList &arglist = _pppdata->pppdArgument();
00135   for ( QStringList::Iterator it = arglist.begin();
00136         it != arglist.end();
00137         ++it )
00138     arguments->insertItem(*it);
00139 }
00140 
00141 
00142 void PPPdArguments::textChanged(const QString &s) {
00143   add->setEnabled(s.length() > 0);
00144 }
00145 
00146 
00147 void PPPdArguments::itemSelected(int idx) {
00148   remove->setEnabled(idx != -1);
00149 }
00150 
00151 

Generated on Sat Nov 5 16:17:51 2005 for OPIE by  doxygen 1.4.2