• May 01, 2024, 07:25:09 pm

Author Topic: [TUT] External URL opening with Star Browser 1.70  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Offline Allstar12345

  • Allstar Software Founder
  • Administrator
  • Forum Genius
  • ******
  • Posts: 5,235
  • Reputation: 812
    • Allstar Software
  • Current Phone: : OnePlus 8 Pro, Xperia 10, Nexus 6p, Jolla Phone, Nokia N8, Nokia 808 PureView, BlackBerry Z30
[TUT] External URL opening with Star Browser 1.70
« on: August 25, 2014, 05:21:36 pm »

Hi guys,

Recently I created a little way to open a URL in upcoming versions of Star Browser (1.70 and possibly higher)

It uses the Qt Publish&Subscribe API which requires no OS capabilities so it doesn't interfere with Signing.

First off:

We need to create a qcrml file in the root of your project folder, Symbian requires this because of the way the OS handles settings (Central Repository stuff), I'll be the first to admit that Qt/C++ isn't my strong point but this is rather easy.

Your qcrml file should look like this, lets call it externalaccesssb.qcrml (yes, three s's):

Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<repository target="RProperty" version="" uidName="KPSUidAknFep" uidValue="YOUR APPS UID GOES HERE!">
<key int="0x1" ref="/Allstar/external/url"> </key>
</repository>

Make sure you change the UID bit or it may cock up.

Next we need to edit the .pro file of the Project:

Inside the
Code: [Select]
symbian {
}
You need to place the following:

Code: [Select]
crml.sources = externalaccesssb.qcrml
 crml.path = c:/resource/qt/crml
DEPLOYMENT += crml

Then you need to add the dependency:

Code: [Select]
CONFIG += mobility
MOBILITY += publishsubscribe


Next is creating your Share Class:

On Qt Creator right click on Sources-Add New-C++ Class, under Class Name type externalsharing

Now here is the pain bit, you should check if Star Browser is open or not, huellif's open source CloseWhatsApp has a perfect example (first running() function):
https://github.com/huellif/CloseWhatsApp/blob/master/main.cpp


CPP, includes:


Code: [Select]
#include "externalsharing.h"
#include <qmobilityglobal.h>
#include <QValueSpaceSubscriber.h>
#include <QValueSpacePublisher.h>
#include <QUrl>
#include <QDebug>
#include <QTimer>


First part of the cpp:

Code: [Select]
ExternalSharing::ExternalSharing(QObject *parent):
        QObject(parent)
{
   pub = new QValueSpacePublisher( "/Allstar/external/", this );
   suc = new QValueSpaceSubscriber ("/Allstar/external/", this);
}
QUrl urler;

Now we have two functions, one which Shares and one which which is triggered by a Timer when Star Browser is closed and shares, giving it time to open on First Gens:


Code: [Select]
void ExternalSharing::shareToStarBrowser(QUrl url) const{

//You need to implement a check if it is open or not, if it is open fire the following code:
        urler=url;
        QString f;
        pub->setValue("/url", url);
        f = suc->value("/url").toString();
        qDebug() << "Url " + f;

//If Star Browser is not open, then use RProcess method in the CloseWhatsApp example to open StarBrowser.exe then fire the following after you have opened Star Browser, you can reduce the time a bit if you want but I recommend 5 seconds to let the browser load all of its components.

}
Code: [Select]
QTimer::singleShot(5000,this,SLOT(shareToClosedStarBrowser()));

This is the function which the QTimer fires if Star Browser is closed.
Code: [Select]
void ExternalSharing::shareToClosedStarBrowser(){

    QString f;
    pub->setValue("/url", urler);
    f = suc->value("/url").toString();
    qDebug() << "Url " + f;
}

Next is the Header file

Code: [Select]
#ifndef EXTERNALSHARING_H
#define EXTERNALSHARING_H

#include <QObject>
#include <QValueSpaceSubscriber>
#include <QValueSpacePublisher.h>
#include <QUrl>
QTM_USE_NAMESPACE
class ExternalSharing : public QObject
{
    Q_OBJECT
public:
    explicit ExternalSharing(QObject *parent = 0);
 Q_INVOKABLE void shareToStarBrowser(QUrl url) const;
    Q_INVOKABLE void shareToClosedStarBrowser();


private:

    QValueSpacePublisher* pub;
    QValueSpaceSubscriber* suc;

};

#endif // EXTERNALSHARING_H


Now you need to include it in your main.cpp and expose the Class to QML (If you don't have a QML UI App you don't need to expose it)

Code: [Select]
#include externalsharing.h
Remember if you use QmlApplicationViewer by default you need to replace the &view and view. with the name of your QmlApplicationViewer, it's usually called viewer

Code: [Select]
ExternalSharing externalsharing (&view);
                    view.rootContext()->setContextProperty("ExternalSharing", &externalsharing);

Now Build your project to make sure there aren't any errors, if it builds fine you can fire it from your App, type ExternalSharing.shareToStarBrowser(URL GOES HERE)
It only has one argument for the function, that is the url you want to share, the ExternalSharing will turn blue if it has exposed correctly.


Now once you have fired that function and Start Browser has opened, Star Browser will pick up the change in data and display a Dialog asking the user if they want to accept the URL.
You can get a copy of Star Browser 1.70 Alpha for testing if you Email me at allstar12345@ovi.com


Small Demo:

https://www.youtube.com/watch?v=84nAAftuxtk&list=UUPzRDBnfgvQVRslv48fmehw
« Last Edit: September 26, 2014, 03:37:03 pm by Allstar12345 »