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