# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake xdg gnome2-utils

if [[ ${PV} == 9999 ]]; then
    KEYWORDS=""
    EGIT_REPO_URI="https://gitlab.com/ubports/development/core/${PN}.git"
    inherit git-r3
else
    KEYWORDS="~amd64"
    SRC_URI="https://gitlab.com/ubports/development/core/${PN}/-/archive/${PV}/${P}.tar.gz"
fi

DESCRIPTION="D-Bus service for out of process thumbnailing"
HOMEPAGE="https://gitlab.com/ubports/development/core/${PN}"

LICENSE="GPL-3"
SLOT="0"
RESTRICT="test"

DEPEND="
    dev-libs/boost
    dev-libs/glib
    dev-libs/persistent-cache-cpp
    dev-qt/qtconcurrent
    lomiri-base/lomiri-api
    media-libs/libexif
    media-plugins/gst-plugins-taglib
    sys-libs/libapparmor
"

RDEPEND="${DEPEND}"

BDEPEND="
    dev-build/cmake
    dev-build/cmake-extras
    dev-build/samurai
    dev-qt/qtdeclarative:5
"

PATCHES=(
    "${FILESDIR}"/001-fix-template-id-cdtor-error.patch
)

src_prepare() {
    eapply_user

    # remove ctest from the build
    sed -i '/include(CTest)/d' CMakeLists.txt || die
    sed -i '/add_subdirectory(tests)/d' CMakeLists.txt || die

    cmake_src_prepare
}

src_configure() {
    local mycmakeargs=(
        -Dskip-dbus-tests="OFF"
        -DENABLE_DOC="OFF"
        -DWerror="OFF"
    )

    cmake_src_configure
}

pkg_postinst() {
    xdg_pkg_postinst
    gnome2_schemas_update
}

pkg_postrm() {
    xdg_pkg_postrm
    gnome2_schemas_update
}