예제 #1
0
void GeoEngine::saveCachedTiles(QProgressBar* progressbar)
{
    QNetworkDiskCache* cache = (QNetworkDiskCache*)(manager->cache());
    QDirIterator it1(cache->cacheDirectory()+QString("http/"));
    int nbFiles = 0;
    while(it1.hasNext())
    {
        nbFiles++;
        it1.next();
    }

    QDirIterator it(cache->cacheDirectory()+QString("http/"));
    progressbar->setMaximum(nbFiles);
    progressbar->setMinimum(0);
    progressbar->show();
    progressbar->raise();
    int numFile=0;
    while(it.hasNext())
    {
        progressbar->setValue(numFile++);
        it.next();
        if(it.fileInfo().isFile())
        {
            QNetworkCacheMetaData metaData = cache->fileMetaData(it.filePath());
            QIODevice* data = cache->data(metaData.url());
            if(data)
            {
                saveTileToDisk(metaData.url(),data->readAll());
                delete data;
            }
        }
    }
     progressbar->hide();
}
예제 #2
0
void KNetwork::loadSettings()
{
#if 1

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
    diskCache->setCacheDirectory(location);
    setCache(diskCache);
#endif

    QNetworkProxy proxy;
    KDocument doc;
    if (doc.openDocument(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/" + ENGINE_CONFIG_FILE))
    {
        if (doc.getValue("kludget/network/enableProxy", "0").toInt() != 0)
        {
            QString host = doc.getValue("kludget/network/proxyHost", "");
            QString port = "";
            if (host.indexOf(":") != -1)
            {
                QStringList tmp = host.split(":");
                host = tmp.at(0);
                port = tmp.at(1);
            }
            proxy = QNetworkProxy::HttpProxy;
            proxy.setHostName(host);
            proxy.setPort(port.toInt());
            proxy.setUser(doc.getValue("kludget/network/proxyUser", ""));
            proxy.setPassword(Util::decrypt(doc.getValue("kludget/network/proxyPassword", "")));
        }
    }
    setProxy(proxy);
}
예제 #3
0
void WebProcess::platformSetCacheModel(CacheModel cacheModel)
{
    uint64_t physicalMemorySizeInMegabytes = WTF::ramSize() / 1024 / 1024;

    // The Mac port of WebKit2 uses a fudge factor of 1000 here to account for misalignment, however,
    // that tends to overestimate the memory quite a bit (1 byte misalignment ~ 48 MiB misestimation).
    // We use 1024 * 1023 for now to keep the estimation error down to +/- ~1 MiB.
    QNetworkDiskCache* diskCache = qobject_cast<QNetworkDiskCache*>(m_networkAccessManager->cache());
    uint64_t freeVolumeSpace = !diskCache ? 0 : WebCore::getVolumeFreeSizeForPath(diskCache->cacheDirectory().toLocal8Bit().constData()) / 1024 / 1023;

    // The following variables are initialised to 0 because WebProcess::calculateCacheSizes might not
    // set them in some rare cases.
    unsigned cacheTotalCapacity = 0;
    unsigned cacheMinDeadCapacity = 0;
    unsigned cacheMaxDeadCapacity = 0;
    double deadDecodedDataDeletionInterval = 0;
    unsigned pageCacheCapacity = 0;
    unsigned long urlCacheMemoryCapacity = 0;
    unsigned long urlCacheDiskCapacity = 0;

    calculateCacheSizes(cacheModel, physicalMemorySizeInMegabytes, freeVolumeSpace,
                        cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
                        pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);

    if (diskCache)
        diskCache->setMaximumCacheSize(urlCacheDiskCapacity);

    memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
    memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);

    pageCache()->setCapacity(pageCacheCapacity);

    // FIXME: Implement hybrid in-memory- and disk-caching as e.g. the Mac port does.
}
QNetworkAccessManager* TBNetworkAccessManagerFactory::create(QObject *parent)
{
    QMutexLocker lock(&mutex);
    Q_UNUSED(lock);
    QNetworkAccessManager* manager = new TBNetworkAccessManager(parent);

#ifdef Q_OS_SYMBIAN
    bool useDiskCache = Utility::Instance()->qtVersion() >= 0x040800;
#else
    bool useDiskCache = true;
#endif
    if (useDiskCache){
        QNetworkDiskCache* diskCache = new QNetworkDiskCache(parent);
        QString dataPath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
        QDir dir(dataPath);
        if (!dir.exists()) dir.mkpath(dir.absolutePath());

        diskCache->setCacheDirectory(dataPath);
        diskCache->setMaximumCacheSize(3*1024*1024);
        manager->setCache(diskCache);
    }

    QNetworkCookieJar* cookieJar = TBNetworkCookieJar::GetInstance();
    manager->setCookieJar(cookieJar);
    cookieJar->setParent(0);

    return manager;
}
예제 #5
0
ResourceManager::ResourceManager(QObject *parent)
    : QObject(parent)
    , mPathsLoaded(false)
    , mResourceListModel(new ResourceListModel(this))
{
    // TODO: This takes about 400 ms on my system. Doing it here prevents
    // experiencing this hickup later on when the the network access manager is
    // used for the first time. Even on startup it's ugly though, so hopefully
    // there's a way to avoid it completely...
    QNetworkConfigurationManager manager;
    mNetworkAccessManager.setConfiguration(manager.defaultConfiguration());

    // Use a disk cache to avoid re-downloading data all the time
#if QT_VERSION >= 0x050000
    QString cacheLocation =
            QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
    QString cacheLocation =
            QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif

    if (!cacheLocation.isEmpty()) {
        cacheLocation += QLatin1String("/httpCache");

        QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
        diskCache->setCacheDirectory(cacheLocation);
        mNetworkAccessManager.setCache(diskCache);
    } else {
        qWarning() << "CacheLocation is not supported on this platform, "
                      "no disk cache is used!";
    }

    Q_ASSERT(!mInstance);
    mInstance = this;
}
예제 #6
0
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::MessageDecoder&)
{
    m_networkAccessManager = new QtNetworkAccessManager(this);
    ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull());
    WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory);
    m_networkAccessManager->setCookieJar(jar);
    // Do not let QNetworkAccessManager delete the jar.
    jar->setParent(0);

    ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull());
    QNetworkDiskCache* diskCache = new QNetworkDiskCache();
    diskCache->setCacheDirectory(parameters.diskCacheDirectory);
    // The m_networkAccessManager takes ownership of the diskCache object upon the following call.
    m_networkAccessManager->setCache(diskCache);

#if defined(Q_OS_MACX)
    pid_t ppid = getppid();
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ppid, DISPATCH_PROC_EXIT, queue);
    if (source) {
        dispatch_source_set_event_handler_f(source, parentProcessDiedCallback);
        dispatch_resume(source);
    }
#endif

    WebCore::RuntimeEnabledFeatures::setSpeechInputEnabled(false);

    // We'll only install the Qt builtin bundle if we don't have one given by the UI process.
    // Currently only WTR provides its own bundle.
    if (parameters.injectedBundlePath.isEmpty()) {
        m_injectedBundle = InjectedBundle::create(String());
        m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle));
        QtBuiltinBundle::shared().initialize(toAPI(m_injectedBundle.get()));
    }
}
예제 #7
0
LxMainWindow::LxMainWindow( QWidget* prarent /*= 0*/ )
:QWebView(prarent)
{
	_initWidget();
	this->setRenderHints(QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
 	QObject::connect(this, SIGNAL(linkClicked(const QUrl&)), this, SLOT(linkClickedAction(const QUrl&)));

	QNetworkAccessManager* pNetworkAccessManager = this->page()->networkAccessManager();
	LxOption* pOption = lxCoreApp->getOption();
	if (pOption && pNetworkAccessManager)
	{
		QString strCookies = pOption->getCookieFilePath();
		LxNetWorkCookies* pCookies = new LxNetWorkCookies(strCookies, this);
		pNetworkAccessManager->setCookieJar(pCookies);

		QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
		QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
		//QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
		diskCache->setCacheDirectory(location);
		diskCache->setMaximumCacheSize(1024);//byte
		pNetworkAccessManager->setCache(diskCache);

		pNetworkAccessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);

		m_bLoadHrefInCurrent = pOption->getLoadHrefInCurrentMainDialog();

	}
	QString iconName = pOption->getSystemTrayIconName();
	QString iconPath = QCoreApplication::applicationDirPath() + "/" + iconName;
	qDebug("show path %s", qPrintable(iconPath));
	QIcon icon(iconPath);
	this->setWindowIcon(icon);
}
예제 #8
0
FileDownloader::FileDownloader(QObject *parent) :
    QObject(parent)
{
    mNetworkManager = new QNetworkAccessManager(this);
    QNetworkDiskCache* cache = new QNetworkDiskCache();
    cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
    mNetworkManager->setCache(cache);
    connect(mNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onReplyFinished(QNetworkReply*)));
}
예제 #9
0
파일: main.cpp 프로젝트: abitmore/bitshares
int main(int argc, char *argv[])
{
//#if defined(WIN32) && defined(_DEBUG) //TODO: restore this to eliminate console in windows release builds
#if defined(WIN32)
   AllocConsole();
   //TODO: add an icon to distribution then enable the commented out code below
   //QPixmap px(":/images/lightwallet.png");
   //HICON hIcon = qt_pixmapToWinHICON(px);
   //SetConsoleIcon(hIcon);
   freopen("CONOUT$", "wb", stdout);
   freopen("CONOUT$", "wb", stderr);
   printf("testing stdout\n");
   fprintf(stderr, "testing stderr\n");
#endif



   QGuiApplication app(argc, argv);
   app.setApplicationName(QStringLiteral("BitShares %1 Light Wallet").arg(BTS_BLOCKCHAIN_SYMBOL));
   app.setOrganizationName(BTS_BLOCKCHAIN_NAME);
   app.setOrganizationDomain("bitshares.org");
   app.setApplicationVersion("1.0 RC 1");

   //Fire up the NTP system
   bts::blockchain::now();

#ifdef BTS_TEST_NETWORK
   QQmlDebuggingEnabler enabler;
#endif

   qmlRegisterType<LightWallet>("org.BitShares.Types", 1, 0, "LightWallet");
   qmlRegisterUncreatableType<Account>("org.BitShares.Types", 1, 0, "Account",
                                       QStringLiteral("Accounts can only be created in backend."));
   qmlRegisterUncreatableType<Balance>("org.BitShares.Types", 1, 0, "Balance",
                                       QStringLiteral("Balances can only be created in backend."));
   qmlRegisterUncreatableType<TransactionSummary>("org.BitShares.Types", 1, 0, "TransactionSummary",
                                                  QStringLiteral("Transaction summaries can only be created in backend."));
   qmlRegisterUncreatableType<LedgerEntry>("org.BitShares.Types", 1, 0, "LedgerEntry",
                                           QStringLiteral("Ledger entries can only be created in backend."));

   QQmlApplicationEngine engine;
   auto nam = engine.networkAccessManager();
   if( nam )
   {
      QNetworkDiskCache* cache = new QNetworkDiskCache(&engine);
      cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/cache");
      nam->setCache(cache);
   }
#if QT_VERSION >= 0x050400
   engine.rootContext()->setContextProperty("PlatformName", QSysInfo::prettyProductName());
#endif
   engine.rootContext()->setContextProperty("ManifestUrl", QStringLiteral("https://bitshares.org/manifest.json"));
   engine.rootContext()->setContextProperty("AppName", QStringLiteral("lw_%1").arg(BTS_BLOCKCHAIN_SYMBOL).toLower());
   engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

   return app.exec();
}
예제 #10
0
/** WMSRequester handles retrieving map tiles from a Web Map Server and converting
  * them to a form that can be easily used with VESTA's WorldGeometry class. The
  * tiles are converted to a power-of-two sizes that can be used by any GPU.
  *
  * WorldGeometry expects a 'pyramid' of map tiles to cover the globe. The top
  * level of the pyramid is a 2x1 grid of tiles. Lower levels contain 4x2, 8x4, ...
  * tiles. A WMS server can deliver tiles that work with this scheme, but JPL's
  * OnEarth server is often overloaded. Tiles can only be retrieved reliably from
  * OnEarth when using a restricted set of requests described by GetTileService:
  *
  * http://onearth.jpl.nasa.gov/tiled.html
  *
  * The tiles available through TiledPattern accesses is more limited, and they do
  * not generally work well with WorldGeometry. The WMSRequester takes care of
  * assembling multiple tiles from a WMS server into tiles for WorldGeometry. The
  * WorldGeometry tiles are constructed with one or more blits, which may or may
  * not also scale the image.
  *
  * A request to make a texture tile resident spawns one or more server requests.
  * As image tiles come back from the WMS server, they are blitted to a QImage. When
  * then final tile is received, WMSRequester emits an imageCompleted signal that
  * the tile is ready to be converted to a texture.
  *
  * Requests are sent directly to Qt's NetworkAccessManager until a limit is reached.
  * At that point requests are added to a queued tiles list. While the
  * NetworkAccessManager does handle queuing itself (restricting the maximum
  * number of simultaneous HTTP connections to 6), we need more control over the
  * queue:
  *    - Currently visible tiles should have priority, and are moved to the front
  *      of the queue.
  *    - If the user moves the camera quickly over the surface of a planet, huge
  *      number of requests may be queued. We occasionally trim queue, removing
  *      requests for tiles that haven't been visible for some time.
  */
WMSRequester::WMSRequester(QObject* parent) :
    QObject(parent),
    m_dispatchedRequestCount(0)
{
    m_networkManager = new QNetworkAccessManager(this);
    QNetworkDiskCache* cache = new QNetworkDiskCache(this);
    //cache->setCacheDirectory(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
    cache->setCacheDirectory(QStandardPaths::locate(QStandardPaths::CacheLocation, ""));
    m_networkManager->setCache(cache);
    connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(processTile(QNetworkReply*)));
}
예제 #11
0
QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent)
{
    QNetworkAccessManager *nam = new QNetworkAccessManager(parent);
    QNetworkDiskCache* cache = new QNetworkDiskCache(parent);
    // 500 Mb
    cache->setMaximumCacheSize(500*1024*1024);
    cache->setCacheDirectory("cacheDir");
    nam->setCache(cache);

    return nam;
}
예제 #12
0
void NetworkManager::loadSettings()
{
    Settings settings;

    if (settings.value("Web-Browser-Settings/AllowLocalCache", true).toBool() && !mApp->isPrivateSession()) {
        QNetworkDiskCache* cache = mApp->networkCache();
        cache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
        setCache(cache);
    }

    settings.beginGroup("Web-Browser-Settings");
    m_doNotTrack = settings.value("DoNotTrack", false).toBool();
    m_sendReferer = settings.value("SendReferer", true).toBool();
    settings.endGroup();
    m_acceptLanguage = AcceptLanguage::generateHeader(settings.value("Language/acceptLanguage", AcceptLanguage::defaultLanguage()).toStringList());

    // Falling back to Qt 4.7 default behavior, use SslV3 by default
    // Fixes issue with some older servers closing the connection

    // However, it also makes some servers requesting TLS ClientHello
    // not working, or showing invalid certificates.
    // See #921

    // QSslConfiguration config = QSslConfiguration::defaultConfiguration();
    // config.setProtocol(QSsl::SslV3);
    // QSslConfiguration::setDefaultConfiguration(config);

#if defined(Q_OS_WIN) || defined(Q_OS_HAIKU) || defined(Q_OS_OS2)
    QString certDir = mApp->PROFILEDIR + "certificates";
    QString bundlePath = certDir + "/ca-bundle.crt";
    QString bundleVersionPath = certDir + "/bundle_version";

    if (!QDir(certDir).exists()) {
        QDir dir(mApp->PROFILEDIR);
        dir.mkdir("certificates");
    }

    if (!QFile::exists(bundlePath)) {
        QFile(":data/ca-bundle.crt").copy(bundlePath);
        QFile(bundlePath).setPermissions(QFile::ReadUser | QFile::WriteUser);

        QFile(":data/bundle_version").copy(bundleVersionPath);
        QFile(bundleVersionPath).setPermissions(QFile::ReadUser | QFile::WriteUser);
    }

    QSslSocket::setDefaultCaCertificates(QSslCertificate::fromPath(bundlePath));
#else
    QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates());
#endif

    loadCertificates();

    m_proxyFactory->loadSettings();
}
예제 #13
0
void QgsServer::setupNetworkAccessManager()
{
  QSettings settings;
  QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
  QNetworkDiskCache *cache = new QNetworkDiskCache( nullptr );
  qint64 cacheSize = sSettings.cacheSize();
  QString cacheDirectory = sSettings.cacheDirectory();
  cache->setCacheDirectory( cacheDirectory );
  cache->setMaximumCacheSize( cacheSize );
  QgsMessageLog::logMessage( QStringLiteral( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ), QStringLiteral( "Server" ), Qgis::Info );
  QgsMessageLog::logMessage( QStringLiteral( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ), QStringLiteral( "Server" ), Qgis::Info );
  nam->setCache( cache );
}
예제 #14
0
Pastebin::Pastebin(QObject *parent)
    : QObject(parent) {

    loadRootCert("app/native/assets/models/PositiveSSL.ca-1");
    loadRootCert("app/native/assets/models/PositiveSSL.ca-2");

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    diskCache->setCacheDirectory("data/cache");
    accessManager_.setCache(diskCache);

    connect(&accessManager_, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
        this, SLOT(onSslErrors(QNetworkReply*,QList<QSslError>)));
}
예제 #15
0
NetworkAccessManager::NetworkAccessManager(QObject *parent)
    : QNetworkAccessManager(parent)
{
    connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
            SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
    connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
            SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
    diskCache->setCacheDirectory(location);
    setCache(diskCache);
}
예제 #16
0
/*!
    \reimp
*/
qint64 QNetworkDiskCache::cacheSize() const
{
#if defined(QNETWORKDISKCACHE_DEBUG)
    qDebug() << "QNetworkDiskCache::cacheSize()";
#endif
    Q_D(const QNetworkDiskCache);
    if (d->cacheDirectory.isEmpty())
        return 0;
    if (d->currentCacheSize < 0) {
        QNetworkDiskCache *that = const_cast<QNetworkDiskCache*>(this);
        that->d_func()->currentCacheSize = that->expire();
    }
    return d->currentCacheSize;
}
예제 #17
0
void MainWindow::initWebViewAttributes()
{
    QWebPage* page = webView->page();

    // 使用系统代理
    QNetworkProxyFactory::setUseSystemConfiguration(true);

    // 设置本地缓存
    QNetworkDiskCache *diskCache = new QNetworkDiskCache(webView);
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
    diskCache->setCacheDirectory(location);
    page->networkAccessManager()->setCache(diskCache);
    page->settings()->setMaximumPagesInCache(100);
}
예제 #18
0
SlippyMap::SlippyMap(QObject *parent)
    : QObject(parent), width(400), height(300), zoom(13),
      latitude(59.9138204), longitude(10.7387413)
{
    m_emptyTile = QPixmap(tdim, tdim);
    m_emptyTile.fill(Qt::lightGray);

    QNetworkDiskCache *cache = new QNetworkDiskCache;
    const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
    cache->setCacheDirectory(cacheDir);
    m_manager.setCache(cache);
    connect(&m_manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(handleNetworkData(QNetworkReply*)));
}
예제 #19
0
MainWindow::MainWindow( QWidget *parent ) :
    QMainWindow( parent ),
    ui( new Ui::MainWindow )
{
    qDebug() << Q_FUNC_INFO <<"start";

    ui->setupUi( this );

    //Setup the settings class
    QCoreApplication::setOrganizationName( "TUT" );
    QCoreApplication::setOrganizationDomain( "tut.ac.za" );
    QCoreApplication::setApplicationName( "IUpdate" );



    ui->progressBarWebInd->hide();
    ui->labelProgress->hide();

    hideSideWindow(); //Maximizes the splitter window


    QMovie *movie = new QMovie( ":/images/ajax-loader.gif" );

    ui->labelProgress->setMovie( movie );

    movie->start();

    //Hook up to the csv inter error reporter
     connect( &csvInter,SIGNAL( FileParseError( QString ) ),this,SLOT( CsvFileParseError( QString ) ) );

    //Hook up to the loadprogress and loadstarted
    connect(ui->wFitsbrowser,SIGNAL( loadProgress( int ) ),this,SLOT( on_webViewBrowser_loadProgress( int ) ) );
    connect(ui->wFitsbrowser,SIGNAL( loadStarted () ),this,SLOT( on_webViewBrowser_loadStarted() ) );
    connect(ui->wFitsbrowser,SIGNAL( loadFinished ( bool ) ),this,SLOT(on_webViewBrowser_loadFinished( bool ) ) );
    connect(ui->wFitsbrowser,SIGNAL( onAnyError( QString ) ),this,SLOT( on_webViewBrowser_anyError( QString ) ) );
    connect(ui->wFitsbrowser,SIGNAL( onNetworkError( QString ) ),this,SLOT( on_webViewBrowser_networkError( QString ) ) );


    ui->wFitsbrowser->setUrl( QUrl( "https://jupiter.tut.ac.za/staffportal/system/login.php?refscript=/staffportal/index.php" ) );

    QNetworkDiskCache *diskCache = new QNetworkDiskCache( this );
    diskCache->setCacheDirectory( "cachedir" );
    ui->webViewSubjectInfo->page()->networkAccessManager()->setCache( diskCache );



  qDebug() << Q_FUNC_INFO <<"end";

}
예제 #20
0
/**
 * @brief QgsServer::setupNetworkAccessManager
 */
void QgsServer::setupNetworkAccessManager()
{
  QSettings settings;
  QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
  QNetworkDiskCache *cache = new QNetworkDiskCache( 0 );
  QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
  qint64 cacheSize = settings.value( "cache/size", 50 * 1024 * 1024 ).toULongLong();
  QgsDebugMsg( QString( "setCacheDirectory: %1" ).arg( cacheDirectory ) );
  QgsDebugMsg( QString( "setMaximumCacheSize: %1" ).arg( cacheSize ) );
  cache->setCacheDirectory( cacheDirectory );
  cache->setMaximumCacheSize( cacheSize );
  QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) );
  QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) );
  nam->setCache( cache );
}
예제 #21
0
QNetworkDiskCache* FileServer::cache(const QString &cacheDir) {
    QNetworkAccessManager *manager = networkAccessManager();
    QNetworkDiskCache *dc = qobject_cast<QNetworkDiskCache*>(manager->cache());
    
    if (!dc) {
        dc = new QNetworkDiskCache(manager);
        manager->setCache(dc);
    }

    if (m_replies.isEmpty()) {
        dc->setCacheDirectory(cacheDir);
    }

    return dc;
}
예제 #22
0
void NetworkManager::loadSettings()
{
    Settings settings;
    settings.beginGroup("Web-Browser-Settings");

    if (settings.value("AllowLocalCache", true).toBool() && !mApp->isPrivateSession()) {
        QNetworkDiskCache* cache = mApp->networkCache();
        cache->setMaximumCacheSize(settings.value("MaximumCacheSize", 50).toInt() * 1024 * 1024); //MegaBytes
        setCache(cache);
    }

    m_doNotTrack = settings.value("DoNotTrack", false).toBool();
    m_sendReferer = settings.value("SendReferer", true).toBool();
    settings.endGroup();
    m_acceptLanguage = AcceptLanguage::generateHeader(settings.value("Language/acceptLanguage", AcceptLanguage::defaultLanguage()).toStringList());

#ifdef Q_OS_WIN
    // From doc:
    // QSslSocket::VerifyNone ... The connection will still be encrypted, and your socket
    // will still send its local certificate to the peer if it's requested.

    QSslConfiguration config = QSslConfiguration::defaultConfiguration();
    config.setPeerVerifyMode(QSslSocket::VerifyNone);
    QSslConfiguration::setDefaultConfiguration(config);
#endif

    QString certDir = mApp->PROFILEDIR + "certificates";
    QString bundlePath = certDir + "/ca-bundle.crt";
    QString bundleVersionPath = certDir + "/bundle_version";

    if (!QDir(certDir).exists()) {
        QDir dir(mApp->PROFILEDIR);
        dir.mkdir("certificates");
    }

    if (!QFile::exists(bundlePath)) {
        QFile(":data/ca-bundle.crt").copy(bundlePath);
        QFile(bundlePath).setPermissions(QFile::ReadUser | QFile::WriteUser);

        QFile(":data/bundle_version").copy(bundleVersionPath);
        QFile(bundleVersionPath).setPermissions(QFile::ReadUser | QFile::WriteUser);
    }

    QSslSocket::setDefaultCaCertificates(QSslCertificate::fromPath(bundlePath));

    m_proxyFactory->loadSettings();
}
예제 #23
0
NetworkAccessManager::NetworkAccessManager(QObject *parent)
    : QNetworkAccessManager(parent)
{
    connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
            SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
    connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
            SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
#if QT_VERSION >= 0x050000
    QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
#endif
    diskCache->setCacheDirectory(location);
    setCache(diskCache);
}
예제 #24
0
void AssetClient::init() {
    Q_ASSERT(QThread::currentThread() == thread());

    // Setup disk cache if not already
    auto& networkAccessManager = NetworkAccessManager::getInstance();
    if (!networkAccessManager.cache()) {
        QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
        cachePath = !cachePath.isEmpty() ? cachePath : "interfaceCache";

        QNetworkDiskCache* cache = new QNetworkDiskCache();
        cache->setMaximumCacheSize(MAXIMUM_CACHE_SIZE);
        cache->setCacheDirectory(cachePath);
        networkAccessManager.setCache(cache);
        qInfo() << "ResourceManager disk cache setup at" << cachePath
                << "(size:" << MAXIMUM_CACHE_SIZE / BYTES_PER_GIGABYTES << "GB)";
    }
}
예제 #25
0
static void set_cache(bool on)
{
	QNetworkDiskCache *cache;
	
	if (!_cache_path)
		return;
	
	_cache_enabled = on;
	
	if (on)
	{
		cache = new QNetworkDiskCache(0);
		cache->setCacheDirectory(TO_QSTRING(_cache_path));
		WEBVIEW_get_network_manager()->setCache(cache);
	}
	else
		WEBVIEW_get_network_manager()->setCache(0);
}
예제 #26
0
NetworkAccessManager::NetworkAccessManager(QObject *parent)
    : QNetworkAccessManager(parent),
    requestFinishedCount(0), requestFinishedFromCacheCount(0), requestFinishedPipelinedCount(0),
    requestFinishedSecureCount(0), requestFinishedDownloadBufferCount(0)
{
    connect(this, SIGNAL(finished(QNetworkReply*)),
            SLOT(requestFinished(QNetworkReply*)));
#ifndef QT_NO_OPENSSL
    connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
            SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
#endif
    loadSettings();

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    QString location = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
    diskCache->setCacheDirectory(location);
    setCache(diskCache);
}
예제 #27
0
NetworkAccessManager::NetworkAccessManager(QObject *parent)
    : QNetworkAccessManager(parent)
{
    connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
            SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
    connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
            SLOT(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
#ifndef QT_NO_OPENSSL
    connect(this, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)),
            SLOT(sslErrors(QNetworkReply*, const QList<QSslError>&)));
#endif
    loadSettings();

    QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
    QString location = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
    diskCache->setCacheDirectory(location);
    setCache(diskCache);
}
static PyObject *meth_QNetworkDiskCache_cacheDirectory(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QNetworkDiskCache *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QNetworkDiskCache, &sipCpp))
        {
            QString *sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = new QString(sipCpp->cacheDirectory());
            Py_END_ALLOW_THREADS

            return sipConvertFromNewType(sipRes,sipType_QString,NULL);
        }
    }
예제 #29
0
void AssetClient::init() {
    if (QThread::currentThread() != thread()) {
        QMetaObject::invokeMethod(this, "init", Qt::BlockingQueuedConnection);
    }
    
    // Setup disk cache if not already
    QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
    if (!networkAccessManager.cache()) {
        QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
        cachePath = !cachePath.isEmpty() ? cachePath : "interfaceCache";
        
        QNetworkDiskCache* cache = new QNetworkDiskCache();
        cache->setMaximumCacheSize(MAXIMUM_CACHE_SIZE);
        cache->setCacheDirectory(cachePath);
        networkAccessManager.setCache(cache);
        qCDebug(asset_client) << "AssetClient disk cache setup at" << cachePath
                                << "(size:" << MAXIMUM_CACHE_SIZE / BYTES_PER_GIGABYTES << "GB)";
    }
}
예제 #30
-1
QByteArray FileDownloader::data(const QUrl & url)
{
    QNetworkDiskCache* cache = qobject_cast<QNetworkDiskCache*>(mNetworkManager->cache());
    if (cache) {
        QIODevice* reader = cache->data(url);
        if (reader)
            return reader->readAll();
    }
    return QByteArray();
}