Re: [SailfishDevel] Fwd: Re: Re: How to get contacts and sms through Qt(C++)

2013-12-25 Thread christopher . lamb

Andrey

That solution would be perfect for me, I would have no problem with  
supplying the code. The sources for the Harmattan version are out  
there on Github already, and the Sailfish sources soon will be.


In theory it might even be possible to separate the SMS bit of my app,  
including the control used to display the text, name and number + send  
button into a separate shared library C++ that would be called by my  
app. My app would simply provide the SMS body and the name of number  
of the chosen contact, and the library would take care of the rest.  
This would reduce the amount of code that would need to be audited.  
(At the moment the GUI bits are QML, I would need to do some thinking  
about how to move these to C++)



Chris

Zitat von Andrey Kozhevnikov coderusin...@gmail.com:

Maybe an option to share sources to jolla QA or even letting them to  
build application from sources and uploading to store to be 100%  
sure in usecase?


On 25.12.2013 17:08, christopher.l...@thurweb.ch wrote:

Hi Bernd

Thanks for your interest.

I understand that there is a strong need to prevent apps that send  
SMSes without the user's consent (a security issue), or to premium  
SMS numbers, thereby defrauding the user.


But we should not throw out the baby with the bathwater. There will  
be apps where SMS sending / handling is a primary part of the  
use-case, and where the user willingly consents to each SMS being  
sent by that app.


My own use-case (simplified) is this:
My main hobby is paragliding. Mostly we land close to where we  
started (at the foot of the mountain), but sometime we go  
cross-country and land many kilometres away, and need to  
communicate back to a recovery team the GPS location of the landing  
site.


The secondary use-case (secondary only because it should be far  
less often used). Is the emergency situation. You have landed in a  
tree, or as happened to me at the start of this year, are stuck on  
a cold and snowy mountain slope with darkness approaching. Here you  
need to alert the recovery team with your location, and the fact  
that your status is NOT OK.


My app uses GPS and SMS to achieve this. Before flying the user  
sets up a number of SMS templates (basically pre-filled messages to  
which GPS coords will later be added. On landing the user fires up  
the app, which starts the GPS. Once the GPS has acquired a fix, the  
user can then chose between Ok and Status NOT Ok SMSes. Based  
on this choice, the appropriate SMS template is taken, the GPS  
coords are added to this, and a pre-selected contact associated  
with the SMS template is chosen. The user sees both the text of the  
SMS, and the chosen contact name and number.


At this point the user can press send, and the SMS is sent to the  
displayed contact. He also has the option of adding further text to  
the SMS, and of changing the contact.


The aim is that he user should be able to send the SMS with an  
absolute minimum of button presses, either because he may be tired  
(Ok Situation), or because he is tired / injured / cold / wet  
(Emergency situation). On the Harmattan version of the app I have  
one press to open the app, a second to chose between Ok / Not Ok,  
and a third for Send. In this case the phone may be being used at  
the limits of touchscreen capabilities (cold and wet), so big  
buttons are called for.


It is in no way concealed from the user that the app sends SMSes:  
Indeed it is the purpose of the app.


There are other apps out there with similar use cases. The Swiss  
Helicopter rescue service REGA have one for iOS and Android.


Later I intend to make the other half: in this case an app for  
the Recovery team, that would pick incoming landed SMSes from  
pilots, and display distance and bearing for each of these relevant  
to the position of the recovery team.


Happy Christmas all.

Chris



Zitat von Bernd Wachter bernd.wach...@jolla.com:


christopher.l...@thurweb.ch writes:


Hi Bernd

Thanks, I am aware of that, but I think it is an inelegant solution,
acceptable ad interim as a workaround, but not longterm.


Allowing arbitrary applications to send SMS brings a big cost risk for
the user, due to all the premium SMS services out there - it'll only be
possible once we enforce proper application permissions.


My app is designed for emergency use, must be easy to use as possible,
and therefore I require a larger send button. I know from personal
experience that trying to operate a mobile when it is wet and below
zero degrees is not easy (at the very edge of the capabilities of
touch screen technology).


Can you describe what exactly you're trying to do?

Bernd






___
SailfishOS.org Devel mailing list


___
SailfishOS.org Devel mailing list





___
SailfishOS.org Devel mailing list


[SailfishDevel] Fwd: Re: Re: How to get contacts and sms through Qt(C++)

2013-12-22 Thread christopher . lamb

Hi Max

No problem, your english is excellent. What is your mother language?

I am visiting family for Christmas at the moment, so I will keep this  
first mail short. I will try and post again this evening.


So first, SMS: In my app I only need to send smses, and I do it using  
the Telepathy library. My explanation below reflects how I did it  
and my use-case, but there are other routes you can take.


The C++ code I am using is at the bottom of this mail.

Note this is ported from Harmattan, and not fully tested yet as my  
Sailfish app is not fully ported, and I only have the Emulator. No  
sign of my phone arriving ...


On Harmattan I originally used the Mobility API, but as that API had a  
very negative effect on app startup time, and is not available for Qt5  
/ Sailfish, I wrote code similar to that below for Harmattan, and was  
able to test it with a real Nokia N9.


//in the .pro file

QT += dbus

PKGCONFIG += TelepathyQt5

Note I need to play around more with the .pro file settings, but with  
the ones above, Telepathy is found, and the code compiles.


Note also that the account used below is almost certainly wrong for  
Sailfish, it is the one that works on the N9.


You also need to make sure that the correct Telepathy Modules are  
installed. I will post more on this later, but for now I think you  
will need

telepathy-ring-devel, telepathy-mission-control, telepathy-qt5-devel.

I will post separately on QtContacts in the next few days, as and when  
Christmas / family festivities permit.


Ciao

Chris



//start telepathy.h
#ifndef TELEPATHYHELPER_H
#define TELEPATHYHELPER_H

#include TelepathyQt/Types

#include QObject
#include QString

namespace Tp
{
class PendingOperation;
}

class TelepathyHelper : public QObject
{
Q_OBJECT

public:
explicit TelepathyHelper(QObject *parent = 0);
~TelepathyHelper();
Q_INVOKABLE void sendSMS(const QString contactIdentifier, const  
QString message);


signals:
void stateMsg(const QString statemsg);
void errorMsg(const QString errormsg);

private Q_SLOTS:
void onSendMessageFinished(Tp::PendingOperation *op);

private:

Tp::ContactMessengerPtr messenger;

};

#endif // TELEPATHYHELPER_H
//end //start telepathy.h

//start telepathy.cpp
#include telepathyhelper.h

#include TelepathyQt/Account
#include TelepathyQt/Debug
#include TelepathyQt/Constants
#include TelepathyQt/ContactMessenger
#include TelepathyQt/PendingSendMessage
#include TelepathyQt/Types


TelepathyHelper::TelepathyHelper(QObject *parent) :
QObject(parent)
{

Tp::registerTypes();
Tp::enableDebug(true);
Tp::enableWarnings(true);
}

TelepathyHelper::~TelepathyHelper()
{
}

void TelepathyHelper::sendSMS(const QString contactIdentifier, const  
QString message)

{

Tp::AccountPtr acc = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME,
  
QLatin1String(/org/freedesktop/Telepathy/Account/ring/tel/ring));

//QLatin1String(/org/freedesktop/Telepathy/Account/ring/tel/account0));
messenger = Tp::ContactMessenger::create(acc, contactIdentifier);

connect(messenger-sendMessage(message),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onSendMessageFinished(Tp::PendingOperation*)));

}

