summaryrefslogtreecommitdiff
path: root/transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@jolla.com>2026-02-12 15:13:50 +0100
committerAndrew Branson <andrew.branson@jolla.com>2026-02-12 15:45:59 +0100
commit7e10e89d72cc3a2b5eb314aa76c340793e5e26dd (patch)
tree7de1130148126ad29a75ec83166b4812440ca77a /transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml
parentbce74e963abeb96a9c335f5461611dee544abc4c (diff)
Add support for text and link sharing in Mastodon transfer plugin
Diffstat (limited to 'transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml')
-rw-r--r--transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml132
1 files changed, 132 insertions, 0 deletions
diff --git a/transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml b/transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml
new file mode 100644
index 0000000..f965209
--- /dev/null
+++ b/transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml
@@ -0,0 +1,132 @@
+import QtQuick 2.6
+import Sailfish.Silica 1.0
+import Sailfish.Lipstick 1.0
+import Sailfish.TransferEngine 1.0
+
+Item {
+ id: root
+
+ property var shareAction
+ property string mimeType: {
+ if (shareAction && shareAction.mimeType) {
+ return shareAction.mimeType
+ }
+ if (shareAction && shareAction.resources
+ && shareAction.resources.length > 0
+ && shareAction.resources[0]
+ && shareAction.resources[0].type) {
+ return shareAction.resources[0].type
+ }
+ return ""
+ }
+ property bool textShare: mimeType === "text/x-url" || mimeType === "text/plain"
+
+ width: parent ? parent.width : 0
+ height: previewLoader.item ? previewLoader.item.height : 0
+
+ Loader {
+ id: previewLoader
+
+ anchors.fill: parent
+ sourceComponent: root.textShare ? postPreview : imagePreview
+ }
+
+ Component {
+ id: imagePreview
+
+ ShareFilePreview {
+ shareAction: root.shareAction
+ metadataStripped: true
+ descriptionPlaceholderText: qsTr("Write a post")
+ }
+ }
+
+ Component {
+ id: postPreview
+
+ SilicaFlickable {
+ id: postRoot
+
+ width: parent.width
+ height: contentHeight
+ contentHeight: contentColumn.height
+
+ Component.onCompleted: {
+ sailfishTransfer.loadConfiguration(root.shareAction.toConfiguration())
+ statusTextField.forceActiveFocus()
+ statusTextField.cursorPosition = statusTextField.text.length
+ }
+
+ SailfishTransfer {
+ id: sailfishTransfer
+ }
+
+ Column {
+ id: contentColumn
+
+ width: parent.width
+
+ TextArea {
+ id: linkTextField
+
+ width: parent.width
+ //% "Link"
+ label: qsTrId("sailfishshare-la-link")
+ placeholderText: label
+ visible: sailfishTransfer.content.type === "text/x-url"
+ text: sailfishTransfer.content.data || sailfishTransfer.content.status || ""
+ }
+
+ TextArea {
+ id: statusTextField
+
+ width: parent.width
+ //% "Status update"
+ label: qsTrId("sailfishshare-la-status_update")
+ placeholderText: label
+ text: {
+ var title = sailfishTransfer.content.name || sailfishTransfer.content.linkTitle || ""
+ if (linkTextField.visible) {
+ return title
+ }
+ var body = sailfishTransfer.content.data || sailfishTransfer.content.status || ""
+ if (title.length > 0 && body.length > 0) {
+ return title + ": " + body
+ }
+ return title + body
+ }
+ }
+
+ SystemDialogIconButton {
+ id: postButton
+
+ anchors.horizontalCenter: parent.horizontalCenter
+ width: parent.width / 2
+ iconSource: "image://theme/icon-m-share"
+ bottomPadding: Theme.paddingLarge
+ _showPress: false
+
+ //: Post a social network account status update
+ //% "Post"
+ text: qsTrId("sailfishshare-la-post_status")
+
+ onClicked: {
+ var status = statusTextField.text || ""
+ var link = linkTextField.visible ? (linkTextField.text || "") : ""
+ if (link.length > 0 && status.indexOf(link) === -1) {
+ status = status.length > 0 ? (status + "\n" + link) : link
+ }
+
+ sailfishTransfer.userData = {
+ "accountId": sailfishTransfer.transferMethodInfo.accountId,
+ "status": status
+ }
+ sailfishTransfer.mimeType = linkTextField.visible ? "text/x-url" : "text/plain"
+ sailfishTransfer.start()
+ root.shareAction.done()
+ }
+ }
+ }
+ }
+ }
+}