~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to src/kconf_update/kdev-gen-settings-kconf_update.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    kconf_update app for migrating kdevelop's ui settings to the new
 
3
    code that will be in 3.3.
 
4
 
 
5
    Copyright (c) 2005 by Matt Rogers <mattr@kde.org>
 
6
    Based on code Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
 
7
 
 
8
    *************************************************************************
 
9
    *                                                                       *
 
10
    * This program is free software; you can redistribute it and/or         *
 
11
    * modify it under the terms of the GNU Lesser General Public            *
 
12
    * License as published by the Free Software Foundation; either          *
 
13
    * version 2 of the License, or (at your option) any later version.      *
 
14
    *                                                                       *
 
15
    *************************************************************************
 
16
*/
 
17
 
 
18
#include <qmap.h>
 
19
#include <qtextstream.h>
 
20
#include <qregexp.h>
 
21
 
 
22
static QTextStream qcin ( stdin,  IO_ReadOnly );
 
23
static QTextStream qcout( stdout, IO_WriteOnly );
 
24
static QTextStream qcerr( stderr, IO_WriteOnly );
 
25
 
 
26
// Group cache. Yes, I know global vars are ugly :)
 
27
bool needFlush = false;
 
28
QString newKeyValue;
 
29
int newDataValue;
 
30
 
 
31
void parseKey( const QString &group, const QString &key,
 
32
               const QString &value, const QString &rawLine )
 
33
{
 
34
 
 
35
    //qcerr << "*** group='" << group << "'" << endl;
 
36
    if ( group == "General Options" && key == "Embed KDevDesigner")
 
37
    {
 
38
        newKeyValue = "Designer App";
 
39
        if ( value.lower() == "true" )
 
40
            newDataValue = 0;
 
41
        else
 
42
            newDataValue = 2;
 
43
        qcout << newKeyValue << "=" << newDataValue << endl;
 
44
        qcout << "# DELETE [" << key << "]" << endl;
 
45
 
 
46
    }
 
47
    else if ( group == "General Options" && key == "Application Font" )
 
48
    {
 
49
        newKeyValue = "OutputViewFont";
 
50
        qcout << newKeyValue << "=" << value << endl;
 
51
        qcout << "# DELETE [" << key << "]" << endl;
 
52
    }
 
53
    else if ( group == "MakeOutputView" && key == "Messages Font" )
 
54
    {
 
55
        qcout << "# DELETE [" << key << "]" << endl;
 
56
    }
 
57
    else if ( group == "TerminalEmulator" && key == "UseKDESetting" )
 
58
    {
 
59
            newKeyValue = "UseKDESetting";
 
60
            if ( value.lower() == "true" )
 
61
                newDataValue = 0;
 
62
            else
 
63
                newDataValue = 1;
 
64
            qcout << newKeyValue << "=" << newDataValue << endl;
 
65
    }
 
66
    else
 
67
    {
 
68
        // keys we don't convert. output the raw line instead.
 
69
        qcout << rawLine << endl;
 
70
    }
 
71
}
 
72
 
 
73
int main()
 
74
{
 
75
    qcin.setEncoding( QTextStream::UnicodeUTF8 );
 
76
    qcout.setEncoding( QTextStream::UnicodeUTF8 );
 
77
 
 
78
    QString curGroup;
 
79
 
 
80
    QRegExp groupRegExp( "^\\[(.*)\\]" );
 
81
    QRegExp keyRegExp( "^([a-zA-Z0-9:, _-]*)\\s*=\\s*(.*)\\s*" );
 
82
    QRegExp commentRegExp( "^(#.*)?$" );
 
83
 
 
84
    while ( !qcin.atEnd() )
 
85
    {
 
86
        QString line = qcin.readLine();
 
87
 
 
88
        if ( commentRegExp.exactMatch( line ) )
 
89
        {
 
90
            // We found a comment, leave unchanged
 
91
            qcout << line << endl;
 
92
        }
 
93
        else if ( groupRegExp.exactMatch( line ) )
 
94
        {
 
95
            curGroup = groupRegExp.capturedTexts()[ 1 ];
 
96
            qcout << line << endl;
 
97
        }
 
98
        else if ( keyRegExp.exactMatch( line ) )
 
99
        {
 
100
            // We found the a key line
 
101
            parseKey( curGroup, keyRegExp.capturedTexts()[ 1 ], keyRegExp.capturedTexts()[ 2 ], line );
 
102
        }
 
103
        else
 
104
        {
 
105
            qcout << line << endl;
 
106
        }
 
107
    }
 
108
 
 
109
    return 0;
 
110
}
 
111
 
 
112
// vim: set noet ts=4 sts=4 sw=4:
 
113