~ci-train-bot/thumbnailer/thumbnailer-ubuntu-yakkety-landing-072

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Michi Henning
  • Date: 2015-09-15 11:04:11 UTC
  • mfrom: (125.1.2 landing150915)
  • Revision ID: ci-train-bot@canonical.com-20150915110411-233xw0fljaq7p2o0
Landing changes on devel to trunk.
Approved by: James Henstridge

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "thumbnailgenerator.h"
20
20
 
21
 
#include "artgeneratorcommon.h"
22
 
#include <service/dbus_names.h>
 
21
#include <QDebug>
 
22
#include <QMimeDatabase>
 
23
#include <QUrl>
 
24
 
 
25
#include <settings.h>
23
26
#include "thumbnailerimageresponse.h"
24
27
 
25
28
namespace
55
58
namespace qml
56
59
{
57
60
 
58
 
ThumbnailGenerator::ThumbnailGenerator()
 
61
ThumbnailGenerator::ThumbnailGenerator(std::shared_ptr<unity::thumbnailer::qt::Thumbnailer> thumbnailer,
 
62
                                       std::shared_ptr<unity::thumbnailer::RateLimiter> backlog_limiter)
59
63
    : QQuickAsyncImageProvider()
 
64
    , thumbnailer(thumbnailer)
 
65
    , backlog_limiter(backlog_limiter)
60
66
{
61
67
}
62
68
 
68
74
    {
69
75
        qWarning().nospace() << "ThumbnailGenerator::requestImageResponse(): deprecated invalid QSize: "
70
76
                             << requestedSize << ". This feature will be removed soon. Pass the desired size instead.";
71
 
        size.setWidth(128);
72
 
        size.setHeight(128);
 
77
        // Size will be adjusted by the service to 128x128.
73
78
    }
74
79
 
75
80
    /* Allow appending a query string (e.g. ?something=timestamp)
83
88
     * is the only way around the issue for now. */
84
89
    QString src_path = QUrl(id).path();
85
90
 
86
 
    if (!connection)
 
91
    // Schedule dbus call
 
92
    auto job = [this, src_path, size]
87
93
    {
88
 
        // Create connection here and not on the constructor, so it belongs to the proper thread.
89
 
        connection.reset(new QDBusConnection(
90
 
            QDBusConnection::connectToBus(QDBusConnection::SessionBus, "thumbnail_generator_dbus_connection")));
91
 
        iface.reset(new ThumbnailerInterface(service::BUS_NAME, service::THUMBNAILER_BUS_PATH, *connection));
92
 
    }
93
 
 
94
 
    auto reply = iface->GetThumbnail(src_path, size);
95
 
    std::unique_ptr<QDBusPendingCallWatcher> watcher(
96
 
        new QDBusPendingCallWatcher(reply));
97
 
    return new ThumbnailerImageResponse(size, default_image_based_on_mime(id), std::move(watcher));
 
94
        return thumbnailer->getThumbnail(src_path, size);
 
95
    };
 
96
    return new ThumbnailerImageResponse(size, default_image_based_on_mime(id), backlog_limiter.get(), job);
98
97
}
99
98
 
100
99
}  // namespace qml