| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2016 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::mpv_version;
|
|---|
| 28 | bool MplayerVersion::is_mpv = false;
|
|---|
| 29 |
|
|---|
| 30 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 31 | QString MplayerVersion::mplayer2_version;
|
|---|
| 32 | bool MplayerVersion::is_mplayer2 = false;
|
|---|
| 33 | #endif
|
|---|
| 34 |
|
|---|
| 35 | int MplayerVersion::mplayerVersion(QString string) {
|
|---|
| 36 | //static QRegExp rx_mplayer_revision("^MPlayer (\\S+)-SVN-r(\\d+)-(.*)");
|
|---|
| 37 | static QRegExp rx_mplayer_revision("^MPlayer (.*)[-\\.]r(\\d+)(.*)");
|
|---|
| 38 | static QRegExp rx_mplayer_version("^MPlayer ([a-z0-9.]+)-(.*)");
|
|---|
| 39 | static QRegExp rx_mplayer_git("^MPlayer GIT(.*)", Qt::CaseInsensitive);
|
|---|
| 40 | static QRegExp rx_mplayer_version_final("1.0rc([0-9])");
|
|---|
| 41 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 42 | static QRegExp rx_mplayer2_version("^MPlayer2 (.*) \\(C\\).*", Qt::CaseInsensitive);
|
|---|
| 43 | #endif
|
|---|
| 44 | static QRegExp rx_mpv_version("^mpv (.*) \\(C\\).*", Qt::CaseInsensitive);
|
|---|
| 45 | #ifndef Q_OS_WIN
|
|---|
| 46 | static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
|
|---|
| 47 | static QRegExp rx_mplayer_revision_ubuntu("^MPlayer svn r(\\d+) (.*)");
|
|---|
| 48 | static QRegExp rx_mplayer_version_mandriva("^MPlayer ([a-z0-9\\.]+)-\\d+\\.([a-z0-9]+)\\.[\\d\\.]+[a-z]+[\\d\\.]+-(.*)");
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | int mplayer_svn = 0;
|
|---|
| 52 | is_mpv = false;
|
|---|
| 53 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 54 | mplayer2_version = QString::null;
|
|---|
| 55 | is_mplayer2 = false;
|
|---|
| 56 | #endif
|
|---|
| 57 |
|
|---|
| 58 | #ifdef Q_OS_WIN
|
|---|
| 59 | // Hack to recognize mplayer 1.0rc2 from CCCP:
|
|---|
| 60 | if (string.startsWith("MPlayer CCCP ")) {
|
|---|
| 61 | string.remove("CCCP ");
|
|---|
| 62 | qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data());
|
|---|
| 63 | }
|
|---|
| 64 | #else
|
|---|
| 65 | // Hack to recognize mplayer 1.0rc1 from Ubuntu:
|
|---|
| 66 | if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
|
|---|
| 67 | int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
|
|---|
| 68 | int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
|
|---|
| 69 | QString rest = rx_mplayer_version_ubuntu.cap(4);
|
|---|
| 70 | //qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
|
|---|
| 71 | string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
|
|---|
| 72 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
|---|
| 73 | }
|
|---|
| 74 | else
|
|---|
| 75 | if (rx_mplayer_revision_ubuntu.indexIn(string) > -1) {
|
|---|
| 76 | int svn = rx_mplayer_revision_ubuntu.cap(1).toInt();
|
|---|
| 77 | QString rest = rx_mplayer_revision_ubuntu.cap(2);
|
|---|
| 78 | string = QString("MPlayer SVN-r%1-%2").arg(svn).arg(rest);
|
|---|
| 79 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | // Hack to recognize mplayer version from Mandriva:
|
|---|
| 83 | if (rx_mplayer_version_mandriva.indexIn(string) > -1) {
|
|---|
| 84 | QString v1 = rx_mplayer_version_mandriva.cap(1);
|
|---|
| 85 | QString v2 = rx_mplayer_version_mandriva.cap(2);
|
|---|
| 86 | QString rest = rx_mplayer_version_mandriva.cap(3);
|
|---|
| 87 | string = QString("MPlayer %1%2-%3").arg(v1).arg(v2).arg(rest);
|
|---|
| 88 | qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
|
|---|
| 89 | }
|
|---|
| 90 | #endif
|
|---|
| 91 |
|
|---|
| 92 | if (rx_mplayer_git.indexIn(string) > -1) {
|
|---|
| 93 | qDebug("MplayerVersion::mplayerVersion: MPlayer from git. Assuming >= 1.0rc3");
|
|---|
| 94 | mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
|---|
| 95 | }
|
|---|
| 96 | else
|
|---|
| 97 | if (rx_mplayer_revision.indexIn(string) > -1) {
|
|---|
| 98 | mplayer_svn = rx_mplayer_revision.cap(2).toInt();
|
|---|
| 99 | qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
|
|---|
| 100 | }
|
|---|
| 101 | else
|
|---|
| 102 | if (rx_mplayer_version.indexIn(string) > -1) {
|
|---|
| 103 | QString version = rx_mplayer_version.cap(1);
|
|---|
| 104 | qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
|
|---|
| 105 | mplayer_svn = 0;
|
|---|
| 106 |
|
|---|
| 107 | if (version == "1.2") mplayer_svn = MPLAYER_1_2;
|
|---|
| 108 | else
|
|---|
| 109 | if (version == "1.1") mplayer_svn = MPLAYER_1_1;
|
|---|
| 110 | else
|
|---|
| 111 | if (version == "1.0rc4") mplayer_svn = MPLAYER_1_0_RC4_SVN;
|
|---|
| 112 | else
|
|---|
| 113 | if (version == "1.0rc3") mplayer_svn = MPLAYER_1_0_RC3_SVN;
|
|---|
| 114 | else
|
|---|
| 115 | if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
|
|---|
| 116 | else
|
|---|
| 117 | if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
|
|---|
| 118 | else
|
|---|
| 119 | /*
|
|---|
| 120 | if(rx_mplayer_version_final.indexIn(version) > -1 && rx_mplayer_version_final.cap(1).toInt() > 3)
|
|---|
| 121 | 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
|
|---|
| 122 | else
|
|---|
| 123 | qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
|
|---|
| 124 | */
|
|---|
| 125 | // Assume it's at least mplayer 1.2
|
|---|
| 126 | mplayer_svn = MPLAYER_1_2;
|
|---|
| 127 | }
|
|---|
| 128 | else
|
|---|
| 129 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 130 | if (rx_mplayer2_version.indexIn(string) > -1) {
|
|---|
| 131 | mplayer2_version = rx_mplayer2_version.cap(1);
|
|---|
| 132 | qDebug("MplayerVersion::mplayerVersion: MPlayer2 version found: %s", mplayer2_version.toUtf8().data());
|
|---|
| 133 | is_mplayer2 = true;
|
|---|
| 134 | mplayer_svn = MPLAYER_1_0_RC4_SVN; // simulates mplayer 1.0rc4
|
|---|
| 135 | }
|
|---|
| 136 | else
|
|---|
| 137 | #endif
|
|---|
| 138 | if (rx_mpv_version.indexIn(string) > -1) {
|
|---|
| 139 | mpv_version = rx_mpv_version.cap(1);
|
|---|
| 140 | qDebug("MplayerVersion::mplayerVersion: mpv version found: %s", mpv_version.toUtf8().data());
|
|---|
| 141 | is_mpv = true;
|
|---|
| 142 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 143 | is_mplayer2 = true;
|
|---|
| 144 | #endif
|
|---|
| 145 | mplayer_svn = MPLAYER_1_0_RC4_SVN; // simulates mplayer 1.0rc4
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | if (pref) {
|
|---|
| 149 | pref->mplayer_detected_version = mplayer_svn;
|
|---|
| 150 | #ifdef MPLAYER2_SUPPORT
|
|---|
| 151 | pref->mplayer_is_mplayer2 = is_mplayer2;
|
|---|
| 152 | pref->mplayer2_detected_version = mplayer2_version;
|
|---|
| 153 | #endif
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | qDebug("MplayerVersion::mplayerVersion: mplayer_svn: %d", mplayer_svn);
|
|---|
| 157 |
|
|---|
| 158 | return mplayer_svn;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
|
|---|
| 162 | qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
|
|---|
| 163 |
|
|---|
| 164 | if (mplayer_svn == -1) {
|
|---|
| 165 | qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
|
|---|
| 166 | }
|
|---|
| 167 | else
|
|---|
| 168 | if (mplayer_svn == 0) {
|
|---|
| 169 | qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | if (mplayer_svn <= 0) {
|
|---|
| 173 | qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
|
|---|
| 174 | return false;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | return (mplayer_svn >= svn_revision);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
|
|---|
| 181 | if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
|
|---|
| 182 | // SVN version seems valid
|
|---|
| 183 | if (pref->mplayer_user_supplied_version != -1) {
|
|---|
| 184 | qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
|
|---|
| 185 | qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
|
|---|
| 186 | pref->mplayer_user_supplied_version = -1;
|
|---|
| 187 | }
|
|---|
| 188 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
|---|
| 189 | }
|
|---|
| 190 | else
|
|---|
| 191 | if (pref->mplayer_user_supplied_version != -1) {
|
|---|
| 192 | qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
|
|---|
| 193 | return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
|
|---|
| 194 | }
|
|---|
| 195 | else {
|
|---|
| 196 | qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
|
|---|
| 197 | return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | QString MplayerVersion::toString(int svn_revision) {
|
|---|
| 202 | QString version;
|
|---|
| 203 |
|
|---|
| 204 | switch (svn_revision) {
|
|---|
| 205 | case MPLAYER_1_0_RC1_SVN: version = QString("1.0rc1"); break;
|
|---|
| 206 | case MPLAYER_1_0_RC2_SVN: version = QString("1.0rc2"); break;
|
|---|
| 207 | case MPLAYER_1_0_RC3_SVN: version = QString("1.0rc3"); break;
|
|---|
| 208 | case MPLAYER_1_0_RC4_SVN: version = QString("1.0rc4"); break;
|
|---|
| 209 | case MPLAYER_1_1: version = QString("1.1"); break;
|
|---|
| 210 | default : version = QString("SVN r%1").arg(svn_revision);
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | return version;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|