Commit 44a75483 authored by Rafał Malinowski's avatar Rafał Malinowski

idle: modernize code a bit

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <[email protected]>
parent 7731bd6d
......@@ -28,6 +28,7 @@
#include "gui/widgets/configuration/configuration-widget.h"
#include "gui/windows/kadu-window.h"
#include "misc/kadu-paths.h"
#include "plugin/activation/plugin-activation-service.h"
#include "plugins/idle/idle-plugin.h"
#include "plugins/idle/idle.h"
......@@ -35,7 +36,9 @@
#include "auto_hide.h"
AutoHide::AutoHide(QObject *parent) :
ConfigurationUiHandler(parent), IdleTime(0)
ConfigurationUiHandler{parent},
MyIdle{nullptr},
IdleTime{0}
{
connect(&Timer, SIGNAL(timeout()), this, SLOT(timerTimeoutSlot()));
......@@ -50,6 +53,9 @@ bool AutoHide::init(bool firstLoad)
{
Q_UNUSED(firstLoad)
auto idleRootComponent = Core::instance()->pluginActivationService()->pluginRootComponent("idle");
MyIdle = dynamic_cast<IdlePlugin *>(idleRootComponent)->idle();
MainConfigurationWindow::registerUiFile(KaduPaths::instance()->dataPath() + QLatin1String("plugins/configuration/auto_hide.ui"));
MainConfigurationWindow::registerUiHandler(this);
......@@ -68,7 +74,7 @@ void AutoHide::timerTimeoutSlot()
{
if (Enabled)
{
if (IdlePlugin::idle()->secondsIdle() >= IdleTime)
if (MyIdle->secondsIdle() >= IdleTime)
{
KaduWindow *window = Core::instance()->kaduWindow();
if (window->docked())
......
......@@ -40,6 +40,7 @@ class AutoHide : public ConfigurationUiHandler, ConfigurationAwareObject, public
Q_PLUGIN_METADATA(IID "im.kadu.PluginRootComponent")
QTimer Timer;
Idle *MyIdle;
int IdleTime;
bool Enabled;
......
......@@ -44,6 +44,7 @@
#include "gui/windows/main-configuration-window.h"
#include "misc/kadu-paths.h"
#include "parser/parser.h"
#include "plugin/activation/plugin-activation-service.h"
#include "status/status-changer-manager.h"
#include "debug.h"
......@@ -61,6 +62,7 @@ AutoAway::AutoAway() :
autoAwayStatusChanger{},
timer{},
StatusChanged{false},
idle{},
idleTime{},
refreshStatusTime{},
refreshStatusInterval{},
......@@ -91,6 +93,9 @@ bool AutoAway::init(bool firstLoad)
{
Q_UNUSED(firstLoad)
auto idleRootComponent = Core::instance()->pluginActivationService()->pluginRootComponent("idle");
idle = dynamic_cast<IdlePlugin *>(idleRootComponent)->idle();
MainConfigurationWindow::registerUiFile(KaduPaths::instance()->dataPath() + QLatin1String("plugins/configuration/autoaway.ui"));
MainConfigurationWindow::registerUiHandler(this);
......@@ -105,7 +110,7 @@ void AutoAway::done()
AutoAwayStatusChanger::ChangeStatusTo AutoAway::changeStatusTo()
{
idleTime = IdlePlugin::idle()->secondsIdle();
idleTime = idle->secondsIdle();
if (idleTime >= autoDisconnectTime && autoDisconnectEnabled)
return AutoAwayStatusChanger::ChangeStatusToOffline;
......@@ -137,7 +142,7 @@ void AutoAway::checkIdleTime()
{
kdebugf();
idleTime = IdlePlugin::idle()->secondsIdle();
idleTime = idle->secondsIdle();
if (refreshStatusInterval > 0 && idleTime >= refreshStatusTime)
{
......
......@@ -43,6 +43,8 @@ class QLineEdit;
class QSpinBox;
class QCheckBox;
class Idle;
/**
* @defgroup autoaway Autoaway
* @{
......@@ -71,6 +73,7 @@ class AutoAway : public ConfigurationUiHandler, ConfigurationAwareObject, public
bool StatusChanged;
Idle *idle;
unsigned int idleTime;
unsigned int refreshStatusTime;
unsigned int refreshStatusInterval;
......
......@@ -24,8 +24,6 @@
#include "idle-plugin.h"
Idle * IdlePlugin::IdleInstance = 0;
IdlePlugin::~IdlePlugin()
{
}
......@@ -34,14 +32,18 @@ bool IdlePlugin::init(bool firstLoad)
{
Q_UNUSED(firstLoad)
IdleInstance = new Idle(this);
m_idle = make_qobject<Idle>(this);
return true;
}
void IdlePlugin::done()
{
delete IdleInstance;
IdleInstance = 0;
m_idle.reset();
}
Idle * IdlePlugin::idle() const
{
return m_idle.get();
}
Q_EXPORT_PLUGIN2(idle, IdlePlugin)
......
......@@ -26,6 +26,7 @@
#ifndef IDLE_PLUGIN_H
#define IDLE_PLUGIN_H
#include "misc/memory.h"
#include "plugin/plugin-root-component.h"
#include "idle_exports.h"
......@@ -38,15 +39,16 @@ class IDLEAPI IdlePlugin : public QObject, public PluginRootComponent
Q_INTERFACES(PluginRootComponent)
Q_PLUGIN_METADATA(IID "im.kadu.PluginRootComponent")
static Idle *IdleInstance;
public:
virtual ~IdlePlugin();
virtual bool init(bool firstLoad);
virtual void done();
static Idle * idle() { return IdleInstance; }
Idle * idle() const;
private:
qobject_ptr<Idle> m_idle;
};
......
......@@ -33,7 +33,7 @@ class IDLEAPI Idle : public QObject
Q_OBJECT
public:
explicit Idle(QObject *parent = 0);
explicit Idle(QObject *parent = nullptr);
virtual ~Idle();
long secondsIdle();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment