3 // Copyright (C) 2001 Neil Stevens <multivac@fcmail.com>
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // Except as contained in this notice, the name(s) of the author(s) shall not be
23 // used in advertising or otherwise to promote the sale, use or other dealings
24 // in this Software without prior written authorization from the author(s).
31 #include <kio/netaccess.h>
35 class KLoader::KLoaderPrivate
38 KLoaderPrivate() : isLocal(true), file(0), textStream(0), dataStream(0) {};
50 QTextStream
*textStream
;
51 QDataStream
*dataStream
;
54 KLoader::KLoader(const KURL
&target
)
56 d
= new KLoaderPrivate
;
59 if(d
->url
.protocol() == "file")
62 d
->file
= new QFile(d
->url
.path());
76 bool KLoader::open(void)
80 if(!d
->file
->open(IO_ReadOnly
))
82 d
->error
= i18n("Could not read from %1.").arg(d
->url
.prettyURL());
88 if(!KIO::NetAccess::download(d
->url
, d
->tempFile
))
90 d
->error
= i18n("Could not read from %1.").arg(d
->url
.prettyURL());
94 d
->file
= new QFile(d
->tempFile
);
95 if(!d
->file
->open(IO_ReadOnly
))
97 d
->error
= i18n("Could not read from %1.").arg(d
->tempFile
);
104 void KLoader::close(void)
113 KIO::NetAccess::removeTempFile(d
->tempFile
);
116 QString
KLoader::error(void)
121 QFile
&KLoader::file(void)
126 return *static_cast<QFile
*>(0);
129 QTextStream
&KLoader::textStream()
133 return *d
->textStream
;
137 d
->textStream
= new QTextStream(d
->file
);
138 return *d
->textStream
;
142 return *static_cast<QTextStream
*>(0);
146 QDataStream
&KLoader::dataStream()
150 return *d
->dataStream
;
154 d
->dataStream
= new QDataStream(d
->file
);
155 return *d
->dataStream
;
159 return *static_cast<QDataStream
*>(0);