Development/Tutorials/KDE4 Porting Guide (de): Difference between revisions

    From KDE TechBase
    Line 77: Line 77:


    ==D-Bus==
    ==D-Bus==
    Instead of DCOP in KDE3, KDE4 now uses D-Bus for its interprocess communication. Porting from DCOP to D-Bus is a large topic that is covered in great detail in the [[Development/Tutorials/Porting_to_D-Bus|Porting to D-Bus tutorial]].
    Statt DCOP, wie es in KDE3 benutzt wird, kommt in KDE4 nun D-Bus für die Kommunikation zwischen Prozessen (interprocess communication) zum Einsatz. Die Portierung von DCOP nach D-BUS ist ein großes Thema, welches im Detail in der Anleitung [[Development/Tutorials/Porting_to_D-Bus|Porting to D-Bus]] (in englisch) beschrieben wird.


    For more information, please see all our [[Development/Tutorials#D-Bus|D-Bus tutorials]].
    Für mehr Informationen sehen Sie bitte auch [[Development/Tutorials#D-Bus|D-Bus tutorials]].


    ==Icons==
    ==Icons==

    Revision as of 21:03, 27 November 2007


    Development/Tutorials/KDE4_Porting_Guide


    Einführung

    Diese Anleitung richtet sich an Entwickler, die ihre Qt3/KDE3 basierten Applikationen nach Qt4/KDE4 portieren wollen. Das muß nämlich kein komplizierter Prozess sein. Es gibt bereits viele Skripte und Dokumentationen, die dabei helfen.

    Konventionen

    Für die Anweisungen dieser Anleitung gelten folgende Konventionen:

    • program bezeichnet ein ausführbares Programm
    • path bezeichnet einen Pfad
    • file bezeichnet eine Datei
    • $SVN ist der vollständige Pfad zu Ihrem KDE subversion depot.

    CMake

    Anders als KDE4 werden KDE4 Applikationen mit der Hilfe von CMake erstellt. Der einfachste Weg die autotools Dateien nach CMake zu portieren ist, das Script am2cmake zu benutzen, welches im Verzeichnis cmake/scripts des kdesdk Modules zu finden ist. Das erzeugt eine Reihe von CMakeLists.txt Dateien neben den alten autotools Dateien.

    Ist Ihr Code zum Beispiel unter /path/to/src gespeichert, dann: % cd /path/to/src % $SVN/trunk/KDE/kdesdk/cmake/scripts/am2cmake --kde4 Führen Sie am2cmake --help aus, um zu prüfen, ob Sie das --kde4 Flag benötigen.

    Weiterhin gibt es ein Werkzeug, welches in den erzeugten CMakeList.txt Dateien nach möglichen Problemen sucht. Dieses Werkzeugt heißt cmakelint.pl und ist unter$SVN/trunk/kde/kdesdk/scripts gespeichert. Benutzen Sie es folgendermaßen: % cd /path/to/src % $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl CMakeLists.txt Oder wenden Sie es auf das gesamte Quellcodevrzeichnis an: % cd /path/to/src % find . -name CMakeLists.txt | \

     xargs $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl
    

    Qt4 API

    Einen Überblick über den Übergang von Qt3 nach Qt4 wird in der Anleitung "Moving from Qt 3 to Qt 4" von Trolltech erläutert. Dieses Dokument bietet einen sehr guter Überblick über die Änderungen in der Funktionalität, die Qt4 mit sich bring und ist daher sehr zu empfehlen.

    Die nachfolgende Anleitung "Porting to Qt 4" gibt eine sehr detailierte Beschreibung des Portierungsprozesses, neben einer Liste von Änderungen in den Klassen und Funktionen.

    Diese Dokumente beschreiben auch ein Werkzeug, das von Trolltech zur Verfügung gestellt wird und sich qt3to4 nennt. Dieses Programm kann dabei helfen, die Qt Teile Ihres Codes von Qt3 nach Qt4 zu portieren, indem es spezielle Funktionen zur Kompatibilität benutzt. Rufen Sie qt3to4 folgendermaßen auf: % $SVN/trunk/qt-copy/bin/qt3to4 [options] <Infile>, [Infile], ... Infile kann eine Quellcodedatei oder eine Projektdatei sein. Möchten Sie eine Projektdatei angeben (mit der Endung '.pro' oder '.pri'), qt3to4 wird alle Dateien portieren, die in dieser Datei angegeben sind.

    Für mehr Informationen können Sie qt3to4 mit der "--help" Option aufrufen oder unter "qt3to4-The Qt 3 to 4 Porting Tool" nachschlagen.

    Weiterhin gibt es ein Programm namens remove-qt3-support.pl im Modul kdesdk, welches nach vielen veralteten Qt3 Strukturen sucht und diese ersetzt. Rufen Sie einfach dieses Programm ohne weitere Optionen im Quellverzeichnis auf. % $SVN/trunk/KDE/kdesdk/scripts/qt4/remove-qt3-support.pl

    KDE4 API

    Ein Großteil der Arbeit beim Portieren besteht einfach aus dem umbenennen von Klassen und Header-Dateien. Da es ziemlich ermüdend ist, dies von Hand zu machen, gibt es ein nützliches Script im scripts/qt4 Verzeichnis des Modules kdesdk namens adapt-to-kde4-api.pl. Dieses scant alle Ihre Dateien und erzeugt eine diff Ausgabe, die dann benutzt werden kann, um Ihren Code zu patchen.

    Wenn diese einfache Codeersetzung erledigt ist, müssen Sie trotzdem noch Ihren zu portierenden Code nachbearbeiten, zum Beispiel wegen der neuen KAction API. Über alle API Änderungen informiert Sie die Datei KDE4PORTING.html des Modules kdelibs.

    Qt Designer UI Dateien

    Qt designer ".ui" files created using Qt3 must be converted to the new Qt4 format. This can be done using the uic3 program available from your Qt4 installation.

    % $SVN/trunk/qt-copy/bin/uic3 -convert file.ui > foo.ui % mv foo.ui file.ui

    Or, if you prefer a graphical tool, you can use Qt4's designer program

    % $SVN/trunk/qt-copy/bin/designer file.ui (you can save file.ui over top itself, or save to a new file)

    Warning
    Beware, the conversion process loses any custom slots, table columns, etc. So, you may need to put some stuff back by hand.

    You should also run the fixuifiles program from the kdesdk module, it performs cleanups and sanify checks: % $SVN/trunk/KDE/kdesdk/scripts/fixuifiles

    D-Bus

    Statt DCOP, wie es in KDE3 benutzt wird, kommt in KDE4 nun D-Bus für die Kommunikation zwischen Prozessen (interprocess communication) zum Einsatz. Die Portierung von DCOP nach D-BUS ist ein großes Thema, welches im Detail in der Anleitung Porting to D-Bus (in englisch) beschrieben wird.

    Für mehr Informationen sehen Sie bitte auch D-Bus tutorials.

    Icons

    KDE4 uses the freedesktop.org icon naming specification as the basis for icon names. This means that both the icons that ship with KDE4 (Oxygen) as well as components in kdelibs that use icons follow this specification.

    Porting your app from the icon names used in KDE3 to the ones used in KDE4 is as easy as running the adapt-to-icon-spec.py script from the root directory of your project and follow the instructions on screen.

    The script automatically converts confirmable positives (e.g. uses of KIcon or KIconLoader), skips confirmable negatives and prompts for what to do with possible positives. It shows the latter with additonal context if desired and makes it a simple matter of pressing 'y' or 'n' for the possible hits to complete the porting.

    Internationalization

    To create your ".pot" file, copy the commands from the 'messages' rule in your projects Makefile.am to a shell script called Messages.sh. You may assume the same variables ($PREPARETIPS, $XGETTEXT, $podir, etc.) still exist, but keep in mind the differences between Makefile and shell script syntax.

    Also be careful that if you use the -k parameter with $XGETTEXT, you will need to explicitely list all variants that you use.

    For example, the 'messages' creation rule: messages: rc.cpp

           rm -f tips.cpp
           $(PREPARETIPS) > tips.cpp
           $(XGETTEXT) -ktranslate *.cpp *.h -o $(podir)/kmail.pot
           rm -f tips.cpp
    

    becomes the following Messages.sh script:

    1. ! /usr/bin/env bash

    $PREPARETIPS > tips.cpp $XGETTEXT -ktranslate:1,1t -ktranslate:1c,2,2t *.cpp *.h -o $podir/kmail.pot rm -f tips.cpp

    Do's und Don'ts

    • Do NOT use the old-style socket classes.
    • Do NOT use QPtrList, and in general, setAutoDelete()
    • Do NOT make use of raster operations.
    • Do NOT do code painting on widgets outside paint events.
    • Try not to use QHBox, QVBox, QGrid. Prefer layouts instead.
    • Do NOT play with frames of groupboxes, labels, or lineedits to fake a different widget. Use the appropriate widget instead. e.g., instead of setting a label to have a sunken lineedit border, how about using a readonly KLineEdit instead? And instead of using a KLineEdit without a border for a copyable widget, use KActiveLabel.
    • Do NOT use a groupbox without border to group widgets! Just use a layout.

    Mehr Informationen

    Dokumentation

    Weitere Hilfe

    • #kde4-devel on irc.freenode.net