mediaplayer2.cpp 3.05 KB
Newer Older
Michael Pyne's avatar
Michael Pyne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/***********************************************************************
 * Copyright 2012  Eike Hein <hein@kde.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ***********************************************************************/

#include "mpris2/mediaplayer2.h"
#include "juk.h"
23
#include "mediafiles.h"
Michael Pyne's avatar
Michael Pyne committed
24 25 26 27 28 29

#include <KAboutData>
#include <KApplication>
#include <KCmdLineArgs>
#include <KWindowSystem>

30 31
#include <QDBusConnection>
#include <QDBusMessage>
Michael Pyne's avatar
Michael Pyne committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <QWidget>

MediaPlayer2::MediaPlayer2(QObject* parent) : QDBusAbstractAdaptor(parent)
{
}

MediaPlayer2::~MediaPlayer2()
{
}

bool MediaPlayer2::CanRaise() const
{
    return true;
}

void MediaPlayer2::Raise() const
{
49 50
    JuK::JuKInstance()->show();
    KWindowSystem::forceActiveWindow(JuK::JuKInstance()->effectiveWinId());
Michael Pyne's avatar
Michael Pyne committed
51 52 53 54 55 56 57 58 59
}

bool MediaPlayer2::CanQuit() const
{
    return true;
}

void MediaPlayer2::Quit() const
{
60
    kapp->quit();
Michael Pyne's avatar
Michael Pyne committed
61 62
}

63 64 65 66 67
bool MediaPlayer2::CanSetFullscreen() const
{
    return false;
}

68 69 70 71 72
bool MediaPlayer2::Fullscreen() const
{
    return false;
}

Michael Pyne's avatar
Michael Pyne committed
73 74 75 76 77 78 79
bool MediaPlayer2::HasTrackList() const
{
    return false;
}

QString MediaPlayer2::Identity() const
{
80 81 82
    // FIXME
    //return KCmdLineArgs::aboutData()->programName();
    return "JuK";
Michael Pyne's avatar
Michael Pyne committed
83 84 85 86
}

QString MediaPlayer2::DesktopEntry() const
{
87
    return QLatin1String("org.kde.juk");
Michael Pyne's avatar
Michael Pyne committed
88 89 90 91 92 93 94 95 96
}

QStringList MediaPlayer2::SupportedUriSchemes() const
{
    return QStringList(QLatin1String("file"));
}

QStringList MediaPlayer2::SupportedMimeTypes() const
{
97
    QStringList mimeTable = MediaFiles::mimeTypes();
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

    // Add whitelist hacks

    // technically, "audio/flac" is not a valid mimetype (not on IANA list), but some things expect it
    if( mimeTable.contains( "audio/x-flac" ) && !mimeTable.contains( "audio/flac" ) )
        mimeTable << "audio/flac";

    bool canPlayMp3 = mimeTable.contains( "audio/mpeg" ) || mimeTable.contains( "audio/x-mp3" );
    // We special case this, as otherwise the users would hate us
    // Again, "audio/mp3" is not a valid mimetype, but is widely used
    // (the proper one is "audio/mpeg", but that is also for .mp1 and .mp2 files)
    if( canPlayMp3 && !mimeTable.contains( "audio/mp3" ) )
        mimeTable << "audio/mp3";
    if( canPlayMp3 && !mimeTable.contains( "audio/x-mp3" ) )
        mimeTable << "audio/x-mp3";

    return mimeTable;
}