summaryrefslogtreecommitdiffstats
path: root/src/kconf_update/kdev-gen-settings-kconf_update.cpp
blob: 1f3c97404d8e1083add960fda2d615cae075a1e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
    kconf_update app for migrating kdevelop's ui settings to the new
    code that will be in 3.3.

    Copyright (c) 2005 by Matt Rogers <mattr@kde.org>
    Based on code Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#include <qmap.h>
#include <qtextstream.h>
#include <qregexp.h>

static QTextStream qcin ( stdin,  IO_ReadOnly );
static QTextStream qcout( stdout, IO_WriteOnly );
static QTextStream qcerr( stderr, IO_WriteOnly );

// Group cache. Yes, I know global vars are ugly :)
bool needFlush = false;
QString newKeyValue;
int newDataValue;

void parseKey( const QString &group, const QString &key,
               const QString &value, const QString &rawLine )
{

    //qcerr << "*** group='" << group << "'" << endl;
    if ( group == "General Options" && key == "Embed KDevDesigner")
    {
        newKeyValue = "Designer App";
        if ( value.lower() == "true" )
            newDataValue = 0;
        else
            newDataValue = 2;
        qcout << newKeyValue << "=" << newDataValue << endl;
        qcout << "# DELETE [" << key << "]" << endl;

    }
    else if ( group == "General Options" && key == "Application Font" )
    {
        newKeyValue = "OutputViewFont";
        qcout << newKeyValue << "=" << value << endl;
        qcout << "# DELETE [" << key << "]" << endl;
    }
    else if ( group == "MakeOutputView" && key == "Messages Font" )
    {
        qcout << "# DELETE [" << key << "]" << endl;
    }
    else if ( group == "TerminalEmulator" && key == "UseKDESetting" )
    {
            newKeyValue = "UseKDESetting";
            if ( value.lower() == "true" )
                newDataValue = 0;
            else
                newDataValue = 1;
            qcout << newKeyValue << "=" << newDataValue << endl;
    }
    else
    {
        // keys we don't convert. output the raw line instead.
        qcout << rawLine << endl;
    }
}

int main()
{
    qcin.setEncoding( QTextStream::UnicodeUTF8 );
    qcout.setEncoding( QTextStream::UnicodeUTF8 );

    QString curGroup;

    QRegExp groupRegExp( "^\\[(.*)\\]" );
    QRegExp keyRegExp( "^([a-zA-Z0-9:, _-]*)\\s*=\\s*(.*)\\s*" );
    QRegExp commentRegExp( "^(#.*)?$" );

    while ( !qcin.atEnd() )
    {
        QString line = qcin.readLine();

        if ( commentRegExp.exactMatch( line ) )
        {
            // We found a comment, leave unchanged
            qcout << line << endl;
        }
        else if ( groupRegExp.exactMatch( line ) )
        {
            curGroup = groupRegExp.capturedTexts()[ 1 ];
            qcout << line << endl;
        }
        else if ( keyRegExp.exactMatch( line ) )
        {
            // We found the a key line
            parseKey( curGroup, keyRegExp.capturedTexts()[ 1 ], keyRegExp.capturedTexts()[ 2 ], line );
        }
        else
        {
            qcout << line << endl;
        }
    }

    return 0;
}

// vim: set noet ts=4 sts=4 sw=4: