# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1
PortGroup           github 1.0

name                photoqt
# 4.x requires Qt6, poppler-qt6 and fails with our exiv2:
# https://trac.macports.org/ticket/69366
# https://github.com/luspi/photoqt/issues/22
github.setup        luspi photoqt 3.4 v
revision            3
categories          graphics
license             GPL-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer

description         PhotoQt Image Viewer
long_description    PhotoQt is a simple yet powerful and good looking image viewer, based on Qt/QML, \
                    published as open-source and completely free.
homepage            https://photoqt.org

depends_lib-append  port:desktop-file-utils \
                    port:exiv2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:shared-mime-info

if {${subport} eq "${name}"} {
    PortGroup       qt5 1.0

    conflicts       photoqt-qt4
    platforms       {darwin > 10}
    checksums       rmd160  884155ef964f60ac886e8e7b20001878cc23888e \
                    sha256  bd26133640f523a34e71f4a5335cb5ff96f3bfd22ffd403e1de4f26bf043de90 \
                    size    4189447
    github.tarball_from archive

    depends_lib-append \
                    port:ImageMagick \
                    port:kde-extra-cmake-modules \
                    port:libarchive \
                    port:libraw \
                    path:lib/pkgconfig/poppler.pc:poppler \
                    port:poppler-qt5 \
                    port:pugixml \
                    port:vips \
                    port:webp

    # We have to use ImageMagick here: https://github.com/luspi/photoqt/issues/19
    configure.args-append \
                    -DCHROMECAST=OFF \
                    -DDEVIL=OFF \
                    -DFREEIMAGE=OFF \
                    -DGRAPHICSMAGICK=OFF \
                    -DIMAGEMAGICK=ON \
                    -DENABLE_WEBP=ON \
                    -DLIBARCHIVE=ON \
                    -DLIBVIPS=ON \
                    -DPOPPLER=ON \
                    -DPUGIXML=ON \
                    -DQTPDF=OFF \
                    -DRAW=ON \
                    -DRESVG=OFF \
                    -DVIDEO_MPV=OFF \
                    -DVIDEO_QT=OFF

    qt5.depends_component \
                    qtlocation qtmultimedia qtsvg qttools qttranslations sqlite-plugin

    # Without this the build cannot find QtPlatformHeaders:
    configure.cxxflags-append \
                    -I${qt_includes_dir}
}

subport photoqt-qt4 {
    PortGroup       qt4 1.0

    # This is the last version to support Qt4.
    # TODO: restore Qt4 support into 1.x.
    github.setup    luspi photoqt-legacy 1.0 v
    revision        2
    conflicts       photoqt
    platforms       {darwin < 11}
    checksums       rmd160  e43351a7d1c1bc5fa96c1b4e759134d594c68c4f \
                    sha256  63c8a41a9dc77ab24d3990ee0d8fff0ea3cd8e9430177378ecd7078121618326 \
                    size    704647
    github.tarball_from archive

    patchfiles-append \
                    patch-desktop-file.diff \
                    patch-exiv2.diff \
                    patch-include-magick.diff

    post-patch {
        reinplace "s,@PREFIX@,${prefix}," ${worksrcpath}/CMakeLists.txt
    }

    depends_lib-append \
                    port:GraphicsMagick \
                    port:phonon

    configure.args-append \
                    -DGM=ON \
                    -DPHONON=ON

    # filehandling.cpp: error: invalid conversion from 'QPushButton*' to 'CustomPushButton*' [-fpermissive]
    if {[string match *gcc* ${configure.compiler}]} {
        configure.cxxflags-append \
                    -fpermissive
    }
}

configure.args-append \
                    -DEXIV2=ON

compiler.cxx_standard   2011

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    system "${prefix}/bin/update-mime-database ${prefix}/share/mime"
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
}
