~ubuntu-branches/debian/sid/smplayer/sid

« back to all changes in this revision

Viewing changes to src/corelib/mplayerversion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-03-31 23:05:43 UTC
  • mto: (1.1.9 upstream) (3.1.2 squeeze)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20090331230543-nsklbxenl2hf2n6h
Tags: upstream-0.6.7
ImportĀ upstreamĀ versionĀ 0.6.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  smplayer, GUI front-end for mplayer.
2
 
    Copyright (C) 2006-2008 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
 
#ifndef Q_OS_WIN
32
 
        static QRegExp rx_mplayer_version_ubuntu("^MPlayer (\\d):(\\d)\\.(\\d)~(.*)");
33
 
#endif
34
 
 
35
 
        int mplayer_svn = 0;
36
 
 
37
 
#ifdef Q_OS_WIN
38
 
        // Hack to recognize mplayer 1.0rc2 from CCCP:
39
 
        if (string.startsWith("MPlayer CCCP ")) { 
40
 
                string.remove("CCCP "); 
41
 
                qDebug("MplayerVersion::mplayerVersion: removing CCCP: '%s'", string.toUtf8().data()); 
42
 
        }
43
 
#else
44
 
        // Hack to recognize mplayer 1.0rc1 from Ubuntu:
45
 
        if (rx_mplayer_version_ubuntu.indexIn(string) > -1) {
46
 
                int v1 = rx_mplayer_version_ubuntu.cap(2).toInt();
47
 
                int v2 = rx_mplayer_version_ubuntu.cap(3).toInt();
48
 
                QString rest = rx_mplayer_version_ubuntu.cap(4);
49
 
                //qDebug("%d - %d - %d", rx_mplayer_version_ubuntu.cap(1).toInt(), v1 , v2);
50
 
                string = QString("MPlayer %1.%2%3").arg(v1).arg(v2).arg(rest);
51
 
                qDebug("MplayerVersion::mplayerVersion: line converted to '%s'", string.toUtf8().data());
52
 
        }
53
 
#endif
54
 
 
55
 
        if (rx_mplayer_revision.indexIn(string) > -1) {
56
 
                mplayer_svn = rx_mplayer_revision.cap(2).toInt();
57
 
                qDebug("MplayerVersion::mplayerVersion: MPlayer SVN revision found: %d", mplayer_svn);
58
 
        } 
59
 
        else
60
 
        if (rx_mplayer_version.indexIn(string) > -1) {
61
 
                QString version = rx_mplayer_version.cap(1);
62
 
                qDebug("MplayerVersion::mplayerVersion: MPlayer version found: %s", version.toUtf8().data());
63
 
                mplayer_svn = 0;
64
 
                if (version == "1.0rc2") mplayer_svn = MPLAYER_1_0_RC2_SVN;
65
 
                else
66
 
                if (version == "1.0rc1") mplayer_svn = MPLAYER_1_0_RC1_SVN;
67
 
                else qWarning("MplayerVersion::mplayerVersion: unknown MPlayer version");
68
 
        }
69
 
 
70
 
        bool volume_option = string.contains("with -volume");
71
 
        if (volume_option) {
72
 
                qDebug("MplayerVersion::mplayerVersion: this build provides the -volume option");
73
 
        }
74
 
 
75
 
        if (pref) {
76
 
                pref->mplayer_detected_version = mplayer_svn;
77
 
                pref->mplayer_has_volume_option = volume_option;
78
 
        }
79
 
 
80
 
        return mplayer_svn;
81
 
}
82
 
 
83
 
bool MplayerVersion::isMplayerAtLeast(int mplayer_svn, int svn_revision) {
84
 
        qDebug("MplayerVersion::isMplayerAtLeast: comparing %d with %d", svn_revision, mplayer_svn);
85
 
 
86
 
        if (mplayer_svn == -1) {
87
 
                qWarning("MplayerVersion::isMplayerAtLeast: no version found!");
88
 
        }
89
 
        else
90
 
        if (mplayer_svn == 0) {
91
 
                qWarning("MplayerVersion::isMplayerAtLeast: version couldn't be parsed!");
92
 
        }
93
 
 
94
 
        if (mplayer_svn <= 0) {
95
 
                qWarning("MplayerVersion::isMplayerAtLeast: assuming that the mplayer version is less than %d", svn_revision);
96
 
                return false;
97
 
        }
98
 
 
99
 
        return (mplayer_svn >= svn_revision);
100
 
}
101
 
 
102
 
bool MplayerVersion::isMplayerAtLeast(int svn_revision) {
103
 
        if (pref->mplayer_detected_version >= MPLAYER_1_0_RC1_SVN) {
104
 
                // SVN version seems valid
105
 
                if (pref->mplayer_user_supplied_version != -1) {
106
 
                        qDebug("MplayerVersion::isMplayerAtLeast: using the parsed svn version from mplayer output");
107
 
                        qDebug("MplayerVersion::isMplayerAtLeast: and clearing the previously user supplied version");
108
 
                        pref->mplayer_user_supplied_version = -1;
109
 
                }
110
 
                return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
111
 
        } 
112
 
        else 
113
 
        if (pref->mplayer_user_supplied_version != -1) {
114
 
                qDebug("MplayerVersion::isMplayerAtLeast: no parsed version, using user supplied version");
115
 
                return isMplayerAtLeast(pref->mplayer_user_supplied_version, svn_revision);
116
 
        }
117
 
        else {
118
 
                qWarning("MplayerVersion::isMplayerAtLeast: there's no parsed version nor user supplied version!");
119
 
                return isMplayerAtLeast(pref->mplayer_detected_version, svn_revision);
120
 
        }
121
 
}