Mercurial > trustbridge
diff ui/downloader.cpp @ 11:7e2f14c7aba2
Split up downloader component and further implement it
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 14 Feb 2014 11:20:15 +0000 |
parents | fe39d93f1261 |
children | 9121eea6d93f |
line wrap: on
line diff
--- a/ui/downloader.cpp Thu Feb 13 14:43:15 2014 +0000 +++ b/ui/downloader.cpp Fri Feb 14 11:20:15 2014 +0000 @@ -1,16 +1,10 @@ #include "downloader.h" -#ifndef MYVERSION -#define MYVERSION "1" -#endif - #ifndef DOWNLOAD_SERVER #define DOWNLOAD_SERVER "https://www.intevation.de" #endif #ifdef Q_OS_WIN -#include <windows.h> -#include <winhttp.h> #endif #include <QFile> @@ -18,7 +12,9 @@ Downloader::Downloader(QObject* parent, const QString& url) { - Downloader (parent, url, QFile(":Certificates/https").readAll()); + QFile certResource(":certificates/https"); + certResource.open(QFile::ReadOnly); + Downloader (parent, url, certResource.readAll()); } Downloader::Downloader(QObject* parent, const QString& url, @@ -29,91 +25,3 @@ { } -void Downloader::run() { -#ifdef Q_OS_WIN - // We use WinAPI here instead of Qt because we want to avoid - // QtNetworks SSL stack which is based on OpenSSL and so - // we might be incompatible with GPL code. Also using the - // native API means that the security of the SSL implementation - // is tied to the security of the system. - BOOL bResults = FALSE; - HINTERNET hSession = NULL, - hConnect = NULL, - hRequest = NULL; - SYSTEMTIME lastModified; - DWORD sizeOfSystemtime = sizeof (SYSTEMTIME); - - // Get a syncronous session handle - hSession = WinHttpOpen(L"M13 "MYVERSION, - WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, 0); - - if (hSession) { - // Initialize connection. No request is done here. - hConnect = WinHttpConnect(hSession, L""DOWNLOAD_SERVER, - INTERNET_DEFAULT_HTTPS_PORT, 0); - - } - - if (hConnect) { - // Make a head request - hRequest = WinHttpOpenRequest(hConnect, L"HEAD", - L"/index.html", - NULL, WINHTTP_NO_REFERER, - WINHTTP_DEFAULT_ACCEPT_TYPES, - 0); - } - - if (hRequest) { - bResults = WinHttpSendRequest(hRequest, - WINHTTP_NO_ADDITIONAL_HEADERS, - 0, WINHTTP_NO_REQUEST_DATA, 0, - 0, 0); - } - - if (bResults) { - bResults = WinHttpReceiveResponse(hRequest, NULL); - } - - - - if (bResults) { - bResults = WinHttpQueryHeaders(hRequest, - WINHTTP_QUERY_LAST_MODIFIED | - WINHTTP_QUERY_FLAG_SYSTEMTIME, - NULL, - &lastModified, - &sizeOfSystemtime, - WINHTTP_NO_HEADER_INDEX ); - } - - qDebug() << "Last modified year: " << lastModified.wYear; - - - if (!bResults) { - // Report any errors. - qDebug() << "Error" << GetLastError(); - emit error(tr("Unknown Problem when connecting"), Unknown); - } - - // Cleanup - if (hRequest) { - WinHttpCloseHandle(hRequest); - } - - if (hConnect) { - WinHttpCloseHandle(hConnect); - - } - - if (hSession) { - WinHttpCloseHandle(hSession); - } -#endif - - for (int i=0; i< 10; i++) { - qDebug("Going to sleep\n"); - sleep(10); - } -}