Merge lp:~jpakkane/thumbnailer/fix-1319698 into lp:thumbnailer

Proposed by Jussi Pakkanen
Status: Superseded
Proposed branch: lp:~jpakkane/thumbnailer/fix-1319698
Merge into: lp:thumbnailer
Diff against target: 4371 lines (+4019/-0) (has conflicts)
65 files modified
CMakeLists.txt (+53/-0)
COPYING (+165/-0)
cmake/coverage.cmake (+34/-0)
debian/changelog (+128/-0)
debian/compat (+1/-0)
debian/control (+74/-0)
debian/copyright (+19/-0)
debian/libthumbnailer-dev.install (+3/-0)
debian/libthumbnailer0.install (+2/-0)
debian/libthumbnailer0.symbols (+6/-0)
debian/qtdeclarative5-ubuntu-thumbnailer0.1.install (+1/-0)
debian/rules (+13/-0)
debian/source/format (+1/-0)
debian/thumbnailer-service.install (+2/-0)
include/CMakeLists.txt (+12/-0)
include/internal/CMakeLists.txt (+1/-0)
include/internal/audioimageextractor.h (+41/-0)
include/internal/config.h.in (+24/-0)
include/internal/gobj_memory.h (+112/-0)
include/internal/httpdownloader.h (+31/-0)
include/internal/imagescaler.h (+43/-0)
include/internal/lastfmdownloader.h (+41/-0)
include/internal/mediaartcache.h (+54/-0)
include/internal/soupdownloader.h (+40/-0)
include/internal/thumbnailcache.h (+45/-0)
include/internal/videoscreenshotter.h (+39/-0)
include/thumbnailer.h (+82/-0)
include/thumbnailer.pc.in (+10/-0)
plugins/Ubuntu/Thumbnailer/CMakeLists.txt (+22/-0)
plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp (+90/-0)
plugins/Ubuntu/Thumbnailer/albumartgenerator.h (+36/-0)
plugins/Ubuntu/Thumbnailer/plugin.cpp (+47/-0)
plugins/Ubuntu/Thumbnailer/plugin.h (+34/-0)
plugins/Ubuntu/Thumbnailer/qmldir (+2/-0)
plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp (+87/-0)
plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h (+36/-0)
src/CMakeLists.txt (+41/-0)
src/audioimageextractor.cpp (+100/-0)
src/imagescaler.cpp (+162/-0)
src/lastfmdownloader.cpp (+87/-0)
src/libthumbnailer.map (+14/-0)
src/mediaartcache.cpp (+201/-0)
src/service/CMakeLists.txt (+34/-0)
src/service/com.canonical.Thumbnailer.service.in (+4/-0)
src/service/dbus-interface.xml (+17/-0)
src/service/dbusinterface.cpp (+168/-0)
src/service/dbusinterface.h (+40/-0)
src/service/main.cpp (+44/-0)
src/soupdownloader.cpp (+46/-0)
src/thumbnailcache.cpp (+300/-0)
src/thumbnailer.cpp (+226/-0)
src/videoscreenshotter.cpp (+105/-0)
src/vs-thumb.cpp (+127/-0)
tests/CMakeLists.txt (+41/-0)
tests/basic.cpp (+183/-0)
tests/download.cpp (+110/-0)
tests/mediaartcachetest.cpp (+150/-0)
tests/qml/tst_image_provider.qml (+62/-0)
tests/testsetup.h.in (+6/-0)
tests/unique_gobj.cpp (+172/-0)
tools/CMakeLists.txt (+11/-0)
tools/cachetool.cpp (+37/-0)
tools/imdump.cpp (+34/-0)
tools/lastfmtest.cpp (+31/-0)
tools/scaler.cpp (+35/-0)
Conflict adding file CMakeLists.txt.  Moved existing file to CMakeLists.txt.moved.
Conflict adding file COPYING.  Moved existing file to COPYING.moved.
Conflict adding file cmake.  Moved existing file to cmake.moved.
Conflict adding file debian.  Moved existing file to debian.moved.
Conflict adding file include.  Moved existing file to include.moved.
Conflict adding file plugins.  Moved existing file to plugins.moved.
Conflict adding file src.  Moved existing file to src.moved.
Conflict adding file tests.  Moved existing file to tests.moved.
Conflict adding file tools.  Moved existing file to tools.moved.
To merge this branch: bzr merge lp:~jpakkane/thumbnailer/fix-1319698
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+248512@code.launchpad.net

Commit message

SRU backport of patch to make file names with chinese characters work.

Description of the change

SRU backport of patch to make file names with chinese characters work.

To post a comment you must log in.
lp:~jpakkane/thumbnailer/fix-1319698 updated
15. By Jussi Pakkanen

Added bzr-builddeb conf file to make this branch citrain ready.

Unmerged revisions

15. By Jussi Pakkanen

Added bzr-builddeb conf file to make this branch citrain ready.

14. By Jussi Pakkanen

Backport patch for filenames with chinese characters.

13. By PS Jenkins bot

[ Michal Hruby ]
Provide virtual thumbnailer package.

12. By PS Jenkins bot

[ Jussi Pakkanen ]
New minor release.

11. By PS Jenkins bot

