Source

oberchatten / MainFormUnit.h

/*
$Id: MainFormUnit.h,v 0.9 2006/03/05 12:01:00 ddrp Exp $

Copyright (C) 2001-2006 Daybo Logic.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
//---------------------------------------------------------------------------
#ifndef MainFormUnitH
#define MainFormUnitH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>

#include <Buttons.hpp>
#include <Dialogs.hpp>
//---------------------------------------------------------------------------
enum dialogTypeID {
  digGeneral,
  digUnsupportedFeature,
  digFoolishUser
};

class TMainForm : public TForm
{
__published:	// IDE-managed Components
        TMainMenu *MainMenu1;
        TMenuItem *MnuHelp;
        TMenuItem *MnuHelpAbout;
        TMenuItem *MnuChums;
        TMenuItem *MnuChumsAdd;
        TMenuItem *MnuChumsSearch;
        TMenuItem *MnuChumsDel;
        TMenuItem *MnyChumsWhois;
        TMenuItem *MnuChumsBackup;
        TMenuItem *MnuChumsRestore;
        TMenuItem *N1;
        TMenuItem *N2;
        TMenuItem *N3;
        TMenuItem *MnuChat;
        TMenuItem *MnuChatSuggestions;
        TMenuItem *MnuChatSuggest1;
        TMenuItem *MnuChatSuggest2;
        TMenuItem *MnuChatSuggest3;
        TMenuItem *MnuChatSuggest4;
        TMenuItem *MnuChatSuggest5;
        TMenuItem *MnuChatSuggest6;
        TMenuItem *N4;
        TMenuItem *MnuChatSuggestMore;
        TMenuItem *MnuChatJoin;
        TMenuItem *MnuOberchatten;
        TMenuItem *MnuOberchattenExit;
        TMenuItem *MnuWindow;
        TMenuItem *MnuWindowChat;
        TMenuItem *MnuOberchattenMailPsw;
        TMenuItem *MnuOberchattenChangeAddress;
        TMenuItem *MnuOberchattenChPass;
        TMenuItem *N5;
        TMenuItem *MnuOberchattenSignon;
        TMenuItem *MnuOberchattenSignoff;
        TMenuItem *MnuOptions;
        TMenuItem *MnuOptionsPrefs;
        TMenuItem *N6;
        TMenuItem *N7;
        TMenuItem *MnuChatMsg;
        TMenuItem *N8;
        TMenuItem *MnuOptionsReload;
        TMenuItem *MnuOptionsSave;
        TTimer *TechnicalTimer;
        TMenuItem *MnuHelpCredits;
        TStatusBar *StatusBar;
        TMenuItem *MnuOptionsMsgWin;
        TMenuItem *MnuOptionsMsgWinBeep;
        TMenuItem *MnuOptionsMsgWinTimestamps;
        TMenuItem *MnuOptionsMsgWinIgnoreWobbles;
        TMenuItem *MnuOptionsAutoLogging;
        TMenuItem *MnuOberchattenAway;
        TMenuItem *MnuOberChattenProfile;
        TMenuItem *N10;
        TMenuItem *MnuOptionsShadows;
        TMenuItem *MnuChumsIgnore;
        TMenuItem *MnuOberchattenAwayNow;
        TMenuItem *MnuOberchattenAwayMsg;
        TMenuItem *MnuOberchattenAwayReturn;
        TMenuItem *N11;
        TMenuItem *MnuOberchattenSrvver;
        TPageControl *PageControl;
        TTabSheet *OnlineChumsTabSheet;
        TListBox *OnlineChumsListBox;
        TTabSheet *ChumEditTabSheet;
        TListBox *ChumsListBox;
        TPopupMenu *ChumPopupMenu;
        TMenuItem *MnuChumPopupAdd;
        TMenuItem *MnuChumPopupDel;
        TMenuItem *MenuItem1;
        TMenuItem *MnuChumPopupSelAll;
        TMenuItem *MnuChumPopupSelNone;
        TMenuItem *MnuChumPopupInvert;
        TMenuItem *MenuItem2;
        TMenuItem *MnuChumPopupGod;
        TMenuItem *MnuGodPopupKill;
        TMenuItem *MnuGodPopupKLine;
        TMenuItem *MnuGodPopupGLine;
        TMenuItem *MnuGodPopupInhialate;
        TMenuItem *MnuGodPopupInhialateAll;
        TMenuItem *MenuItem3;
        TMenuItem *MnuChumPopupWhois;
        TTimer *IsOnlineHackTimer;
        TOpenDialog *OpenDialog1;
        TSaveDialog *SaveDialog1;
        TPanel *ToolPanel;
        TSpeedButton *AddChumBtn;
        TSpeedButton *DelChumBtn;
        TSpeedButton *WhoisChumBtn;
        TMenuItem *MnuWindowMsg;
        TMenuItem *N9;
        TMenuItem *MnuWindowStats;
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall MnuOberchattenExitClick(TObject *Sender);
        void __fastcall MnuHelpAboutClick(TObject *Sender);
        void __fastcall FormShow(TObject *Sender);
        void __fastcall MnuOptionsPrefsClick(TObject *Sender);
        void __fastcall MnuOberchattenSignonClick(TObject *Sender);
        void __fastcall MnuOberchattenSignoffClick(TObject *Sender);
        void __fastcall MnuChatMsgClick(TObject *Sender);
        void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
        void __fastcall MnuOptionsReloadClick(TObject *Sender);
        void __fastcall MnuOptionsSaveClick(TObject *Sender);
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall TechnicalTimerTimer(TObject *Sender);
        void __fastcall MnuChatJoinClick(TObject *Sender);
        void __fastcall MnuHelpCreditsClick(TObject *Sender);
        void __fastcall MnuChumsSearchClick(TObject *Sender);
        void __fastcall MnuOptionsMsgWinBeepClick(TObject *Sender);
        void __fastcall MnuChumsBackupClick(TObject *Sender);
        void __fastcall MnuChumsRestoreClick(TObject *Sender);
        void __fastcall MnuOptionsMsgWinTimestampsClick(TObject *Sender);
        void __fastcall MnuOptionsMsgWinIgnoreWobblesClick(TObject *Sender);
        void __fastcall MnuOptionsAutoLoggingClick(TObject *Sender);
        void __fastcall MnuOptionsShadowsClick(TObject *Sender);
        void __fastcall MnuChumsIgnoreClick(TObject *Sender);
        void __fastcall MnuOberChattenProfileClick(TObject *Sender);
        void __fastcall MnuOberchattenAwayMsgClick(TObject *Sender);
        void __fastcall MnuOberchattenAwayNowClick(TObject *Sender);
        void __fastcall MnuOberchattenAwayReturnClick(TObject *Sender);
        void __fastcall FormResize(TObject *Sender);
        void __fastcall MnuOberchattenSrvverClick(TObject *Sender);
        void __fastcall ChumsListBoxDblClick(TObject *Sender);
        void __fastcall MnuChumPopupWhoisClick(TObject *Sender);
        void __fastcall IsOnlineHackTimerTimer(TObject *Sender);
        void __fastcall OnlineChumsListBoxDblClick(TObject *Sender);
        void __fastcall PageControlChange(TObject *Sender);
        void __fastcall MnuChumPopupDelClick(TObject *Sender);
        void __fastcall MnuChumPopupAddClick(TObject *Sender);
        void __fastcall MnuGodPopupKillClick(TObject *Sender);
        void __fastcall MnuChumPopupInvertClick(TObject *Sender);
        void __fastcall MnuChumPopupSelNoneClick(TObject *Sender);
        void __fastcall MnuChumPopupSelAllClick(TObject *Sender);
        void __fastcall MnuWindowStatsClick(TObject *Sender);
private:	// User declarations
        blake_link_ptrs messageWindows; // List of message windows
        blake_link_ptrs chatWindows; // List of chat rooms
        bool checkedAutoSignon; // Set true once initially checked
        bool dimsLoaded;

        void DelMsg(TMsgForm *FormPointer); // Deletes a dynamic conversation
        void DelMsgs(); // Deletes all dynamic conversations
        void DelPendingMsgs(); // Delete message windows which are due to be deleted

        void DelChat(TChatForm *FormPointer); // Deletes a dynamic chat room
        void DelChats(); // Deletes all dynamic chat rooms
        void DelPendingChats(); // Delete chat rooms which are due to be deleted
        void InstallEventHandlers();
        void UninstallEventHandlers();
        void Egg1(); // An Easter Egg used for messaging user "OverChat"
        void Egg2(); // An Easter Agg for people who want to know too much about Blake
        void __fastcall OnMove(TWMMove &Message);
protected:
        void InternalDialog(const char *Message, enum dialogTypeID ID);
        void BackupChumsDlg(); // Display backup chums dialog
        void RestoreChumsDlg(); // Display restore chums dialog
        bool BackupChums(const AnsiString &FileName);
        bool RestoreChums(const AnsiString &FileName);
        bool IsChum(const AnsiString &ChumName);
        bool IsChum(const char *ChumName);
        void ChumGoIdle(const AnsiString &NickName); // Show a chum in an idle state
        void ChumUnIdle(const AnsiString &NickName); // Show a chum as back
        void ChumSignOn(const AnsiString &NickName); // Show a chum as signed on
        void ChumSignOff(const AnsiString &NickName); // Show a chum as signed off
        bool AddToChumList(const AnsiString &ChumName, const bool SkipDupTest = false); // Set SkipDupTest to true if you want to avoid a call to IsChum()
        bool AddToChumList(const char *ChumName, const bool SkipDupTest = false);
        void ClearChums(); // Clears the chums (generally used before reloading), you might need to use ClearOnlineChums() too
        void ClearOnlineChums(); // Useful when the connection dies
        void RestoreDims();
        void SaveDims();
public:		// User declarations
        TMyUser MyUser; // Global information to describe the logged in user
        Oberchatten::TStatusBarManager StatusBarManager; // StatusBar's custom governor

        // Try to keep this friend list to a sensible minimum.  Only things
        // which are totally inseparable should be here.
        friend class TSignonForm; // To modify menus, very integral
        friend class Oberchatten::TOptions; // To call this->ClearChums()

        __fastcall TMainForm(TComponent *Owner);
        __fastcall ~TMainForm();

        TMsgForm *NewMsg_AnsiString(AnsiString &RemoteUser);
        TMsgForm *NewMsg_char(const char *RemoteUser);
        TMsgForm *NewMsg_Event(OVERCHAT_EVENT *PMessageEvent);
        TMsgForm *FindMsg(AnsiString &RemoteUser);
        TMsgForm *FindMsg(const char *RemoteUser);

        TChatForm *NewChat(AnsiString &ChatName, enum blakeExchange Exch);
        TChatForm *NewChat(const char *ChatName, enum blakeExchange Exch);
        TChatForm *FindChat(AnsiString &ChatName, enum blakeExchange Exch);

        void ProcessMessage2(const char *Command); // Sub-protocol processor

        // VCL handlers
        void __fastcall IdleHandler(TObject*, bool &done); // Executes whenever we get a chance
        void __fastcall HintHandler(TObject *Sender);

        void CriticalProtocol(char *Message); // Display a critical protocol error
        void BlakeError(const char *File, const unsigned int Line, enum blakeError ErrorNumber); // Display a Blake library error
        void BlakeNetBufferError(const char *File, const unsigned int Line, enum blakeNetBufferError NetBufferErrorNumber); // Display a NetBuffer error
        void WhoisInfo(struct blakeWhoisInfo *PWhoisInfo);
        void Versioned(struct blakeVersioned *PVersioned);
        void GotError(struct blakeGotError *PGotError);
        void Whois(AnsiString &RemoteUser); // Request whois on a user
        void IsOnlineReply(struct blakeIsOnlineReply *PIsOnlineReply);
        void IsOnline(AnsiString &RemoteUser); // Test if a user is online
        void Kill(const AnsiString &NickName, const AnsiString &SneerMessage);
        void Kill(const char *NickName, const char *SneerMessage);
        void Killed(struct blakeKilled *PKilled);
        void Super(struct blakeSuper *PSuper);
        void SuperRequest(); // Ask your own privilege level
        void NoticePrivilegeChanged( // Update GUI to the new privilege level
          blake_word8_t OldPrivilege,
          blake_word8_t NewPrivilege
        );
        bool AddChum(const AnsiString &ChumNick, bool ShowGoodMsg=true);
        bool AddChum(const char *ChumNick, bool ShowGoodMsg=true);
        bool ChumSearch();
        void Unsupported(const AnsiString &Message);
        void Unsupported(const char *Message);
        void Dialog(const AnsiString &Message);
        void Dialog(const char *Message);
        void FoolishUser(const AnsiString &Message);
        void FoolishUser(const char *Message);
        void CheckAutoSignon(void); // Will only run once
        int ChumCount();
        int OnlineChumCount();

        // Callbacks from other forms
        void CallbackStatsFormClose();

        // Message map table
        BEGIN_MESSAGE_MAP
          MESSAGE_HANDLER(WM_MOVE, TWMMove, OnMove)
        END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif