00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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
00108
00109 QStringList arglist(_pppdata->pppdArgument());
00110
00111
00112 _pppdata->setpppdArgumentDefaults();
00113 init();
00114
00115
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