25 #undef TQT_NO_CAST_ASCII
30 #include <tqtextstream.h>
31 #include <kinstance.h>
32 #include <kstandarddirs.h>
33 #include <tdeconfig.h>
36 TQString get_entry( TQString* ll )
39 l = l.stripWhiteSpace();
41 return TQString::null;
46 while( pos < l.length() && l[ pos ] !=
'\'' )
48 if( pos >= l.length())
51 return TQString::null;
53 *ll = l.mid( pos + 1 );
57 while( pos < l.length() && l[ pos ] !=
' ' )
65 TDEInstance inst(
"tdedostartupconfig" );
66 kdDebug() <<
"Running tdedostartupconfig." << endl;
67 TQString keysname = locateLocal(
"config",
"startupconfigkeys" );
68 TQFile keys( keysname );
69 if( !keys.open( IO_ReadOnly ))
71 TQFile f1( locateLocal(
"config",
"startupconfig" ));
72 if( !f1.open( IO_WriteOnly ))
74 TQFile f2( locateLocal(
"config",
"startupconfigfiles" ));
75 if( !f2.open( IO_WriteOnly ))
77 TQTextStream startupconfig( &f1 );
78 TQTextStream startupconfigfiles( &f2 );
79 startupconfig <<
"#! /bin/sh\n";
83 if( keys.readLine( line, 1024 ) < 0 )
85 line = line.stripWhiteSpace();
89 TQString file, group, key, def;
90 file = get_entry( &tmp );
91 group = get_entry( &tmp );
92 key = get_entry( &tmp );
93 def = get_entry( &tmp );
94 if( file.isEmpty() || group.isEmpty())
96 if( group.left( 1 ) ==
"[" && group.right( 1 ) ==
"]" )
98 TDEConfig cfg( file );
99 group = group.mid( 1, group.length() - 2 );
100 TQMap< TQString, TQString > entries = cfg.entryMap( group );
101 startupconfig <<
"# " << line <<
"\n";
102 for( TQMap< TQString, TQString >::ConstIterator it = entries.begin();
106 TQString key = it.key();
107 TQString value = *it;
108 startupconfig << TQString(file.replace(
' ',
'_' )).lower()
109 <<
"_" << TQString(group.replace(
' ',
'_' )).lower()
110 <<
"_" << TQString(key.replace(
' ',
'_' )).lower()
111 <<
"=\"" << value.replace(
"\"",
"\\\"" ) <<
"\"\n";
118 TDEConfig cfg( file );
119 cfg.setGroup( group );
120 TQString value = cfg.readEntry( key, def );
121 startupconfig <<
"# " << line <<
"\n";
122 startupconfig << TQString(file.replace(
' ',
'_' )).lower()
123 <<
"_" << TQString(group.replace(
' ',
'_' )).lower()
124 <<
"_" <<TQString( key.replace(
' ',
'_' )).lower()
125 <<
"=\"" << value.replace(
"\"",
"\\\"" ) <<
"\"\n";
127 startupconfigfiles << line << endl;
129 TQStringList dirs = TQStringList::split( KPATH_SEPARATOR, TDEGlobal::dirs()->kfsstnd_prefixes());
130 for( TQStringList::ConstIterator it = dirs.begin();
134 TQString cfg = *it +
"share/config/" + file;
135 if( TDEStandardDirs::exists( cfg ))
136 startupconfigfiles << cfg <<
"\n";
138 startupconfigfiles <<
"!" << cfg <<
"\n";
140 startupconfigfiles <<
"*\n";