| Line 141: | Line 141: | ||
</code> | </code> | ||
| − | {{Tip|Aplicativos iniciados usando o SSH como esse não provocam o correto lançamento de respostas, então você provavelmente vai querer desativar "feedback de lançamento" para o seu arquivo .desktop}} | + | {{Tip (pt BR)|Aplicativos iniciados usando o SSH como esse não provocam o correto lançamento de respostas, então você provavelmente vai querer desativar "feedback de lançamento" para o seu arquivo .desktop}} |
{{nota|Para criar um arquivo .desktop de um aplicativo do KDE 4 usando esse padrão, o pacote do aplicativo terá que ter sido instalado em <tt>~/kde/bin</tt> usando o comando <tt>cmakekde</tt>}} | {{nota|Para criar um arquivo .desktop de um aplicativo do KDE 4 usando esse padrão, o pacote do aplicativo terá que ter sido instalado em <tt>~/kde/bin</tt> usando o comando <tt>cmakekde</tt>}} | ||
Contents |
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
| Tutorial Series | Começando |
| Previous | Construindo o KDE 4 |
| What's Next | Outros tópicos de desenvolvimento |
| Further Reading | n/a |
| Esta página presume que você tenha construído kdelibs, kdepimlibs, e kdebase de acordo com estas instruções |
|---|
| Nota |
Como você começa o desenvolvimento para o KDE 4, geralmente há três opções disponíveis para você:
As três opções são descritas nas seções seguintes.
|
Se você obter erros ao executar qualquer aplicativo kde4, tais como: Qt: Session management error: Could not open network socket QMutex::lock: Deadlock detected in thread -1241241936 ou quando você executar startkde e ficar emperrado, leia este artigo para a solução. |
|---|
| Nota |
Para este método, é necessária a ferramenta sux (http://fgouget.free.fr/sux/sux-readme.shtml). sux está disponível na maioria das distribuições. De outro modo você pode contar com o método abaixo shell normal sem sux. sux permite que você mude para outro usuário com um gerenciamento implícito dos detalhes de encaminhamento de X (autenticação e exportação de DISPLAY) de uma forma clara e simples.
Fazer o login, tipo sux - kde-devel
Todas as variáveis de ambiente e todo o resto devem ser configurados corretamente pelo seu.bashrc. Para iniciar um aplicativo, basta digitar seu nome; por exemplo kwrite
|
Se você receber erros sobre mimetypes ausentes ou algo parecido, tente o seguinte:
|
|---|
| Nota |
O método mais simples para iniciar aplicativos do KDE 4 é usando su para logar como usuário kde-devel e, em seguida, iniciar qualquer aplicativo do KDE 4 a partir da linha de comando. Fazer o login, tipo
su - kde-devel
e, em seguida, digitar sua senha
export DISPLAY=:0
| A exportação da variável DISPLAY é necessária para que os aplicativos do KDE 4 apareçam normalmente no seu KDE 3 desktop. |
|---|
| Nota |
Todas as variáveis de ambiente e todo o resto devem ser configurados corretamente pelo seu .bashrc. Para iniciar um aplicativo, basta digitar seu nome; por exemplo kwrite
|
Se você receber erros sobre mimetypes ausentes ou algo parecido, tente o seguinte:
|
|---|
| Nota |
A maneira mais simples de executar um aplicativo do KDE 4 com SSH em seu ambiente de trabalho é obter um X-aware shell prompt como um usuário kde-devel como este:
ssh -X kde-devel@localhost
Agora você pode executar aplicativos do KDE apps como de costume, por exemplo:
kwrite
As duas linhas podem ser convenientemente combinadas:
ssh -X kde-devel@localhost kwrite
Antes de fazer qualquer coisa importante usando este método, um login sem senha precisa ser configurado. Para começar, execute o seguinte comando como usuário normal do desktop:
ssh-keygen -t rsa
Aperte enter três vezes para aceitar o caminho de ~/.ssh/id_rsa e uma senha vazia. Agora, copie a única linha no ~/.ssh/id_rsa.pub que é exibida depois da execução deste comando:
cat ~/.ssh/id_rsa.pub
Depois que a linha for copiada, volte ao ssh no usuário kde-devel e coloque-a no arquivo $HOME/.ssh/authorized_keys:
ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \
$HOME/.ssh/authorized_keys
Cole na linha, salve o arquivo, e saia do KWrite.
Em seguida certifique-se de que $HOME/.ssh/authorized_keys tem as permissões corretas:
ssh kde-devel@localhost chmod og-xrw ~kde-devel/.ssh/authorized_keys
Agora tente executar KWrite novamente com o mesmo comando SSH, você não deve mais ter que digitar uma senha:
ssh -X kde-devel@localhost $HOME/kde/bin/kwrite
Se você quiser iniciar os aplicativos de um modo mais fácil que executando-os com um comando SSH a partir da linha de comando, crie um arquivo .desktop para o ssh em outra conta.
| Isso só será útil se o seu ambiente de trabalho suportar arquivos .desktop, pelo menos como fazem KDE e GNOME. |
|---|
| Nota |
Você pode começar com um arquivo .desktop existente como modelo (como um de seu desktop) ou você pode criar um novo. A ideia principal é prefixar o comando a ser executado com esta string:
ssh -X kde-devel@localhost $HOME/kde/bin/
Um simples arquivo .desktop que roda KWrite teria o seguinte conteúdo:
[Desktop Entry]
Categories=Qt;KDE;TextEditor;
Comment=
DocPath=kwrite/index.html
Encoding=UTF-8
Exec=ssh -X kde-devel@localhost /home/kde-devel/kde/bin/kwrite %U
GenericName=Text Editor
Icon=kwrite
InitialPreference=8
MimeType=text/plain
Name=KWrite (kde-devel)
Path=
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-StartupType=Multi
X-DCOP-ServiceType=non
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
| Aplicativos iniciados usando o SSH como esse não provocam o correto lançamento de respostas, então você provavelmente vai querer desativar "feedback de lançamento" para o seu arquivo .desktop |
|---|
| Dica |
| Para criar um arquivo .desktop de um aplicativo do KDE 4 usando esse padrão, o pacote do aplicativo terá que ter sido instalado em ~/kde/bin usando o comando cmakekde |
|---|
| Nota |
Em vez de usar um novo X virtual já desenvolvido para o desenvolvimento de software você pode utilizar o Xephyr para incorporar sua sessão do KDE 4 em sua sessão de trabalho do KDE 3 ou outro ambiente X11.
Você também pode fazer isso com o xnest, mas como xnest não consegue lidar com extensões como Render muitas pessoas preferem Xephyr.
Se você quiser ter uma sessão mínima do KDE instalada e funcionando, apenas inicie Xephyr (disponível no Kubuntu como xserver-xephyr; Usuários do Gentoo compilem x11-base/xorg-server com USE="kdrive"):
Xephyr :1 -extension GLX &
Agora você já pode iniciar o KDE:
su - $USER
export DISPLAY=:1
/path/to/kde4/bin/startkde-modified &
startkde-modified é uma cópia de startkde-script que incluem as seguintes linhas no topo:
export KDEDIR=`kde4-config --prefix`
export LD_LIBRARY_PATH=$KDEDIR/lib
export PATH=$KDEDIR/bin/:$PATH
export KDEHOME=~/.kde4
Você também pode usar Xephyr com KDM através do protocolo Xdmcp e simplesmente uma nova sessão do KDE 4 para KDM.
No Kubuntu, você pode habilitá-lo alterando
[Xdmcp]
Enable=false
em /etc/kde3/kdm/kdmrc para
[Xdmcp]
Enable=true
e ajustar seu /etc/kde3/kdm/Xaccess para permitir seu acesso à máquina local. Além disso, você deve certificar-se de criar uma política de bloqueio de porta em todas as interfaces externas para a porta Xdmcp, se você está fazendo isto em um laptop ou um PC em um ambiente não confiável.
Se você estiver pronto, basta iniciar Xephyr:
Xephyr -query localhost :1 -host-cursor -screen 1024x768&
onde -host-cursor tenta reutilizar o cursor do host e -screen define as dimensões da tela.
Nota: Se você tiver muitos erros de conexão recusada, você pode usar a opção -ac do Xephyr. Por exemplo:
Xephyr -ac :1&
Uma outra opção para tentar caso receba muitos erros de conexão recusada é garantir o acesso do seu usuário kde-devel ao seu servidor X. Como root ou usando sudo:
xhost +local:kde-devel
Se você não tem Xephyr, você pode também usar Xnest:
Xnest -ac :1& export DISPLAY=:1
| This section needs improvements: Please help us to
cleanup confusing sections and fix sections which contain a todo |
Eu uso isso para meu script de inicialização nested_kde4.sh:
#! /bin/bash
NESTED_KDE_DISPLAY_BACKUP=$DISPLAY
export DISPLAY=:0
Xephyr :1 -screen 1024x768 &
export DISPLAY=:1
$HOME/kde/bin/startkde-modified &
export DISPLAY=${NESTED_KDE_DISPLAY_BACKUP}
Se você executar em
"Call to lnusertemp failed (temporary directories full?). Check your installation."
tente isto:
mkdir /var/tmp/kde-devel-kde4
O código acima assume que você trabalha com o usuário kde-devel.
To run a full KDE 4 desktop environment session, you can either start it from the command line as you normally would, with something like this:
X :1 & export DISPLAY=:1 startkde
| Note |
|---|
| If the X server refuses the connection saying something like: Xlib: connection to ":1.0" refused by server, try X -ac :1 instead. |
or you can can add it to your login manager. If you are using KDM (or a compatible login manager) this is done by creating a .desktop file in either `kde-config --prefix`/share/apps/kdm/sessions/ or in /usr/share/xsessions/. The easiest thing to do is to copy an existing kde.desktop file and name it kde4.desktop. Open this new .desktop file in a text editor and change the Exec, TryExec and Name entries to look something like this:
Exec=$HOME/kde/bin/startkde
TryExec=$HOME/kde/bin/startkde
Name=KDE4
Replace $HOME/kde in the example above with the prefix you are installing KDE4 into.
After restarting the login manager (Alt+e in KDM) this new entry should appear in the sessions menu.
You might have to edit your startkde scripts, ie: change
this
kdehome=$HOME/.kde
to this
kdehome=$HOME/.kde4
or paste this
export KDEDIR=`kde4-config --prefix`
export LD_LIBRARY_PATH=$KDEDIR/lib
export PATH=$KDEDIR/bin/:$PATH
export KDEHOME=~/.kde4
on top.
| Note |
|---|
| You should have path to 'qdbus' program (usually it is $QTDIR/bin) in your $PATH to login successfully. If it is not there, you'll get an error message "Could not start DBus. Check your installation." |
This section will explain how to use KDevelop 3.4 to develop KDE 4 applications. If you have any questions, corrections or rants about this section, please post them on the discussion page.
You need at least KDevelop 3.4 for this, which is still a KDE 3 application. Versions lower than 3.4 do not have Qt 4 support among other things. The KDE 4 version of KDevelop is not yet ready for serious development. You can get KDevelop at the KDevelop homepage. Make sure you install KDevelop like all other KDE 3 applications, not with your kde-devel user.
You also need the lastest GDB version, which is currently 6.6.0. Note that the GDB version which is shipped with openSuse 10.3 is broken, it constantly crashes when examining variables (which KDevelop does automatically). Use the GDB version from this repository instead.
You need to have the kdelibs API documentation locally, which is described in the build instructions.
You also need ctags, htdig, htmerge and htsearch. valgrind and callgrind can also be useful.
Be sure you followed the steps in the KDE 4 build instructions and have a working KDE 4 environment. Make sure simple KDE 4 applications like Konsole or KWrite can be started from the command line of the kde-devel user without problems.
The following steps are all done with the kde-devel user. You need to login as that user by typing
su - kde-devel
KDevelop has no native support for CMake projects. Fortunately, CMake has the ability to generate KDevelop project files itself. In order to do this, you need to pass the -GKDevelop3 flag to the cmake command. This tells CMake to generate project files for KDevelop alongside the normal makefiles. The best way to do this is to modify your cmakekde function in your .bashrc. Just change
cmake $srcFolder -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull&& \
make && \
make install;
to
cmake $srcFolder -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull&& \
make && \
make install;
After you have done that, re-login so that the changes to the .bashrc file take effect. Then you need to rerun cmakekde in the (root) build directory of the project you want to work on with KDevelop (if you didn't use -GKDevelop3 on the building step). For example, if you want to work on Konsole, which lives in kdebase, you need to run cmakekde in the $KDE_BUILD/KDE/kdebase directory. This unfortunately completely rebuilds everything, but only once when you change the generator.
Since all environment variables of the kde-devel user are KDE 4 specific, these need to be set back to match your KDE 3 environment before starting KDevelop. A simple way to do this is to add the following function to your .bashrc:
function start3app {
mkdir -p /tmp/$USER-kde export PATH=/opt/kde3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games export LD_LIBRARY_PATH= export KDETMP=/tmp/$USER-kde export KDEVARTMP=/var/tmp/$USER-kde export KDEHOME=$HOME/.kde export KDEDIR=/usr export KDEDIRS=$KDEDIR export DISPLAY=:0 eval "$@" source $HOME/.bashrc #Reset environment variables again
}
The PATH and LD_LIBRARY_PATH variables are taken from the KDE 3 user, and they may be different on your system. Type echo $PATH and echo $LD_LIBRARY_PATH as normal KDE 3 user to get these values. The above function assumes that KDE 3 is installed in the /usr prefix, as it is the case on Debian-based systems. If your KDE 3 is installed to a different prefix, you need to change the line setting KDEDIR accordingly. Here's an example how you find out your KDE installation prefix; in this example it is /opt/kde3:
kde-config --prefix
/opt/kde3
Now you should be able to start KDevelop by typing start3app kdevelop. Do that now.
| Tip |
|---|
| You can start any KDE 3 application with the start3app function. Useful candidates include Kompare and kdesvn. However, you can not start KDbg this way to debug KDE 4 applications, since then the environment variables for the debugged application are wrong. |
Symptome: kdevelop says "cannot talk to klauncher". You cannot open a file.
Solution: add your KDE library path to LD_LIBRARY_PATH, e.g.:
export LD_LIBRARY_PATH=/opt/kde3/lib
Now that KDevelop has started, you need to adjust a few settings. Go to Settings->Configure KDevelop...->Documentation for this. Remove all entries that are not relevant to KDE 4 coding.
| Note |
|---|
| Although environment variables like $HOME are used in this section, you should replace them with real paths because KDevelop does not resolve environment variables. |
Optionally, you can add the kdelibs API documentation. You must create it beforehand. Then add the documentation by clicking Add.... In this dialog, use the following settings:
Now add the Qt API documentation, which also must be created beforehand, using the following settings:
After you have added kdelibs and Qt API documentation, make sure all checkboxes (TOC,Index and Search) are enabled. Then, go to the Full Text Search tab and make sure the paths to the htdig, htmerge and htsearch executables are correct. You can then close the settings dialog.
Now it is time to open the project you want to work on by clicking Project->Open Project.... The project files are located in the build directory. For example, if you want to work on Konsole, you need to open $KDE_BUILD/KDE/kdebase/apps/konsole/konsole.kdevelop. You now need to adjust a few project-specific settings in Project->Project Options. You need to do this every time you start to work on a different project.
| Note |
|---|
| Sometimes, a KDevelop project file is not present for the folder you want to work on.
This can have several reasons, it depends on how the CMake files are written. Usually, CMake files which have a project(projectname) statement in them should work fine. Once you are familiar enough with CMake, you can try adding the statement. A workaround for this is to simply use the KDevelop project file of the parent folder, or even higher. In this case, you need to use the Make Active Directory entry in the context menu of the File Selector sidetab. With this, you can ignore the other unwanted folders when building and installing. |
| Note |
|---|
| The Qt4 PCS Importer is only needed if you didn't install Qt4, i.e. you use it directly from the build directory. The drawback of using the Qt4 importer is that it doesn't show progress and the application seems to hang while it imports. The alternative is to use the Custom Directory PCS Importer for this too |
| Name | Value |
|---|---|
| KDEHOME | $HOME/.kde4 |
| PATH | $KDEDIR/bin:$QTDIR/bin:/usr/local/bin:$PATH |
| LD_LIBRARY_PATH | $KDEDIR/lib:$QTDIR/lib:$LD_LIBRARY_PATH |
| KDETMP | /tmp/$USER-kde4 |
| KDEVARTMP | /var/tmp/$USER-kde4 |
| KDEDIR | $HOME/kde |
| KDEDIRS | $KDEDIR |
| LD_BIND_NOW | 42 |
Now you have finished adjusting your project-specific settings. Now you should remove some plugins you do not need, in Settings->Configure Plugins.... I for example disable the following plugins:
Abbreviation Expansion, Code Snippets, Doxygen Support, Embedded Konsole, File Tree, Final Packaging Support, "Open with" Menu Addon, QuickOpen, Regular Expression Tester, Scripting, Security Checker, Shell Filtering and Insertion, Text Structure and Tools Menu Addition.
You should at least disable the bold ones.
Now, open any source file if none is open already. This will enable the Settings->Configure Editor... entry, where you need to set the tab options to match the tab style used by the project you are working on. The important settings are:
In the mainwindow, click the CTags tab on the bottom tabbar, then click the Regenerate button to create a CTags database for easier source code navigation.
Now you have completed all essential configuration, congratulations!
Refer to the KDevelop manual for general help using KDevelop. The following section will only deal with special cases for KDE 4.
KDE apps have many symbols, which means that you need a lot of memory to get a decent loading times for debugging. To quote a GDB developer: "I would be reluctant to debug KDE on something with <1GB RAM." If the stepping function of the debugger is slow for you, try the following tips:
| Note |
|---|
| KDevelop does not yet support modifing the CMake build system. This means you can not use KDevelop to add or remove files from the project or to change any other aspect of your project's build process. You need to modify the CMake files by hand and then rerun cmakekde instead. Read the CMake tutorial to learn how to do this. |
| Tip |
|---|
| When you work on libraries, you first need to install them before you can test or debug your changes.
Since this is cumbersome and time consuming, you should create symlinks (ln -s) pointing from the build directory to the installation directory for all affected libraries. Often, even simple programs use libraries internally, for example the settings dialog of Konsole is really a library. |
This describes how to use Eclipse to develop KDE 4 applications. It has been tested with Eclipse Ganymed and SUSE Linux 11.1 but should work same or similar with every combination. As an example KDE application we use ktimetracker from the kdepim module, other applications short work analog.
Using this description you will be able to
svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepim
If you want to integrate the cmake build step into your build toolchain, you will need to
cat >/bin/eclipsebuild<<EOF cmake . && make -j4 && make install EOF chmod 777 /bin/eclipsebuild
To revert what eclipse did to your project simply run
rm -rf .externalToolBuilders/ .project .cproject
When using eclipse's svn plugin and building a KDE program, you will get error messages complaining that your svn binary is too old. If you want to try and change this, here's how you get to that error:
This describes how to use QtCreator to develop KDE 4 applications. It has been tested with QtCreator 1.2.80 and SUSE Linux 11.1 but should work same or similar with every combination. As an example KDE application we use ktimetracker from the kdepim module, other applications should work same or similar.
As discussed here we use ktimetracker as example project.
File -> Open -> kdepim/CMakeLists.txt.
Projects -> ktimetracker -> build settings -> Add a configuration ktimetracker.
As build directory choose kdepim. As arguments for cmake use e.g.
. -DCMAKE_INSTALL_PREFIX=/usr/local -DLIB_SUFFIX=64 -DCMAKE_BUILD_TYPE=debugfull
To start a new project you need to tell qtcreator to use the KDE libraries when building. So, choose File -> New... and create your project. We will call it yourproject here. To be able to use KDE's libraries, go to your home directory, cd into yourproject and modify yourproject.pro. Add a line
LIBS += -lkdeui