Qtopia library API Documentation

proxies.cpp

00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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 
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001