1
/****************************************************************************
3
Copyright (C) 2005 Lubos Lunak <l.lunak@kde.org>
5
Permission is hereby granted, free of charge, to any person obtaining a
6
copy of this software and associated documentation files (the "Software"),
7
to deal in the Software without restriction, including without limitation
8
the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
and/or sell copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
DEALINGS IN THE SOFTWARE.
23
****************************************************************************/
27
This utility helps to have some configuration options available in startkde
28
without the need to launch anything linked to KDE libraries (which may need
31
The configuration options are written to $KDEHOME/share/config/startupconfigkeys,
32
one option per line, as <file> <group> <key> <default>. It is possible to
33
use ' for quoting multiword entries. Values of these options will be written
34
to $KDEHOME/share/config/startupconfig as a shell script that will set
35
the values to shell variables, named <file>_<group>_<key> (all spaces replaced
36
by underscores, everything lowercase). So e.g. line
37
"ksplashrc KSplash Theme Default" may result in "ksplashrc_ksplash_theme=Default".
39
In order to real a whole group it is possible to use <file> <[group]>, e.g.
40
"ksplashrc [KSplash]", which will set shell variables for all keys in the group.
41
It is not possible to specify default values, but since the configuration options
42
are processed in the order they are specified this can be solved by first
43
specifying a group and then all the entries that need default values.
45
When a kconf_update script is used to update such option, kstartupconfig is run
46
before kconf_update and therefore cannot see the change in time. To avoid this
47
problem, together with the kconf_update script also the matching global config
48
file should be updated (any change, kstartupconfig will see the timestamp change).
50
Note that the kdeglobals config file is not used as a depedendency for other config
53
Since the checking is timestamp-based, config files that are frequently updated
56
Kstartupconfig works by storing every line from startupconfigkeys in file startupconfigfiles
57
followed by paths of all files that are relevant to the option. Non-existent files
58
have '!' prepended (for the case they'll be later created), the list of files is
59
terminated by line containing '*'. If the timestamps of all relevant files are older
60
than the timestamp of the startupconfigfile file, there's no need to update anything.
61
Otherwise kdostartupconfig is launched to create or update all the necessary files
62
(which already requires loading KDE libraries, but this case should be rare).
68
#include <config-workspace.h>
70
#include <sys/types.h>
85
char filename[ 1024 ];
87
if( getenv( "KDEHOME" ))
88
strlcpy( kdehome, getenv( "KDEHOME" ), 1024 );
89
else if( getenv( "HOME" ))
91
strlcpy( kdehome, getenv( "HOME" ), 1024 );
92
strlcat( kdehome, "/" KDE_DEFAULT_HOME, 1024 );
96
strlcpy( filename, kdehome, 1024 );
97
strlcat( filename, "/share/config/startupconfig", 1024 );
98
if( access( filename, R_OK ) != 0 )
100
strlcpy( filename, kdehome, 1024 );
101
strlcat( filename, "/share/config/startupconfigfiles", 1024 );
102
if( stat( filename, &st ) != 0 )
104
config_time = st.st_mtime;
105
config = fopen( filename, "r" );
108
strlcpy( filename, kdehome, 1024 );
109
strlcat( filename, "/share/config/startupconfigkeys", 1024 );
110
keys = fopen( filename, "r" );
116
char keyline[ 1024 ];
119
if( fgets( keyline, 1023, keys ) == NULL )
121
if( (nl = strchr( keyline, '\n' )) )
123
if( fgets( line, 1023, config ) == NULL )
125
if( (nl = strchr( line, '\n' )) )
127
if( strcmp( keyline, line ) != 0 )
131
if( fgets( line, 1023, config ) == NULL )
133
if( (nl = strchr( line, '\n' )) )
141
if( access( line + 1, R_OK ) == 0 )
142
goto doit2; /* file now exists -> update */
146
if( stat( line, &st ) != 0 )
148
if( st.st_mtime > config_time )
157
return WEXITSTATUS( system( "kdostartupconfig4" ) );