A central de conteúdo - dicas e truques#
No Ubuntu Touch os aplicativos são confinados. A maneira de compartilhar arquivos entre eles é através da Central de Conteúdos (Content Hub), uma parte do sistema que cuida da importação, exportação e compartilhamento de arquivos.
Diferentes formas de compartilhar o conteúdo#
Como podemos ver na documentação da Central de Conteúdos (Content Hub documentation) <https://api-docs.ubports.com/sdk/apps/qml/Ubuntu.Content/ContentHandler.html#detailed-description> _, existem várias maneiras de lidar o arquivo a ser compartilhado:
ContentHandler.Source
(The selected app will provide a file to be imported)ContentHandler.Destination
(The selected app will be the destination for the exported file)ContentHandler.Share
(The selected app will be the destination for the exported file, which will then be shared externally)
Importando#
Examinando o código do Criador de Webapp, encontraremos o código para importar uma imagem para ser usada como ícone. Tocar no espaço reservado abrirá a Central de Conteúdo (Content Hub) que nos permitirá escolher de onde importar a imagem (`consulte o código fonte do Criador de Webapp <https://gitlab.com/cibersheep/webapp-creator/blob/master/webapp- criador / app / ImportPage.qml # L38> `_)
ContentPeerPicker {
anchors { fill: parent; topMargin: picker.header.height }
visible: parent.visible
showTitle: false
contentType: picker.contentType //ContentType.Pictures
handler: picker.handler //ContentHandler.Source
`` ContentPeerPicker`` é o elemento que mostra os aplicativos.
var importPage = mainPageStack.push(Qt.resolvedUrl("ImportPage.qml"),{"contentType": ContentType.Pictures, "handler": ContentHandler.Source})
`` contentType`` é passado em Main.qml <https://gitlab.com/cibersheep/webapp-creator/blob/master/webapp-creator/app/Main.qml#L118> _ como ContentType.Pictures. Então, só veremos aplicativos dos quais só podemos importar imagens. O `` handler`` é passado na mesma linha que o ContentHandler.Source. Como queremos importar uma imagem do aplicativo selecionado na Central de Conteúdo (Content Hub).
Exportando#
Em Gelek, vamos terminar com alguns jogos salvos que queremos salvar em nosso dispositivo ou compartilhar conosco (no Telegram e depois salvá-los em nosso computador).
Tocando no ícone de download, obteremos um Central de Conteúdo (Content Hub) para salvar o arquivo do jogo (que é, na verdade, uma exportação).
The game file is a file of type glksave
. We will tell Content Hub that we are sending a file of type All
(see the Install Page code).
ContentPeerPicker {
anchors { fill: parent; topMargin: picker.header.height }
visible: parent.visible
showTitle: false
contentType: ContentType.All
handler: ContentHandler.Destination
onPeerSelected: {
contentType
is ContentType.All
, so we will only see apps which are able to receive unmarked file types. handler
is ContentHandler.Destination
, so the app selected should store the saved game.
Tapping on the File Manager we will save the saved game in the folder we choose.
Wait a minute. Why the different apps?#
Each developer can decide the rules each app would follow in relation to the Content Hub. Why the OpenStore is shown as the destination of an export?
Let’s check its manifest.json
"hooks": {
"openstore": {
"apparmor": "openstore/openstore.apparmor",
"desktop": "openstore/openstore.desktop",
"urls": "openstore/openstore.url-dispatcher",
"content-hub": "openstore/openstore-contenthub.json"
}
},
The above code defines that the hooks for the app named "openstore"
in relation to the "content-hub"
should follow the rules defined in openstore-contenthub.json
{
"destination": [
"all"
]
}
This means, the OpenStore will be the destination for all ContentTypes
.
What about uMatriks? Let’s see its content-hub.json
{
"destination": [
"pictures",
"documents",
"videos",
"contacts",
"music"
],
"share": [
"pictures",
"documents",
"videos",
"contacts",
"music"
],
"source": [
"pictures",
"documents",
"videos",
"contacts",
"music"
]
}
So, with this example, uMatriks will be able to be the destination, source and share app for all kinds of ContentType
.
What about the other hooks in the manifest.json
? That is discussed in the next guide.