Exemple #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
Exemple #2
0
void
BBPhoneAccount::recheckProcess()
{
    if (NULL == m_sock) {
        Q_WARN("NULL socket");
        return;
    }

    m_sock->write("ping");
    m_sock->waitForBytesWritten();
    if (!m_sock->waitForReadyRead ()) {
        // Start the process again
        m_sock->write("quit");
        m_sock->waitForBytesWritten();
        m_sock->deleteLater();
        m_sock = NULL;

        QFileInfo fi("app/native/qt4srv");
        if (!QProcess::startDetached (fi.absoluteFilePath ())) {
            Q_WARN("Failed to start process");
        } else {
            QTimer::singleShot (1000, this, SLOT(onProcessStarted()));
        }
    } else {
        if (m_sock->readAll().startsWith("pong")) {
            m_TimerLogMessage.start ();
        }
    }
}//BBPhoneAccount::recheckProcess
void
SymbianCallInitiator::initiateCall (const QString &strDestination,
                                    void *ctx /*= NULL*/)
{
    bool bOk = false;
    m_Context = ctx;
    do { // Begin cleanup block (not a loop)
        if (NULL != dialer) {
            Q_WARN ("Call in progress. Ask again later.");
            break;  // false
        }
        if (NULL != observer) {
            Q_WARN ("observer was still alive. WTF?");
            CBase::Delete (observer);
        }
        observer = SymbianCallObserverPrivate::NewL (this);

        QMutexLocker locker(&mutex);
        strObservedNumber = strDestination;

        dialer = SymbianCallInitiatorPrivate::NewL (this, strDestination);
        if (NULL == dialer) {
            CBase::Delete (observer);
            observer = NULL;
            Q_WARN ("Could not dial out.");
            break;  // false
        }
        bOk = true;
    } while (0); // End cleanup block (not a loop)
    if (!bOk) {
        emit callInitiated (false, m_Context);
    }
}//SymbianCallInitiator::initiateCall
Exemple #4
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
Exemple #5
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
Exemple #6
0
BBPhoneAccount::~BBPhoneAccount()
{
#if USE_PROCESS
    if (NULL != m_sock) {
        m_sock->write("quit");
        m_sock->waitForBytesWritten (1000);
        delete m_sock;
    }
#else
    if (NULL != m_phoneCtx) {
        typedef void (*DeleteCtxFn)(void *ctx);
        DeleteCtxFn fn = (DeleteCtxFn) dlsym(m_hBBPhone,
                                             "deletePhoneContext");
        if (NULL == fn) {
            Q_WARN("Failed to get deletePhoneContext");
        } else {
            fn(m_phoneCtx);
        }
    }
    if (NULL != m_hBBPhone) {
        dlclose (m_hBBPhone);
        m_hBBPhone = NULL;
    }
#endif
}//BBPhoneAccount::~BBPhoneAccount
Exemple #7
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
Exemple #8
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
Exemple #9
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
Exemple #10
0
CQmlViewer::CQmlViewer()
: m_view(SailfishApp::createView())
{
    if (NULL == m_view) {
        Q_WARN("Failed to create view");
    }

    connect(m_view, SIGNAL(statusChanged(QQuickView::Status)),
            this, SLOT(onDeclStatusChanged(QQuickView::Status)));
}//CQmlViewer::CQmlViewer
Exemple #11
0
bool
SymbianPhoneAccount::initiateCall(AsyncTaskToken *task)
{
    SymbianCallInitiatorPrivate *dialer =
            SymbianCallInitiatorPrivate::NewL (this, task);
    if (NULL == dialer) {
        Q_WARN ("Could not dial out.");
        // NewL will emit the signal on task.
    }
}//SymbianPhoneAccount::initiateCall
Exemple #12
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
Exemple #13
0
void
SkypeAccount::attemptCreateSkypeClient ()
{
    if (NULL == m_skypeClient) {
        OsDependant *osd = (OsDependant *) Lib::ref().osd ();
        SkypeClientFactory &skypeFactory = osd->skypeClientFactory();
        m_skypeClient = skypeFactory.ensureSkypeClient (APPLICATION_NAME);
        if (NULL == m_skypeClient) {
            Q_WARN("Failed to create skype Client!");
            return;
        }

        bool rv = connect(m_skypeClient, SIGNAL(connectedChanged(bool)),
                          this, SIGNAL(changed()));
        if (!rv) {
            Q_WARN("Failed to connect to changed signal");
        }
        Q_ASSERT(rv);
        emit changed ();
    }
Exemple #14
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
Exemple #15
0
QVariant
GVNumModel::data (const QModelIndex &index, int role) const
{
    QVariant var;
    do { // Begin cleanup block (not a loop)
        int row = index.row();
        int col = index.column();
        GVRegisteredNumber num;

        if (row < m_dialBack.count ()) {
            num = m_dialBack[row];
        } else {
            row -= m_dialBack.count ();
            if (row < m_dialOut.count ()) {
                num = m_dialOut[row];
            } else {
                Q_WARN("Array index out of bounds!");
                break;
            }
        }

        if (IdRole == role) {
            var = num.id;
            break;
        }
        if (TypeRole == role) {
            var = num.chType;
            break;
        }
        if (NameRole == role) {
            var = num.name;
            break;
        }
        if (NumberRole == role) {
            var = num.number;
            break;
        }

        // This code path is only for QComboBox.
        // QComboBox only needs the 0th column.
        if (col != 0) {
            break;
        }

        if (Qt::DisplayRole == role) {
            var = QString("%1\n(%2)").arg(num.name, num.number);
            break;
        }
    } while (0); // End cleanup block (not a loop)
    return (var);
}//GVNumModel::data
Exemple #16
0
void
CQmlViewer::onDeclStatusChanged(QQuickView::Status status)
{
    if (QQuickView::Ready == status) {
        emit viewerStatusChanged (true);
        return;
    }

    if (QQuickView::Error != status) {
        return;
    }

    Q_WARN(QString("status = %1").arg (status));
    emit viewerStatusChanged (false);
}//CQmlViewer::onDeclStatusChanged
Exemple #17
0
void
NwReqTracker::onReplySslErrors(const QList<QSslError> &errors)
{
    bool first = true;
    QString strError = "SSL Errors: ";
    foreach(QSslError err, errors) {
        if (!first) {
            strError += ", ";
        }
        strError += err.errorString ();
        first = false;
    }

    Q_WARN(strError);
}//NwReqTracker::onReplySslErrors
Exemple #18
0
ObserverFactory::ObserverFactory(QObject *parent)
: QObject(parent)
{
    bool rv;

    // Observer for Skype on desktop Linux and desktop Windows
    SkypeObserver *skypeObs = new SkypeObserver ();

    rv = connect (skypeObs, SIGNAL (status(const QString &, int)),
                  this    , SIGNAL (status(const QString &, int)));
    if (!rv) {
        Q_WARN("Could not connect skype observer");
    }
    Q_ASSERT(rv);

    listObservers += (IObserver*) skypeObs;
}//ObserverFactory::ObserverFactory
Exemple #19
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
Exemple #20
0
QString
BBPhoneAccount::getNumber()
{
#if USE_PROCESS
    return m_number;
#else
    if (NULL == m_phoneCtx) {
        Q_WARN("BB phone library is not initialized");
        return QString();
    }

    typedef const char *(*GetNumFn)(void *ctx);
    GetNumFn fn = (GetNumFn) dlsym(m_hBBPhone, "getNumber");
    const char *bbrv = fn(m_phoneCtx);

    QString rv;
    rv += bbrv;

    return rv;
#endif
}//BBPhoneAccount::getNumber
void
SymbianCallInitiator::callDone (SymbianCallInitiatorPrivate *self, int status)
{
    delete self;

    QMutexLocker locker(&mutex);
    strObservedNumber.clear ();

    if (NULL != observer) {
        CBase::Delete (observer);
        observer = NULL;
    }

    if (dialer != self) {
        Q_WARN ("Dialer does not match!!!");
        if (NULL != dialer) {
            CBase::Delete (dialer);
        }
    }
    dialer = NULL;

    emit callInitiated ((status == KErrNone), m_Context);
}//SymbianCallInitiator::callDone
Exemple #22
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
Exemple #23
0
void
NwReqTracker::onReplyError(QNetworkReply::NetworkError code)
{
    QString strErr = QString("NW error %1").arg((int)code);
    Q_WARN(strErr);
}//NwReqTracker::onReplyError
Exemple #24
0
void
NwReqTracker::onReplyFinished()
{
    replyTimer.stop ();

    bool rv = false, done = false;
    QByteArray response;
    QNetworkReply *origReply = reply;

    do { // Begin cleanup block (not a loop)
        if (aborted) {
            Q_WARN("Reply was aborted");
            break;
        }

        if (QNetworkReply::NoError != origReply->error ()) {
            Q_WARN("Response error: ") << origReply->errorString ();
            break;
        }

        response = origReply->readAll ();
        rv = true;
    } while (0); // End cleanup block (not a loop)

    do { // Begin cleanup block (not a loop)
        done = true;

        if (!rv) {
            break;
        }

        if (!autoRedirect) {
            break;
        }

        QUrl urlMoved = hasMoved (origReply);
        if (urlMoved.isEmpty ()) {
            break;
        }

        QNetworkRequest req(urlMoved);
        req.setRawHeader("User-Agent", uaString);

        NwReqTracker::setCookies (jar, req);
        QNetworkReply *nextReply = nwMgr.get(req);
        if (!nextReply) {
            break;
        }

        disconnectReply ();
        init (nextReply, ctx, emitLog, autoDelete);
        autoRedirect = true;

        done = false;
    } while (0); // End cleanup block (not a loop)

    if (done) {
        if (!autoRedirect && response.contains ("Moved Temporarily")) {
            QString msg = "Auto-redirect not requested, but page content "
                          "probably indicates that this page has been "
                          "temporarily moved. Original request = %1";

            msg = msg.arg (origReply->request().url().toString ());

            QString strResp = response;
            int pos = strResp.indexOf ("a href=", 0, Qt::CaseInsensitive);
            if (-1 != pos) {
                int endpos = strResp.indexOf ("</a>", pos, Qt::CaseInsensitive);
                if (-1 != endpos) {
                    msg += "\nRedirect URL = " + strResp.mid(pos+8, endpos-pos);
                }
            }

            Q_WARN(msg);
        }

        emit sigDone (rv, response, origReply, ctx);
    }

    origReply->deleteLater ();
    if (done && autoDelete) {
        this->deleteLater ();
    }
}//NwReqTracker::onReplyFinished