# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=qownnotes
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=24.10.4
pkgrel=1
pkgdesc="Plain-text file markdown note taking with Nextcloud/ownCloud integration"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qownnotes.org/'
msys2_repository_url='https://github.com/pbek/QOwnNotes/'
msys2_references=(
  'aur: qownnotes'
)
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-svg"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-openssl"
  "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
  "${MINGW_PACKAGE_PREFIX}-aspell"
  "${MINGW_PACKAGE_PREFIX}-qt6-5compat"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
source=("https://github.com/pbek/QOwnNotes/releases/download/v${pkgver}/qownnotes-${pkgver}.tar.xz")
sha256sums=('fa325c2daa5c6ee6f88297d1751b8ffd2ee7a056ee9981ca4369d24553072450')

build() {
  cd "${_realname}-${pkgver}"

  qmake6 \
    QMAKE_CFLAGS_RELEASE="${CFLAGS}" \
    QMAKE_CXXFLAGS_RELEASE="${CXXFLAGS}" \
    QMAKE_LFLAGS_RELEASE="${LDFLAGS}"
  make
}

package() {
  cd "${_realname}-${pkgver}"

  # install application
  install -D -m755 release/QOwnNotes.exe "${pkgdir}${MINGW_PREFIX}/bin/QOwnNotes.exe"

  # install visuals
  install -D -m644 PBE.QOwnNotes.desktop "${pkgdir}${MINGW_PREFIX}/share/applications/PBE.QOwnNotes.desktop"
  for format in {16x16,24x24,32x32,48x48,64x64,96x96,128x128,256x256,512x512}; do
    install -D -m644 "images/icons/${format}/apps/QOwnNotes.png" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/$format/apps/QOwnNotes.png"
  done
  install -D -m644 "images/icons/scalable/apps/QOwnNotes.svg" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/scalable/apps/QOwnNotes.svg"

  # install languages (it looks for "qt5" even in the qt6 build)
  install -d "${pkgdir}${MINGW_PREFIX}/share/qt5/translations/"
  install -D -m644 languages/*.qm "${pkgdir}${MINGW_PREFIX}/share/qt5/translations/"
}
