# Contributor: Chocobo1 <https://github.com/Chocobo1>

_realname=qbittorrent
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=4.3.6
pkgrel=1
pkgdesc="An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://qbittorrent.org/"
license=('custom' 'GPL')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-libtorrent-rasterbar"
         "${MINGW_PACKAGE_PREFIX}-zlib")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: needed for torrent search tab")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("https://downloads.sourceforge.net/sourceforge/qbittorrent/${_realname}-${pkgver}.tar.xz"{,.asc}
        001-PROCESS_CLASS_INFORMATION-require-win8.patch
        002-winconf-prepare-env-for-mingw.patch)
sha256sums=('d3094fa799bb901b81df6e380974bf4e38602fe1a7bfb268013ddffa30a7b16f'
            'SKIP'
            'a89b2830259203734e30c02f40104bf2898ced576543a5b0edc559fe1884e0b4'
            '7c9fabb9cfc1b721803868be719daee448100ef97e8ba8fbd7b144e8af235bf3')
validpgpkeys=('D8F3DA77AAC6741053599C136E4A2D025B7CC9A2') # sledgehammer_999 <hammered999@gmail.com>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p0 -i ${srcdir}/001-PROCESS_CLASS_INFORMATION-require-win8.patch

  # prepare env for mingw
  # sed -i 's/unix:!macx:/unix|win32-g++:/g' "src/src.pro"
  # sed -i 's/!haiku/#!haiku/g' "unixconf.pri"
  patch -Np1 -i "${srcdir}/002-winconf-prepare-env-for-mingw.patch"
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-boost-system=boost_system-mt
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make INSTALL_ROOT=${pkgdir} install
  install -Dm644 "COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
