Save and share Canvas without a hard coded path

Hi, I have an app where I draw pictures with Canvas. I want to share the picture via e-mail. I manage to code the whole operation with a hard coded path. It is OK for OpenRepos but is rejected by a validation for Jolla Harbour. When substituting /home/nemo/ with $HOME/ the app won’t work any more. The code follows. If you want to look all the spaghetti, please try https://github.com/Rikujolla/harbour-math-teacher/blob/master/qml/pages/FunPage.qml

MenuItem {
    text:qsTr("Share my horse")
    onClicked:{
        saddle.save("/home/nemo/horse.png")
        //saddle.save("$HOME/horse.png")
        pageStack.push("Sailfish.TransferEngine.SharePage",
                       {
                           "source": "/home/nemo/horse.png",
                           //"source": "$HOME/horse.png",
                           "mimeType": "image/png",
                           "content": { "type": "text/x-uri", "status": "Sent from SailfishOS app Math teacher" },
                           "serviceFilter": ["sharing", "e-mail"]
                       }
                       )
    }
}

}

Use Silica’s StandardPaths: https://sailfishos.org/develop/docs/silica/qml-sailfishsilica-sailfish-silica-standardpaths.html/

In your case:

MenuItem {
    text:qsTr("Share my horse")
    onClicked:{
        saddle.save(StandardPaths.home + "/horse.png")
        //saddle.save("$HOME/horse.png")
        pageStack.push("Sailfish.TransferEngine.SharePage",
                       {
                           "source": StandardPaths.home + "/horse.png",
                           //"source": "$HOME/horse.png",
                           "mimeType": "image/png",
                           "content": { "type": "text/x-uri", "status": "Sent from SailfishOS app Math teacher" },
                           "serviceFilter": ["sharing", "e-mail"]
                       }
                       )
    }
}

}

would work.

1 Like

Thanks a lot, it works well. For some reason I had not found that.

1 Like