blob: eaa0d62661c52508ca2ff2d5441caa6358a6ea42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/***************************************************************************
copyright : (C) 2007 by Robby Stephenson
email : robby@periapsis.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#include "xmphandler.h"
#include "tellico_debug.h"
#include <config.h>
#include <tqfile.h>
#include <tqtextstream.h>
#ifdef HAVE_EXEMPI
#include <exempi/xmp.h>
#endif
using Tellico::XMPHandler;
int XMPHandler::s_initCount = 0;
bool XMPHandler::isXMPEnabled() {
#ifdef HAVE_EXEMPI
return true;
#else
return false;
#endif
}
XMPHandler::XMPHandler() {
init();
}
XMPHandler::~XMPHandler() {
#ifdef HAVE_EXEMPI
--s_initCount;
if(s_initCount == 0) {
xmp_terminate();
}
#endif
}
void XMPHandler::init() {
#ifdef HAVE_EXEMPI
if(s_initCount == 0) {
xmp_init();
}
++s_initCount;
#endif
}
TQString XMPHandler::extractXMP(const TQString& file) {
TQString result;
#ifdef HAVE_EXEMPI
XmpFilePtr xmpfile = xmp_files_open_new(TQFile::encodeName(file), XMP_OPEN_READ);
if(!xmpfile) {
myDebug() << "XMPHandler::parse() - unable to open " << file << endl;
return result;
}
XmpPtr xmp = xmp_files_get_new_xmp(xmpfile);
if(xmp) {
XmpStringPtr buffer = xmp_string_new();
xmp_serialize(xmp, buffer, 0, 0);
result = TQString::fromUtf8(xmp_string_cstr(buffer));
xmp_string_free(buffer);
// myDebug() << result << endl;
#if 0
kdWarning() << "XMPHandler::parse() - turn me off!" << endl;
TQFile f1(TQString::fromLatin1("/tmp/xmp.xml"));
if(f1.open(IO_WriteOnly)) {
TQTextStream t(&f1);
t << result;
}
f1.close();
#endif
xmp_free(xmp);
xmp_files_close(xmpfile, XMP_CLOSE_NOOPTION);
xmp_files_free(xmpfile);
} else {
myDebug() << "XMPHandler::parse() - unable to parse " << file << endl;
}
#endif
return result;
}
|