~ubuntu-branches/ubuntu/wily/thumbnailer/wily-proposed

« back to all changes in this revision

Viewing changes to src/service/inactivityhandler.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot, James Henstridge
  • Date: 2015-05-27 05:36:31 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20150527053631-uxwxlyuhuapa0tiz
Tags: 2.0+15.10.20150527-0ubuntu1
[ James Henstridge ]
* New upstream version with many changes:
  - Switch to new cache implementation based on leveldb.
  - Move local file thumbnailing to the central D-Bus daemon,
    allowing for the cache to be shared between apps and its size
    kept under control.
  - The libthumbnailer library has been removed, since all clients
    of the cache rely on the D-Bus interface now.
  - The QML plugin now uses the QQuickAsyncImageProvider interface,
    enabling multiple thumbnails to be loaded simultaneously.
  - Improved test coverage.
* Remove the libthumbnailer0 and libthumbnailer-dev binary packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 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: Xavi Garcia <xavi.garcia.mena@canonical.com>
 
17
 */
 
18
 
 
19
#include "inactivityhandler.h"
 
20
 
 
21
#include <QCoreApplication>
 
22
#include <QDebug>
 
23
 
 
24
#include <sstream>
 
25
#include <string>
 
26
 
 
27
const int MAX_INACTIVITY_TIME = 30000;  // max inactivity time before exiting the app, in milliseconds
 
28
 
 
29
using namespace unity::thumbnailer::service;
 
30
 
 
31
int get_env_inactivity_time(int default_value)
 
32
{
 
33
    char const* c_idle_time = getenv("THUMBNAILER_MAX_IDLE");
 
34
    if (c_idle_time)
 
35
    {
 
36
        std::string str_idle_time(c_idle_time);
 
37
        try
 
38
        {
 
39
            int env_value = std::stoi(str_idle_time);
 
40
            return env_value;
 
41
        }
 
42
        catch (std::exception& e)
 
43
        {
 
44
            std::ostringstream s;
 
45
            s << "InactivityHandler::InactivityHandler(): Value for env variable THUMBNAILER_MAX_IDLE \""
 
46
              << str_idle_time << "\" is not correct. It must be an integer.";
 
47
            throw std::invalid_argument(s.str());
 
48
        }
 
49
    }
 
50
    return default_value;
 
51
}
 
52
 
 
53
InactivityHandler::InactivityHandler(DBusInterface& iface)
 
54
    : QObject(&iface)
 
55
{
 
56
    timer_.setInterval(get_env_inactivity_time(MAX_INACTIVITY_TIME));
 
57
 
 
58
    // connect dbus interface inactivity signals to the QTimer start and stop
 
59
    connect(&iface, &DBusInterface::endInactivity, &timer_, &QTimer::stop);
 
60
    connect(&iface, &DBusInterface::startInactivity, &timer_, static_cast<void (QTimer::*)()>(&QTimer::start));
 
61
    connect(&timer_, &QTimer::timeout, QCoreApplication::instance(), &QCoreApplication::quit);
 
62
}