summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/kswizard.cpp
blob: 852583622e3abcd89032d32123e4af0599dab535 (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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***************************************************************************
                          kswizard.cpp  -  description
                             -------------------
    begin                : Wed 28 Jan 2004
    copyright            : (C) 2004 by Jason Harris
    email                : kstars@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 <tqfile.h>
#include <tqpixmap.h>
#include <tqlabel.h>
#include <klineedit.h>
#include <klistbox.h>
#include <kpushbutton.h>

#include "kstars.h"
#include "kstarsdata.h"
#include "ksutils.h"
#include "geolocation.h"
#include "dmsbox.h"
#include "telescopewizardprocess.h"
#include "kswizardui.h"
#include "kswizard.h"

KSWizard::KSWizard( TQWidget *parent, const char *name )
 : KSWizardUI( parent, name )
{
	ksw = (KStars *)parent;
	GeoID.resize(10000);
	
	//Removing telescope page for now...
	removePage( page(2) );
	
	//Remove Download page if KDE < 3.2.90
	#if ( ! KDE_IS_VERSION( 3, 2, 90 ) ) 
	removePage( page(3) );
	#endif
	
	//each page should have a finish button
	for ( unsigned int i=0; i<((unsigned int) pageCount()); ++i ) {
		setFinishEnabled( page(i), true );
	}

	//Disable "Next" Button on last page
	setNextEnabled( page( pageCount() - 1 ), false );

	//Load images into banner frames.
	TQFile imFile;
	TQPixmap im = TQPixmap();
	
	if ( KSUtils::openDataFile( imFile, "wzstars.png" ) ) {
		imFile.close(); //Just need the filename...
		im.load( imFile.name() );
	}
	Banner1->setPixmap( im );
	
	if ( KSUtils::openDataFile( imFile, "wzgeo.png" ) ) {
		imFile.close(); //Just need the filename...
		im.load( imFile.name() );
	}
	Banner2->setPixmap( im );
	
//Uncomment if we ever need the telescope page...
//	if ( KSUtils::openDataFile( imFile, "wzscope.png" ) ) {
//		imFile.close(); //Just need the filename...
//		im.load( imFile.name() );
//	}
//	Banner3->setPixmap( im );

	//Only load the download page banner if KDE >= 3.2.90
	#if ( KDE_IS_VERSION( 3, 2, 90 ) )
	if ( KSUtils::openDataFile( imFile, "wzdownload.png" ) ) {
		imFile.close(); //Just need the filename...
		im.load( imFile.name() );
	}
	Banner4->setPixmap( im );
	#endif

	//connect signals/slots
	connect( CityListBox, TQT_SIGNAL( selectionChanged() ), this, TQT_SLOT( slotChangeCity() ) );
	connect( CityFilter, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( slotFilterCities() ) );
	connect( ProvinceFilter, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( slotFilterCities() ) );
	connect( CountryFilter, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( slotFilterCities() ) );
//Uncomment if we ever need the telescope page...
//	connect( TelescopeWizardButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotTelescopeSetup() ) );
	#if ( KDE_IS_VERSION( 3, 2, 90 ) )
	connect( DownloadButton, TQT_SIGNAL( clicked() ), ksw, TQT_SLOT( slotDownload() ) );
	#endif
	
	//Initialize Geographic Location page
	filteredCityList.setAutoDelete( false );
	initGeoPage();
}

KSWizard::~KSWizard() 
{}

void KSWizard::initGeoPage() {
	LongBox->setReadOnly( true );
	LatBox->setReadOnly( true );

	//Populate the CityListBox
	//flag the ID of the current City
	int index(0);
	for (GeoLocation *loc = ksw->data()->geoList.first(); loc; loc = ksw->data()->geoList.next()) {
		CityListBox->insertItem( loc->fullName() );
		filteredCityList.append( loc );
		
		if ( loc->fullName() == ksw->data()->geo()->fullName() ) {
			index = ksw->data()->geoList.at();
			Geo = loc;
		}
	}
	
	//Sort alphabetically
	CityListBox->sort();
	
	//preset to current city
	CityListBox->setCurrentItem( index + 1 );
}

void KSWizard::slotChangeCity() {
	Geo = 0L;
	
	if ( CityListBox->currentItem() >= 0 ) {
		for (GeoLocation *loc = filteredCityList.first(); loc; loc = filteredCityList.next()) {
			if ( loc->fullName() == CityListBox->currentText() ) {
				Geo = loc;
				break;
			}
		}
	}

	LongBox->showInDegrees( Geo->lng() );
	LatBox->showInDegrees( Geo->lat() );
}

void KSWizard::slotFilterCities() {
	CityListBox->clear();
	filteredCityList.clear();

	for (GeoLocation *loc = ksw->data()->geoList.first(); loc; loc = ksw->data()->geoList.next()) {
		TQString sc( loc->translatedName() );
		TQString ss( loc->translatedCountry() );
		TQString sp = "";
		if ( !loc->province().isEmpty() )
			sp = loc->translatedProvince();

		if ( sc.lower().startsWith( CityFilter->text().lower() ) &&
				sp.lower().startsWith( ProvinceFilter->text().lower() ) &&
				ss.lower().startsWith( CountryFilter->text().lower() ) ) {
			CityListBox->insertItem( loc->fullName() );
			filteredCityList.append( loc );
		}
	}
	
	CityListBox->sort();

	if ( CityListBox->firstItem() )  // set first item in list as selected
		CityListBox->setCurrentItem( CityListBox->firstItem() );
}

//Uncomment if we ever need the telescope page...
//void KSWizard::slotTelescopeSetup() {
//	telescopeWizardProcess twiz(ksw);
//	twiz.exec();
//}

#include "kswizard.moc"