• 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 
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:
11 
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14 
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.
22 
23 ****************************************************************************/
24 
25 /*
26 
27 This utility helps to have some configuration options available in starttde
28 without the need to launch anything linked to KDE libraries (which may need
29 some time to load).
30 
31 The configuration options are written to $TDEHOME/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 $TDEHOME/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".
38 
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.
44 
45 When a tdeconf_update script is used to update such option, tdestartupconfig is run
46 before tdeconf_update and therefore cannot see the change in time. To avoid this
47 problem, together with the tdeconf_update script also the matching global config
48 file should be updated (any change, tdestartupconfig will see the timestamp change).
49 
50 Note that the kdeglobals config file is not used as a depedendency for other config
51 files.
52 
53 Since the checking is timestamp-based, config files that are frequently updated
54 should not be used.
55 
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 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 
76 int 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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeinit by doxygen 1.8.8
This website is maintained by Timothy Pearson.