/***************************************************************************
                          dcgui.h  -  description
                             -------------------
    begin                : Mon Okt  1 19:59:45 CEST 2001
    copyright            : (C) 2001-2005 by Mathias Küster
    email                : mathen@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DCGUI_H
#define DCGUI_H

// include files for QT
#include <QMainWindow>
#include <QString>
#include <QEvent>
#include <QDockWidget>
#include <QSystemTrayIcon>
#include <QTabBar>
#include <QMouseEvent>
#include <QProgressBar>
#include <QWheelEvent>
#include <QShowEvent>

#include "dcapplicationevents.h"
#include "dcconfig.h"
#include "dcclient.h"
#include "dcchat.h"

#include <exception>

#include <dclib/core/types.h>


// forward declaration of the DCGui classes
class QTimer;
class QAction;
class QActionGroup;
class QToolBar;
class QMdiArea;
class QMdiSubWindow;
class QMenu;
class QLabel;

class DCTabBar : public QTabBar {

    Q_OBJECT

public:

    DCTabBar(QWidget *parent) : QTabBar(parent) {
    }

    void nextTab();
    void prevTab();

protected:

    virtual void mousePressEvent(QMouseEvent *me);

};

/**
 * This Class is the base class for your application. It sets up the main
 * window and providing a menubar, toolbar
 * and statusbar. For the main view, an instance of class DCGuiView is
 * created which creates your view.
 *
 * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
 * @version KDevelop version 1.3 code generation
 */
class DCGuiApp : public QMainWindow {
    Q_OBJECT

public:
    /** construtor */
    DCGuiApp();
    /** destructor */
    virtual ~DCGuiApp();

    /** */
    void ShowOptionsDialog() {
        slotFileOptions();
    };
    /** setup all windows */
    void initWindows();

    /** */
    void Dock() {
        slotViewDock();
    }
    /** */
    bool InTray() const {
        return m_bTray;
    }
    /** */
    void WakeUp();
    /** */
    void showNotification(QString sender = "", QString message = "", eTrayMessageType t = eTrayMessageTypeDISC, bool show_anyway = false);
    /** */
    void SetChatOff(bool);
    /** */
    static void SetInstance(DCGuiApp*);
    /** */
    static DCGuiApp *Instance();
    /** */
    static void SetMdiAreaInstance(QMdiArea*);
    /** */
    static QMdiArea *MdiAreaInstance();

protected:
    friend class DCApplicationEvents;
    /** overloaded for Message box on last window exit */
    bool queryExit();
    /** Catch QT4 QMainWindow close event*/
    virtual void closeEvent(QCloseEvent *event);
    /** Receive custom events for updating status bars */
    virtual void customEvent(QEvent * event);
    /** */
    virtual void showEvent(QShowEvent *e);
    /** */
    virtual void changeEvent(QEvent *e);
    /** */
    virtual bool eventFilter(QObject*, QEvent*);

private slots:

    /** */
    void slotFileOptions();
    /** */
    void slotFileQuickOptions();
    /** */
    void slotFileQuickConnect();
    /** */
    void slotFileMenuBar();
#ifndef WIN32
    /** */
    void slotFileInotifyEnable();
#endif
    /** */
    void slotFileFileListBrowser();
    /** */
    void slotFileFileListBrowserLocal();
    /** */
    void slotFileCreateShare();
    /** */
    void slotFileReloadPlugins();
    /** change default download mode */
    void slotChangeDefaultDldMode(QAction* DldType);
    /** exits the application */
    bool slotFileQuit();

    /** */
    void slotRightButtonFileToolbar(QPoint);

    /** */
    void slotClearCurrentChat();

    /** toggle the tabbar*/
    void slotViewTabBar(bool toggle);
    /** toggle the toolbar*/
    void slotViewToolBar(bool toggle);
    /** toggle the statusbar*/
    void slotViewStatusBar(bool toggle);
    /** dock the application */
    void slotViewDock();
    /** show or hide the system tray icon */
    void slotViewTrayIcon(bool toggle);
    /** */
    void slotToolBarBtnStyle(QAction*);
    /** */
    void slotMenuBarView(QAction*);
    /** shows an about dlg*/
    void slotHelpAbout();
    /** opens the online manual in web browser */
    void slotHelpManual();
    /** connect to the valknut hub */
    void slotHelpSupport();
    /** gets called when the window menu is activated; recreates the window menu with all opened window titles. */
    void windowMenuAboutToShow();
    /** activates the MDI child widget when it gets selected from the window menu. */
    void windowMenuActivated(QAction * action);

