2
* Copyright (C) 2015 Canonical Ltd
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.
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.
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/>.
16
* Authored by: Xavi Garcia <xavi.garcia.mena@canonical.com>
19
#include "inactivityhandler.h"
21
#include <QCoreApplication>
27
const int MAX_INACTIVITY_TIME = 30000; // max inactivity time before exiting the app, in milliseconds
29
using namespace unity::thumbnailer::service;
31
int get_env_inactivity_time(int default_value)
33
char const* c_idle_time = getenv("THUMBNAILER_MAX_IDLE");
36
std::string str_idle_time(c_idle_time);
39
int env_value = std::stoi(str_idle_time);
42
catch (std::exception& e)
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());
53
InactivityHandler::InactivityHandler(DBusInterface& iface)
56
timer_.setInterval(get_env_inactivity_time(MAX_INACTIVITY_TIME));
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);