Directorios editables#

El confinamiento de las aplicaciones es parte del concepto de seguridad de Ubuntu Touch. Se pueden intercambiar datos entre aplicaciones solo de acuerdo con las políticas de «AppArmor», principalmente usando el gestor de contenido. Dicho esto, las aplicaciones solo pueden leer y escribir archivos que están ubicados en alguno de los tres directorios específicos para aplicaciones explicados en esta guía.

Rutas estándar#

Además del acceso de escritura a los directorios de la aplicación explicados más adelante, la aplicación puede escribir mensajes de depuración en el archivo de registro ubicado en /home/phablet/.cache/upstart/application-click-<nombrecompletoaplicación>_<nombreaplicación>_<version>.log. Para agregar mensajes al archivo de registro, use las funciones de depuración de Qt.

Configuración#

Ruta: /home/phablet/.config/<nombrecompletoaplicación>/

Este es el lugar donde guardar los archivos de configuración. La aplicación de música, por ejemplo, guarda su configuración en /home/phablet/.config/com.ubuntu.music/com.ubuntu.music.conf.

Caché#

Ruta: /home/phablet/.cache/<nombrecompletoaplicación>/

Este es el lugar para los datos de la caché que se van a usar más tarde. También la usa el gestor de contenidos. Los archivos que han sido compartidos con la aplicación de música, por ejemplo, se pueden encontrar en /home/phablet/.cache/com.ubuntu.music/HubIncoming/.

Nota

Data in the cache directory should be treated as temporary and the app should still function normally if this directory is cleared - clearing cache is commonly done to recover some space on the device. Don’t store user account info here :)

Datos de la aplicación#

Ruta: /home/phablet/.local/share/<nombrecompletoaplicación>/

Aquí es donde su aplicación guarda cualquier dato. La aplicación de música, por ejemplo, almacena sus bases de datos en /home/phablet/.local/share/com.ubuntu.music/Databases/.

Usando rutas estándar en C++#

The Qt header QStandardPaths provides the app’s writable locations in C++:

#include <QStandardPaths>
...
QString configPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
...

Since the value of the QStandardPaths strings are decided by the Qt application name, this needs to be the same as the clickable application name.

Advertencia

Setting the organizationName will change the paths returned by these functions too - if you need to do this, set it to the clickable application name as well, otherwise the paths won’t work on the device.

Usando rutas estándar en QML#

The Qt module Qt.labs.platform provides the app’s writable locations in QML:

import Qt.labs.platform 1.0
...
Label
{
    text: StandardPaths.writableLocation(StandardPaths.AppConfigLocation)
}
Label
{
    text: StandardPaths.writableLocation(StandardPaths.CacheLocation)
}
Label
{
    text: StandardPaths.writableLocation(StandardPaths.AppDataLocation)
}
...

Notice that QStandardPaths returns paths ('/phablet/home/...'), and QML StandardPaths returns urls ('file:///phablet/home/...'). This must be considered specially if the app is sharing location strings between QML and C++.