summaryrefslogtreecommitdiff
path: root/library/proxies.cpp
Unidiff
Diffstat (limited to 'library/proxies.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/proxies.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/library/proxies.cpp b/library/proxies.cpp
new file mode 100644
index 0000000..eff943e
--- a/dev/null
+++ b/library/proxies.cpp
@@ -0,0 +1,118 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "proxies.h"
22#include "proxiesbase_p.h"
23#include "config.h"
24
25#include <qcombobox.h>
26#include <qlineedit.h>
27#include <qframe.h>
28#include <qvalidator.h>
29#include <qspinbox.h>
30#include <qradiobutton.h>
31
32Proxies::Proxies( QWidget* parent ) :
33 QVBox(parent)
34{
35 d = new ProxiesBase( this );
36 connect(d->type,SIGNAL(activated(int)),this,SLOT(typeChanged(int)));
37}
38
39void Proxies::typeChanged(int t)
40{
41 switch (t) {
42 case 0: d->autopanel->hide(); d->setpanel->hide(); break;
43 case 1: d->setpanel->hide(); d->autopanel->show(); break;
44 case 2: d->autopanel->hide(); d->setpanel->show(); break;
45 }
46}
47
48class ProxyValidator : public QValidator {
49public:
50 ProxyValidator( QWidget * parent, const char *name = 0 ) :
51 QValidator(parent,name)
52 {
53 }
54
55 State validate( QString &s, int &pos ) const
56 {
57 int i;
58 for (i=0; i<(int)s.length(); i++) {
59 if ( s[i] == ',' || s[i] == ';' || s[i] == '\n' || s[i] == '\r' )
60 s[i] = ' ';
61 }
62 for (i=0; i<(int)s.length()-1; ) {
63 if ( s[i] == ' ' && s[i+1] == ' ' ) {
64 if (pos>i) pos--;
65 s = s.left(i)+s.mid(i+2);
66 } else
67 i++;
68 }
69 return Valid;
70 }
71};
72
73void Proxies::readConfig(Config& cfg)
74{
75 int t = cfg.readNumEntry("type",0);
76 d->type->setCurrentItem(t);
77 typeChanged(t);
78
79 QString s;
80
81 s = cfg.readEntry("autoconfig");
82 if ( !s.isEmpty() )
83 d->autoconfig->insertItem(s);
84
85
86 s = cfg.readEntry("httphost");
87 if ( !s.isEmpty() )
88 d->httphost->setText(s);
89
90 int i;
91 i = cfg.readNumEntry("httpport");
92 if ( i>0 )
93 d->httpport->setValue(i);
94
95 s = cfg.readEntry("ftphost");
96 if ( !s.isEmpty() )
97 d->ftphost->setText(s);
98
99 i = cfg.readNumEntry("ftpport");
100 if ( i>0 )
101 d->ftpport->setValue(i);
102
103 s = cfg.readEntry("noproxies");
104 d->noproxies->setValidator(new ProxyValidator(this));
105 d->noproxies->setText(s);
106}
107
108void Proxies::writeConfig( Config &cfg )
109{
110 cfg.writeEntry("type",d->type->currentItem());
111 cfg.writeEntry("autoconfig", d->autoconfig->currentText());
112 cfg.writeEntry("httphost", d->httphost->text());
113 cfg.writeEntry("httpport", d->httpport->text());
114 cfg.writeEntry("ftphost", d->ftphost->text());
115 cfg.writeEntry("ftpport", d->ftpport->text());
116 cfg.writeEntry("noproxies", d->noproxies->text());
117}
118