diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/core/createdcop.py | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/core/createdcop.py')
-rwxr-xr-x | krita/core/createdcop.py | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/krita/core/createdcop.py b/krita/core/createdcop.py new file mode 100755 index 00000000..b3395ea2 --- /dev/null +++ b/krita/core/createdcop.py @@ -0,0 +1,171 @@ +#!/usr/bin/env python + +import os, sys + +dcopiface_header = """/* This file is part of the KDE project + * Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef %(classname_upper)sIFACE_H +#define %(classname_upper)sIFACE_H + +#include <dcopref.h> +#include <dcopobj.h> + +#include <qstring.h> + +class %(classname)s; + +class %(classname)sIface : virtual public DCOPObject +{ + K_DCOP +public: + %(classname)sIface( %(classname)s * parent ); +k_dcop: + +private: + + %(classname)s *m_parent; +}; + +#endif +""" + +dcopiface_template = """/* + * This file is part of the KDE project + * + * Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include <kapplication.h> + + +#include "%(ifaceheader)s" + +#include "%(classheader)s" + +#include <dcopclient.h> + +%(classname)sIface::%(classname)sIface( %(classname)s * parent ) + : DCOPObject() +{ + m_parent = parent; +} + +""" + +def parseHeader(headerfile, classname): + # parse the source class header to get a list of functions we're going to wrap + functions = [] + if (headerfile.find("private:") > -1): + lines = headerfile[headerfile.find(classname):headerfile.find("private")].splitlines() + else: + lines = headerfile[headerfile.find(classname):headerfile.find("#endif")].splitlines() + i = 0 + while i < len(lines): + line = lines[i].strip() + if (line.startswith("/") or + line.startswith("public:") or + line.startswith("*") or + line.startswith(classname) or + line.startswith("class") or + line.startswith("Q_OBJECT") or + line.startswith("#") or + line.startswith("}") or + line.startswith("public slots:") or + line.find("~") != -1 or + len(line) == 0 + ): + i+=1 + continue + if (line.startswith("protected")): + return functions + # by now we are reasonable sure that this is a function. We need to find the end of the function definition, and then + # if the return type is not primitive, replace it with dcopref. + function = line + complete = 0 + # strip the inline implementation + if (line.find("{") > -1): + function = line[:line.find("{")] + if function.find("}") > -1: + function += line[line.find("}") + 1:] + complete = 1 + else: + i += 1 + # search for the missing } on the next lines + while i < len(lines): + if (lines[i].find("}") > -1): + function += lines[i][lines[i].find("}") + 1:] + complete = 1 + i += 1 + else: + complete = 1 + + if complete == 0: + i+=1 + continue + + if (function.endswith("= 0;")): + function = function[:-4] + ";" + print "\t", function + i+=1 + + +def createDCOP(header): + + # Determine filenames and classnames + + implementation = header[:-1] + "cc" + classname = "" + classname_upper ="_" + for part in header[:-2].split("_"): + classname = classname + part.capitalize() + classname_upper = classname_upper + part.upper() + "_" + ifaceheader = header[:-2] + "_iface.h" + ifaceimplementation = header[:-2] + "_iface.cc" + ifaceclass = classname + "Iface" + + #print "with: ", implementation, classname, classname_upper, ifaceheader, ifaceimplementation, ifaceclass + file(ifaceheader, "w+").write(dcopiface_header % { "classname_upper" : classname_upper, + "classname" : classname}) + file(ifaceimplementation, "w+").write(dcopiface_template % {"ifaceheader" : ifaceheader, + "classheader" : header, + "classname" : classname }) + functions = parseHeader(open(header).read(), classname) + +def main(args): + for line in args[1:]: + print "Going to create a dcop interface for:", line[:-1] + createDCOP(line.strip()) + +if __name__=="__main__": + main(sys.argv) + + |