Exemple #1
0
QString DNSUpdater::getUpdateUrl() const
{
    QUrl url;
#ifdef QT_NO_OPENSSL
    url.setScheme("http");
#else
    url.setScheme("https");
#endif
    url.setUserName(m_username);
    url.setPassword(m_password);

    Q_ASSERT(!m_lastIP.isNull());
    // Service specific
    switch (m_service) {
    case DNS::DYNDNS:
        url.setHost("members.dyndns.org");
        break;
    case DNS::NOIP:
        url.setHost("dynupdate.no-ip.com");
        break;
    default:
        qWarning() << "Unrecognized Dynamic DNS service!";
        Q_ASSERT(0);
    }
    url.setPath("/nic/update");

    QUrlQuery urlQuery(url);
    urlQuery.addQueryItem("hostname", m_domain);
    urlQuery.addQueryItem("myip", m_lastIP.toString());
    url.setQuery(urlQuery);
    Q_ASSERT(url.isValid());

    qDebug() << Q_FUNC_INFO << url.toString();
    return url.toString();
}
void Wikipedia::getTranslation()
{
    if (langCode().isEmpty() || entry().isEmpty()) {
        return;
    }

    QSettings s;
    QString lang = s.value(QStringLiteral("display/language")).toString().left(2).toUpper();
    if (lang.isEmpty() || (lang == QLatin1String("C"))) {
        lang = QLocale::system().name().left(2);
    }

    QUrl wpURL;
    wpURL.setScheme(QStringLiteral("https"));


    if (lang == langCode()) {
        wpURL.setHost(QStringLiteral("%1.wikipedia.org").arg(langCode()));
        wpURL.setPath(QStringLiteral("/wiki/%1").arg(entry()));
    } else {

        QString enFallback;

        QMap<QString, QString> interWiki = reqTranslations(langCode(), entry());
        if (interWiki.contains(QStringLiteral("en"))) {
            enFallback = interWiki.value(QStringLiteral("en"));
        }

        while (!interWiki.contains(lang) && (interWiki[QStringLiteral("cont")] != QStringLiteral(""))) {

            interWiki = reqTranslations(langCode(), entry(), interWiki[QStringLiteral("cont")]);

            if (interWiki.contains(QStringLiteral("en"))) {
                enFallback = interWiki.value(QStringLiteral("en"));
            }
        }

        if (interWiki.contains(lang)) {
            wpURL.setHost(QStringLiteral("%1.wikipedia.org").arg(lang));
            wpURL.setPath(QStringLiteral("/wiki/%1").arg(interWiki[lang]));
        } else if (!enFallback.isEmpty()) {
            wpURL.setHost(QStringLiteral("en.wikipedia.org"));
            wpURL.setPath(QStringLiteral("/wiki/%1").arg(enFallback));
        } else {
            wpURL.setHost(QStringLiteral("%1.wikipedia.org").arg(langCode()));
            wpURL.setPath(QStringLiteral("/wiki/%1").arg(entry()));
        }

#ifdef QT_DEBUG
        qDebug() << "Wikipedia URL: " << wpURL;
#endif

    }

    setUrl(wpURL);
}
Exemple #3
0
WebFetch::WebFetch(QUrl url, QObject *obj, const char *slot) : QObject(), qoObject(obj), cpSlot(slot) {
	url.setScheme(QLatin1String("http"));

	// Fix in case the regional host is broken
	url.setHost(g.s.qsRegionalHost);
	if (url.host() != g.s.qsRegionalHost)
		url.setHost(QLatin1String("mumble.info"));

	qnr = Network::get(url);
	connect(qnr, SIGNAL(finished()), this, SLOT(finished()));
	connect(this, SIGNAL(fetched(QByteArray,QUrl,QMap<QString,QString>)), obj, slot);
}
Exemple #4
0
  void TcpAddress::Init(const QString &ip, int port)
  {
    bool valid = true;

    if(port < 0 || port > 65535) {
      qWarning() << "Invalid port:" << port;
      valid = false;
    }

    QHostAddress host(ip);
    if(host.toString() != ip) {
      qWarning() << "Invalid IP:" << ip;
      valid = false;
    }

    if(host == QHostAddress::Null) {
      host = QHostAddress::Any;
    }

    QUrl url;
    url.setScheme(Scheme);
    url.setHost(ip);
    url.setPort(port);

    _data = new TcpAddressData(url, host, port, valid);
  }
