[tracker/harmattan-pre-signal-updates: 1370/1380] tracker-extract: Code cleanups for quill albumart implementation
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/harmattan-pre-signal-updates: 1370/1380] tracker-extract: Code cleanups for quill albumart implementation
- Date: Wed, 22 Sep 2010 15:49:27 +0000 (UTC)
commit 64f3bf9d458c46ce4451549c2e11c2404d86767b
Author: Martyn Russell <martyn lanedo com>
Date: Mon Sep 20 16:36:48 2010 +0100
tracker-extract: Code cleanups for quill albumart implementation
src/tracker-extract/tracker-albumart-quill.cpp | 106 ++++++++++++++++--------
1 files changed, 70 insertions(+), 36 deletions(-)
---
diff --git a/src/tracker-extract/tracker-albumart-quill.cpp b/src/tracker-extract/tracker-albumart-quill.cpp
index 2e59fe2..efaf29f 100644
--- a/src/tracker-extract/tracker-albumart-quill.cpp
+++ b/src/tracker-extract/tracker-albumart-quill.cpp
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2008, Nokia
+ * Copyright (C) 2010, Nokia
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -34,38 +34,53 @@
#include "tracker-albumart-generic.h"
+#define TRACKER_ALBUMART_QUILL_SAVE "org.maemo.save"
G_BEGIN_DECLS
-static gboolean init = FALSE;
-
gboolean
tracker_albumart_file_to_jpeg (const gchar *filename,
const gchar *target)
{
- if (!init) {
- init = TRUE;
+ QFile file (filename);
+
+ if (!file.open (QIODevice::ReadOnly)) {
+ g_message ("Could not get QFile from JPEG file:'%s'",
+ filename);
+ return FALSE;
}
- QFile file(filename);
- if (file.open(QIODevice::ReadOnly)) {
+ QByteArray array = file.readAll ();
+ QBuffer buffer (&array);
- QByteArray array = file.readAll();
- QBuffer buffer(&array);
- buffer.open(QIODevice::ReadOnly);
+ buffer.open (QIODevice::ReadOnly);
- QImageReader reader(&buffer);
+ QImageReader reader (&buffer);
- if (reader.canRead()) {
- QImage image = reader.read();
- QuillImageFilter *filter =
- QuillImageFilterFactory::createImageFilter("org.maemo.save");
- filter->setOption(QuillImageFilter::FileFormat, QVariant(QString("jpeg")));
- filter->setOption(QuillImageFilter::FileName, QVariant(QString(target)));
- filter->apply(image);
- delete filter;
- }
+ if (!reader.canRead ()) {
+ g_message ("Could not get QImageReader from JPEG file, canRead was FALSE");
+ return FALSE;
+ }
+
+ QImage image;
+ QuillImageFilter *filter;
+
+ image = reader.read ();
+ filter = QuillImageFilterFactory::createImageFilter (TRACKER_ALBUMART_QUILL_SAVE);
+
+ if (!filter) {
+ g_message ("Could not get QuillImageFilter from JPEG file using:'%s'",
+ TRACKER_ALBUMART_QUILL_SAVE);
+
+ return FALSE;
}
+
+ filter->setOption (QuillImageFilter::FileFormat, QVariant (QString ("jpeg")));
+ filter->setOption (QuillImageFilter::FileName, QVariant (QString (target)));
+ filter->apply (image);
+
+ delete filter;
+
return TRUE;
}
@@ -75,31 +90,50 @@ tracker_albumart_buffer_to_jpeg (const unsigned char *buffer,
const gchar *buffer_mime,
const gchar *target)
{
- if (!init) {
- init = TRUE;
- }
QImageReader *reader = NULL;
- QByteArray array = QByteArray ((const char *) buffer, (int) len);
- QBuffer qbuffer(&array);
- qbuffer.open(QIODevice::ReadOnly);
+ QByteArray array;
+
+ array = QByteArray ((const char *) buffer, (int) len);
+
+ QBuffer qbuffer (&array);
+ qbuffer.open (QIODevice::ReadOnly);
if (buffer_mime != NULL) {
- reader = new QImageReader::QImageReader (&qbuffer, QByteArray(buffer_mime));
+ reader = new QImageReader::QImageReader (&qbuffer, QByteArray (buffer_mime));
} else {
- QByteArray format = QImageReader::imageFormat(&qbuffer);
- if (!format.isEmpty ())
+ QByteArray format = QImageReader::imageFormat (&qbuffer);
+
+ if (!format.isEmpty ()) {
reader = new QImageReader::QImageReader (&qbuffer, format);
+ }
+ }
+
+ if (!reader) {
+ g_message ("Could not get QImageReader from JPEG buffer");
+ return FALSE;
}
- if (reader != NULL) {
- QImage image = reader->read();
- QuillImageFilter *filter = QuillImageFilterFactory::createImageFilter("org.maemo.save");
- filter->setOption(QuillImageFilter::FileFormat, QVariant(QString("jpeg")));
- filter->setOption(QuillImageFilter::FileName, QVariant(QString(target)));
- filter->apply(image);
+
+ QImage image;
+ QuillImageFilter *filter;
+
+ image = reader->read ();
+ filter = QuillImageFilterFactory::createImageFilter (TRACKER_ALBUMART_QUILL_SAVE);
+
+ if (!filter) {
+ g_message ("Could not get QuillImageFilter from JPEG buffer using:'%s'",
+ TRACKER_ALBUMART_QUILL_SAVE);
delete reader;
- delete filter;
+
+ return FALSE;
}
+ filter->setOption (QuillImageFilter::FileFormat, QVariant (QString ("jpeg")));
+ filter->setOption (QuillImageFilter::FileName, QVariant (QString (target)));
+ filter->apply (image);
+
+ delete reader;
+ delete filter;
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]