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

2013-12-22 Thread christopher . lamb

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 be highly appreciated.
thanks



maxinjun





___
SailfishOS.org Devel mailing list


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

2013-12-22 Thread itviewer
Hi Chris
Thank you very much  for your guidance,It's very helpful for me and I will try 
as your use-case.

My mother tongue is Chinese and my English is so-so. 
Wishing you and your family a very merry Christmas. 




maxinjun 

From: christopher.lamb
Date: 2013-12-22 18:55
To: itviewer; devel@lists.sailfishos.org
Subject: Fwd: Re: Re: [SailfishDevel] 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++)
 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

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

2013-12-22 Thread christopher . lamb

Hi Maxinjun

Now to answer the Contacts part of your question.

So far I have only briefly played with Contacts on Sailfish / Qt5, and  
I was interested in accessing contacts from QML rather than C++.


I was mainly interested to see if a bug that I had found in Qt  
Mobility Contacts (Qt4.8) was also present in Qt5, but that is a story  
for another day.


In my app .yaml file I have

PkgBR: qt5-qtdeclarative-pim-contacts

and

Requires: qt5-qtdeclarative-pim-contacts

This installs the QML Contacts components, plus qt5-qtpim-contacts and  
qt5-qtpim-versit.


As you want to use C++ you will probably also need qt5-qtpim-contacts-devel

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 be highly appreciated.
thanks



maxinjun





___
SailfishOS.org Devel mailing list


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

2013-12-21 Thread itviewer
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 be highly appreciated.
thanks



maxinjun ___
SailfishOS.org Devel mailing list