3
# Copyright David Faure <faure@kde.org>, License LGPL v2
5
# This script converts a kde3 screensaver to kde4, adapting it to the change
6
# of API in libkscreensaver.
8
# If the input file could be parsed correctly (i.e. it had extern "C" and kss_* symbols),
9
# then this script will *overwrite* it with the result of the conversion.
10
# Make backups first, if you don't use a version control system.
12
# Usage: change those two lines before running the script
14
filename = 'pendulum.cpp'
15
savername = 'KPendulumSaver' # Interface is appended to this string.
18
f = file(filename, 'r')
20
lines = data.split('\n')
21
externCRe = re.compile('^\s*extern "C"')
22
appNameRe = re.compile('.*kss_applicationName\s*=\s*(".*")')
23
descriptionRe = re.compile('.*kss_description\s*=\s*(.*);')
24
versionRe = re.compile('.*kss_version\s*=\s*(.*);')
33
if (line[0:2] == '//'):
34
outputlines.append(line)
37
if (externCRe.match(line)):
39
if (line.find('{') >= 0):
40
braceLevel = braceLevel+1
41
outputlines.append(line.replace('extern "C"', 'class ' + savername + 'Interface : public KScreenSaverInterface'))
43
outputlines.append(line)
45
if (line.find('{') >= 0):
46
braceLevel = braceLevel+1
47
if (line.find('}') >= 0):
48
braceLevel = braceLevel-1
49
match = appNameRe.match(line)
51
appName = match.group(1)
53
match = descriptionRe.match(line)
55
description = match.group(1)
57
match = versionRe.match(line)
59
version = match.group(1)
61
if appName and description and version and not aboutDataWritten:
62
outputlines.append( "public:" )
63
outputlines.append( " virtual KAboutData* aboutData() {" )
64
outputlines.append( " return new KAboutData( " + appName + ", " + description + ", " + version + ", " + description + " );" )
65
outputlines.append( " }" )
68
line = re.sub('KDE_EXPORT\s*','',line)
69
line = re.sub('KScreenSaver\s*\*\s*kss_create','virtual KScreenSaver* create',line)
70
line = re.sub('QDialog\s*\*\s*kss_setup','virtual QDialog* setup',line)
72
outputlines.append( '};' )
73
outputlines.append( '' )
74
outputlines.append( 'int main( int argc, char *argv[] )' )
75
outputlines.append( '{' )
76
outputlines.append( ' ' + savername + 'Interface kss;' )
77
outputlines.append( ' return kScreenSaverMain( argc, argv, kss );' )
78
outputlines.append( '}' )
81
outputlines.append( line )
83
if not aboutDataWritten:
85
print 'appName=' + appName
86
print 'description=' + description
87
print 'version=' + version
89
open(filename,"w").write(string.join(outputlines, '\n'))
90
os.system('svn di ' + filename)