コード例 #1
0
void
lastfm::InternetConnectionMonitor::onFinished( QNetworkReply* reply )
{
    if( reply->attribute( QNetworkRequest::SourceIsFromCacheAttribute).toBool() ) return;

    switch( reply->error() )
    {
        case QNetworkReply::NoError:
            if ( !m_up )
            {
                m_up = true;
                emit up();
                emit connectivityChanged( m_up );
                qDebug() << "Internet connection is reachable :)";
            }
            break;
        case QNetworkReply::HostNotFoundError:
        case QNetworkReply::TimeoutError:
        case QNetworkReply::ProxyConnectionRefusedError:
        case QNetworkReply::ProxyConnectionClosedError:
        case QNetworkReply::ProxyNotFoundError:
        case QNetworkReply::ProxyTimeoutError:
        case QNetworkReply::ProxyAuthenticationRequiredError:
            if ( m_up )
            {
                m_up = false;
                emit down();
                emit connectivityChanged( m_up );
            }
            break;
        default:
            break;
    }
}
コード例 #2
0
ファイル: Hangish.cpp プロジェクト: mzanetti/hangish
int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("Hangish");
    QCoreApplication::setApplicationName("Hangish");
    QCoreApplication::setApplicationVersion("0.6.0");

    QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
    QScopedPointer<QQuickView> view(SailfishApp::createView());
    ConversationModel *conversationModel = new ConversationModel();
    RosterModel *rosterModel = new RosterModel();
    ContactsModel *contactsModel = new ContactsModel();
    FileModel *fileModel = new FileModel();
    Client *c = new Client(rosterModel, conversationModel, contactsModel);
    ImageHandler *ih = new ImageHandler();
    ih->setAuthenticator(c->getAuthenticator());
    //Do this once when app is launching
    ih->cleanCache();

    view->rootContext()->setContextProperty("conversationModel", conversationModel);
    view->rootContext()->setContextProperty("rosterModel", rosterModel);
    view->rootContext()->setContextProperty("contactsModel", contactsModel);
    view->rootContext()->setContextProperty("fileModel", fileModel);
    view->engine()->rootContext()->setContextProperty("Client", c);
    view->engine()->rootContext()->setContextProperty("ImageHandler", ih);


    QDBusConnection system = QDBusConnection::systemBus();
    if (!system.isConnected())
    {
        qFatal("Cannot connect to the D-Bus session bus.");
        return 1;
    }
    system.connect("net.connman",
                   "/net/connman/technology/wifi",
                   "net.connman.Technology",
                   "PropertyChanged",
                   c,
                   SLOT(connectivityChanged(QString,QDBusVariant))
                  );
    system.connect("net.connman",
                   "/net/connman/technology/cellular",
                   "net.connman.Technology",
                   "PropertyChanged",
                   c,
                   SLOT(connectivityChanged(QString,QDBusVariant))
                  );

    view->setSource(SailfishApp::pathTo("qml/harbour-hangish.qml"));
    view->showFullScreen();
    app->exec();
}
コード例 #3
0
void
lastfm::InternetConnectionMonitor::onNetworkDown()
{
    qDebug() << "Internet is unreachable :(";
    m_up = false;
    emit down();
    emit connectivityChanged( m_up );
}
コード例 #4
0
void
lastfm::InternetConnectionMonitor::onNetworkUp()
{
#ifdef Q_OS_MAC
    // We don't need to check on mac as the
    // check is done as part of the reach api
        m_up = true;
    emit up();
    emit connectivityChanged( m_up );
    qDebug() << "Internet connection is reachable :)";
#else
    qDebug() << "Network seems to be up again. Let's try if there's internet connection!";
    lastfm::nam()->head( QNetworkRequest( QUrl( tr( "http://www.last.fm/" ) ) ) );
#endif
}