1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
---|
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 | 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,.]+)-(.*)");
|
---|
31 | static QRegExp rx_mplayer_git("^MPlayer GIT(.*)", Qt::CaseInsensitive);
|
---|
32 | #ifndef Q_OS_WIN
|
---|
33 | static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
|
---|
34 | static QRegExp rx_mplayer_version_mandriva("^MPlayer ([a-z0-9\\.]+)-\\d+\\.([a-z0-9]+)\\.[\\d\\.]+[a-z]+[\\d\\.]+-(.*)");
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | int mplayer_svn = 0;
|
---|
38 |
|
---|
39 | #ifdef Q_OS_WIN
|
---|
40 | // Hack to recognize mplayer 1.0rc2 from CCCP:
|
---|
41 | if (string.startsWith("MPlayer CCCP ")) {
|
---|
42 | string.remove("CCCP ");
|
---|
43 | qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data());
|
---|
44 | }
|
---|
45 | #else
|
---|
46 | // Hack to recognize mplayer 1.0rc1 from Ubuntu:
|
---|
47 | if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
|
---|
48 | int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
|
---|
49 | int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
|
---|
50 | QString rest = rx_mplayer_version_ubuntu.cap(4);
|
---|
51 | //qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
|
---|
52 | string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
|
---|
53 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
---|
54 | }
|
---|
55 | // Hack to recognize mplayer version from Mandriva:
|
---|
56 | if (rx_mplayer_version_mandriva.indexIn(string) > -1) {
|
---|
57 | QString v1 = rx_mplayer_version_mandriva.cap(1);
|
---|
58 | QString v2 = rx_mplayer_version_mandriva.cap(2);
|
---|
59 | QString rest = rx_mplayer_version_mandriva.cap(3);
|
---|
60 | string = QString("MPlayer %1%2-%3").arg(v1).arg(v2).arg(rest);
|
---|
61 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
---|
62 | }
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | if (rx_mplayer_git.indexIn(string) > -1) {
|
---|
66 | qDebug("MplayerVersion::mplayerVersion: MPlayer from git. Assuming >= 1.0rc3");
|
---|
67 | mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
---|
68 | }
|
---|
69 | else
|
---|
70 | if (rx_mplayer_revision.indexIn(string) > -1) {
|
---|
71 | mplayer_svn = rx_mplayer_revision.cap(2).toInt();
|
---|
72 | qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
|
---|
73 | }
|
---|
74 | else
|
---|
75 | if (rx_mplayer_version.indexIn(string) > -1) {
|
---|
76 | QString version = rx_mplayer_version.cap(1);
|
---|
77 | qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
|
---|
78 | mplayer_svn = 0;
|
---|
79 | if (version == "1.0rc3") mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
---|
80 | else
|
---|
81 | if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
|
---|
82 | else
|
---|
83 | if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
|
---|
84 | else qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
|
---|
85 | }
|
---|
86 |
|
---|
87 | if (pref) {
|
---|
88 | pref->mplayer_detected_version = mplayer_svn;
|
---|
89 | }
|
---|
90 |
|
---|
91 | return mplayer_svn;
|
---|
92 | }
|
---|
93 |
|
---|
94 | bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
|
---|
95 | qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
|
---|
96 |
|
---|
97 | if (mplayer_svn == -1) {
|
---|
98 | qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
|
---|
99 | }
|
---|
100 | else
|
---|
101 | if (mplayer_svn == 0) {
|
---|
102 | qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
|
---|
103 | }
|
---|
104 |
|
---|
105 | if (mplayer_svn <= 0) {
|
---|
106 | qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
|
---|
107 | return false;
|
---|
108 | }
|
---|
109 |
|
---|
110 | return (mplayer_svn >= svn_revision);
|
---|
111 | }
|
---|
112 |
|
---|
113 | bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
|
---|
114 | if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
|
---|
115 | // SVN version seems valid
|
---|
116 | if (pref->mplayer_user_supplied_version != -1) {
|
---|
117 | qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
|
---|
118 | qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
|
---|
119 | pref->mplayer_user_supplied_version = -1;
|
---|
120 | }
|
---|
121 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
---|
122 | }
|
---|
123 | else
|
---|
124 | if (pref->mplayer_user_supplied_version != -1) {
|
---|
125 | qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
|
---|
126 | return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
|
---|
127 | }
|
---|
128 | else {
|
---|
129 | qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
|
---|
130 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | QString MplayerVersion::toString(int svn_revision) {
|
---|
135 | QString version;
|
---|
136 |
|
---|
137 | switch (svn_revision) {
|
---|
138 | case MPLAYER_1_0_RC1_SVN: version = QString("1.0rc1"); break;
|
---|
139 | case MPLAYER_1_0_RC2_SVN: version = QString("1.0rc2"); break;
|
---|
140 | case MPLAYER_1_0_RC3_SVN: version = QString("1.0rc3"); break;
|
---|
141 | default : version = QString("SVN r%1").arg(svn_revision);
|
---|
142 | }
|
---|
143 |
|
---|
144 | return version;
|
---|
145 | }
|
---|
146 |
|
---|