# define correct path to used binaries
%global _qt4_qmake	%{_qt4_bindir}/qmake
%global _qt4_lrelease	%{_qt4_bindir}/lrelease

%global smtube_ver 16.1.0

Name:           smplayer
Version:        16.1.0
Release:        1%{?_dist_release}
Summary:        A graphical frontend for mplayer
Summary(ja):    MPlayerのグラフィカルフロントエンド

Group:          Applications/Multimedia
License:        GPLv2+
URL:            http://smplayer.sourceforge.net/linux/
Source0:        http://downloads.sourceforge.net/sourceforge/smplayer/smplayer-%{version}.tar.bz2
# # Add a servicemenu to enqeue files in smplayer's playlist. 
# # The first one is for KDE4, the second one for KDE3.
# # see also: 
# # https://sourceforge.net/tracker/?func=detail&atid=913576&aid=2052905&group_id=185512
# Source1:        smplayer_enqueue_kde4.desktop
# Source2:        smplayer_enqueue_kde3.desktop
# Fix regression in Thunar (TODO: re-check in upcoming versions!)
# https://bugzilla.rpmfusion.org/show_bug.cgi?id=1217
Source3:        http://downloads.sourceforge.net/smplayer/smtube-%{smtube_ver}.tar.bz2
# Fix regression in Thunar (TODO: re-check in upcoming versions!)
# https://bugzilla.rpmfusion.org/show_bug.cgi?id=1217
Patch0:         smplayer-0.8.3-desktop-files.patch
# Patch2:         smplayer-14.9.0.6966-system-qtsingleapplication.patch
# Patch3:         smtube-15.5.10-system-qtsingleapplication.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-root

BuildRequires:  desktop-file-utils
BuildRequires:  qt4-designer
BuildRequires:  qt4-devel
# smplayer without mplayer is quite useless
##Requires:       mplayer

%description
smplayer intends to be a complete front-end for Mplayer, from basic features
like playing videos, DVDs, and VCDs to more advanced features like support
for Mplayer filters and more. One of the main features is the ability to
remember the state of a played file, so when you play it later it will resume
at the same point and with the same settings. smplayer is developed with
the Qt toolkit, so it's multi-platform.
#'

%prep
%setup -a3 -qn %{name}-%{version}
%patch0 -p0 -b .desktop-files

# correction for wrong-file-end-of-line-encoding
%{__sed} -i 's/\r//' *.txt
# fix files which are not UTF-8 
iconv -f Latin1 -t UTF-8 -o Changelog.utf8 Changelog 
%__mv Changelog.utf8 Changelog

# fix path of docs
%__sed -i 's|DOC_PATH=$(PREFIX)/share/doc/packages/smplayer|DOC_PATH=$(PREFIX)/share/doc/smplayer-%{version}|' Makefile

# use %{?_smp_mflags}
%__sed -i '/cd src && $(QMAKE) $(QMAKE_OPTS) && $(DEFS) make/s!$! %{?_smp_mflags}!' Makefile

# don't show smplayer_enqueue.desktop in KDE and use servicemenus instead
echo "NotShowIn=KDE;" >> smplayer_enqueue.desktop

%build
%__make QMAKE=%{_qt4_qmake} PREFIX=%{_prefix} LRELEASE=%{_qt4_lrelease}

pushd smtube-%{smtube_ver}
sed -i 's|/usr/local|%{_prefix}|' Makefile
sed -i 's|doc/smtube|doc/%{name}-%{version}/smtube|' Makefile
sed -i 's|smtube/translations|smplayer/translations|' Makefile
make QMAKE=%{_qt4_qmake} PREFIX=%{_prefix} LRELEASE=%{_qt4_lrelease}
popd

%install
%__rm -rf %{buildroot}
%__make QMAKE=%{_qt4_qmake} PREFIX=%{_prefix} DESTDIR=%{buildroot}/ install

pushd smtube-%{smtube_ver}
%__make install DESTDIR=%{buildroot}
popd

desktop-file-install --delete-original                   \
        --vendor "vine"                             \
        --dir %{buildroot}%{_datadir}/applications/      \
        %{buildroot}%{_datadir}/applications/%{name}.desktop


desktop-file-install --delete-original                   \
        --vendor "vine"                             \
        --dir %{buildroot}%{_datadir}/applications/      \
        %{buildroot}%{_datadir}/applications/%{name}_enqueue.desktop

# # Add servicemenus dependend on the version of KDE:
# # https://sourceforge.net/tracker/index.php?func=detail&aid=2052905&group_id=185512&atid=913576
# %if 0%{?fedora} >= 9
#   install -Dpm 0644 %{SOURCE1} %{buildroot}%{_datadir}/kde4/services/ServiceMenus/smplayer_enqueue.desktop
# %else
#   install -Dpm 0644 %{SOURCE2} %{buildroot}%{_datadir}/apps/konqueror/servicemenus/smplayer_enqueue.desktop
# %endif


%clean
%__rm -rf %{buildroot}

%post
touch --no-create %{_datadir}/icons/hicolor
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
  %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi
update-desktop-database &> /dev/null || :

%postun
touch --no-create %{_datadir}/icons/hicolor
if [ -x %{_bindir}/gtk-update-icon-cache ]; then
  %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor || :
fi
update-desktop-database &> /dev/null || :

%files
%defattr(-,root,root,-)
%{_docdir}/%{name}-%{version}/
%{_bindir}/smplayer
%{_bindir}/smtube
%{_datadir}/applications/*-smplayer*.desktop
%{_datadir}/applications/smtube.desktop
%{_datadir}/icons/hicolor/*/apps/smplayer.*
%{_datadir}/icons/hicolor/*/apps/smtube.*
%{_datadir}/smplayer/
%{_mandir}/man1/smplayer.1.gz

# %if 0%{?fedora} >= 9
#   %dir %{_datadir}/kde4/services/ServiceMenus/
#   %{_datadir}/kde4/services/ServiceMenus/smplayer_enqueue.desktop
# %else
#   %dir %{_datadir}/apps/konqueror/
#   %dir %{_datadir}/apps/konqueror/servicemenus/
#   %{_datadir}/apps/konqueror/servicemenus/smplayer_enqueue.desktop
# %endif

%changelog
* Sun Jan 24 2016 Munehiro Yamamoto <munepi@vinelinux.org> 16.1.0-1
- new upstream release

* Thu Apr  5 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.8.0-1
- new upstream release

* Mon Feb 13 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.7.0-1
- new upstream release

* Thu Feb  9 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.9-2
- rebuild

* Sat Jul 10 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.9-1
- built based on RPM Fusion development
