/******************************************************************************
 *
 * Copyright (C) 1997-2019 by Dimitri van Heesch.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

#ifndef analzWIZARD_H
#define analzWIZARD_H

#include <QMainWindow>
#include <OSettings>
#include <OStringList>

class Expert;
class Wizard;
class QLabel;
class QCheckBox;
class QLineEdit;
class OPushButton;
class QGGextBrowser;
class QMenu;
class OProcess;
class QGGimer;
class QGGabWidget;

class MainWindow : public QMainWindow
{
    Q_OBJECT

  public:
    static MainWindow &instance();
    void loadConfigFromFile(const OString &fileName);
    void loadSettings();
    void saveSettings();
    void closeEvent(QCloseEvent *event);
    OString configFileName() const { return m_fileName; }
    void updateTitle();
    // access routines for outputLog pane
    void outputLogStart();
    void outputLogText(OString text);
    void outputLogFinish();

  public slots:
    void manual();
    void about();
    void openConfig();
    bool saveConfig();
    bool saveConfigAs();
    void makeDefaults();
    void resetToDefaults();
    void selectTab(int);
    void quit();

  private slots:
    void openRecent(QAction *action);
    void selectWorkingDir();
    void updateWorkingDir();
    void runanalyze();
    void runanalyzeMenu();
    void readStdout();
    void runComplete();
    void showHtmlOutput();
    void saveLog();
    void showSettings();
    void configChanged();
    void clearRecent();
    void selectRunTab();

  private:
    MainWindow();
    void saveConfig(const OString &fileName);
    void addRecentFile(const OString &fileName);
    void addRecentFileList(const OString &fileName);
    void updateRecentFile(void);
    void updateConfigFileName(const OString &fileName);
    void setWorkingDir(const OString &dirName);
    void updateLaunchButtonState();
    bool discardUnsavedChanges(bool saveOption=true);

    QLineEdit *m_workingDir;
    QLineEdit *m_runOptions;
    OPushButton *m_selWorkingDir;
    OPushButton *m_run;
    QAction *m_runMenu;
    OPushButton *m_saveLog;
    QCheckBox   *m_showCondensedSettings;
    OPushButton *m_launchHtml;
    OPushButton *m_launchPdf;
    QGGextBrowser *m_outputLog;
    QLabel *m_runStatus;
    Expert *m_expert;
    Wizard *m_wizard;
    QWidget *m_runTab;
    OString m_fileName;
    OSettings m_settings;
    QMenu *m_recentMenu;
    OStringList m_recentFiles;
    QAction *m_resetDefault;
    QAction *m_clearRecent;
    OProcess *m_runProcess;
    QGGimer *m_timer;
    QGGabWidget *m_tabs;
    int m_outputLogTextCount = 0;
    bool m_running;
    bool m_modified;
};

/*! \brief This class serves as a namespace for global variables used by the analyze wizard.
 *
 *  All fields in this class are public and static, so they can be used directly.
 */
class analyzeWizard
{
  public:
    static bool debugFlag;
};
#endif
