# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
# Contributor: William Rea <sillywilly@gmail.com>

pkgname=gpsbabel
pkgver=1.6.0
_pkgver=1_6_0
pkgrel=2
pkgdesc="Read, write and manipulate GPS waypoints in a variety of formats"
arch=('x86_64')
url="https://www.gpsbabel.org/"
license=('GPL')
depends=('hicolor-icon-theme' 'libusb-compat' 'qt5-base') # 'qt5-webengine'
makedepends=('imagemagick' 'qt5-tools')
source=(https://github.com/gpsbabel/$pkgname/archive/${pkgname}_$_pkgver.tar.gz
        gpsbabel.appdata.xml
        desktop-file.patch
        drop-map.patch)
sha256sums=('ad56796f725dcdb7f52d9a9509d4922f11198c382fe10fc2d6c9efa8159f2090'
            '5eb52ab0c4bdde61c747856e849f9bce9ca660e942c15f730a4330a38fd6a39a'
            'e66a786dc5592388f651f2bcabb4205809a42e0a937bb034cb469bd2cd50d1a1'
            '5377f1a6f0d52d93f7d604c171ce1f6b18bb389c9e4c67ff4910c4079a2696fd')

prepare() {
  cd $pkgname-${pkgname}_$_pkgver

  # Correct name of Exec in desktop file
  # https://github.com/gpsbabel/gpsbabel/pull/353
  patch -Np1 -i ../desktop-file.patch

  # Remove map due to heavy WebEngine dependency
  patch -Np1 -i ../drop-map.patch

  # Fix path
  sed -i 's|langPath_ = QApplication::applicationDirPath();|langPath_ = "/usr/share/gpsbabel";|' gui/mainwindow.cc
  sed -i 's|baseFile =  QApplication::applicationDirPath() + "/gmapbase.html";|baseFile = "/usr/share/gpsbabel/gmapbase.html";|' gui/map.cc

  convert gui/images/appicon.png +set date:create +set date:modify -background none -gravity center -extent 512x512 gui/images/appicon.png
}

build() {
  cd $pkgname-${pkgname}_$_pkgver
  ./configure --prefix=/usr
  make

  # GUI
  cd gui
  qmake-qt5
  lrelease-qt5 *.ts
  make
}

package() {
  cd $pkgname-${pkgname}_$_pkgver
  make DESTDIR="$pkgdir" install

  # GUI
  install -Dm755 gui/objects/gpsbabelfe "$pkgdir"/usr/bin/gpsbabelfe
  install -Dm644 gui/images/appicon.png "$pkgdir"/usr/share/icons/hicolor/512x512/apps/gpsbabel.png
  install -Dm644 gui/gpsbabel.desktop "$pkgdir"/usr/share/applications/gpsbabel.desktop
  install -Dm644 ../$pkgname.appdata.xml "$pkgdir/usr/share/metainfo/$pkgname.appdata.xml"
  install -Dm644 gui/gmapbase.html "$pkgdir"/usr/share/gpsbabel/gmapbase.html
  install -dm755 "$pkgdir"/usr/share/gpsbabel/translations/
  install -Dm644 gui/*.qm "$pkgdir"/usr/share/gpsbabel/translations/
}
