• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KInit

kdostartupconfig.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  Copyright (C) 2005 Lubos Lunak        <l.lunak@kde.org>
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a
00006 copy of this software and associated documentation files (the "Software"),
00007 to deal in the Software without restriction, including without limitation
00008 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009 and/or sell copies of the Software, and to permit persons to whom the
00010 Software is furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00018 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00021 DEALINGS IN THE SOFTWARE.
00022 
00023 ****************************************************************************/
00024 
00025 #undef QT_NO_CAST_ASCII
00026 
00027 // See description in kstartupconfig.cpp .
00028 
00029 #include <qfile.h>
00030 #include <qtextstream.h>
00031 #include <kinstance.h>
00032 #include <kstandarddirs.h>
00033 #include <kconfig.h>
00034 #include <kdebug.h>
00035 
00036 QString get_entry( QString* ll )
00037     {
00038     QString& l = *ll;
00039     l = l.stripWhiteSpace();
00040     if( l.isEmpty())
00041         return QString::null;
00042     QString ret;
00043     if( l[ 0 ] == '\'' )
00044         {
00045         unsigned int pos = 1;
00046         while( pos < l.length() && l[ pos ] != '\'' )
00047             ret += l[ pos++ ];
00048         if( pos >= l.length())
00049             {
00050             *ll = QString::null;
00051             return QString::null;
00052             }
00053         *ll = l.mid( pos + 1 );
00054         return ret;
00055         }
00056     unsigned int pos = 0;
00057     while( pos < l.length() && l[ pos ] != ' ' )
00058         ret += l[ pos++ ];
00059     *ll = l.mid( pos );
00060     return ret;
00061     }
00062 
00063 int main()
00064     {
00065     KInstance inst( "kdostartupconfig" );
00066     kdDebug() << "Running kdostartupconfig." << endl;
00067     QString keysname = locateLocal( "config", "startupconfigkeys" );
00068     QFile keys( keysname );
00069     if( !keys.open( IO_ReadOnly ))
00070         return 3;
00071     QFile f1( locateLocal( "config", "startupconfig" ));
00072     if( !f1.open( IO_WriteOnly ))
00073         return 4;
00074     QFile f2( locateLocal( "config", "startupconfigfiles" ));
00075     if( !f2.open( IO_WriteOnly ))
00076         return 5;
00077     QTextStream startupconfig( &f1 );
00078     QTextStream startupconfigfiles( &f2 );
00079     startupconfig << "#! /bin/sh\n";
00080     for(;;)
00081         {
00082         QString line;
00083         if( keys.readLine( line, 1024 ) < 0 )
00084             break;
00085         line = line.stripWhiteSpace();
00086         if( line.isEmpty())
00087             break;
00088         QString tmp = line;
00089         QString file, group, key, def;
00090         file = get_entry( &tmp );
00091         group = get_entry( &tmp );
00092         key = get_entry( &tmp );
00093         def = get_entry( &tmp );
00094         if( file.isEmpty() || group.isEmpty())
00095             return 6;
00096         if( group.left( 1 ) == "[" && group.right( 1 ) == "]" )
00097             { // whole config group
00098             KConfig cfg( file );
00099             group = group.mid( 1, group.length() - 2 );
00100             QMap< QString, QString > entries = cfg.entryMap( group );
00101             startupconfig << "# " << line << "\n";
00102             for( QMap< QString, QString >::ConstIterator it = entries.begin();
00103                  it != entries.end();
00104                  ++it )
00105                 {
00106                 QString key = it.key();
00107                 QString value = *it;
00108                 startupconfig << file.replace( ' ', '_' ).lower()
00109                     << "_" << group.replace( ' ', '_' ).lower()
00110                     << "_" << key.replace( ' ', '_' ).lower()
00111                     << "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
00112                 }
00113             }
00114         else
00115             { // a single key
00116             if( key.isEmpty())
00117                 return 7;
00118             KConfig cfg( file );
00119             cfg.setGroup( group );
00120             QString value = cfg.readEntry( key, def );
00121             startupconfig << "# " << line << "\n";
00122             startupconfig << file.replace( ' ', '_' ).lower()
00123                 << "_" << group.replace( ' ', '_' ).lower()
00124                 << "_" << key.replace( ' ', '_' ).lower()
00125                 << "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
00126             }
00127         startupconfigfiles << line << endl;
00128         // use even currently non-existing paths in $KDEDIRS
00129         QStringList dirs = QStringList::split( KPATH_SEPARATOR, KGlobal::dirs()->kfsstnd_prefixes());
00130         for( QStringList::ConstIterator it = dirs.begin();
00131              it != dirs.end();
00132              ++it )
00133             {
00134             QString cfg = *it + "share/config/" + file;
00135             if( KStandardDirs::exists( cfg ))
00136                 startupconfigfiles << cfg << "\n";
00137             else
00138                 startupconfigfiles << "!" << cfg << "\n";
00139             }
00140         startupconfigfiles << "*\n";
00141         }
00142     return 0;
00143     }

KInit

Skip menu "KInit"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal