1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
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.
|
---|
8 |
|
---|
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.
|
---|
13 |
|
---|
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
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "mplayerversion.h"
|
---|
20 | #include "global.h"
|
---|
21 | #include "preferences.h"
|
---|
22 |
|
---|
23 | #include <QRegExp>
|
---|
24 |
|
---|
25 | using namespace Global;
|
---|
26 |
|
---|
27 | QString MplayerVersion::mplayer2_version;
|
---|
28 | bool MplayerVersion::is_mplayer2 = false;
|
---|
29 |
|
---|
30 | int MplayerVersion::mplayerVersion(QString string) {
|
---|
31 | //static QRegExp rx_mplayer_revision("^MPlayer (\\S+)-SVN-r(\\d+)-(.*)");
|
---|
32 | static QRegExp rx_mplayer_revision("^MPlayer (.*)[-\\.]r(\\d+)(.*)");
|
---|
33 | static QRegExp rx_mplayer_version("^MPlayer ([a-z,0-9,.]+)-(.*)");
|
---|
34 | static QRegExp rx_mplayer_git("^MPlayer GIT(.*)", Qt::CaseInsensitive);
|
---|
35 | static QRegExp rx_mplayer_version_final("1.0rc([0-9])");
|
---|
36 | static QRegExp rx_mplayer2_version("^MPlayer2 (.*) \\(C\\).*");
|
---|
37 | #ifndef Q_OS_WIN
|
---|
38 | static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
|
---|
39 | static QRegExp rx_mplayer_version_mandriva("^MPlayer ([a-z0-9\\.]+)-\\d+\\.([a-z0-9]+)\\.[\\d\\.]+[a-z]+[\\d\\.]+-(.*)");
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | int mplayer_svn = 0;
|
---|
43 | mplayer2_version = QString::null;
|
---|
44 | is_mplayer2 = false;
|
---|
45 |
|
---|
46 | #ifdef Q_OS_WIN
|
---|
47 | // Hack to recognize mplayer 1.0rc2 from CCCP:
|
---|
48 | if (string.startsWith("MPlayer CCCP ")) {
|
---|
49 | string.remove("CCCP ");
|
---|
50 | qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data());
|
---|
51 | }
|
---|
52 | #else
|
---|
53 | // Hack to recognize mplayer 1.0rc1 from Ubuntu:
|
---|
54 | if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
|
---|
55 | int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
|
---|
56 | int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
|
---|
57 | QString rest = rx_mplayer_version_ubuntu.cap(4);
|
---|
58 | //qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
|
---|
59 | string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
|
---|
60 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
---|
61 | }
|
---|
62 | // Hack to recognize mplayer version from Mandriva:
|
---|
63 | if (rx_mplayer_version_mandriva.indexIn(string) > -1) {
|
---|
64 | QString v1 = rx_mplayer_version_mandriva.cap(1);
|
---|
65 | QString v2 = rx_mplayer_version_mandriva.cap(2);
|
---|
66 | QString rest = rx_mplayer_version_mandriva.cap(3);
|
---|
67 | string = QString("MPlayer %1%2-%3").arg(v1).arg(v2).arg(rest);
|
---|
68 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
---|
69 | }
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | if (rx_mplayer_git.indexIn(string) > -1) {
|
---|
73 | qDebug("MplayerVersion::mplayerVersion: MPlayer from git. Assuming >= 1.0rc3");
|
---|
74 | mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
---|
75 | }
|
---|
76 | else
|
---|
77 | if (rx_mplayer_revision.indexIn(string) > -1) {
|
---|
78 | mplayer_svn = rx_mplayer_revision.cap(2).toInt();
|
---|
79 | qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
|
---|
80 | }
|
---|
81 | else
|
---|
82 | if (rx_mplayer_version.indexIn(string) > -1) {
|
---|
83 | QString version = rx_mplayer_version.cap(1);
|
---|
84 | qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
|
---|
85 | mplayer_svn = 0;
|
---|
86 |
|
---|
87 | if (version == "1.0rc4") mplayer_svn = MPLAYER_1_0_RC4_SVN;
|
---|
88 | else
|
---|
89 | if (version == "1.0rc3") mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
---|
90 | else
|
---|
91 | if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
|
---|
92 | else
|
---|
93 | if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
|
---|
94 | else
|
---|
95 | if(rx_mplayer_version_final.indexIn(version) > -1 && rx_mplayer_version_final.cap(1).toInt() > 3)
|
---|
96 | mplayer_svn = MPLAYER_1_0_RC3_SVN; //version is > 1.0rc3, so treat as 1.0rc3 since support for later versions is not yet implemented
|
---|
97 |
|
---|
98 | else
|
---|
99 | qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
|
---|
100 |
|
---|
101 | }
|
---|
102 | else
|
---|
103 | if (rx_mplayer2_version.indexIn(string) > -1) {
|
---|
104 | mplayer2_version = rx_mplayer2_version.cap(1);
|
---|
105 | qDebug("MplayerVersion::mplayerVersion: MPlayer2 version found: %s", mplayer2_version.toUtf8().data());
|
---|
106 | is_mplayer2 = true;
|
---|
107 | mplayer_svn = MPLAYER_1_0_RC4_SVN; // simulates mplayer 1.0rc4
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (pref) {
|
---|
111 | pref->mplayer_detected_version = mplayer_svn;
|
---|
112 | pref->mplayer_is_mplayer2 = is_mplayer2;
|
---|
113 | pref->mplayer2_detected_version = mplayer2_version;
|
---|
114 | }
|
---|
115 |
|
---|
116 | return mplayer_svn;
|
---|
117 | }
|
---|
118 |
|
---|
119 | bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
|
---|
120 | qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
|
---|
121 |
|
---|
122 | if (mplayer_svn == -1) {
|
---|
123 | qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
|
---|
124 | }
|
---|
125 | else
|
---|
126 | if (mplayer_svn == 0) {
|
---|
127 | qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
|
---|
128 | }
|
---|
129 |
|
---|
130 | if (mplayer_svn <= 0) {
|
---|
131 | qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
|
---|
132 | return false;
|
---|
133 | }
|
---|
134 |
|
---|
135 | return (mplayer_svn >= svn_revision);
|
---|
136 | }
|
---|
137 |
|
---|
138 | bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
|
---|
139 | if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
|
---|
140 | // SVN version seems valid
|
---|
141 | if (pref->mplayer_user_supplied_version != -1) {
|
---|
142 | qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
|
---|
143 | qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
|
---|
144 | pref->mplayer_user_supplied_version = -1;
|
---|
145 | }
|
---|
146 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | if (pref->mplayer_user_supplied_version != -1) {
|
---|
150 | qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
|
---|
151 | return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
|
---|
152 | }
|
---|
153 | else {
|
---|
154 | qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
|
---|
155 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | QString MplayerVersion::toString(int svn_revision) {
|
---|
160 | QString version;
|
---|
161 |
|
---|
162 | switch (svn_revision) {
|
---|
163 | case MPLAYER_1_0_RC1_SVN: version = QString("1.0rc1"); break;
|
---|
164 | case MPLAYER_1_0_RC2_SVN: version = QString("1.0rc2"); break;
|
---|
165 | case MPLAYER_1_0_RC3_SVN: version = QString("1.0rc3"); break;
|
---|
166 | case MPLAYER_1_0_RC4_SVN: version = QString("1.0rc4"); break;
|
---|
167 | default : version = QString("SVN r%1").arg(svn_revision);
|
---|
168 | }
|
---|
169 |
|
---|
170 | return version;
|
---|
171 | }
|
---|
172 |
|
---|