# $Id: PKGBUILD 138245 2015-08-11 14:52:31Z bgyorgy $
# Maintainer: Alexandre Filgueira <alexfilgueira@cinnarch.com>
# Contributor: M0Rf30
# Contributor: unifiedlinux
# Contributor: CReimer

pkgname=cinnamon
pkgver=2.6.13
pkgrel=3
pkgdesc="Linux desktop which provides advanced innovative features and a traditional user experience"
arch=('i686' 'x86_64')
url="http://cinnamon.linuxmint.com/"
license=('GPL2')
depends=('accountsservice' 'caribou' 'cinnamon-settings-daemon' 'cinnamon-session'
         'cinnamon-translations' 'cjs' 'clutter-gtk' 'gnome-backgrounds' 'gconf'
         'gnome-themes-standard' 'gstreamer' 'libgnome-keyring' 'libkeybinder3' 'librsvg'
         'networkmanager' 'muffin' 'python2-cairo' 'python2-dbus' 'python2-pillow'
         'python2-pam' 'python2-pexpect' 'python2-pyinotify' 'python2-lxml' 'webkitgtk'
         'cinnamon-control-center' 'cinnamon-screensaver' 'cinnamon-menus' 'libgnomekbd'
         'network-manager-applet' 'nemo' 'polkit-gnome')
makedepends=('gnome-common' 'intltool' 'gtk-doc' 'gobject-introspection')
optdepends=('blueberry: Bluetooth support'
            'system-config-printer: printer settings')
options=('!emptydirs')
install=${pkgname}.install
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxmint/Cinnamon/archive/$pkgver.tar.gz"
        "set_wheel.patch"
        "gnome-3.14.patch"
        "default-theme.patch"
        "dont-hardcode-nemo.patch"
        "fix-keyboard-flags.patch")
sha256sums=('f349403901bf3e84cda2ebd425dc6f58850059092775e285862067f120debe86'
            '2f0fec7d733aa19be426a0e1aecff1af451183de038d2868a2ee3195f227956e'
            '5ecce3c1617c0479ef97290494aaaa4e5a58d24de31d00a527d44921e2a44d91'
            '566585873f38a79ec248b916645a2e081abec3c6d4df2c34339cde1f35375cc5'
            '26a9fb9a3855759cc7d5fa9a195ae8860d5c6b3e12adc1bfe86269e047c119b4'
            '35478dd7df2ecee484bbe758885ed55797e0567643615984973d153f34700016')
            
prepare() {
  cd ${srcdir}/Cinnamon*

  # Python2 fix
  sed -i 's:/usr/bin/python :/usr/bin/python2 :' files/usr/bin/cinnamon-menu-editor
  find -type f | xargs sed -i 's@^#!.*python$@#!/usr/bin/python2@'

  # Use wheel group instread of sudo
  patch -Np1 -i ../set_wheel.patch

  # Make Adwaita icon theme selectable in theme settings
  patch -Np1 -i ../gnome-3.14.patch

  # Set default theme to 'cinnamon'
  patch -Np1 -i ../default-theme.patch

  # Don't hardcode Nemo
  patch -Np1 -i ../dont-hardcode-nemo.patch

  # Fix missing flags in keyboard applet (FS#45615)
  patch -Np1 -i ../fix-keyboard-flags.patch

  # Add polkit agent to required components
  sed -i 's/RequiredComponents=\(.*\)$/RequiredComponents=\1polkit-gnome-authentication-agent-1;/' \
    files/usr/share/cinnamon-session/sessions/cinnamon*.session

  # Fix for the python2 PAM module  
  sed -i 's:import PAM:import pam:' files/usr/lib/cinnamon-settings/modules/cs_user.py

  # Use pkexec instead of gksu
  sed -i 's/gksu/pkexec/' files/usr/bin/cinnamon-settings-users

  # Check for the cc-panel path, not for the unneeded binary
  sed -i 's|/usr/bin/cinnamon-control-center|/usr/lib/cinnamon-control-center-1/panels|' \
    files/usr/bin/cinnamon-settings

  # Cinnamon has no upstream backgrounds, use GNOME backgrounds instead
  sed -i 's|/usr/share/cinnamon-background-properties|/usr/share/gnome-background-properties|' \
    files/usr/lib/cinnamon-settings/modules/cs_backgrounds.py

  # Fix selected background color in Cinnamon Settings for Adwaita theme
  sed -i 's/@selected_bg_color;/@theme_selected_bg_color;/' \
    files/usr/lib/cinnamon-settings/cinnamon-settings.py

  # Fix missing icons with the Adwaita theme
  sed -i 's/"gtk-file"/"text-x-generic"/' docs/applets-examples/finder@cinnamon.org/applet.js  src/cinnamon-util.c
  sed -i "s/SECONDARY, 'ok'/SECONDARY, 'gtk-apply'/
          s/SECONDARY, 'stop'/SECONDARY, 'dialog-error'/" files/usr/lib/cinnamon-desktop-editor/cinnamon-desktop-editor.py
  sed -i "s/'gnome-panel-launcher'/'system-run'/" files/usr/lib/cinnamon-desktop-editor/cinnamon-desktop-editor.py
  sed -i 's/icon_name">gnome-panel-launcher/icon_name">system-run/' files/usr/lib/cinnamon-desktop-editor/launcher-editor.ui
  sed -i 's/"reload"/"view-refresh"/' files/usr/lib/cinnamon-settings-users/cinnamon-settings-users.py
  sed -i 's/"gtk-dialog-question"/"dialog-question"/
          s/"gtk-directory"/"folder"/' files/usr/lib/cinnamon-settings/modules/cs_default.py
  sed -i 's/"display"/"video-display"/
          s/"access"/"preferences-desktop-accessibility"/
          s/"gnome-panel-launcher"/"system-run"/' files/usr/lib/cinnamon-settings/modules/cs_keyboard.py
  sed -i 's/"stock_calendar"/"x-office-calendar"/' files/usr/share/cinnamon/applets/calendar@cinnamon.org/metadata.json
  sed -i 's/"keyboard"/"input-keyboard"/' files/usr/share/cinnamon/applets/keyboard@cinnamon.org/metadata.json
  sed -i 's/"desktop"/"user-desktop"/' files/usr/share/cinnamon/applets/show-desktop@cinnamon.org/metadata.json
  sed -i 's/"stock_volume"/"multimedia-volume-control"/' files/usr/share/cinnamon/applets/sound@cinnamon.org/metadata.json
  sed -i 's/"stock_calendar"/"x-office-calendar"/' files/usr/share/cinnamon/desklets/clock@cinnamon.org/metadata.json
}

build() {
  cd ${srcdir}/Cinnamon*

  ./autogen.sh --prefix=/usr \
               --sysconfdir=/etc \
               --libexecdir=/usr/lib/cinnamon \
               --localstatedir=/var \
               --disable-static \
               --disable-schemas-compile \
               --enable-compile-warnings=yes \
               --with-session-tracking=systemd
  make
}

package() {
  cd ${srcdir}/Cinnamon*
  make DESTDIR="${pkgdir}" install
}
