proxies.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "proxies.h"
00022 #include "proxiesbase_p.h"
00023 #include "config.h"
00024
00025 #include <qcombobox.h>
00026 #include <qlineedit.h>
00027 #include <qframe.h>
00028 #include <qvalidator.h>
00029 #include <qspinbox.h>
00030 #include <qradiobutton.h>
00031
00032 Proxies::Proxies( QWidget* parent ) :
00033 QVBox(parent)
00034 {
00035 d = new ProxiesBase( this );
00036 connect(d->type,SIGNAL(activated(int)),this,SLOT(typeChanged(int)));
00037 }
00038
00039 void Proxies::typeChanged(int t)
00040 {
00041 switch (t) {
00042 case 0: d->autopanel->hide(); d->setpanel->hide(); break;
00043 case 1: d->setpanel->hide(); d->autopanel->show(); break;
00044 case 2: d->autopanel->hide(); d->setpanel->show(); break;
00045 }
00046 }
00047
00048 class ProxyValidator : public QValidator {
00049 public:
00050 ProxyValidator( QWidget * parent, const char *name = 0 ) :
00051 QValidator(parent,name)
00052 {
00053 }
00054
00055 State validate( QString &s, int &pos ) const
00056 {
00057 int i;
00058 for (i=0; i<(int)s.length(); i++) {
00059 if ( s[i] == ',' || s[i] == ';' || s[i] == '\n' || s[i] == '\r' )
00060 s[i] = ' ';
00061 }
00062 for (i=0; i<(int)s.length()-1; ) {
00063 if ( s[i] == ' ' && s[i+1] == ' ' ) {
00064 if (pos>i) pos--;
00065 s = s.left(i)+s.mid(i+2);
00066 } else
00067 i++;
00068 }
00069 return Valid;
00070 }
00071 };
00072
00073 void Proxies::readConfig(Config& cfg)
00074 {
00075 int t = cfg.readNumEntry("type",0);
00076 d->type->setCurrentItem(t);
00077 typeChanged(t);
00078
00079 QString s;
00080
00081 s = cfg.readEntry("autoconfig");
00082 if ( !s.isEmpty() )
00083 d->autoconfig->insertItem(s);
00084
00085
00086 s = cfg.readEntry("httphost");
00087 if ( !s.isEmpty() )
00088 d->httphost->setText(s);
00089
00090 int i;
00091 i = cfg.readNumEntry("httpport");
00092 if ( i>0 )
00093 d->httpport->setValue(i);
00094
00095 s = cfg.readEntry("ftphost");
00096 if ( !s.isEmpty() )
00097 d->ftphost->setText(s);
00098
00099 i = cfg.readNumEntry("ftpport");
00100 if ( i>0 )
00101 d->ftpport->setValue(i);
00102
00103 s = cfg.readEntry("noproxies");
00104 d->noproxies->setValidator(new ProxyValidator(this));
00105 d->noproxies->setText(s);
00106 }
00107
00108 void Proxies::writeConfig( Config &cfg )
00109 {
00110 cfg.writeEntry("type",d->type->currentItem());
00111 cfg.writeEntry("autoconfig", d->autoconfig->currentText());
00112 cfg.writeEntry("httphost", d->httphost->text());
00113 cfg.writeEntry("httpport", d->httpport->text());
00114 cfg.writeEntry("ftphost", d->ftphost->text());
00115 cfg.writeEntry("ftpport", d->ftpport->text());
00116 cfg.writeEntry("noproxies", d->noproxies->text());
00117 }
00118
This file is part of the documentation for OPIE Version 1.5.5.