summaryrefslogtreecommitdiff
path: root/transferengine-plugins/mastodonshareplugin
diff options
context:
space:
mode:
Diffstat (limited to 'transferengine-plugins/mastodonshareplugin')
-rw-r--r--transferengine-plugins/mastodonshareplugin/MastodonShareImage.qml10
-rw-r--r--transferengine-plugins/mastodonshareplugin/MastodonSharePost.qml132
-rw-r--r--transferengine-plugins/mastodonshareplugin/mastodonplugininfo.cpp7
-rw-r--r--transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro2
4 files changed, 137 insertions, 14 deletions
diff --git a/transferengine-plugins/mastodonshareplugin/MastodonShareImage.qml b/transferengine-plugins/mastodonshareplugin/MastodonShareImage.qml
deleted file mode 100644
index 56b4b4b..0000000
--- a/transferengine-plugins/mastodonshareplugin/MastodonShareImage.qml
+++ /dev/null
@@ -1,10 +0,0 @@
-import QtQuick 2.6
-import Sailfish.Silica 1.0
-import Sailfish.TransferEngine 1.0
-
-ShareFilePreview {
- id: root
-
- metadataStripped: true
- descriptionPlaceholderText: qsTr("Write a post")
-}
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()
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/transferengine-plugins/mastodonshareplugin/mastodonplugininfo.cpp b/transferengine-plugins/mastodonshareplugin/mastodonplugininfo.cpp
index bc66752..a9cc1b7 100644
--- a/transferengine-plugins/mastodonshareplugin/mastodonplugininfo.cpp
+++ b/transferengine-plugins/mastodonshareplugin/mastodonplugininfo.cpp
@@ -6,7 +6,9 @@ MastodonPluginInfo::MastodonPluginInfo()
, m_mastodonShareServiceStatus(new MastodonShareServiceStatus(this))
{
m_capabilities << QLatin1String("image/jpeg")
- << QLatin1String("image/png");
+ << QLatin1String("image/png")
+ << QLatin1String("text/x-url")
+ << QLatin1String("text/plain");
connect(m_mastodonShareServiceStatus, &MastodonShareServiceStatus::serviceReady,
this, &MastodonPluginInfo::serviceReady);
@@ -42,9 +44,8 @@ void MastodonPluginInfo::serviceReady()
info.setMethodId(QLatin1String("Mastodon"));
info.setMethodIcon(QLatin1String("image://theme/icon-l-mastodon"));
- info.setShareUIPath(QLatin1String("/usr/share/nemo-transferengine/plugins/sharing/MastodonShareImage.qml"));
+ info.setShareUIPath(QLatin1String("/usr/share/nemo-transferengine/plugins/sharing/MastodonSharePost.qml"));
info.setCapabilities(m_capabilities);
-
m_info << info;
}
diff --git a/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro b/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro
index 1ab7c6c..0dd1443 100644
--- a/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro
+++ b/transferengine-plugins/mastodonshareplugin/mastodonshareplugin.pro
@@ -20,7 +20,7 @@ target.path = $$[QT_INSTALL_LIBS]/nemo-transferengine/plugins/sharing
OTHER_FILES += *.qml
-shareui.files = MastodonShareImage.qml
+shareui.files = MastodonSharePost.qml
shareui.path = /usr/share/nemo-transferengine/plugins/sharing
INSTALLS += target shareui