1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* smplayer, GUI front-end for mplayer.
Copyright (C) 2006-2009 Ricardo Villalba <rvm@escomposlinux.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mplayerversion.h"
#include "global.h"
#include "preferences.h"
#include <QRegExp>
using namespace Global;
int MplayerVersion::mplayerVersion(QString string) {
//static QRegExp rx_mplayer_revision("^MPlayer (\\S+)-SVN-r(\\d+)-(.*)");
static QRegExp rx_mplayer_revision("^MPlayer (.*)-r(\\d+)(.*)");
static QRegExp rx_mplayer_version("^MPlayer ([a-z,0-9,.]+)-(.*)");
static QRegExp rx_mplayer_git("^MPlayer GIT(.*)");
#ifndef Q_OS_WIN
static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
#endif
int mplayer_svn = 0;
#ifdef Q_OS_WIN
// Hack to recognize mplayer 1.0rc2 from CCCP:
if (string.startsWith("MPlayer CCCP ")) {
string.remove("CCCP ");
qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data());
}
#else
// Hack to recognize mplayer 1.0rc1 from Ubuntu:
if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
QString rest = rx_mplayer_version_ubuntu.cap(4);
//qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
}
#endif
if (rx_mplayer_revision.indexIn(string) > -1) {
mplayer_svn = rx_mplayer_revision.cap(2).toInt();
qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
}
else
if (rx_mplayer_version.indexIn(string) > -1) {
QString version = rx_mplayer_version.cap(1);
qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
mplayer_svn = 0;
if (version == "1.0rc3") mplayer_svn = MPLAYER_1_0_RC3_SVN;
else
if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
else
if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
else qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
}
else
if (rx_mplayer_git.indexIn(string) > -1) {
qDebug("MplayerVersion::mplayerVersion: MPlayer from git. Assuming >= 1.0rc3");
mplayer_svn = MPLAYER_1_0_RC3_SVN;
}
if (pref) {
pref->mplayer_detected_version = mplayer_svn;
}
return mplayer_svn;
}
bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
if (mplayer_svn == -1) {
qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
}
else
if (mplayer_svn == 0) {
qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
}
if (mplayer_svn <= 0) {
qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
return false;
}
return (mplayer_svn >= svn_revision);
}
bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
// SVN version seems valid
if (pref->mplayer_user_supplied_version != -1) {
qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
pref->mplayer_user_supplied_version = -1;
}
return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
}
else
if (pref->mplayer_user_supplied_version != -1) {
qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
}
else {
qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
}
}
QString MplayerVersion::toString(int svn_revision) {
QString version;
switch (svn_revision) {
case MPLAYER_1_0_RC1_SVN: version = QString("1.0rc1"); break;
case MPLAYER_1_0_RC2_SVN: version = QString("1.0rc2"); break;
case MPLAYER_1_0_RC3_SVN: version = QString("1.0rc3"); break;
default : version = QString("SVN r%1").arg(svn_revision);
}
return version;
}
|