Exemple #5
0
static QUrl getApiUrl(BtsApi_private *p, const QString &method, const QueryList &querylist = QueryList())
{
	assertClient(p);

	QUrl res;

	res.setScheme("http");

	res.setHost(p->client->getHost());
	res.setPort(p->client->getPort());

	if(!p->client->getUserName().isEmpty())
		res.setUserName(p->client->getUserName());

	if(!p->client->getPassword().isEmpty())
		res.setPassword(p->client->getPassword());

	res.setPath("/api");

	QUrlQuery urlQuery;
	urlQuery.addQueryItem("method", method);

	for(const QueryPair &qp: querylist)
	{
		if(qp.second.isNull())
			urlQuery.addQueryItem(qp.first, "");
		else
			urlQuery.addQueryItem(qp.first, qp.second);
	}

	res.setQuery(urlQuery);

	return res;
}
MsgPartNetworkReply::MsgPartNetworkReply(MsgPartNetAccessManager *parent, const QPersistentModelIndex &part, bool requireFormatting):
    QNetworkReply(parent), part(part), formattedBufferContent(0), requireFormatting(requireFormatting)
{
    QUrl url;
    url.setScheme(QLatin1String("trojita-imap"));
    url.setHost(QLatin1String("msg"));
    url.setPath(part.data(Imap::Mailbox::RolePartPathToPart).toString());
    setUrl(url);

    setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
    Q_ASSERT(part.isValid());
    const Mailbox::Model *model = 0;
    Mailbox::Model::realTreeItem(part, &model);
    Q_ASSERT(model);

    connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotModelDataChanged(QModelIndex,QModelIndex)));

    //TODO: fileDownloadProgress signal in model signal the process of the current download.
    //      This reply might not be the current download, but now we assume that because the only use case here
    //      is just see the download progress of attachments that is usually the only downloading event.
    //      Should match message UID and partId and then emit downloadProgress.
    connect(model, SIGNAL(fileDownloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64,qint64)));

    Mailbox::TreeItemPart *partPtr = dynamic_cast<Mailbox::TreeItemPart *>(static_cast<Mailbox::TreeItem *>(part.internalPointer()));
    Q_ASSERT(partPtr);

    // We have to ask for contents before we check whether it's already fetched
    partPtr->fetch(const_cast<Mailbox::Model *>(model));
    // The part data might be already unavailable or already fetched
    QTimer::singleShot(0, this, SLOT(slotMyDataChanged()));

    buffer.setBuffer(partPtr->dataPtr());
    buffer.open(QIODevice::ReadOnly);
}
Exemple #7
0
QUrl DesktopDevice::toolControlChannel(const ControlChannelHint &) const
{
    QUrl url;
    url.setScheme(Utils::urlTcpScheme());
    url.setHost("localhost");
    return url;
}
MsgPartNetworkReply::MsgPartNetworkReply(MsgPartNetAccessManager *parent, const QPersistentModelIndex &part):
    QNetworkReply(parent), part(part)
{
    QUrl url;
    url.setScheme(QStringLiteral("trojita-imap"));
    url.setHost(QStringLiteral("msg"));
    url.setPath(part.data(Imap::Mailbox::RolePartPathToPart).toString());
    setUrl(url);

    setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
    Q_ASSERT(part.isValid());

    connect(part.model(), &QAbstractItemModel::dataChanged, this, &MsgPartNetworkReply::slotModelDataChanged);

    // We have to ask for contents before we check whether it's already fetched
    part.data(Imap::Mailbox::RolePartData);

    // The part data might be already unavailable or already fetched
    QTimer::singleShot(0, this, SLOT(slotMyDataChanged()));

    QByteArray* bufferPtr = part.data(Imap::Mailbox::RolePartBufferPtr).value<QByteArray*>();
    Q_ASSERT(bufferPtr);
    buffer.setBuffer(bufferPtr);
    buffer.open(QIODevice::ReadOnly);
}
Exemple #9
0
int Url::setHost ( lua_State * L )// ( const QString & host )
{
	QUrl* lhs = ValueInstaller2<QUrl>::check( L, 1 );
	//QString* host = ValueInstaller2<QString>::check( L, 2 );
	lhs->setHost( Util::toString( L, 2 ) );
	return 0;
}
Exemple #10
0
void MumbleDBus::getCurrentUrl(const QDBusMessage &msg) {
	if (!g.sh || !g.sh->isRunning() || ! g.uiSession) {
		QDBusConnection::sessionBus().send(msg.createErrorReply(QLatin1String("net.sourceforge.mumble.Error.connection"), QLatin1String("Not connected")));
		return;
	}
	QString host, user, pw;
	unsigned short port;
	QUrl u;

	g.sh->getConnectionInfo(host, port, user, pw);
	u.setScheme(QLatin1String("mumble"));
	u.setHost(host);
	u.setPort(port);
	u.setUserName(user);

#if QT_VERSION >= 0x050000
	QUrlQuery query;
	query.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
	u.setQuery(query);
#else
	u.addQueryItem(QLatin1String("version"), QLatin1String("1.2.0"));
#endif

	QStringList path;
	Channel *c = ClientUser::get(g.uiSession)->cChannel;
	while (c->cParent) {
		path.prepend(c->qsName);
		c = c->cParent;
	}
	u.setPath(path.join(QLatin1String("/")));
	QDBusConnection::sessionBus().send(msg.createReply(QString::fromLatin1(u.toEncoded())));
}
void
SendLogsRequest::send()
{
    QUrl url;
    url.setScheme( "http" );
    url.setHost( "oops.last.fm" );
    url.setPath( "logsubmission/add" );
    url.addEncodedQueryItem( "username", QUrl::toPercentEncoding(Ws::Username) );
    #ifdef Q_WS_MAC
        url.addQueryItem( "platform", "macosx" );
    #elif defined WIN32
        url.addQueryItem( "platform", "win32" );
    #else
        url.addQueryItem( "platform", "linux" );
    #endif
    url.addQueryItem( "clientname", QCoreApplication::applicationName() );
    url.addQueryItem( "clientversion", QCoreApplication::applicationVersion() );

    QNetworkRequest request = QNetworkRequest( url );
    request.setRawHeader( "Content-Type", "multipart/form-data;boundary=8e61d618ca16" );
    request.setRawHeader( "Accept", "*/*" );

    m_data.append( postData( "usernotes", escapeString( m_usernotes ).toLatin1() ) );
    m_data.append( postData( "logs", m_logs.join(",").toLatin1() ) );
    m_data.append( "--8e61d618ca16--" ); // close the post request
    
    m_error = false;
    QNetworkReply *reply = (new WsAccessManager( this ))->post( request, m_data );
    
    connect( reply, SIGNAL( finished() ),
             this, SLOT( onFinished() ) );
    connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
             this, SLOT( onError( QNetworkReply::NetworkError ) ) );
}
Exemple #12
0
    /* The parse function is invoked after the loadFinished signal is received 
     * from  the webkit code upon successfully parsing a page. From here, the 
     * entire DOM can be manipulated and traversed really conveniently. The 
     * code right now just traverses the DOM looking for link tags, and queues 
     * them if they are valid, but this function is where all of the 
     * interesting development will take place in the future. 
     */
   void Parser::parse() {
      QUrl currentUrl;
      QWebElementCollection linkTags =
         page->mainFrame()->findAllElements("a");

      foreach(QWebElement current, linkTags) {
         currentUrl = QUrl(current.attribute("href"));
         /* This discards the fragment. It is useless in this context and
          * will complicate our visited hashtable.
          */
         currentUrl.setEncodedFragment(QByteArray());

         if (currentUrl.isEmpty()) {
            continue;
         }

         /* Prepend the parent URL if we have a relative link in an attempt
          * to validate it for retrieval.
          */
         if (currentUrl.isRelative() &&
            currentUrl.host() == "" && currentUrl.path() != "") {
            qDebug() << currentUrl << " is relative path. prepending host";
            currentUrl.setHost(url.host());
            currentUrl.setScheme(url.scheme());
            qDebug() << "with host fix: " << currentUrl;
         }

         /* Finally, check to make sure it's valid before queueing it */
         if (validateUrl(currentUrl)) {
            parsedUrls.push_back(currentUrl);
         }
      }
Exemple #13
0
void MainWidget::hostLookuped(QHostInfo hostInfo)
{
    m_v4Addr.clear();
    m_v6Addr.clear();

    qDebug() << "ipV6 addresses:";
    for( auto address: hostInfo.addresses()){
        if( address.protocol() == QAbstractSocket::IPv6Protocol ){
            qDebug() << "  " << address;
            m_v6Addr = address;
            break;
        }
    }
    qDebug() << "ipV4 addresses:";
    for( auto address: hostInfo.addresses()){
        if( address.protocol() == QAbstractSocket::IPv4Protocol ){
            qDebug() << "  " << address;
            m_v4Addr = address;
            break;
        }
    }

    if(! m_v6Addr.isNull()){
        QUrl url;
        url.setScheme("http");
        url.setHost(m_v6Addr.toString());
        qDebug() << "request to " << url;

        connect(m_naman,SIGNAL(finished(QNetworkReply*)),
                this,SLOT(replyFinishedV6(QNetworkReply*)));
        m_naman->get(QNetworkRequest(url));
    }
void BookmarksRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action)
{
    Q_UNUSED(context);
    const QString term = action.data().toString();
    QUrl url = QUrl(term);

    //support urls like "kde.org" by transforming them to http://kde.org
    if (url.scheme().isEmpty()) {
        const int idx = term.indexOf('/');

        url.clear();
        url.setHost(term.left(idx));
        if (idx != -1) {
            //allow queries
            const int queryStart = term.indexOf('?', idx);
            int pathLength = -1;
            if ((queryStart > -1) && (idx < queryStart)) {
                pathLength = queryStart - idx;
                url.setQuery(term.mid(queryStart));
            }

            url.setPath(term.mid(idx, pathLength));
        }
        url.setScheme(QStringLiteral("http"));
    }

    KToolInvocation::invokeBrowser(url.url());
}
void PatMainWindow::setRubyProxyEnvironment(const QNetworkProxy &t_proxy)
{
  OS_ASSERT(t_proxy.type() == QNetworkProxy::NoProxy || t_proxy.type() == QNetworkProxy::HttpProxy);

  if (t_proxy.type() == QNetworkProxy::NoProxy)
  {
    LOG(Info, "Clearing proxy environment variables");
    bool set = qputenv("HTTP_PROXY", QByteArray());
    OS_ASSERT(set);
    set = qputenv("HTTP_PROXY_USER", QByteArray());
    OS_ASSERT(set);
    set = qputenv("HTTP_PROXY_PASS", QByteArray());
    OS_ASSERT(set);
    set = qputenv("HTTP_USER", QByteArray());
    OS_ASSERT(set);
    set = qputenv("HTTP_PASS", QByteArray());
    OS_ASSERT(set);
  } else if (t_proxy.type() == QNetworkProxy::HttpProxy) {
    LOG(Info, "Clearing proxy environment variables");
    QUrl urlsimple;
    urlsimple.setHost(t_proxy.hostName());
    urlsimple.setPort(t_proxy.port());
    urlsimple.setScheme("http");
    bool set = qputenv("HTTP_PROXY", urlsimple.toString().toLatin1());
    OS_ASSERT(set);
    set = qputenv("HTTP_PROXY_USER", t_proxy.user().toLatin1());
    OS_ASSERT(set);
    set = qputenv("HTTP_PROXY_PASS", t_proxy.password().toLatin1());
    OS_ASSERT(set);
    set = qputenv("HTTP_USER", t_proxy.user().toLatin1());
    OS_ASSERT(set);
    set = qputenv("HTTP_PASS", t_proxy.password().toLatin1());
    OS_ASSERT(set);
  }
}
void WebInspectorWidget::webPageSelected(int index)
{
  QObject *obj = ui->webPageComboBox->itemData(index, ObjectModel::ObjectRole).value<QObject*>();

  // Wk 1, local
  if (QWebPage *page = qobject_cast<QWebPage*>(obj)) {
    page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
    ui->webInspector->setPage(page);
    // webinspector needs a show event to actually show anything, just setting the page is not enough...
    ui->webInspector->hide();
    ui->webInspector->show();

    ui->stack->setCurrentWidget(ui->wk1LocalPage);
  }

  else if (ui->webPageComboBox->itemData(index, WebViewModel::WebKitVersionRole).toInt() == 2) {
    const QUrl serverUrl = Endpoint::instance()->serverAddress();
    if (serverUrl.scheme() == QLatin1String("tcp")) {
      QUrl inspectorUrl;
      inspectorUrl.setScheme(QStringLiteral("http"));
      inspectorUrl.setHost(serverUrl.host());
      inspectorUrl.setPort(Endpoint::defaultPort() + 1);
      ui->webView->setUrl(inspectorUrl);
      ui->stack->setCurrentWidget(ui->wk2Page);
    }
  }

  // WK1, remote
  else {
    ui->stack->setCurrentWidget(ui->wk1RemotePage);
  }
}
Exemple #17
0
void TsFactory::TestMakeParser()
{
  try
  {
    //test postgis uri
    QUrl postgisUri;
    postgisUri.setScheme("postgis");
    postgisUri.setHost("localhost");
    postgisUri.setPort(5432);
    postgisUri.setUserName("postgres");
    postgisUri.setPassword("postgres");
    postgisUri.setPath("/basedeteste");

    terrama2::core::DataSetItem unknownTypeItem(terrama2::core::DataSetItem::UNKNOWN_TYPE);

    //FIXME: create a DataSetItem kind for ParserPostgis
//    terrama2::collector::ParserPtr parser = terrama2::collector::Factory::makeParser(unknownTypeItem);
//    terrama2::collector::ParserPostgis* parserPostgis = dynamic_cast<terrama2::collector::ParserPostgis*>(parser.get());
//    QVERIFY(parserPostgis);

    QUrl fileUri;
    fileUri.setScheme("file");
    fileUri.setPath("/tmp");

    terrama2::collector::ParserPtr parser = terrama2::collector::Factory::makeParser(unknownTypeItem);
    terrama2::collector::ParserOGR* parserOGR = dynamic_cast<terrama2::collector::ParserOGR*>(parser.get());
    QVERIFY(parserOGR);

    terrama2::core::DataSetItem pcdInpeTypeItem(terrama2::core::DataSetItem::PCD_INPE_TYPE);
    parser = terrama2::collector::Factory::makeParser(pcdInpeTypeItem);
    terrama2::collector::ParserPcdInpe* parserPdcInpe = dynamic_cast<terrama2::collector::ParserPcdInpe*>(parser.get());
    QVERIFY(parserPdcInpe);

    terrama2::core::DataSetItem pcdToaTypeItem(terrama2::core::DataSetItem::PCD_TOA5_TYPE);
    parser = terrama2::collector::Factory::makeParser(pcdToaTypeItem);
    terrama2::collector::ParserPcdToa5* parserPdctoa5 = dynamic_cast<terrama2::collector::ParserPcdToa5*>(parser.get());
    QVERIFY(parserPdctoa5);

    terrama2::core::DataSetItem firePointTypeItem(terrama2::core::DataSetItem::FIRE_POINTS_TYPE);
    parser = terrama2::collector::Factory::makeParser(firePointTypeItem);
    terrama2::collector::ParserFirePoint* parserFirePoint = dynamic_cast<terrama2::collector::ParserFirePoint*>(parser.get());
    QVERIFY(parserFirePoint);

    try
    {
      terrama2::core::DataSetItem diseaseTypeItem(terrama2::core::DataSetItem::DISEASE_OCCURRENCE_TYPE);
      parser = terrama2::collector::Factory::makeParser(diseaseTypeItem);

      QFAIL(NO_EXCEPTION_THROWN);
    }
    catch(terrama2::collector::ConflictingParserTypeSchemeException& e)
    {

    }
  }
  catch(...)
  {
    QFAIL(NO_EXCEPTION_EXPECTED);
  }
}
Exemple #18
0
void requester::go()
{
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(manager, SIGNAL(finished(QNetworkReply*)),
        this, SLOT(replyFinished(QNetworkReply*)));

    QUrl url;
    url.setScheme("http");
    url.setHost("192.168.121.129");
    url.setPath("/cgi-bin/tilecache.cgi");
    url.setQueryDelimiters('=', '&');
    url.addQueryItem("layers", "osm");
    url.addQueryItem("service", "mapnik");
    url.addQueryItem("version", "1.1.1");
    url.addQueryItem("request", "GetMap");
    url.addQueryItem("bbox", "-78271.51696402048, 6653078.941941741, 0.0, 6731350.458905762");

    QNetworkRequest request(url);

    timer_.start();

    counter_ = 100;
    for (int i = 0; i < counter_; ++i)
        manager->get(request);                                      
}
Exemple #19
0
        KJob *UPnPRouter::sendSoapQuery(const QString & query,const QString & soapact,const QString & controlurl)
        {
            // if port is not set, 0 will be returned
            // thanks to Diego R. Brogna for spotting this bug
            if (location.port()<=0)
                location.setPort(80);

            QUrl address;

            address.setScheme(QString("http"));
            address.setHost(location.host());
            address.setPort(location.port());
            address.setPath(controlurl);

            KIO::TransferJob *req = KIO::http_post( address, query.toLatin1(), KIO::HideProgressInfo );

            req->addMetaData("content-type", QString("text/xml"));
            req->addMetaData("UserAgent", QString("Konversation UPnP"));
            req->addMetaData("customHTTPHeader", QString("SOAPAction: ") + soapact);

            soap_data_out[req] = QByteArray();
            soap_data_in[req]  = QByteArray();

            connect(req, &KIO::TransferJob::data, this, &UPnPRouter::recvSoapData);
            connect(req, &KIO::TransferJob::dataReq, this, &UPnPRouter::sendSoapData);

            connect(req, &KIO::TransferJob::result, this, &UPnPRouter::onRequestFinished);

            return req;
        }
Exemple #20
0
void AccessManager::slotAuthenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator)
{
#ifndef TOKEN_AUTH_ONLY
    // do not handle 401 created by the networkjobs. We may want
    // to eventually exempt some, but for now we need
    // it only for other things, e.g. the browser. Would we handle
    // network jobs, this would break the wizard logic
    if (reply->property("doNotHandleAuth").toBool()) {
        return;
    }
    QUrl url = reply->url();
    // show only scheme, host and port
    QUrl reducedUrl;
    reducedUrl.setScheme(url.scheme());
    reducedUrl.setHost(url.host());
    reducedUrl.setPort(url.port());

    AuthenticationDialog dialog(authenticator->realm(), reducedUrl.toString());
    if (dialog.exec() == QDialog::Accepted) {
        authenticator->setUser(dialog.user());
        authenticator->setPassword(dialog.password());
    }
#else
    Q_UNUSED(reply) Q_UNUSED(authenticator)
    Q_ASSERT(!"OCC::AccessManager::slotAuthenticationRequired called");
#endif
}
Exemple #21
0
Song & MagnatuneService::fixPath(Song &s) const
{
    s.type=Song::OnlineSvrTrack;
    if (MB_None!=membership) {
        QUrl url;
        #if QT_VERSION < 0x050000
        url.setEncodedUrl(s.file.toLocal8Bit());
        #else
        url=QUrl(s.file);
        #endif
        url.setScheme("http");
        url.setHost(MB_Streaming==membership ? constStreamingHostname : constDownloadHostname);
        url.setUserName(username);
        url.setPassword(password);

        // And remove the commercial
        QString path = url.path();
        path.insert(path.lastIndexOf('.'), "_nospeech");
        url.setPath(path);
        s.file=url.toString();
    // TODO: Magnatune downloads!
    //    if (MB_Download==membership) {
    //        s.genre=downloadTypeStr(download);
    //    }
    }
    s.setIsFromOnlineService(name());
    return encode(s);
}
Exemple #22
0
void SoundCloud::checkUrl(const QUrl &webUrl) {
    QUrl url;

    if (webUrl.hasQueryItem("client_id")) {
        url = webUrl;
        url.setHost("api.soundcloud.com");
    }
    else {
        url.setUrl("http://api.soundcloud.com/resolve.json");
#if QT_VERSION >= 0x050000
        QUrlQuery query(url);
        query.addQueryItem("url", webUrl.toString());
        query.addQueryItem("client_id", CLIENT_ID);
        url.setQuery(query);
#else
        url.addQueryItem("url", webUrl.toString());
        url.addQueryItem("client_id", CLIENT_ID);
#endif
    }

    QNetworkRequest request(url);
    QNetworkReply *reply = this->networkAccessManager()->get(request);
    this->connect(reply, SIGNAL(finished()), this, SLOT(checkUrlIsValid()));
    this->connect(this, SIGNAL(currentOperationCancelled()), reply, SLOT(deleteLater()));
}
LegacyTuner::LegacyTuner( const RadioStation& station, const QString& password_md5 )
    : m_retry_counter( 0 ),
      m_station( station )
{
#ifdef WIN32
    static const char *PLATFORM = "win32";
#elif defined Q_WS_X11
    static const char *PLATFORM = "linux";
#elif defined Q_WS_MAC
    static const char *PLATFORM = "mac";
#else
    static const char *PLATFORM = "unknown";
#endif

    QUrl url;
    url.setScheme( "http" );
    url.setHost( "ws.audioscrobbler.com" );
    url.setPath( "/radio/handshake.php" );
    url.addEncodedQueryItem( "version", QCoreApplication::applicationVersion().toAscii() );
    url.addEncodedQueryItem( "platform", PLATFORM );
    url.addEncodedQueryItem( "username", QUrl::toPercentEncoding(lastfm::ws::Username) );
    url.addEncodedQueryItem( "passwordmd5", password_md5.toAscii() );
    url.addEncodedQueryItem( "language", iso3166() );

    QNetworkRequest request( url );
    QNetworkReply* reply = lastfm::nam()->get( request );
    connect( reply, SIGNAL(finished()), SLOT(onHandshakeReturn()) );
}
DeviceManager::DeviceSetupStatus DevicePluginOsdomotics::setupDevice(Device *device)
{

    if (device->deviceClassId() == rplRouterDeviceClassId) {
        qCDebug(dcOsdomotics) << "Setup RPL router" << device->paramValue("host").toString();
        QHostAddress address(device->paramValue("host").toString());

        if (address.isNull()) {
            qCWarning(dcOsdomotics) << "Got invalid address" << device->paramValue("host").toString();
            return DeviceManager::DeviceSetupStatusFailure;
        }

        QUrl url;
        url.setScheme("http");
        url.setHost(address.toString());

        QNetworkReply *reply = networkManagerGet(QNetworkRequest(url));
        m_asyncSetup.insert(reply, device);

        return DeviceManager::DeviceSetupStatusAsync;
    } else if (device->deviceClassId() == merkurNodeDeviceClassId) {
        qCDebug(dcOsdomotics) << "Setup Merkur node" << device->paramValue("host").toString();
        device->setParentId(DeviceId(device->paramValue("router id").toString()));
        return DeviceManager::DeviceSetupStatusSuccess;
    }
    return DeviceManager::DeviceSetupStatusFailure;
}
Exemple #25
0
void SpotifyIO::loginReply()
{
    qDebug() << "resolver request";
    QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
    if (reply) {
        QByteArray data(reply->readAll());
        QVariantMap json = QJsonDocument::fromJson(data).toVariant().toMap();

        if (json["status"].toString() == "OK") {
            settings = json["config"].toMap();
            QVariantMap resolver = settings["aps"].toMap()["resolver"].toMap();

            QUrl url;
            url.setScheme("https");
            url.setHost(resolver["hostname"].toString());
            QUrlQuery query;
            query.addQueryItem("client", "24:0:0:" + settings["version"].toString());
            QString site = resolver["site"].toString();
            if (!site.isEmpty()) {
                query.addQueryItem("site", site);
            }
            url.setQuery(query);
            QNetworkRequest req(url);
            req.setHeader(QNetworkRequest::UserAgentHeader, userAgent);
            QObject::connect(nam->get(req), SIGNAL(finished()), this, SLOT(resolverReply()));
        }
        else {
            qDebug() << json["error"];
            Q_EMIT authFailed(json["error"].toString());

            _state = DisconnectedState;
            Q_EMIT stateChanged();
        }
    }
}
VkLoginDialog::VkLoginDialog(QWidget *parent) : QDialog(parent)
{
    qDebug() << __FUNCTION__;
    QUrl url;
    url.setScheme("https");
    url.setHost("oauth.vk.com");
    url.setPath("/authorize");

    QUrlQuery urlQuery;
    urlQuery.addQueryItem("client_id", "5042372");
    urlQuery.addQueryItem("display", "page");
    urlQuery.addQueryItem("redirect_uri", "https://oauth.vk.com/blank.html");
    urlQuery.addQueryItem("response_type", "token");
    urlQuery.addQueryItem("v", "5.37");
    urlQuery.addQueryItem("scope", "audio");
    url.setQuery(urlQuery);

    QWebView *webView = new QWebView(this);
    webView->load(url);

    connect(webView, SIGNAL(urlChanged(QUrl)), this, SLOT(getTokenFromUrl(QUrl)));

    QGridLayout *layout = new QGridLayout(this);
    layout->addWidget(webView);
}
Exemple #27
0
    CddbConnection(cddb_disc_t *d) : disc(0) {
        connection = cddb_new();
        if (connection) {
            cddb_cache_disable(connection);
            cddb_set_server_name(connection, Settings::self()->cddbHost().toLatin1().constData());
            cddb_set_server_port(connection, Settings::self()->cddbPort());
            disc=cddb_disc_clone(d);
#ifdef ENABLE_KDE_SUPPORT
            QString proxy=KProtocolManager::proxyFor("http");
            if (!proxy.isEmpty()) {
                QUrl url(proxy);
                cddb_set_http_proxy_server_name(connection, url.host().toLatin1().constData());
                cddb_set_http_proxy_server_port(connection, url.port());
                cddb_http_proxy_enable(connection);
            }
#else
            QUrl url;
            url.setHost(Settings::self()->cddbHost());
            url.setPort(Settings::self()->cddbPort());
            QList<QNetworkProxy> proxies=NetworkProxyFactory::self()->queryProxy(QNetworkProxyQuery(url));

            foreach (const QNetworkProxy &p, proxies) {
                if (QNetworkProxy::HttpProxy==p.type() && 0!=p.port()) {
                    cddb_set_http_proxy_server_name(connection, p.hostName().toLatin1().constData());
                    cddb_set_http_proxy_server_port(connection, p.port());
                    cddb_http_proxy_enable(connection);
                    break;
                }
            }
#endif
        }
    }
