# Maintainer (Arch): schuay <jakob.gruber@gmail.com>
# Contributor (Arch): Ray Powell <ray_al@xphoniexx.net>
# Maintainer (Hyperbola): André Silva <emulatorman@hyperbola.info>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
# Contributor: bill-auger <bill-auger@programmer.net>

pkgname=mcomix
pkgver=1.3.0.dev0
pkgrel=3
pkgrel+=.parabola1
pkgdesc="A user-friendly, customizable image viewer specifically designed to handle comic books"
pkgdesc+=", without non-free RAR support"
arch=('any')
url="https://github.com/multiSnow/mcomix3"
license=('GPL')
depends=('gtk3' 'python-cairo' 'python-gobject' 'python-pillow')
makedepends=('git')
optdepends=('mupdf-tools: for pdf comics'
            'p7zip: for 7zip compressed comics')
_commit=a95f08140fc8850890f283bc06e3e2615477d736  # HEAD as of 20200528.
source=("git+https://github.com/multiSnow/mcomix3.git#commit=$_commit"
        'libre.patch')
sha256sums=('SKIP'
            '8566f979b4d56866074f22a44ee31f6904dac6ef802fa88413cedd82ee752721')

prepare() {
  cd mcomix3

  # Remove nonfree unRAR support
  rm -v mcomix/mcomix/archive/rar{,_external}.py
  patch -Np1 -i ${srcdir}/libre.patch
}

package() {
  cd mcomix3

  python installer.py --srcdir=mcomix --target="${pkgdir}"/usr/share

  install -dm755 "$pkgdir"/usr/bin
  ln -s /usr/share/mcomix/mcomixstarter.py "$pkgdir"/usr/bin/mcomix
  ln -s /usr/share/mcomix/comicthumb.py "$pkgdir"/usr/bin/comicthumb

  install -Dm644 mime/mcomix.desktop "$pkgdir"/usr/share/applications/mcomix.desktop
  install -Dm644 mime/mcomix.appdata.xml "$pkgdir"/usr/share/metainfo/mcomix.appdata.xml
  install -Dm644 mime/comicthumb.thumbnailer "$pkgdir"/usr/share/thumbnailers/comicthumb.thumbnailer

  for size in 16x16 22x22 24x24 32x32 48x48
  do
    install -dm755 "$pkgdir"/usr/share/icons/hicolor/$size/apps/
    install -Dm644 mcomix/mcomix/images/$size/mcomix.png "$pkgdir"/usr/share/icons/hicolor/$size/apps/mcomix.png
    install -Dm644 mime/icons/$size/application-x-cb7.png "$pkgdir"/usr/share/icons/hicolor/$size/mimetypes/application-x-cb7.png
    install -Dm644 mime/icons/$size/application-x-cbt.png "$pkgdir"/usr/share/icons/hicolor/$size/mimetypes/application-x-cbt.png
  done

  install -Dm644 man/mcomix.1 "$pkgdir"/usr/share/man/man1/mcomix.1
  install -Dm644 man/comicthumb.1 "$pkgdir"/usr/share/man/man1/comicthumb.1
}
