summaryrefslogtreecommitdiffstats
path: root/knights/pgn.h
blob: eeff9d82b289a933882953772d3d6a36fca578f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/***************************************************************************
                          pgn.h  -  description
                             -------------------
    begin                : Mon Jul 30 2001
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 PGN_H
#define PGN_H

#include <klocale.h>
#include <ktempfile.h>
#include <kio/netaccess.h>
#include <qobject.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qvaluelist.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qpainter.h>
#include "definitions.h"
#include "resource.h"
#include "knightsmap.h"
#include "match_param.h"

/**
  *@author Troy Corbin Jr.
  */

typedef struct Annotation
{
	int RAV;
	QString text;
};

typedef QValueList<ChessMove> MoveList;
typedef KnightsMap<int, Annotation*> Annotations;

class tab_pgnView;

class pgn : public QObject
{
	Q_OBJECT
	public:
		/* Standard PGN Tags */
		QString 						TAG_Event;
		QString 						TAG_Site;
		QString 						TAG_Date;
		QString 						TAG_Round;
		QString 						TAG_White;
		QString 						TAG_Black;
		QString 						TAG_Result;
		QString 						TAG_EventDate;
		QString 						TAG_EventSponsor;
		QString 						TAG_Section;
		QString 						TAG_Stage;
		QString 						TAG_Board;
		QString 						TAG_WhiteTitle;
		QString 						TAG_WhiteElo;
		QString 						TAG_WhiteUSCF;
		QString 						TAG_WhiteNA;
		QString 						TAG_WhiteType;
		QString 						TAG_BlackTitle;
		QString 						TAG_BlackElo;
		QString 						TAG_BlackUSCF;
		QString 						TAG_BlackNA;
		QString 						TAG_BlackType;
		QString 						TAG_Opening;
		QString 						TAG_Variation;
		QString 						TAG_SubVariation;
		QString 						TAG_ECO;
		QString 						TAG_NIC;
		QString 						TAG_Time;
		QString 						TAG_UTCTime;
		QString 						TAG_UTCDate;
		QString 						TAG_TimeControl;
		QString 						TAG_SetUp;
		QString 						TAG_FEN;
		QString							TAG_Termination;
		QString							TAG_Annotator;
		QString							TAG_Mode;
		QString 						TAG_PlyCount;

		int									File_Position; // Used to scan PGN file
		QStringList					Move_Data;

		/* The match_param */
		match_param					*Param;

												/* These are used in unfinished save games */
		int									whiteTime;
		int									blackTime;
		TCPList							whiteTCP;
		TCPList							blackTCP;

		QString							CurrentURL;
		MoveList						Moves;
		Annotations					RAV;
		Annotations					annotations;
		QStringList					Positions;
		unsigned int				currentIndex;

												pgn( resource *Rsrc=0, match_param *param=NULL );
												~pgn();
		void								clear( void );
		void								init( void );
		int									scan( void );
		bool								load( const int pos=0 );
		bool								save( QString URL );
		bool								open( const QString& URL );
		void								print( void );
		QStringList*				notation( const int format=1 );
		void								close( void );
		static QString			getNAG( int num );
		QString							caption( void );

	signals:
		void								processMove( ChessMove );
		void								processSpecial( void );

	public slots:
		bool								loadNext( void );
		void								parseMatchParam( void );
		void								childViewDestroyed( void );

	private:
		resource						*Resource;
		tab_pgnView					*pgnView;
		QString							tempFile;
		QString							currentLine;
		QFile								File;
		QTextStream					Input;

		QChar								getch( void );
		QString							getword( void );
		void								clearTags( void );
		void								parseTag( void );
		void								parseAnnotation( const int fromRAVnum=0 );
		void								parseRAV( void );
		void								parseKnightsData( void );
};

#endif