[ Jussi Pakkanen ]
Obey the TMPDIR. (LP: #1296987)

10. By PS Jenkins bot

[ Jussi Pakkanen ]
Prevent crash if exif entry is null. (LP: #1294274)

9. By PS Jenkins bot

[ Jussi Pakkanen ]
* Added visibility info to prevent accidental ABI breakages.
* Reorient images manually to work around a bug in GdkPixbuf.

8. By PS Jenkins bot

[ CI bot ]
* Resync trunk

[ Ugo Riboni ]
* Add a new nonstandard thumbnail size (360) needed by gallery-app To
  test from QML you will need this MR as well:
  https://code.launchpad.net/~amanzi-team/ubuntu-ui-toolkit/ubuntu-ui-
  toolkit-xlarge-thumbnails/+merge/207500 (LP: #1221968)

[ Jussi Pakkanen ]
* Error condition checking and error messages.
* Fix image orientation.

7. By PS Jenkins bot

[ Ricardo Salveti de Araujo ]
* vs-thumb: give pipeline at least 3 seconds to preroll

[ Jussi Pakkanen ]
* Created a unique_gobj class for managing gobject based resources.
* Fix use of #includes. (LP: #1237045)
* A bunch of fixes to make the project compile on precise.
* Removed accidentally added file.
* Invalidate cached images when source has changed.

6. By PS Jenkins bot

[ Jussi Pakkanen ]
* Fix install directory of vs-thumb. (LP: #1235325)
* Wait for child process to die when killing it with SIGKILL.

[ Ubuntu daily release ]
* Automatic snapshot from revision 58

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'CMakeLists.txt'
--- CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,53 @@
1project(thumbnailer C CXX)
2cmake_minimum_required(VERSION 2.8.7)
3set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
4
5include(CheckCXXCompilerFlag)
6check_cxx_compiler_flag(-std=c++11 HAS_C11)
7# Precise's GCC is too old to have -std=c++11
8if(HAS_C11)
9set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
10else()
11set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Dfinal=")
12endif()
13
14set(SO_VERSION_MAJOR "1")
15set(SO_VERSION_MINOR "1")
16set(SO_VERSION_PATCH "0")
17
18set(SO_VERSION "${SO_VERSION_MAJOR}.${SO_VERSION_MINOR}.${SO_VERSION_PATCH}")
19
20# Increment this manually whenever breaking ABI.
21# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN135
22set(ABI_VERSION 0)
23
24include(cmake/coverage.cmake)
25
26include(GNUInstallDirs)
27set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
28set(SHARE_PRIV_DIR ${CMAKE_INSTALL_LIBDIR}/thumbnailer)
29set(SHARE_PRIV_ABS ${CMAKE_INSTALL_PREFIX}/${SHARE_PRIV_DIR})
30
31find_package(Threads REQUIRED)
32find_package(Qt5Core REQUIRED)
33include(FindPkgConfig)
34pkg_check_modules(GST_DEPS REQUIRED gstreamer-1.0 gstreamer-plugins-base-1.0 gstreamer-pbutils-1.0 gstreamer-app-1.0)
35pkg_check_modules(GIO_DEPS REQUIRED gio-2.0 gio-unix-2.0)
36pkg_check_modules(IMG_DEPS REQUIRED gdk-pixbuf-2.0 libexif)
37pkg_check_modules(SOUP_DEPS REQUIRED libsoup-2.4)
38pkg_check_modules(XML_DEPS REQUIRED libxml-2.0)
39
40include_directories(${GST_DEPS_INCLUDE_DIRS})
41include_directories(${GIO_DEPS_INCLUDE_DIRS})
42include_directories(${IMG_DEPS_INCLUDE_DIRS})
43include_directories(${SOUP_DEPS_INCLUDE_DIRS})
44include_directories(${XML_DEPS_INCLUDE_DIRS})
45include_directories(include)
46include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
47
48enable_testing()
49add_subdirectory(src)
50add_subdirectory(plugins/Ubuntu/Thumbnailer)
51add_subdirectory(tests)
52add_subdirectory(tools)
53add_subdirectory(include)
054
=== renamed file 'CMakeLists.txt' => 'CMakeLists.txt.moved'
=== added file 'COPYING'
--- COPYING 1970-01-01 00:00:00 +0000
+++ COPYING 2015-02-04 08:57:20 +0000
@@ -0,0 +1,165 @@
1 GNU LESSER GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8
9 This version of the GNU Lesser General Public License incorporates
10the terms and conditions of version 3 of the GNU General Public
11License, supplemented by the additional permissions listed below.
12
13 0. Additional Definitions.
14
15 As used herein, "this License" refers to version 3 of the GNU Lesser
16General Public License, and the "GNU GPL" refers to version 3 of the GNU
17General Public License.
18
19 "The Library" refers to a covered work governed by this License,
20other than an Application or a Combined Work as defined below.
21
22 An "Application" is any work that makes use of an interface provided
23by the Library, but which is not otherwise based on the Library.
24Defining a subclass of a class defined by the Library is deemed a mode
25of using an interface provided by the Library.
26
27 A "Combined Work" is a work produced by combining or linking an
28Application with the Library. The particular version of the Library
29with which the Combined Work was made is also called the "Linked
30Version".
31
32 The "Minimal Corresponding Source" for a Combined Work means the
33Corresponding Source for the Combined Work, excluding any source code
34for portions of the Combined Work that, considered in isolation, are
35based on the Application, and not on the Linked Version.
36
37 The "Corresponding Application Code" for a Combined Work means the
38object code and/or source code for the Application, including any data
39and utility programs needed for reproducing the Combined Work from the
40Application, but excluding the System Libraries of the Combined Work.
41
42 1. Exception to Section 3 of the GNU GPL.
43
44 You may convey a covered work under sections 3 and 4 of this License
45without being bound by section 3 of the GNU GPL.
46
47 2. Conveying Modified Versions.
48
49 If you modify a copy of the Library, and, in your modifications, a
50facility refers to a function or data to be supplied by an Application
51that uses the facility (other than as an argument passed when the
52facility is invoked), then you may convey a copy of the modified
53version:
54
55 a) under this License, provided that you make a good faith effort to
56 ensure that, in the event an Application does not supply the
57 function or data, the facility still operates, and performs
58 whatever part of its purpose remains meaningful, or
59
60 b) under the GNU GPL, with none of the additional permissions of
61 this License applicable to that copy.
62
63 3. Object Code Incorporating Material from Library Header Files.
64
65 The object code form of an Application may incorporate material from
66a header file that is part of the Library. You may convey such object
67code under terms of your choice, provided that, if the incorporated
68material is not limited to numerical parameters, data structure
69layouts and accessors, or small macros, inline functions and templates
70(ten or fewer lines in length), you do both of the following:
71
72 a) Give prominent notice with each copy of the object code that the
73 Library is used in it and that the Library and its use are
74 covered by this License.
75
76 b) Accompany the object code with a copy of the GNU GPL and this license
77 document.
78
79 4. Combined Works.
80
81 You may convey a Combined Work under terms of your choice that,
82taken together, effectively do not restrict modification of the
83portions of the Library contained in the Combined Work and reverse
84engineering for debugging such modifications, if you also do each of
85the following:
86
87 a) Give prominent notice with each copy of the Combined Work that
88 the Library is used in it and that the Library and its use are
89 covered by this License.
90
91 b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 document.
93
94 c) For a Combined Work that displays copyright notices during
95 execution, include the copyright notice for the Library among
96 these notices, as well as a reference directing the user to the
97 copies of the GNU GPL and this license document.
98
99 d) Do one of the following:
100
101 0) Convey the Minimal Corresponding Source under the terms of this
102 License, and the Corresponding Application Code in a form
103 suitable for, and under terms that permit, the user to
104 recombine or relink the Application with a modified version of
105 the Linked Version to produce a modified Combined Work, in the
106 manner specified by section 6 of the GNU GPL for conveying
107 Corresponding Source.
108
109 1) Use a suitable shared library mechanism for linking with the
110 Library. A suitable mechanism is one that (a) uses at run time
111 a copy of the Library already present on the user's computer
112 system, and (b) will operate properly with a modified version
113 of the Library that is interface-compatible with the Linked
114 Version.
115
116 e) Provide Installation Information, but only if you would otherwise
117 be required to provide such information under section 6 of the
118 GNU GPL, and only to the extent that such information is
119 necessary to install and execute a modified version of the
120 Combined Work produced by recombining or relinking the
121 Application with a modified version of the Linked Version. (If
122 you use option 4d0, the Installation Information must accompany
123 the Minimal Corresponding Source and Corresponding Application
124 Code. If you use option 4d1, you must provide the Installation
125 Information in the manner specified by section 6 of the GNU GPL
126 for conveying Corresponding Source.)
127
128 5. Combined Libraries.
129
130 You may place library facilities that are a work based on the
131Library side by side in a single library together with other library
132facilities that are not Applications and are not covered by this
133License, and convey such a combined library under terms of your
134choice, if you do both of the following:
135
136 a) Accompany the combined library with a copy of the same work based
137 on the Library, uncombined with any other library facilities,
138 conveyed under the terms of this License.
139
140 b) Give prominent notice with the combined library that part of it
141 is a work based on the Library, and explaining where to find the
142 accompanying uncombined form of the same work.
143
144 6. Revised Versions of the GNU Lesser General Public License.
145
146 The Free Software Foundation may publish revised and/or new versions
147of the GNU Lesser General Public License from time to time. Such new
148versions will be similar in spirit to the present version, but may
149differ in detail to address new problems or concerns.
150
151 Each version is given a distinguishing version number. If the
152Library as you received it specifies that a certain numbered version
153of the GNU Lesser General Public License "or any later version"
154applies to it, you have the option of following the terms and
155conditions either of that published version or of any later version
156published by the Free Software Foundation. If the Library as you
157received it does not specify a version number of the GNU Lesser
158General Public License, you may choose any version of the GNU Lesser
159General Public License ever published by the Free Software Foundation.
160
161 If the Library as you received it specifies that a proxy can decide
162whether future versions of the GNU Lesser General Public License shall
163apply, that proxy's public statement of acceptance of any version is
164permanent authorization for you to choose that version for the
165Library.
0166
=== renamed file 'COPYING' => 'COPYING.moved'
=== added directory 'cmake'
=== renamed directory 'cmake' => 'cmake.moved'
=== added file 'cmake/coverage.cmake'
--- cmake/coverage.cmake 1970-01-01 00:00:00 +0000
+++ cmake/coverage.cmake 2015-02-04 08:57:20 +0000
@@ -0,0 +1,34 @@
1if (CMAKE_BUILD_TYPE MATCHES coverage)
2 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
3 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
4 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
5 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
6
7 find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
8 if (NOT GCOVR_EXECUTABLE)
9 message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
10 else ()
11 message(STATUS "Gcovr found, can generate XML coverage info.")
12 add_custom_target (coverage-xml
13 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
14 COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" -x -r "${CMAKE_SOURCE_DIR}"
15 --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
16 endif()
17
18 find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
19 find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
20 if (NOT LCOV_EXECUTABLE)
21 message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
22 else ()
23 if(NOT GENHTML_EXECUTABLE)
24 message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
25 else()
26 message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
27 add_custom_target (coverage-html
28 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
29 COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum
30 COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info
31 )
32 endif()
33 endif()
34endif()
035
=== added directory 'debian'
=== renamed directory 'debian' => 'debian.moved'
=== added file 'debian/changelog'
--- debian/changelog 1970-01-01 00:00:00 +0000
+++ debian/changelog 2015-02-04 08:57:20 +0000
@@ -0,0 +1,128 @@
1thumbnailer (1.1+14.04.20140401.1-0ubuntu1) trusty; urgency=low
2
3 [ Michal Hruby ]
4 * Provide virtual thumbnailer package.
5
6 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 01 Apr 2014 22:45:34 +0000
7
8thumbnailer (1.1+14.04.20140331-0ubuntu1) trusty; urgency=medium
9
10 [ Jussi Pakkanen ]
11 * New minor release.
12
13 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 31 Mar 2014 09:08:36 +0000
14
15thumbnailer (1.0+14.04.20140327-0ubuntu1) trusty; urgency=low
16
17 [ Jussi Pakkanen ]
18 * Obey the TMPDIR. (LP: #1296987)
19
20 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 27 Mar 2014 08:36:59 +0000
21
22thumbnailer (1.0+14.04.20140319-0ubuntu1) trusty; urgency=low
23
24 [ Jussi Pakkanen ]
25 * Prevent crash if exif entry is null. (LP: #1294274)
26
27 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 19 Mar 2014 20:16:40 +0000
28
29thumbnailer (1.0+14.04.20140307-0ubuntu1) trusty; urgency=low
30
31 [ Jussi Pakkanen ]
32 * Added visibility info to prevent accidental ABI breakages.
33 * Reorient images manually to work around a bug in GdkPixbuf.
34
35 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 07 Mar 2014 15:41:18 +0000
36
37thumbnailer (1.0+14.04.20140304-0ubuntu1) trusty; urgency=low
38
39 [ CI bot ]
40 * Resync trunk
41
42 [ Ugo Riboni ]
43 * Add a new nonstandard thumbnail size (360) needed by gallery-app To
44 test from QML you will need this MR as well:
45 https://code.launchpad.net/~amanzi-team/ubuntu-ui-toolkit/ubuntu-ui-
46 toolkit-xlarge-thumbnails/+merge/207500 (LP: #1221968)
47
48 [ Jussi Pakkanen ]
49 * Error condition checking and error messages.
50 * Fix image orientation.
51
52 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 04 Mar 2014 10:09:12 +0000
53
54thumbnailer (1.0+14.04.20140218-0ubuntu1) trusty; urgency=low
55
56 [ Ricardo Salveti de Araujo ]
57 * vs-thumb: give pipeline at least 3 seconds to preroll
58
59 [ Jussi Pakkanen ]
60 * Created a unique_gobj class for managing gobject based resources.
61 * Fix use of #includes. (LP: #1237045)
62 * A bunch of fixes to make the project compile on precise.
63 * Removed accidentally added file.
64 * Invalidate cached images when source has changed.
65
66 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 18 Feb 2014 23:01:31 +0000
67
68thumbnailer (1.0+13.10.20131011-0ubuntu1) saucy; urgency=low
69
70 [ Jussi Pakkanen ]
71 * Fix install directory of vs-thumb. (LP: #1235325)
72 * Wait for child process to die when killing it with SIGKILL.
73
74 [ Ubuntu daily release ]
75 * Automatic snapshot from revision 58
76
77 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Fri, 11 Oct 2013 05:41:32 +0000
78
79thumbnailer (1.0+13.10.20131008-0ubuntu1) saucy; urgency=low
80
81 [ Jussi Pakkanen ]
82 * Fix off by one error. (LP: #1235444)
83 * Disable use of in-process GStreamer because we use 1.0, which
84 clashes with 0.10. (LP: #1235484)
85
86 [ Ubuntu daily release ]
87 * Automatic snapshot from revision 55
88
89 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Tue, 08 Oct 2013 12:49:51 +0000
90
91thumbnailer (1.0+13.10.20131007-0ubuntu1) saucy; urgency=low
92
93 [ Jussi Pakkanen ]
94 * Write files into cache atomically.
95 * Guard against a frozen worker process.
96 * Document the public interface.
97
98 [ Ubuntu daily release ]
99 * Automatic snapshot from revision 52
100
101 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 07 Oct 2013 10:52:14 +0000
102
103thumbnailer (1.0+13.10.20131003-0ubuntu1) saucy; urgency=low
104
105 [ Jussi Pakkanen ]
106 * Run gstreamer video pipelines in an external process.
107 * Get helper path from config.h.
108 * Use helper binary from build dir when running tests.
109 * Adds support for full resolution thumbnails.
110
111 [ Ubuntu daily release ]
112 * Automatic snapshot from revision 48
113
114 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Thu, 03 Oct 2013 03:26:49 +0000
115
116thumbnailer (1.0+13.10.20131002-0ubuntu1) saucy; urgency=low
117
118 [ Jussi Pakkanen ]
119 * Initial release.
120 * Typo fix.
121
122 [ Łukasz 'sil2100' Zemczak ]
123 * Automatic snapshot from revision 41 (bootstrap)
124
125 [ Ubuntu daily release ]
126 * Automatic snapshot from revision 43
127
128 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 02 Oct 2013 02:34:38 +0000
0129
=== added file 'debian/compat'
--- debian/compat 1970-01-01 00:00:00 +0000
+++ debian/compat 2015-02-04 08:57:20 +0000
@@ -0,0 +1,1 @@
19
02
=== added file 'debian/control'
--- debian/control 1970-01-01 00:00:00 +0000
+++ debian/control 2015-02-04 08:57:20 +0000
@@ -0,0 +1,74 @@
1Source: thumbnailer
2Section: libdevel
3Priority: optional
4Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5Standards-Version: 3.9.4
6Build-Depends: cmake,
7 debhelper (>= 9),
8 gstreamer1.0-plugins-good,
9 libexif-dev,
10 libgdk-pixbuf2.0-dev,
11 libgstreamer1.0-dev,
12 libgstreamer-plugins-base1.0-dev,
13 libgtest-dev,
14 libsoup2.4-dev,
15 libxml2-dev,
16 qt5-default,
17 qtbase5-dev,
18 qtbase5-dev-tools,
19 qtdeclarative5-dev,
20 shared-mime-info,
21Homepage: https://launchpad.net/thumbnailer
22# if you don't have have commit access to this branch but would like to upload
23# directly to Ubuntu, don't worry: your changes will be merged back into the
24# upstream branch
25Vcs-Bzr: lp:thumbnailer
26
27Package: libthumbnailer0
28Architecture: any
29Multi-Arch: same
30Pre-Depends: ${misc:Pre-Depends},
31Depends: ${misc:Depends},
32 ${shlibs:Depends},
33Description: generate thumbnails from files
34 Thumbnailer is a shared library that generates
35 thumbnail images for multiple file types such
36 as video and audio files.
37
38Package: libthumbnailer-dev
39Architecture: any
40Multi-Arch: same
41Pre-Depends: ${misc:Pre-Depends},
42Depends: ${misc:Depends},
43 ${shlibs:Depends},
44 gstreamer1.0-plugins-base,
45 gstreamer1.0-plugins-good,
46 libthumbnailer0 (= ${binary:Version}),
47Description: development files for thumbnailer
48 This package contains development files
49 for the thumbnailer package.
50
51Package: thumbnailer-service
52Architecture: any
53Multi-Arch: foreign
54Pre-Depends: ${misc:Pre-Depends},
55Depends: ${misc:Depends},
56 ${shlibs:Depends},
57 libthumbnailer0 (= ${binary:Version}),
58Description: D-Bus service for out of process thumbnailing
59 This package provides a D-Bus service that can provide thumbnails on
60 behalf of another process.
61
62Package: qtdeclarative5-ubuntu-thumbnailer0.1
63Architecture: any
64Multi-Arch: same
65Pre-Depends: ${misc:Pre-Depends},
66Depends: ${misc:Depends},
67 ${shlibs:Depends},
68 libthumbnailer0 (= ${binary:Version}),
69Provides: ubuntu-thumbnailer-impl,
70 ubuntu-thumbnailer-impl-0,
71Recommends: thumbnailer-service (= ${binary:Version}),
72Description: QML interface for the thumbnailer.
73 This package provides image providers that allow access to the
74 thumbnailer from Qt Quick 2 / QML applications.
075
=== added file 'debian/copyright'
--- debian/copyright 1970-01-01 00:00:00 +0000
+++ debian/copyright 2015-02-04 08:57:20 +0000
@@ -0,0 +1,19 @@
1Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2Upstream-Name: thumbnailer
3Source: https://launchpad.net/thumbnailer
4
5Files: *
6Copyright: 2013 Canonical ltd
7License: LGPL-3
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of version 3 of the GNU Lesser General Public
10 License as published by the Free Software Foundation.
11 .
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 .
17 On Debian systems, the full text of the GNU Lesser General Public
18 License version 3 can be found in the file
19 `/usr/share/common-licenses/LGPL-3'
020
=== added file 'debian/libthumbnailer-dev.install'
--- debian/libthumbnailer-dev.install 1970-01-01 00:00:00 +0000
+++ debian/libthumbnailer-dev.install 2015-02-04 08:57:20 +0000
@@ -0,0 +1,3 @@
1usr/include/*
2usr/lib/*/lib*.so
3usr/lib/*/pkgconfig/*
04
=== added file 'debian/libthumbnailer0.install'
--- debian/libthumbnailer0.install 1970-01-01 00:00:00 +0000
+++ debian/libthumbnailer0.install 2015-02-04 08:57:20 +0000
@@ -0,0 +1,2 @@
1usr/lib/*/libthumb*.so.*
2usr/lib/*/thumbnailer/vs-thumb
03
=== added file 'debian/libthumbnailer0.symbols'
--- debian/libthumbnailer0.symbols 1970-01-01 00:00:00 +0000
+++ debian/libthumbnailer0.symbols 2015-02-04 08:57:20 +0000
@@ -0,0 +1,6 @@
1libthumbnailer.so.0 libthumbnailer0 #MINVER#
2 (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize)@Base" 1.0
3 (c++)"Thumbnailer::get_thumbnail(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
4 (c++)"Thumbnailer::get_album_art(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ThumbnailSize, ThumbnailPolicy)@Base" 1.0
5 (c++)"Thumbnailer::Thumbnailer()@Base" 1.0
6 (c++)"Thumbnailer::~Thumbnailer()@Base" 1.0
07
=== added file 'debian/qtdeclarative5-ubuntu-thumbnailer0.1.install'
--- debian/qtdeclarative5-ubuntu-thumbnailer0.1.install 1970-01-01 00:00:00 +0000
+++ debian/qtdeclarative5-ubuntu-thumbnailer0.1.install 2015-02-04 08:57:20 +0000
@@ -0,0 +1,1 @@
1usr/lib/*/qt5/qml/Ubuntu/Thumbnailer.0.1/*
02
=== added file 'debian/rules'
--- debian/rules 1970-01-01 00:00:00 +0000
+++ debian/rules 2015-02-04 08:57:20 +0000
@@ -0,0 +1,13 @@
1#!/usr/bin/make -f
2# -*- makefile -*-
3
4# Uncomment this to turn on verbose mode.
5#export DH_VERBOSE=1
6
7export DPKG_GENSYMBOLS_CHECK_LEVEL=4
8
9# http://ccache.samba.org/manual.html#_precompiled_headers
10export CCACHE_SLOPPINESS=time_macros
11
12%:
13 dh $@ --parallel --fail-missing
014
=== added directory 'debian/source'
=== added file 'debian/source/format'
--- debian/source/format 1970-01-01 00:00:00 +0000
+++ debian/source/format 2015-02-04 08:57:20 +0000
@@ -0,0 +1,1 @@
11.0
02
=== added file 'debian/thumbnailer-service.install'
--- debian/thumbnailer-service.install 1970-01-01 00:00:00 +0000
+++ debian/thumbnailer-service.install 2015-02-04 08:57:20 +0000
@@ -0,0 +1,2 @@
1usr/lib/*/thumbnailer/thumbnailer-service
2usr/share/dbus-1/services/com.canonical.Thumbnailer.service
03
=== added directory 'include'
=== renamed directory 'include' => 'include.moved'
=== added file 'include/CMakeLists.txt'
--- include/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ include/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,12 @@
1add_subdirectory(internal)
2
3install(FILES thumbnailer.h DESTINATION include)
4
5# Build and install a pkg-config file
6set(prefix ${CMAKE_INSTALL_PREFIX})
7set(exec_prefix ${prefix}/bin)
8set(libdir ${prefix}/${LIBDIR})
9set(includedir ${prefix}/include)
10set(pkg-name "lib${COL_LIB_BASENAME}")
11configure_file(thumbnailer.pc.in thumbnailer.pc @ONLY)
12install(FILES ${CMAKE_CURRENT_BINARY_DIR}/thumbnailer.pc DESTINATION ${LIBDIR}/pkgconfig)
013
=== added directory 'include/internal'
=== added file 'include/internal/CMakeLists.txt'
--- include/internal/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ include/internal/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,1 @@
1configure_file(config.h.in config.h @ONLY)
02
=== added file 'include/internal/audioimageextractor.h'
--- include/internal/audioimageextractor.h 1970-01-01 00:00:00 +0000
+++ include/internal/audioimageextractor.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef AUDIOIMAGEEXTRACTOR_H_
20#define AUDIOIMAGEEXTRACTOR_H_
21
22#include<string>
23
24class AudioImageExtractorPrivate;
25
26class AudioImageExtractor final {
27public:
28 AudioImageExtractor();
29 ~AudioImageExtractor();
30
31 AudioImageExtractor(const AudioImageExtractor &t) = delete;
32 AudioImageExtractor & operator=(const AudioImageExtractor &t) = delete;
33
34 bool extract(const std::string &ifname, const std::string &ofname);
35
36private:
37 AudioImageExtractorPrivate *p;
38};
39
40
41#endif
042
=== added file 'include/internal/config.h.in'
--- include/internal/config.h.in 1970-01-01 00:00:00 +0000
+++ include/internal/config.h.in 2015-02-04 08:57:20 +0000
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef THUMBNAILER_CONFIG_H
20#define THUMBNAILER_CONFIG_H
21
22#cmakedefine SHARE_PRIV_ABS "@SHARE_PRIV_ABS@"
23
24#endif
025
=== added file 'include/internal/gobj_memory.h'
--- include/internal/gobj_memory.h 1970-01-01 00:00:00 +0000
+++ include/internal/gobj_memory.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,112 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef GOBJ_MEMORY_H_
20#define GOBJ_MEMORY_H_
21
22#include<glib-object.h>
23#include<stdexcept>
24
25/**
26 * This class is meant for automatically managing the lifetime of C objects derived
27 * from gobject. Its API perfectly mirrors the API of unique_ptr except that you
28 * can't define your own deleter function as it is always g_object_unref.
29 *
30 * API/ABI stability is not guaranteed. If you need to pass the object across an ABI
31 * boundary, pass the plain gobject.
32 *
33 * This is how you would use unique_gobj 99% of the time:
34 *
35 * unique_gobj<GSomeType> o(g_some_type_new(...));
36 *
37 * More specifically, the object will decrement the gobject reference count
38 * of the object it points to when it goes out of scope. It will never increment it.
39 * Thus you should only assign to it when already holding a reference. unique_gobj
40 * will then take ownership of that particular reference.
41 *
42 * Floating gobjects can not be put in this container as they are meant to be put
43 * into native gobject aware containers immediately upon construction. Trying to insert
44 * a floating gobject into a unique_gobj will throw an invalid_argument exception. To
45 * prevent accidental memory leaks, the floating gobject is unreffed in this case.
46 */
47template<typename T>
48class unique_gobj final {
49private:
50 T* u;
51
52 void validate_float(T *t) {
53 if(t != nullptr && g_object_is_floating(G_OBJECT(t))) {
54 throw std::invalid_argument("Tried to add a floating gobject into a unique_gobj.");
55 }
56 }
57
58public:
59 typedef T element_type;
60 typedef T* pointer;
61 typedef decltype(g_object_unref) deleter_type;
62
63 constexpr unique_gobj() noexcept : u(nullptr) {}
64 explicit unique_gobj(T *t) : u(t) {
65 // What should we do if validate throws? Unreffing unknown objs
66 // is dodgy but not unreffing runs the risk of
67 // memory leaks. Currently unrefs as u is destroyed
68 // when this exception is thrown.
69 validate_float(t);
70 }
71 constexpr unique_gobj(std::nullptr_t) noexcept : u(nullptr) {};
72 unique_gobj(unique_gobj &&o) noexcept { u = o.u; o.u = nullptr; }
73 unique_gobj(const unique_gobj &o) = delete;
74 unique_gobj& operator=(unique_gobj &o) = delete;
75 ~unique_gobj() { reset(); }
76
77 deleter_type& get_deleter() noexcept { return g_object_unref; }
78 const deleter_type& get_deleter() const noexcept { return g_object_unref; }
79
80 void swap(unique_gobj<T> &o) noexcept { T*tmp = u; u = o.u; o.u = tmp; }
81 void reset(pointer p = pointer()) {
82 if(u!=nullptr) {
83 g_object_unref(G_OBJECT(u));
84 u = nullptr;
85 }
86 // Same throw dilemma as in pointer constructor.
87 u = p;
88 validate_float(p);
89 }
90
91 T* release() noexcept { T* r = u; u=nullptr; return r; }
92 T* get() const noexcept { return u; }
93
94 T& operator*() const { return *u; }
95 T* operator->() const noexcept { return u; }
96 explicit operator bool() const noexcept { return u != nullptr; }
97
98 unique_gobj& operator=(unique_gobj &&o) noexcept { reset(); u = o.u; o.u = nullptr; return *this; }
99 unique_gobj& operator=(std::nullptr_t) noexcept { reset(); return *this; }
100 bool operator==(const unique_gobj<T> &o) const noexcept { return u == o.u; }
101 bool operator!=(const unique_gobj<T> &o) const noexcept { return u != o.u; }
102 bool operator<(const unique_gobj<T> &o) const noexcept { return u < o.u; }
103 bool operator<=(const unique_gobj<T> &o) const noexcept { return u <= o.u; }
104 bool operator>(const unique_gobj<T> &o) const noexcept { return u > o.u; }
105 bool operator>=(const unique_gobj<T> &o) const noexcept { return u >= o.u; }
106};
107
108template<typename T>
109void ::std::swap(unique_gobj<T> &f, unique_gobj<T> &s) noexcept { f.swap(s); }
110
111
112#endif
0113
=== added file 'include/internal/httpdownloader.h'
--- include/internal/httpdownloader.h 1970-01-01 00:00:00 +0000
+++ include/internal/httpdownloader.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef HTTPDOWNLOADER_H
20#define HTTPDOWNLOADER_H
21
22#include<string>
23
24class HttpDownloader {
25public:
26 virtual std::string download(const std::string &url) = 0;
27 virtual ~HttpDownloader() {};
28};
29
30
31#endif
032
=== added file 'include/internal/imagescaler.h'
--- include/internal/imagescaler.h 1970-01-01 00:00:00 +0000
+++ include/internal/imagescaler.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,43 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef IMAGESCALER_H_
20#define IMAGESCALER_H_
21
22#include<thumbnailer.h>
23#include<string>
24
25class ImageScalerPrivate;
26
27class ImageScaler final {
28public:
29 ImageScaler();
30 ~ImageScaler();
31
32 ImageScaler(const ImageScaler &t) = delete;
33 ImageScaler & operator=(const ImageScaler &t) = delete;
34
35 bool scale(const std::string &ifilename, const std::string &ofilename,
36 ThumbnailSize wanted, const std::string &original_location) const;
37
38private:
39 ImageScalerPrivate *p;
40};
41
42
43#endif
044
=== added file 'include/internal/lastfmdownloader.h'
--- include/internal/lastfmdownloader.h 1970-01-01 00:00:00 +0000
+++ include/internal/lastfmdownloader.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef LASTFM_DOWNLOADER_H
20#define LASTFM_DOWNLOADER_H
21
22#include<string>
23#include<memory>
24#include<internal/httpdownloader.h>
25
26class LastFMDownloader final {
27public:
28 LastFMDownloader();
29 LastFMDownloader(HttpDownloader *o); // Takes ownership.
30 ~LastFMDownloader();
31 LastFMDownloader(const LastFMDownloader &o) = delete;
32 LastFMDownloader& operator=(const LastFMDownloader &o) = delete;
33
34 bool download(const std::string &artist, const std::string &album,
35 const std::string &fname);
36private:
37 std::string parseXML(const std::string &xml);
38 std::unique_ptr<HttpDownloader> dl;
39};
40
41#endif
042
=== added file 'include/internal/mediaartcache.h'
--- include/internal/mediaartcache.h 1970-01-01 00:00:00 +0000
+++ include/internal/mediaartcache.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright (C) 2013-2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef MEDIAARTCACHE_H
20#define MEDIAARTCACHE_H
21
22#include<string>
23
24/*
25 * A class to store thumbnails for files according to
26 * https://wiki.gnome.org/MediaArtStorageSpec
27 *
28 * As this class deals mostly with the filesystem, all
29 * errors are reported with runtime_error exceptions.
30 */
31
32
33class MediaArtCache {
34private:
35 std::string root_dir;
36
37 std::string compute_base_name(const std::string &artist, const std::string &album) const;
38 std::string get_full_filename(const std::string &artist, const std::string & album) const;
39
40public:
41 static const unsigned int MAX_SIZE = 200;
42
43 MediaArtCache();
44 bool has_art(const std::string &artist, const std::string &album) const;
45 void add_art(const std::string &artist, const std::string &album,
46 const char *data, unsigned int datalen);
47 std::string get_art_file(const std::string &artist, const std::string &album) const;
48 std::string get_art_uri(const std::string &artist, const std::string &album) const;
49 void clear() const;
50 void prune();
51 std::string get_cache_dir() const { return root_dir; }
52};
53
54#endif
055
=== added file 'include/internal/soupdownloader.h'
--- include/internal/soupdownloader.h 1970-01-01 00:00:00 +0000
+++ include/internal/soupdownloader.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef SOUPDOWNLOADER_H
20#define SOUPDOWNLOADER_H
21
22#include<internal/httpdownloader.h>
23
24typedef struct _SoupSession SoupSession;
25
26class SoupDownloader final : public HttpDownloader {
27
28private:
29 SoupSession *session;
30
31public:
32 SoupDownloader();
33 virtual ~SoupDownloader();
34 SoupDownloader(const SoupDownloader &o) = delete;
35 SoupDownloader& operator=(const SoupDownloader &o) = delete;
36
37 std::string download(const std::string &url) override;
38};
39
40#endif
041
=== added file 'include/internal/thumbnailcache.h'
--- include/internal/thumbnailcache.h 1970-01-01 00:00:00 +0000
+++ include/internal/thumbnailcache.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,45 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef THUMBNAILCACHE_H_
20#define THUMBNAILCACHE_H_
21
22#include<thumbnailer.h>
23#include<string>
24
25class ThumbnailCachePrivate;
26
27class ThumbnailCache final {
28public:
29 ThumbnailCache();
30 ~ThumbnailCache();
31
32 ThumbnailCache(const ThumbnailCache &t) = delete;
33 ThumbnailCache & operator=(const ThumbnailCache &t) = delete;
34
35 std::string get_if_exists(const std::string &abs_path, ThumbnailSize desired_size) const;
36 std::string get_cache_file_name(const std::string &as_path, ThumbnailSize desired_size) const;
37 void clear();
38 void prune();
39
40private:
41 ThumbnailCachePrivate *p;
42};
43
44
45#endif
046
=== added file 'include/internal/videoscreenshotter.h'
--- include/internal/videoscreenshotter.h 1970-01-01 00:00:00 +0000
+++ include/internal/videoscreenshotter.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef VIDEOSCREENSHOTTER_H_
20#define VIDEOSCREENSHOTTER_H_
21
22#include<string>
23
24class VideoScreenshotterPrivate;
25
26class VideoScreenshotter final {
27public:
28 VideoScreenshotter();
29 ~VideoScreenshotter();
30
31 VideoScreenshotter(const VideoScreenshotter &t) = delete;
32 VideoScreenshotter & operator=(const VideoScreenshotter &t) = delete;
33
34 bool extract(const std::string &ifname, const std::string &ofname);
35
36};
37
38
39#endif
040
=== added file 'include/thumbnailer.h'
--- include/thumbnailer.h 1970-01-01 00:00:00 +0000
+++ include/thumbnailer.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,82 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef THUMBNAILER_H_
20#define THUMBNAILER_H_
21
22#include<string>
23
24class ThumbnailerPrivate;
25
26enum ThumbnailSize {
27 TN_SIZE_SMALL, // maximum dimension 128 pixels
28 TN_SIZE_LARGE, // maximum dimension 256 pixels
29 TN_SIZE_XLARGE, // maximum dimension 512 pixels
30 TN_SIZE_ORIGINAL // Whatever the original size was, e.g. 1920x1080 for FullHD video
31};
32
33enum ThumbnailPolicy {
34 TN_LOCAL, // Use only local information
35 TN_REMOTE, // Use remote services (e.g. album art downloading)
36};
37
38/**
39 * This class provides a way to generate and access
40 * thumbnails of video, audio and image files.
41 *
42 * All methods are blocking.
43 *
44 * All methods are thread safe.
45 *
46 * Errors are reported as exceptions.
47 */
48
49class Thumbnailer {
50public:
51 Thumbnailer();
52 ~Thumbnailer();
53
54 /**
55 * Gets a thumbnail of the given input file in the requested size.
56 *
57 * Return value is a string pointing to the thumbnail file. If
58 * the thumbnail could not be generated and empty string is returned.
59 *
60 * Applications should treat the returned file as read only. They should _not_
61 * delete it.
62 *
63 * In case of unexpected problems, the function throws a
64 * std::runtime_error.
65 */
66 std::string get_thumbnail(const std::string &filename, ThumbnailSize desired_size,
67 ThumbnailPolicy policy);
68 /**
69 * Deprecated. Do not use!
70 */
71 std::string get_thumbnail(const std::string &filename, ThumbnailSize desired_size);
72
73 std::string get_album_art(const std::string &artist, const std::string &album,
74 ThumbnailSize desiredSize, ThumbnailPolicy policy);
75private:
76 Thumbnailer(const Thumbnailer &t);
77 Thumbnailer & operator=(const Thumbnailer &t);
78
79 ThumbnailerPrivate *p;
80};
81
82#endif
083
=== added file 'include/thumbnailer.pc.in'
--- include/thumbnailer.pc.in 1970-01-01 00:00:00 +0000
+++ include/thumbnailer.pc.in 2015-02-04 08:57:20 +0000
@@ -0,0 +1,10 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: thumbnailer
7Description: Thumbnail generator for multiple file types.
8Version: @SO_VERSION@
9Libs: -L${libdir} -lthumbnailer
10Cflags: -I${includedir}
011
=== added directory 'plugins'
=== renamed directory 'plugins' => 'plugins.moved'
=== added directory 'plugins/Ubuntu'
=== added directory 'plugins/Ubuntu/Thumbnailer'
=== added file 'plugins/Ubuntu/Thumbnailer/CMakeLists.txt'
--- plugins/Ubuntu/Thumbnailer/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,22 @@
1
2set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/Thumbnailer.0.1")
3
4add_library(thumbnailer-qml MODULE
5 plugin.cpp
6 albumartgenerator.cpp
7 thumbnailgenerator.cpp
8)
9
10set_target_properties(thumbnailer-qml PROPERTIES AUTOMOC TRUE)
11qt5_use_modules(thumbnailer-qml Qml Quick DBus)
12target_link_libraries(thumbnailer-qml thumbnailer)
13
14install(
15 TARGETS thumbnailer-qml
16 LIBRARY DESTINATION ${QML_PLUGIN_DIR}
17)
18
19install(
20 FILES qmldir
21 DESTINATION ${QML_PLUGIN_DIR}
22)
023
=== added file 'plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp'
--- plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/albumartgenerator.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,90 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 * James Henstridge <james.henstridge@canonical.com>
18*/
19
20#include "albumartgenerator.h"
21#include <stdexcept>
22#include <QDebug>
23#include <QFile>
24#include <QUrlQuery>
25#include <QDBusUnixFileDescriptor>
26#include <QDBusReply>
27
28static const char DEFAULT_ALBUM_ART[] = "/usr/share/unity/icons/album_missing.png";
29
30static const char BUS_NAME[] = "com.canonical.Thumbnailer";
31static const char BUS_PATH[] = "/com/canonical/Thumbnailer";
32static const char THUMBNAILER_IFACE[] = "com.canonical.Thumbnailer";
33static const char GET_ALBUM_ART[] = "GetAlbumArt";
34
35AlbumArtGenerator::AlbumArtGenerator()
36 : QQuickImageProvider(QQuickImageProvider::Image, QQmlImageProviderBase::ForceAsynchronousImageLoading),
37 iface(BUS_NAME, BUS_PATH, THUMBNAILER_IFACE) {
38}
39
40static QImage fallbackImage(QSize *realSize) {
41 QImage fallback;
42 fallback.load(DEFAULT_ALBUM_ART);
43 *realSize = fallback.size();
44 return fallback;
45}
46
47QImage AlbumArtGenerator::requestImage(const QString &id, QSize *realSize,
48 const QSize &requestedSize) {
49 QUrlQuery query(id);
50 if (!query.hasQueryItem("artist") || !query.hasQueryItem("album")) {
51 qWarning() << "Invalid albumart uri:" << id;
52 return fallbackImage(realSize);
53 }
54
55 const QString artist = query.queryItemValue("artist", QUrl::FullyDecoded);
56 const QString album = query.queryItemValue("album", QUrl::FullyDecoded);
57
58 QString desiredSize = "original";
59 int size = requestedSize.width() > requestedSize.height() ? requestedSize.width() : requestedSize.height();
60 if (size < 128) {
61 desiredSize = "small";
62 } else if (size < 256) {
63 desiredSize = "large";
64 } else if (size < 512) {
65 desiredSize = "xlarge";
66 }
67
68 // perform dbus call
69 QDBusReply<QDBusUnixFileDescriptor> reply = iface.call(
70 GET_ALBUM_ART, artist, album, desiredSize);
71 if (!reply.isValid()) {
72 qWarning() << "D-Bus error: " << reply.error().message();
73 return fallbackImage(realSize);
74 }
75
76 try {
77 QFile file;
78 file.open(reply.value().fileDescriptor(), QIODevice::ReadOnly);
79 QImage image;
80 image.load(&file, NULL);
81 *realSize = image.size();
82 return image;
83 } catch (const std::exception &e) {
84 qDebug() << "Album art loader failed: " << e.what();
85 } catch (...) {
86 qDebug() << "Unknown error when generating image.";
87 }
88
89 return fallbackImage(realSize);
90}
091
=== added file 'plugins/Ubuntu/Thumbnailer/albumartgenerator.h'
--- plugins/Ubuntu/Thumbnailer/albumartgenerator.h 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/albumartgenerator.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 * James Henstridge <james.henstridge@canonical.com>
18*/
19
20#ifndef ALBUMART_GENERATOR_H
21#define ALBUMART_GENERATOR_H
22
23#include <QDBusInterface>
24#include <QQuickImageProvider>
25
26class AlbumArtGenerator: public QQuickImageProvider
27{
28private:
29 QDBusInterface iface;
30
31public:
32 AlbumArtGenerator();
33 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
34};
35
36#endif
037
=== added file 'plugins/Ubuntu/Thumbnailer/plugin.cpp'
--- plugins/Ubuntu/Thumbnailer/plugin.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/plugin.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,47 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: James Henstridge <james.henstridge@canonical.com>
17*/
18
19#include "plugin.h"
20#include "albumartgenerator.h"
21#include "thumbnailgenerator.h"
22
23void ThumbnailerPlugin::registerTypes(const char *uri) {
24 qmlRegisterTypeNotAvailable(
25 uri, 0, 1, "__ThumbnailerIgnoreMe",
26 "Ignore this: QML plugins must contain at least one type");
27}
28
29void ThumbnailerPlugin::initializeEngine(QQmlEngine *engine, const char *uri) {
30 QQmlExtensionPlugin::initializeEngine(engine, uri);
31
32 try {
33 engine->addImageProvider("albumart", new AlbumArtGenerator());
34 } catch (const std::exception &e) {
35 qWarning() << "Failed to register albumart image provider:" << e.what();
36 } catch (...) {
37 qWarning() << "Failed to register albumart image provider.";
38 }
39
40 try {
41 engine->addImageProvider("thumbnailer", new ThumbnailGenerator());
42 } catch (const std::exception &e) {
43 qWarning() << "Failed to register thumbnailer image provider:" << e.what();
44 } catch (...) {
45 qWarning() << "Failed to register thumbnailer image provider.";
46 }
47}
048
=== added file 'plugins/Ubuntu/Thumbnailer/plugin.h'
--- plugins/Ubuntu/Thumbnailer/plugin.h 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/plugin.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: James Henstridge <james.henstridge@canonical.com>
17*/
18
19#ifndef THUMBNAILER_PLUGIN_H
20#define THUMBNAILER_PLUGIN_H
21
22#include <QtQml>
23
24class ThumbnailerPlugin : public QQmlExtensionPlugin
25{
26 Q_OBJECT
27 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
28
29public:
30 virtual void registerTypes(const char *uri) override;
31 virtual void initializeEngine(QQmlEngine *engine, const char *uri) override;
32};
33
34#endif
035
=== added file 'plugins/Ubuntu/Thumbnailer/qmldir'
--- plugins/Ubuntu/Thumbnailer/qmldir 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/qmldir 2015-02-04 08:57:20 +0000
@@ -0,0 +1,2 @@
1module Ubuntu.Thumbnailer
2plugin thumbnailer-qml
03
=== added file 'plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp'
--- plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/thumbnailgenerator.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17*/
18
19#include "thumbnailgenerator.h"
20#include <stdexcept>
21#include <QDebug>
22#include <QMimeDatabase>
23#include <QUrl>
24
25static const char *DEFAULT_VIDEO_ART = "/usr/share/unity/icons/video_missing.png";
26static const char *DEFAULT_ALBUM_ART = "/usr/share/unity/icons/album_missing.png";
27
28ThumbnailGenerator::ThumbnailGenerator() : QQuickImageProvider(QQuickImageProvider::Image,
29 QQmlImageProviderBase::ForceAsynchronousImageLoading) {
30
31}
32
33QImage ThumbnailGenerator::requestImage(const QString &id, QSize *realSize,
34 const QSize &requestedSize) {
35 /* Allow appending a query string (e.g. ?something=timestamp)
36 * to the id and then ignore it.
37 * This is workaround to force reloading a thumbnail when it has
38 * the same file name on disk but we know the content has changed.
39 * It is necessary because in such a situation the QML image cache
40 * will kick in and this ImageProvider will never get called.
41 * The only "solution" is setting Image.cache = false, but in some
42 * cases we don't want to do that for performance reasons, so this
43 * is the only way around the issue for now. */
44 std::string src_path(QUrl(id).path().toUtf8().data());
45 std::string tgt_path;
46 try {
47 ThumbnailSize desiredSize;
48 const int xlarge_cutoff = 512;
49 const int large_cutoff = 256;
50 const int small_cutoff = 128;
51 if(requestedSize.width() > xlarge_cutoff || requestedSize.height() > xlarge_cutoff) {
52 desiredSize = TN_SIZE_ORIGINAL;
53 } if(requestedSize.width() > large_cutoff || requestedSize.height() > large_cutoff) {
54 desiredSize = TN_SIZE_XLARGE;
55 } else if(requestedSize.width() > small_cutoff || requestedSize.height() > small_cutoff) {
56 desiredSize = TN_SIZE_LARGE;
57 } else {
58 desiredSize = TN_SIZE_SMALL;
59 }
60 tgt_path = tn.get_thumbnail(src_path, desiredSize);
61 if(!tgt_path.empty()) {
62 QString tgt(tgt_path.c_str());
63 QImage image;
64 image.load(tgt);
65 *realSize = image.size();
66 return image;
67 }
68 } catch(std::runtime_error &e) {
69 qDebug() << "Thumbnail generator failed: " << e.what();
70 }
71 return getFallbackImage(id, realSize, requestedSize);
72}
73
74QImage ThumbnailGenerator::getFallbackImage(const QString &id, QSize *size,
75 const QSize &requestedSize) {
76 Q_UNUSED(requestedSize);
77 QMimeDatabase db;
78 QMimeType mime = db.mimeTypeForFile(id);
79 QImage result;
80 if(mime.name().contains("audio")) {
81 result.load(DEFAULT_ALBUM_ART);
82 } else if(mime.name().contains("video")) {
83 result.load(DEFAULT_VIDEO_ART);
84 }
85 *size = result.size();
86 return result;
87}
088
=== added file 'plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h'
--- plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h 1970-01-01 00:00:00 +0000
+++ plugins/Ubuntu/Thumbnailer/thumbnailgenerator.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17*/
18
19#ifndef THUMBNAIL_GENERATOR_H
20#define THUMBNAIL_GENERATOR_H
21
22#include <QQuickImageProvider>
23#include <thumbnailer.h>
24
25class ThumbnailGenerator: public QQuickImageProvider
26{
27private:
28 Thumbnailer tn;
29
30public:
31 ThumbnailGenerator();
32 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize);
33 QImage getFallbackImage(const QString &id, QSize *size, const QSize &requestedSize);
34};
35
36#endif
037
=== added directory 'src'
=== renamed directory 'src' => 'src.moved'
=== added file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,41 @@
1add_library(thumbnailer SHARED
2#audioimageextractor.cpp
3imagescaler.cpp
4lastfmdownloader.cpp
5mediaartcache.cpp
6soupdownloader.cpp
7thumbnailcache.cpp
8thumbnailer.cpp
9videoscreenshotter.cpp
10)
11
12set(symbol_map "${CMAKE_CURRENT_SOURCE_DIR}/libthumbnailer.map")
13
14target_link_libraries(thumbnailer #${GST_DEPS_LDFLAGS}
15 ${GLIB_DEPS_LDFLAGS}
16 ${GIO_DEPS_LDFLAGS}
17 ${IMG_DEPS_LDFLAGS}
18 ${XML_DEPS_LDFLAGS}
19 ${SOUP_DEPS_LDFLAGS})
20set_target_properties(thumbnailer PROPERTIES VERSION ${SO_VERSION} SOVERSION ${ABI_VERSION})
21set_target_properties(thumbnailer PROPERTIES
22 LINK_FLAGS "${ldflags} -Wl,--version-script,${symbol_map}")
23set_target_properties(thumbnailer PROPERTIES LINK_DEPENDS ${symbol_map})
24
25install(
26 TARGETS thumbnailer
27 ARCHIVE DESTINATION ${LIBDIR}
28 RUNTIME DESTINATION bin
29 LIBRARY DESTINATION ${LIBDIR}
30)
31
32add_executable(vs-thumb vs-thumb.cpp)
33target_link_libraries(vs-thumb ${GST_DEPS_LDFLAGS} ${IMG_DEPS_LDFLAGS})
34install(
35 TARGETS vs-thumb
36 ARCHIVE DESTINATION ${SHARE_PRIV_DIR}
37 RUNTIME DESTINATION ${SHARE_PRIV_DIR}
38 LIBRARY DESTINATION ${SHARE_PRIV_DIR}
39)
40
41add_subdirectory(service)
042
=== added file 'src/audioimageextractor.cpp'
--- src/audioimageextractor.cpp 1970-01-01 00:00:00 +0000
+++ src/audioimageextractor.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,100 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<cstdio>
20#include<internal/audioimageextractor.h>
21#include<unistd.h>
22#include<stdexcept>
23#include<memory>
24#include <gst/pbutils/pbutils.h>
25
26using namespace std;
27
28class GstInitializer {
29public:
30 GstInitializer() { gst_init(nullptr, nullptr); };
31};
32
33class AudioImageExtractorPrivate {
34};
35
36static bool has_tag(const GstTagList *tlist, const gchar *tagname) {
37 const GValue *val = gst_tag_list_get_value_index(tlist, tagname, 0);
38 return val;
39}
40
41static void extract_image(const GstTagList *tlist, FILE *outf) {
42 const GValue *val = gst_tag_list_get_value_index(tlist, GST_TAG_IMAGE, 0);
43 GstSample *sample = (GstSample*)g_value_get_boxed(val);
44 GstBuffer *buf = gst_sample_get_buffer(sample);
45
46 for(guint i=0; i<gst_buffer_n_memory(buf); i++) {
47 GstMemory *mem = gst_buffer_peek_memory(buf, i);
48 GstMapInfo mi;
49 gst_memory_map(mem, &mi, GST_MAP_READ);
50 fwrite(mi.data, 1, mi.size, outf);
51 gst_memory_unmap(mem, &mi);
52 }
53}
54
55AudioImageExtractor::AudioImageExtractor() {
56 static GstInitializer i; // C++ standard guarantees this to be lazy and thread safe.
57 p = new AudioImageExtractorPrivate();
58}
59
60AudioImageExtractor::~AudioImageExtractor() {
61 delete p;
62}
63
64
65bool AudioImageExtractor::extract(const string &ifname, const string &ofname) {
66 string uri("file://");
67 if(ifname[0] != '/') {
68 uri += getcwd(nullptr, 0);
69 uri += '/';
70 }
71 uri += ifname;
72 GError *err = nullptr;
73 unique_ptr<GstDiscoverer, void(*)(GstDiscoverer*)> dsc(
74 gst_discoverer_new(GST_SECOND, &err),
75 [](GstDiscoverer *t) {g_object_unref(G_OBJECT(t));});
76 if(err) {
77 string msg(err->message);
78 g_error_free(err);
79 throw runtime_error(msg);
80 }
81 unique_ptr<GstDiscovererInfo, void(*)(GstDiscovererInfo*)> info(
82 gst_discoverer_discover_uri(dsc.get(), uri.c_str(), &err),
83 [](GstDiscovererInfo *t) {g_object_unref(G_OBJECT(t));});
84 if(err) {
85 string msg(err->message);
86 g_error_free(err);
87 throw runtime_error(msg);
88 }
89 const GstTagList *tlist = gst_discoverer_info_get_tags(info.get());
90 if(!tlist) {
91 return false;
92 }
93 if(!has_tag(tlist, GST_TAG_IMAGE)) {
94 return false;
95 }
96 FILE *outfile = fopen(ofname.c_str(), "wb");
97 extract_image(tlist, outfile);
98 fclose(outfile);
99 return true;
100}
0101
=== added file 'src/imagescaler.cpp'
--- src/imagescaler.cpp 1970-01-01 00:00:00 +0000
+++ src/imagescaler.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,162 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/imagescaler.h>
20#include<internal/gobj_memory.h>
21#include<gdk-pixbuf/gdk-pixbuf.h>
22#include<libexif/exif-loader.h>
23#include<memory>
24#include<stdexcept>
25#include<sys/stat.h>
26#include<cassert>
27#include<random>
28#include<cstring>
29
30using namespace std;
31
32static void determine_new_size(const int w, const int h, int &neww, int &newh,
33 const ThumbnailSize wanted) {
34 if(wanted == TN_SIZE_ORIGINAL) {
35 neww = w;
36 newh = h;
37 } else {
38 int max_dim = ((wanted == TN_SIZE_SMALL) ? 128 : ((wanted == TN_SIZE_LARGE) ? 256 : 512));
39 if(w > h) {
40 neww = max_dim;
41 newh = ((double)(max_dim))*h/w;
42 if (newh == 0)
43 newh = 1;
44 } else {
45 newh = max_dim;
46 neww = ((double)(max_dim))*w/h;
47 if(neww == 0)
48 neww = 1;
49 }
50 }
51}
52
53static GdkPixbuf* fix_orientation(const char *infile, GdkPixbuf *src) {
54 ExifLoader *l;
55 l = exif_loader_new();
56 ExifData *ed;
57 exif_loader_write_file(l, infile);
58 ed = exif_loader_get_data(l);
59 exif_loader_unref(l);
60 GdkPixbuf *rot = nullptr;
61 // Have to do this manually because of
62 // https://bugzilla.gnome.org/show_bug.cgi?id=725582
63 if(ed) {
64 ExifEntry *e = exif_data_get_entry(ed, EXIF_TAG_ORIENTATION);
65 if(e) {
66 int orientation = exif_get_short(e->data, exif_data_get_byte_order(ed));
67 if(orientation == 6) {
68 rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_CLOCKWISE);
69 } else if (orientation == 8) {
70 rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
71 } else if (orientation == 3) {
72 rot = gdk_pixbuf_rotate_simple(src, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
73 } else {
74 // We don't do mirrored images, at least not yet.
75 }
76 }
77 }
78 if(!rot) {
79 // This entire function should only contain this call, really.
80 rot = gdk_pixbuf_apply_embedded_orientation(src);
81 }
82 exif_data_unref(ed);
83 return rot;
84}
85
86class ImageScalerPrivate {
87};
88
89ImageScaler::ImageScaler() {
90 p = new ImageScalerPrivate();
91}
92
93ImageScaler::~ImageScaler() {
94 delete p;
95}
96
97bool ImageScaler::scale(const std::string &ifilename, const std::string &ofilename, ThumbnailSize wanted,
98 const std::string &original_location) const {
99 random_device rnd;
100 assert(ifilename[0] == '/');
101 assert(ofilename[0] == '/');
102 GError *err = nullptr;
103 string ofilename_tmp = ofilename;
104 ofilename_tmp += ".tmp." + to_string(rnd());
105 unique_gobj<GdkPixbuf> orig(gdk_pixbuf_new_from_file(ifilename.c_str(), &err));
106 if(err) {
107 string msg = err->message;
108 g_error_free(err);
109 throw runtime_error(msg);
110 }
111 unique_gobj<GdkPixbuf> src(fix_orientation(ifilename.c_str(), orig.get()));
112 if(!src) {
113 throw runtime_error("Unknown error reorienting image.");
114 }
115 const int w = gdk_pixbuf_get_width(src.get());
116 const int h = gdk_pixbuf_get_height(src.get());
117 if(w == 0 || h == 0) {
118 throw runtime_error("Invalid image resolution.");
119 }
120
121 int neww, newh;
122 determine_new_size(w, h, neww, newh, wanted);
123 unique_gobj<GdkPixbuf> dst(gdk_pixbuf_scale_simple(src.get(), neww, newh, GDK_INTERP_BILINEAR));
124 gboolean save_ok;
125 if(original_location.empty()) {
126 save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err, NULL);
127 } else {
128 assert(original_location[0] == '/');
129 time_t mtime;
130 string uri = "file://" + original_location;
131 struct stat sbuf;
132 if(stat(original_location.c_str(), &sbuf) != 0) {
133 mtime = 0;
134 } else {
135 mtime = sbuf.st_mtim.tv_sec;
136 }
137 string mtime_str = to_string(mtime);
138 save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err,
139 "tEXt::Thumb::URI", uri.c_str(), "tEXt::Thumb::MTime", mtime_str.c_str(), NULL);
140 if(!save_ok) {
141 // Sigh. PNG text chunks are encoded in ISO-8859-1 but this is impossible if
142 // the file name contains e.g. Chinese characters. Fall back to writing the
143 // thumbnail without metadata. This does not conform to the thumbnailing standard
144 // but at least it will give us a working thumbnail.
145 g_error_free(err);
146 err = nullptr;
147 save_ok = gdk_pixbuf_save(dst.get(), ofilename_tmp.c_str(), "png", &err, NULL);
148 }
149 }
150 if(!save_ok) {
151 string msg = err->message;
152 g_error_free(err);
153 throw runtime_error(msg);
154 }
155 if(rename(ofilename_tmp.c_str(), ofilename.c_str()) <0) {
156 string msg("Could not rename temp file to actual file: ");
157 msg += strerror(errno);
158 unlink(ofilename_tmp.c_str()); // Nothing we can do if it fails.
159 throw runtime_error(msg);
160 }
161 return true;
162}
0163
=== added file 'src/lastfmdownloader.cpp'
--- src/lastfmdownloader.cpp 1970-01-01 00:00:00 +0000
+++ src/lastfmdownloader.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/lastfmdownloader.h>
20#include<internal/soupdownloader.h>
21#include<internal/gobj_memory.h>
22#include<memory>
23#include <libxml/parser.h>
24#include <libxml/xmlmemory.h>
25#include <libxml/xpath.h>
26
27const char *NOTFOUND_IMAGE = "http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_medium.png";
28
29using namespace std;
30
31LastFMDownloader::LastFMDownloader() : dl(new SoupDownloader()){
32}
33
34LastFMDownloader::LastFMDownloader(HttpDownloader *o) : dl(o) {
35}
36
37LastFMDownloader::~LastFMDownloader() {
38}
39
40string LastFMDownloader::parseXML(const string &xml) {
41 string node = "/album/coverart/large";
42 unique_ptr<xmlDoc, void(*)(xmlDoc*)> doc(
43 xmlReadMemory(xml.c_str(), xmlStrlen ((xmlChar*) xml.c_str()), NULL, NULL,
44 XML_PARSE_RECOVER | XML_PARSE_NOBLANKS), xmlFreeDoc);
45 if (!doc) {
46 return "";
47 }
48 unique_ptr<xmlXPathContext, void(*)(xmlXPathContext*)> cntx(
49 xmlXPathNewContext(doc.get()), xmlXPathFreeContext);
50
51 unique_ptr<xmlXPathObject, void(*)(xmlXPathObject *)> path(
52 xmlXPathEvalExpression((xmlChar *) node.c_str(), cntx.get()),
53 xmlXPathFreeObject);
54 if (!path) {
55 return "";
56 }
57
58 char *imageurl;
59 if (path->nodesetval->nodeTab) {
60 imageurl = (char *) xmlNodeListGetString(doc.get(),
61 path->nodesetval->nodeTab[0]->xmlChildrenNode, 1);
62 }
63 string url(imageurl);
64 xmlFree(imageurl);
65 return url;
66}
67
68bool LastFMDownloader::download(const std::string &artist,
69 const std::string &album, const std::string &fname) {
70 const char *lastfmTemplate = "http://ws.audioscrobbler.com/1.0/album/%s/%s/info.xml";
71 const int bufsize = 1024;
72 char buf[bufsize];
73 snprintf(buf, bufsize, lastfmTemplate, artist.c_str(), album.c_str());
74 string xml(dl->download(buf));
75 string parsed = parseXML(xml);
76 if(parsed.empty() ||
77 parsed == NOTFOUND_IMAGE) {
78 fprintf(stderr, "Could not find album art.\n");
79 return false;
80 }
81
82 string image(dl->download(parsed));
83 FILE *f = fopen(fname.c_str(), "w");
84 fwrite(image.c_str(), 1, image.length(), f);
85 fclose(f);
86 return true;
87}
088
=== added file 'src/libthumbnailer.map'
--- src/libthumbnailer.map 1970-01-01 00:00:00 +0000
+++ src/libthumbnailer.map 2015-02-04 08:57:20 +0000
@@ -0,0 +1,14 @@
1{
2global:
3 extern "C++" {
4 "Thumbnailer::Thumbnailer()";
5 "Thumbnailer::~Thumbnailer()";
6 "Thumbnailer::get_thumbnail(std::string const&, ThumbnailSize)";
7 "Thumbnailer::get_thumbnail(std::string const&, ThumbnailSize, ThumbnailPolicy)";
8 "Thumbnailer::get_album_art(std::string const&, std::string const&, ThumbnailSize, ThumbnailPolicy)";
9 };
10local:
11 extern "C++" {
12 *;
13 };
14};
015
=== added file 'src/mediaartcache.cpp'
--- src/mediaartcache.cpp 1970-01-01 00:00:00 +0000
+++ src/mediaartcache.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,201 @@
1/*
2 * Copyright (C) 2012-2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/mediaartcache.h>
20
21#include<dirent.h>
22#include<sys/stat.h>
23#include<fcntl.h>
24#include<unistd.h>
25#include<errno.h>
26#include<stdio.h>
27#include<string.h>
28#include<stdlib.h>
29#include<assert.h>
30#include<utime.h>
31
32#include<glib.h>
33
34#include<vector>
35#include<algorithm>
36#include<stdexcept>
37
38using namespace std;
39
40static string md5(const string &str) {
41 const unsigned char *buf = (const unsigned char *)str.c_str();
42 char *normalized = g_utf8_normalize((const gchar*)buf, str.size(), G_NORMALIZE_ALL);
43 string final;
44 gchar *result;
45
46 if(normalized) {
47 buf = (const unsigned char*)normalized;
48 }
49
50 result = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, strlen((const char*)buf));
51 final = result;
52 g_free((gpointer)normalized);
53 g_free(result);
54 return final;
55}
56
57MediaArtCache::MediaArtCache() {
58 string xdg_base = g_get_user_cache_dir();
59
60 if (xdg_base == "") {
61 string s("Could not determine cache dir.");
62 throw runtime_error(s);
63 }
64 int ec = mkdir(xdg_base.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
65 if (ec < 0 && errno != EEXIST) {
66 string s("Could not create base dir.");
67 throw runtime_error(s);
68 }
69 root_dir = xdg_base + "/media-art";
70 ec = mkdir(root_dir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
71 if (ec < 0 && errno != EEXIST) {
72 string s("Could not create cache dir.");
73 throw runtime_error(s);
74 }
75}
76
77bool MediaArtCache::has_art(const std::string &artist, const std::string &album) const {
78 string fname = get_art_file(artist, album);
79 return access(fname.c_str(), R_OK) == 0;
80}
81
82void MediaArtCache::add_art(const std::string &artist, const std::string &album,
83 const char *data, unsigned int datalen) {
84 string abs_fname = get_full_filename(artist, album);
85 GError *err = nullptr;
86 if(!g_file_set_contents(abs_fname.c_str(), data, datalen, &err)) {
87 string e("Could not write file ");
88 e += abs_fname;
89 e += ": ";
90 e += err->message;
91 g_error_free(err);
92 throw runtime_error(e);
93 }
94}
95
96string MediaArtCache::get_art_file(const std::string &artist, const std::string &album) const {
97 string abs_fname = get_full_filename(artist, album);
98
99 if (access(abs_fname.c_str(), R_OK) == 0) {
100 utime(abs_fname.c_str(), nullptr); // update access times to current time
101 return abs_fname;
102 }
103 return "";
104}
105
106string MediaArtCache::get_art_uri(const string &artist, const string &album) const
107{
108 std::string filename = get_art_file(artist, album);
109
110 if (filename == "") {
111 return "";
112 }
113
114 GError *err = nullptr;
115 char *c_uri = g_filename_to_uri(filename.c_str(), "", &err);
116 if (!c_uri) {
117 string e("Could not convert file name ");
118 e += filename;
119 e += " to URI: ";
120 e += err->message;
121 g_error_free(err);
122 throw runtime_error(e);
123 }
124
125 std::string uri = c_uri;
126 g_free(c_uri);
127 return uri;
128}
129
130std::string MediaArtCache::get_full_filename(const std::string &artist, const std::string & album) const {
131 return root_dir + "/" + compute_base_name(artist, album);
132}
133
134
135std::string MediaArtCache::compute_base_name(const std::string &artist, const std::string &album) const {
136 string type = "album";
137 string h1 = md5(artist);
138 string h2 = md5(album);
139 return type + "-" + h1 + "-" + h2 + ".jpg";
140}
141
142
143void MediaArtCache::clear() const {
144 DIR *d = opendir(root_dir.c_str());
145 if(!d) {
146 string s = "Something went wrong.";
147 throw runtime_error(s);
148 }
149 struct dirent *entry, *de;
150 entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX + 1);
151 while(readdir_r(d, entry, &de) == 0 && de) {
152 string basename = entry->d_name;
153 if (basename == "." || basename == "..")
154 continue;
155 string fname = root_dir + "/" + basename;
156 if(remove(fname.c_str()) < 0) {
157 // This is not really an error worth
158 // halting everything for.
159 fprintf(stderr, "Could not delete file %s: %s.\n", fname.c_str(),
160 strerror(errno));
161 }
162 }
163 free(entry);
164 closedir(d);
165}
166
167void MediaArtCache::prune() {
168 vector<pair<double, string>> mtimes;
169 DIR *d = opendir(root_dir.c_str());
170 if(!d) {
171 string s = "Something went wrong.";
172 throw runtime_error(s);
173 }
174 struct dirent *entry, *de;
175 entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX + 1);
176 while(readdir_r(d, entry, &de) == 0 && de) {
177 string basename = entry->d_name;
178 if (basename == "." || basename == "..")
179 continue;
180 string fname = root_dir + "/" + basename;
181 struct stat sbuf;
182 if(stat(fname.c_str(), &sbuf) != 0) {
183 continue;
184 }
185 // Use mtime because atime is not guaranteed to work if, for example
186 // the filesystem is mounted with noatime or relatime.
187 mtimes.push_back(make_pair(sbuf.st_mtim.tv_sec + sbuf.st_mtim.tv_nsec/1000000000.0, fname));
188 }
189 free(entry);
190 closedir(d);
191 if (mtimes.size() <= MAX_SIZE)
192 return;
193 sort(mtimes.begin(), mtimes.end());
194 for(size_t i=0; i < mtimes.size()-MAX_SIZE; i++) {
195 if(remove(mtimes[i].second.c_str()) < 0) {
196 fprintf(stderr, "Could not remove file %s: %s.\n",
197 mtimes[i].second.c_str(), strerror(errno));
198 }
199 }
200}
201
0202
=== added directory 'src/service'
=== added file 'src/service/CMakeLists.txt'
--- src/service/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/service/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,34 @@
1add_definitions(${THUMBNAILER_CFLAGS})
2include_directories(${CMAKE_CURRENT_BINARY_DIR})
3
4add_executable(thumbnailer-service
5 main.cpp
6 dbusinterface.cpp
7 dbus-generated.c
8)
9
10target_link_libraries(thumbnailer-service thumbnailer)
11
12install(
13 TARGETS thumbnailer-service
14 RUNTIME DESTINATION ${SHARE_PRIV_DIR}
15)
16
17find_program(gdbus_codegen gdbus-codegen)
18if(NOT gdbus_codegen)
19 msg(FATAL_ERROR "Could not locate gdbus-codegen")
20endif()
21
22add_custom_command(
23 OUTPUT dbus-generated.c dbus-generated.h
24 COMMAND ${gdbus_codegen} --interface-prefix=com.canonical. --generate-c-code dbus-generated --c-namespace TN ${CMAKE_CURRENT_SOURCE_DIR}/dbus-interface.xml
25 MAIN_DEPENDENCY dbus-interface.xml
26)
27
28# Install the service file.
29configure_file(com.canonical.Thumbnailer.service.in com.canonical.Thumbnailer.service)
30
31install(
32 FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.Thumbnailer.service
33 DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services
34)
035
=== added file 'src/service/com.canonical.Thumbnailer.service.in'
--- src/service/com.canonical.Thumbnailer.service.in 1970-01-01 00:00:00 +0000
+++ src/service/com.canonical.Thumbnailer.service.in 2015-02-04 08:57:20 +0000
@@ -0,0 +1,4 @@
1[D-BUS Service]
2Name=com.canonical.Thumbnailer
3Exec=@SHARE_PRIV_ABS@/thumbnailer-service
4
05
=== added file 'src/service/dbus-interface.xml'
--- src/service/dbus-interface.xml 1970-01-01 00:00:00 +0000
+++ src/service/dbus-interface.xml 2015-02-04 08:57:20 +0000
@@ -0,0 +1,17 @@
1<node>
2 <interface name="com.canonical.Thumbnailer">
3 <method name="GetAlbumArt">
4 <arg direction="in" type="s" name="artist" />
5 <arg direction="in" type="s" name="album" />
6 <!-- possible values are "small", "large", "xlarge" and "original" -->
7 <arg direction="in" type="s" name="desiredSize" />
8 <arg direction="out" type="h" name="fd" />
9 <annotation name="org.gtk.GDBus.C.UnixFD" value="true" />
10 </method>
11
12 <!-- Note: if adding additional thumbnailing methods that take a
13 file name as input, ensure that the calling process has
14 permission to read said file. Otherwise we will leak
15 information to confined applications. -->
16 </interface>
17</node>
018
=== added file 'src/service/dbusinterface.cpp'
--- src/service/dbusinterface.cpp 1970-01-01 00:00:00 +0000
+++ src/service/dbusinterface.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,168 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of version 3 of the GNU General Public License as published
9 * by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "dbusinterface.h"
21
22#include <cstdio>
23#include <cstring>
24#include <memory>
25#include <stdexcept>
26#include <string>
27#include <thread>
28#include <fcntl.h>
29#include <unistd.h>
30
31#include <glib.h>
32#include <glib-object.h>
33#include <gio/gio.h>
34#include <gio/gunixfdlist.h>
35#include <thumbnailer.h>
36
37#include <internal/gobj_memory.h>
38#include "dbus-generated.h"
39
40using namespace std;
41
42static const char BUS_NAME[] = "com.canonical.MediaScanner2";
43static const char ART_ERROR[] = "com.canonical.MediaScanner2.Error.Failed";
44
45static const char MISSING_ALBUM_ART[] = "/usr/share/unity/icons/album_missing.png";
46
47struct DBusInterfacePrivate {
48 const std::string bus_path;
49 unique_gobj<GDBusConnection> bus;
50 unique_gobj<TNThumbnailer> iface;
51 unsigned int handler_id;
52 std::shared_ptr<Thumbnailer> thumbnailer;
53
54 DBusInterfacePrivate(GDBusConnection *g_bus, const std::string& bus_path)
55 : bus_path(bus_path),
56 bus(static_cast<GDBusConnection*>(g_object_ref(g_bus))),
57 iface(tn_thumbnailer_skeleton_new()),
58 handler_id(0),
59 thumbnailer(std::make_shared<Thumbnailer>()) {
60 handler_id = g_signal_connect(
61 iface.get(), "handle-get-album-art",
62 G_CALLBACK(&DBusInterfacePrivate::handleGetAlbumArt), this);
63
64 GError *error = nullptr;
65 if (!g_dbus_interface_skeleton_export(
66 G_DBUS_INTERFACE_SKELETON(iface.get()), bus.get(),
67 bus_path.c_str(), &error)) {
68 string errortxt(error->message);
69 g_error_free(error);
70
71 string msg = "Failed to export interface: ";
72 msg += errortxt;
73 throw runtime_error(msg);
74 }
75 }
76
77 ~DBusInterfacePrivate() {
78 g_dbus_interface_skeleton_unexport(
79 G_DBUS_INTERFACE_SKELETON(iface.get()));
80 g_signal_handler_disconnect(iface.get(), handler_id);
81 }
82
83 static gboolean handleGetAlbumArt(TNThumbnailer *iface, GDBusMethodInvocation *invocation, GUnixFDList *, const char *artist, const char *album, const char *size, void *user_data) {
84 auto p = static_cast<DBusInterfacePrivate*>(user_data);
85 fprintf(stderr, "Look up cover art for %s/%s at size %s\n", artist, album, size);
86
87 ThumbnailSize desiredSize;
88 if (!strcmp(size, "small")) {
89 desiredSize = TN_SIZE_SMALL;
90 } else if (!strcmp(size, "large")) {
91 desiredSize = TN_SIZE_LARGE;
92 } else if (!strcmp(size, "xlarge")) {
93 desiredSize = TN_SIZE_XLARGE;
94 } else if (!strcmp(size, "original")) {
95 desiredSize = TN_SIZE_ORIGINAL;
96 } else {
97 std::string error("Unknown size: ");
98 error += size;
99 g_dbus_method_invocation_return_dbus_error(
100 invocation, ART_ERROR, error.c_str());
101 return TRUE;
102 }
103
104 try {
105 std::thread t(&getAlbumArt,
106 unique_gobj<TNThumbnailer>(static_cast<TNThumbnailer*>(g_object_ref(iface))),
107 unique_gobj<GDBusMethodInvocation>(static_cast<GDBusMethodInvocation*>(g_object_ref(invocation))),
108 p->thumbnailer,
109 std::string(artist), std::string(album), desiredSize);
110 t.detach();
111 } catch (const std::exception &e) {
112 g_dbus_method_invocation_return_dbus_error(
113 invocation, ART_ERROR, e.what());
114 }
115 return TRUE;
116 }
117
118 static void getAlbumArt(unique_gobj<TNThumbnailer> iface,
119 unique_gobj<GDBusMethodInvocation> invocation,
120 std::shared_ptr<Thumbnailer> thumbnailer,
121 const std::string artist, const std::string album,
122 ThumbnailSize desiredSize) {
123 std::string art;
124 try {
125 art = thumbnailer->get_album_art(
126 artist, album, desiredSize, TN_REMOTE);
127 } catch (const std::exception &e) {
128 g_dbus_method_invocation_return_dbus_error(
129 invocation.get(), ART_ERROR, e.what());
130 return;
131 }
132
133 if (art.empty()) {
134 g_dbus_method_invocation_return_dbus_error(
135 invocation.get(), ART_ERROR, "Could not get thumbnail");
136 return;
137 }
138 int fd = open(art.c_str(), O_RDONLY);
139 if (fd < 0) {
140 g_dbus_method_invocation_return_dbus_error(
141 invocation.get(), ART_ERROR, strerror(errno));
142 return;
143 }
144
145 unique_gobj<GUnixFDList> fd_list(g_unix_fd_list_new());
146 GError *error = nullptr;
147 g_unix_fd_list_append(fd_list.get(), fd, &error);
148 close(fd);
149 if (error != nullptr) {
150 g_dbus_method_invocation_return_dbus_error(
151 invocation.get(), ART_ERROR, error->message);
152 g_error_free(error);
153 return;
154 }
155
156 tn_thumbnailer_complete_get_album_art(
157 iface.get(), invocation.get(), fd_list.get(), g_variant_new_handle(0));
158 }
159
160};
161
162DBusInterface::DBusInterface(GDBusConnection *bus, const std::string& bus_path)
163 : p(new DBusInterfacePrivate(bus, bus_path)) {
164}
165
166DBusInterface::~DBusInterface() {
167 delete p;
168}
0169
=== added file 'src/service/dbusinterface.h'
--- src/service/dbusinterface.h 1970-01-01 00:00:00 +0000
+++ src/service/dbusinterface.h 2015-02-04 08:57:20 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This library is free software; you can redistribute it and/or modify it under
8 * the terms of version 3 of the GNU General Public License as published
9 * by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef DBUSINTERFACE_H
21#define DBUSINTERFACE_H
22
23#include <string>
24
25struct DBusInterfacePrivate;
26typedef struct _GDBusConnection GDBusConnection;
27
28class DBusInterface final {
29public:
30 DBusInterface(GDBusConnection *bus, const std::string& bus_path);
31 ~DBusInterface();
32
33 DBusInterface(const DBusInterface&) = delete;
34 DBusInterface& operator=(DBusInterface&) = delete;
35
36private:
37 DBusInterfacePrivate *p;
38};
39
40#endif
041
=== added file 'src/service/main.cpp'
--- src/service/main.cpp 1970-01-01 00:00:00 +0000
+++ src/service/main.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,44 @@
1#include <cstdio>
2#include <memory>
3#include <stdexcept>
4#include <glib.h>
5#include <gio/gio.h>
6
7#include "dbusinterface.h"
8
9static const char BUS_NAME[] = "com.canonical.Thumbnailer";
10static const char BUS_PATH[] = "/com/canonical/Thumbnailer";
11
12static std::unique_ptr<GMainLoop,void(*)(GMainLoop*)> main_loop(
13 g_main_loop_new(nullptr, FALSE), g_main_loop_unref);
14
15static void nameLost(GDBusConnection *, const char *, void *) {
16 fprintf(stderr, "Could no acquire D-Bus name %s. Quitting.\n", BUS_NAME);
17 g_main_loop_quit(main_loop.get());
18}
19
20int main(int argc, char **argv) {
21 GError *error = nullptr;
22 std::unique_ptr<GDBusConnection, void(*)(void*)> bus(
23 g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error),
24 g_object_unref);
25 if (error != nullptr) {
26 fprintf(stderr, "Failed to connect to session bus: %s\n", error->message);
27 g_error_free(error);
28 return 1;
29 }
30
31 DBusInterface dbus(bus.get(), BUS_PATH);
32
33 unsigned int name_id = g_bus_own_name_on_connection(
34 bus.get(), BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE,
35 nullptr, &nameLost, nullptr, nullptr);
36
37 g_main_loop_run(main_loop.get());
38
39 if (name_id != 0) {
40 g_bus_unown_name(name_id);
41 }
42
43 return 0;
44}
045
=== added file 'src/soupdownloader.cpp'
--- src/soupdownloader.cpp 1970-01-01 00:00:00 +0000
+++ src/soupdownloader.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/soupdownloader.h>
20#include<libsoup/soup.h>
21#include<internal/gobj_memory.h>
22#include<stdexcept>
23
24SoupDownloader::SoupDownloader() {
25 session = soup_session_sync_new();
26 if(!session) {
27 throw std::runtime_error("Could not create Soup session.");
28 }
29}
30
31SoupDownloader::~SoupDownloader() {
32 g_object_unref(G_OBJECT(session));
33}
34
35std::string SoupDownloader::download(const std::string &url) {
36 unique_gobj<SoupMessage> msg(soup_message_new("GET", url.c_str()));
37 guint status;
38 status = soup_session_send_message(session, msg.get());
39 if(!SOUP_STATUS_IS_SUCCESSFUL(status)) {
40 fprintf(stderr, "Determination failed.\n");
41 return "";
42 }
43 std::string result(msg->response_body->data, msg->response_body->length);
44 return result;
45}
46
047
=== added file 'src/thumbnailcache.cpp'
--- src/thumbnailcache.cpp 1970-01-01 00:00:00 +0000
+++ src/thumbnailcache.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,300 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#ifndef _POSIX_SOURCE
20#define _POSIX_SOURCE
21#endif
22
23#include<thumbnailer.h>
24#include<internal/thumbnailcache.h>
25#include<stdexcept>
26#include<glib.h>
27#include<sys/stat.h>
28#include<sys/types.h>
29#include<cassert>
30#include<cstdio>
31#include<cstring>
32#include<errno.h>
33#include<fcntl.h>
34#include<unistd.h>
35#include<vector>
36#include<algorithm>
37#include<dirent.h>
38
39using namespace std;
40
41static void cleardir(const string &root_dir) {
42 DIR *d = opendir(root_dir.c_str());
43 if(!d) {
44 string s = "Something went wrong.";
45 throw runtime_error(s);
46 }
47 struct dirent *entry, *de;
48 entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
49 while(readdir_r(d, entry, &de) == 0 && de) {
50 string basename = entry->d_name;
51 if (basename == "." || basename == "..")
52 continue;
53 string fname = root_dir + "/" + basename;
54 remove(fname.c_str());
55 }
56 free(entry);
57 closedir(d);
58}
59
60/*
61 * This code is copied from mediaartcache. All tests etc
62 * are there. When we merge the two, remove this and
63 * make both use the same code.
64 */
65static void prune_dir(const string &root_dir, const size_t max_files) {
66 vector<pair<double, string>> mtimes;
67 DIR *d = opendir(root_dir.c_str());
68 if(!d) {
69 string s = "Something went wrong.";
70 throw runtime_error(s);
71 }
72 struct dirent *entry, *de;
73 entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
74 while(readdir_r(d, entry, &de) == 0 && de) {
75 string basename = entry->d_name;
76 if (basename == "." || basename == "..")
77 continue;
78 string fname = root_dir + "/" + basename;
79 struct stat sbuf;
80 if(stat(fname.c_str(), &sbuf) != 0) {
81 continue;
82 }
83 // Use mtime because atime is not guaranteed to work if, for example
84 // the filesystem is mounted with noatime or relatime.
85 mtimes.push_back(make_pair(sbuf.st_mtim.tv_sec + sbuf.st_mtim.tv_nsec/1000000000.0, fname));
86 }
87 free(entry);
88 closedir(d);
89 if (mtimes.size() <= max_files)
90 return;
91 sort(mtimes.begin(), mtimes.end());
92 for(size_t i=0; i < mtimes.size()-max_files; i++) {
93 remove(mtimes[i].second.c_str());
94 }
95}
96
97static string get_app_pkg_name() {
98 const int bufsize = 1024;
99 char data[bufsize+1];
100 FILE *f = fopen("/proc/self/attr/current", "r");
101 if(!f) {
102 throw runtime_error("Could not open /proc/self/attr/current.");
103 }
104 size_t numread = fread(data, 1, bufsize, f);
105 fclose(f);
106 if(numread == 0) {
107 throw runtime_error("Could not read from /proc/self/attr/current.");
108 }
109 data[numread] = '\0';
110 string core(data);
111 string::size_type ind = core.find('_');
112 if(ind == string::npos) {
113 throw runtime_error("/proc/self/attr/current malformed, does not have _ in it.");
114 }
115 if(ind == 0) {
116 throw runtime_error("/proc/self/attr/current malformed, starts with '_'.");
117 }
118 return core.substr(0, ind);
119}
120
121class ThumbnailCachePrivate {
122public:
123
124 ThumbnailCachePrivate();
125 string md5(const string &str) const;
126 string get_cache_file_name(const std::string &original, ThumbnailSize desired) const;
127 void clear();
128 void delete_from_cache(const std::string &abs_path);
129 void prune();
130
131private:
132 string tndir;
133 string smalldir;
134 string largedir;
135 string xlargedir;
136 string originaldir;
137 static const size_t MAX_FILES = 200;
138
139};
140
141void ThumbnailCachePrivate::clear() {
142 cleardir(smalldir);
143 cleardir(largedir);
144 cleardir(xlargedir);
145 cleardir(originaldir);
146}
147
148
149void ThumbnailCachePrivate::prune() {
150 prune_dir(smalldir, MAX_FILES);
151 prune_dir(largedir, MAX_FILES);
152 prune_dir(xlargedir, MAX_FILES);
153 prune_dir(originaldir, MAX_FILES);
154}
155
156void ThumbnailCachePrivate::delete_from_cache(const std::string &abs_path) {
157 unlink(get_cache_file_name(abs_path, TN_SIZE_SMALL).c_str());
158 unlink(get_cache_file_name(abs_path, TN_SIZE_LARGE).c_str());
159 unlink(get_cache_file_name(abs_path, TN_SIZE_XLARGE).c_str());
160 unlink(get_cache_file_name(abs_path, TN_SIZE_ORIGINAL).c_str());
161}
162
163static string makedir(const string &base, const string &subdir) {
164 string dirname = base;
165 dirname += "/";
166 dirname += subdir;
167 int ec;
168 errno = 0;
169 ec = mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
170 if (ec < 0 && errno != EEXIST) {
171 string s("Could not create ");
172 s += subdir;
173 s += " - ";
174 s += strerror(errno);
175 throw runtime_error(s);
176 }
177 return dirname;
178}
179
180ThumbnailCachePrivate::ThumbnailCachePrivate() {
181 string xdg_base = g_get_user_cache_dir();
182 if (xdg_base == "") {
183 string s("Could not determine cache dir.");
184 throw runtime_error(s);
185 }
186 int ec = mkdir(xdg_base.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
187 if (ec < 0 && errno != EEXIST) {
188 string s("Could not create base dir - ");
189 s += strerror(errno);
190 throw runtime_error(s);
191 }
192 // This is where it gets tricky. Desktop apps can write to
193 // cache dir but confined apps only to cache/appname/
194 // First try global cache and fall back to app-specific one.
195 string testfile = xdg_base + "/tncache-write-text.null";
196 int fd = open(testfile.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
197 bool use_global = true;
198 if(fd<0) {
199 if(errno == EACCES) {
200 use_global = false;
201 } else {
202 string s("Unknown error when checking cache access: ");
203 s += strerror(errno);
204 throw runtime_error(s);
205 }
206 } else {
207 use_global = true;
208 close(fd);
209 unlink(testfile.c_str());
210 }
211 if(!use_global) {
212 string app_pkgname = get_app_pkg_name();
213 xdg_base = makedir(xdg_base, app_pkgname);
214 }
215 tndir = xdg_base + "/thumbnails";
216 tndir = makedir(xdg_base, "thumbnails");
217 smalldir = makedir(tndir,"normal");
218 largedir = makedir(tndir, "large");
219 xlargedir = makedir(tndir, "xlarge");
220 originaldir = makedir(tndir, "original");
221}
222
223string ThumbnailCachePrivate::md5(const string &str) const {
224 const unsigned char *buf = (const unsigned char *)str.c_str();
225 char *normalized = g_utf8_normalize((const gchar*)buf, str.size(), G_NORMALIZE_ALL);
226 string final_result;
227 gchar *result;
228
229 if(normalized) {
230 buf = (const unsigned char*)normalized;
231 }
232 gssize bytes = str.length();
233
234 result = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, bytes);
235 final_result = result;
236 g_free((gpointer)normalized);
237 g_free(result);
238 return final_result;
239}
240
241string ThumbnailCachePrivate::get_cache_file_name(const std::string & abs_original, ThumbnailSize desired) const {
242 assert(abs_original[0] == '/');
243 string path;
244 switch(desired) {
245 case TN_SIZE_SMALL : path = smalldir; break;
246 case TN_SIZE_LARGE : path = largedir; break;
247 case TN_SIZE_XLARGE : path = xlargedir; break;
248 case TN_SIZE_ORIGINAL : path = originaldir; break;
249 default : throw runtime_error("Unreachable code");
250 }
251 path += "/" + md5("file://" + abs_original) + ".png";
252 return path;
253}
254
255ThumbnailCache::ThumbnailCache() : p(new ThumbnailCachePrivate()) {
256}
257
258ThumbnailCache::~ThumbnailCache() {
259 delete p;
260}
261
262std::string ThumbnailCache::get_if_exists(const std::string &abs_path, ThumbnailSize desired_size) const {
263 assert(abs_path[0] == '/');
264 string fname = p->get_cache_file_name(abs_path, desired_size);
265 FILE *f = fopen(abs_path.c_str(), "r");
266 if(!f) {
267 p->delete_from_cache(abs_path);
268 return "";
269 }
270 fclose(f);
271 f = fopen(fname.c_str(), "r");
272 bool existed = false;
273 if(f) {
274 existed = true;
275 fclose(f);
276 }
277 // Has it been changed since the thumbnail was taken?
278 if(existed) {
279 struct stat original, thumbnail;
280 stat(abs_path.c_str(), &original);
281 stat(fname.c_str(), &thumbnail);
282 if(original.st_mtime > thumbnail.st_mtime) {
283 p->delete_from_cache(abs_path);
284 return "";
285 }
286 }
287 return existed ? fname : string("");
288}
289
290std::string ThumbnailCache::get_cache_file_name(const std::string &abs_path, ThumbnailSize desired) const {
291 return p->get_cache_file_name(abs_path, desired);
292}
293
294void ThumbnailCache::clear() {
295 p->clear();
296}
297
298void ThumbnailCache::prune() {
299 p->prune();
300}
0301
=== added file 'src/thumbnailer.cpp'
--- src/thumbnailer.cpp 1970-01-01 00:00:00 +0000
+++ src/thumbnailer.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,226 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<thumbnailer.h>
20#include<internal/thumbnailcache.h>
21#include<internal/audioimageextractor.h>
22#include<internal/videoscreenshotter.h>
23#include<internal/imagescaler.h>
24#include<internal/mediaartcache.h>
25#include<internal/lastfmdownloader.h>
26#include<gdk-pixbuf/gdk-pixbuf.h>
27#include<unistd.h>
28#include<gst/gst.h>
29#include<stdexcept>
30#include<random>
31#include<gio/gio.h>
32#include<glib.h>
33#include<memory>
34
35using namespace std;
36
37class ThumbnailerPrivate {
38private:
39 random_device rnd;
40
41 string create_audio_thumbnail(const string &abspath, ThumbnailSize desired_size,
42 ThumbnailPolicy policy);
43 string create_video_thumbnail(const string &abspath, ThumbnailSize desired_size);
44 string create_generic_thumbnail(const string &abspath, ThumbnailSize desired_size);
45
46public:
47 ThumbnailCache cache;
48// AudioImageExtractor audio;
49 VideoScreenshotter video;
50 ImageScaler scaler;
51 MediaArtCache macache;
52 LastFMDownloader lfm;
53
54 ThumbnailerPrivate() {};
55
56 string create_thumbnail(const string &abspath, ThumbnailSize desired_size,
57 ThumbnailPolicy policy);
58 string create_random_filename();
59};
60
61
62string ThumbnailerPrivate::create_random_filename() {
63 string fname;
64 char *dirbase = getenv("TMPDIR"); // Set when in a confined application.
65 if(dirbase) {
66 fname = dirbase;
67 } else {
68 fname = "/tmp";
69 }
70 fname += "/thumbnailer.";
71 fname += to_string(rnd());
72 fname += ".tmp";
73 return fname;
74}
75
76string ThumbnailerPrivate::create_audio_thumbnail(const string &/*abspath*/,
77 ThumbnailSize /*desired_size*/, ThumbnailPolicy /*policy*/) {
78 // There was a symbol clash between 1.0 and 0.10 versions of
79 // GStreamer on the desktop so we need to disable in-process
80 // usage of gstreamer. Re-enable this once desktop moves to
81 // newer Qt multimedia that has GStreamer 1.0.
82/*
83 try {
84 if(audio.extract(abspath, tmpname)) {
85 extracted = true;
86 }
87 } catch(runtime_error &e) {
88 }
89 if(extracted) {
90 scaler.scale(tmpname, tnfile, desired_size, abspath); // If this throws, let it propagate.
91 unlink(tmpname.c_str());
92 return tnfile;
93 }
94 */
95 return "";
96}
97string ThumbnailerPrivate::create_generic_thumbnail(const string &abspath, ThumbnailSize desired_size) {
98 int tmpw, tmph;
99 string tnfile = cache.get_cache_file_name(abspath, desired_size);
100 // Special case: full size image files are their own preview.
101 if(desired_size == TN_SIZE_ORIGINAL &&
102 gdk_pixbuf_get_file_info(abspath.c_str(), &tmpw, &tmph)) {
103 return abspath;
104 }
105 try {
106 if(scaler.scale(abspath, tnfile, desired_size, abspath))
107 return tnfile;
108 } catch(runtime_error &e) {
109 }
110 return "";
111}
112
113string ThumbnailerPrivate::create_video_thumbnail(const string &abspath, ThumbnailSize desired_size) {
114 string tnfile = cache.get_cache_file_name(abspath, desired_size);
115 string tmpname = create_random_filename();
116 if(video.extract(abspath, tmpname)) {
117 scaler.scale(tmpname, tnfile, desired_size, abspath);
118 unlink(tmpname.c_str());
119 return tnfile;
120 }
121 throw runtime_error("Video extraction failed.");
122}
123
124string ThumbnailerPrivate::create_thumbnail(const string &abspath, ThumbnailSize desired_size,
125 ThumbnailPolicy policy) {
126 // Every now and then see if we have too much stuff and delete them if so.
127 if((rnd() % 100) == 0) { // No, this is not perfectly random. It does not need to be.
128 cache.prune();
129 }
130 std::unique_ptr<GFile, void(*)(void *)> file(
131 g_file_new_for_path(abspath.c_str()), g_object_unref);
132 if(!file) {
133 return "";
134 }
135
136 std::unique_ptr<GFileInfo, void(*)(void *)> info(
137 g_file_query_info(file.get(), G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
138 G_FILE_QUERY_INFO_NONE, /* cancellable */ NULL, /* error */NULL),
139 g_object_unref);
140 if(!info) {
141 return "";
142 }
143
144 std::string content_type(g_file_info_get_content_type(info.get()));
145 if (content_type.empty()) {
146 return "";
147 }
148
149 if (content_type.find("audio/") == 0) {
150 return create_audio_thumbnail(abspath, desired_size, policy);
151 }
152
153 if (content_type.find("video/") == 0) {
154 return create_video_thumbnail(abspath, desired_size);
155 }
156
157 return create_generic_thumbnail(abspath, desired_size);
158}
159
160Thumbnailer::Thumbnailer() {
161 g_type_init(); // Unfortunately still needed in precise.
162 p = new ThumbnailerPrivate();
163}
164
165Thumbnailer::~Thumbnailer() {
166 delete p;
167}
168std::string Thumbnailer::get_thumbnail(const std::string &filename, ThumbnailSize desired_size,
169 ThumbnailPolicy policy) {
170 string abspath;
171 if(filename[0] != '/') {
172 abspath += getcwd(nullptr, 0);
173 abspath += "/" + filename;
174 } else {
175 abspath = filename;
176 }
177 std::string estimate = p->cache.get_if_exists(abspath, desired_size);
178 if(!estimate.empty())
179 return estimate;
180 string generated = p->create_thumbnail(abspath, desired_size, policy);
181 if(generated == abspath) {
182 return abspath;
183 }
184 return p->cache.get_if_exists(abspath, desired_size);
185}
186
187string Thumbnailer::get_thumbnail(const string &filename, ThumbnailSize desired_size) {
188 return get_thumbnail(filename, desired_size, TN_LOCAL);
189}
190
191std::string Thumbnailer::get_album_art(const std::string &artist, const std::string &album,
192 ThumbnailSize desired_size, ThumbnailPolicy policy) {
193 if(!p->macache.has_art(artist, album)) {
194 if(policy == TN_LOCAL) {
195 // We don't have it cached and can't access the net
196 // -> nothing to be done.
197 return "";
198 }
199 char filebuf[] = "/tmp/some/long/text/here/so/path/will/fit";
200 std::string tmpname = tmpnam(filebuf);
201 if(!p->lfm.download(artist, album, tmpname)) {
202 return "";
203 }
204 gchar *contents;
205 gsize content_size;
206 GError *err = nullptr;
207 if(!g_file_get_contents(tmpname.c_str(), &contents, &content_size, &err)) {
208 unlink(tmpname.c_str());
209 std::string msg("Error reading file: ");
210 msg += err->message;
211 g_error_free(err);
212 throw std::runtime_error(msg);
213 }
214 unlink(tmpname.c_str());
215 unique_ptr<gchar, void(*)(gpointer)> deleter(contents, g_free);
216 p->macache.add_art(artist, album, contents, content_size);
217 }
218 // At this point we know we have the image in our art cache (unless
219 // someone just deleted it concurrently, in which case we can't
220 // really do anything.
221 std::string original = p->macache.get_art_file(artist, album);
222 if(desired_size == TN_SIZE_ORIGINAL) {
223 return original;
224 }
225 return get_thumbnail(original, desired_size, policy);
226}
0227
=== added file 'src/videoscreenshotter.cpp'
--- src/videoscreenshotter.cpp 1970-01-01 00:00:00 +0000
+++ src/videoscreenshotter.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,105 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/config.h>
20#include<internal/videoscreenshotter.h>
21
22#include<unistd.h>
23#include<sys/wait.h>
24#include<stdexcept>
25#include<cstring>
26#include<sys/time.h>
27#include<signal.h>
28#include<time.h>
29
30using namespace std;
31static double timestamp() {
32 struct timeval now;
33 gettimeofday(&now, NULL);
34 return now.tv_sec + now.tv_usec/1000000.0;
35
36}
37
38static bool wait_for_helper(pid_t child) {
39 const double max_wait_time = 10;
40 struct timespec sleep_time;
41 double start = timestamp();
42 sleep_time.tv_sec = 0;
43 sleep_time.tv_nsec = 100000000;
44 int status;
45 while(waitpid(child, &status, WNOHANG) == 0) {
46 struct timespec dummy;
47 double now = timestamp();
48 if(now - start >= max_wait_time) {
49 if(kill(child, SIGKILL) < 0) {
50 string msg("Could not kill child process: ");
51 msg += strerror(errno);
52 throw runtime_error(msg);
53 }
54 waitpid(child, &status, 0);
55 throw runtime_error("Helper process took too long.");
56 }
57 nanosleep(&sleep_time, &dummy);
58 }
59 if(status < 0) {
60 throw runtime_error("Waiting for child process failed.");
61 }
62 if(status == 0) {
63 return true;
64 }
65 if(status == 1) {
66 return false;
67 }
68 if(status == 2) {
69 throw runtime_error("Video extractor pipeline failed");
70 }
71 throw runtime_error("Unknown error when trying to extract video screenshot.");
72}
73
74VideoScreenshotter::VideoScreenshotter() {
75}
76
77VideoScreenshotter::~VideoScreenshotter() {
78}
79
80bool VideoScreenshotter::extract(const std::string &ifname, const std::string &ofname) {
81 // Gstreamer video pipelines are unstable so we need to run an
82 // external helper library.
83 string exe_path;
84 char *utildir = getenv("TN_UTILDIR");
85 exe_path = utildir ? utildir : SHARE_PRIV_ABS;
86 string cmd(exe_path + "/vs-thumb");
87 pid_t child = fork();
88 if(child == -1) {
89 throw runtime_error("Could not spawn worker process.");
90 }
91 if(child == 0) {
92 execl(cmd.c_str(), cmd.c_str(), ifname.c_str(), ofname.c_str(), (char*) NULL);
93 fprintf(stderr, "Could not execute worker process: %s", strerror(errno));
94 _exit(100);
95 } else {
96 try {
97 return wait_for_helper(child);
98 } catch(...) {
99 unlink(ofname.c_str());
100 throw;
101 }
102 }
103 throw runtime_error("Code that should not have been reached was reached.");
104}
105
0106
=== added file 'src/vs-thumb.cpp'
--- src/vs-thumb.cpp 1970-01-01 00:00:00 +0000
+++ src/vs-thumb.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,127 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/gobj_memory.h>
20#include<cstdio>
21#include<memory>
22#include<stdexcept>
23#include<gst/gst.h>
24#include<gst/app/gstappsink.h>
25#include<gdk-pixbuf/gdk-pixbuf.h>
26
27using namespace std;
28
29bool extract(const std::string &ifname, const std::string &ofname) {
30 string caps_string = "video/x-raw,format=RGB,pixel-aspect-ratio=1/1";
31 GstElement *sink;
32 gint64 duration, seek_point;
33 string pipe_cmd = "filesrc location=\"";
34 pipe_cmd += ifname;
35 pipe_cmd += "\" ! decodebin ! videoconvert ! videoscale !";
36 pipe_cmd += "appsink name=sink caps=\"";
37 pipe_cmd += caps_string;
38 pipe_cmd += "\"";
39
40 unique_ptr<GstElement, void(*)(GstElement *t)> pipeline(
41 gst_parse_launch(pipe_cmd.c_str(), nullptr),
42 [](GstElement *t){ gst_object_unref(t);});
43 sink = gst_bin_get_by_name(GST_BIN(pipeline.get()), "sink");
44
45 GstStateChangeReturn ret = gst_element_set_state(pipeline.get(), GST_STATE_PAUSED);
46 switch (ret) {
47 case GST_STATE_CHANGE_FAILURE:
48 throw runtime_error("Fail to start thumbnail pipeline.");
49 case GST_STATE_CHANGE_NO_PREROLL:
50 throw runtime_error("Thumbnail not supported for live sources.");
51 default:
52 break;
53 }
54 // Need to preroll in order to get duration.
55 ret = gst_element_get_state(pipeline.get(), nullptr, nullptr, 3*GST_SECOND);
56 if(ret == GST_STATE_CHANGE_FAILURE) {
57 throw runtime_error("Failed to preroll.");
58 } else if(ret == GST_STATE_CHANGE_ASYNC) {
59 fprintf(stderr, "Problem prerolling, trying to continue anyway.\n");
60 }
61 if(!gst_element_query_duration(pipeline.get(), GST_FORMAT_TIME, &duration)) {
62 fprintf(stderr, "Media backend does not implement query_duration, using fallback time.\n");
63 seek_point = 10*GST_SECOND;
64 } else {
65 seek_point = 2*duration/7;
66 }
67 gst_element_seek_simple(pipeline.get(),
68 GST_FORMAT_TIME,
69 static_cast<GstSeekFlags>(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT),
70 seek_point);
71 GstSample *sample = nullptr;
72 sample = gst_app_sink_pull_preroll(GST_APP_SINK(sink));
73 if(sample == nullptr || !GST_IS_SAMPLE(sample)) {
74 throw runtime_error("Could not create sample. Unsupported or invalid file type?");
75 }
76 GstCaps *caps = gst_sample_get_caps(sample);
77
78 GstBuffer *buf = gst_sample_get_buffer(sample);
79 if (sample) {
80 gint width, height;
81 GstStructure *s = gst_caps_get_structure(caps, 0);
82 gboolean res = gst_structure_get_int(s, "width", &width);
83 res |= gst_structure_get_int (s, "height", &height);
84 if (!res) {
85 throw runtime_error("could not determine snapshot dimension.");
86 }
87 GstMapInfo mi;
88 gst_buffer_map(buf, &mi, GST_MAP_READ);
89 unique_gobj<GdkPixbuf> img(
90 gdk_pixbuf_new_from_data(mi.data, GDK_COLORSPACE_RGB,
91 false, 8, width, height,
92 (((width * 3)+3)&~3),
93 nullptr, nullptr));
94 gst_buffer_unmap(buf, &mi);
95 GError *err = nullptr;
96 if(!gdk_pixbuf_save(img.get(), ofname.c_str(), "jpeg", &err, NULL)) {
97 string msg = err->message;
98 g_error_free(err);
99 throw runtime_error(msg);
100 }
101 } else {
102 throw runtime_error("Pipeline failed.");
103 }
104
105 gst_element_set_state(pipeline.get(), GST_STATE_NULL);
106 return true;
107}
108
109int main(int argc, char **argv) {
110 gst_init(&argc, &argv);
111 if(argc != 3) {
112 printf("%s <source file> <output file>\n", argv[0]);
113 return 1;
114 }
115 string infile(argv[1]);
116 string outfile(argv[2]);
117 bool success;
118 try {
119 success = extract(infile, outfile);
120 } catch(runtime_error &e) {
121 return 2;
122 }
123 if(success) {
124 return 0;
125 }
126 return 1;
127}
0128
=== added directory 'tests'
=== renamed directory 'tests' => 'tests.moved'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,41 @@
1if (NOT DEFINED GTEST_ROOT)
2 set(GTEST_ROOT /usr/src/gtest)
3endif()
4
5set(GTEST_SRC_DIR "${GTEST_ROOT}/src")
6set(GTEST_INCLUDE_DIR ${GTEST_ROOT})
7
8add_library(gtest STATIC
9${GTEST_SRC_DIR}/gtest-all.cc
10)
11set_target_properties(gtest PROPERTIES INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR})
12target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT})
13
14set(TESTDATADIR ${CMAKE_CURRENT_SOURCE_DIR})
15
16configure_file(testsetup.h.in testsetup.h @ONLY)
17include_directories(${CMAKE_CURRENT_BINARY_DIR})
18
19add_executable(basic basic.cpp)
20target_link_libraries(basic thumbnailer gtest)
21add_test(basic basic)
22set_property(TEST basic PROPERTY ENVIRONMENT "XDG_CACHE_HOME=${CMAKE_CURRENT_BINARY_DIR}")
23set_property(TEST basic APPEND PROPERTY ENVIRONMENT "TN_UTILDIR=${CMAKE_BINARY_DIR}/src")
24
25add_executable(mediaartcachetest mediaartcachetest.cpp ../src/mediaartcache.cpp)
26target_link_libraries(mediaartcachetest ${GIO_DEPS_LDFLAGS} gtest)
27add_test(mediaartcache mediaartcachetest)
28set_property(TEST mediaartcache PROPERTY ENVIRONMENT "XDG_CACHE_HOME=${CMAKE_CURRENT_BINARY_DIR}")
29
30add_executable(downloadtest download.cpp ../src/lastfmdownloader.cpp ../src/soupdownloader.cpp)
31target_link_libraries(downloadtest ${XML_DEPS_LDFLAGS} ${SOUP_DEPS_LDFLAGS} gtest)
32add_test(downloadtest downloadtest)
33
34# This is only needed here because GStreamer brings in gobject.
35pkg_check_modules(GOBJ_DEPS REQUIRED gobject-2.0)
36
37include_directories(${GOBJ_DEPS_INCLUDE_DIRS})
38
39add_executable(unique_gobj unique_gobj.cpp)
40target_link_libraries(unique_gobj ${GOBJ_DEPS_LDFLAGS} ${IMG_DEPS_LDFLAGS} gtest)
41add_test(unique_gobj unique_gobj)
042
=== added file 'tests/basic.cpp'
--- tests/basic.cpp 1970-01-01 00:00:00 +0000
+++ tests/basic.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<thumbnailer.h>
20#include<testsetup.h>
21#include<gtest/gtest.h>
22#include<unistd.h>
23#include<gdk-pixbuf/gdk-pixbuf.h>
24
25#define TESTIMAGE TESTDATADIR "/testimage.jpg"
26#define ROTTESTIMAGE TESTDATADIR "/testrotate.jpg"
27#define TESTVIDEO TESTDATADIR "/testvideo.ogg"
28
29using namespace std;
30
31bool file_exists(const string &s) {
32 FILE *f = fopen(s.c_str(), "r");
33 if(f) {
34 fclose(f);
35 return true;
36 }
37 return false;
38}
39
40void copy_file(const string &src, const string &dst) {
41 FILE* f = fopen(src.c_str(), "r");
42 ASSERT_TRUE(f);
43 fseek(f, 0, SEEK_END);
44 size_t size = ftell(f);
45
46 char* buf = new char[size];
47
48 fseek(f, 0, SEEK_SET);
49 ASSERT_EQ(fread(buf, 1, size, f), size);
50 fclose(f);
51
52 f = fopen(dst.c_str(), "w");
53 ASSERT_TRUE(f);
54 ASSERT_EQ(fwrite(buf, 1, size, f), size);
55 fclose(f);
56 delete[] buf;
57}
58
59TEST(Thumbnailer, trivial) {
60 Thumbnailer tn;
61}
62
63static void file_test(Thumbnailer &tn, string &ifile) {
64 int w, h;
65 ASSERT_TRUE(file_exists(ifile));
66 string thumbfile = tn.get_thumbnail(ifile, TN_SIZE_SMALL, TN_LOCAL);
67 unlink(thumbfile.c_str());
68 ASSERT_FALSE(file_exists(thumbfile));
69 string thumbfile2 = tn.get_thumbnail(ifile, TN_SIZE_SMALL, TN_LOCAL);
70 ASSERT_EQ(thumbfile, thumbfile2);
71 ASSERT_TRUE(file_exists(thumbfile));
72 ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
73 ASSERT_LE(w, 128);
74 ASSERT_LE(h, 128);
75}
76
77TEST(Thumbnailer, image) {
78 Thumbnailer tn;
79 string imfile(TESTIMAGE);
80 file_test(tn, imfile);
81}
82
83TEST(Thumbnailer, video) {
84 Thumbnailer tn;
85 string videofile(TESTVIDEO);
86 file_test(tn, videofile);
87}
88
89TEST(Thumbnailer, rotate) {
90 Thumbnailer tn;
91 string imfile(ROTTESTIMAGE);
92 int w, h;
93 ASSERT_TRUE(file_exists(imfile));
94 string thumbfile = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
95 unlink(thumbfile.c_str());
96 ASSERT_FALSE(file_exists(thumbfile));
97 string thumbfile2 = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
98 ASSERT_EQ(thumbfile, thumbfile2);
99 ASSERT_TRUE(file_exists(thumbfile));
100 ASSERT_TRUE(gdk_pixbuf_get_file_info(imfile.c_str(), &w, &h));
101 ASSERT_GT(w, h); // gdk_pixbuf does not reorient images automatically.
102 ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
103 ASSERT_GT(h, w); // Has the orientation been straightened during scaling?
104}
105
106
107TEST(Thumbnailer, video_original) {
108 Thumbnailer tn;
109 int w, h;
110 string videofile(TESTVIDEO);
111 string origsize = tn.get_thumbnail(videofile, TN_SIZE_ORIGINAL);
112 ASSERT_TRUE(file_exists(origsize));
113 ASSERT_TRUE(gdk_pixbuf_get_file_info(origsize.c_str(), &w, &h));
114 ASSERT_EQ(w, 1920);
115 ASSERT_EQ(h, 1080);
116}
117
118
119TEST(Thumbnailer, size) {
120 Thumbnailer tn;
121 int w, h;
122 string imfile(TESTIMAGE);
123 string thumbfile = tn.get_thumbnail(imfile, TN_SIZE_SMALL);
124 string thumbfile2 = tn.get_thumbnail(imfile, TN_SIZE_LARGE);
125 string thumbfile3 = tn.get_thumbnail(imfile, TN_SIZE_XLARGE);
126 ASSERT_FALSE(thumbfile.empty());
127 ASSERT_FALSE(thumbfile2.empty());
128 ASSERT_FALSE(thumbfile3.empty());
129 ASSERT_NE(thumbfile, thumbfile2);
130 ASSERT_NE(thumbfile, thumbfile3);
131 ASSERT_NE(thumbfile2, thumbfile3);
132 ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile.c_str(), &w, &h));
133 ASSERT_EQ(w, 128);
134 ASSERT_LE(h, 128);
135 ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile2.c_str(), &w, &h));
136 ASSERT_EQ(w, 256);
137 ASSERT_LE(h, 256);
138 ASSERT_TRUE(gdk_pixbuf_get_file_info(thumbfile3.c_str(), &w, &h));
139 ASSERT_EQ(w, 512);
140 ASSERT_LE(h, 512);
141}
142
143TEST(Thumbnailer, deletetest) {
144 Thumbnailer tn;
145 string srcimg(TESTIMAGE);
146 string workimage("working_image.jpg");
147 copy_file(srcimg, workimage);
148 ASSERT_TRUE(file_exists(workimage));
149 string thumbfile = tn.get_thumbnail(workimage, TN_SIZE_SMALL);
150 string thumbfile2 = tn.get_thumbnail(workimage, TN_SIZE_LARGE);
151 string thumbfile3 = tn.get_thumbnail(workimage, TN_SIZE_XLARGE);
152 ASSERT_TRUE(file_exists(thumbfile));
153 ASSERT_TRUE(file_exists(thumbfile2));
154 ASSERT_TRUE(file_exists(thumbfile3));
155 unlink(workimage.c_str());
156 string tmp = tn.get_thumbnail(workimage, TN_SIZE_SMALL);
157 ASSERT_TRUE(tmp.empty());
158 ASSERT_FALSE(file_exists(thumbfile));
159 ASSERT_FALSE(file_exists(thumbfile2));
160 ASSERT_FALSE(file_exists(thumbfile3));
161}
162
163TEST(Thumbnailer, no_image_cache) {
164 Thumbnailer tn;
165 string srcimg(TESTIMAGE);
166 string dstimg = tn.get_thumbnail(srcimg, TN_SIZE_ORIGINAL);
167 ASSERT_EQ(srcimg, dstimg);
168}
169
170TEST(Thumbnailer, album_art) {
171 // During test suite run we may not have access to the net.
172 // So just test calling to ensure symbol visibility etc work.
173 Thumbnailer tn;
174 string artist("The Prodigy");
175 string album("Music for the Jilted Generation");
176 tn.get_album_art(artist, album, TN_SIZE_ORIGINAL, TN_LOCAL);
177}
178
179int main(int argc, char **argv) {
180 g_type_init(); // Still needed in precise.
181 ::testing::InitGoogleTest(&argc, argv);
182 return RUN_ALL_TESTS();
183}
0184
=== added file 'tests/download.cpp'
--- tests/download.cpp 1970-01-01 00:00:00 +0000
+++ tests/download.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,110 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<gtest/gtest.h>
20#include<internal/lastfmdownloader.h>
21#include<cstdio>
22#include<unistd.h>
23#include<mutex>
24#include<condition_variable>
25#include<thread>
26
27using namespace std;
28
29const char *testimage = "abc";
30
31class FakeDownloader : public HttpDownloader {
32private:
33 constexpr static const char *imloc = "http://dummy";
34 constexpr static const char *xml = "<album><coverart><large>http://dummy</large></coverart></album>";
35
36public:
37 std::string download(const std::string &url) override {
38 if(url.find("audioscrobbler") != std::string::npos) {
39 return xml;
40 }
41 if(url == imloc) {
42 return testimage;
43 }
44 throw std::runtime_error("Tried to get unknown data from FakeDownloader.");
45 }
46};
47
48TEST(Downloader, canned) {
49 LastFMDownloader lfdl(new FakeDownloader());
50 string artist("Some guy");
51 string album("Some album");
52 string outfile("/tmp/temptestfile");
53 unlink(outfile.c_str());
54 ASSERT_TRUE(lfdl.download(artist, album, outfile));
55 char output[4];
56 FILE *f = fopen(outfile.c_str(), "r");
57 ASSERT_TRUE(f);
58 ASSERT_EQ(fread(output, 1, 3, f), 3);
59 output[3] = '\0';
60 fclose(f);
61 unlink(outfile.c_str());
62 string s1(testimage);
63 string s2(output);
64 ASSERT_EQ(s1, s2);
65}
66
67static std::mutex m;
68static std::condition_variable cv;
69static bool go = false;
70
71static void query_thread(LastFMDownloader *lfdl, int num) {
72 string fname("/tmp/tmpfile");
73 string artist("Some guy");
74 string album("Some album");
75 artist += num;
76 album += num;
77 fname += num;
78 {
79 std::unique_lock<std::mutex> lk(m);
80 cv.wait(lk, []{return go;});
81 }
82 for(int i=0; i<10; i++) {
83 unlink(fname.c_str());
84 ASSERT_TRUE(lfdl->download(artist, album, fname));
85 }
86 unlink(fname.c_str());
87}
88
89TEST(Downloader, threads) {
90 LastFMDownloader lfdl(new FakeDownloader());
91 vector<std::thread> workers;
92 for(int i=0; i<10; i++) {
93 workers.emplace_back(query_thread, &lfdl, i);
94 }
95 std::this_thread::sleep_for(std::chrono::seconds(1));
96 {
97 std::lock_guard<std::mutex> g(m);
98 go = true;
99 }
100 cv.notify_all();
101 for(auto &i : workers) {
102 i.join();
103 }
104}
105
106
107int main(int argc, char **argv) {
108 ::testing::InitGoogleTest(&argc, argv);
109 return RUN_ALL_TESTS();
110}
0111
=== added file 'tests/mediaartcachetest.cpp'
--- tests/mediaartcachetest.cpp 1970-01-01 00:00:00 +0000
+++ tests/mediaartcachetest.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,150 @@
1/*
2 * Copyright (C) 2013-2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<sys/types.h>
20#include<string.h>
21#include<stdio.h>
22#include<dirent.h>
23
24#include<string>
25#include <gtest/gtest.h>
26
27#include "../include/internal/mediaartcache.h"
28
29using namespace std;
30
31namespace mediascanner {
32
33TEST(MediaArtCacheTest, BasicFunctionality) {
34 MediaArtCache mac;
35 mac.clear();
36 string artist = "Some Guy";
37 string album = "Muzak";
38 const int datasize = 3;
39 char data[datasize] = {'a', 'b', 'c'};
40 char indata[datasize];
41 FILE *f;
42
43 ASSERT_FALSE(mac.has_art(artist, album));
44 mac.add_art(artist, album, data, datasize);
45 ASSERT_TRUE(mac.has_art(artist, album));
46 f = fopen(mac.get_art_file(artist, album).c_str(), "r");
47 ASSERT_TRUE(f);
48 ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
49 fclose(f);
50 ASSERT_EQ(memcmp(indata, data, datasize), 0);
51
52 mac.clear();
53 assert(!mac.has_art(artist, album));
54}
55
56TEST(MediaArtCacheTest, Swapped) {
57 string artist1("foo");
58 string album1("bar");
59 string artist2(album1);
60 string album2(artist1);
61 const int datasize = 4;
62 char data1[datasize] = {'a', 'b', 'c', 'd'};
63 char data2[datasize] = {'d', 'c', 'b', 'e'};
64 char indata[datasize];
65 MediaArtCache mac;
66 FILE *f;
67 mac.clear();
68
69 ASSERT_FALSE(mac.has_art(artist1, album1));
70 ASSERT_FALSE(mac.has_art(artist2, album2));
71
72 mac.add_art(artist1, album1, data1, datasize);
73 ASSERT_TRUE(mac.has_art(artist1, album1));
74 ASSERT_FALSE(mac.has_art(artist2, album2));
75
76 mac.clear();
77
78 mac.add_art(artist2, album2, data2, datasize);
79 ASSERT_FALSE(mac.has_art(artist1, album1));
80 ASSERT_TRUE(mac.has_art(artist2, album2));
81
82 mac.add_art(artist1, album1, data1, datasize);
83
84 f = fopen(mac.get_art_file(artist1, album1).c_str(), "r");
85 ASSERT_TRUE(f);
86 ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
87 fclose(f);
88 ASSERT_EQ(memcmp(indata, data1, datasize), 0);
89
90 f = fopen(mac.get_art_file(artist2, album2).c_str(), "r");
91 ASSERT_TRUE(f);
92 ASSERT_EQ(fread(indata, 1, datasize, f), datasize);
93 fclose(f);
94 ASSERT_EQ(memcmp(indata, data2, datasize), 0);
95}
96
97static int count_files(const string &dir) {
98 DIR *d = opendir(dir.c_str());
99 int count = 0;
100 if(!d) {
101 string s = "Something went wrong.";
102 throw s;
103 }
104 struct dirent *entry, *de;
105 entry = (dirent*)malloc(sizeof(dirent) + NAME_MAX);
106 while(readdir_r(d, entry, &de) == 0 && de) {
107 string basename = entry->d_name;
108 if (basename == "." || basename == "..")
109 continue;
110 count++;
111 }
112 closedir(d);
113 free(entry);
114 return count;
115}
116
117TEST(MediaArtCacheTest, Prune) {
118 MediaArtCache mac;
119 mac.clear();
120 const int max_files = MediaArtCache::MAX_SIZE;
121 string cache_dir = mac.get_cache_dir();
122 char arr[] = {'a', 'b', 'c'};
123 ASSERT_EQ(count_files(cache_dir), 0);
124 for(int i=0; i<max_files+5; i++) {
125 string tmpname = cache_dir + "/" + to_string(i) + ".jpg";
126 FILE *f = fopen(tmpname.c_str(), "w");
127 if (!f) {
128 string error("Could not create file ");
129 error += tmpname;
130 throw error;
131 }
132 fwrite(arr, 1, 3, f);
133 fflush(f);
134 fclose(f);
135 }
136 ASSERT_GT(count_files(cache_dir), max_files);
137 mac.prune();
138 int numfiles = count_files(cache_dir);
139 ASSERT_GT(numfiles, 0);
140 ASSERT_LE(numfiles, max_files);
141 mac.prune();
142 ASSERT_EQ(numfiles, count_files(cache_dir));
143}
144
145}
146
147int main(int argc, char *argv[]) {
148 ::testing::InitGoogleTest(&argc, argv);
149 return RUN_ALL_TESTS();
150}
0151
=== added directory 'tests/qml'
=== added file 'tests/qml/tst_image_provider.qml'
--- tests/qml/tst_image_provider.qml 1970-01-01 00:00:00 +0000
+++ tests/qml/tst_image_provider.qml 2015-02-04 08:57:20 +0000
@@ -0,0 +1,62 @@
1import QtQuick 2.0
2import QtTest 1.0
3import Ubuntu.Thumbnailer 0.1
4
5Item {
6 Image {
7 id: image
8 width: 200
9 height: 200
10
11 SignalSpy {
12 id: spy
13 target: image
14 signalName: "statusChanged"
15 }
16 }
17
18 Canvas {
19 id: canvas
20 width: 200
21 height: 200
22 renderStrategy: Canvas.Immediate
23 renderTarget: Canvas.Image
24 }
25
26 TestCase {
27 name: "ThumbnailerProviderTests"
28 when: windowShown
29
30 function test_albumart() {
31 var ctx = loadImage(
32 "image://albumart/artist=Gotye&album=Making%20Mirrors");
33 comparePixel(ctx, 0, 0, 242, 228, 209, 255);
34 }
35
36 function loadImage(uri) {
37 image.source = uri
38 while (image.status == Image.Loading) {
39 spy.wait();
40 }
41 compare(image.status, Image.Ready);
42
43 var ctx = canvas.getContext("2d");
44 ctx.drawImage(image, 0, 0);
45 return ctx;
46 }
47
48 function comparePixel(ctx,x,y,r,g,b,a, d) {
49 var c = ctx.getImageData(x,y,1,1).data;
50 if (d === undefined)
51 d = 0;
52 r = Math.round(r);
53 g = Math.round(g);
54 b = Math.round(b);
55 a = Math.round(a);
56 var notSame = Math.abs(c[0]-r)>d || Math.abs(c[1]-g)>d || Math.abs(c[2]-b)>d || Math.abs(c[3]-a)>d;
57 if (notSame)
58 qtest_fail('Pixel compare fail:\nactual :[' + c[0]+','+c[1]+','+c[2]+','+c[3] + ']\nexpected:['+r+','+g+','+b+','+a+'] +/- '+d, 1);
59
60 }
61 }
62}
063
=== added file 'tests/testimage.jpg'
1Binary files tests/testimage.jpg 1970-01-01 00:00:00 +0000 and tests/testimage.jpg 2015-02-04 08:57:20 +0000 differ64Binary files tests/testimage.jpg 1970-01-01 00:00:00 +0000 and tests/testimage.jpg 2015-02-04 08:57:20 +0000 differ
=== added file 'tests/testrotate.jpg'
2Binary files tests/testrotate.jpg 1970-01-01 00:00:00 +0000 and tests/testrotate.jpg 2015-02-04 08:57:20 +0000 differ65Binary files tests/testrotate.jpg 1970-01-01 00:00:00 +0000 and tests/testrotate.jpg 2015-02-04 08:57:20 +0000 differ
=== added file 'tests/testsetup.h.in'
--- tests/testsetup.h.in 1970-01-01 00:00:00 +0000
+++ tests/testsetup.h.in 2015-02-04 08:57:20 +0000
@@ -0,0 +1,6 @@
1#ifndef TESTSETUP_H
2#define TESTSETUP_H
3
4#define TESTDATADIR "@TESTDATADIR@"
5
6#endif
07
=== added file 'tests/testvideo.ogg'
1Binary files tests/testvideo.ogg 1970-01-01 00:00:00 +0000 and tests/testvideo.ogg 2015-02-04 08:57:20 +0000 differ8Binary files tests/testvideo.ogg 1970-01-01 00:00:00 +0000 and tests/testvideo.ogg 2015-02-04 08:57:20 +0000 differ
=== added file 'tests/unique_gobj.cpp'
--- tests/unique_gobj.cpp 1970-01-01 00:00:00 +0000
+++ tests/unique_gobj.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,172 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/gobj_memory.h>
20#include<gdk-pixbuf/gdk-pixbuf.h>
21#include<gtest/gtest.h>
22
23using namespace std;
24
25TEST(Unique_gobj, trivial) {
26 unique_gobj<GdkPixbuf> basic(gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480));
27 ASSERT_TRUE(bool(basic));
28 ASSERT_TRUE(gdk_pixbuf_get_width(basic.get()) == 640);
29 ASSERT_TRUE(gdk_pixbuf_get_height(basic.get()) == 480);
30}
31
32TEST(Unique_gobj, compare) {
33 GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
34 GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
35 if(pb1 > pb2) {
36 std::swap(pb1, pb2);
37 }
38 ASSERT_TRUE(pb1 < pb2);
39 unique_gobj<GdkPixbuf> u1(pb1);
40 unique_gobj<GdkPixbuf> u2(pb2);
41
42 ASSERT_TRUE(!(u1 == nullptr));
43 ASSERT_TRUE(u1 != nullptr);
44 ASSERT_TRUE(u1 != u2);
45 ASSERT_TRUE(!(u1 == u2));
46 ASSERT_TRUE(u1 < u2);
47 ASSERT_TRUE(!(u2 < u1));
48 ASSERT_TRUE(!(u1 == u2));
49 ASSERT_TRUE(!(u2 == u1));
50 ASSERT_TRUE(u1 <= u2);
51 ASSERT_TRUE(!(u2 <= u1));
52}
53
54// This is its own thing due to need to avoid double release.
55
56TEST(Unique_gobj, equality) {
57 GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
58 unique_gobj<GdkPixbuf> u1(pb);
59 g_object_ref(G_OBJECT(pb));
60 unique_gobj<GdkPixbuf> u2(pb);
61 ASSERT_TRUE(u1 == u2);
62 ASSERT_TRUE(u2 == u1);
63 ASSERT_TRUE(!(u1 != u2));
64 ASSERT_TRUE(!(u2 != u1));
65}
66
67TEST(Unique_gobj, release) {
68 GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
69 unique_gobj<GdkPixbuf> u(pb);
70 ASSERT_TRUE(u != nullptr);
71 ASSERT_TRUE(u.get() != nullptr);
72 ASSERT_TRUE(pb == u.release());
73 ASSERT_TRUE(!u);
74 ASSERT_TRUE(u.get() == nullptr);
75 g_object_unref(pb);
76}
77
78void sub_func(GdkPixbuf *pb) {
79 ASSERT_TRUE(G_OBJECT(pb)->ref_count == 2);
80 unique_gobj<GdkPixbuf> u(pb);
81 ASSERT_TRUE(G_OBJECT(pb)->ref_count == 2);
82 // Now it dies and refcount is reduced.
83}
84
85TEST(Unique_gobj, refcount) {
86 GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
87 ASSERT_TRUE(G_OBJECT(pb)->ref_count == 1);
88 g_object_ref(G_OBJECT(pb));
89 sub_func(pb);
90 ASSERT_TRUE(G_OBJECT(pb)->ref_count == 1);
91 g_object_unref(G_OBJECT(pb));
92}
93
94TEST(Unique_gobj, swap) {
95 GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
96 GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
97 unique_gobj<GdkPixbuf> u1(pb1);
98 unique_gobj<GdkPixbuf> u2(pb2);
99
100 u1.swap(u2);
101 ASSERT_TRUE(u1.get() == pb2);
102 ASSERT_TRUE(u2.get() == pb1);
103
104 std::swap(u1, u2);
105 ASSERT_TRUE(u1.get() == pb1);
106 ASSERT_TRUE(u2.get() == pb2);
107}
108
109TEST(Unique_gobj, floating) {
110 GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
111 bool got_exception = false;
112 g_object_force_floating(G_OBJECT(pb));
113 try {
114 unique_gobj<GdkPixbuf> u(pb);
115 } catch(const invalid_argument &c) {
116 got_exception = true;
117 }
118 g_object_unref(G_OBJECT(pb));
119 ASSERT_TRUE(got_exception);
120}
121
122TEST(Unique_gobj, move) {
123 GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
124 GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
125 g_object_ref(G_OBJECT(pb1));
126 unique_gobj<GdkPixbuf> u1(pb1);
127 unique_gobj<GdkPixbuf> u2(pb2);
128 u1 = std::move(u2);
129 ASSERT_TRUE(u1.get() == pb2);
130 ASSERT_TRUE(!u2);
131 ASSERT_TRUE(G_OBJECT(pb1)->ref_count == 1);
132 g_object_unref(G_OBJECT(pb1));
133}
134
135TEST(Unique_gobj, null) {
136 GdkPixbuf *pb1 = NULL;
137 GdkPixbuf *pb3 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
138 unique_gobj<GdkPixbuf> u1(pb1);
139 unique_gobj<GdkPixbuf> u2(nullptr);
140 unique_gobj<GdkPixbuf> u3(pb3);
141
142 ASSERT_TRUE(!u1);
143 ASSERT_TRUE(!u2);
144 u3 = nullptr;
145 ASSERT_TRUE(!u3);
146}
147
148TEST(Unique_gobj, reset) {
149 GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
150 GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
151 unique_gobj<GdkPixbuf> u(pb1);
152
153 u.reset(pb2);
154 ASSERT_TRUE(u.get() == pb2);
155 u.reset(nullptr);
156 ASSERT_TRUE(!u);
157}
158
159TEST(Unique_gobj, sizeoftest) {
160 ASSERT_TRUE(sizeof(GdkPixbuf*) == sizeof(unique_gobj<GdkPixbuf>));
161}
162
163TEST(Unique_gobj, deleter) {
164 unique_gobj<GdkPixbuf> u1;
165 ASSERT_TRUE(u1.get_deleter() == g_object_unref);
166}
167
168int main(int argc, char **argv) {
169 g_type_init(); // Still needed in precise.
170 ::testing::InitGoogleTest(&argc, argv);
171 return RUN_ALL_TESTS();
172}
0173
=== added directory 'tools'
=== renamed directory 'tools' => 'tools.moved'
=== added file 'tools/CMakeLists.txt'
--- tools/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tools/CMakeLists.txt 2015-02-04 08:57:20 +0000
@@ -0,0 +1,11 @@
1#add_executable(imdump imdump.cpp)
2#target_link_libraries(imdump thumbnailer ${GST_DEPS_LDFLAGS})
3
4add_executable(scaler scaler.cpp ../src/imagescaler.cpp)
5target_link_libraries(scaler ${IMG_DEPS_LDFLAGS})
6
7add_executable(cachetool cachetool.cpp)
8target_link_libraries(cachetool thumbnailer)
9
10add_executable(lastfmtest lastfmtest.cpp ../src/lastfmdownloader.cpp ../src/soupdownloader.cpp)
11target_link_libraries(lastfmtest ${SOUP_DEPS_LDFLAGS} ${XML_DEPS_LDFLAGS})
012
=== added file 'tools/cachetool.cpp'
--- tools/cachetool.cpp 1970-01-01 00:00:00 +0000
+++ tools/cachetool.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,37 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<thumbnailer.h>
20#include<cstdio>
21#include<gst/gst.h>
22#include<stdexcept>
23
24int main(int argc, char **argv) {
25 Thumbnailer t;
26 if(argc != 2) {
27 printf("%s <file name>\n", argv[0]);
28 return 1;
29 }
30 std::string ifilename(argv[1]);
31 std::string ofilename = t.get_thumbnail(ifilename, TN_SIZE_LARGE);
32 if(ofilename.empty())
33 printf("Thumbnail could not be generated.\n");
34 else
35 printf("Thumbnail file is %s.\n", ofilename.c_str());
36 return 0;
37}
038
=== added file 'tools/imdump.cpp'
--- tools/imdump.cpp 1970-01-01 00:00:00 +0000
+++ tools/imdump.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/audioimageextractor.h>
20#include<cstdio>
21#include<gst/gst.h>
22#include<stdexcept>
23
24int main(int argc, char **argv) {
25 gst_init(&argc, &argv);
26 AudioImageExtractor ae;
27 try {
28 ae.extract(argv[1], argv[2]);
29 } catch(std::runtime_error &e) {
30 printf("Failed: %s\n", e.what());
31 return 1;
32 }
33 return 0;
34}
035
=== added file 'tools/lastfmtest.cpp'
--- tools/lastfmtest.cpp 1970-01-01 00:00:00 +0000
+++ tools/lastfmtest.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<string>
20#include<cstdio>
21
22#include<internal/lastfmdownloader.h>
23#include<memory>
24
25using namespace std;
26
27int main(int /*argc*/, char **/*argv*/) {
28 LastFMDownloader dl;
29 dl.download("The Prodigy", "Music for the Jilted Generation", "image.jpg");
30 return 0;
31}
032
=== added file 'tools/scaler.cpp'
--- tools/scaler.cpp 1970-01-01 00:00:00 +0000
+++ tools/scaler.cpp 2015-02-04 08:57:20 +0000
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17 */
18
19#include<internal/imagescaler.h>
20#include<cstdio>
21#include<gst/gst.h>
22#include<stdexcept>
23
24int main(int argc, char **argv) {
25 ImageScaler sc;
26 try {
27 std::string ifilename(argv[1]);
28 std::string ofilename(argv[2]);
29 sc.scale(ifilename, ofilename, TN_SIZE_LARGE, ifilename);
30 } catch(std::runtime_error &e) {
31 printf("Failed: %s\n", e.what());
32 return 1;
33 }
34 return 0;
35}

Subscribers

People subscribed via source and target branches

to all changes: