Ejemplo n.º 1
0
void BlFile::sync() {
  BL_FUNC_DEBUG  

//  if (!exists() {
  
      QFileInfo fileInfo(m_file);
      QString filename(fileInfo.fileName());
      
      QString user = g_confpr->value(CONF_LOGIN_USER);
      QString dbname = g_confpr->value(CONF_DBNAME);
    #ifdef Q_OS_WIN32
      QString platform = "MS_WIN";
    #else
      QString platform = "LINUX";
    #endif
      
      QString url = "http://www.bulmages.com/bulmaincloud/"+platform+"/"+user+"/"+dbname+"/"+filename;
      fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData());
      
      manager = new QNetworkAccessManager(this);
      QNetworkRequest request;
      request.setUrl(QUrl(url));
      request.setRawHeader("User-Agent", "BgBrowser 1.0");
    
      QNetworkReply *reply = manager->get(request);
      connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
      connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));

      connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
	    this, SLOT(slotError(QNetworkReply::NetworkError)));
      connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
	    this, SLOT(slotSslErrors(QList<QSslError>)));
      connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*)));

      while (reply->isRunning()) {
	QApplication::processEvents();
      } // end while
 
//  }// end if
 
      url = "http://www.bulmages.com/bulmaincloud/ALL/"+user+"/"+dbname+"/"+filename;
      fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData());
      request.setUrl(QUrl(url));
      reply = manager->get(request);
      while (reply->isRunning()) {
	QApplication::processEvents();
      } // end while
      if (reply->error() == QNetworkReply::NoError) {
	return;
      } // end if

      url = "http://www.bulmages.com/bulmaincloud/ALL/ALL/"+filename;
      fprintf(stderr, "Iniciando descarga %s\n", url.toLatin1().constData());
      request.setUrl(QUrl(url));
      reply = manager->get(request);
      while (reply->isRunning()) {
	QApplication::processEvents();
      } // end while
    
}
Ejemplo n.º 2
0
//链接请求
void ReqUtil::startRequest(QUrl url)
{

    reply = manager->get(QNetworkRequest(url));
    connect(reply,SIGNAL(finished()),this,SLOT(httpFinished()));  //下载完成后
    connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead())); //有可用数据时
    // 判断异常
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>)));

    connect(reply,SIGNAL(finished()),loop,SLOT(quit()));  // 退出循环
    loop->exec();
}
Ejemplo n.º 3
0
void ImapAccess::setSslMode(const QString &sslMode)
{
    m_sslMode = sslMode;
    Q_ASSERT(!m_imapModel);

    Imap::Mailbox::SocketFactoryPtr factory;
    Imap::Mailbox::TaskFactoryPtr taskFactory(new Imap::Mailbox::TaskFactory());

    if (m_sslMode == QLatin1String("SSL")) {
        QSettings().setValue(Common::SettingsNames::imapMethodKey, Common::SettingsNames::methodSSL);
        factory.reset(new Imap::Mailbox::SslSocketFactory(server(), port()));
    } else if (m_sslMode == QLatin1String("StartTLS")) {
        QSettings().setValue(Common::SettingsNames::imapMethodKey, Common::SettingsNames::methodTCP);
        QSettings().setValue(Common::SettingsNames::imapStartTlsKey, true);
        factory.reset(new Imap::Mailbox::TlsAbleSocketFactory(server(), port()));
        factory->setStartTlsRequired(true);
    } else {
        QSettings().setValue(Common::SettingsNames::imapMethodKey, Common::SettingsNames::methodTCP);
        QSettings().setValue(Common::SettingsNames::imapStartTlsKey, false);
        factory.reset(new Imap::Mailbox::TlsAbleSocketFactory(server(), port()));
    }

    // FIXME: respect the settings about the cache
    cache = new Imap::Mailbox::MemoryCache(this);

    m_imapModel = new Imap::Mailbox::Model(this, cache, factory, taskFactory, false);
    m_imapModel->setProperty("trojita-imap-enable-id", true);
    connect(m_imapModel, SIGNAL(alertReceived(QString)), this, SLOT(alertReceived(QString)));
    connect(m_imapModel, SIGNAL(connectionError(QString)), this, SLOT(connectionError(QString)));
    connect(m_imapModel, SIGNAL(logged(uint,Common::LogMessage)), this, SLOT(slotLogged(uint,Common::LogMessage)));
    connect(m_imapModel, SIGNAL(needsSslDecision(QList<QSslCertificate>,QList<QSslError>)),
            this, SLOT(slotSslErrors(QList<QSslCertificate>,QList<QSslError>)));

    m_imapModel->setImapUser(username());
    if (!m_password.isNull()) {
        // Really; the idea is to wait before it has been set for the first time
        m_imapModel->setImapPassword(password());
    }

    m_mailboxModel = new Imap::Mailbox::MailboxModel(this, m_imapModel);
    m_mailboxSubtreeModel = new Imap::Mailbox::SubtreeModelOfMailboxModel(this);
    m_mailboxSubtreeModel->setSourceModel(m_mailboxModel);
    m_mailboxSubtreeModel->setOriginalRoot();
    m_msgListModel = new Imap::Mailbox::MsgListModel(this, m_imapModel);
    m_visibleTasksModel = new Imap::Mailbox::VisibleTasksModel(this, m_imapModel->taskModel());
    m_oneMessageModel = new Imap::Mailbox::OneMessageModel(m_imapModel);
    m_msgQNAM = new Imap::Network::MsgPartNetAccessManager(this);
    emit modelsChanged();
}
Ejemplo n.º 4
0
void HTMLPage::Request()
{

    if (!manager)
        manager = new QNetworkAccessManager();

    QNetworkRequest request;
    request.setUrl(url);
    request.setRawHeader("User-Agent", "FireBox 1.0");

    reply = manager->get(request);

    connect(reply, SIGNAL(finished()), this, SLOT(slotFinished()));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
    connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>)));

    qDebug() << "Requesting" << url.toString();
}
Ejemplo n.º 5
0
void Delete::deleteEvent(const QString &uri) {
    QNetworkRequest request;
    QUrl url(mSettings->url() + uri );
    if (!mSettings->authToken().isEmpty()) {
        request.setRawHeader(QString("Authorization").toLatin1(),
                             QString("Bearer " + mSettings->authToken()).toLatin1());
    } else {
        url.setUserName(mSettings->username());
        url.setPassword(mSettings->password());
    }

    request.setUrl(url);
    mNReply = mNAManager->sendCustomRequest(request, REQUEST_TYPE.toLatin1());
    debugRequest(request, "");
    connect(mNReply, SIGNAL(finished()), this, SLOT(requestFinished()));
    connect(mNReply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(slotError(QNetworkReply::NetworkError)));
    connect(mNReply, SIGNAL(sslErrors(QList<QSslError>)),
            this, SLOT(slotSslErrors(QList<QSslError>)));

}
Ejemplo n.º 6
0
QXmppOutgoingServer::QXmppOutgoingServer(const QString &domain, QObject *parent)
    : QXmppStream(parent),
    d(new QXmppOutgoingServerPrivate)
{
    bool check;
    Q_UNUSED(check);

    // socket initialisation
    QSslSocket *socket = new QSslSocket(this);
    setSocket(socket);

    check = connect(socket, SIGNAL(disconnected()),
                    this, SLOT(_q_socketDisconnected()));
    Q_ASSERT(check);

    check = connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
                    this, SLOT(socketError(QAbstractSocket::SocketError)));
    Q_ASSERT(check);

    // DNS lookups
    check = connect(&d->dns, SIGNAL(finished()),
                    this, SLOT(_q_dnsLookupFinished()));
    Q_ASSERT(check);

    d->dialbackTimer = new QTimer(this);
    d->dialbackTimer->setInterval(5000);
    d->dialbackTimer->setSingleShot(true);
    check = connect(d->dialbackTimer, SIGNAL(timeout()),
                    this, SLOT(sendDialback()));
    Q_ASSERT(check);

    d->localDomain = domain;
    d->ready = false;

    check = connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
                    this, SLOT(slotSslErrors(QList<QSslError>)));
    Q_ASSERT(check);
}
Ejemplo n.º 7
0
QNetworkReply* QWebDAV::sendWebdavRequest(QUrl url, DAVType type,
                                          QByteArray verb, QIODevice *data,
                                          QString extra, QString extra2)
{
    // Prepare the network request and headers
    QNetworkRequest request;
    QNetworkReply *reply;
    request.setUrl(url);
    request.setRawHeader(QByteArray("Host"),url.host().toUtf8());

    qDebug() << "Sending " << type << "with url: " << url;

    // First, find out what type we want
    if( type == DAVLIST ) {
        // A PROPFIND can include 0, 1 or infinity
        QString depthString = extra;
        request.setRawHeader(QByteArray("Depth"),
                             QByteArray(depthString.toLatin1()));
        request.setAttribute(QNetworkRequest::User, QVariant("list"));
        request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User+
                                                        ATTDATA)
                             ,QVariant(mRequestNumber));
        request.setRawHeader(QByteArray("Content-Type"),
                             QByteArray("text/xml; charset=\"utf-8\""));
        request.setRawHeader(QByteArray("Content-Length"),QByteArray("99999"));

        reply = sendCustomRequest(request,verb,data);
    } else if ( type == DAVGET ) {
        request.setRawHeader("User-Agent", "QWebDAV 0.1");
        request.setAttribute(QNetworkRequest::User, QVariant("get"));
        reply = QNetworkAccessManager::get(request);
        connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                 this, SLOT(slotError(QNetworkReply::NetworkError)));
        connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
                 this, SLOT(slotSslErrors(QList<QSslError>)));
    } else if ( type == DAVPUT )  {
        request.setAttribute(QNetworkRequest::User, QVariant("put"));
        if ( mRequestFile.value(mRequestNumber) ) {
            request.setAttribute(QNetworkRequest::Attribute(
                                     QNetworkRequest::User+ATTFILE)
                                 ,QVariant(mRequestNumber));
            request.setAttribute(QNetworkRequest::Attribute(
                                     QNetworkRequest::User+ATTPREFIX)
                                 ,QVariant(extra.toLatin1()));
            if( extra2 != 0 ) {
                // We were given a lock token.
                request.setRawHeader(QByteArray("If"),
                                     QByteArray(extra2.toLatin1()));
            }
        } else {
            request.setAttribute(QNetworkRequest::Attribute(
                                     QNetworkRequest::User+ATTDATA)
                             ,QVariant(mRequestNumber));
        }
        reply = QNetworkAccessManager::put(request,data);
    } else if ( type == DAVMKCOL ) {
        request.setAttribute(QNetworkRequest::User, QVariant("mkcol"));
        reply = sendCustomRequest(request,verb,0);
    } else if ( type == DAVDELETE ) {
        request.setAttribute(QNetworkRequest::User, QVariant("delete"));
        reply = sendCustomRequest(request, verb,0);
    } else if ( type == DAVMOVE ) {
        request.setAttribute(QNetworkRequest::User, QVariant("move"));
        request.setRawHeader(QByteArray("Destination"),
                             QByteArray(extra.toLatin1()));
        request.setRawHeader(QByteArray("Overwrite"),
                             QByteArray("T"));
        if( extra2 != 0 ) {
            // We were given (a) lock token(s).
            request.setRawHeader(QByteArray("If"),
                                 QByteArray(extra2.toLatin1()));
            request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User+
                                                            ATTLOCKTYPE)
                                 ,QVariant(extra.replace(mHostname,"").toLatin1()));
        }
        reply = sendCustomRequest(request, verb,0);
    } else if ( type == DAVLOCK) {
        request.setAttribute(QNetworkRequest::User,
                             QVariant("lock"));
        // We don't bother setting a timeout, apparently the system defaults
        // to 5 minutes anyway.
        request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User+
                                                        ATTDATA)
                             ,QVariant(mRequestNumber));
        request.setAttribute(QNetworkRequest::Attribute(QNetworkRequest::User+
                                                        ATTLOCKTYPE)
                             ,QVariant(extra));

        reply = sendCustomRequest(request,verb,data);
    } else if ( type == DAVUNLOCK) {
        QString token = "<"+extra+">";
        request.setAttribute(QNetworkRequest::User,
                             QVariant("unlock"));
        request.setRawHeader(QByteArray("Lock-Token"),
                             QByteArray(token.toLatin1()));
        reply = sendCustomRequest(request,verb,0);
    } else {
        syncDebug() << "Error! DAV Request of type " << type << " is not known!";
        reply = 0;
    }

    // Connect the finished() signal!
    connectReplyFinished(reply);
    return reply;
}
manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
//! [0]


//! [1]
QNetworkRequest request;
request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");

QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
        this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
        this, SLOT(slotSslErrors(QList<QSslError>)));
//! [1]

//! [2]
QNetworkConfigurationManager manager;
networkAccessManager->setConfiguration(manager.defaultConfiguration());
//! [2]

//! [3]
networkAccessManager->setConfiguration(QNetworkConfiguration());
//! [3]

//! [4]
networkAccessManager->setNetworkAccessible(QNetworkAccessManager::NotAccessible);
//! [4]
Ejemplo n.º 9
0
void ImapAccess::doConnect()
{
    Q_ASSERT(!m_imapModel);

    Imap::Mailbox::SocketFactoryPtr factory;
    Imap::Mailbox::TaskFactoryPtr taskFactory(new Imap::Mailbox::TaskFactory());

    Streams::ProxySettings proxySettings = m_settings->value(Common::SettingsNames::imapUseSystemProxy, true).toBool() ?
                Streams::ProxySettings::RespectSystemProxy : Streams::ProxySettings::DirectConnect;

    switch (m_connectionMethod) {
    case Common::ConnectionMethod::Invalid:
        factory.reset(new Streams::FakeSocketFactory(Imap::CONN_STATE_LOGOUT));
        break;
    case Common::ConnectionMethod::NetCleartext:
    case Common::ConnectionMethod::NetStartTls:
        factory.reset(new Streams::TlsAbleSocketFactory(server(), port()));
        factory->setStartTlsRequired(m_connectionMethod == Common::ConnectionMethod::NetStartTls);
        factory->setProxySettings(proxySettings, QLatin1String("imap"));
        break;
    case Common::ConnectionMethod::NetDedicatedTls:
        factory.reset(new Streams::SslSocketFactory(server(), port()));
        factory->setProxySettings(proxySettings, QLatin1String("imap"));
        break;
    case Common::ConnectionMethod::Process:
        QStringList args = m_settings->value(Common::SettingsNames::imapProcessKey).toString().split(QLatin1Char(' '));
        if (args.isEmpty()) {
            // it's going to fail anyway
            args << QLatin1String("");
        }
        QString appName = args.takeFirst();
        factory.reset(new Streams::ProcessSocketFactory(appName, args));
        break;
    }

    bool shouldUsePersistentCache =
            m_settings->value(Common::SettingsNames::cacheOfflineKey).toString() != Common::SettingsNames::cacheOfflineNone;

    if (shouldUsePersistentCache && !QDir().mkpath(m_cacheDir)) {
        onCacheError(tr("Failed to create directory %1").arg(m_cacheDir));
        shouldUsePersistentCache = false;
    }

    if (shouldUsePersistentCache) {
        QFile::Permissions expectedPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;
        if (QFileInfo(m_cacheDir).permissions() != expectedPerms) {
            if (!QFile::setPermissions(m_cacheDir, expectedPerms)) {
#ifndef Q_OS_WIN32
                onCacheError(tr("Failed to set safe permissions on cache directory %1").arg(m_cacheDir));
                shouldUsePersistentCache = false;
#endif
            }
        }
    }

    Imap::Mailbox::AbstractCache *cache = 0;

    if (!shouldUsePersistentCache) {
        cache = new Imap::Mailbox::MemoryCache(this);
    } else {
        cache = new Imap::Mailbox::CombinedCache(this, QLatin1String("trojita-imap-cache"), m_cacheDir);
        connect(cache, SIGNAL(error(QString)), this, SLOT(onCacheError(QString)));
        if (! static_cast<Imap::Mailbox::CombinedCache *>(cache)->open()) {
            // Error message was already shown by the cacheError() slot
            cache->deleteLater();
            cache = new Imap::Mailbox::MemoryCache(this);
        } else {
            if (m_settings->value(Common::SettingsNames::cacheOfflineKey).toString() == Common::SettingsNames::cacheOfflineAll) {
                cache->setRenewalThreshold(0);
            } else {
                const int defaultCacheLifetime = 30;
                bool ok;
                int num = m_settings->value(Common::SettingsNames::cacheOfflineNumberDaysKey, defaultCacheLifetime).toInt(&ok);
                if (!ok)
                    num = defaultCacheLifetime;
                cache->setRenewalThreshold(num);
            }
        }
    }

    m_imapModel = new Imap::Mailbox::Model(this, cache, std::move(factory), std::move(taskFactory));
    m_imapModel->setObjectName(QString::fromUtf8("imapModel-%1").arg(m_accountName));
    m_imapModel->setCapabilitiesBlacklist(m_settings->value(Common::SettingsNames::imapBlacklistedCapabilities).toStringList());
    m_imapModel->setProperty("trojita-imap-enable-id", m_settings->value(Common::SettingsNames::imapEnableId, true).toBool());
    connect(m_imapModel, SIGNAL(alertReceived(QString)), this, SLOT(alertReceived(QString)));
    connect(m_imapModel, SIGNAL(imapError(QString)), this, SLOT(imapError(QString)));
    connect(m_imapModel, SIGNAL(networkError(QString)), this, SLOT(networkError(QString)));
    //connect(m_imapModel, SIGNAL(logged(uint,Common::LogMessage)), this, SLOT(slotLogged(uint,Common::LogMessage)));
    connect(m_imapModel, SIGNAL(needsSslDecision(QList<QSslCertificate>,QList<QSslError>)),
            this, SLOT(slotSslErrors(QList<QSslCertificate>,QList<QSslError>)));

    if (m_settings->value(Common::SettingsNames::imapNeedsNetwork, true).toBool()) {
        m_netWatcher = new Imap::Mailbox::SystemNetworkWatcher(this, m_imapModel);
    } else {
        m_netWatcher = new Imap::Mailbox::DummyNetworkWatcher(this, m_imapModel);
    }
    QMetaObject::invokeMethod(m_netWatcher,
                              m_settings->value(Common::SettingsNames::imapStartOffline).toBool() ?
                                  "setNetworkOffline" : "setNetworkOnline",
                              Qt::QueuedConnection);

    m_imapModel->setImapUser(username());
    if (!m_password.isNull()) {
        // Really; the idea is to wait before it has been set for the first time
        m_imapModel->setImapPassword(password());
    }

    m_mailboxModel = new Imap::Mailbox::MailboxModel(this, m_imapModel);
    m_mailboxModel->setObjectName(QString::fromUtf8("mailboxModel-%1").arg(m_accountName));
    m_mailboxSubtreeModel = new Imap::Mailbox::SubtreeModelOfMailboxModel(this);
    m_mailboxSubtreeModel->setObjectName(QString::fromUtf8("mailboxSubtreeModel-%1").arg(m_accountName));
    m_mailboxSubtreeModel->setSourceModel(m_mailboxModel);
    m_mailboxSubtreeModel->setOriginalRoot();
    m_msgListModel = new Imap::Mailbox::MsgListModel(this, m_imapModel);
    m_msgListModel->setObjectName(QString::fromUtf8("msgListModel-%1").arg(m_accountName));
    m_visibleTasksModel = new Imap::Mailbox::VisibleTasksModel(this, m_imapModel->taskModel());
    m_visibleTasksModel->setObjectName(QString::fromUtf8("visibleTasksModel-%1").arg(m_accountName));
    m_oneMessageModel = new Imap::Mailbox::OneMessageModel(m_imapModel);
    m_oneMessageModel->setObjectName(QString::fromUtf8("oneMessageModel-%1").arg(m_accountName));
    m_msgQNAM = new Imap::Network::MsgPartNetAccessManager(this);
    m_msgQNAM->setObjectName(QString::fromUtf8("m_msgQNAM-%1").arg(m_accountName));
    m_threadingMsgListModel = new Imap::Mailbox::ThreadingMsgListModel(this);
    m_threadingMsgListModel->setObjectName(QString::fromUtf8("threadingMsgListModel-%1").arg(m_accountName));
    m_threadingMsgListModel->setSourceModel(m_msgListModel);
    emit modelsChanged();
}
Ejemplo n.º 10
0
void KDSoapClientInterfacePrivate::setupReply(QNetworkReply *reply)
{
    if (m_ignoreSslErrors) {
        QObject::connect(reply, SIGNAL(sslErrors(const QList<QSslError>&)), reply, SLOT(ignoreSslErrors()));
    } else {
#ifndef QT_NO_OPENSSL
        if (m_sslHandler) {
            QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), m_sslHandler, SLOT(slotSslErrors(QList<QSslError>)));
        }
#endif
    }
}