summaryrefslogtreecommitdiffstats
path: root/kopete/kopete/kconf_update/kopete-pluginloader2.cpp
blob: 42878e68f5c56c03e3afa3729aca51fd352ce6b8 (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
/*
    kconf_update app for migrating the list of loaded plugins in
    kopete 0.7.x to the new KPluginSelector format.

    Copyright (c) 2003      by Martijn Klingens <klingens@kde.org>

    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * This library 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 <textstream.h>
#include <tqregexp.h>

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

void parseKey( const TQString &group, const TQString &key, const TQString &value, const TQString &rawLine )
{
	//qcerr << "*** group='" << group << "'" << endl;
	if ( group.isEmpty() && key == "Plugins" )
	{
		TQStringList plugins = TQStringList::split( ',', value );
		if ( !plugins.isEmpty() )
		{
			qcout << "[Plugins]" << endl;
			for ( TQStringList::Iterator it = plugins.begin(); it != plugins.end(); ++it )
				qcout << "kopete_" << ( *it ).remove( ".desktop" ) << "Enabled=true" << endl;
		}
		qcout << "# DELETE []Plugins" << endl;
	}
	else
	{
		// groups we don't convert. output the raw line instead.
		qcout << rawLine << endl;
	}
}

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

	TQString curGroup;

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

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

		if ( commentRegExp.exactMatch( line ) )
		{
			// We found a comment, leave unchanged
			qcout << line << endl;
		}
		else if ( groupRegExp.exactMatch( line ) )
		{
			// We found the start of a group, leave unchanged
			qcout << line << endl;

			curGroup = groupRegExp.capturedTexts()[ 1 ];
		}
		else if ( keyRegExp.exactMatch( line ) )
		{
			// We found the a key line
			parseKey( curGroup, keyRegExp.capturedTexts()[ 1 ], keyRegExp.capturedTexts()[ 2 ], line );
		}
		else
		{
			qcerr << "** Unknown input line: " << line << endl;
		}
	}

	return 0;
}

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