    /** show/hide transfer list window */
    void slotActionTransferList();
    /** show/hide server list window */
    void slotActionServerList();
    /** show/hide hub search window */
    void slotActionHubSearch();
    /** show/hide spy window */
    void slotActionSpy();
    /** show/hide users window */
    void slotActionUsers();
    /** change user away mode */
    void slotChangeAwayMode();
    /** away mode was changed elsewhere - update menu */
    void slotAwayModeChanged(eUserAwayMode mode);
    /** */
    void slotActionTransferViewType();
    /** */
    void slotActionAntiSpam();
    /** */
    void slotActionIPFilter();
    /** */
    void slotLoadCSS();

    /** */
    void tileVertically();
    /** minimize all windows */
    void slotWindowMinimize();
    /** close all disconnected hub windows */
    void slotWindowCloseHubs();
    /** */
    void slotWindowCloseAllChats();
    /** */
    void slotWindowCloseOfflineChats();
    /** */
    void slotWindowCloseFilelists();
    /** */
    void slotWindowCloseSearches();

    /** */
    void slotTimeout();
    /** tray menu triggers */
    void slotTrayMenuTriggered(QSystemTrayIcon::ActivationReason reason);
    /** called on selecting remove tray icon from the system tray icon's own menu */
    void slotRemoveTrayIcon();

    /** set quick options menu to match setting */
    void slotDefaultDownloadModeChanged();

    /** context menu to reset traffic stats */
    void slotContextMenuTraffic(const QPoint & pos);

    /** show debug settings dialog */
    void slotDebugSettings();

    /** show a malloc info dialog and print malloc stats */
    void slotMallocInfo();

    /** auto away mode enabled or disabled */
    void slotAutoAwayModeChanged(bool enabled);
    /** */
    void slotChildOnDie(QWidget*);
#ifndef WIN32
    /** */
    void slotInotify();
#endif
    /** */
    void slotChatZoomIn();
    /** */
    void slotChatZoomOut();
    /** */
    void slotChatOff();

    /** */
    void slotHubReconnect();

    /** */
    void slotOpenDownloadDir();

private:
    /** */
    void SetTheme();

    /** initializes all QActions of the application */
    void initActions();
    /** deinitializes all QActions of the application */
    void deinitActions();
    /** initMenuBar creates the menu_bar and inserts the menuitems */
    void initMenuBar();
    /** this creates the toolbars. Change the toobar look and add new toolbars in this
     * function */
    void initToolBar();
    /** setup the statusbar */
    void initStatusBar();
    /** initialize the mainview*/
    void initView();
    /** deinitialize the mainview*/
    void deinitView();
    /** initialize the tray icon */
    void initTray();
    /** deinitialize the tray icon */
    void deinitTray();
    /** show/hide mdi widget */
    void showMDIWidget(QMdiSubWindow * window);
    /** */
    void showFreeDiscSpace();
    /** */
    void closeWindowsOfClass(QString classname);

    /** file_menu contains all items of the menubar entry "File" */
    QMenu *pFileMenu;
    /** */
    QMenu *pQuickOptionsMenu;
    /** view_menu contains all items of the menubar entry "View" */
    QMenu *pViewMenu;
    /** view_menu contains all items of the menubar entry "Help" */
    QMenu *pHelpMenu;
    /** the window menu */
    QMenu *pWindowMenu;
#ifndef WIN32
    /** */
    QMenu *pInotify;
#endif
    QMenu *pToolBarMenu;

    /** action */
    QMenu *pActionMenu;
    /** away mode */
    QMenu *pAwayMenu;
    /** */
    QToolBar *windowsTabBar;
    /** */
    QToolBar *fileToolbar;
    /** */
    QLabel * statusDMLabel;
    /** */
    QLabel * statusTRLabel;
    /** */
    QLabel * statusDSLabel;
    /** */
    QMdiArea *pMdiArea;
    /** */
    QAction *fileOptions;
    /** */
    QAction *fileOpenDownloadDir;
    /** */
    QAction *fileQuickOptions;
    /** */
    QAction *fileQuickConnect;
    /** */
    QAction *fileHubReconnect;
    /** */
    QAction *fileMenuBar;
    /** */
    QActionGroup *viewToolBarGrp;
    /** */
    QAction *viewToolBarIconOnly;
    /** */
    QAction *viewToolBarTextOnly;
    /** Text beside the icon*/
    QAction *viewToolBarTextBIcon;
    /** Text under the icon*/
    QAction *viewToolBarTextUIcon;
    /** */
    QMenu *pMenuBarHide;
    /** */
    QActionGroup *viewMenuBar;
    /** */
    QAction *viewMenuBarNormal;
    /** */
    QAction *viewMenuBarCompact;

#ifndef WIN32
    /** */
    QAction *fileInotify;
    /** */
    QAction *fileInotifyEnable;
#endif
    /** */
    QAction *fileFileListBrowser;
    /** */
    QAction *fileFileListBrowserLocal;
    /** */
    QAction *fileFileListRefresh;
    /** */
    QAction *fileReloadPlugins;
    /** */
    QAction *fileQuit;

    /** */
    QAction *chatZoomIn;
    /** */
    QAction *chatZoomOut;
    /** */
    QAction *chatOff;

    /** */
    QAction *actionClearChat;
    /** */
    QActionGroup *fileDefaultDldGroup;
    /** */
    QAction *fileDefaultDldAsk;
    /** */
    QAction *fileDefaultDldSingle;
    /** */
    QAction *fileDefaultDldMulti;
    /** */
    QAction *viewTabBar;
    /** */
    QAction *viewToolBar;
    /** */
    QAction *viewStatusBar;
    /** */
    QAction *viewDock;
    /** */
    QAction *viewTrayIcon;
    /** */
    QAction *viewReloadCSS;
    /** */
    QAction *windowTile;
    /** */
    QAction *windowTileHor;
    /** */
    QAction *windowCascade;
    /** */
    QAction *windowMinimize;
    /** */
    QAction *windowCloseHubs;
    /** */
    QAction *windowCloseAllChats;
    /** */
    QAction *windowCloseOfflineChats;
    /** */
    QAction *windowCloseFilelists;
    /** */
    QAction *windowCloseSearches;
    /** */
    QActionGroup *windowAction;
    /** */
    QActionGroup *windowsGroup;
    /** */
    QAction *actionServerList;
    /** */
    QAction *actionTransferList;
    /** */
    QAction *actionHubSearch;
    /** */
    QAction *actionSpy;
    /** */
    QAction *actionUsers;
    /** */
    QActionGroup * actionGroupAwayMode;
    /** */
    QAction *actionAwayModeNormal;
    /** */
    QAction *actionAwayModeAway;
    /** */
    QAction *actionTransferViewType;
    /** */
    QAction *actionAntiSpam;
    /** */
    QAction *actionIPFilter;
    /** */
    QAction *helpAboutApp;
    /** */
    QAction *helpManualApp;
    /** */
    QAction *helpSupportApp;
    /** */
    QAction *debugSettings;
    /** */
    QDockWidget * pTransferViewDock;
    /** */
    QTimer * m_pTimer;
    /** */
    DCApplicationEvents m_ApplicationEvents;
    /** tray icon */
    QSystemTrayIcon * m_pTrayIcon;
    /** */
    QProgressBar *m_pProgessBar;
    /** */
    bool m_bTray;
    /** */
    bool m_bEnableTray;
    /** */
    bool ready2Unload;
    /**
     * Set to true if the transfer view was floating when valknut got
     * minimized to tray.
     */
    bool m_bTransferViewGotTrayed;
    /** hold old desktop position on dock/undock */
    QPoint m_DesktopPosition;
    /** hold old maximized status on dock/undock */
    bool m_bWasMaximized;
    /** */
    bool m_bIsQuitPromptVisible;
    /** */
    QList<QAction*> menubar_menus;
    /** */
    QDialog *qc;
    /** */
    //QList<QAction*> toolbar_actions;

    /** */
    static DCGuiApp *pMainWin;
    /** */
    static QMdiArea *s_pMdiArea;
};

/** */
inline void DCGuiApp::SetInstance(DCGuiApp *app) {
    pMainWin = app;
}

/** */
inline DCGuiApp *DCGuiApp::Instance() {
    return pMainWin;
}

inline void DCGuiApp::SetMdiAreaInstance(QMdiArea *area) {
    s_pMdiArea = area;
}

inline QMdiArea *DCGuiApp::MdiAreaInstance() {
    return s_pMdiArea;
}

#endif
