moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / kswizard.cpp
blobcd38262583cb92f110b46c63090ddf325e2a0f51
1 /***************************************************************************
2 kswizard.cpp - description
3 -------------------
4 begin : Wed 28 Jan 2004
5 copyright : (C) 2004 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include <qfile.h>
19 #include <qpixmap.h>
20 #include <qlabel.h>
21 #include <klineedit.h>
22 #include <klistbox.h>
23 #include <kpushbutton.h>
25 #include "kstars.h"
26 #include "kstarsdata.h"
27 #include "ksutils.h"
28 #include "geolocation.h"
29 #include "dmsbox.h"
30 #include "telescopewizardprocess.h"
31 #include "kswizardui.h"
32 #include "kswizard.h"
34 KSWizard::KSWizard( QWidget *parent, const char *name )
35 : KSWizardUI( parent, name )
37 ksw = (KStars *)parent;
38 GeoID.resize(10000);
40 //Removing telescope page for now...
41 removePage( page(2) );
43 //Remove Download page if KDE < 3.2.90
44 #if ( ! KDE_IS_VERSION( 3, 2, 90 ) )
45 removePage( page(3) );
46 #endif
48 //each page should have a finish button
49 for ( unsigned int i=0; i<((unsigned int) pageCount()); ++i ) {
50 setFinishEnabled( page(i), true );
53 //Disable "Next" Button on last page
54 setNextEnabled( page( pageCount() - 1 ), false );
56 //Load images into banner frames.
57 QFile imFile;
58 QPixmap im = QPixmap();
60 if ( KSUtils::openDataFile( imFile, "wzstars.png" ) ) {
61 imFile.close(); //Just need the filename...
62 im.load( imFile.name() );
64 Banner1->setPixmap( im );
66 if ( KSUtils::openDataFile( imFile, "wzgeo.png" ) ) {
67 imFile.close(); //Just need the filename...
68 im.load( imFile.name() );
70 Banner2->setPixmap( im );
72 //Uncomment if we ever need the telescope page...
73 // if ( KSUtils::openDataFile( imFile, "wzscope.png" ) ) {
74 // imFile.close(); //Just need the filename...
75 // im.load( imFile.name() );
76 // }
77 // Banner3->setPixmap( im );
79 //Only load the download page banner if KDE >= 3.2.90
80 #if ( KDE_IS_VERSION( 3, 2, 90 ) )
81 if ( KSUtils::openDataFile( imFile, "wzdownload.png" ) ) {
82 imFile.close(); //Just need the filename...
83 im.load( imFile.name() );
85 Banner4->setPixmap( im );
86 #endif
88 //connect signals/slots
89 connect( CityListBox, SIGNAL( selectionChanged() ), this, SLOT( slotChangeCity() ) );
90 connect( CityFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
91 connect( ProvinceFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
92 connect( CountryFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterCities() ) );
93 //Uncomment if we ever need the telescope page...
94 // connect( TelescopeWizardButton, SIGNAL( clicked() ), this, SLOT( slotTelescopeSetup() ) );
95 #if ( KDE_IS_VERSION( 3, 2, 90 ) )
96 connect( DownloadButton, SIGNAL( clicked() ), ksw, SLOT( slotDownload() ) );
97 #endif
99 //Initialize Geographic Location page
100 filteredCityList.setAutoDelete( false );
101 initGeoPage();
104 KSWizard::~KSWizard()
107 void KSWizard::initGeoPage() {
108 LongBox->setReadOnly( true );
109 LatBox->setReadOnly( true );
111 //Populate the CityListBox
112 //flag the ID of the current City
113 int index(0);
114 for (GeoLocation *loc = ksw->data()->geoList.first(); loc; loc = ksw->data()->geoList.next()) {
115 CityListBox->insertItem( loc->fullName() );
116 filteredCityList.append( loc );
118 if ( loc->fullName() == ksw->data()->geo()->fullName() )
119 index = ksw->data()->geoList.at();
122 //Sort alphabetically
123 CityListBox->sort();
125 //preset to current city
126 CityListBox->setCurrentItem( index );
129 void KSWizard::slotChangeCity() {
130 Geo = 0L;
132 if ( CityListBox->currentItem() >= 0 ) {
133 for (GeoLocation *loc = filteredCityList.first(); loc; loc = filteredCityList.next()) {
134 if ( loc->fullName() == CityListBox->currentText() ) {
135 Geo = loc;
136 break;
141 LongBox->showInDegrees( Geo->lng() );
142 LatBox->showInDegrees( Geo->lat() );
145 void KSWizard::slotFilterCities() {
146 CityListBox->clear();
147 filteredCityList.clear();
149 for (GeoLocation *loc = ksw->data()->geoList.first(); loc; loc = ksw->data()->geoList.next()) {
150 QString sc( loc->translatedName() );
151 QString ss( loc->translatedCountry() );
152 QString sp = "";
153 if ( !loc->province().isEmpty() )
154 sp = loc->translatedProvince();
156 if ( sc.lower().startsWith( CityFilter->text().lower() ) &&
157 sp.lower().startsWith( ProvinceFilter->text().lower() ) &&
158 ss.lower().startsWith( CountryFilter->text().lower() ) ) {
159 CityListBox->insertItem( loc->fullName() );
160 filteredCityList.append( loc );
164 CityListBox->sort();
166 if ( CityListBox->firstItem() ) // set first item in list as selected
167 CityListBox->setCurrentItem( CityListBox->firstItem() );
170 //Uncomment if we ever need the telescope page...
171 //void KSWizard::slotTelescopeSetup() {
172 // telescopeWizardProcess twiz(ksw);
173 // twiz.exec();
176 #include "kswizard.moc"