/*
    This file is part of Bemused.

    Bemused 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.

    Bemused 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 Bemused; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

	Copyright (C) 2003 Ashley Montanaro and Daniel Winter.
*/


#define MAX_PATH 1024


/////////////////////////////////////////////////////////////////////////////
// CDirTreeNode class

class CDirTreeNode
	{
public:
	CDirTreeNode();
	~CDirTreeNode();

	unsigned char iNodeType;
	unsigned char iFileType;
	char* iFileName;

	bool iWrittenToBuffer;

	CDirTreeNode* iParent;
	CDirTreeNode* iFirstChild;
	CDirTreeNode* iNextSibling;
	};


/////////////////////////////////////////////////////////////////////////////
// CBemusedServerDlg dialog

class CBemusedServerDlg
{
// Construction
public:
	CBemusedServerDlg();	// standard constructor
	~CBemusedServerDlg();
	bool OnInitDialog(bool daemonize = false);

// Implementation

private:
	int BluetoothConnectToSocket(int Channel);
  int BluetoothWaitforConnect(int s);
	void ReadBluetoothCommand();
	void HandleBluetooth();

	bool CheckWinamp(const char* aWindowName);
  bool CBemusedServerDlg::ReadFile(int handle,char* buffer,int maxbytes,long unsigned int* bytesread,int* bla);
  bool CBemusedServerDlg::ReadFile(int handle,unsigned char* buffer,int maxbytes,long unsigned int* bytesread,int* bla);
  bool CBemusedServerDlg::WriteFile(int handle, char* buffer,int maxbytes, long unsigned int* byteswritten,int* bla);
  bool CBemusedServerDlg::WriteFile(int handle,unsigned char* buffer,int maxbytes, long unsigned int* byteswritten,int* bla);
  char* CBemusedServerDlg::GetLastError();

	void WriteListToPhone();
	void WriteDirectoryListToPhone();
	void WritePlaylistToPhone();

	void WriteInfoToPhone();
	void WriteInf2ToPhone();
	void WriteDetailedInfoToPhone();
	void Play();
	void PlayFile(bool aAddToPlaylist);
	void GetFileInfo();
	void SetSeek();
	void DownloadFile();
	void SetVolume();
	void GetVolume();
	void Version();
	void SelectInPlaylist();
	void RemoveAllFromPlaylist();
	void Stop(bool aFadeOut);
	void Pause();
	void NextTrack();
	void PreviousTrack();
	void FastForward();
	void Rewind();
	void Shuffle();
	void Repeat();
	void ShutDown();
	void Check();
	void FadeOut();
	void ReadIniFile();

	void CBemusedServerDlg::AddBookmarks(CDirTreeNode* aNode, CDirTreeNode* pNode, bool aRecursive);
	void GenerateFileList(const char* aRoot, bool aRecursive);
	void ReadDir(char* aDir, CDirTreeNode* aNode, bool aRecursive);
	bool WriteNodeToBuffer(CDirTreeNode* aNode, unsigned char*& aBufferPtr, int& aSizeRemaining);
	void ResetWrittenFlag(CDirTreeNode* aNode);

	void Log(char* aFormatString, ...);

	CDirTreeNode* iDirTreeRoot;
	CDirTreeNode* iDirTreeCurrentNode;

	int iCommHandle;
	bool iExitNow;
	bool iStopEnd;
	bool iStopNow;

  int startAutomatically;
  char winampPath[256];
  char bookmarkfile[256];
  char bookmarks[100][256];  // stream URLS
  char bookmarktitles[100][100];  // stream Titles
  int nobookmarks;
  int socket1;
  int channel;
  int fastforbackspeed;
  char mp3Dirs[1024];
  bool tcp;
  int tcpport;
  int lastTime;
};