void TelepathyHelper::onSendMessageFinished(Tp::PendingOperation *op)
{
if (op-isError()) {
qDebug()  Error sending message:  op-errorName()   
-  op-errorMessage();

emit errorMsg(Error sending message);
return;
}

Tp::PendingSendMessage *psm = qobject_castTp::PendingSendMessage *(op);
qDebug()  Message sent, token is  psm-sentMessageToken();
emit stateMsg(FinishedState);
}

//end telepathy.cpp

- Weitergeleitete Nachricht von itvie...@jolladev.net -
 Datum: Sun, 22 Dec 2013 17:36:18 +0800
   Von: itviewer itvie...@jolladev.net
   Betreff: Re: Re: [SailfishDevel] How to get contacts and sms  
through Qt(C++)

An: christopher.lamb christopher.l...@thurweb.ch

Hi Chris
Thanks for your help,I  reviewed all your posts ,however, I still do  
not know how to start.

Will you be able to provide some cases I can refer to?

Thank you and sorry for my english.


maxinjun

From: christopher.lamb
Date: 2013-12-22 15:59
To: Sailfish OS Developers; itviewer
CC: devel
Subject: Re: [SailfishDevel] How to get contacts and sms through Qt(C++)
Hi myinjun

If you search through the archives of this mailing list, especially
for posts with my name you will find some stuff on Sailfish and SMS.

I was able to get SMS working (as far as that is possible) on the
Emulator using the Telepathy libraries.

Note however that currently that will probably be a no-no for
inclusion in the Harbour Store.

For Contacts access, see the recent thread on QtContact.

Chris

Zitat von itviewer itvie...@jolladev.net:


Hi,
I want to manage contacts and sms message through Qt C++?how can i
do that?Are there any helpful documents?
Any pointers whatsoever would 

Re: [SailfishDevel] Fwd: Re: Re: How to get contacts and sms through Qt(C++)

2013-12-22 Thread christopher . lamb

Hi Jonni

Thanks, I mentioned that at earlier in this thread.

However I think that the harbour rule is too strict. I think there is  
a legitimate case for apps that clearly state that their purpose is to  
send SMSes, and have their own send button -- i.e. SMSes are only  
sent with explicit permission of the user at time of sending.


