karchive and QSaveFile (fwd)
David Faure
faure at kde.org
Sat Apr 1 19:57:15 UTC 2017
On mercredi 29 mars 2017 14:40:10 CEST Boudewijn Rempt wrote:
> Hi,
>
> I'm trying to make Krita use QSaveFile instead of the home-grown
> mess of temporary files that get copied over the original file
> after saving succeeded. The problem is that Krita, like Calligra,
> uses KArchive. And KArchive, even when a KZip is created with
> an existing QIODevice, decides on its own to call close(), which
> is not allowed with QSaveFile.
>
> I've tried to set KZip's io device to 0 just before closing the
> kzip, but that means the zip file doesn't get written correctly.
> I've got a hack around that... I've made a tiny subclass of KZip:
>
> class SaveZip : public KZip {
> public:
> SaveZip(const QString &filename) : KZip(filename) {}
> SaveZip(QIODevice *dev) : KZip(dev) {}
> virtual ~SaveZip() {}
> void resetDevice() {
> closeArchive();
> setDevice(0);
> }
> };
>
>
> And call resetDevice before deleting or closing the kzip instance
> in KoStore.
>
> But that's a hack, and I'm now wondering whether to hack QSaveFile's
> close() to just not abort, or add inherits("QSaveFile") checks all
> over KArchive -- or whether there's a third, better option that I've
> missed...
Oh.
Yes I think a qobject_cast<QSaveFile *>(device) might be necessary in
KArchive, in order to call commit() rather than close().
That would work, right?
Feel like adding a unittest for this?
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5
More information about the Kde-frameworks-devel
mailing list