diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-10 00:18:25 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-10 00:18:25 +0000 |
commit | f21e5792b5084f5d008bf46f6316030c6dfb31e5 (patch) | |
tree | d51583b36aa1672bac78d98a682cdc330df27e4d /file-integration/basketthumbcreator.cpp | |
download | basket-f21e5792b5084f5d008bf46f6316030c6dfb31e5.tar.gz basket-f21e5792b5084f5d008bf46f6316030c6dfb31e5.zip |
Add author-abandoned basket application
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/basket@1072339 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'file-integration/basketthumbcreator.cpp')
-rw-r--r-- | file-integration/basketthumbcreator.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/file-integration/basketthumbcreator.cpp b/file-integration/basketthumbcreator.cpp new file mode 100644 index 0000000..afad656 --- /dev/null +++ b/file-integration/basketthumbcreator.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + * Copyright (C) 2006 by Sébastien Laoût * + * [email protected] * + * * + * 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <qstringlist.h> +#include <qdir.h> +#include <qfile.h> +#include <qfileinfo.h> +#include <qtextstream.h> +#include <ktempdir.h> + +#include "basketthumbcreator.h" + +bool BasketThumbCreator::create(const QString &path, int /*width*/, int /*height*/, QImage &image) +{ + // Create the temporar folder: + KTempDir tempDir; + tempDir.setAutoDelete(true); + QString tempFolder = tempDir.name(); + QDir dir; + dir.mkdir(tempFolder); + const Q_ULONG BUFFER_SIZE = 1024; + + QFile file(path); + if (file.open(IO_ReadOnly)) { + QTextStream stream(&file); + stream.setEncoding(QTextStream::Latin1); + QString line = stream.readLine(); + if (line != "BasKetNP:archive" && line != "BasKetNP:template") { + file.close(); + return false; + } + while (!stream.atEnd()) { + // Get Key/Value Pair From the Line to Read: + line = stream.readLine(); + int index = line.find(':'); + QString key; + QString value; + if (index >= 0) { + key = line.left(index); + value = line.right(line.length() - index - 1); + } else { + key = line; + value = ""; + } + if (key == "preview*") { + bool ok; + ulong size = value.toULong(&ok); + if (!ok) { + file.close(); + return false; + } + // Get the preview file: + QFile previewFile(tempFolder + "preview.png"); + if (previewFile.open(IO_WriteOnly)) { + char *buffer = new char[BUFFER_SIZE]; + Q_LONG sizeRead; + while ((sizeRead = file.readBlock(buffer, QMIN(BUFFER_SIZE, size))) > 0) { + previewFile.writeBlock(buffer, sizeRead); + size -= sizeRead; + } + previewFile.close(); + delete buffer; + image = QImage(tempFolder + "preview.png"); + file.close(); + return true; + } + } else if (key.endsWith("*")) { + // We do not know what it is, but we should read the embedded-file in order to discard it: + bool ok; + ulong size = value.toULong(&ok); + if (!ok) { + file.close(); + return false; + } + // Get the archive file: + char *buffer = new char[BUFFER_SIZE]; + Q_LONG sizeRead; + while ((sizeRead = file.readBlock(buffer, QMIN(BUFFER_SIZE, size))) > 0) { + size -= sizeRead; + } + delete buffer; + } + } + file.close(); + } + return false; +} + +ThumbCreator::Flags BasketThumbCreator::flags() const +{ + return (Flags) (DrawFrame | BlendIcon); +} + +extern "C" +{ + ThumbCreator *new_creator() + { + return new BasketThumbCreator(); + } +}; |