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

Jason Harris kstars at 30doradus.org
Thu Dec 20 23:42:11 CET 2007


SVN commit 751026 by harris:

Add "loadColorScheme" to the list of DBUS functions that get parsed by 
KStarsData::executeScript() (which is the function that gets invoked by 
"--script" on the command line, to execute a script when in image dump 
mode).

Also, moved logic about inferring the color-scheme filename from a given 
color scheme name from KStars::loadColorScheme() to ColorScheme::load() 
(because, again, there's no KStars object in image dump mode, and it 
fits better in ColorScheme anyway).

CCMAIL: kstars-devel at kde.org



 M  +27 -4     colorscheme.cpp  
 M  +31 -0     kstarsdata.cpp  
 M  +3 -27     kstarsdcop.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/colorscheme.cpp #751025:751026
@@ -180,19 +180,42 @@
     Palette.insert( key, color );
 }
 
-bool ColorScheme::load( const QString &filename ) {
+bool ColorScheme::load( const QString &name ) {
+    QString filename = name.toLower().trimmed();
     QFile file;
     int inew(0),iold(0);
+    bool ok( false );
 
-    if ( !KSUtils::openDataFile( file, filename ) )
-        return false;
+    //Parse default names which don't follow the regular file-naming scheme
+    if ( name == i18nc("use default color scheme", "Default Colors") ) filename = "classic.colors";
+    if ( name == i18nc("use 'star chart' color scheme", "Star Chart") ) filename = "chart.colors";
+    if ( name == i18nc("use 'night vision' color scheme", "Night Vision") ) filename = "night.colors";
 
+    //Try the filename if it ends with ".colors"
+    if ( filename.endsWith( ".colors" ) )
+        ok = KSUtils::openDataFile( file, filename );
+
+    //If that didn't work, try assuming that 'name' is the color scheme name
+    //convert it to a filename exactly as ColorScheme::save() does
+    if ( ! ok ) {
+        if ( !filename.isEmpty() ) {
+            filename.replace( " ", "-" ).append( ".colors" );
+            ok = KSUtils::openDataFile( file, filename );
+        }
+
+        if ( ! ok ) {
+            kDebug() << i18n( "Unable to load color scheme named %1. Also tried %2.", name, filename );
+            return false;
+        }
+    }
+
+    //If we reach here, the file should have been successfully opened
     QTextStream stream( &file );
     QString line;
 
     //first line is the star-color mode and star color intensity
     line = stream.readLine();
-    bool ok(false);
+    ok = false;
     int newmode = line.left(1).toInt( &ok );
     if ( ok ) setStarColorMode( newmode );
     if ( line.contains(':') ) {
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.cpp #751025:751026
@@ -1081,6 +1081,37 @@
                     cmdCount++;
                 }
 
+            } else if ( fn[0] == "loadColorScheme" ) {
+                fn.removeAll( fn.first() );
+                QString csName = fn.join(" ").replace('\"', "");
+                kDebug() << "Color scheme: " << csName << endl;
+
+                QString filename = csName.toLower().trimmed();
+                bool ok( false );
+
+                //Parse default names which don't follow the regular file-naming scheme
+                if ( csName == i18nc("use default color scheme", "Default Colors") ) filename = "classic.colors";
+                if ( csName == i18nc("use 'star chart' color scheme", "Star Chart") ) filename = "chart.colors";
+                if ( csName == i18nc("use 'night vision' color scheme", "Night Vision") ) filename = "night.colors";
+
+                //Try the filename if it ends with ".colors"
+                if ( filename.endsWith( ".colors" ) )
+                    ok = colorScheme()->load( filename );
+
+                //If that didn't work, try assuming that 'name' is the color scheme name
+                //convert it to a filename exactly as ColorScheme::save() does
+                if ( ! ok ) {
+                    if ( !filename.isEmpty() ) {
+                        for( int i=0; i<filename.length(); ++i)
+                            if ( filename.at(i)==' ' ) filename.replace( i, 1, "-" );
+            
+                        filename = filename.append( ".colors" );
+                        ok = colorScheme()->load( filename );
+                    }
+            
+                    if ( ! ok ) kDebug() << i18n( "Unable to load color scheme named %1. Also tried %2.", csName, filename ) << endl;
+                }
+
             } else if ( fn[0] == "zoom" && fn.size() == 2 ) {
                 bool ok(false);
                 double z = fn[1].toDouble(&ok);
--- trunk/KDE/kdeedu/kstars/kstars/kstarsdcop.cpp #751025:751026
@@ -348,34 +348,10 @@
     }
 }
 
-void KStars::loadColorScheme( const QString &_name ) {
-    QString name( _name );
-    QString filename = name.toLower().trimmed();
-    bool ok( false );
+void KStars::loadColorScheme( const QString &name ) {
+    bool ok = data()->colorScheme()->load( name );
+    QString filename = data()->colorScheme()->fileName();
 
-    //Parse default names which don't follow the regular file-naming scheme
-    if ( name == i18nc("use default color scheme", "Default Colors") ) filename = "classic.colors";
-    if ( name == i18nc("use 'star chart' color scheme", "Star Chart") ) filename = "chart.colors";
-    if ( name == i18nc("use 'night vision' color scheme", "Night Vision") ) filename = "night.colors";
-
-    //Try the filename if it ends with ".colors"
-    if ( filename.endsWith( ".colors" ) )
-        ok = data()->colorScheme()->load( filename );
-
-    //If that didn't work, try assuming that 'name' is the color scheme name
-    //convert it to a filename exactly as ColorScheme::save() does
-    if ( ! ok ) {
-        if ( !filename.isEmpty() ) {
-            for( int i=0; i<filename.length(); ++i)
-                if ( filename.at(i)==' ' ) filename.replace( i, 1, "-" );
-
-            filename = filename.append( ".colors" );
-            ok = data()->colorScheme()->load( filename );
-        }
-
-        if ( ! ok ) kDebug() << i18n( "Unable to load color scheme named %1. Also tried %2.", name, filename );
-    }
-
     if ( ok ) {
         //set the application colors for the Night Vision scheme
         if ( Options::darkAppColors() == false && filename == "night.colors" )  {


More information about the Kstars-devel mailing list