/**
    File        : Main.h
    Description : Initializes the app
    Author      : Raymond Marsh
    Created     : 08/01/2009
    Copyright 2009, 2010 Raymond Marsh

    This program is distributed under the terms of the GNU General Public License.
    To view a copy of the license see the file 'copying.txt'

    This file is part of the Ace Personal Finance Assistant Suite.

    Ace Personal Finance Assistant 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 3 of the License, or (at your option) any later version.

    Ace Personal Finance Assistant 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 Ace Personal Finance Assistant.
    If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED

#include <wx/app.h>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/toolbar.h>
#include <wx/menu.h>
#include <wx/sizer.h>
#include <wx/aboutdlg.h>
#include <wx/dir.h>
#include <wx/dynlib.h>
#include <wx/utils.h>
#include <wx/bitmap.h>
#include <wx/iconbndl.h>
#include <vector>
#include <algorithm>
#include "Licene.h"
#include "version.h"
#include "Data.h"
#include "IPlugin.h"
#include "Settings.h"
#include "SettingsDlg.h"
#include "Dialogs.h"
#include "SplashScreen.h"
#include "AccountManager.h"
#include "ReoccuringTransactions.h"
#include "LanguageDlg.h"


typedef std::vector<SPluginInfo>  PLUGIN_LIST;
typedef PLUGIN_LIST::iterator     PLUGIN_LIST_ITER;

bool SortPluginsByWeight(const SPluginInfo& A, const SPluginInfo& B);

class CMainFrame;

class CApp : public wxApp
{
    public:
    virtual bool OnInit();
    virtual int OnExit();

    private:
    // id's

    // event handlers

    // private data
    CMainFrame*     m_pMainFrame;
};

class CMainFrame : public wxFrame, public IPluginHost
{
    public:
    CMainFrame(const wxString& title);
    ~CMainFrame();
    void FinishStartup();
    long GetNewId()                   { return wxNewId(); }
    wxEvtHandler* GetEvtHandler()     { return GetEventHandler(); }
    wxMenuBar* GetMainMenuBar()       { return GetMenuBar(); }
    wxToolBar* GetMainToolBar()       { return GetToolBar(); }
    ace::CData* GetGlobalDataObject() { return m_pData; }
    void GetViewer(const wxString ViewerName, CAccountTypePluginBase** ppViewer);
    bool GetAvailableAccountTypes(wxArrayString& AccountTypes);

    private:
    int EnumPlugins();
    void LoadPlugin(const wxString &Filename);
    void UnloadAllPlugins();

    // id's
    enum
    {
        idTimer = 100,
        idFileQuit,             /**< Menu Exit */
        idAccountNew,           /**< Menu New Account */
        idAccountEdit,          /**< Menu Edit Account */
        idAccountDelete,        /**< Menu Delete Account */
        idBillsView,            /**< Menu View Bills */
        idPluginManager,        /**< Menu Plugin Manager */
        idSettingsEnviroment,   /**< Menu Enviroment Settings */
        idSettingsLanguage,     /**< Menu Language Settings */
        idSettingsRestore,      /**< Menu Restore Defaults */
        idHelpAbout,            /**< Menu About */
        idHelpUsing,            /**< Menu Help */
        idHelpWidgets,          /**< Menu Anout wxWidgets */
    };

    // event handlers
    void OnTimerEnd(wxTimerEvent& event);
    void OnQuit(wxCommandEvent& event);
    void OnViewBills(wxCommandEvent& event);
    void OnManagePlugins(wxCommandEvent& event);
    void OnChangeEnviromentSettings(wxCommandEvent& event);
    void OnChangeLanguageSettings(wxCommandEvent& event);
    void OnRestoreDefaultSettings(wxCommandEvent& event);
    void OnHelp(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
    void OnWidgets(wxCommandEvent& event);

    // child controls
    CAccountManager*                m_pAccountManager;
    CReoccuringTransactionListDlg*  m_pReoccuringTransactionDlg;

    // private data
    CSplashScreen*                  m_pSplash;
    bool                            m_IsOkToRun;
    ace::CData*                     m_pData;
    PLUGIN_LIST                     m_PluginList;
    wxIconBundle                    m_Icon;
};

const wxString g_AppName = _("ACE Personal Finance Assistant (Ace PFA)");
const wxString g_AppVersion = wxString::Format(_("%u.%u.%u %s\nRevision %u"),
                                               AutoVersion::MAJOR,
                                               AutoVersion::MINOR,
                                               AutoVersion::BUILD,
                                               AutoVersion::STATUS,
                                               AutoVersion::REVISION);

#endif // MAIN_H_INCLUDED
