KInit
kdostartupconfig.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #undef QT_NO_CAST_ASCII
00026
00027
00028
00029 #include <qfile.h>
00030 #include <qtextstream.h>
00031 #include <kinstance.h>
00032 #include <kstandarddirs.h>
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035
00036 QString get_entry( QString* ll )
00037 {
00038 QString& l = *ll;
00039 l = l.stripWhiteSpace();
00040 if( l.isEmpty())
00041 return QString::null;
00042 QString ret;
00043 if( l[ 0 ] == '\'' )
00044 {
00045 unsigned int pos = 1;
00046 while( pos < l.length() && l[ pos ] != '\'' )
00047 ret += l[ pos++ ];
00048 if( pos >= l.length())
00049 {
00050 *ll = QString::null;
00051 return QString::null;
00052 }
00053 *ll = l.mid( pos + 1 );
00054 return ret;
00055 }
00056 unsigned int pos = 0;
00057 while( pos < l.length() && l[ pos ] != ' ' )
00058 ret += l[ pos++ ];
00059 *ll = l.mid( pos );
00060 return ret;
00061 }
00062
00063 int main()
00064 {
00065 KInstance inst( "kdostartupconfig" );
00066 kdDebug() << "Running kdostartupconfig." << endl;
00067 QString keysname = locateLocal( "config", "startupconfigkeys" );
00068 QFile keys( keysname );
00069 if( !keys.open( IO_ReadOnly ))
00070 return 3;
00071 QFile f1( locateLocal( "config", "startupconfig" ));
00072 if( !f1.open( IO_WriteOnly ))
00073 return 4;
00074 QFile f2( locateLocal( "config", "startupconfigfiles" ));
00075 if( !f2.open( IO_WriteOnly ))
00076 return 5;
00077 QTextStream startupconfig( &f1 );
00078 QTextStream startupconfigfiles( &f2 );
00079 startupconfig << "#! /bin/sh\n";
00080 for(;;)
00081 {
00082 QString line;
00083 if( keys.readLine( line, 1024 ) < 0 )
00084 break;
00085 line = line.stripWhiteSpace();
00086 if( line.isEmpty())
00087 break;
00088 QString tmp = line;
00089 QString file, group, key, def;
00090 file = get_entry( &tmp );
00091 group = get_entry( &tmp );
00092 key = get_entry( &tmp );
00093 def = get_entry( &tmp );
00094 if( file.isEmpty() || group.isEmpty())
00095 return 6;
00096 if( group.left( 1 ) == "[" && group.right( 1 ) == "]" )
00097 {
00098 KConfig cfg( file );
00099 group = group.mid( 1, group.length() - 2 );
00100 QMap< QString, QString > entries = cfg.entryMap( group );
00101 startupconfig << "# " << line << "\n";
00102 for( QMap< QString, QString >::ConstIterator it = entries.begin();
00103 it != entries.end();
00104 ++it )
00105 {
00106 QString key = it.key();
00107 QString value = *it;
00108 startupconfig << file.replace( ' ', '_' ).lower()
00109 << "_" << group.replace( ' ', '_' ).lower()
00110 << "_" << key.replace( ' ', '_' ).lower()
00111 << "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
00112 }
00113 }
00114 else
00115 {
00116 if( key.isEmpty())
00117 return 7;
00118 KConfig cfg( file );
00119 cfg.setGroup( group );
00120 QString value = cfg.readEntry( key, def );
00121 startupconfig << "# " << line << "\n";
00122 startupconfig << file.replace( ' ', '_' ).lower()
00123 << "_" << group.replace( ' ', '_' ).lower()
00124 << "_" << key.replace( ' ', '_' ).lower()
00125 << "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
00126 }
00127 startupconfigfiles << line << endl;
00128
00129 QStringList dirs = QStringList::split( KPATH_SEPARATOR, KGlobal::dirs()->kfsstnd_prefixes());
00130 for( QStringList::ConstIterator it = dirs.begin();
00131 it != dirs.end();
00132 ++it )
00133 {
00134 QString cfg = *it + "share/config/" + file;
00135 if( KStandardDirs::exists( cfg ))
00136 startupconfigfiles << cfg << "\n";
00137 else
00138 startupconfigfiles << "!" << cfg << "\n";
00139 }
00140 startupconfigfiles << "*\n";
00141 }
00142 return 0;
00143 }