source: smplayer/trunk/src/mplayerversion.cpp@ 121

Last change on this file since 121 was 119, checked in by Silvan Scherrer, 14 years ago

SMPlayer: latest svn update

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