#include "dbusservice.h"

#include "multitaskviewmanager.h"

namespace MultitaskView {

DBusService::DBusService(MultitaskViewManager *viewManager, QObject *parent)
    : QObject(parent),
      viewManager_(viewManager),
      connection_(QDBusConnection::sessionBus())
{
    startService();
}

DBusService::~DBusService()
{
    stopService();
}

bool DBusService::startService()
{
    return connection_.registerService(serviceName_)
            && connection_.registerObject(servicePath_, this, QDBusConnection::ExportAllSlots);
}

bool DBusService::stopService()
{
    connection_.unregisterObject(servicePath_);
    return connection_.unregisterService(serviceName_);
}

void DBusService::show()
{
    viewManager_->open();
}

void DBusService::hide()
{
    viewManager_->close();
}

} // namespace MultitaskView
