File indexing completed on 2024-04-28 04:48:38
0001 /* 0002 SPDX-FileCopyrightText: 2005 Max Howell <max.howell@methylblue.com> 0003 SPDX-FileCopyrightText: 2007 Ian Monroe <ian@monroe.nu> 0004 0005 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "theStream.h" 0009 0010 #include <QDebug> 0011 #include <QHash> 0012 0013 #include <phonon/MediaController> 0014 #include <phonon/MediaObject> 0015 #include <phonon/MediaSource> 0016 #include <phonon/VideoWidget> 0017 0018 #include <KLocalizedString> 0019 #include <KSharedConfig> 0020 0021 #include <Solid/Device> 0022 #include <Solid/StorageVolume> 0023 0024 #include "videoWindow.h" 0025 0026 namespace Dragon 0027 { 0028 0029 const char *TheStream::CHANNEL_PROPERTY = "channel"; 0030 0031 QHash<int, QAction *> TheStream::s_aspectRatioActions; 0032 0033 KConfigGroup TheStream::profile() 0034 { 0035 Phonon::MediaSource::Type current = videoWindow()->m_media->currentSource().type(); 0036 if (current == Phonon::MediaSource::Disc) { 0037 QList<Solid::Device> deviceList = Solid::Device::listFromType(Solid::DeviceInterface::OpticalDisc); 0038 if (!deviceList.isEmpty()) { 0039 Solid::StorageVolume *disc = deviceList.first().as<Solid::StorageVolume>(); 0040 if (disc) { 0041 QString discLabel = QStringLiteral("disc:%1,%2").arg(disc->uuid()).arg(disc->label()); 0042 return KConfigGroup(KSharedConfig::openConfig(), discLabel); 0043 } else 0044 qDebug() << "profile: doesn't convert into Solid::StorageVolume"; 0045 } else 0046 qDebug() << "profile: empty device list"; 0047 } 0048 // if not a disc, or Solid fails 0049 return KConfigGroup(KSharedConfig::openConfig(), url().toDisplayString()); 0050 } 0051 0052 QUrl TheStream::url() 0053 { 0054 return videoWindow()->m_media->currentSource().url(); 0055 } 0056 0057 bool TheStream::canSeek() 0058 { 0059 return videoWindow()->m_media->isSeekable(); 0060 } 0061 0062 bool TheStream::hasAudio() 0063 { 0064 return true; 0065 } 0066 0067 bool TheStream::hasVideo() 0068 { 0069 return videoWindow()->m_media->hasVideo(); 0070 } 0071 0072 bool TheStream::hasMedia() 0073 { 0074 if (videoWindow()->m_media->currentSource().type() == Phonon::MediaSource::Invalid) 0075 return false; 0076 if (videoWindow()->m_media->currentSource().type() == Phonon::MediaSource::Empty) 0077 return false; 0078 // otherwise 0079 return true; 0080 } 0081 0082 QSize TheStream::defaultVideoSize() 0083 { 0084 return videoWindow()->m_vWidget->sizeHint(); 0085 } 0086 0087 int TheStream::aspectRatio() 0088 { 0089 return engine()->m_vWidget->aspectRatio(); 0090 } 0091 0092 QAction *TheStream::aspectRatioAction() 0093 { 0094 return s_aspectRatioActions[engine()->m_vWidget->aspectRatio()]; 0095 } 0096 0097 void TheStream::addRatio(int aspectEnum, QAction *ratioAction) 0098 { 0099 s_aspectRatioActions[aspectEnum] = ratioAction; 0100 } 0101 0102 int TheStream::subtitleChannel() 0103 { 0104 return engine()->m_controller->currentSubtitle().index(); 0105 } 0106 0107 int TheStream::audioChannel() 0108 { 0109 return engine()->m_controller->currentAudioChannel().index(); 0110 } 0111 0112 void TheStream::setRatio(QAction *ratioAction) 0113 { 0114 if (ratioAction) 0115 engine()->m_vWidget->setAspectRatio((Phonon::VideoWidget::AspectRatio)s_aspectRatioActions.key(ratioAction)); 0116 } 0117 0118 QString TheStream::prettyTitle() 0119 { 0120 const QUrl url = videoWindow()->m_media->currentSource().url(); 0121 QString artist, title; 0122 0123 const QStringList artists = videoWindow()->m_media->metaData(Phonon::ArtistMetaData); 0124 if (!artists.isEmpty()) { 0125 artist = artists.first().trimmed(); 0126 } 0127 0128 const QStringList titles = videoWindow()->m_media->metaData(Phonon::TitleMetaData); 0129 if (!titles.isEmpty()) { 0130 title = titles.first().trimmed(); 0131 } 0132 0133 if (hasVideo() && !title.isEmpty()) 0134 return title; 0135 else if (!title.isEmpty() && !artist.isEmpty()) 0136 return artist + QLatin1String(" - ") + title; 0137 else if (url.scheme() != QLatin1String("http") && !url.fileName().isEmpty()) { 0138 const QString n = url.fileName(); 0139 // toLatin1 sense fromPercentEncoding takes a QByteArray 0140 // I'm not sure about this whole method though, should double check that titles make sense 0141 // using QString::toLatin1() will display "????" in titlelabel. Should be QString::toUtf8(). patched by nihui, Jul.6th, 2008 0142 return QUrl::fromPercentEncoding( 0143 n.left(n.lastIndexOf(QLatin1Char('.'))).replace(QLatin1Char('_'), QLatin1Char(' ')).toUtf8()); // krazy:exclude-qclasses 0144 } else if (videoWindow()->m_media->currentSource().discType() == Phonon::Cd) { 0145 return i18n("Track %1/%2", 0146 videoWindow()->m_media->metaData().value(QStringLiteral("TRACK-NUMBER")), 0147 videoWindow()->m_media->metaData().value(QStringLiteral("TRACK-COUNT"))); 0148 } else { 0149 return url.toDisplayString(); 0150 } 0151 } 0152 0153 QString TheStream::fullTitle() 0154 { /* 0155 QString artist,album,title; 0156 QStringList artists = m_mediaObject->metaData(Phonon::ArtistMetaData); 0157 QStringList albums = m_mediaObject->metaData(Phonon::AlbumMetaData); 0158 QStringList titles = m_mediaObject->metaData(Phonon::TitleMetaData) 0159 title = (title ? titles.join( QLatin1String( " ") : "" ) ); 0160 album = (albums ? albums.join( QLatin1String( " "): "" ) ); 0161 artist = (artists ? artists.join( QLatin1String( " "): "" ) ); 0162 0163 return title + "\n" + album + "\n" + artist;*/ 0164 return QString(); 0165 } 0166 0167 bool TheStream::hasProfile() 0168 { 0169 return KSharedConfig::openConfig()->hasGroup(url().toDisplayString()); 0170 } 0171 0172 QString TheStream::metaData(Phonon::MetaData key) 0173 { 0174 QStringList values = videoWindow()->m_media->metaData(key); 0175 qDebug() << values; 0176 return (values.isEmpty()) ? QString() : values.join(QLatin1Char(' ')); 0177 } 0178 0179 QString TheStream::discId() 0180 { 0181 QStringList values = videoWindow()->m_media->metaData(Phonon::MusicBrainzDiscIdMetaData); 0182 if (!values.isEmpty()) 0183 return values.first(); 0184 0185 return QString(); 0186 } 0187 0188 }