#include <QtDBus>
#include "tray_win.h"
#include "job_manager_window.h"

TrayWin::TrayWin(QWidget *parent) : QWidget(parent)
{
    createActions();
    createTrayIcon();

    m_trayIcon->show();
}
void TrayWin::showNotify(QStringList notify)
{
    QIcon icon(QIcon::fromTheme("kylin-printer"));
    m_trayIcon->showMessage(notify.at(0), notify.at(1), icon,
                          10);
}
void TrayWin::createTrayIcon()
{
    m_trayIconMenu = new QMenu(this);
    m_trayIconMenu->addAction(m_minimizeAction);
    m_trayIconMenu->addAction(m_maximizeAction);
    m_trayIconMenu->addSeparator();
    m_trayIconMenu->addAction(m_quitAction);

    m_trayIcon = new QSystemTrayIcon(this);
    m_trayIcon->setContextMenu(m_trayIconMenu);

    m_trayIcon->setIcon(QIcon::fromTheme("kylin-printer"));
}
void TrayWin::createActions()
{
    m_minimizeAction = new QAction(tr("Minimize"), this);
    connect(m_minimizeAction, &QAction::triggered, this,[=](){
        JobManagerWindow *w = JobManagerWindow::getInstance();
        w->hideThis();
    });

    m_maximizeAction = new QAction(tr("Maximize"), this);
    connect(m_maximizeAction, &QAction::triggered, this,[=](){
        JobManagerWindow *w = JobManagerWindow::getInstance();
        w->showThis();
    });

    m_quitAction = new QAction(tr("Quit"), this);
    connect(m_quitAction, &QAction::triggered, this,[=](){
        JobManagerWindow *w = JobManagerWindow::getInstance();
        if (w->isActiveWindow())
        {
            w->close();
        }
        else
        {
            return;
        }
    });
}
