Example #1
0
void
BBPhoneAccount::onProcessStarted()
{
    Q_DEBUG("Process started!");

    m_sock = new QLocalSocket(this);
    if (NULL == m_sock) {
        Q_WARN("Failed to allocate local socket");
        return;
    }

    m_sock->connectToServer ("qgvdial");
    if (!m_sock->waitForConnected (1000)) {
        Q_WARN("Waiting for a second to connect to server");
        QTimer::singleShot (1000, this, SLOT(onProcessStarted()));
        delete m_sock;
        m_sock = NULL;
        return;
    }

    Q_DEBUG("Socket connected");

    if (!pingPong()) {
        return;
    }

    connect(m_sock, SIGNAL(readyRead()), this, SLOT(onGetNumber()));
    m_sock->write("getNumber");

    m_TimerLogMessage.start ();
}//BBPhoneAccount::onProcessStarted
Example #2
0
void
TpObserver::observeChannels(
    const MethodInvocationContextPtr<>  &context,
    const AccountPtr                    &account,
    const ConnectionPtr                 &connection,
    const QList<ChannelPtr>             &channels,
    const ChannelDispatchOperationPtr   &dispatchOperation,
    const QList<ChannelRequestPtr>      &requestsSatisfied,
    const ObserverInfo                  &observerInfo)
{
    bool bOk;
    QString msg;
    Q_DEBUG ("TpObserver: Observer got something!");

    if (strContact.isEmpty ()) {
        context->setFinished ();
        Q_DEBUG ("TpObserver: But we weren't asked to notify anything");
        return;
    }

    msg = QString("TpObserver: There are %1 channels in channels list")
          .arg (channels.length ());
    Q_DEBUG (msg);

    foreach (ChannelPtr channel, channels) {
        if (!channel->isReady ()) {
            Q_DEBUG ("TpObserver: Channel is not ready");

            ChannelAccepter *closer =
                new ChannelAccepter(context,
                                    account,
                                    connection,
                                    channels,
                                    dispatchOperation,
                                    requestsSatisfied,
                                    observerInfo.allInfo (),
                                    channel,
                                    strContact,
                                    this);
            bOk = connect (closer, SIGNAL (callStarted ()),
                           this  , SIGNAL (callStarted ()));
            Q_ASSERT(bOk);
            Q_UNUSED(bOk);
            closer->init ();
            break;
        }
    }
}//TpObserver::observeChannels
Example #3
0
BBPhoneAccount::BBPhoneAccount(QObject *parent)
: IPhoneAccount(parent)
#if USE_PROCESS
, m_sock(NULL)
#else
, m_hBBPhone(NULL)
, m_phoneCtx(NULL)
#endif
{
#if USE_PROCESS
    QFileInfo fi("app/native/qt4srv");
    if (!QProcess::startDetached (fi.absoluteFilePath ())) {
        Q_WARN("Failed to start process");
    } else {
        QTimer::singleShot (1000, this, SLOT(onProcessStarted()));
    }

    m_TimerLogMessage.setSingleShot (true);
    m_TimerLogMessage.setInterval (1000);
    connect(&m_TimerLogMessage, SIGNAL(timeout()),
            this, SLOT(onLogMessagesTimer()));
#else
    if (NULL == m_hBBPhone) {
        QFileInfo fi("app/native/libbbphone.so");
        m_hBBPhone = dlopen (fi.absoluteFilePath().toLatin1().constData(),
                             RTLD_NOW);
        if (NULL == m_hBBPhone) {
            Q_WARN("Failed to load BB Phone Qt4 library");
            return;
        }
    }
    Q_DEBUG("bbphone lib opened");

    typedef void *(*CreateCtxFn)();
    CreateCtxFn fn = (CreateCtxFn) dlsym(m_hBBPhone,
                                         "createPhoneContext");
    if (NULL == fn) {
        Q_WARN("Failed to get createPhoneContext");
        return;
    }
    Q_DEBUG("Got createPhoneContext");

    m_phoneCtx = fn();
    if (NULL == m_phoneCtx) {
        Q_WARN("Get NULL from createPhoneContext");
    }
#endif
}//BBPhoneAccount::BBPhoneAccount
Example #4
0
bool
BBPhoneAccount::pingPong()
{
    m_sock->write("ping");
    m_sock->waitForBytesWritten();
    if (!m_sock->waitForReadyRead()) {
        recheckProcess();
        return false;
    }

    QByteArray pong = m_sock->readAll();
    if (!pong.startsWith("pong")) {
        recheckProcess();
        return false;
    }
    if (!pong.contains("first")) {
        Q_DEBUG("We're the second instance!");

        delete m_sock;
        m_sock = NULL;

        qApp->quit();
        return false;
    }
    if (pong.contains("wakeup")) {
        // Wake up! : Hackity hack!
        BB10PhoneFactory *f = (BB10PhoneFactory *) this->parent ();
        LibGvPhones *gvp = (LibGvPhones *) f->parent ();
        MainWindow *win = (MainWindow *) gvp->parent ();

        win->messageReceived ("show");
    }

    return true;
}//BBPhoneAccount::pingPong
Example #5
0
QUrl
NwReqTracker::hasMoved(QNetworkReply *reply)
{
    QUrl url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute)
                     .toUrl ();

    do { // Begin cleanup block (not a loop)
        if (url.isEmpty ()) {
            break;
        }
        if ((url.scheme () == "https") || (url.scheme () == "http")) {
            break;
        }

        QString result = url.scheme ();
        if (!result.isEmpty ()) {
            break;
        }

        result = url.toString ();
        int pos = result.indexOf ("https://");
        if (-1 == pos) {
            break;
        }

        url = QUrl(result.remove (0, pos));
        Q_DEBUG("url:") << url.toString ();
    } while (0); // End cleanup block (not a loop)
    return url;
}//NwReqTracker::hasMoved
Example #6
0
void
MyXmlErrorHandler::handleMessage (QtMsgType type, const QString &description,
                                  const QUrl & /*identifier*/,
                                  const QSourceLocation &sourceLocation)
{
    QString msg = QString("XML message: %1, at uri= %2 "
                          "line %3 column %4")
                .arg(description)
                .arg(sourceLocation.uri ().toString ())
                .arg(sourceLocation.line ())
                .arg(sourceLocation.column ());

    switch (type) {
    case QtDebugMsg:
        Q_DEBUG(msg);
        break;
    case QtWarningMsg:
        Q_WARN(msg);
        break;
    case QtCriticalMsg:
    case QtFatalMsg:
        Q_CRIT(msg);
        break;
    }
}//MyXmlErrorHandler::handleMessage
void
SymbianCallInitiator::nextDtmf()
{
    if (arrTones.isEmpty ()) {
        Q_DEBUG ("No more tones");
        return;
    }

    QString strTones = arrTones.first ();
    arrTones.pop_front ();

    if (strTones.isEmpty ()) {
        Q_DEBUG ("Blank tone");
        QTimer::singleShot (1000, this, SLOT(nextDtmf ()));
    } else {
        Q_DEBUG(QString("Current tone = %1").arg(strTones));

        dtmfSender->sendDTMF (strTones);
    }
}//SymbianCallInitiator::nextDtmf
Example #8
0
void
ChannelAccepter::onCallAccepted (Tp::PendingOperation *operation)
{
    if (operation->isError ()) {
        Q_WARN ("TpObserver: Failed to accept call");
    } else {
        Q_DEBUG ("TpObserver: Call accepted");
    }
    context->setFinished ();
    this->deleteLater ();
}//ChannelAccepter::onCallAccepted
Example #9
0
void
MainWindow::init()
{
    QString qt4srvLog = QDir::currentPath() + "/logs/qt4srv.txt";
    if (QFileInfo(qt4srvLog).exists ()) {
        g_arrLogFiles.append(qt4srvLog);
    }

    bool isSquare = true;
    qreal val;
    int width = QGuiApplication::primaryScreen()->size().width();
    if (width == 720) {
        Q_DEBUG("Its a Q10!");
        val = 0.7;
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor1", val);
        val = 0.8;
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor2", val);
    } else if (width == 1440) {
        Q_DEBUG("Its a Passport!");
        val = 0.7;
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor1", val);
        val = 0.8;
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor2", val);
    } else {
        val = 1.0;
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor1", val);
        m_view->engine()->rootContext()
                    ->setContextProperty("g_keypadScaleFactor2", val);

        isSquare = false;
    }

    m_view->engine()->rootContext()->setContextProperty("g_isSquare", isSquare);

    QmlMainWindow::init ();
}//MainWindow::init
Example #10
0
void
NwReqTracker::abort()
{
    aborted = true;
    Q_DEBUG("Abort!!");

    reply->abort ();

    if (autoDelete) {
        this->deleteLater ();
    }
}//NwReqTracker::abort
Example #11
0
bool
ChannelAccepter::init ()
{
    PendingReady *pendingReady;
    QMutexLocker locker(&mutex);

    nRefCount ++;   // One for protection

    nRefCount ++;
    pendingReady = connection->becomeReady ();
    bool bOk = connect (
                   pendingReady, SIGNAL (finished (Tp::PendingOperation *)),
                   this        , SLOT   (onConnectionReady (Tp::PendingOperation *)));
    if (bOk) {
        Q_DEBUG ("TpObserver: Waiting for connection to become ready");
    }

    nRefCount ++;
    pendingReady = account->becomeReady ();
    bOk = connect (
              pendingReady, SIGNAL (finished (Tp::PendingOperation *)),
              this        , SLOT   (onAccountReady (Tp::PendingOperation *)));
    if (bOk) {
        Q_DEBUG ("TpObserver: Waiting for account to become ready");
    }

    nRefCount ++;
    pendingReady = currentChannel->becomeReady ();
    bOk = connect (
              pendingReady, SIGNAL (finished (Tp::PendingOperation *)),
              this        , SLOT   (onChannelReady (Tp::PendingOperation *)));
    if (bOk) {
        Q_DEBUG ("TpObserver: Waiting for channel to become ready");
    }

    Q_DEBUG ("TpObserver: All become ready's sent");
    decrefCleanup ();

    return (bOk);
}//ChannelAccepter::init
Example #12
0
void
BBPhoneAccount::onGetNumber()
{
    disconnect(m_sock, SIGNAL(readyRead()), this, SLOT(onGetNumber()));

    QByteArray ba = m_sock->readAll ();
    m_number = ba;

    Q_DEBUG(QString("Got number \"%1\". Length of ba = %2").arg (m_number)
            .arg(ba.length()));

    emit numberReady();
}//BBPhoneAccount::onGetNumber
Example #13
0
void
BBPhoneAccount::onLogMessagesTimer()
{
    m_sock->write("getDebugMessages");
    m_sock->waitForBytesWritten();

    if (!m_sock->waitForReadyRead ()) {
        recheckProcess();
        return;
    }

    QString msgs = m_sock->readAll ();
    if (msgs.length ()) {
        Q_DEBUG(msgs);
    }

    m_TimerLogMessage.start ();
}//BBPhoneAccount::onLogMessagesTimer
Example #14
0
bool
BBPhoneAccount::initiateCall(AsyncTaskToken *task)
{
    if (!task->inParams.contains("destination")) {
        Q_WARN("Destination not given!");
        task->status = ATTS_INVALID_PARAMS;
        task->emitCompleted();
        return true;
    }
    QString dest = task->inParams["destination"].toString();

#if USE_PROCESS
    if (NULL == m_sock) {
        Q_WARN("BB phone library is not initialized");
        task->status = ATTS_FAILURE;
        task->emitCompleted();
        return true;
    }

    //dest = "initiateCellularCall" + dest;
    //m_sock->write(dest.toLatin1 ());

    QDesktopServices::openUrl(QUrl("tel:" + dest));
#else
    typedef void (*InitiateCallFn)(void *ctx, const char *dest);
    InitiateCallFn fn = (InitiateCallFn) dlsym(m_hBBPhone,
                                               "initiateCellularCall");
    if (NULL == fn) {
        Q_WARN("Failed to get initiateCellularCall");
        task->status = ATTS_FAILURE;
        task->emitCompleted();
        return true;
    } else {
        fn(m_phoneCtx, dest.toLatin1().constData());
    }
#endif

    Q_DEBUG(QString("Call initiated to dest: %1").arg(dest));

    //TODO: Do this in the slot for the completion of the phone call
    task->status = ATTS_SUCCESS;
    task->emitCompleted();
    return true;
}//BBPhoneAccount::initiateCall
Example #15
0
bool
CQmlViewer::connectToChangeNotify(QObject *item, const QString &propName,
                                  QObject *receiver, const char *slotName)
{
    bool rv = false;
    do {
        const QMetaObject *metaObject = item->metaObject ();
        if (NULL == metaObject) {
            Q_WARN("NULL metaObject");
            break;
        }

        QMetaProperty metaProp;
        for (int i = 0; i < metaObject->propertyCount (); i++) {
            metaProp = metaObject->property (i);
            if (metaProp.name () == propName) {
                rv = true;
                break;
            }
        }

        if (!rv) {
            Q_WARN(QString("Couldn't find property named %1").arg(propName));
            break;
        }
        rv = false;

        if (!metaProp.hasNotifySignal ()) {
            Q_WARN(QString("Property %1 does not have a notify signal")
                   .arg(propName));
            break;
        }

        QString signalName = metaProp.notifySignal().methodSignature();
        signalName = "2" + signalName;

        Q_DEBUG(QString("Connect %1 to %2").arg(signalName).arg(slotName));

        rv =
        connect(item, signalName.toLatin1().constData(), receiver, slotName);
    } while(0);

    return (rv);
}//CQmlViewer::connectToChangeNotify
Example #16
0
bool
IosPhoneAccount::initiateCall(AsyncTaskToken *task)
{
    if (!task->inParams.contains("destination")) {
        Q_WARN("Destination not given!");
        task->status = ATTS_INVALID_PARAMS;
        task->emitCompleted();
        return true;
    }
    QString dest = task->inParams["destination"].toString();

    QDesktopServices::openUrl(QUrl("tel:" + dest));
    Q_DEBUG(QString("Call initiated to dest: %1").arg(dest));

    //TODO: Do this in the slot for the completion of the phone call
    task->status = ATTS_SUCCESS;
    task->emitCompleted();
    return true;
}//IosPhoneAccount::initiateCall
Example #17
0
void
ChannelAccepter::onAccountReady (Tp::PendingOperation *operation)
{
    do { // Not a loop
        if (operation->isError ()) {
            Q_WARN ("TpObserver: Account could not become ready");
            bFailure = true;
        }

        if (!account->isReady ()) {
            Q_WARN ("TpObserver: Dammit the account is still not ready");
        } else {
            Q_DEBUG ("TpObserver: Account is ready");
        }

        decrefCleanup ();
    } while (0); // Not a loop
    operation->deleteLater ();
}//ChannelAccepter::onAccountReady
Example #18
0
bool
QGVChannel::registerObject()
{
    ChannelAdaptor *ca = new ChannelAdaptor(this);
    if (NULL == ca) {
        Q_WARN("Failed to create channel adapter object");
        return false;
    }

    QDBusConnection sessionBus = QDBusConnection::sessionBus();
    bool rv = sessionBus.registerObject(m_dbusObjectPath, this);
    if (!rv) {
        Q_WARN(QString("Couldn't register Channel object path %1")
                .arg(m_dbusObjectPath));
        delete ca;
        return false;
    }

    Q_DEBUG(QString("Registered channel object %1").arg(m_dbusObjectPath));

    return true;
}//QGVChannel::registerObject
Example #19
0
void
QGVChannel::Close()
{
    Q_DEBUG("Channel close requested");
    this->deleteLater();
}//QGVChannel::Close
Example #20
0
void
TpObserver::stopMonitoring ()
{
    Q_DEBUG ("TpObserver: Stop monitoring") << strContact;
    strContact.clear ();
}//TpObserver::stopMonitoring
Example #21
0
void
TpObserver::startMonitoring (const QString &strC)
{
    Q_DEBUG ("TpObserver: Start monitoring") << strC;
    strContact = strC;
}//TpObserver::startMonitoring
Example #22
0
QString
QGVChannel::GetChannelType()
{
    Q_DEBUG(QString("Channel type = %1").arg(m_channelType));
    return m_channelType;
}//QGVChannel::GetChannelType
Example #23
0
void
ChannelAccepter::decrefCleanup ()
{
    QMutexLocker locker(&mutex);
    nRefCount--;
    if (0 != nRefCount)
    {
        return;
    }

    Q_DEBUG ("TpObserver: Everything ready. Cleaning up");

    bool bCleanupLater = false;
    do { // Not a loop
        if (bFailure) {
            Q_WARN ("TpObserver: Failed while waiting for something");
            break;
        }

        QString msg;
        msg = QString("TpObserver: Channel type = %1. isRequested = %2")
              .arg (currentChannel->channelType ())
              .arg (currentChannel->isRequested ());
        Q_DEBUG (msg);

        ContactPtr contact = currentChannel->initiatorContact ();
        msg = QString("TpObserver: Contact id = %1. alias = %2")
              .arg (contact->id ())
              .arg (contact->alias ());
        Q_DEBUG (msg);

        int interested = 0;
        if (0 == currentChannel->channelType().compare (
                    TPQT_CHANNEL_TYPE_STREAMED_MEDIA))
        {
            interested++;
        }
        if (!currentChannel->isRequested ())
        {
            interested++;
        }
        if (contact->id ().contains (strCheckNumber))
        {
            interested++;
        }

        if (3 != interested)
        {
            Q_DEBUG ("TpObserver: Channel that we're not interested in");
            break;
        }

        Q_DEBUG ("TpObserver: Incoming call from our number!");
        emit callStarted ();
    } while (0); // Not a loop

    if (!bCleanupLater)
    {
        context->setFinished ();
        this->deleteLater ();
    }
}//ChannelAccepter::decrefCleanup
Example #24
0
QStringList
QGVChannel::GetInterfaces()
{
    Q_DEBUG(QString("Returning interfaces [%1]").arg(m_interfaces.join(", ")));
    return m_interfaces;
}//QGVChannel::GetInterfaces
void
SymbianCallInitiator::onDtmfSent (SymbianDTMFPrivate *self, bool bSuccess)
{
    Q_DEBUG(QString("Send DTMF %1").arg(bSuccess ? "suceeded" : "failed"));
    QTimer::singleShot (1000, this, SLOT(nextDtmf ()));
}//SymbianCallInitiator::onDtmfSent