#include <QCoreApplication>
#include <QtDBus/QDBusConnection>
#include <QtDebug>

#include "common.h"
#include "screen.h"
#include "audio.h"
#include "network.h"
#include "bluetooth.h"
#include "power.h"
#include "touchpad.h"
#include "keyboard.h"
#include "panel_config.h"
#include "mouse.h"

#include "theme.h"
#include "background.h"
#include "font.h"
#include "effect.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    // Todo
    // 启动后台服务，加载Dbus接口,注册DBus对象
    QDBusConnection sessionBus = QDBusConnection::sessionBus();
    if (sessionBus.registerService(DBUS_NAME)) {
        sessionBus.registerObject(DEVICES_SCREEN_PATH, new Screen(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );
        sessionBus.registerObject(DEVICES_AUDIO_PATH, new Audio(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );
        BLUETOOTHDBUS::instance();
        sessionBus.registerObject(DEVICES_BLUETOOTH_PATH, BLUETOOTHDBUS::getInstance(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );
        sessionBus.registerObject(DEVICES_WIFI_PATH, new Network(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );
        sessionBus.registerObject(DEVICES_POWER_PATH, new UkuiPowerInterface(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );
        
        sessionBus.registerObject(DEVICES_TOUCHPAD_PATH, new TouchpadManager(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );

        sessionBus.registerObject(DEVICES_KEYBOARD_PATH, new Keyboard(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );

        sessionBus.registerObject(DEVICES_MOUSE_PATH, new Mouse(),
                                 QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
                                 );

        QDBusConnection::RegisterOptions uiOptions = QDBusConnection::ExportAllSlots |
                QDBusConnection::ExportAllSignals | QDBusConnection::ExportAllProperties;
        sessionBus.registerObject(UI_THEME_PATH, new Theme(&a), uiOptions);
        sessionBus.registerObject(UI_WALLPAPER_PATH, new Background(&a), uiOptions);
        sessionBus.registerObject(UI_FONT_PATH, new Font(&a), uiOptions);
        sessionBus.registerObject(UI_EFFECTS_PATH, new Effect(&a), uiOptions);
        sessionBus.registerObject(UI_Panel_PATH, new ConfigUkPanel(&a), uiOptions);
    }

    return a.exec();
}
