/**
 * @brief TrayIcon::TrayIcon
 * @param MainWindow* _parent
 * @param Controller* _ctrl
 */
TrayIcon::TrayIcon(MainWindow* _parent, Controller* _ctrl) :
    QSystemTrayIcon(_parent),
    m_ctrl(_ctrl),
    m_parent(_parent)
{
    connect(m_parent, SIGNAL(showHidden(bool)),     this, SLOT(onWindowShown(bool)));
    connect(m_ctrl,   SIGNAL(startedPaused(bool)),  this, SLOT(onStartPause(bool)));
    connect(m_ctrl,   SIGNAL(lockToggled(bool)),    this, SLOT(setLocked(bool)));
    connect(m_parent, &MainWindow::settingsChanged, this, [this]{ setLockEnabled(m_ctrl->lockEnabled() == UM::LOCK_ALL); });
    connect(m_ctrl,   SIGNAL(generationFinished()), this, SLOT(onListChanged()));
    connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));

    QMenu* menu = new QMenu();
    m_actionPause =          menu->addAction(QIcon(":/images/icons/play_pause.png"), tr("Pause"));
    QAction* actionRefresh = menu->addAction(QIcon(":/images/icons/refresh.png"),    tr("Refresh"));
    m_actionHide =           menu->addAction(QIcon(":/images/icons/hide.png"),       tr("Hide"));
    m_actionLock =           menu->addAction(QIcon(":/images/icons/lock.png"),       tr("Lock"));
    m_actionUnlock =         menu->addAction(QIcon(":/images/icons/lock.png"),       tr("Unlock"));
    m_quickMenu =            menu->addMenu(QIcon(":/images/icons/quick.png"),        tr("Quick switch"));
                             menu->addSeparator();
    QAction* actionQuit =    menu->addAction(QIcon(":/images/icons/quit.png"),       tr("Quit"));

    connect(actionQuit,    SIGNAL(triggered()), m_parent, SLOT(quit()));
    connect(m_actionHide,  SIGNAL(triggered()), m_parent, SLOT(toggleWindow()));
    connect(m_actionPause, SIGNAL(triggered()), m_ctrl,   SLOT(startPause()));
    connect(actionRefresh, SIGNAL(triggered()), m_ctrl,   SLOT(update()));
    connect(m_actionLock,  SIGNAL(triggered()), m_ctrl,   SLOT(lock()));
    connect(m_actionUnlock,SIGNAL(triggered()), m_parent, SLOT(openUnlockDialog()));

    setToolTip(APP_NAME);
    setContextMenu(menu);

    onListChanged();
    setLockEnabled(m_ctrl->lockEnabled() == UM::LOCK_ALL);
    updateIcon();
}
void ConserveWidget::initConnect() {
    connect(gamma_slider, SIGNAL(valueChanged(double)), this, SLOT(setScreenGammaValue(double)));
    connect(brightness_slider, SIGNAL(valueChanged(int)), this, SLOT(setBrightnessValue(int)));
//    connect(idle_delay_combo, SIGNAL(currentIndexChanged(QString)),  this, SLOT(setIdleDelay(QString)));
    connect(idle_delay_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setIdleDelay(int)));
    connect(lock_enabled_switch, SIGNAL(clicked()),  this, SLOT(setLockEnabled()));
//    connect(lock_delay_combo, SIGNAL(currentIndexChanged(QString)),  this, SLOT(setLockDelay(QString)));
    connect(lock_delay_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setLockDelay(int)));
    connect(suspend_low_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(shutdown_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(suspend_lid_battery_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(nothing_battery_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(suspend_lid_ac_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(nothing_ac_radio, SIGNAL(clicked()), this, SLOT(setRadioButtonRowStatus()));
    connect(sleep_battery_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setSleepTimeoutBattery(int)));
    connect(sleep_ac_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setSleepTimeoutAC(int)));
    connect(sleep_battery_display_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setSleepTimeoutDisplayBattery(int)));
    connect(sleep_ac_display_combo, SIGNAL(currentIndexChanged(int)),  this, SLOT(setSleepTimeoutDisplayAC(int)));
}