[Kstars-devel] KDE/kdeedu/kstars/kstars

Alexey Khudyakov alexey.skladnoy at gmail.com
Sun Aug 16 12:29:04 CEST 2009


SVN commit 1011899 by khudyakov:

Simplify logic of KStarsData initialization.
If data file not found either abort or continue without it.
This makes logic easier to understand.

CCMAIL: kstars-devel at kde.org

 M  +30 -70    kstarsdata.cpp  
 M  +0 -4      kstarsdata.h  
 M  +0 -1      main.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.cpp #1011898:1011899
@@ -75,8 +75,6 @@
     m_preUpdateNum( J2000 ), m_updateNum( J2000 ),
     temporaryTrail( false )
 {
-    startupComplete = false;
-
     TypeName[0] = i18n( "star" );
     TypeName[1] = i18n( "star" );
     TypeName[2] = i18n( "planet" );
@@ -119,10 +117,7 @@
 }
 
 void KStarsData::initialize() {
-    if (startupComplete) return;
-
     QTimer::singleShot(0, this, SLOT( slotInitialize() ) );
-    initCounter = 0;
 }
 
 void KStarsData::initError(const QString &s, bool required = false) {
@@ -147,82 +142,47 @@
                   + i18n( "Otherwise, press Cancel to continue loading without this file.");
         caption = i18n( "Non-Critical File Not Found: %1", s );
     }
-
-    if ( KMessageBox::warningContinueCancel( 0, message, caption, KGuiItem( i18n( "Retry" ) ) ) == KMessageBox::Continue ) {
-        initCounter--;
-        QTimer::singleShot(0, this, SLOT( slotInitialize() ) );
-    } else {
-        if (required) {
-            emit initFinished(false);
-        } else {
-            QTimer::singleShot(0, this, SLOT( slotInitialize() ) );
-        }
-    }
+    // Warn user.
+    int res = KMessageBox::warningContinueCancel( 0, message, caption, KGuiItem(i18n( "Retry" )) );
+    if( required  ||  res != KMessageBox::Continue )
+        qApp->quit();
 }
 
 void KStarsData::slotInitialize() {
 
     qApp->flush(); // flush all paint events before loading data
 
-    switch ( initCounter )
-    {
-    case 0: //Load Time Zone Rules//
-        emit progressText( i18n("Reading time zone rules") );
+    // Load Time Zone Rules
+    emit progressText( i18n("Reading time zone rules") );
+    if( !readTimeZoneRulebook( ) )
+        initError( "TZrules.dat", true );
+    
+    // Load Cities
+    emit progressText( i18n("Loading city data") );
+    if ( !readCityData( ) )
+        initError( "Cities.dat", true );
 
-        // timezone rules
-        if ( !readTimeZoneRulebook( ) )
-            initError( "TZrules.dat", true );
+    //Initialize SkyMapComposite//
+    emit progressText(i18n("Loading sky objects" ) );
+    skyComposite()->init( this );
 
-        break;
+    //Load Image URLs//
+    emit progressText( i18n("Loading Image URLs" ) );
+    if ( !readURLData( "image_url.dat", 0 ) )
+        initError( "image_url.dat", false );
 
-    case 1: //Load Cities//
-        emit progressText( i18n("Loading city data") );
-        if ( !readCityData( ) )
-            initError( "Cities.dat", true );
-        break;
+    //Load Information URLs//
+    emit progressText( i18n("Loading Information URLs" ) );
+    if ( !readURLData( "info_url.dat", 1 ) )
+        initError( "info_url.dat", false );
 
-    case 2: //Initialize SkyMapComposite//
+    emit progressText( i18n("Loading Variable Stars" ) );
+    readINDIHosts();
+    readUserLog();
+    readVARData();
+    readADVTreeData();
 
-        emit progressText(i18n("Loading sky objects" ) );
-        skyComposite()->init( this );
-        break;
-
-    case 3: //Load Image URLs//
-
-        emit progressText( i18n("Loading Image URLs" ) );
-        if ( !readURLData( "image_url.dat", 0 ) ) {
-            initError( "image_url.dat", false );
-        }
-
-        break;
-
-    case 4: //Load Information URLs//
-
-        emit progressText( i18n("Loading Information URLs" ) );
-        if ( !readURLData( "info_url.dat", 1 ) ) {
-            initError( "info_url.dat", false );
-        }
-
-        break;
-
-    case 5:
-        emit progressText( i18n("Loading Variable Stars" ) );
-        readINDIHosts();
-        readUserLog();
-        readVARData();
-        readADVTreeData();
-        break;
-
-    default:
-        startupComplete = true;
-        emit initFinished(true);
-        break;
-    } // switch ( initCounter )
-
-    initCounter++;  // before processEvents!
-    if(!startupComplete)
-        QTimer::singleShot(0, this, SLOT( slotInitialize() ) );
-    qApp->processEvents();
+    emit initFinished(true);
 }
 
 void KStarsData::updateTime( GeoLocation *geo, SkyMap *skymap, const bool automaticDSTchange ) {
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.h #1011898:1011899
@@ -318,8 +318,6 @@
     	*/
     //	void initGuides( KSNumbers *num );
 
-    bool startupComplete;
-
     /*@short Appends telescope sky object to the list of INDI telescope objects. This enables KStars to track all telescopes properly.
     	*@param object pointer to telescope sky object
 
@@ -475,8 +473,6 @@
     KStarsDateTime NextDSTChange;
     KStarsDateTime StoredDate;
 
-    int initCounter;
-
     QString TypeName[18];
 
     //--- Static member variables
--- trunk/KDE/kdeedu/kstars/kstars/main.cpp #1011898:1011899
@@ -102,7 +102,6 @@
         KStarsData *dat = KStarsData::Create();
         QObject::connect( dat, SIGNAL( progressText(QString) ), dat, SLOT( slotConsoleMessage(QString) ) );
         dat->initialize();
-        while (!dat->startupComplete) { qApp->processEvents(); }
 
         //Set Geographic Location
         dat->setLocationFromOptions();


More information about the Kstars-devel mailing list