• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeinit
 

tdeinit

  • tdeinit
tdestartupconfig.cpp
1/****************************************************************************
2
3 Copyright (C) 2005 Lubos Lunak <l.lunak@kde.org>
4
5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the "Software"),
7to deal in the Software without restriction, including without limitation
8the rights to use, copy, modify, merge, publish, distribute, sublicense,
9and/or sell copies of the Software, and to permit persons to whom the
10Software is furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21DEALINGS IN THE SOFTWARE.
22
23****************************************************************************/
24
25/*
26
27This utility helps to have some configuration options available in starttde
28without the need to launch anything linked to KDE libraries (which may need
29some time to load).
30
31The configuration options are written to $TDEHOME/share/config/startupconfigkeys,
32one option per line, as <file> <group> <key> <default>. It is possible to
33use ' for quoting multiword entries. Values of these options will be written
34to $TDEHOME/share/config/startupconfig as a shell script that will set
35the values to shell variables, named <file>_<group>_<key> (all spaces replaced
36by underscores, everything lowercase). So e.g. line
37"ksplashrc KSplash Theme Default" may result in "ksplashrc_ksplash_theme=Default".
38
39In 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.
41It is not possible to specify default values, but since the configuration options
42are processed in the order they are specified this can be solved by first
43specifying a group and then all the entries that need default values.
44
45When a tdeconf_update script is used to update such option, tdestartupconfig is run
46before tdeconf_update and therefore cannot see the change in time. To avoid this
47problem, together with the tdeconf_update script also the matching global config
48file should be updated (any change, tdestartupconfig will see the timestamp change).
49
50Note that the kdeglobals config file is not used as a depedendency for other config
51files.
52
53Since the checking is timestamp-based, config files that are frequently updated
54should not be used.
55
56Kstartupconfig works by storing every line from startupconfigkeys in file startupconfigfiles
57followed by paths of all files that are relevant to the option. Non-existent files
58have '!' prepended (for the case they'll be later created), the list of files is
59terminated by line containing '*'. If the timestamps of all relevant files are older
60than the timestamp of the startupconfigfile file, there's no need to update anything.
61Otherwise tdedostartupconfig is launched to create or update all the necessary files
62(which already requires loading KDE libraries, but this case should be rare).
63
64*/
65
66#include <config.h>
67
68#include <sys/types.h>
69#include <sys/stat.h>
70#include <sys/wait.h>
71#include <unistd.h>
72#include <stdio.h>
73#include <string.h>
74#include <stdlib.h>
75
76int main()
77 {
78 char tdehome[ 1024 ];
79 if( getenv( "TDEHOME" ))
80 strlcpy( tdehome, getenv( "TDEHOME" ), 1024 );
81 else if( getenv( "HOME" ))
82 {
83 strlcpy( tdehome, getenv( "HOME" ), 1024 );
84 strlcat( tdehome, "/.trinity", 1024 );
85 }
86 else
87 return 1;
88 char filename[ 1024 ];
89 strlcpy( filename, tdehome, 1024 );
90 strlcat( filename, "/share/config/startupconfig", 1024 );
91 if( access( filename, R_OK ) != 0 )
92 {
93 int ret = system( "tdedostartupconfig" );
94 return WEXITSTATUS( ret );
95 }
96 strlcpy( filename, tdehome, 1024 );
97 strlcat( filename, "/share/config/startupconfigfiles", 1024 );
98 struct stat st;
99 if( stat( filename, &st ) != 0 )
100 {
101 int ret = system( "tdedostartupconfig" );
102 return WEXITSTATUS( ret );
103 }
104 time_t config_time = st.st_mtime;
105 FILE* config = fopen( filename, "r" );
106 if( config == NULL )
107 {
108 int ret = system( "tdedostartupconfig" );
109 return WEXITSTATUS( ret );
110 }
111 strlcpy( filename, tdehome, 1024 );
112 strlcat( filename, "/share/config/startupconfigkeys", 1024 );
113 FILE* keys = fopen( filename, "r" );
114 if( keys == NULL )
115 {
116 fclose( config );
117 return 2;
118 }
119 bool need_update = true;
120 for(;;)
121 {
122 char keyline[ 1024 ];
123 if( fgets( keyline, 1023, keys ) == NULL )
124 {
125 need_update = false;
126 break;
127 }
128 if( char* nl = strchr( keyline, '\n' ))
129 *nl = '\0';
130 char line[ 1024 ];
131 if( fgets( line, 1023, config ) == NULL )
132 break;
133 if( char* nl = strchr( line, '\n' ))
134 *nl = '\0';
135 if( strcmp( keyline, line ) != 0 )
136 break;
137 bool ok = false;
138 for(;;)
139 {
140 if( fgets( line, 1023, config ) == NULL )
141 break;
142 if( char* nl = strchr( line, '\n' ))
143 *nl = '\0';
144 if( *line == '\0' )
145 break;
146 if( *line == '*' )
147 {
148 ok = true;
149 break;
150 }
151 if( *line == '!' )
152 {
153 if( access( line + 1, R_OK ) == 0 )
154 break; // file now exists -> update
155 }
156 else
157 {
158 struct stat st;
159 if( stat( line, &st ) != 0 )
160 break;
161 if( st.st_mtime > config_time )
162 break;
163 }
164 }
165 if( !ok )
166 break;
167 }
168 fclose( keys );
169 fclose( config );
170 if( need_update )
171 {
172 int ret = system( "tdedostartupconfig" );
173 return WEXITSTATUS( ret );
174 }
175 return 0;
176 }

tdeinit

Skip menu "tdeinit"
  • Main Page
  • File List
  • Related Pages

tdeinit

Skip menu "tdeinit"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeinit by doxygen 1.9.4
This website is maintained by Timothy Pearson.