contact-messenger/sender.cpp

| Home · All Classes · All Namespaces · Modules · Functions · Files

contact-messenger/sender.cpp
#include "sender.h"
#include "_gen/sender.moc.hpp"
#include <TelepathyQt/Account>
#include <TelepathyQt/Debug>
#include <TelepathyQt/Constants>
#include <TelepathyQt/ContactMessenger>
#include <TelepathyQt/PendingSendMessage>
#include <TelepathyQt/Types>
#include <QCoreApplication>
Sender::Sender(const QString &accountPath,
const QString &contactIdentifier, const QString &message)
{
Tp::AccountPtr acc = Tp::Account::create(TP_QT_ACCOUNT_MANAGER_BUS_NAME,
accountPath);
messenger = Tp::ContactMessenger::create(acc, contactIdentifier);
connect(messenger->sendMessage(message),
SIGNAL(finished(Tp::PendingOperation*)),
SLOT(onSendMessageFinished(Tp::PendingOperation*)));
}
Sender::~Sender()
{
}
void Sender::onSendMessageFinished(Tp::PendingOperation *op)
{
if (op->isError()) {
qDebug() << "Error sending message:" << op->errorName() << "-" << op->errorMessage();
QCoreApplication::exit(1);
return;
}
Tp::PendingSendMessage *psm = qobject_cast<Tp::PendingSendMessage *>(op);
qDebug() << "Message sent, token is" << psm->sentMessageToken();
QCoreApplication::exit(0);
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
Tp::registerTypes();
Tp::enableDebug(true);
Tp::enableWarnings(true);
if (argc < 4) {
qDebug() << "Usage: contact-messenger account_path contact_id message";
return -1;
}
Sender *sender = new Sender(QLatin1String(argv[1]), QLatin1String(argv[2]),
QLatin1String(argv[3]));
int ret = app.exec();
delete sender;
return ret;
}