/* -*- 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 MAINWINDOW_H
#define MAINWINDOW_H

#include <QFrame>
#include <QPushButton>
#include <QLabel>
#include <QToolButton>
#include <QMenu>
#include <QGSettings>
#include <QSettings>
#include <kysdk/applications/ukuiwindowhelper/ukuiwindowhelper.h>

#include "kleftwidget.h"
#include "krightwidget.h"
#include "process/processwidget.h"
#include "filesystem/filesystemwidget.h"
#include "service/servicewidget.h"
#include "windowmanager/windowmanager.h"
#include "sysresource/cpudetailswidget.h"
#include "sysresource/memdetailswidget.h"
#include "sysresource/netdetailswidget.h"
#include "sysresource/diskdetailswidget.h"
#include "sysresource/basedetailviewwidget.h"

#include "trayicon.h"

class MainWindow : public QFrame
{
    Q_OBJECT
public:
    enum {
        FUNCTION_MODULE_PROCESS,
        FUNCTION_MODULE_SERVICE,
        FUNCTION_MODULE_FILESYSTEM,
        FUNCTION_MODULE_COUNT
    };
    explicit MainWindow(QWidget *parent = nullptr);
    virtual ~MainWindow();
    void windowShow();

public slots:
    void handleMessage(const QString &);
    void onSwitchPage(int nIndex);
    void onMinimizeWindow();
    void onMaximizeWindow();
    void switchPage(int nIndex);
    void tabletmodeDbusSlot(bool isTabletmode);
    void saveSettings();

signals:

protected:
    void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
    void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
    void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; //键盘松开事件
    void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
    bool eventFilter(QObject *watched, QEvent *event);

private:
    void initUI();
    void initConnections();
    void initOpacityGSettings();

    void initLeftSideBar();
    void initRightPanel();
    void getOsRelease();
    bool loadSettings();

    bool dblOnEdge(QMouseEvent *event);
    void moveCenter();

private:
    KLeftWidget *m_leftWidget = nullptr;
    KRightWidget *m_rightWidget = nullptr;
    QPoint dragPosition;
    bool mousePressed = false;
    // layout
    QHBoxLayout *m_mainLayout = nullptr;
    // QGSettings
    QGSettings *m_gsTransOpacity = nullptr;
    qreal m_curTransOpacity = 1;
    QGSettings *m_ifSettings = nullptr;
    bool m_isSurportService = false;
    int m_idxService = -1;

    QSettings *m_proSettings = nullptr;
    QSize m_lastWndSize;
    bool m_bIsWndMax;
    QString m_osVersion = "";

    ProcessWidget *m_procWidget = nullptr;
    FileSystemWidget *m_fsWidget = nullptr;
    ServiceWidget *m_svcWidget = nullptr;
    CpuDetailsWidget *mCpuDetailsWidget = nullptr;
    MemDetailsWidget *mMemDetailsWidget = nullptr;
    NetDetailsWidget *mNetDetailsWidget = nullptr;
    DiskDetailsWidget *m_pDiskDetailsWidget = nullptr;

    QList<WindowId> m_listWinIds;

    int mFirstKey = 0;

    QGSettings *m_pSystemMonitorGSetting = nullptr;
    bool isShutDown = false;
    UkuiWindowHelper *m_pUkuiWindowHelper = nullptr;
};

#endif // MAINWINDOW_H
