[Kstars-devel] branches/KDE/3.5/kdeedu

Jason Harris kstars at 30doradus.org
Wed Nov 2 07:23:56 CET 2005


SVN commit 476798 by harris:

Some obscure fixes related to setting the clock on startup:

+ Make the ExtDate::fromString() function les picky about what date 
formats it accepts. 

+ When setting the date from a script which is run from the command 
line, make sure to set the given time as the local time, not the UT.

+ Make sure focus position specified in a script is persistent if the 
script is run from the command line.

Will forward port to trunk.

Thanks to Yannick Gingras for the bug report!

CCMAIL: kstars-devel at kde.org
CCMAIL: ygingras at ygingras.net



 M  +7 -2      kstars/kstars/kstarsdata.cpp  
 M  +9 -5      kstars/kstars/main.cpp  
 M  +32 -3     libkdeedu/extdate/extdatetime.cpp  
 M  +4 -2      libkdeedu/extdate/extdatetime.h  


--- branches/KDE/3.5/kdeedu/kstars/kstars/kstarsdata.cpp #476797:476798
@@ -2346,11 +2346,16 @@
 				if ( arg == "sw" || arg == "southwest" ) az = 225.0;
 				if ( arg == "w"  || arg == "west" )      az = 270.0;
 				if ( arg == "nw" || arg == "northwest" ) az = 335.0;
-				if ( az >= 0.0 ) { map->setFocusAltAz( 15.0, az ); cmdCount++; }
+				if ( az >= 0.0 ) { 
+					map->setFocusAltAz( 15.0, az ); 
+					cmdCount++; 
+					map->setDestination( map->focus() );
+				}
 
 				if ( arg == "z" || arg == "zenith" ) {
 					map->setFocusAltAz( 90.0, map->focus()->az()->Degrees() );
 					cmdCount++;
+					map->setDestination( map->focus() );
 				}
 
 				//try a named object.  name is everything after the first word (which is 'lookTowards')
@@ -2413,7 +2418,7 @@
 				if ( ok ) min = fn[5].toInt(&ok);
 				if ( ok ) sec = fn[6].toInt(&ok);
 				if ( ok ) {
-					changeDateTime( KStarsDateTime( ExtDate(yr, mth, day), QTime(hr,min,sec) ) );
+					changeDateTime( geo()->LTtoUT( KStarsDateTime( ExtDate(yr, mth, day), QTime(hr,min,sec) ) ) );
 					cmdCount++;
 				} else {
 					kdWarning() << i18n( "Could not set time: %1 / %2 / %3 ; %4:%5:%6" )
--- branches/KDE/3.5/kdeedu/kstars/kstars/main.cpp #476797:476798
@@ -142,9 +142,6 @@
 		map->resize( w, h );
 		QPixmap sky( w, h );
 
-		dat->setFullTimeUpdate();
-		dat->updateTime(dat->geo(), map );
-
 		map->setDestination( new SkyPoint( Options::focusRA(), Options::focusDec() ) );
 		map->destination()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
 		map->setFocus( map->destination() );
@@ -160,6 +157,10 @@
 			}
 		}
 
+		dat->setFullTimeUpdate();
+		dat->updateTime(dat->geo(), map );
+
+		kapp->processEvents(100000);
 		map->setMapGeometry();
 		map->exportSkyImage( &sky );
 		kapp->processEvents(100000);
@@ -174,10 +175,13 @@
 
 	//start up normally in GUI mode
 	
-	//warn about invalid dates
+	//Try to parse the given date string
 	QString datestring = args->getOption( "date" );
-	if ( ! datestring.isEmpty() && ! KStarsDateTime::fromString( datestring ).isValid() )
+
+	if ( ! datestring.isEmpty() && ! KStarsDateTime::fromString( datestring ).isValid() ) {
 		kdWarning() << i18n("Specified date (%1) is invalid.  Will use current CPU date instead." ).arg( datestring ) << endl;
+		datestring = "";
+	}
 	
 	new KStars( true, ! args->isSet( "paused" ), datestring );
 	QObject::connect(kapp, SIGNAL(lastWindowClosed()), kapp, SLOT(quit()));
--- branches/KDE/3.5/kdeedu/libkdeedu/extdate/extdatetime.cpp #476797:476798
@@ -356,6 +356,17 @@
 }
 
 #ifndef QT_NO_DATESTRING
