Development/Architecture/KDE3/Standard Resources/pt-br

From KDE TechBase
Revision as of 19:47, 29 August 2014 by Aracele (talk | contribs) (Created page with "* apps - menu de aplicativos (arquivos .desktop) * cgi - CGIs para executar do khelpcenter")


Arquitetura do KDE - Acessando diretórios de recursos padrões

Visão geral

O KDE oferece várias formas de acessar os arquivos que o seu aplicativo instalou no disco rígido do usuário enquanto torna transparente para você onde os dados realmente estão. Para permitir aos usuários (ou administrador, na maioria dos casos) mover arquivos para onde eles se encaixarem melhor, o KDE oferece uma lista de diferentes tipos de recursos para a qual o caminho de pesquisa diferente é atribuído. Você pode ter ouvido sobre a variável de ambiente PATH para procurar executáveis ou MANPATH para procurar man pages (páginas de manuais). Você não esperaria man para procurar man pages em PATH.

Similar a esse conceito o KDE separa caminhos de busca para diferentes coisas para tornar mais simples adicionar caminhos para um recurso específico sem fazer uma procura por outro recurso desnecessário e mais lento e sem exigir de você que coloque tudo em um diretório.

Os tipos de recursos que o KDE oferece são

  • apps - menu de aplicativos (arquivos .desktop)
  • cgi - CGIs para executar do khelpcenter* config - configuration files
  • data - where applications store data* exe - executables installed privatly for KDE's use
  • html - HTML documentation* icon - application icons to appear in the window manager or the panel
  • lib - libraries and to be dlopened modules* locale - translation files for KLocale
  • mime - mime types* sound - application sounds
  • toolbar - toolbar pictures
  • wallpaper - wallpapers

For all of them exist also Makefile aliases that configures created by the development tools provided for KDE (e.g. kdevelop) will know about.

KStandardDirs

This is one of the most central classes in kdelibs as it provides a basic service: it knows where the files reside on the user's harddisk. And it's meant to be the only one that knows - to make the real location as transparent as possible to both the user and the applications.

For this it encapsulates all informations from the application and applications always refer to a file with a resource type (e.g. apps) and a filename (e.g. Home.desktop). In an ideal world the application would make no assumption where this file is and leaves it up to KStandardDirs::findResource("apps", "Home.desktop") to apply this knowledge.

The main idea behind KStandardDirs is that there are several toplevel prefixes where files are below. One of this prefixes is the one where the user installed kdelibs into, one where the application has been installed to and one is $HOME/.kde, but there may be even more. Under these prefixes there are several well defined suffixes where specific resource types are to be found. For example for toolbar icons that is share/toolbar and share/apps/<appname>/pics.

So the search algorithm basicly appends to each prefix each registered suffix and tries to locate the file there. To make the thing even more complex, it's also possible to register absolute paths that KStandardDirs looks up after not finding anything in the former steps. They can be useful if the user wants to provide specific directories that aren't in his $HOME/.kde directory as example for icons.

On the usage of locate and locateLocal

locate and locateLocal are both convenient functions that make the use of KStandardDirs as simple as possible. You have however the possibility to use the full power of KStandardDirs without them.

Typical KDE applications use resource files in one out of three ways:

  • A resource file is read but is never written. A system default is supplied but the user can override this default in his local .kde directory:
// Code example
myFile = locate("appdata", "groups.lst")
myData = myReadGroups(myFile);
  • A resource file is read and written. If the user has no local version of the file the system default is used. The resource file is always written to the users local .kde directory.
// Code example
myFile = locate("appdata", "groups.lst")
myData = myReadGroups(myFile);
...
doSomething(myData);
...
myFile = locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);
  • A resource file is read and written. No system default is used if the user has no local version of the file. The resource file is always written to the users local .kde directory.
// Code example
myFile = locateLocal("appdata", "groups.lst");
myData =  myReadGroups(myFile);
...
doSomething(myData);
...
myFile = locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);

Initial Author: Stephan Kulow ([email protected])