name: qownnotes
#version: git
adopt-info: qownnotes
summary: Plain-text file markdown note taking with Nextcloud/ownCloud integration
grade: stable
confinement: strict
# There is no qmake plugin in core22!
base: core22
description: |
  QOwnNotes is the open source (GPL) plain-text file markdown note taking app
  for GNU/Linux, macOS and Windows, that (optionally) works together with the
  notes application of Nextcloud/ownCloud.
  https://www.qownnotes.org/

apps:
  qownnotes:
    # "=" is not allowed in the command anymore in core20
    command: "./wrapper.sh"
    environment:
      DISABLE_WAYLAND: 1
      QT_QPA_PLATFORMTHEME: gtk3
      GIT_EXEC_PATH: $SNAP/usr/lib/git-core
      GIT_TEMPLATE_DIR: $SNAP/usr/share/git-core/templates
      GIT_AUTHOR_NAME: "QOwnNotes"
      GIT_AUTHOR_EMAIL: "snap@qownnotes.git"
      GIT_COMMITTER_NAME: "QOwnNotes"
      GIT_COMMITTER_EMAIL: "snap@qownnotes.git"
      EMAIL: "snap@qownnotes.git"
    # see https://docs.snapcraft.io/reference/interfaces
    plugs:
      - x11
      - unity7
      - network
      - network-bind
      - home
      #      - kde-frameworks-5-plug
      - desktop
      - desktop-legacy
      - removable-media
      - opengl
      - cups-control

# plugs:
#   kde-frameworks-5-plug:
#     content: kde-frameworks-5-all
#     interface: content
#     default-provider: kde-frameworks-5
#     target: kf5

plugs: # plugs for theming, font settings, cursor and to use gtk3 file chooser
  gtk-3-themes:
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes:gtk-3-themes
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes:icon-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes:sounds-themes

parts:
  qownnotes:
    source: src
    #    source: https://github.com/pbek/qownnotes.git
    # see https://snapcraft.io/docs/qmake-plugin
    #    plugin: qmake
    plugin: make
    #    qmake-parameters:
    #      - CONFIG+=release
    #      - CONFIG+=snapcraft
    #    qmake-project-file: ./src/QOwnNotes.pro
    override-build: |
      #cd /build/qownnotes/parts/qownnotes/src
      export QT_SELECT=qt5
      >&2 pwd
      >&2 find
      # remove the default desktop file
      rm PBE.QOwnNotes.desktop
      echo "#define RELEASE \"Snapcraft.io\"" > release.h
      # qmake INSTALLDIR=/usr
      lrelease QOwnNotes.pro
      # make -j $(nproc)
      # make install
      qmake CONFIG+=release CONFIG+=snapcraft QOwnNotes.pro
      snapcraftctl set-version "$(cat version.h | sed 's/[^0-9,.]//g')"
      # snapcraftctl build
      craftctl default
      make install INSTALL_ROOT="${CRAFT_PART_INSTALL}"
    build-packages:
      - qt5-qmake
      - qttools5-dev
      - build-essential
      - qtdeclarative5-dev
      - libqt5svg5-dev
      - qttools5-dev-tools
      - libqt5websockets5-dev
      - libqt5x11extras5-dev
    stage-packages:
      - libqt5gui5
      - libqt5sql5
      - libqt5sql5-sqlite
      - libqt5widgets5
      - libqt5qml5
      - libqt5svg5
      - libqt5network5
      - libqt5xml5
      - libqt5printsupport5
      - libqt5websockets5
      - libqt5x11extras5
      - qtwayland5
      - git-core
    stage:
      - -usr/share/pkgconfig
    after: [desktop-qt5]

  desktop-qt5:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    source-subdir: qt
    plugin: make
    make-parameters: ["FLAVOR=qt5"]
    build-packages:
      - build-essential
      - qtbase5-dev
      - dpkg-dev
    stage-packages:
      - libxkbcommon0
      #        - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libqt5gui5
      - libgdk-pixbuf2.0-0
      #        - libgtk2.0-0 # snapcraft was complaining about missing libgtk-x11-2.0.so.0
      - libqt5svg5 # for loading icon themes which are svg
      #        - appmenu-qt5
      - locales-all
      - xdg-user-dirs
      - fcitx-frontend-qt5
      - libglib2.0-0 # we need this or under Gnome the file chooser will crash the app!

  plasma-integration:
    plugin: nil
    stage-packages:
      #    - plasma-integration # causes the KDE file selector to be used that didn't work
      - kde-style-breeze
      - breeze-icon-theme
    #    - kio # runtime slaves for kio, but does not seem to work
    prime:
      - "-usr/share/wallpapers/*"
      - "-usr/share/fonts/*"

  qt5-gtk-platform:
    plugin: nil
    stage-packages:
      - qt5-gtk-platformtheme

  scripts:
    plugin: dump
    source: snap/local
    stage:
      - wrapper.sh
