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

    From KDE TechBase
    (Tästä se lähtee..)
     
    No edit summary
     
    (12 intermediate revisions by 3 users not shown)
    Line 1: Line 1:
    {{Template:I18n/Language Navigation Bar|Development/Tutorials/KDE4_Porting_Guide}}
     


    ==Esipuhe==
    ==Esipuhe==
    Tämä perehdytys on tarkoitettu ohjelmistokehittäjille auttaakseen heitä siirtämään heidän Qt3/KDE3 ohjelmistonsa Qt4/KDE4 ympäristöön. KDE3 ohjelmien siirron ei välttämättä tarvitse olla hankala prosessi. On olemassa valmiina monia komentojonoja ja dokumentaatio lähteitä tämän helpottamiseksi.
    Tämä ohje tarkoitettu ohjelmistokehittäjille auttamaan heitä siirtämään Qt3/KDE3 -ohjelmisto Qt4/KDE4-ympäristöön. KDE3-ohjelmien siirron ei välttämättä tarvitse olla hankala prosessi. On olemassa valmiina monia komentojonoja ja dokumentaatiolähteitä, jotka helpottavat tätä siirtoa.


    ==Conventions==
    ==Käsitteet==
    For the instructions in this tutorial we use the following shorthand:
    Tämän perehdytyksen ohjeissa käytetään seuraavia käsitteitä:
    * {{program|program}} refers to an executable program
    * {{program|program}} kuvaa suoritettavaa tiedostoa, ohjelmaa
    * {{path|path}} refers to a path
    * {{path|path}} kuvaa polkua
    * {{path|file}} refers to a file
    * {{path|file}} kuvaa tiedostoa
    * $SVN is the fullpath to the location of your KDE subversion checkout
    * $SVN on täydellinen polku paikalliseen kopioon KDE:n SVN kopiosta


    ==CMake==
    ==CMake==
    Unlike KDE3, KDE4 applications will be built with the help of [[Development/Tutorials/CMake | CMake]]. The easiest way to port your autotools system to CMake is with the help of the {{program|am2cmake}} script which can be found in the {{path|cmake/scripts}} directory of the [http://websvn.kde.org/trunk/KDE/kdesdk/ kdesdk] module. This will create a series of {{path|CMakeLists.txt}} files alongside your old buildsystem files.
    KDE3-ohjelmista poiketen KDE4-ohjelmat käännetään [[Development/Tutorials/CMake (fi)| CMakea]] apuna käyttäen. Helpoin tapa siirtää "autotools system" CMakelle on käyttää apuna {{program|am2cmake}}-komentojonoa joka löytyy [http://websvn.kde.org/trunk/KDE/kdesdk/ kdesdk] moduulin alta {{path|cmake/scripts}}-hakemistosta. {{program|am2cmake}} luo vanhan käännösjärjestelmän tiedostojen määrästä riippuen joukon {{path|CMakeLists.txt}}-tiedostoja.


    For example, if your source code is located in {{path|/path/to/src}} then:
    Esimerkiksi jos lähdekoodisi sijaitsee {{path|/path/to/src}}-hakemistossa, niin:
    <code bash>
    <syntaxhighlight lang="bash">
    % cd /path/to/src
    % cd /path/to/src
    % $SVN/trunk/KDE/kdesdk/cmake/scripts/am2cmake --kde4
    % $SVN/trunk/KDE/kdesdk/cmake/scripts/am2cmake --kde4
    </code>
    </syntaxhighlight>
    Run <tt> am2cmake --help</tt> to check whether you need the <tt>--kde4</tt> flag.
    Suorita <tt> am2cmake --help</tt> tarkistaaksesi tarvitsetko <tt>--kde4</tt> valitsinta.


    There is also a tool that looks in your resulting {{path|CMakeList.txt}} files for potential problems.  This tool called {{program|cmakelint.pl}} is located in {{path|$SVN/trunk/kde/kdesdk/scripts}}. Use it like so:
    Samasta {{path|$SVN/trunk/kde/kdesdk/scripts}}-hakemistosta löytyy myös {{program|cmakelint.pl}}-niminen työkalu, jolla voit tarkistaa uusien {{path|CMakeList.txt}}-tiedostojen mahdolliset ongelmat. Käyttö:
    <code bash>
    <syntaxhighlight lang="bash">
    % cd /path/to/src
    % cd /path/to/src
    % $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl CMakeLists.txt
    % $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl CMakeLists.txt
    </code>
    </syntaxhighlight>
    Or, to run it over your entire source directory:
    Tai, jos tarkistat kaikki {{path|CMakeLists.txt}} lähdekoodi hakemistostasi:
    <code bash>
    <syntaxhighlight lang="bash">
    % cd /path/to/src
    % cd /path/to/src
    % find . -name CMakeLists.txt | \
    % find . -name CMakeLists.txt | \
       xargs $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl
       xargs $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl
    </code>
    </syntaxhighlight>


    ==Qt4 API==
    ==Qt4 API==
    An overview of the Qt3 to Qt4 transition is provided in Trolltech's
    [http://www.trolltech.com/products/qt/whatsnew/porting "Moving from Qt 3 to Qt 4"] paper.  This document provides an excellent overview into the major functionality changes with Qt4 and is highly recommended.


    The follow-on [http://doc.trolltech.com/latest/porting4.html "Porting to Qt 4"] page gives an amazingly detailed description of the porting process, along with a list of the changes in the classes and functions.
    Aluksi on erittäin suositeltavaa tutustua Trolltech:n tuottamaan [http://www.trolltech.com/products/qt/whatsnew/porting "Moving from Qt 3 to Qt 4"]-dokumenttiin, josta löytyy erittäin hyvä yleiskatsaus suuremmista muutoksista siirryttäessä Qt3:sta Qt4:n.
     
    Seuraavana löytyy [http://doc.trolltech.com/latest/porting4.html "Porting to Qt 4"]-dokumentti, jossa on kerrottu hyvin yksityiskohtaisesti siirrosprosessista. Sivustossa on yksityiskohtaisesti listattu luokkien ja funktioiden muutokset.


    These documents describe a tool provided by Trolltech called {{program|qt3to4}} that can help port the Qt parts of your code from Qt3 to Qt4, using compatibility functions. Run {{program|qt3to4}} as follows:
    Näissä dokumenteissa on esitelty Trolltechin tuottama työkalu nimeltä {{program|qt3to4}}, joka on tarkoitettu yhteensopivuus funktioita apuna käyttäen helpottamaan koodin Qt-osuuksien siirtämistä Qt3:sta Qt4:n. Käytä {{program|qt3to4}} seuraavasti:
    <code bash>
    <syntaxhighlight lang="bash">
    % $SVN/trunk/qt-copy/bin/qt3to4 [options] <Infile>, [Infile], ...
    % $SVN/trunk/qt-copy/bin/qt3to4 [options] <Infile>, [Infile], ...
    </code>
    </syntaxhighlight>
    Infile can be a source file or a project file. If you specify a project file, ending with '.pro' or '.pri', {{program|qt3to4}} will port all files specified in that project.
    Infile voi olla joko lähdekooditiedosto tai projektitiedosto. Jos käytät projektitiedostoa, pääte joko '.pro' tai '.pri', {{program|qt3to4}} käy läpi kaikki tiedostot, jotka kuuluvat projektiin.


    For more information, run {{program|qt3to4}} with the "--help" option or visit
    Lisätietoja saat suorittamalla komennon {{program|qt3to4}} '--help' valitsimen kanssa tai tutustumalla sivuun [http://doc.trolltech.com/latest/qt3to4.html "qt3to4-The Qt 3 to 4 Porting Tool"].
    the [http://doc.trolltech.com/latest/qt3to4.html "qt3to4-The Qt 3 to 4 Porting Tool"] page.


    Additionally, there is a program called {{program|remove-qt3-support.pl}} in the {{module|kdesdk}} module that will search and replace lots of deprecated Qt3 stuff for you. Simply run this program without any options in the source directory.
    Lisäksi {{module|kdesdk}}-moduulissa on työkalu nimeltä {{program|remove-qt3-support.pl}}. Se etsii ja korvaa suuren osan vanhentuneita Qt3-asioita puolestasi. Aja tämä työkalu ilman valitsimia lähdekoodihakemistossasi:
    <code bash>
    <syntaxhighlight lang="bash">
    % $SVN/trunk/KDE/kdesdk/scripts/qt4/remove-qt3-support.pl
    % $SVN/trunk/KDE/kdesdk/scripts/qt4/remove-qt3-support.pl
    </code>
    </syntaxhighlight>


    Chances are that some Qt3 classes will still remain in the code, so make sure your top-level CMakeLists.txt file defines the QT3_SUPPORT and QT3_SUPPORT_WARNINGS macros for the Qt headers, like so:
    Koska on mahdollista, että joitain Qt3 luokkia jää vielä koodiin, varmista että lähdekoodihakemistosi juuren CMakeLists.txt tiedostossa on määritelty sekä QT3_SUPPORT että QT3_SUPPORT_WARNINGS -makrot Qt-otsikkotiedostoille. Esim:
    <code>
    <syntaxhighlight lang="text">
    add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
    add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
    </code>
    </syntaxhighlight>


    ==KDE4 API==
    ==KDE4 API==
    Line 66: Line 65:
    Qt designer ".ui" files created using Qt3 must be converted to the new Qt4 format.  This can be done using the {{program|uic3}} program available from your Qt4 installation.
    Qt designer ".ui" files created using Qt3 must be converted to the new Qt4 format.  This can be done using the {{program|uic3}} program available from your Qt4 installation.


    <code bash>
    <syntaxhighlight lang="bash">
    % $SVN/trunk/qt-copy/bin/uic3 -convert file.ui > foo.ui
    % $SVN/trunk/qt-copy/bin/uic3 -convert file.ui > foo.ui
    % mv foo.ui file.ui
    % mv foo.ui file.ui
    </code>
    </syntaxhighlight>


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


    <code bash>
    <syntaxhighlight lang="bash">
    % $SVN/trunk/qt-copy/bin/designer file.ui
    % $SVN/trunk/qt-copy/bin/designer file.ui
    (you can save file.ui over top itself, or save to a new file)
    (you can save file.ui over top itself, or save to a new file)
    </code>
    </syntaxhighlight>
    {{Warning|Beware, the conversion process loses any custom slots, table columns, etc.  So, you may need to put some stuff back by hand.}}
    {{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 {{program|fixuifiles}} program from the {{module|kdesdk}} module, it performs cleanups and sanity checks:
    You should also run the {{program|fixuifiles}} program from the {{module|kdesdk}} module, it performs cleanups and sanity checks:
    <code bash>
    <syntaxhighlight lang="bash">
    % $SVN/trunk/KDE/kdesdk/scripts/fixuifiles
    % $SVN/trunk/KDE/kdesdk/scripts/fixuifiles
    </code>
    </syntaxhighlight>


    ==D-Bus==
    ==D-Bus==
    Line 101: Line 100:


    For example, the 'messages' creation rule:
    For example, the 'messages' creation rule:
    <code>
    <syntaxhighlight lang="text">
    messages: rc.cpp
    messages: rc.cpp
             rm -f tips.cpp
             rm -f tips.cpp
    Line 107: Line 106:
             $(XGETTEXT) -ktranslate *.cpp *.h -o $(podir)/kmail.pot
             $(XGETTEXT) -ktranslate *.cpp *.h -o $(podir)/kmail.pot
             rm -f tips.cpp
             rm -f tips.cpp
    </code>
    </syntaxhighlight>
    becomes the following {{path|Messages.sh}} script:
    becomes the following {{path|Messages.sh}} script:
    <code bash>
    <syntaxhighlight lang="bash">
    #! /usr/bin/env bash
    #! /usr/bin/env bash
    $PREPARETIPS > tips.cpp
    $PREPARETIPS > tips.cpp
    $XGETTEXT -ktranslate:1,1t -ktranslate:1c,2,2t *.cpp *.h -o $podir/kmail.pot
    $XGETTEXT -ktranslate:1,1t -ktranslate:1c,2,2t *.cpp *.h -o $podir/kmail.pot
    rm -f tips.cpp
    rm -f tips.cpp
    </code>
    </syntaxhighlight>


    ==Do's and Don'ts==   
    ==Do's and Don'ts==   

    Latest revision as of 09:52, 15 July 2012


    Esipuhe

    Tämä ohje tarkoitettu ohjelmistokehittäjille auttamaan heitä siirtämään Qt3/KDE3 -ohjelmisto Qt4/KDE4-ympäristöön. KDE3-ohjelmien siirron ei välttämättä tarvitse olla hankala prosessi. On olemassa valmiina monia komentojonoja ja dokumentaatiolähteitä, jotka helpottavat tätä siirtoa.

    Käsitteet

    Tämän perehdytyksen ohjeissa käytetään seuraavia käsitteitä:

    • program kuvaa suoritettavaa tiedostoa, ohjelmaa
    • path kuvaa polkua
    • file kuvaa tiedostoa
    • $SVN on täydellinen polku paikalliseen kopioon KDE:n SVN kopiosta

    CMake

    KDE3-ohjelmista poiketen KDE4-ohjelmat käännetään CMakea apuna käyttäen. Helpoin tapa siirtää "autotools system" CMakelle on käyttää apuna am2cmake-komentojonoa joka löytyy kdesdk moduulin alta cmake/scripts-hakemistosta. am2cmake luo vanhan käännösjärjestelmän tiedostojen määrästä riippuen joukon CMakeLists.txt-tiedostoja.

    Esimerkiksi jos lähdekoodisi sijaitsee /path/to/src-hakemistossa, niin:

    % cd /path/to/src
    % $SVN/trunk/KDE/kdesdk/cmake/scripts/am2cmake --kde4
    

    Suorita am2cmake --help tarkistaaksesi tarvitsetko --kde4 valitsinta.

    Samasta $SVN/trunk/kde/kdesdk/scripts-hakemistosta löytyy myös cmakelint.pl-niminen työkalu, jolla voit tarkistaa uusien CMakeList.txt-tiedostojen mahdolliset ongelmat. Käyttö:

    % cd /path/to/src
    % $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl CMakeLists.txt
    

    Tai, jos tarkistat kaikki CMakeLists.txt lähdekoodi hakemistostasi:

    % cd /path/to/src
    % find . -name CMakeLists.txt | \
      xargs $SVN/trunk/KDE/kdesdk/scripts/cmakelint.pl
    

    Qt4 API

    Aluksi on erittäin suositeltavaa tutustua Trolltech:n tuottamaan "Moving from Qt 3 to Qt 4"-dokumenttiin, josta löytyy erittäin hyvä yleiskatsaus suuremmista muutoksista siirryttäessä Qt3:sta Qt4:n.

    Seuraavana löytyy "Porting to Qt 4"-dokumentti, jossa on kerrottu hyvin yksityiskohtaisesti siirrosprosessista. Sivustossa on yksityiskohtaisesti listattu luokkien ja funktioiden muutokset.

    Näissä dokumenteissa on esitelty Trolltechin tuottama työkalu nimeltä qt3to4, joka on tarkoitettu yhteensopivuus funktioita apuna käyttäen helpottamaan koodin Qt-osuuksien siirtämistä Qt3:sta Qt4:n. Käytä qt3to4 seuraavasti:

    % $SVN/trunk/qt-copy/bin/qt3to4 [options] <Infile>, [Infile], ...
    

    Infile voi olla joko lähdekooditiedosto tai projektitiedosto. Jos käytät projektitiedostoa, pääte joko '.pro' tai '.pri', qt3to4 käy läpi kaikki tiedostot, jotka kuuluvat projektiin.

    Lisätietoja saat suorittamalla komennon qt3to4 '--help' valitsimen kanssa tai tutustumalla sivuun "qt3to4-The Qt 3 to 4 Porting Tool".

    Lisäksi kdesdk-moduulissa on työkalu nimeltä remove-qt3-support.pl. Se etsii ja korvaa suuren osan vanhentuneita Qt3-asioita puolestasi. Aja tämä työkalu ilman valitsimia lähdekoodihakemistossasi:

    % $SVN/trunk/KDE/kdesdk/scripts/qt4/remove-qt3-support.pl
    

    Koska on mahdollista, että joitain Qt3 luokkia jää vielä koodiin, varmista että lähdekoodihakemistosi juuren CMakeLists.txt tiedostossa on määritelty sekä QT3_SUPPORT että QT3_SUPPORT_WARNINGS -makrot Qt-otsikkotiedostoille. Esim:

    add_definitions (-DQT3_SUPPORT -DQT3_SUPPORT_WARNINGS)
    

    KDE4 API

    Much of the porting effort consists of simply renaming class names and header files. Since it would be rather tedious to change all these by hand, there is a handy script in the scripts/qt4 directory of kdesdk called adapt-to-kde4-api.pl. This will scan all your files and create a diff output which can then be used to patch your code.

    Once that simple code substitution has been done, you will still have to go through your code to port to, for example, the new KAction API. Documentation about all API changes is kept in the KDE4PORTING.html file in the kdelibs module.

    Qt Designer UI Files

    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 sanity checks:

    % $SVN/trunk/KDE/kdesdk/scripts/fixuifiles
    

    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 Porting to D-Bus tutorial.

    For more information, please see all our 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 explicitly 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:

    #! /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 and 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.

    Resources

    Documentation

    Other Help

    • #kde4-devel on irc.freenode.net