1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include "mplayerversion.h"
21
#include "preferences.h"
25
using namespace Global;
27
int MplayerVersion::mplayerVersion(QString string) {
28
//static QRegExp rx_mplayer_revision("^MPlayer (\\S+)-SVN-r(\\d+)-(.*)");
29
static QRegExp rx_mplayer_revision("^MPlayer (.*)-r(\\d+)(.*)");
30
static QRegExp rx_mplayer_version("^MPlayer ([a-z,0-9,.]+)-(.*)");
32
static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
38
// Hack to recognize mplayer 1.0rc2 from CCCP:
39
if (string.startsWith("MPlayer CCCP ")) {
40
string.remove("CCCP ");
41
qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data());
44
// Hack to recognize mplayer 1.0rc1 from Ubuntu:
45
if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
46
int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
47
int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
48
QString rest = rx_mplayer_version_ubuntu.cap(4);
49
//qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
50
string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
51
qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
55
if (rx_mplayer_revision.indexIn(string) > -1) {
56
mplayer_svn = rx_mplayer_revision.cap(2).toInt();
57
qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
60
if (rx_mplayer_version.indexIn(string) > -1) {
61
QString version = rx_mplayer_version.cap(1);
62
qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
64
if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
66
if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
67
else qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
70
bool volume_option = string.contains("with -volume");
72
qDebug("MplayerVersion::mplayerVersion: this build provides the -volume option");
76
pref->mplayer_detected_version = mplayer_svn;
77
pref->mplayer_has_volume_option = volume_option;
83
bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
84
qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
86
if (mplayer_svn == -1) {
87
qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
90
if (mplayer_svn == 0) {
91
qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
94
if (mplayer_svn <= 0) {
95
qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
99
return (mplayer_svn >= svn_revision);
102
bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
103
if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
104
// SVN version seems valid
105
if (pref->mplayer_user_supplied_version != -1) {
106
qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
107
qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
108
pref->mplayer_user_supplied_version = -1;
110
return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
113
if (pref->mplayer_user_supplied_version != -1) {
114
qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
115
return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
118
qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
119
return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);