void TsDataRetrieverFTP::TestOKDownloadFile()
{
  try
  {
    QUrl url;
    url.setHost("ftp.dgi.inpe.br");
    url.setPath("/focos_operacao/");
    url.setScheme("FTP");
    url.setPort(21);
    url.setUserName("queimadas");
    url.setPassword("inpe_2012");

    curl_global_init(CURL_GLOBAL_ALL);

    //DataProvider information
    terrama2::core::DataProvider* dataProvider = new terrama2::core::DataProvider();
    terrama2::core::DataProviderPtr dataProviderPtr(dataProvider);
    dataProvider->uri = url.url().toStdString();
    dataProvider->intent = terrama2::core::DataProviderIntent::COLLECTOR_INTENT;
    dataProvider->dataProviderType = "FTP";
    dataProvider->active = true;

    //empty filter
    terrama2::core::Filter filter;
    std::string path;
    std::string mask = "exporta_20160501_0230.csv";

    MockCurlWrapper mock_;

    ON_CALL(mock_, verifyURL(_)).WillByDefault(Return(CURLE_OK));
    ON_CALL(mock_, getDownloadFiles(_,_,_)).WillByDefault(Return(CURLE_OK));

    try
    {
      terrama2::core::DataRetrieverFTP retrieverFTP(dataProviderPtr, std::move(mock_));
      auto remover = std::make_shared<terrama2::core::FileRemover>();
      path = retrieverFTP.retrieveData(mask, filter, remover);
    }
    catch(...)
    {
      QFAIL("Unexpected exception!");
    }

    curl_global_cleanup();

  }
  catch(const terrama2::Exception& e)
  {
    QFAIL(boost::get_error_info< terrama2::ErrorDescription >(e)->toStdString().c_str());
  }

  catch(...)
  {
    QFAIL("Unexpected exception!");
  }

  return;

}
Exemple #29
0
QUrl TestHTTPServer::baseUrl() const
{
    QUrl url;
    url.setScheme(QStringLiteral("http"));
    url.setHost(QStringLiteral("127.0.0.1"));
    url.setPort(server.serverPort());
    return url;
}
Exemple #30
0
void ConnectPage::launchClient()
{
  QUrl url;
  url.setScheme("tcp");
  url.setHost(ui->host->text());
  url.setPort(ui->port->value());
  ClientLauncher::launchDetached(url);
}