~jamesh/thumbnailer/qml-module-package-name

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Thumbnailer.0.1/thumbnailgenerator.cpp

  • Committer: James Henstridge
  • Date: 2015-09-14 07:03:06 UTC
  • mto: This revision was merged to the branch mainline in revision 271.
  • Revision ID: james@jamesh.id.au-20150914070306-dpn05n210rwpfmir
Use a single instances of Thumbnailer and RateLimiter shared between the 
three ImageProvider classes.

Also use the default D-Bus connection rather than creating three new 
ones.  We are making our D-Bus calls from the main thread and performing 
them asynchronously, so should be safe to use a shared connection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "thumbnailgenerator.h"
20
20
 
21
 
#include <QDBusConnection>
22
21
#include <QDebug>
23
22
#include <QMimeDatabase>
24
23
#include <QUrl>
59
58
namespace qml
60
59
{
61
60
 
62
 
ThumbnailGenerator::ThumbnailGenerator()
 
61
ThumbnailGenerator::ThumbnailGenerator(std::shared_ptr<unity::thumbnailer::qt::Thumbnailer> thumbnailer,
 
62
                                       std::shared_ptr<unity::thumbnailer::RateLimiter> backlog_limiter)
63
63
    : QQuickAsyncImageProvider()
64
 
    , backlog_limiter(Settings().max_backlog())
 
64
    , thumbnailer(thumbnailer)
 
65
    , backlog_limiter(backlog_limiter)
65
66
{
66
67
}
67
68
 
87
88
     * is the only way around the issue for now. */
88
89
    QString src_path = QUrl(id).path();
89
90
 
90
 
    if (!thumbnailer)
91
 
    {
92
 
        // Create connection here and not on the constructor, so it belongs to the proper thread.
93
 
        thumbnailer.reset(
94
 
            new unity::thumbnailer::qt::Thumbnailer(
95
 
                QDBusConnection::connectToBus(
96
 
                    QDBusConnection::SessionBus, "thumbnail_generator_dbus_connection")));
97
 
    }
98
 
 
99
91
    // Schedule dbus call
100
92
    auto job = [this, src_path, size]
101
93
    {
102
94
        return thumbnailer->getThumbnail(src_path, size);
103
95
    };
104
 
    return new ThumbnailerImageResponse(size, default_image_based_on_mime(id), &backlog_limiter, job);
 
96
    return new ThumbnailerImageResponse(size, default_image_based_on_mime(id), backlog_limiter.get(), job);
105
97
}
106
98
 
107
99
}  // namespace qml