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 <ktempfile.h>
32
#include <kio/netaccess.h>
36
class KSaver::KSaverPrivate
39
KSaverPrivate() : isLocal(true), tempFile(0), file(0), textStream(0), dataStream(0) {};
45
QTextStream *textStream;
46
QDataStream *dataStream;
49
KSaver::KSaver(const KURL &_target)
51
d = new KSaverPrivate;
54
if(d->url.protocol() == "file")
57
d->file = new QFile(d->url.path());
71
bool KSaver::open(void)
75
if(d->file->open(IO_WriteOnly))
81
d->error = i18n("Could not write to %1.").arg(d->url.prettyURL());
87
d->tempFile = new KTempFile;
92
bool KSaver::close(void)
102
if(!d->file) return true;
110
if(!d->tempFile) return true;
112
d->tempFile->close();
114
bool retval = KIO::NetAccess::upload(d->tempFile->name(), d->url);
123
QString KSaver::error(void)
128
QFile &KSaver::file(void)
130
if(d->isLocal && d->file)
132
else if(!d->isLocal && d->tempFile)
133
return *d->tempFile->file();
135
return *static_cast<QFile *>(0);
138
QTextStream &KSaver::textStream()
142
return *d->textStream;
144
else if(d->isLocal && d->file)
146
d->textStream = new QTextStream(d->file);
147
return *d->textStream;
149
else if(!d->isLocal && d->tempFile)
151
d->textStream = d->tempFile->textStream();
152
return *d->textStream;
156
return *static_cast<QTextStream *>(0);
160
QDataStream &KSaver::dataStream()
164
return *d->dataStream;
166
else if(d->isLocal && d->file)
168
d->dataStream = new QDataStream(d->file);
169
return *d->dataStream;
171
else if(!d->isLocal && d->tempFile)
173
d->dataStream = d->tempFile->dataStream();
174
return *d->dataStream;
178
return *static_cast<QDataStream *>(0);