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!";
    }
  }
1 Like

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)))

Is your code available? I’m looking at a temporary fix for adding timetable entries to the calendar from fahrplan.

Yes it is. You can find it on GitHub. I hope it is understandable and helpful. In case you see an option to improve the code let me know!

1 Like

Thank you! Updating against the new KCaldendarCore stuff is non-trivial :wink:

I wondered if you, or perhaps @Sikarjan, had an idea of how to insert in the stream if you have to iterate at some point. I’ve had to strip html fragments since they seem to get jumbled in the QML richtext display in the Calendar app. In the main, I had the problem with newlines being stripped if I try to aggregate my ‘Description:’ bit.

https://github.com/poetaster/fahrplan/blob/master/src/calendar_sfos_wrapper.cpp It’s a bit of a monster, so don’t worry if it’s too painful. I have to think about the message too, so I’m revising this as I go.

1 Like

I am only a very little skilled hobby programmer but I would like to help out.

Did you verify that the event you are creating is valid? Take the log put it in a text file and see if you calendar app can read it properly. I remember that it was very helpful for me to read the vcal specification.

The other thing I noticed is that I am using \r\n to create a new line where you are only using \n.
Not to sure what you mean by iterate. I am creating a string on QML side that I pass to the C++ code, which creates the temp file. Iterating to create a string should not be an issue. But might be that I did not get your point.

Thanks!

I’m creating files that are imported properly. It’s just that the description: field is generated dynamically and should contain newlines. Anytime I created a field with ‘\n’ line endings within variables (QString) the stream would be stripped of the newlines. I belived I tried ‘\r\n’ too, but I’ll try that again :slight_smile:

One variation was to construct

     aDesc.append("DESCRIPTION:\n");
    for ( const auto& i : slist  )
    {
        aDesc.append( i + "\n" );
    }
    aDesc.append("END:VEVENT\n");

Another operated in << In any case, a simple QString with no newlines works without problems.

A QString, with no newlines, but with html in it becomes messed up.