Sailfish.Share API Documentation

Hi there!

I read in a blog post that there is a new API to share between apps. In one of my apps I show dates and I would like to add the option to add a date to the calendar. Is there some documentation on the share API that would help me to understand how to use the API?

Thanks =)

Hi!

Sorry, the documentation is still making its way to the documentation website. We will try to publish it there asap.

1 Like

Hi. I don’t think that sharing API is the right choice for that. Its purpose is to share data outside the phone. And I believe that there is no calendar sharing plugin. For opening event in calendar, I would suggest you to write it to VCalendar file to temporary location and open it (just call xdg-open with that file as argument)…

Hi!

Thanks for all the replies.
@karry I guess that is a good solution, if you know how to create a temp file :sweat_smile: in SailfishOS.
Can I use
QString filename=“Data.txt”;
QFile file( filename );
if ( file.open(QIODevice::ReadWrite) )
{
QTextStream stream( &file );
stream << “something” << endl;
}

Within the home directory?

I have created vCalendar files before but with PHP.

or in cpp as here:

Thanks again! I hope I have time on the weekend to check that out =)

probably simplest way from c++:

  QTemporaryFile *tmpFile = new QTemporaryFile(
    QDir::tempPath() + QDir::separator() + "event-XXXXXX.ics", 
    this); // destructed and file deleted with this object

  if (tmpFile->open()) {
    QTextStream stream( tmpFile );
    stream << "BEGIN:VCALENDAR" << '\n'
           << "..." << '\n'
           << "END:VCALENDAR" << '\n';
    tmpFile->close();

    qDebug() << "Opening" << tmpFile->fileName();
    if (!QDesktopServices::openUrl("file://" + tmpFile->fileName())) {
      qWarning() << "QDesktopServices::openUrl fails!";
    }
  }

Thanks to all the help. I got it working =)

I did one modification to @karry’s code:

if (!QDesktopServices::openUrl(QUrl("file://" + tmpFile->fileName(), QUrl::TolerantMode)))