# * Copyright 2024 Soumyadeep Ghosh (সৌম্যদীপ ঘোষ) <soumyadeepghosh2004@zohomail.in>
# * Copyright 2023 Scarlett Moore <sgmoore@kde.org>
# * SPDX-License-Identifier: GPL-2.0-or-later
name: kclock
confinement: strict
grade: stable
base: core22
adopt-info: kclock

apps:
  kclockd:
    command: usr/bin/kclockd
    command-chain:
      - usr/bin/kclockd-command-chain.sh
    daemon: simple
    plugs:
      - network
      - network-bind

  kclock:
    extensions:
      - kde-neon-6
    common-id: org.kde.kclock
    desktop: usr/share/applications/org.kde.kclock.desktop
    command: usr/bin/kclock
    command-chain:
      - usr/bin/kclockd-command-chain.sh
    plugs:
      - home
slots:
  session-dbus-interface:
    interface: dbus
    name: org.kde.kclockd
    bus: session

parts:
  libplasma:
    plugin: cmake
    source: https://invent.kde.org/plasma/libplasma/-/archive/v6.0.3/libplasma-v6.0.3.tar.gz
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DBUILD_DESKTOPTHEMES=OFF
      - -DBUILD_TESTING=OFF
    build-packages:
      - libxcb-composite0-dev
      - libxcb-damage0-dev
      - libxcb-shape0-dev
      - libxcb-glx0-dev
      - libvulkan-dev
      - libxkbcommon-dev
      - libwayland-dev
      - doxygen
      - gettext
      - graphviz
      - pkg-config
      - libgl-dev
      - libgl1-mesa-dev
      - libgles-dev
      - libglvnd-dev
      - libglx-dev
      - libegl-dev
      - libsm-dev
      - docbook
      - docbook-xml
      - docbook-xsl
    prime:
      - -usr/lib/*/cmake/*
      - -usr/include/*
      - -usr/share/ECM/*
      - -usr/share/doc/*
      - -usr/share/man/*
      - -usr/share/icons/breeze-dark*
      - -usr/bin/X11
      - -usr/lib/gcc/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - -usr/lib/aspell/*
      - -usr/share/docs
      - -usr/share/lintain

  plasma-mobile-sounds:
    source: https://download.kde.org/stable/plasma-mobile-sounds/0.1/plasma-mobile-sounds-0.1.tar.xz
    build-environment:
      - CMAKE_PREFIX_PATH: $CRAFT_STAGE/usr:/snap/kde-qt6-core22-sdk/current/usr:/snap/kf6-core22-sdk/current/usr${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}
    plugin: cmake
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release

  kclock:
    after: [plasma-mobile-sounds, libplasma]
    parse-info:
      - usr/share/metainfo/org.kde.kclock.appdata.xml
    plugin: cmake
    source: .
    source-type: local
    build-environment:
      - CMAKE_PREFIX_PATH: $CRAFT_STAGE/usr:/snap/kde-qt6-core22-sdk/current/usr:/snap/kf6-core22-sdk/current/usr${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DENABLE_TESTING=OFF
      - -DBUILD_TESTING=OFF
    build-packages:
      - libpulse-dev
    override-build: |
      craftctl default
      cat <<EOF > $CRAFT_PART_INSTALL/usr/bin/kclockd-command-chain.sh
      #!/bin/sh
        exec \$SNAP/usr/bin/kclockd & exec "\$@"
      EOF
      chmod +x $CRAFT_PART_INSTALL/usr/bin/kclockd-command-chain.sh
    prime:
      - -usr/lib/*/cmake/*
      - -usr/include/*
      - -usr/share/ECM/*
      - -usr/share/man/*
      - -usr/bin/X11
      - -usr/lib/gcc/$CRAFT_ARCH_TRIPLET/6.0.0
      - -usr/lib/aspell/*
      - -usr/share/lintian 
