File indexing completed on 2024-05-05 04:50:12
0001 /* 0002 SPDX-FileCopyrightText: 2012 Eike Hein <hein@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "mediaplayer2.h" 0008 #include "actions.h" 0009 #include "codeine.h" 0010 #include "mpris2.h" 0011 #include "theStream.h" 0012 #include "videoWindow.h" 0013 0014 #include <QApplication> 0015 0016 #include <KAboutData> 0017 #include <KProtocolInfo> 0018 #include <KService> 0019 #include <KX11Extras> 0020 0021 MediaPlayer2::MediaPlayer2(QObject *parent) 0022 : QDBusAbstractAdaptor(parent) 0023 { 0024 connect(Dragon::action("fullscreen"), &QAction::toggled, this, &MediaPlayer2::emitFullscreenChange); 0025 connect(Dragon::videoWindow(), &Dragon::VideoWindow::hasVideoChanged, this, &MediaPlayer2::emitFullscreenChange); 0026 } 0027 0028 MediaPlayer2::~MediaPlayer2() 0029 { 0030 } 0031 0032 bool MediaPlayer2::CanQuit() const 0033 { 0034 return true; 0035 } 0036 0037 void MediaPlayer2::Quit() const 0038 { 0039 qApp->closeAllWindows(); 0040 } 0041 0042 bool MediaPlayer2::CanRaise() const 0043 { 0044 return true; 0045 } 0046 0047 void MediaPlayer2::Raise() const 0048 { 0049 Dragon::mainWindow()->raise(); 0050 KX11Extras::forceActiveWindow(Dragon::mainWindow()->winId()); 0051 } 0052 0053 bool MediaPlayer2::Fullscreen() const 0054 { 0055 return Dragon::action("fullscreen")->isChecked(); 0056 } 0057 0058 void MediaPlayer2::setFullscreen(bool fullscreen) const 0059 { 0060 Dragon::action("fullscreen")->setChecked(fullscreen); 0061 } 0062 0063 void MediaPlayer2::emitFullscreenChange(bool fullscreen) const 0064 { 0065 const QVariantMap properties{ 0066 {QStringLiteral("Fullscreen"), fullscreen}, 0067 {QStringLiteral("CanSetFullscreen"), CanSetFullscreen()}, 0068 }; 0069 Mpris2::signalPropertiesChange(this, properties); 0070 } 0071 0072 bool MediaPlayer2::CanSetFullscreen() const 0073 { 0074 return Dragon::TheStream::hasVideo(); 0075 } 0076 0077 bool MediaPlayer2::HasTrackList() const 0078 { 0079 return false; 0080 } 0081 0082 QString MediaPlayer2::Identity() const 0083 { 0084 return KAboutData::applicationData().displayName(); 0085 } 0086 0087 QString MediaPlayer2::DesktopEntry() const 0088 { 0089 return QStringLiteral("org.kde." APP_NAME); 0090 } 0091 0092 QStringList MediaPlayer2::SupportedUriSchemes() const 0093 { 0094 QStringList protocols; 0095 0096 const auto allProtocols = KProtocolInfo::protocols(); 0097 for (const QString &protocol : allProtocols) { 0098 if (!KProtocolInfo::isHelperProtocol(protocol)) 0099 protocols << protocol; 0100 } 0101 0102 return protocols; 0103 } 0104 0105 QStringList MediaPlayer2::SupportedMimeTypes() const 0106 { 0107 KService::Ptr app = KService::serviceByDesktopName(DesktopEntry()); 0108 0109 if (app) 0110 return app->mimeTypes(); 0111 0112 return QStringList(); 0113 } 0114 0115 #include "moc_mediaplayer2.cpp"