summaryrefslogtreecommitdiffstats
path: root/knights/list_pgn.cpp
blob: f1dfc22df0fef3be9d567667196b2569ef48c1e2 (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
/***************************************************************************
                          list_pgn.cpp  -  description
                             -------------------
    begin                : Thu Dec 13 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "list_pgn.moc"
#include <tdelistview.h>
#include <kstatusbar.h>
#include <kprogress.h>
#include <tqhbox.h>
#include "resource.h"
#include "match_param.h"

list_pgn::list_pgn(TQWidget *parent, const char *name) : TQVBox(parent,name)
{
	listView = new TDEListView( this, "listView" );
	listView->addColumn( i18n( "Result" ) );
	listView->addColumn( i18n( "White" ) );
	listView->addColumn( i18n( "Black" ) );
	listView->addColumn( i18n( "Round" ) );
	listView->addColumn( i18n( "Site" ) );
	listView->addColumn( i18n( "Date" ) );
	listView->setSorting( 1 );
	listView->setAllColumnsShowFocus( TRUE );
	listView->setMultiSelection( FALSE );
	listView->setShowSortIndicator( TRUE );
	listView->restoreLayout( kapp->config(), "PGN_ListView" );
	listView->show();
	connect( listView, TQT_SIGNAL( executed( TQListViewItem* ) ), this, TQT_SLOT( slot_selected( TQListViewItem* ) ) );

	/*
			Showing listView while scanning can mean the difference between
			a 12 second load time and a 40 second load time. dummyView is
			just a placeholder for listView while scanning.
	*/
	dummyView = new TDEListView( this, "dummyView" );
	dummyView->addColumn( i18n( "Result" ) );
	dummyView->addColumn( i18n( "White" ) );
	dummyView->addColumn( i18n( "Black" ) );
	dummyView->addColumn( i18n( "Round" ) );
	dummyView->addColumn( i18n( "Site" ) );
	dummyView->addColumn( i18n( "Date" ) );
	dummyView->restoreLayout( kapp->config(), "PGN_ListView" );
	dummyView->hide();

	statusBox = new TQHBox( this, "statusBox" );
	status = new KStatusBar( statusBox, "status" );

	progress = new KProgress( statusBox, "progress" );
	progress->setValue( 0 );

	show();
}
list_pgn::~list_pgn()
{
	listView->saveLayout( kapp->config(), "PGN_ListView" );
}
///////////////////////////////////////
//
//	list_pgn::setURL
//
///////////////////////////////////////
void list_pgn::setURL( TQString URL )
{
	myURL = URL;
	listView->clear();
	setCaption( URL );

	if( tmpPGN.open( URL ) == FALSE )
	{
		status->message( i18n( "Can not open %1" ).arg( URL ) );
		return;
	}
	listView->hide();
	dummyView->show();
	startTimer( 0 );
}
///////////////////////////////////////
//
//	list_pgn::setProgress
//
///////////////////////////////////////
void list_pgn::setProgress( const int num )
{
	progress->setValue( num );
	if( num == 100 )
		progress->setEnabled( FALSE );
	else
		progress->setEnabled( TRUE );
}
///////////////////////////////////////
//
//	list_pgn::slot_selected
//
///////////////////////////////////////
void list_pgn::slot_selected( TQListViewItem *item )
{
	emit selected( myURL, item->text(6).toInt() );
}
///////////////////////////////////////
//
//	list_pgn::timerEvent
//
///////////////////////////////////////
void list_pgn::timerEvent( TQTimerEvent* )
{
	int fileProgress;

	fileProgress = tmpPGN.scan();
	setProgress( fileProgress );
	if( tmpPGN.TAG_White.isEmpty() )
	{
		if( listView->childCount() == 1 )
		{
			emit selected( myURL, 0 );
		}
		TQT_TQOBJECT(this)->killTimers();
		listView->show();
		dummyView->hide();
	}
	else
	{
		(void) new TDEListViewItem( listView,
															tmpPGN.TAG_Result,
															tmpPGN.TAG_White,
															tmpPGN.TAG_Black,
															tmpPGN.TAG_Round,
															tmpPGN.TAG_Site,
															tmpPGN.TAG_Date,
															TQString::number(tmpPGN.File_Position) );
		status->message( i18n( "%1 matches found." ).arg( listView->childCount() ) );
	}
}