/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * Copyright (C) 2024 KylinSoft  Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
#ifndef BOOT_H
#define BOOT_H

#include <QObject>

#include <unistd.h>
#include <QListWidget>

#include <kysdk/kysdk-system/libkysysinfo.h>
#include <kysdk/applications/kswitchbutton.h>
#include <kysdk/applications/kpushbutton.h>
#include <kysdk/applications/klabel.h>
using namespace kdk;

#include "comboxwidget.h"
#include "switchwidget.h"
#include "shell/interface.h"

#include "bootlistwidget.h"
#include "loadingwidget.h"

#define THEME_SCHAME         "org.ukui.style"
#define UKCC_SCHAME "org.ukui.control-center"
#define SYSTEMS_SAME "systems-same"

class Boot : public QObject, CommonInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.ukcc.CommonInterface")
    Q_INTERFACES(CommonInterface)

public:
    Boot();
    ~Boot() Q_DECL_OVERRIDE;

    QString plugini18nName() Q_DECL_OVERRIDE;
    int pluginTypes() Q_DECL_OVERRIDE;
    QWidget *pluginUi() Q_DECL_OVERRIDE;
    const QString name() const  Q_DECL_OVERRIDE;
    bool isShowOnHomePage() const Q_DECL_OVERRIDE;
    QIcon icon() const Q_DECL_OVERRIDE;
    bool isEnable() const Q_DECL_OVERRIDE;

private:
    QWidget *m_pPluginWidget = nullptr;
    int m_pluginType;
    QString m_pluginName;
    bool m_firstLoad;

    KSwitchButton *m_pGrubBtn = nullptr;
    QLabel *m_pGrubLabel = nullptr;
    KPushButton *m_pResetPasswdBtn = nullptr;
    ComboxWidget *m_pGrubBootDelayFrame = nullptr;
    QFrame *m_pBootOrderFrame = nullptr;
    KLabel *m_pDefaultBootLabel = nullptr;
    QListWidget *m_pBootListWidget = nullptr;
    QDBusInterface *m_pUkccSystemDbus = nullptr;
    QDBusInterface *m_pUkccSessionDbus = nullptr;
    QList<BootListWidget* > bootlist;
    int m_preBootDelay;
    int m_preBootDefault;
    LoadingWidget *m_pLoadingWidget = nullptr;
    QGSettings *m_pukccGsetting = nullptr;

private:
    void initUI(QWidget *widget);
    void initConnection();
    void gsettingConnection();
    void initGrubVerifyStatus();
    void initBootTime();

    void setGrubPasswd(QString pwd, bool isOpen);
    void initBootList();
    void initDefaultBoot();
    bool authoriyGrub();
    void showLoadingWidget(QString text);

private Q_SLOTS:
    void bootSlot(bool checked);
    void resetPasswdSlot();
    void changeBootDelay(int index);
    void setDefaultBoot(int order);
public slots:
    void taskFinished(int type, bool reply);
};
#endif // BOOT_H