+//Try both DateFormat values
+ExtDate ExtDate::fromString( const QString& s )
+{
+	ExtDate dResult = ExtDate::fromString( s, Qt::TextDate );
+	if ( dResult.isValid() ) return dResult;
+
+	dResult = ExtDate::fromString( s, Qt::ISODate );
+	if ( dResult.isValid() ) return dResult;
+	else return ExtDate(); //invalid	
+}
+
 ExtDate ExtDate::fromString( const QString& s, Qt::DateFormat f )
 {
 	ExtDate dt = ExtDate();  //initialize invalid date
@@ -373,6 +384,7 @@
 			int year( s.mid( 0, 4 ).toInt() );
 			int month( s.mid( 5, 2 ).toInt() );
 			int day( s.mid( 8, 2 ).toInt() );
+
 			if ( year && month && day )
 				return ExtDate( year, month, day );
 		}
@@ -384,6 +396,7 @@
 		{
 			//Three possible date formats:
 			//dd mth yyyy; mth dd yyyy; wkd mth dd yyyy
+			//"mth" is the word for the month (long or short form)
 			QStringList ss = QStringList::split( " ", s );
 			bool ok = false;
 			int month = -1;
@@ -412,7 +425,7 @@
 			}
 
 			for ( uint i = 0; i < 12; i++ ) {
-				if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) {
+				if ( ss[imonth] == shortMonthName( i+1 ) || ss[imonth] == longMonthName( i+1 ) ) {
 						month = i + 1;
 						break;
 				}
@@ -422,7 +435,7 @@
 				imonth = 2;
 				iyear = 3;
 				for ( uint i = 0; i < 12; i++ ) {
-					if ( ss[imonth] == m_shortMonthNames[i] || ss[imonth] == shortMonthName( i + 1 ) ) {
+					if ( ss[imonth] == shortMonthName( i+1 ) || ss[imonth] == longMonthName( i+1 ) ) {
 							month = i + 1;
 							break;
 					}
@@ -1002,6 +1015,17 @@
 
     \warning Note that \c Qt::LocalDate cannot be used here.
 */
+ExtDateTime ExtDateTime::fromString( const QString& s )
+{
+	ExtDateTime dtResult = ExtDateTime::fromString( s, Qt::TextDate );
+	if ( dtResult.isValid() ) return dtResult;
+
+	dtResult = ExtDateTime::fromString( s, Qt::ISODate );
+
+	if ( dtResult.isValid() ) return dtResult;
+	else return ExtDateTime(); //invalid
+}
+
 ExtDateTime ExtDateTime::fromString( const QString& s, Qt::DateFormat f )
 {
 	ExtDateTime dt;
@@ -1015,8 +1039,13 @@
 	}
 
 	if ( f == Qt::ISODate ) {
-		return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ),
+		if ( s.length() <= 10 || ! s.contains( ':' )  ) { //no time specified
+			QTime t = QTime(0,0,0);
+			return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ) );
+		} else {
+			return ExtDateTime( ExtDate::fromString( s.mid(0,10), Qt::ISODate ),
 					QTime::fromString( s.mid(11), Qt::ISODate ) );
+		}
 	}
 #if !defined(QT_NO_REGEXP) && !defined(QT_NO_TEXTDATE)
 	else if ( f == Qt::TextDate ) {
--- branches/KDE/3.5/kdeedu/libkdeedu/extdate/extdatetime.h #476797:476798
@@ -90,7 +90,8 @@
 
 	static ExtDate currentDate( Qt::TimeSpec ts = Qt::LocalTime );
 #ifndef QT_NO_DATESTRING
-	static ExtDate fromString( const QString& s, Qt::DateFormat f = Qt::TextDate );
+	static ExtDate fromString( const QString &s );
+	static ExtDate fromString( const QString &s, Qt::DateFormat f );
 #endif
 	static bool isValid( int y, int m, int d );
 	static bool leapYear( int year );
@@ -164,7 +165,8 @@
     static ExtDateTime currentDateTime();
     static ExtDateTime currentDateTime( Qt::TimeSpec );
 #ifndef QT_NO_DATESTRING
-    static ExtDateTime fromString( const QString& s, Qt::DateFormat f = Qt::TextDate );
+    static ExtDateTime fromString( const QString &s );
+    static ExtDateTime fromString( const QString &s, Qt::DateFormat f );
 #endif
 private:
     ExtDate  d;


More information about the Kstars-devel mailing list