From 9f1f99f4db3bd757b8e40af07e8e9e1b48a6e09e Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Tue, 4 Sep 2018 20:59:25 +0200
Subject: [PATCH 1/3] Add a WebFlowCredentialsAccessManager

Fixes #279

Some setups don't make Qt emit the right signals and the client would
end up in state where it could not do the initial authentications.
This is a similar hack that apparently already was is place for basic
http auth.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 src/gui/creds/webflowcredentials.cpp | 31 +++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp
index 2b70c5328..fc3370c8d 100644
--- a/src/gui/creds/webflowcredentials.cpp
+++ b/src/gui/creds/webflowcredentials.cpp
@@ -24,6 +24,35 @@ namespace OCC {
 
 Q_LOGGING_CATEGORY(lcWebFlowCredentials, "sync.credentials.webflow", QtInfoMsg)
 
+class WebFlowCredentialsAccessManager : public AccessManager
+{
+public:
+    WebFlowCredentialsAccessManager(const WebFlowCredentials *cred, QObject *parent = nullptr)
+        : AccessManager(parent)
+        , _cred(cred)
+    {
+    }
+
+protected:
+    QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData) Q_DECL_OVERRIDE
+    {
+        QNetworkRequest req(request);
+        if (!req.attribute(HttpCredentials::DontAddCredentialsAttribute).toBool()) {
+            if (_cred && !_cred->password().isEmpty()) {
+                QByteArray credHash = QByteArray(_cred->user().toUtf8() + ":" + _cred->password().toUtf8()).toBase64();
+                req.setRawHeader("Authorization", "Basic " + credHash);
+            }
+        }
+
+        return AccessManager::createRequest(op, req, outgoingData);
+    }
+
+private:
+    // The credentials object dies along with the account, while the QNAM might
+    // outlive both.
+    QPointer<const WebFlowCredentials> _cred;
+};
+
 WebFlowCredentials::WebFlowCredentials()
     : _ready(false),
       _credentialsValid(false)
@@ -56,7 +85,7 @@ QString WebFlowCredentials::password() const {
 
 QNetworkAccessManager *WebFlowCredentials::createQNAM() const {
     qCInfo(lcWebFlowCredentials()) << "Get QNAM";
-    AccessManager *qnam = new AccessManager();
+    AccessManager *qnam = new WebFlowCredentialsAccessManager(this);
 
     connect(qnam, &AccessManager::authenticationRequired, this, &WebFlowCredentials::slotAuthentication);
     connect(qnam, &AccessManager::finished, this, &WebFlowCredentials::slotFinished);

From 2bfb99f174249b3f6f48c386eab7622f81d39e9a Mon Sep 17 00:00:00 2001
From: Oskar Kruschitz <okr@huemer-it.com>
Date: Wed, 5 Sep 2018 11:57:26 +0200
Subject: [PATCH 2/3] Mac Application Icon

Replaced ownCloud.icns with APPLICATION_ICON_NAME variable
---
 NextcloudCPack.cmake                    | 2 +-
 cmake/modules/MacOSXBundleInfo.plist.in | 2 +-
 src/gui/CMakeLists.txt                  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/NextcloudCPack.cmake b/NextcloudCPack.cmake
index 0a506b945..2edb205e1 100644
--- a/NextcloudCPack.cmake
+++ b/NextcloudCPack.cmake
@@ -19,7 +19,7 @@ if(APPLE)
     set( CPACK_GENERATOR "DragNDrop" )
     set( CPACK_SOURCE_GENERATOR "")
     set( CPACK_PACKAGE_FILE_NAME ${APPLICATION_SHORTNAME}-${CPACK_PACKAGE_VERSION} )
-    set( CPACK_PACKAGE_ICON ${CMAKE_BINARY_DIR}/src/gui/ownCloud.icns)
+    set( CPACK_PACKAGE_ICON ${CMAKE_BINARY_DIR}/src/gui/${APPLICATION_ICON_NAME}.icns)
 
     set( CPACK_DMG_DS_STORE "${CMAKE_SOURCE_DIR}/admin/osx/DS_Store.in")
 #    set( CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/admin/osx/DMGBackground.png" )
diff --git a/cmake/modules/MacOSXBundleInfo.plist.in b/cmake/modules/MacOSXBundleInfo.plist.in
index 5b8f3388a..62e30cbbe 100644
--- a/cmake/modules/MacOSXBundleInfo.plist.in
+++ b/cmake/modules/MacOSXBundleInfo.plist.in
@@ -11,7 +11,7 @@
         <key>CFBundleExecutable</key>
         <string>@APPLICATION_EXECUTABLE@</string>
         <key>CFBundleIconFile</key>
-        <string>ownCloud.icns</string>
+        <string>@APPLICATION_ICON_NAME@.icns</string>
         <key>CFBundleIdentifier</key>
         <string>@APPLICATION_REV_DOMAIN@</string>
         <key>CFBundleInfoDictionaryVersion</key>
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index 05a93f556..4684e9117 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -272,7 +272,7 @@ if(NOT BUILD_OWNCLOUD_OSX_BUNDLE)
     add_executable( ${APPLICATION_EXECUTABLE} WIN32 main.cpp ${final_src})
 else()
     # set(CMAKE_INSTALL_PREFIX ".") # Examples use /Applications. hurmpf.
-    set(MACOSX_BUNDLE_ICON_FILE "ownCloud.icns")
+    set(MACOSX_BUNDLE_ICON_FILE "${APPLICATION_ICON_NAME}.icns")
 
     # we must add MACOSX_BUNDLE only if building a bundle
     add_executable( ${APPLICATION_EXECUTABLE} WIN32 MACOSX_BUNDLE main.cpp ${final_src})

From 23d276021e42382e5ed9c2137657eb539933a8f8 Mon Sep 17 00:00:00 2001
From: Camila Ayres <hello@camila.codes>
Date: Wed, 5 Sep 2018 13:23:58 +0200
Subject: [PATCH 3/3] Updates README cmake instruction for Windows.

Signed-off-by: Camila San <hello@camila.codes>
---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 0feca92e9..df72496f4 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ you want to install system wide you could use `/usr/local` or `/opt/nextcloud/`.
 ##### Linux
 
 ```
-$ cmake .. -DCMAKE_INSTALL_PREFIX=path-to-install-folder/ -DCMAKE_BUILD_TYPE=Debug -DNO_SHIBBOLETH=1
+$ cmake "-GVisual Studio 15 2017 Win64" .. -DCMAKE_INSTALL_PREFIX=path-to-install-folder/ -DCMAKE_BUILD_TYPE=Debug -DNO_SHIBBOLETH=1 -DPng2Ico_EXECUTABLE=/path-to-install-png2ico/png2ico.exe  -DQTKEYCHAIN_LIBRARY=/path-to-qt5keychain-folder/lib/qt5keychain.lib -DQTKEYCHAIN_INCLUDE_DIR=/path-to-qt5keychain-folder/include/qt5keychain/ -DOPENSSL_ROOT_DIR=/path-to-openssl-folder/ -DOPENSSL_INCLUDE_DIR=path-to-openssl-folder/include -DOPENSSL_LIBRARIES=path-to-openssl-folder/lib
 $ make install
 ```