内容中心 - 提示和技巧#
在 Ubuntu Touch 上的应用程序是有限的。它们之间共享文件的方式是通过内容中心来负责文件导入、导出和共享系统的一部分。
分享内容的不同方式#
正如我们在 内容中心文档 中看到的,有几种方法可以处理要共享的文件:
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)
导入#
查看网页应用开发者的代码,我们将会找到代码导入要用作图标的图像。点击所有者将打开内容中心,让我们选择从何处导入图像 (参见网络应用开发者的源代码)
ContentPeerPicker {
anchors { fill: parent; topMargin: picker.header.height }
visible: parent.visible
showTitle: false
contentType: picker.contentType //ContentType.Pictures
handler: picker.handler //ContentHandler.Source
ContentPeerPicker
是用于显示应用的元素。
var importPage = mainPageStack.push(Qt.resolvedUrl("ImportPage.qml"),{"contentType": ContentType.Pictures, "handler": ContentHandler.Source})
contentType
is passed in Main.qml as ContentType.Pictures. So, we will only see apps from which we only can import images. handler
is passed in the same line as ContentHandler.Source. As we want to import an image from the app selected in the Content Hub.
导出#
在 Gelek 中,我们将结束一些保存的游戏,这些游戏我们希望保存在我们的设备中或与我们自己分享(在 Telegram 上,然后将其保存到我们的电脑里)。
点击下载图标,我们将得到一个内容中心来 保存 游戏文件(实际上是一次导出)。
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.