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>
81 if( getenv( "KDEHOME" ))
82 strlcpy( kdehome
, getenv( "KDEHOME" ), 1024 );
83 else if( getenv( "HOME" ))
85 strlcpy( kdehome
, getenv( "HOME" ), 1024 );
86 strlcat( kdehome
, "/" KDE_DEFAULT_HOME
, 1024 );
90 char filename
[ 1024 ];
91 strlcpy( filename
, kdehome
, 1024 );
92 strlcat( filename
, "/share/config/startupconfig", 1024 );
93 if( access( filename
, R_OK
) != 0 )
95 int ret
= system( "kdostartupconfig4" );
96 return WEXITSTATUS( ret
);
98 strlcpy( filename
, kdehome
, 1024 );
99 strlcat( filename
, "/share/config/startupconfigfiles", 1024 );
101 if( stat( filename
, &st
) != 0 )
103 int ret
= system( "kdostartupconfig4" );
104 return WEXITSTATUS( ret
);
106 time_t config_time
= st
.st_mtime
;
107 FILE* config
= fopen( filename
, "r" );
110 int ret
= system( "kdostartupconfig4" );
111 return WEXITSTATUS( ret
);
113 strlcpy( filename
, kdehome
, 1024 );
114 strlcat( filename
, "/share/config/startupconfigkeys", 1024 );
115 FILE* keys
= fopen( filename
, "r" );
121 bool need_update
= true;
124 char keyline
[ 1024 ];
125 if( fgets( keyline
, 1023, keys
) == NULL
)
130 if( char* nl
= strchr( keyline
, '\n' ))
133 if( fgets( line
, 1023, config
) == NULL
)
135 if( char* nl
= strchr( line
, '\n' ))
137 if( strcmp( keyline
, line
) != 0 )
142 if( fgets( line
, 1023, config
) == NULL
)
144 if( char* nl
= strchr( line
, '\n' ))
155 if( access( line
+ 1, R_OK
) == 0 )
156 break; // file now exists -> update
161 if( stat( line
, &st
) != 0 )
163 if( st
.st_mtime
> config_time
)
174 int ret
= system( "kdostartupconfig4" );
175 return WEXITSTATUS( ret
);