Diffstat (limited to 'noncore/net/ubrowser/httpfactory.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/ubrowser/httpfactory.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/noncore/net/ubrowser/httpfactory.cpp b/noncore/net/ubrowser/httpfactory.cpp new file mode 100644 index 0000000..92718fb --- a/dev/null +++ b/noncore/net/ubrowser/httpfactory.cpp | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing | ||
3 | Copyright (C) 2002 Thomas Stephens | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | ||
7 | version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
11 | Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | ||
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | */ | ||
16 | |||
17 | #include "httpfactory.h" | ||
18 | |||
19 | HttpFactory::HttpFactory(QTextBrowser *newBrowser):QMimeSourceFactory() | ||
20 | { | ||
21 | socket = new QSocket; | ||
22 | text = new QTextDrag; | ||
23 | browser=newBrowser; | ||
24 | comm = new HttpComm(socket, browser); | ||
25 | } | ||
26 | |||
27 | const QMimeSource * HttpFactory::data(const QString &abs_name) const | ||
28 | { | ||
29 | printf("HttpFactory::data: using absolute data func\n"); | ||
30 | |||
31 | int port=80, addrEnd, portSep; | ||
32 | QString host, file, portS, name, tempString; | ||
33 | bool done=false; | ||
34 | |||
35 | comm->setUp((QString *)&abs_name); | ||
36 | |||
37 | name = abs_name; | ||
38 | //name = name.lower(); | ||
39 | name = name.stripWhiteSpace(); | ||
40 | |||
41 | printf("%s\n", name.latin1()); | ||
42 | |||
43 | if(name.startsWith("http://")) | ||
44 | { | ||
45 | name = name.remove(0, 7); | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | addrEnd = name.find('/'); | ||
53 | if(addrEnd == -1) | ||
54 | { | ||
55 | name += '/'; | ||
56 | addrEnd = name.length()-1; | ||
57 | } | ||
58 | |||
59 | host = name; | ||
60 | file = name; | ||
61 | |||
62 | host.truncate(addrEnd); | ||
63 | file.remove(0, addrEnd); | ||
64 | |||
65 | portSep = host.find(':'); | ||
66 | if(portSep != -1) | ||
67 | { | ||
68 | portS=host; | ||
69 | host.truncate(portSep); | ||
70 | portS.remove(0, portSep+1); | ||
71 | port = portS.toInt(); | ||
72 | } | ||
73 | |||
74 | printf("%s %s %d\n", host.latin1(), file.latin1(), port); | ||
75 | |||
76 | if(port == 80) | ||
77 | { | ||
78 | portS="80"; | ||
79 | } | ||
80 | |||
81 | comm->setStuff(host, portS, file, text); | ||
82 | |||
83 | socket->connectToHost(host, port); | ||
84 | |||
85 | text->setText(""); | ||
86 | |||
87 | return text; | ||
88 | } | ||
89 | |||
90 | const QMimeSource * HttpFactory::data(const QString &abs_or_rel_name, const QString & context) const | ||
91 | { | ||
92 | printf("HttpFactory::data: using relative data func\n"); | ||
93 | |||
94 | if(abs_or_rel_name.startsWith(context)) | ||
95 | { | ||
96 | return data(abs_or_rel_name); | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | return data(context + abs_or_rel_name); | ||
101 | } | ||
102 | |||
103 | return 0; | ||
104 | } | ||