Chris


Zitat von Jonni Rainisto jonni.raini...@jolla.com:

Please keep in mind that Harbour will not allow any application that  
sends SMS'es by themselves, if you want application to send sms'es  
you should open systems sms sending app (mayba can prefill the  
data), but end user should clearly press the send button her/himself  
before text message is sent.



From: devel-boun...@lists.sailfishos.org  
[devel-boun...@lists.sailfishos.org] on behalf of  
christopher.l...@thurweb.ch [christopher.l...@thurweb.ch]

Sent: Sunday, December 22, 2013 12:55 PM
To: itviewer; devel@lists.sailfishos.org
Subject: [SailfishDevel] Fwd: Re: Re: How to get contacts and sms 
   through Qt(C++)


Hi Max

No problem, your english is excellent. What is your mother language?

I am visiting family for Christmas at the moment, so I will keep this
first mail short. I will try and post again this evening.

So first, SMS: In my app I only need to send smses, and I do it using
the Telepathy library. My explanation below reflects how I did it
and my use-case, but there are other routes you can take.

The C++ code I am using is at the bottom of this mail.

Note this is ported from Harmattan, and not fully tested yet as my
Sailfish app is not fully ported, and I only have the Emulator. No
sign of my phone arriving ...

On Harmattan I originally used the Mobility API, but as that API had a
very negative effect on app startup time, and is not available for Qt5
/ Sailfish, I wrote code similar to that below for Harmattan, and was
able to test it with a real Nokia N9.

//in the .pro file

QT += dbus

PKGCONFIG += TelepathyQt5

Note I need to play around more with the .pro file settings, but with
the ones above, Telepathy is found, and the code compiles.

Note also that the account used below is almost certainly wrong for
Sailfish, it is the one that works on the N9.

You also need to make sure that the correct Telepathy Modules are
installed. I will post more on this later, but for now I think you
will need
telepathy-ring-devel, telepathy-mission-control, telepathy-qt5-devel.

I will post separately on QtContacts in the next few days, as and when
Christmas / family festivities permit.

Ciao

Chris



//start telepathy.h
#ifndef TELEPATHYHELPER_H
#define TELEPATHYHELPER_H

#include TelepathyQt/Types

#include QObject
#include QString

namespace Tp
{
 class PendingOperation;
}

class TelepathyHelper : public QObject
{
 Q_OBJECT

public:
 explicit TelepathyHelper(QObject *parent = 0);
 ~TelepathyHelper();
 Q_INVOKABLE void sendSMS(const QString contactIdentifier, const
QString message);

signals:
 void stateMsg(const QString statemsg);
 void errorMsg(const QString errormsg);

private Q_SLOTS:
 void onSendMessageFinished(Tp::PendingOperation *op);

private:

 Tp::ContactMessengerPtr messenger;

};

#endif // TELEPATHYHELPER_H
//end //start telepathy.h

//start telepathy.cpp
#include telepathyhelper.h

#include TelepathyQt/Account
#include TelepathyQt/Debug
#include TelepathyQt/Constants
#include TelepathyQt/ContactMessenger
#include TelepathyQt/PendingSendMessage
#include TelepathyQt/Types


TelepathyHelper::TelepathyHelper(QObject *parent) :
 QObject(parent)
{

 Tp::registerTypes();
 Tp::enableDebug(true);
 Tp::enableWarnings(true);
}

TelepathyHelper::~TelepathyHelper()
{
}

void TelepathyHelper::sendSMS(const QString contactIdentifier, const
QString message)
{

 Tp::AccountPtr acc = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME,

QLatin1String(/org/freedesktop/Telepathy/Account/ring/tel/ring));
  
//QLatin1String(/org/freedesktop/Telepathy/Account/ring/tel/account0));

 messenger = Tp::ContactMessenger::create(acc, contactIdentifier);

 connect(messenger-sendMessage(message),
 SIGNAL(finished(Tp::PendingOperation*)),
 SLOT(onSendMessageFinished(Tp::PendingOperation*)));

}

void TelepathyHelper::onSendMessageFinished(Tp::PendingOperation *op)
{
 if (op-isError()) {
 qDebug()  Error sending message:  op-errorName() 
-  op-errorMessage();
 emit errorMsg(Error sending message);
 return;
 }

 Tp::PendingSendMessage *psm =  
qobject_castTp::PendingSendMessage *(op);

 qDebug()  Message sent, token is  psm-sentMessageToken();
 emit stateMsg(FinishedState);
}

//end telepathy.cpp

- Weitergeleitete Nachricht von itvie...@jolladev.net -
  Datum: Sun, 22 Dec 2013 17:36:18 +0800
Von: itviewer itvie...@jolladev.net
Betreff: Re: Re: [SailfishDevel] How to get contacts and sms
through Qt(C